Search in sources :

Example 1 with BaseGraph

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

the class PrepareRoutingSubnetworksTest method createSubnetworkTestStorage.

private static BaseGraph createSubnetworkTestStorage(EncodingManager encodingManager) {
    BaseGraph g = new BaseGraph.Builder(encodingManager).create();
    // 5 - 6
    // | /
    // 4
    // | <- (no access flags unless we change it)
    // 0 - 1 - 3 - 7 - 8
    // |       |
    // 2 -------
    g.edge(3, 4).setDistance(1);
    g.edge(0, 1).setDistance(1);
    g.edge(1, 3).setDistance(1);
    g.edge(0, 2).setDistance(1);
    g.edge(2, 3).setDistance(1);
    g.edge(3, 7).setDistance(1);
    g.edge(7, 8).setDistance(1);
    g.edge(4, 5).setDistance(1);
    g.edge(5, 6).setDistance(1);
    g.edge(4, 6).setDistance(1);
    // set access for all encoders
    AllEdgesIterator iter = g.getAllEdges();
    while (iter.next()) {
        // edge 3-4 gets no speed/access by default
        if (iter.getEdge() == 0)
            continue;
        for (FlagEncoder encoder : encodingManager.fetchEdgeEncoders()) {
            iter.set(encoder.getAverageSpeedEnc(), 10);
            iter.set(encoder.getAccessEnc(), true, true);
        }
    }
    return g;
}
Also used : AllEdgesIterator(com.graphhopper.routing.util.AllEdgesIterator) FlagEncoder(com.graphhopper.routing.util.FlagEncoder) BaseGraph(com.graphhopper.storage.BaseGraph)

Example 2 with BaseGraph

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

the class PrepareRoutingSubnetworksTest method createSubnetworkTestStorageWithOneWays.

private BaseGraph createSubnetworkTestStorageWithOneWays(EncodingManager em, FlagEncoder encoder) {
    if (em.fetchEdgeEncoders().size() > 1)
        fail("Warning: This method only sets access/speed for a single encoder, but the given encoding manager has multiple encoders");
    BaseGraph g = new BaseGraph.Builder(em).create();
    // 0 - 1 - 2 - 3 - 4 <- 5 - 6
    GHUtility.setSpeed(60, true, true, encoder, g.edge(0, 1).setDistance(1));
    GHUtility.setSpeed(60, true, true, encoder, g.edge(1, 2).setDistance(1));
    GHUtility.setSpeed(60, true, true, encoder, g.edge(2, 3).setDistance(1));
    GHUtility.setSpeed(60, true, true, encoder, g.edge(3, 4).setDistance(1));
    GHUtility.setSpeed(60, true, false, encoder, g.edge(5, 4).setDistance(1));
    GHUtility.setSpeed(60, true, true, encoder, g.edge(5, 6).setDistance(1));
    // 7 -> 8 - 9 - 10
    GHUtility.setSpeed(60, true, false, encoder, g.edge(7, 8).setDistance(1));
    GHUtility.setSpeed(60, true, true, encoder, g.edge(8, 9).setDistance(1));
    GHUtility.setSpeed(60, true, true, encoder, g.edge(9, 10).setDistance(1));
    return g;
}
Also used : BaseGraph(com.graphhopper.storage.BaseGraph)

Example 3 with BaseGraph

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

the class PrepareRoutingSubnetworksTest method testPrepareSubnetworks_twoVehicles.

@Test
public void testPrepareSubnetworks_twoVehicles() {
    EncodingManager em = createEncodingManager("car,bike");
    FlagEncoder carEncoder = em.getEncoder("car");
    FlagEncoder bikeEncoder = em.getEncoder("bike");
    BaseGraph g = createSubnetworkTestStorage(em);
    // first we only block the middle edge for cars. this way a subnetwork should be created but only for car
    EdgeIteratorState edge = GHUtility.getEdge(g, 3, 4);
    GHUtility.setSpeed(10, false, false, carEncoder, edge);
    GHUtility.setSpeed(5, true, true, bikeEncoder, edge);
    List<PrepareRoutingSubnetworks.PrepareJob> prepareJobs = Arrays.asList(createJob(em, carEncoder, NO_TURN_COST_PROVIDER), createJob(em, bikeEncoder, NO_TURN_COST_PROVIDER));
    PrepareRoutingSubnetworks instance = new PrepareRoutingSubnetworks(g, prepareJobs);
    instance.setMinNetworkSize(5);
    assertEquals(3, instance.doWork());
    assertEquals(IntArrayList.from(7, 8, 9), getSubnetworkEdges(g, carEncoder));
    assertEquals(IntArrayList.from(), getSubnetworkEdges(g, bikeEncoder));
    // now we block the edge for both vehicles -> there should be a subnetwork for both vehicles
    g = createSubnetworkTestStorage(em);
    edge = GHUtility.getEdge(g, 3, 4);
    GHUtility.setSpeed(10, false, false, carEncoder, edge);
    GHUtility.setSpeed(5, false, false, bikeEncoder, edge);
    instance = new PrepareRoutingSubnetworks(g, prepareJobs);
    instance.setMinNetworkSize(5);
    assertEquals(6, instance.doWork());
    assertEquals(IntArrayList.from(7, 8, 9), getSubnetworkEdges(g, carEncoder));
    assertEquals(IntArrayList.from(7, 8, 9), getSubnetworkEdges(g, bikeEncoder));
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) FlagEncoder(com.graphhopper.routing.util.FlagEncoder) EdgeIteratorState(com.graphhopper.util.EdgeIteratorState) BaseGraph(com.graphhopper.storage.BaseGraph) Test(org.junit.jupiter.api.Test)

Example 4 with BaseGraph

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

the class PrepareRoutingSubnetworksTest method testPrepareSubnetworks_withOneWays.

@Test
public void testPrepareSubnetworks_withOneWays() {
    EncodingManager em = createEncodingManager("car");
    FlagEncoder encoder = em.fetchEdgeEncoders().iterator().next();
    BaseGraph g = createSubnetworkTestStorageWithOneWays(em, encoder);
    assertEquals(11, g.getNodes());
    PrepareRoutingSubnetworks.PrepareJob job = createJob(em, encoder, NO_TURN_COST_PROVIDER);
    PrepareRoutingSubnetworks instance = new PrepareRoutingSubnetworks(g, Collections.singletonList(job)).setMinNetworkSize(2);
    int subnetworkEdges = instance.doWork();
    // the (7) and the (5,6) components become subnetworks -> 2 remaining components and 3 subnetwork edges
    // note that the subnetworkEV per profile is one bit per *edge*. Before we used the encoder$access with 2 bits
    // and got more fine grained response here (8 removed *edgeKeys*)
    assertEquals(3, subnetworkEdges);
    assertEquals(IntArrayList.from(4, 5, 6), getSubnetworkEdges(g, encoder));
    g = createSubnetworkTestStorageWithOneWays(em, encoder);
    assertEquals(11, g.getNodes());
    instance = new PrepareRoutingSubnetworks(g, Collections.singletonList(job)).setMinNetworkSize(3);
    subnetworkEdges = instance.doWork();
    // due to the larger min network size this time also the (8,9,10) component is a subnetwork
    assertEquals(5, subnetworkEdges);
    assertEquals(IntArrayList.from(4, 5, 6, 7, 8), getSubnetworkEdges(g, encoder));
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) FlagEncoder(com.graphhopper.routing.util.FlagEncoder) BaseGraph(com.graphhopper.storage.BaseGraph) Test(org.junit.jupiter.api.Test)

Example 5 with BaseGraph

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

the class NameSimilarityEdgeFilterTest method curvedWayGeometry_issue2319.

@Test
public void curvedWayGeometry_issue2319() {
    // 0 - 1
    // |   |
    // |   |
    // -----
    // 
    // 2 -- 3
    FlagEncoder encoder = FlagEncoders.createCar(new PMap().putObject("speed_two_directions", true));
    EncodingManager em = EncodingManager.create(encoder);
    BaseGraph graph = new BaseGraph.Builder(em).create();
    PointList pointList = new PointList(20, false);
    pointList.add(43.844377, -79.264005);
    pointList.add(43.843771, -79.263824);
    pointList.add(43.843743, -79.2638);
    pointList.add(43.843725, -79.26375);
    pointList.add(43.843724, -79.263676);
    pointList.add(43.843801, -79.263412);
    pointList.add(43.843866, -79.263);
    pointList.add(43.843873, -79.262838);
    pointList.add(43.843863, -79.262801);
    pointList.add(43.843781, -79.262729);
    pointList.add(43.842408, -79.262395);
    pointList.add(43.842363, -79.262397);
    pointList.add(43.842336, -79.262422);
    pointList.add(43.842168, -79.263186);
    pointList.add(43.842152, -79.263348);
    pointList.add(43.842225, -79.263421);
    pointList.add(43.842379, -79.263441);
    pointList.add(43.842668, -79.26352);
    pointList.add(43.842777, -79.263566);
    pointList.add(43.842832, -79.263627);
    pointList.add(43.842833, -79.263739);
    pointList.add(43.842807, -79.263802);
    pointList.add(43.842691, -79.264477);
    pointList.add(43.842711, -79.264588);
    graph.getNodeAccess().setNode(0, 43.844521, -79.263976);
    graph.getNodeAccess().setNode(1, 43.842775, -79.264649);
    EdgeIteratorState doubtfire = graph.edge(0, 1).setWayGeometry(pointList).set(encoder.getAccessEnc(), true, true).set(encoder.getAverageSpeedEnc(), 60, 60).setName("Doubtfire Crescent");
    EdgeIteratorState golden = graph.edge(0, 1).set(encoder.getAccessEnc(), true, true).set(encoder.getAverageSpeedEnc(), 60, 60).setName("Golden Avenue");
    graph.getNodeAccess().setNode(2, 43.841501560244744, -79.26366394602502);
    graph.getNodeAccess().setNode(3, 43.842247922172724, -79.2605663670726);
    PointList pointList2 = new PointList(1, false);
    pointList2.add(43.84191413615452, -79.261912128223);
    EdgeIteratorState denison = graph.edge(2, 3).setWayGeometry(pointList2).set(encoder.getAccessEnc(), true, true).set(encoder.getAverageSpeedEnc(), 60, 60).setName("Denison Street");
    double qlat = 43.842122;
    double qLon = -79.262162;
    // if we use a very large radius we find doubtfire
    NameSimilarityEdgeFilter filter = new NameSimilarityEdgeFilter(EdgeFilter.ALL_EDGES, "doubtfire", new GHPoint(qlat, qLon), 1_000);
    assertFalse(filter.accept(golden));
    assertFalse(filter.accept(denison));
    assertTrue(filter.accept(doubtfire));
    // but also using a smaller radius should work, because the inner way geomerty of Doubtfire Crescent comes very
    // close to the marker even though the tower nodes are rather far away
    filter = new NameSimilarityEdgeFilter(EdgeFilter.ALL_EDGES, "doubtfire", new GHPoint(qlat, qLon), 100);
    assertFalse(filter.accept(golden));
    assertFalse(filter.accept(denison));
    assertTrue(filter.accept(doubtfire));
}
Also used : BaseGraph(com.graphhopper.storage.BaseGraph) GHPoint(com.graphhopper.util.shapes.GHPoint) Test(org.junit.jupiter.api.Test)

Aggregations

BaseGraph (com.graphhopper.storage.BaseGraph)100 Test (org.junit.jupiter.api.Test)75 NodeAccess (com.graphhopper.storage.NodeAccess)37 FlagEncoder (com.graphhopper.routing.util.FlagEncoder)28 EncodingManager (com.graphhopper.routing.util.EncodingManager)26 FastestWeighting (com.graphhopper.routing.weighting.FastestWeighting)14 ShortestWeighting (com.graphhopper.routing.weighting.ShortestWeighting)14 Dijkstra (com.graphhopper.routing.Dijkstra)13 Path (com.graphhopper.routing.Path)13 GHPoint (com.graphhopper.util.shapes.GHPoint)13 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)11 ArgumentsSource (org.junit.jupiter.params.provider.ArgumentsSource)11 GHRequest (com.graphhopper.GHRequest)8 GHResponse (com.graphhopper.GHResponse)8 VirtualEdgeIteratorState (com.graphhopper.routing.querygraph.VirtualEdgeIteratorState)6 EdgeIteratorState (com.graphhopper.util.EdgeIteratorState)6 GHUtility.createMockedEdgeIteratorState (com.graphhopper.util.GHUtility.createMockedEdgeIteratorState)6 PMap (com.graphhopper.util.PMap)6 IntsRef (com.graphhopper.storage.IntsRef)4 ReaderWay (com.graphhopper.reader.ReaderWay)3