Search in sources :

Example 1 with CHAlgoFactoryDecorator

use of com.graphhopper.routing.ch.CHAlgoFactoryDecorator in project graphhopper by graphhopper.

the class GraphHopperOSMTest method testGetWeightingForCH.

@Test
public void testGetWeightingForCH() {
    TestEncoder truck = new TestEncoder("truck");
    TestEncoder simpleTruck = new TestEncoder("simple_truck");
    // use simple truck first
    EncodingManager em = new EncodingManager(simpleTruck, truck);
    CHAlgoFactoryDecorator decorator = new CHAlgoFactoryDecorator();
    Weighting fwSimpleTruck = new FastestWeighting(simpleTruck);
    Weighting fwTruck = new FastestWeighting(truck);
    RAMDirectory ramDir = new RAMDirectory();
    GraphHopperStorage storage = new GraphHopperStorage(Arrays.asList(fwSimpleTruck, fwTruck), ramDir, em, false, new GraphExtension.NoOpExtension());
    decorator.addWeighting(fwSimpleTruck);
    decorator.addWeighting(fwTruck);
    decorator.addPreparation(new PrepareContractionHierarchies(ramDir, storage, storage.getGraph(CHGraph.class, fwSimpleTruck), fwSimpleTruck, TraversalMode.NODE_BASED));
    decorator.addPreparation(new PrepareContractionHierarchies(ramDir, storage, storage.getGraph(CHGraph.class, fwTruck), fwTruck, TraversalMode.NODE_BASED));
    HintsMap wMap = new HintsMap("fastest");
    wMap.put("vehicle", "truck");
    assertEquals("fastest|truck", ((PrepareContractionHierarchies) decorator.getDecoratedAlgorithmFactory(null, wMap)).getWeighting().toString());
    wMap.put("vehicle", "simple_truck");
    assertEquals("fastest|simple_truck", ((PrepareContractionHierarchies) decorator.getDecoratedAlgorithmFactory(null, wMap)).getWeighting().toString());
    // make sure weighting cannot be mixed
    decorator.addWeighting(fwTruck);
    decorator.addWeighting(fwSimpleTruck);
    try {
        decorator.addPreparation(new PrepareContractionHierarchies(ramDir, storage, storage.getGraph(CHGraph.class, fwSimpleTruck), fwSimpleTruck, TraversalMode.NODE_BASED));
        assertTrue(false);
    } catch (Exception ex) {
    }
}
Also used : FastestWeighting(com.graphhopper.routing.weighting.FastestWeighting) AbstractWeighting(com.graphhopper.routing.weighting.AbstractWeighting) Weighting(com.graphhopper.routing.weighting.Weighting) PrepareContractionHierarchies(com.graphhopper.routing.ch.PrepareContractionHierarchies) CHAlgoFactoryDecorator(com.graphhopper.routing.ch.CHAlgoFactoryDecorator) FastestWeighting(com.graphhopper.routing.weighting.FastestWeighting) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

CHAlgoFactoryDecorator (com.graphhopper.routing.ch.CHAlgoFactoryDecorator)1 PrepareContractionHierarchies (com.graphhopper.routing.ch.PrepareContractionHierarchies)1 AbstractWeighting (com.graphhopper.routing.weighting.AbstractWeighting)1 FastestWeighting (com.graphhopper.routing.weighting.FastestWeighting)1 Weighting (com.graphhopper.routing.weighting.Weighting)1 IOException (java.io.IOException)1 Test (org.junit.Test)1