// Use this for initialization void Start() { //利用LazyPrim算法计算稀疏有权图的最短路径 print("求稀疏有权图的最小生成树"); string name = ""; string url = ""; name = "testWeightG1.txt"; url = FileHelper.FileNameHelper(name); WeightSpareGraph <float> wsGraph = null; ReadWeightGraph.ReadGraphFromFile(url, out wsGraph, false); wsGraph.print(); LazyPrimMST lazyPrim = new LazyPrimMST(wsGraph); lazyPrim.print(); print("最小生成树的长度为:" + lazyPrim.length()); print("使用深度优先搜索的方法得到一棵生成树"); lazyPrim = new LazyPrimMST(wsGraph, true); lazyPrim.printOneTree(); print("*********************"); //利用Prim算法计算稀疏有权图的最短路径 PrimMST prim = new PrimMST(wsGraph); prim.print(); }
// Use this for initialization void Start() { string name = "testWeightG1.txt"; string url = FileHelper.FileNameHelper(name); WeightSpareGraph <float> sGraph = null; ReadWeightGraph.ReadGraphFromFile(url, out sGraph, false); KrusalMST <float> krusalMST = new KrusalMST <float> (sGraph); print("Krusal算法生成的最小生成树,长度为" + krusalMST.length()); krusalMST.print(); }
// Use this for initialization void Start() { string name = "testWeightG1.txt"; // name = "testShortPath.txt"; string url = FileHelper.FileNameHelper(name); WeightSpareGraph <float> sGraph = null; ReadWeightGraph.ReadGraphFromFile(url, out sGraph, false); sGraph.print(); Dijkstra dijkstra = new Dijkstra(sGraph, 0); dijkstra.ShowAllPath(); BellmanFord bellmanFord = new BellmanFord(sGraph, 0); bellmanFord.showAllPath(); }
//测试稠密有权图 //测试稀疏有权图 public void testWeightDSGraph() { string name = ""; string url = ""; //测试稠密有权图~ print("测试稠密有权图"); WeightDenseGraph <float> wdGraph = null; name = "testWeightG1.txt"; url = FileHelper.FileNameHelper(name); ReadWeightGraph.ReadGraphFromFile(url, out wdGraph, false); // out不可缺少 wdGraph.print(); //测试稀疏有权图 print("测试稀疏有权图"); WeightSpareGraph <float> wsGraph = null; ReadWeightGraph.ReadGraphFromFile(url, out wsGraph, false); wsGraph.print(); }