public void Test() { var weights = new DenseGraph <int?>(new int?[, ] { { 0000, 0007, 0009, null, null, 0014 }, { 0007, 0000, 0010, 0014, null, null }, { 0009, 0010, 0000, 0011, null, 0002 }, { null, 0014, 0011, 0000, 0006, null }, { null, null, null, 0006, 0000, 0009 }, { 0014, null, 0002, null, 0009, 0000 }, }); var floydWarshall = new FloydWarshall(weights); var floydWarshallResult = floydWarshall.GetResult(); var dijkstra = new Dijkstra(weights); for (var i = 0; i < weights.VertexCount; i++) { var dijkstraResult = dijkstra.GetResult(i); Assert.Equal(floydWarshallResult.distance.SliceRow(i), dijkstraResult.Select(x => x.Distance)); for (var j = 0; j < weights.VertexCount; j++) { Assert.Equal(floydWarshall.GetPath(floydWarshallResult.next, i, j), dijkstra.GetPath(dijkstraResult, i, j)); } } }
/// <summary> /// Test case for extracting paths /// </summary> //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void testPath() public virtual void TestPath() { Graph.makeEdge("a", "b", "cost", ( double )1); Graph.makeEdge("b", "c", "cost", ( float )1); Graph.makeEdge("c", "d", "cost", 1); Graph.makeEdge("d", "e", "cost", ( long )1); Graph.makeEdge("e", "f", "cost", ( sbyte )1); FloydWarshall <double> floydWarshall = new FloydWarshall <double>(0.0, double.MaxValue, Direction.OUTGOING, CommonEvaluators.doubleCostEvaluator("cost"), new Org.Neo4j.Graphalgo.impl.util.DoubleAdder(), double?.compareTo, Graph.AllNodes, Graph.AllEdges); IList <Node> path = floydWarshall.GetPath(Graph.getNode("a"), Graph.getNode("f")); assertEquals(6, path.Count); assertEquals(path[0], Graph.getNode("a")); assertEquals(path[1], Graph.getNode("b")); assertEquals(path[2], Graph.getNode("c")); assertEquals(path[3], Graph.getNode("d")); assertEquals(path[4], Graph.getNode("e")); assertEquals(path[5], Graph.getNode("f")); }
public void UnitFloydWarshall() { FloydWarshall newFloyd = new FloydWarshall(); newFloyd.MaxValue = 9999; newFloyd.TwoDimensionArray = new int[5, 5] { { 0, 3, 8, 9999, -4 }, { 9999, 0, 9999, 1, 7 }, { 9999, 4, 0, 9999, 9999 }, { 2, 9999, -5, 0, 9999 }, { 9999, 9999, 9999, 6, 0 } }; //newFloyd.dist = new int[5, 5] { { 0, int.MaxValue, int.MaxValue, 2, int.MaxValue }, { 3, 0, 4, int.MaxValue, int.MaxValue }, { 8, int.MaxValue, 0, -5, int.MaxValue }, { int.MaxValue, 1, int.MaxValue, 0, 6 }, { -4, 7, int.MaxValue, int.MaxValue, 0 } }; //newFloyd.dist = new int[5, 5] { { 0, int.MaxValue, 3, int.MaxValue, 1 }, // { 5, 0, int.MaxValue, int.MaxValue, 3 }, // { int.MaxValue, 2, 0, 4, int.MaxValue }, // { 2, int.MaxValue, int.MaxValue, 0, 0 }, // { int.MaxValue, int.MaxValue, 7, 1, 0 } }; //newFloyd.dist = new int[5, 5] { { 0, 5, int.MaxValue, 2, int.MaxValue }, // { int.MaxValue, 0, 2, int.MaxValue, int.MaxValue }, // { 3, int.MaxValue, 0, int.MaxValue, 7 }, // { int.MaxValue, int.MaxValue, 4, 0, 1 }, // { 1, 3, int.MaxValue, int.MaxValue, 0 } }; //newFloyd.dist = new int[4, 4] { {0, 5, 9999, 10}, // {9999, 0, 3, 9999}, // {9999, 9999, 0, 1}, // {9999, 9999, 9999, 0} }; newFloyd.NumberOfNodes = 5; newFloyd.Floyd_warshallWork(); List <int> rez = new List <int>(); newFloyd.GetPath(2, 4, ref rez); string result = ""; foreach (var item in rez) { result += item; } Assert.AreEqual("21304", result); }