private Node GetMinWeightRudeNode(PlanCourse planCourse,ArrayList nodeList,string originID) { double weighting = double.MaxValue; Node destNode = null; foreach (Node node in nodeList) { if (node.Name==originID) { continue; } PassedPath pPath = planCourse[node.Name]; if (pPath.BeProcessed) { continue; } if (pPath.Weighting<weighting) { weighting = pPath.Weighting; destNode = node; } } return destNode; }
public RoutePlanResult Plan(ArrayList nodeList,string originID,string destID) { PlanCourse planCourse = new PlanCourse(nodeList,originID); Node curNode = GetMinWeightRudeNode(planCourse, nodeList, originID); while (curNode!=null) { PassedPath curPath = planCourse[curNode.Name]; foreach (Edge edge in curNode.Edges) { PassedPath targetPath = planCourse[edge.End]; double tempWeighting = curPath.Weighting + edge.Weighting; if (tempWeighting<targetPath.Weighting) { targetPath.Weighting = tempWeighting; targetPath.PassedIDList.Clear(); for (int i = 0; i < curPath.PassedIDList.Count; i++) { targetPath.PassedIDList.Add(curPath.PassedIDList[i].ToString()); } targetPath.PassedIDList.Add(curNode.Name); } } planCourse[curNode.Name].BeProcessed = true; curNode = GetMinWeightRudeNode(planCourse,nodeList,originID); } return this.GetResult(planCourse,destID); }
private RoutePlanResult GetResult(PlanCourse planCourse, string destID) { RoutePlanResult result = null; PassedPath pPath = planCourse[destID]; if (pPath.Weighting==int.MaxValue) { result = new RoutePlanResult(null,double.MaxValue); } else { string[] passedNodeIDs = new string[pPath.PassedIDList.Count]; for (int i = 0; i < passedNodeIDs.Length; i++) { passedNodeIDs[i] = pPath.PassedIDList[i].ToString(); } result = new RoutePlanResult(passedNodeIDs, pPath.Weighting); } return result; }