Search in sources :

Example 21 with GraphHopperStorage

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

the class PrepareRoutingSubnetworksTest method test481.

@Test
public void test481() {
    // 0->1->3->4->5->6
    // 2        7<--/
    GraphHopperStorage g = createStorage(em);
    g.edge(0, 1, 1, false);
    g.edge(1, 2, 1, false);
    g.edge(2, 0, 1, false);
    g.edge(1, 3, 1, false);
    g.edge(3, 4, 1, false);
    g.edge(4, 5, 1, false);
    g.edge(5, 6, 1, false);
    g.edge(6, 7, 1, false);
    g.edge(7, 4, 1, false);
    PrepareRoutingSubnetworks instance = new PrepareRoutingSubnetworks(g, Collections.singletonList(carFlagEncoder)).setMinOneWayNetworkSize(2).setMinNetworkSize(4);
    instance.doWork();
    // only one remaining network
    List<IntArrayList> components = instance.findSubnetworks(new PrepEdgeFilter(carFlagEncoder));
    assertEquals(1, components.size());
}
Also used : IntArrayList(com.carrotsearch.hppc.IntArrayList) PrepEdgeFilter(com.graphhopper.routing.subnetwork.PrepareRoutingSubnetworks.PrepEdgeFilter) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) Test(org.junit.Test)

Example 22 with GraphHopperStorage

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

the class EngineWarmUp method warmUpNonCHSubNetwork.

private static void warmUpNonCHSubNetwork(final GraphHopper graphHopper, int iterations) {
    GraphHopperStorage ghStorage = graphHopper.getGraphHopperStorage();
    Random rand = new Random(0);
    EdgeExplorer explorer = ghStorage.getBaseGraph().createEdgeExplorer();
    for (int i = 0; i < iterations; i++) {
        BreadthFirstSearch bfs = new BreadthFirstSearch() {

            int counter = 0;

            @Override
            public boolean goFurther(int nodeId) {
                counter++;
                return counter < graphHopper.getMaxVisitedNodes();
            }
        };
        int startNode = rand.nextInt(ghStorage.getBaseGraph().getNodes() + 1);
        bfs.start(explorer, startNode);
    }
}
Also used : Random(java.util.Random) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage)

Example 23 with GraphHopperStorage

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

the class EngineWarmUp method warmUpCHSubNetwork.

private static void warmUpCHSubNetwork(GraphHopper graphHopper, int iterations) {
    GraphHopperStorage ghStorage = graphHopper.getGraphHopperStorage();
    Random rand = new Random(0);
    for (int i = 0; i < iterations; i++) {
        int startNode = rand.nextInt(graphHopper.getMaxVisitedNodes() + 1);
        int endNode = rand.nextInt(graphHopper.getMaxVisitedNodes() + 1);
        double fromLatitude = ghStorage.getNodeAccess().getLatitude(startNode);
        double fromLongitude = ghStorage.getNodeAccess().getLongitude(startNode);
        double toLatitude = ghStorage.getNodeAccess().getLatitude(endNode);
        double toLongitude = ghStorage.getNodeAccess().getLongitude(endNode);
        GHRequest request = new GHRequest(fromLatitude, fromLongitude, toLatitude, toLongitude);
        graphHopper.route(request);
    }
}
Also used : Random(java.util.Random) GHRequest(com.graphhopper.GHRequest) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage)

Example 24 with GraphHopperStorage

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

the class EdgeBasedRoutingAlgorithmTest method testTurnCostsBug_991.

@Test
public void testTurnCostsBug_991() {
    final GraphHopperStorage g = createStorage(createEncodingManager(false));
    initGraph(g);
    TurnCostExtension tcs = (TurnCostExtension) g.getExtension();
    long tflags = carEncoder.getTurnFlags(false, 2);
    tcs.addTurnInfo(getEdge(g, 5, 2).getEdge(), 2, getEdge(g, 2, 3).getEdge(), tflags);
    tcs.addTurnInfo(getEdge(g, 2, 0).getEdge(), 0, getEdge(g, 0, 1).getEdge(), tflags);
    tcs.addTurnInfo(getEdge(g, 5, 6).getEdge(), 6, getEdge(g, 6, 3).getEdge(), tflags);
    tflags = carEncoder.getTurnFlags(false, 1);
    tcs.addTurnInfo(getEdge(g, 6, 7).getEdge(), 7, getEdge(g, 7, 4).getEdge(), tflags);
    Path p = createAlgo(g, AlgorithmOptions.start().weighting(new TurnWeighting(new FastestWeighting(carEncoder), tcs) {

        @Override
        public double calcTurnWeight(int edgeFrom, int nodeVia, int edgeTo) {
            if (edgeFrom >= 0)
                assertNotNull("edge " + edgeFrom + " to " + nodeVia + " does not exist", g.getEdgeIteratorState(edgeFrom, nodeVia));
            if (edgeTo >= 0)
                assertNotNull("edge " + edgeTo + " to " + nodeVia + " does not exist", g.getEdgeIteratorState(edgeTo, nodeVia));
            return super.calcTurnWeight(edgeFrom, nodeVia, edgeTo);
        }
    }.setDefaultUTurnCost(40)).traversalMode(TraversalMode.EDGE_BASED_2DIR).build()).calcPath(5, 1);
    assertEquals(Helper.createTList(5, 6, 7, 4, 3, 1), p.calcNodes());
    assertEquals(301, p.getTime(), .1);
}
Also used : TurnWeighting(com.graphhopper.routing.weighting.TurnWeighting) TurnCostExtension(com.graphhopper.storage.TurnCostExtension) FastestWeighting(com.graphhopper.routing.weighting.FastestWeighting) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) Test(org.junit.Test)

Example 25 with GraphHopperStorage

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

the class PrepareRoutingSubnetworksTest method createDeadEndUnvisitedNetworkStorage.

GraphHopperStorage createDeadEndUnvisitedNetworkStorage(EncodingManager em) {
    GraphHopperStorage g = createStorage(em);
    // 0 <-> 1 <-> 2 <-> 3 <-> 4 <- 5 <-> 6
    g.edge(0, 1, 1, true);
    g.edge(1, 2, 1, true);
    g.edge(2, 3, 1, true);
    g.edge(3, 4, 1, true);
    g.edge(5, 4, 1, false);
    g.edge(5, 6, 1, true);
    // 7 -> 8 <-> 9 <-> 10
    g.edge(7, 8, 1, false);
    g.edge(8, 9, 1, true);
    g.edge(9, 10, 1, true);
    return g;
}
Also used : GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage)

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