public void TestFindKShortestPath2() { Graph graph = new Graph(); var A = new Node() { Label = "A" }; var B = new Node() { Label = "B" }; var C = new Node() { Label = "C" }; var D = new Node() { Label = "D" }; var E = new Node() { Label = "E" }; graph.Add(A); graph.Add(B); graph.Add(C); graph.Add(D); graph.Add(E); graph.ConnectNodeToWith(A, B, new Edge(new AttributePair <Double> { Name = "Weight", Attribute = 4 })); graph.ConnectNodeToWith(B, E, new Edge(new AttributePair <Double> { Name = "Weight", Attribute = 5 })); graph.ConnectNodeToWith(A, C, new Edge(new AttributePair <Double> { Name = "Weight", Attribute = 5 })); graph.ConnectNodeToWith(C, E, new Edge(new AttributePair <Double> { Name = "Weight", Attribute = 4 })); graph.ConnectNodeToWith(A, D, new Edge(new AttributePair <Double> { Name = "Weight", Attribute = 1 })); graph.ConnectNodeToWith(D, E, new Edge(new AttributePair <Double> { Name = "Weight", Attribute = 7 })); /* * graph.ConnectNodeToWith(B, C, new Edge(new AttributePair<Double> { Name="Weight", Attribute=)(1)); * graph.ConnectNodeToWith(C, D, new Edge(new AttributePair<Double> { Name="Weight", Attribute=)(3)); * graph.ConnectNodeToWith(D, C, new Edge(new AttributePair<Double> { Name="Weight", Attribute=)(2)); * graph.ConnectNodeToWith(E, C, new Edge(new AttributePair<Double> { Name="Weight", Attribute=)(1)); */ KShortestPath ksp = new KShortestPath(); ksp.Setup(A, "Weight"); ksp.Run(); Assert.AreEqual(1, ksp.PathsTo(E).Count); }
public void TestFindKShortestPath5() { Graph graph = new Graph(); var A = new Node() { Label = "A" }; var B = new Node() { Label = "B" }; var C = new Node() { Label = "C" }; var D = new Node() { Label = "D" }; var E = new Node() { Label = "E" }; var F = new Node() { Label = "F" }; var G = new Node() { Label = "G" }; graph.Add(A); graph.Add(B); graph.Add(C); graph.Add(D); graph.Add(E); graph.Add(F); graph.Add(G); graph.ConnectNodeToWith(A, B, new Edge(new AttributePair <Double> { Name = "Weight", Attribute = 4 })); graph.ConnectNodeToWith(B, D, new Edge(new AttributePair <Double> { Name = "Weight", Attribute = 5 })); graph.ConnectNodeToWith(A, C, new Edge(new AttributePair <Double> { Name = "Weight", Attribute = 7 })); graph.ConnectNodeToWith(C, D, new Edge(new AttributePair <Double> { Name = "Weight", Attribute = 2 })); graph.ConnectNodeToWith(A, E, new Edge(new AttributePair <Double> { Name = "Weight", Attribute = 1 })); graph.ConnectNodeToWith(E, F, new Edge(new AttributePair <Double> { Name = "Weight", Attribute = 1 })); graph.ConnectNodeToWith(F, G, new Edge(new AttributePair <Double> { Name = "Weight", Attribute = 1 })); graph.ConnectNodeToWith(G, D, new Edge(new AttributePair <Double> { Name = "Weight", Attribute = 1 })); KShortestPath ksp = new KShortestPath(); ksp.Setup(A, "Weight"); ksp.Run(); Assert.AreEqual(1, ksp.PathsTo(D).Count); }