Search in sources :

Example 1 with ConfigMap

use of com.graphhopper.util.ConfigMap in project graphhopper by graphhopper.

the class GraphEdgeIdFinderTest method testParseStringHints.

@Test
public void testParseStringHints() {
    FlagEncoder encoder = new CarFlagEncoder();
    EncodingManager em = new EncodingManager(encoder);
    GraphHopperStorage graph = new GraphBuilder(em).create();
    // 0-1-2
    // | |
    // 3-4
    graph.edge(0, 1, 1, true);
    graph.edge(1, 2, 1, true);
    graph.edge(3, 4, 1, true);
    graph.edge(0, 3, 1, true);
    graph.edge(1, 4, 1, true);
    AbstractRoutingAlgorithmTester.updateDistancesFor(graph, 0, 0.01, 0.00);
    AbstractRoutingAlgorithmTester.updateDistancesFor(graph, 1, 0.01, 0.01);
    AbstractRoutingAlgorithmTester.updateDistancesFor(graph, 2, 0.01, 0.02);
    AbstractRoutingAlgorithmTester.updateDistancesFor(graph, 3, 0.00, 0.00);
    AbstractRoutingAlgorithmTester.updateDistancesFor(graph, 4, 0.00, 0.01);
    LocationIndex locationIndex = new LocationIndexTree(graph, new RAMDirectory()).prepareIndex();
    HintsMap hints = new HintsMap();
    hints.put(Parameters.Routing.BLOCK_AREA, "0.01,0.005,1");
    ConfigMap cMap = new ConfigMap();
    GraphEdgeIdFinder graphFinder = new GraphEdgeIdFinder(graph, locationIndex);
    ConfigMap result = graphFinder.parseStringHints(cMap, hints, new DefaultEdgeFilter(encoder));
    GHIntHashSet blockedEdges = new GHIntHashSet();
    blockedEdges.add(0);
    assertEquals(blockedEdges, result.get(BLOCKED_EDGES, new GHIntHashSet()));
    List<Shape> blockedShapes = new ArrayList<>();
    assertEquals(blockedShapes, result.get(BLOCKED_SHAPES, new ArrayList<>()));
    // big area converts into shapes
    hints.put(Parameters.Routing.BLOCK_AREA, "0,0,1000");
    result = graphFinder.parseStringHints(cMap, hints, new DefaultEdgeFilter(encoder));
    blockedEdges.clear();
    assertEquals(blockedEdges, result.get(BLOCKED_EDGES, new GHIntHashSet()));
    blockedShapes.add(new Circle(0, 0, 1000));
    assertEquals(blockedShapes, result.get(BLOCKED_SHAPES, new ArrayList<>()));
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) HintsMap(com.graphhopper.routing.util.HintsMap) Circle(com.graphhopper.util.shapes.Circle) GHIntHashSet(com.graphhopper.coll.GHIntHashSet) Shape(com.graphhopper.util.shapes.Shape) ConfigMap(com.graphhopper.util.ConfigMap) CarFlagEncoder(com.graphhopper.routing.util.CarFlagEncoder) FlagEncoder(com.graphhopper.routing.util.FlagEncoder) ArrayList(java.util.ArrayList) LocationIndex(com.graphhopper.storage.index.LocationIndex) DefaultEdgeFilter(com.graphhopper.routing.util.DefaultEdgeFilter) LocationIndexTree(com.graphhopper.storage.index.LocationIndexTree) CarFlagEncoder(com.graphhopper.routing.util.CarFlagEncoder) Test(org.junit.Test)

Aggregations

GHIntHashSet (com.graphhopper.coll.GHIntHashSet)1 CarFlagEncoder (com.graphhopper.routing.util.CarFlagEncoder)1 DefaultEdgeFilter (com.graphhopper.routing.util.DefaultEdgeFilter)1 EncodingManager (com.graphhopper.routing.util.EncodingManager)1 FlagEncoder (com.graphhopper.routing.util.FlagEncoder)1 HintsMap (com.graphhopper.routing.util.HintsMap)1 LocationIndex (com.graphhopper.storage.index.LocationIndex)1 LocationIndexTree (com.graphhopper.storage.index.LocationIndexTree)1 ConfigMap (com.graphhopper.util.ConfigMap)1 Circle (com.graphhopper.util.shapes.Circle)1 Shape (com.graphhopper.util.shapes.Shape)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1