Search in sources :

Example 6 with GraphHopperStorage

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

the class AlternativeRouteTest method createTestGraph.

public GraphHopperStorage createTestGraph(boolean fullGraph, EncodingManager tmpEM) {
    GraphHopperStorage graph = new GraphHopperStorage(new RAMDirectory(), tmpEM, false, new GraphExtension.NoOpExtension());
    graph.create(1000);
    /* 9
         _/\
         1  2-3-4-10
         \   /   \
         5--6-7---8
        
         */
    graph.edge(1, 9, 1, true);
    graph.edge(9, 2, 1, true);
    if (fullGraph)
        graph.edge(2, 3, 1, true);
    graph.edge(3, 4, 1, true);
    graph.edge(4, 10, 1, true);
    graph.edge(5, 6, 1, true);
    graph.edge(6, 7, 1, true);
    graph.edge(7, 8, 1, true);
    if (fullGraph)
        graph.edge(1, 5, 2, true);
    graph.edge(6, 3, 1, true);
    graph.edge(4, 8, 1, true);
    updateDistancesFor(graph, 5, 0.00, 0.05);
    updateDistancesFor(graph, 6, 0.00, 0.10);
    updateDistancesFor(graph, 7, 0.00, 0.15);
    updateDistancesFor(graph, 8, 0.00, 0.25);
    updateDistancesFor(graph, 1, 0.05, 0.00);
    updateDistancesFor(graph, 9, 0.10, 0.05);
    updateDistancesFor(graph, 2, 0.05, 0.10);
    updateDistancesFor(graph, 3, 0.05, 0.15);
    updateDistancesFor(graph, 4, 0.05, 0.25);
    updateDistancesFor(graph, 10, 0.05, 0.30);
    return graph;
}
Also used : RAMDirectory(com.graphhopper.storage.RAMDirectory) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) GraphExtension(com.graphhopper.storage.GraphExtension)

Example 7 with GraphHopperStorage

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

the class DijkstraOneToManyTest method testIssue239_and362.

@Test
public void testIssue239_and362() {
    GraphHopperStorage g = createGHStorage(false);
    g.edge(0, 1, 1, true);
    g.edge(1, 2, 1, true);
    g.edge(2, 0, 1, true);
    g.edge(4, 5, 1, true);
    g.edge(5, 6, 1, true);
    g.edge(6, 4, 1, true);
    DijkstraOneToMany algo = (DijkstraOneToMany) createAlgo(g);
    assertEquals(-1, algo.findEndNode(0, 4));
    assertEquals(-1, algo.findEndNode(0, 4));
    assertEquals(1, algo.findEndNode(0, 1));
    assertEquals(1, algo.findEndNode(0, 1));
}
Also used : GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) Test(org.junit.Test)

Example 8 with GraphHopperStorage

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

the class EdgeBasedRoutingAlgorithmTest method testBasicTurnCosts.

@Test
public void testBasicTurnCosts() {
    GraphHopperStorage g = createStorage(createEncodingManager(false));
    initGraph(g);
    TurnCostExtension tcs = (TurnCostExtension) g.getExtension();
    Path p = createAlgo(g, AlgorithmOptions.start().weighting(createWeighting(carEncoder, tcs, 40)).traversalMode(TraversalMode.EDGE_BASED_1DIR).build()).calcPath(5, 1);
    // no restriction and costs
    EdgeIteratorState e3_6 = getEdge(g, 5, 6);
    e3_6.setDistance(2);
    assertEquals(Helper.createTList(5, 2, 3, 1), p.calcNodes());
    // now introduce some turn costs
    long tflags = carEncoder.getTurnFlags(false, 2);
    tcs.addTurnInfo(getEdge(g, 5, 2).getEdge(), 2, getEdge(g, 2, 3).getEdge(), tflags);
    p = createAlgo(g, AlgorithmOptions.start().weighting(createWeighting(carEncoder, tcs, 40)).traversalMode(TraversalMode.EDGE_BASED_1DIR).build()).calcPath(5, 1);
    assertEquals(Helper.createTList(5, 6, 3, 1), p.calcNodes());
}
Also used : EdgeIteratorState(com.graphhopper.util.EdgeIteratorState) TurnCostExtension(com.graphhopper.storage.TurnCostExtension) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) Test(org.junit.Test)

Example 9 with GraphHopperStorage

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

the class EdgeBasedRoutingAlgorithmTest method testUTurns.

@Test
public void testUTurns() {
    GraphHopperStorage g = createStorage(createEncodingManager(true));
    initGraph(g);
    TurnCostExtension tcs = (TurnCostExtension) g.getExtension();
    long tflags = carEncoder.getTurnFlags(true, 0);
    // force u-turn via lowering the cost for it
    EdgeIteratorState e3_6 = getEdge(g, 3, 6);
    e3_6.setDistance(0.1);
    getEdge(g, 3, 2).setDistance(864);
    getEdge(g, 1, 0).setDistance(864);
    tcs.addTurnInfo(getEdge(g, 7, 6).getEdge(), 6, getEdge(g, 6, 5).getEdge(), tflags);
    tcs.addTurnInfo(getEdge(g, 4, 3).getEdge(), 3, e3_6.getEdge(), tflags);
    AlgorithmOptions opts = AlgorithmOptions.start().weighting(createWeighting(carEncoder, tcs, 50)).traversalMode(TraversalMode.EDGE_BASED_2DIR_UTURN).build();
    Path p = createAlgo(g, opts).calcPath(7, 5);
    assertEquals(Helper.createTList(7, 6, 3, 6, 5), p.calcNodes());
    // no u-turn for 6-3
    opts = AlgorithmOptions.start().weighting(createWeighting(carEncoder, tcs, 100)).traversalMode(TraversalMode.EDGE_BASED_2DIR_UTURN).build();
    tcs.addTurnInfo(getEdge(g, 6, 3).getEdge(), 3, getEdge(g, 3, 6).getEdge(), tflags);
    p = createAlgo(g, opts).calcPath(7, 5);
    assertEquals(Helper.createTList(7, 6, 3, 2, 5), p.calcNodes());
}
Also used : EdgeIteratorState(com.graphhopper.util.EdgeIteratorState) TurnCostExtension(com.graphhopper.storage.TurnCostExtension) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) Test(org.junit.Test)

Example 10 with GraphHopperStorage

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

the class PrepareRoutingSubnetworksTest method testFindSubnetworks.

@Test
public void testFindSubnetworks() {
    GraphHopperStorage g = createSubnetworkTestStorage();
    PrepEdgeFilter filter = new PrepEdgeFilter(carFlagEncoder);
    PrepareRoutingSubnetworks instance = new PrepareRoutingSubnetworks(g, Collections.singletonList(carFlagEncoder));
    List<IntArrayList> components = instance.findSubnetworks(filter);
    assertEquals(3, components.size());
    // start is at 0 => large network
    assertEquals(Helper.createTList(0, 7, 3, 13, 5), components.get(0));
    // next smallest and unvisited node is 1 => big network
    assertEquals(Helper.createTList(1, 8, 4, 2, 11, 12, 9, 15), components.get(1));
    assertEquals(Helper.createTList(6, 14, 10), components.get(2));
}
Also used : IntArrayList(com.carrotsearch.hppc.IntArrayList) PrepEdgeFilter(com.graphhopper.routing.subnetwork.PrepareRoutingSubnetworks.PrepEdgeFilter) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) Test(org.junit.Test)

Aggregations

GraphHopperStorage (com.graphhopper.storage.GraphHopperStorage)33 Test (org.junit.Test)25 GraphBuilder (com.graphhopper.storage.GraphBuilder)8 EncodingManager (com.graphhopper.routing.util.EncodingManager)7 PrepEdgeFilter (com.graphhopper.routing.subnetwork.PrepareRoutingSubnetworks.PrepEdgeFilter)6 EdgeIteratorState (com.graphhopper.util.EdgeIteratorState)5 IntArrayList (com.carrotsearch.hppc.IntArrayList)4 FastestWeighting (com.graphhopper.routing.weighting.FastestWeighting)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 RAMDirectory (com.graphhopper.storage.RAMDirectory)3 TurnCostExtension (com.graphhopper.storage.TurnCostExtension)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 CHGraph (com.graphhopper.storage.CHGraph)2 GraphExtension (com.graphhopper.storage.GraphExtension)2