Search in sources :

Example 16 with GraphHopperStorage

use of com.graphhopper.storage.GraphHopperStorage in project graphhopper by graphhopper.

the class EdgeBasedRoutingAlgorithmTest method testBlockANode.

@Test
public void testBlockANode() {
    GraphHopperStorage g = createStorage(createEncodingManager(true));
    initGraph(g);
    TurnCostExtension tcs = (TurnCostExtension) g.getExtension();
    blockNode3(g, tcs, carEncoder);
    for (int i = 0; i <= 7; i++) {
        if (i == 3)
            continue;
        for (int j = 0; j <= 7; j++) {
            if (j == 3)
                continue;
            Path p = createAlgo(g, AlgorithmOptions.start().weighting(createWeighting(carEncoder, tcs, 40)).traversalMode(TraversalMode.EDGE_BASED_2DIR).build()).calcPath(i, j);
            // We can go from everywhere to everywhere else without using node 3
            assertTrue(p.isFound());
            for (IntCursor node : p.calcNodes()) {
                assertNotEquals(p.calcNodes().toString(), 3, node.value);
            }
        }
    }
}
Also used : IntCursor(com.carrotsearch.hppc.cursors.IntCursor) TurnCostExtension(com.graphhopper.storage.TurnCostExtension) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) Test(org.junit.Test)

Example 17 with GraphHopperStorage

use of com.graphhopper.storage.GraphHopperStorage in project graphhopper by graphhopper.

the class FakeWalkNetworkBuilder method buildWalkNetwork.

static void buildWalkNetwork(Collection<GTFSFeed> feeds, GraphHopperStorage graph, PtFlagEncoder encoder, DistanceCalc distCalc) {
    Collection<ConstraintVertex> sites = new ArrayList<>();
    Map<Vertex, Integer> vertex2nodeId = new HashMap<>();
    feeds.stream().flatMap(feed -> feed.stops.values().stream()).forEach(stop -> {
        int i = graph.getNodes();
        graph.getNodeAccess().setNode(i++, stop.stop_lat, stop.stop_lon);
        ConstraintVertex site = new ConstraintVertex(new Coordinate(stop.stop_lon, stop.stop_lat));
        sites.add(site);
        vertex2nodeId.put(site, i - 1);
    });
    ConformingDelaunayTriangulator conformingDelaunayTriangulator = new ConformingDelaunayTriangulator(sites, 0.0);
    conformingDelaunayTriangulator.setConstraints(new ArrayList(), new ArrayList());
    conformingDelaunayTriangulator.formInitialDelaunay();
    QuadEdgeSubdivision tin = conformingDelaunayTriangulator.getSubdivision();
    List<QuadEdge> edges = tin.getPrimaryEdges(false);
    for (QuadEdge edge : edges) {
        EdgeIteratorState ghEdge = graph.edge(vertex2nodeId.get(edge.orig()), vertex2nodeId.get(edge.dest()));
        double distance = distCalc.calcDist(edge.orig().getY(), edge.orig().getX(), edge.dest().getY(), edge.dest().getX());
        ghEdge.setDistance(distance);
        ghEdge.setFlags(encoder.setSpeed(ghEdge.getFlags(), 5.0));
        ghEdge.setFlags(encoder.setAccess(ghEdge.getFlags(), true, true));
    }
}
Also used : GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) Coordinate(com.vividsolutions.jts.geom.Coordinate) QuadEdge(com.vividsolutions.jts.triangulate.quadedge.QuadEdge) java.util(java.util) EdgeIteratorState(com.graphhopper.util.EdgeIteratorState) ConformingDelaunayTriangulator(com.vividsolutions.jts.triangulate.ConformingDelaunayTriangulator) ConstraintVertex(com.vividsolutions.jts.triangulate.ConstraintVertex) Vertex(com.vividsolutions.jts.triangulate.quadedge.Vertex) GTFSFeed(com.conveyal.gtfs.GTFSFeed) DistanceCalc(com.graphhopper.util.DistanceCalc) QuadEdgeSubdivision(com.vividsolutions.jts.triangulate.quadedge.QuadEdgeSubdivision) ConstraintVertex(com.vividsolutions.jts.triangulate.ConstraintVertex) Vertex(com.vividsolutions.jts.triangulate.quadedge.Vertex) QuadEdge(com.vividsolutions.jts.triangulate.quadedge.QuadEdge) ConformingDelaunayTriangulator(com.vividsolutions.jts.triangulate.ConformingDelaunayTriangulator) QuadEdgeSubdivision(com.vividsolutions.jts.triangulate.quadedge.QuadEdgeSubdivision) ConstraintVertex(com.vividsolutions.jts.triangulate.ConstraintVertex) Coordinate(com.vividsolutions.jts.geom.Coordinate) EdgeIteratorState(com.graphhopper.util.EdgeIteratorState)

Example 18 with GraphHopperStorage

use of com.graphhopper.storage.GraphHopperStorage 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 19 with GraphHopperStorage

use of com.graphhopper.storage.GraphHopperStorage 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()), 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 20 with GraphHopperStorage

use of com.graphhopper.storage.GraphHopperStorage in project graphhopper by graphhopper.

the class PrepareRoutingSubnetworksTest method testAddEdgesAfterwards.

@Test
public void testAddEdgesAfterwards() {
    GraphHopperStorage g = createDeadEndUnvisitedNetworkStorage(em);
    assertEquals(11, g.getNodes());
    PrepareRoutingSubnetworks instance = new PrepareRoutingSubnetworks(g, Collections.singletonList(carFlagEncoder)).setMinOneWayNetworkSize(3);
    int removed = instance.removeDeadEndUnvisitedNetworks(new PrepEdgeFilter(carFlagEncoder));
    assertEquals(3, removed);
    instance.markNodesRemovedIfUnreachable();
    g.optimize();
    assertEquals(8, g.getNodes());
    assertTrue(isConsistent(g));
    g.edge(7, 8);
    assertTrue(isConsistent(g));
}
Also used : PrepEdgeFilter(com.graphhopper.routing.subnetwork.PrepareRoutingSubnetworks.PrepEdgeFilter) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) Test(org.junit.Test)

Aggregations

GraphHopperStorage (com.graphhopper.storage.GraphHopperStorage)40 Test (org.junit.Test)28 GraphBuilder (com.graphhopper.storage.GraphBuilder)8 PrepEdgeFilter (com.graphhopper.routing.subnetwork.PrepareRoutingSubnetworks.PrepEdgeFilter)7 EncodingManager (com.graphhopper.routing.util.EncodingManager)7 EdgeIteratorState (com.graphhopper.util.EdgeIteratorState)6 FastestWeighting (com.graphhopper.routing.weighting.FastestWeighting)5 TurnCostExtension (com.graphhopper.storage.TurnCostExtension)5 IntArrayList (com.carrotsearch.hppc.IntArrayList)4 RAMDirectory (com.graphhopper.storage.RAMDirectory)4 EdgeExplorer (com.graphhopper.util.EdgeExplorer)4 CarFlagEncoder (com.graphhopper.routing.util.CarFlagEncoder)3 FlagEncoder (com.graphhopper.routing.util.FlagEncoder)3 Weighting (com.graphhopper.routing.weighting.Weighting)3 GraphExtension (com.graphhopper.storage.GraphExtension)3 Random (java.util.Random)3 GraphHopper (com.graphhopper.GraphHopper)2 EdgeFilter (com.graphhopper.routing.util.EdgeFilter)2 HintsMap (com.graphhopper.routing.util.HintsMap)2 AlgoHelperEntry (com.graphhopper.routing.util.TestAlgoCollector.AlgoHelperEntry)2