Search in sources :

Example 21 with Edge

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]);
        }
    }
}
Also used : EdgeWeightedGraph(chapter4.section3.EdgeWeightedGraph) Edge(chapter4.section3.Edge)

Aggregations

Edge (boofcv.alg.segmentation.fh04.SegmentFelzenszwalbHuttenlocher04.Edge)18 GrayF32 (boofcv.struct.image.GrayF32)4 GrayU8 (boofcv.struct.image.GrayU8)4 FastQueue (org.ddogleg.struct.FastQueue)2 Test (org.junit.Test)2 Queue (chapter1.section3.Queue)1 UnionFind (chapter1.section5.UnionFind)1 PriorityQueueResize (chapter2.section4.PriorityQueueResize)1 SeparateChainingHashTable (chapter3.section4.SeparateChainingHashTable)1 HashSet (chapter3.section5.HashSet)1 OptimizedGraph (chapter4.section1.OptimizedGraph)1 TwoColor (chapter4.section1.TwoColor)1 Edge (chapter4.section3.Edge)1 EdgeWeightedGraph (chapter4.section3.EdgeWeightedGraph)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1