Пример #1
0
        //获取从起点到终点的权值最小的路径,DIJSTRA算法
        public RoutePlanResult[] Plan(List <Node> NodeList, string OriginID, string[] DestID)
        {
            //获取源点到与其相邻点的路径和权重值
            PlanCourse planCourse = new PlanCourse(NodeList, OriginID);
            //获取当前累积权重值最小,并且没有被处理过的节点
            Node curNode = GetMinWeightRouteNode(planCourse, NodeList, OriginID);

            while (curNode != null)
            {
                PassedPath curPath = planCourse[curNode.ID];
                foreach (Edge edge in curNode.EdgeList)
                {
                    if (edge.EndNodeID != OriginID)
                    {
                        PassedPath targetPath = planCourse[edge.EndNodeID];
                        double     tempWeight = curPath.SumWeight + edge.Weight;
                        if (tempWeight < targetPath.SumWeight)
                        {
                            targetPath.SumWeight = tempWeight;
                            targetPath.PathIDList.Clear();
                            for (int i = 0; i < curPath.PathIDList.Count; i++)
                            {
                                targetPath.PathIDList.Add(curPath.PathIDList[i].ToString());
                            }
                            targetPath.PathIDList.Add(curNode.ID);
                        }
                    }
                }
                //标记该节点已经处理了
                planCourse[curNode.ID].BeProcessed = true;
                ///获取下一个累积权重值最小,并且没有被处理过的节点
                curNode = GetMinWeightRouteNode(planCourse, NodeList, OriginID);
            }

            RoutePlanResult[] result = new RoutePlanResult[DestID.Length];
            for (int i = 0; i < DestID.Length; i++)
            {
                if (!DestID[i].Equals(OriginID))
                {
                    result[i] = GetResult(planCourse, DestID[i]);
                }
                else
                {
                    string[] passedNodeID = new string[1];
                    passedNodeID[0] = DestID[i];
                    result[i]       = new RoutePlanResult(passedNodeID, 0);
                }
            }

            return(result);

            //return GetResult(planCourse,DestID);
        }
Пример #2
0
        private void FindPath(string StartID, string EndID)
        {
            RoutePlanner    planner     = new RoutePlanner();
            RoutePlanResult routeresult = planner.Plan(NodeList, StartID, EndID);
            Result          result      = new Result();

            result.StrResultNode = routeresult.ResultNodes;
            result.EndNodeID     = EndID;
            if (result.StrResultNode == null)
            {
                int i = Convert.ToInt32(StartID);
                int j = Convert.ToInt32(EndID);
                MessageBox.Show(i.ToString() + ":" + j.ToString());
            }
            ResultList.Add(result);
        }
Пример #3
0
        public void FindPath(string StartID, string depotName, string[] EndID)
        {
            RoutePlanner planner = new RoutePlanner();

            RoutePlanResult[] RouteResult = new RoutePlanResult[EndID.Length];
            RouteResult = planner.Plan(NodeList, StartID, EndID);
            for (int i = 0; i < EndID.Length; i++)
            {
                Result result = new Result();
                result.DepotName       = depotName;
                result.WeightTime      = RouteResult[i].WeightValues;
                result.dynamicschedule = false;
                result.EndNodeID       = EndID[i];
                result.StrResultNode   = RouteResult[i].ResultNodes;
                ResultList.Add(result);
            }
        }
Пример #4
0
        public static RoutePlanResult GetResult(PlanCourse planCourse, string destID)
        {
            PassedPath pPath = planCourse[destID];

            if (pPath.SumWeight == double.MaxValue)
            {
                RoutePlanResult routePlanResult = new RoutePlanResult(null, double.MaxValue);
                return(routePlanResult);
            }

            string[] passedNodeIDs = new string[pPath.PathIDList.Count];
            for (int i = 0; i < passedNodeIDs.Length; i++)
            {
                passedNodeIDs[i] = pPath.PathIDList[i].ToString();
            }
            RoutePlanResult result = new RoutePlanResult(passedNodeIDs, pPath.SumWeight);

            return(result);
        }