Search in sources :

Example 1 with HintsMap

use of com.graphhopper.routing.util.HintsMap in project graphhopper by graphhopper.

the class RoutingAlgorithmIT method createAlgos.

public static List<AlgoHelperEntry> createAlgos(final GraphHopper hopper, final HintsMap hints, TraversalMode tMode) {
    GraphHopperStorage ghStorage = hopper.getGraphHopperStorage();
    LocationIndex idx = hopper.getLocationIndex();
    String addStr = "";
    if (tMode.isEdgeBased())
        addStr = "turn|";
    FlagEncoder encoder = hopper.getEncodingManager().getEncoder(hints.getVehicle());
    Weighting weighting = hopper.createWeighting(hints, encoder, hopper.getGraphHopperStorage());
    HintsMap defaultHints = new HintsMap().put(Parameters.CH.DISABLE, true).put(Parameters.Landmark.DISABLE, true).setVehicle(hints.getVehicle()).setWeighting(hints.getWeighting());
    AlgorithmOptions defaultOpts = AlgorithmOptions.start(new AlgorithmOptions("", weighting, tMode)).hints(defaultHints).build();
    List<AlgoHelperEntry> prepare = new ArrayList<>();
    prepare.add(new AlgoHelperEntry(ghStorage, AlgorithmOptions.start(defaultOpts).algorithm(ASTAR).build(), idx, "astar|beeline|" + addStr + weighting));
    // later: include dijkstraOneToMany
    prepare.add(new AlgoHelperEntry(ghStorage, AlgorithmOptions.start(defaultOpts).algorithm(DIJKSTRA).build(), idx, "dijkstra|" + addStr + weighting));
    AlgorithmOptions astarbiOpts = AlgorithmOptions.start(defaultOpts).algorithm(ASTAR_BI).build();
    astarbiOpts.getHints().put(ASTAR_BI + ".approximation", "BeelineSimplification");
    AlgorithmOptions dijkstrabiOpts = AlgorithmOptions.start(defaultOpts).algorithm(DIJKSTRA_BI).build();
    prepare.add(new AlgoHelperEntry(ghStorage, astarbiOpts, idx, "astarbi|beeline|" + addStr + weighting));
    prepare.add(new AlgoHelperEntry(ghStorage, dijkstrabiOpts, idx, "dijkstrabi|" + addStr + weighting));
    // add additional preparations if CH and LM preparation are enabled
    if (hopper.getLMFactoryDecorator().isEnabled()) {
        final HintsMap lmHints = new HintsMap(defaultHints).put(Parameters.Landmark.DISABLE, false);
        prepare.add(new AlgoHelperEntry(ghStorage, AlgorithmOptions.start(astarbiOpts).hints(lmHints).build(), idx, "astarbi|landmarks|" + weighting) {

            @Override
            public RoutingAlgorithmFactory createRoutingFactory() {
                return hopper.getAlgorithmFactory(lmHints);
            }
        });
    }
    if (hopper.getCHFactoryDecorator().isEnabled()) {
        final HintsMap chHints = new HintsMap(defaultHints).put(Parameters.CH.DISABLE, false);
        Weighting pickedWeighting = null;
        for (Weighting tmpWeighting : hopper.getCHFactoryDecorator().getWeightings()) {
            if (tmpWeighting.equals(weighting)) {
                pickedWeighting = tmpWeighting;
                break;
            }
        }
        if (pickedWeighting == null)
            throw new IllegalStateException("Didn't find weighting " + hints.getWeighting() + " in " + hopper.getCHFactoryDecorator().getWeightings());
        prepare.add(new AlgoHelperEntry(ghStorage.getGraph(CHGraph.class, pickedWeighting), AlgorithmOptions.start(dijkstrabiOpts).hints(chHints).build(), idx, "dijkstrabi|ch|prepare|" + hints.getWeighting()) {

            @Override
            public RoutingAlgorithmFactory createRoutingFactory() {
                return hopper.getAlgorithmFactory(chHints);
            }
        });
        prepare.add(new AlgoHelperEntry(ghStorage.getGraph(CHGraph.class, pickedWeighting), AlgorithmOptions.start(astarbiOpts).hints(chHints).build(), idx, "astarbi|ch|prepare|" + hints.getWeighting()) {

            @Override
            public RoutingAlgorithmFactory createRoutingFactory() {
                return hopper.getAlgorithmFactory(chHints);
            }
        });
    }
    return prepare;
}
Also used : HintsMap(com.graphhopper.routing.util.HintsMap) AlgoHelperEntry(com.graphhopper.routing.util.TestAlgoCollector.AlgoHelperEntry) FlagEncoder(com.graphhopper.routing.util.FlagEncoder) ArrayList(java.util.ArrayList) LocationIndex(com.graphhopper.storage.index.LocationIndex) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) Weighting(com.graphhopper.routing.weighting.Weighting)

Example 2 with HintsMap

use of com.graphhopper.routing.util.HintsMap in project graphhopper by graphhopper.

the class GenericWeightingTest method testRoadAttributeRestriction.

@Test
public void testRoadAttributeRestriction() {
    EdgeIteratorState edge = graph.getEdgeIteratorState(0, 1);
    Weighting instance = new GenericWeighting(encoder, new HintsMap().put(GenericWeighting.HEIGHT_LIMIT, 4.0));
    assertEquals(edgeWeight, instance.calcWeight(edge, false, EdgeIterator.NO_EDGE), 1e-8);
    instance = new GenericWeighting(encoder, new HintsMap().put(GenericWeighting.HEIGHT_LIMIT, 5.0));
    assertEquals(Double.POSITIVE_INFINITY, instance.calcWeight(edge, false, EdgeIterator.NO_EDGE), 1e-8);
}
Also used : HintsMap(com.graphhopper.routing.util.HintsMap) EdgeIteratorState(com.graphhopper.util.EdgeIteratorState) Test(org.junit.Test)

Example 3 with HintsMap

use of com.graphhopper.routing.util.HintsMap in project graphhopper by graphhopper.

the class RoutingAlgorithmIT method testPerformance.

@Test
public void testPerformance() throws IOException {
    int N = 10;
    int noJvmWarming = N / 4;
    Random rand = new Random(0);
    final EncodingManager eManager = new EncodingManager("car");
    final GraphHopperStorage graph = new GraphBuilder(eManager).create();
    String bigFile = "10000EWD.txt.gz";
    new PrincetonReader(graph).setStream(new GZIPInputStream(PrincetonReader.class.getResourceAsStream(bigFile))).read();
    GraphHopper hopper = new GraphHopper() {

        {
            setCHEnabled(false);
            setEncodingManager(eManager);
            loadGraph(graph);
        }

        @Override
        protected LocationIndex createLocationIndex(Directory dir) {
            return new LocationIndexTree(graph, dir);
        }
    };
    Collection<AlgoHelperEntry> prepares = createAlgos(hopper, new HintsMap().setWeighting("shortest").setVehicle("car"), TraversalMode.NODE_BASED);
    for (AlgoHelperEntry entry : prepares) {
        StopWatch sw = new StopWatch();
        for (int i = 0; i < N; i++) {
            int node1 = Math.abs(rand.nextInt(graph.getNodes()));
            int node2 = Math.abs(rand.nextInt(graph.getNodes()));
            RoutingAlgorithm d = entry.createRoutingFactory().createAlgo(graph, entry.getAlgorithmOptions());
            if (i >= noJvmWarming)
                sw.start();
            Path p = d.calcPath(node1, node2);
            // avoid jvm optimization => call p.distance
            if (i >= noJvmWarming && p.getDistance() > -1)
                sw.stop();
        // System.out.println("#" + i + " " + name + ":" + sw.getSeconds() + " " + p.nodes());
        }
        float perRun = sw.stop().getSeconds() / ((float) (N - noJvmWarming));
        System.out.println("# " + getClass().getSimpleName() + " " + entry + ":" + sw.stop().getSeconds() + ", per run:" + perRun);
        assertTrue("speed to low!? " + perRun + " per run", perRun < 0.08);
    }
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) AlgoHelperEntry(com.graphhopper.routing.util.TestAlgoCollector.AlgoHelperEntry) HintsMap(com.graphhopper.routing.util.HintsMap) PrincetonReader(com.graphhopper.reader.PrincetonReader) GraphHopper(com.graphhopper.GraphHopper) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) LocationIndexTree(com.graphhopper.storage.index.LocationIndexTree) StopWatch(com.graphhopper.util.StopWatch) GZIPInputStream(java.util.zip.GZIPInputStream) Random(java.util.Random) GraphBuilder(com.graphhopper.storage.GraphBuilder) Directory(com.graphhopper.storage.Directory) Test(org.junit.Test)

Example 4 with HintsMap

use of com.graphhopper.routing.util.HintsMap in project graphhopper by graphhopper.

the class GenericWeightingTest method testCalcTime.

@Test
public void testCalcTime() {
    GenericWeighting weighting = new GenericWeighting(encoder, new HintsMap());
    EdgeIteratorState edge = graph.getEdgeIteratorState(0, 1);
    assertEquals(edgeWeight, weighting.calcMillis(edge, false, EdgeIterator.NO_EDGE), .1);
}
Also used : HintsMap(com.graphhopper.routing.util.HintsMap) EdgeIteratorState(com.graphhopper.util.EdgeIteratorState) Test(org.junit.Test)

Example 5 with HintsMap

use of com.graphhopper.routing.util.HintsMap in project graphhopper by graphhopper.

the class GenericWeightingTest method testDisabledRoadAttributes.

@Test
public void testDisabledRoadAttributes() {
    DataFlagEncoder simpleEncoder = new DataFlagEncoder();
    EncodingManager simpleEncodingManager = new EncodingManager(simpleEncoder);
    Graph simpleGraph = new GraphBuilder(simpleEncodingManager).create();
    ReaderWay way = new ReaderWay(27l);
    way.setTag("highway", "primary");
    way.setTag("maxspeed", "10");
    way.setTag("maxheight", "4.4");
    // 0-1
    simpleGraph.edge(0, 1, 1, true);
    AbstractRoutingAlgorithmTester.updateDistancesFor(simpleGraph, 0, 0.00, 0.00);
    AbstractRoutingAlgorithmTester.updateDistancesFor(simpleGraph, 1, 0.01, 0.01);
    simpleGraph.getEdgeIteratorState(0, 1).setFlags(simpleEncoder.handleWayTags(way, 1, 0));
    Weighting instance = new GenericWeighting(simpleEncoder, new HintsMap().put(GenericWeighting.HEIGHT_LIMIT, 5.0));
    EdgeIteratorState edge = simpleGraph.getEdgeIteratorState(0, 1);
    assertEquals(edgeWeight, instance.calcWeight(edge, false, EdgeIterator.NO_EDGE), 1e-8);
}
Also used : DataFlagEncoder(com.graphhopper.routing.util.DataFlagEncoder) EncodingManager(com.graphhopper.routing.util.EncodingManager) HintsMap(com.graphhopper.routing.util.HintsMap) Graph(com.graphhopper.storage.Graph) EdgeIteratorState(com.graphhopper.util.EdgeIteratorState) GraphBuilder(com.graphhopper.storage.GraphBuilder) ReaderWay(com.graphhopper.reader.ReaderWay) Test(org.junit.Test)

Aggregations

HintsMap (com.graphhopper.routing.util.HintsMap)5 Test (org.junit.Test)4 EdgeIteratorState (com.graphhopper.util.EdgeIteratorState)3 EncodingManager (com.graphhopper.routing.util.EncodingManager)2 AlgoHelperEntry (com.graphhopper.routing.util.TestAlgoCollector.AlgoHelperEntry)2 GraphBuilder (com.graphhopper.storage.GraphBuilder)2 GraphHopperStorage (com.graphhopper.storage.GraphHopperStorage)2 GraphHopper (com.graphhopper.GraphHopper)1 PrincetonReader (com.graphhopper.reader.PrincetonReader)1 ReaderWay (com.graphhopper.reader.ReaderWay)1 DataFlagEncoder (com.graphhopper.routing.util.DataFlagEncoder)1 FlagEncoder (com.graphhopper.routing.util.FlagEncoder)1 Weighting (com.graphhopper.routing.weighting.Weighting)1 Directory (com.graphhopper.storage.Directory)1 Graph (com.graphhopper.storage.Graph)1 LocationIndex (com.graphhopper.storage.index.LocationIndex)1 LocationIndexTree (com.graphhopper.storage.index.LocationIndexTree)1 StopWatch (com.graphhopper.util.StopWatch)1 ArrayList (java.util.ArrayList)1 Random (java.util.Random)1