static void Main(string[] args) { ArrayList nodeList = new ArrayList(); StreamReader sr = new StreamReader("./data.txt", Encoding.Default); string line; while ((line = sr.ReadLine()) != null) { string[] strs = line.Split(','); string nodeID = strs[0]; Node n = new Node(nodeID); for (int i = 1; i < strs.Length; i++) { Edge e = new Edge() { StartNodeID = n.ID, EndNodeID = strs[i].Split(':')[0], Weight = Convert.ToDouble(strs[i].Split(':')[1]) }; n.EdgeList.Add(e); } nodeList.Add(n); } RoutePlanner planner = new RoutePlanner(); sr.Close(); sr = new StreamReader("./fromto.txt", Encoding.Default); line = sr.ReadLine(); RoutePlanResult result = planner.Paln(nodeList, line.Split(',')[0], line.Split(',')[1]); Console.WriteLine(String.Format("{0}-{1}最短路径:", line.Split(',')[0], line.Split(',')[1])); foreach (string path in result.getPassedNodeIDs()) { Console.Write(path + " "); } Console.WriteLine(line.Split(',')[1]); Console.WriteLine(String.Format("权重为:{0}", result.getWeight())); planner = null; sr.Close(); Console.ReadKey(); }
//从PlanCourse表中取出目标节点的PassedPath,这个PassedPath即是规划结果 private RoutePlanResult GetResult(PlanCourse planCourse, string destID) { PassedPath pPath = planCourse[destID]; if (pPath.Weight == int.MaxValue) { RoutePlanResult result1 = new RoutePlanResult(null, int.MaxValue); return(result1); } string[] passedNodeIDs = new string[pPath.PassedIDList.Count]; for (int i = 0; i < passedNodeIDs.Length; i++) { passedNodeIDs[i] = pPath.PassedIDList[i].ToString(); } RoutePlanResult result = new RoutePlanResult(passedNodeIDs, pPath.Weight); return(result); }