private static void JohnsonFunction() { string filename = @"data\SimpleGraph.txt"; Graph <int> g = new Graph <int>(); //LoadGraph loader = new LoadGraph(g, @"data\GraphWithNoNegativeCycle.txt"); LoadGraph loader = new LoadGraph(); loader.LoadAdjacencyListGraph(g, filename); var alg = new GraphTraversal(); var result = alg.JohnsonFunction(g); if (result.Item1) { Console.WriteLine("Negative Path found"); return; } if (result.Item2 != null) { foreach (var item in result.Item2) { Tuple <GraphNode <int>, GraphNode <int> > keyset = item.Key; GraphNode <int> nodeFrom = keyset.Item1; GraphNode <int> nodeTo = keyset.Item2; Console.WriteLine("Shortest distance from Node: " + nodeFrom.Value + " To: " + nodeTo.Value + " = " + item.Value); } } Console.WriteLine("Path found: "); }
private static void JohnsonFunction() { Graph <int> g = new Graph <int>(); LoadGraph loader = new LoadGraph(g, @"data\GraphWithNoNegativeCycle.txt"); var alg = new GraphTraversal(); var result = alg.JohnsonFunction(g); if (result != null) { foreach (var item in result) { Tuple <GraphNode <int>, GraphNode <int> > keyset = item.Key; GraphNode <int> nodeFrom = keyset.Item1; GraphNode <int> nodeTo = keyset.Item2; Console.WriteLine("Shortest distance from Node: " + nodeFrom.Value + " To: " + nodeTo.Value + " = " + item.Value); } } Console.WriteLine("Path found: "); }