//RoutePlanner 提供图算法中常用的路径规划功能。///2005.09.06///publicclassRoutePlanner
{publicRoutePlanner()
{
}#regionPaln//获取权值最小的路径publicRoutePlanResult Paln(ArrayList nodeList ,stringoriginID ,stringdestID)
{
PlanCourse planCourse=newPlanCourse(nodeList ,originID) ;
Node curNode=this.GetMinWeightRudeNode(planCourse ,nodeList ,originID) ;#region计算过程while(curNode!=null)
{
PassedPath curPath=planCourse[curNode.ID] ;foreach(Edge edgeincurNode.EdgeList)
{
PassedPath targetPath=planCourse[edge.EndNodeID] ;doubletempWeight=curPath.Weight+edge.Weight ;if(tempWeight
{
targetPath.Weight=tempWeight ;
targetPath.PassedIDList.Clear() ;for(inti=0;i
{
targetPath.PassedIDList.Add(curPath.PassedIDList[i].ToString()) ;
}
targetPath.PassedIDList.Add(curNode.ID) ;
}
}//标志为已处理planCourse[curNode.ID].BeProcessed=true;//获取下一个未处理节点curNode=this.GetMinWeightRudeNode(planCourse ,nodeList ,originID) ;
}#endregion//表示规划结束returnthis.GetResult(planCourse ,destID) ;
}#endregion#regionprivate method#regionGetResult//从PlanCourse表中取出目标节点的PassedPath,这个PassedPath即是规划结果privateRoutePlanResult GetResult(PlanCourse planCourse ,stringdestID)
{
PassedPath pPath=planCourse[destID] ;if(pPath.Weight==int.MaxValue)
{
RoutePlanResult result1=newRoutePlanResult(null,int.MaxValue) ;returnresult1 ;
}string[] passedNodeIDs=newstring[pPath.PassedIDList.Count] ;for(inti=0;i
{
passedNodeIDs[i]=pPath.PassedIDList[i].ToString() ;
}
RoutePlanResult result=newRoutePlanResult(passedNodeIDs ,pPath.Weight) ;returnresult ;
}#endregion#regionGetMinWeightRudeNode//从PlanCourse取出一个当前累积权值最小,并且没有被处理过的节点privateNode GetMinWeightRudeNode(PlanCourse planCourse ,ArrayList nodeList ,stringoriginID)
{doubleweight=double.MaxValue ;
Node destNode=null;foreach(Node nodeinnodeList)
{if(node.ID==originID)
{continue;
}
PassedPath pPath=planCourse[node.ID] ;if(pPath.BeProcessed)
{continue;
}if(pPath.Weight
{
weight=pPath.Weight ;
destNode=node ;
}
}returndestNode ;
}#endregion#endregion}