public void DijkstraSimpleTest1() { var n5 = new SingleSourceShortestPaths.Node(); var n3 = new SingleSourceShortestPaths.Node(); n3.Edges.Add(new SingleSourceShortestPaths.Edge() { Length = 10, ToNode = n5 }); var n4 = new SingleSourceShortestPaths.Node(); n4.Edges.Add(new SingleSourceShortestPaths.Edge() { Length = 20, ToNode = n3 }); n4.Edges.Add(new SingleSourceShortestPaths.Edge() { Length = 60, ToNode = n5 }); var n2 = new SingleSourceShortestPaths.Node(); n2.Edges.Add(new SingleSourceShortestPaths.Edge() { Length = 50, ToNode = n3 }); var n1 = new SingleSourceShortestPaths.Node(); n1.Edges.Add(new SingleSourceShortestPaths.Edge() { Length = 10, ToNode = n2 }); n1.Edges.Add(new SingleSourceShortestPaths.Edge() { Length = 30, ToNode = n4 }); n1.Edges.Add(new SingleSourceShortestPaths.Edge() { Length = 100, ToNode = n5 }); var d = SingleSourceShortestPaths.DijkstraSimple(n1); Assert.Equal(0ul, d[n1]); Assert.Equal(10ul, d[n2]); Assert.Equal(50ul, d[n3]); Assert.Equal(30ul, d[n4]); Assert.Equal(60ul, d[n5]); }
public void DijkstraTest2() { var n1 = new SingleSourceShortestPaths.Node(); var n2 = new SingleSourceShortestPaths.Node(); var n3 = new SingleSourceShortestPaths.Node(); var n4 = new SingleSourceShortestPaths.Node(); var n5 = new SingleSourceShortestPaths.Node(); var n6 = new SingleSourceShortestPaths.Node(); n1.Edges.Add(new SingleSourceShortestPaths.Edge() { Length = 50, ToNode = n2 }); n1.Edges.Add(new SingleSourceShortestPaths.Edge() { Length = 10, ToNode = n3 }); n1.Edges.Add(new SingleSourceShortestPaths.Edge() { Length = 45, ToNode = n5 }); n2.Edges.Add(new SingleSourceShortestPaths.Edge() { Length = 10, ToNode = n5 }); n3.Edges.Add(new SingleSourceShortestPaths.Edge() { Length = 20, ToNode = n1 }); n3.Edges.Add(new SingleSourceShortestPaths.Edge() { Length = 15, ToNode = n4 }); n4.Edges.Add(new SingleSourceShortestPaths.Edge() { Length = 20, ToNode = n2 }); n4.Edges.Add(new SingleSourceShortestPaths.Edge() { Length = 35, ToNode = n5 }); n5.Edges.Add(new SingleSourceShortestPaths.Edge() { Length = 30, ToNode = n4 }); n6.Edges.Add(new SingleSourceShortestPaths.Edge() { Length = 3, ToNode = n4 }); var d = SingleSourceShortestPaths.Dijkstra(n1); Assert.Equal(0ul, d[n1]); Assert.Equal(45ul, d[n2]); Assert.Equal(10ul, d[n3]); Assert.Equal(25ul, d[n4]); Assert.Equal(45ul, d[n5]); Assert.False(d.ContainsKey(n6)); d = SingleSourceShortestPaths.Dijkstra(n5); Assert.False(d.ContainsKey(n1)); Assert.Equal(50ul, d[n2]); Assert.False(d.ContainsKey(n3)); Assert.Equal(30ul, d[n4]); Assert.Equal(0ul, d[n5]); Assert.False(d.ContainsKey(n6)); d = SingleSourceShortestPaths.Dijkstra(n6); Assert.False(d.ContainsKey(n1)); Assert.Equal(23ul, d[n2]); Assert.False(d.ContainsKey(n3)); Assert.Equal(3ul, d[n4]); Assert.Equal(33ul, d[n5]); Assert.Equal(0ul, d[n6]); }