Search in sources :

Example 31 with EncodingManager

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

the class PrepareContractionHierarchiesTest method testMultiplePreparationsDifferentView.

@Test
public void testMultiplePreparationsDifferentView() {
    CarFlagEncoder tmpCarEncoder = new CarFlagEncoder();
    BikeFlagEncoder tmpBikeEncoder = new BikeFlagEncoder();
    EncodingManager tmpEncodingManager = new EncodingManager(tmpCarEncoder, tmpBikeEncoder);
    Weighting carWeighting = new FastestWeighting(tmpCarEncoder);
    Weighting bikeWeighting = new FastestWeighting(tmpBikeEncoder);
    List<Weighting> chWeightings = Arrays.asList(carWeighting, bikeWeighting);
    GraphHopperStorage ghStorage = new GraphHopperStorage(chWeightings, dir, tmpEncodingManager, false, new GraphExtension.NoOpExtension()).create(1000);
    initShortcutsGraph(ghStorage);
    EdgeIteratorState edge = GHUtility.getEdge(ghStorage, 9, 14);
    edge.setFlags(tmpBikeEncoder.setAccess(edge.getFlags(), false, false));
    ghStorage.freeze();
    checkPath(ghStorage, carWeighting, 7, 5, Helper.createTList(3, 9, 14, 16, 13, 12));
    // detour around blocked 9,14
    checkPath(ghStorage, bikeWeighting, 9, 5, Helper.createTList(3, 10, 14, 16, 13, 12));
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) FastestWeighting(com.graphhopper.routing.weighting.FastestWeighting) Weighting(com.graphhopper.routing.weighting.Weighting) ShortestWeighting(com.graphhopper.routing.weighting.ShortestWeighting) BikeFlagEncoder(com.graphhopper.routing.util.BikeFlagEncoder) FastestWeighting(com.graphhopper.routing.weighting.FastestWeighting) CarFlagEncoder(com.graphhopper.routing.util.CarFlagEncoder) Test(org.junit.Test)

Example 32 with EncodingManager

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

the class LMAlgoFactoryDecoratorTest method addWeighting.

@Test
public void addWeighting() {
    LMAlgoFactoryDecorator dec = new LMAlgoFactoryDecorator().setEnabled(true);
    dec.addWeighting("fastest");
    assertEquals(Arrays.asList("fastest"), dec.getWeightingsAsStrings());
    // special parameters like the maximum weight
    dec = new LMAlgoFactoryDecorator().setEnabled(true);
    dec.addWeighting("fastest|maximum=65000");
    dec.addWeighting("shortest|maximum=20000");
    assertEquals(Arrays.asList("fastest", "shortest"), dec.getWeightingsAsStrings());
    FlagEncoder car = new CarFlagEncoder();
    EncodingManager em = new EncodingManager(car);
    dec.addWeighting(new FastestWeighting(car)).addWeighting(new ShortestWeighting(car));
    dec.createPreparations(new GraphHopperStorage(new RAMDirectory(), em, false, new GraphExtension.NoOpExtension()), TraversalMode.NODE_BASED, null);
    assertEquals(1, dec.getPreparations().get(0).getLandmarkStorage().getFactor(), .1);
    assertEquals(0.3, dec.getPreparations().get(1).getLandmarkStorage().getFactor(), .1);
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) CarFlagEncoder(com.graphhopper.routing.util.CarFlagEncoder) FlagEncoder(com.graphhopper.routing.util.FlagEncoder) FastestWeighting(com.graphhopper.routing.weighting.FastestWeighting) CarFlagEncoder(com.graphhopper.routing.util.CarFlagEncoder) ShortestWeighting(com.graphhopper.routing.weighting.ShortestWeighting) RAMDirectory(com.graphhopper.storage.RAMDirectory) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) Test(org.junit.Test)

Example 33 with EncodingManager

use of com.graphhopper.routing.util.EncodingManager 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 PrinctonReader(graph).setStream(new GZIPInputStream(PrinctonReader.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) HintsMap(com.graphhopper.routing.util.HintsMap) AlgoHelperEntry(com.graphhopper.routing.util.TestAlgoCollector.AlgoHelperEntry) 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) PrinctonReader(com.graphhopper.reader.PrinctonReader) GraphBuilder(com.graphhopper.storage.GraphBuilder) Directory(com.graphhopper.storage.Directory) Test(org.junit.Test)

Aggregations

EncodingManager (com.graphhopper.routing.util.EncodingManager)33 Test (org.junit.Test)15 GraphHopperOSM (com.graphhopper.reader.osm.GraphHopperOSM)14 GraphBuilder (com.graphhopper.storage.GraphBuilder)10 CarFlagEncoder (com.graphhopper.routing.util.CarFlagEncoder)8 GraphHopperStorage (com.graphhopper.storage.GraphHopperStorage)7 FlagEncoder (com.graphhopper.routing.util.FlagEncoder)6 Graph (com.graphhopper.storage.Graph)5 File (java.io.File)5 DefaultEdgeFilter (com.graphhopper.routing.util.DefaultEdgeFilter)4 FastestWeighting (com.graphhopper.routing.weighting.FastestWeighting)4 SRTMProvider (com.graphhopper.reader.dem.SRTMProvider)3 ShortestWeighting (com.graphhopper.routing.weighting.ShortestWeighting)3 RAMDirectory (com.graphhopper.storage.RAMDirectory)3 Before (org.junit.Before)3 GraphHopper (com.graphhopper.GraphHopper)2 ReaderWay (com.graphhopper.reader.ReaderWay)2 BikeFlagEncoder (com.graphhopper.routing.util.BikeFlagEncoder)2 DataFlagEncoder (com.graphhopper.routing.util.DataFlagEncoder)2 HintsMap (com.graphhopper.routing.util.HintsMap)2