use of chapter4.section3.Edge in project algorithms-sedgewick-wayne by reneargento.
the class Exercise31_AllPairsShortestPathsOnALine method main.
public static void main(String[] args) {
EdgeWeightedGraph edgeWeightedGraph = new EdgeWeightedGraph(5);
edgeWeightedGraph.addEdge(new Edge(0, 1, 2));
edgeWeightedGraph.addEdge(new Edge(1, 2, 3));
edgeWeightedGraph.addEdge(new Edge(2, 3, 4));
edgeWeightedGraph.addEdge(new Edge(3, 4, 1));
AllPairsShortestPathsOnALine allPairsShortestPathsOnALine = new Exercise31_AllPairsShortestPathsOnALine().new AllPairsShortestPathsOnALine(edgeWeightedGraph);
double[][] expectedDistances = { { 0, 2, 5, 9, 10 }, { 2, 0, 3, 7, 8 }, { 5, 3, 0, 4, 5 }, { 9, 7, 4, 0, 1 }, { 10, 8, 5, 1, 0 } };
for (int source = 0; source < edgeWeightedGraph.vertices(); source++) {
for (int target = 0; target < edgeWeightedGraph.vertices(); target++) {
StdOut.println("Distance from " + source + " to " + target + ": " + allPairsShortestPathsOnALine.dist(source, target) + " Expected: " + expectedDistances[source][target]);
}
}
}
Aggregations