Search in sources :

Example 66 with EdgeIteratorState

use of com.graphhopper.util.EdgeIteratorState 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");
    GraphHopperStorage 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) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) Test(org.junit.jupiter.api.Test)

Example 67 with EdgeIteratorState

use of com.graphhopper.util.EdgeIteratorState in project graphhopper by graphhopper.

the class MotorcycleFlagEncoderTest method testCurvature.

@Test
public void testCurvature() {
    Graph graph = initExampleGraph();
    EdgeIteratorState edge = GHUtility.getEdge(graph, 0, 1);
    double bendinessOfStraightWay = getBendiness(edge, 100.0);
    double bendinessOfCurvyWay = getBendiness(edge, 10.0);
    assertTrue(bendinessOfCurvyWay < bendinessOfStraightWay, "The bendiness of the straight road is smaller than the one of the curvy road");
}
Also used : EdgeIteratorState(com.graphhopper.util.EdgeIteratorState) Test(org.junit.jupiter.api.Test)

Example 68 with EdgeIteratorState

use of com.graphhopper.util.EdgeIteratorState in project graphhopper by graphhopper.

the class RoutingCHGraphImplTest method testGetWeight.

@Test
public void testGetWeight() {
    CarFlagEncoder encoder = new CarFlagEncoder();
    EncodingManager em = EncodingManager.create(encoder);
    GraphHopperStorage graph = new GraphBuilder(em).create();
    EdgeIteratorState edge1 = graph.edge(0, 1);
    EdgeIteratorState edge2 = graph.edge(1, 2);
    graph.freeze();
    CHConfig chConfig = CHConfig.nodeBased("ch", new FastestWeighting(encoder));
    CHStorage store = graph.createCHStorage(chConfig);
    RoutingCHGraph g = graph.createCHGraph(store, chConfig);
    assertFalse(g.getEdgeIteratorState(edge1.getEdge(), Integer.MIN_VALUE).isShortcut());
    assertFalse(g.getEdgeIteratorState(edge2.getEdge(), Integer.MIN_VALUE).isShortcut());
    CHStorageBuilder chBuilder = new CHStorageBuilder(store);
    chBuilder.setIdentityLevels();
    // only remove edges
    int flags = PrepareEncoder.getScDirMask();
    chBuilder.addShortcutNodeBased(0, 1, flags, 5, NO_EDGE, NO_EDGE);
    RoutingCHEdgeIteratorState sc1 = g.getEdgeIteratorState(2, 1);
    assertEquals(0, sc1.getBaseNode());
    assertEquals(1, sc1.getAdjNode());
    assertEquals(5, sc1.getWeight(false), 1e-3);
    assertTrue(sc1.isShortcut());
}
Also used : EdgeIteratorState(com.graphhopper.util.EdgeIteratorState) FastestWeighting(com.graphhopper.routing.weighting.FastestWeighting) Test(org.junit.jupiter.api.Test)

Example 69 with EdgeIteratorState

use of com.graphhopper.util.EdgeIteratorState in project graphhopper by graphhopper.

the class RoutingCHGraphImplTest method testAddShortcutSkippedEdgesWriteRead.

@Test
public void testAddShortcutSkippedEdgesWriteRead() {
    CarFlagEncoder carEncoder = new CarFlagEncoder();
    EncodingManager em = EncodingManager.create(carEncoder);
    GraphHopperStorage graph = new GraphBuilder(em).create();
    final EdgeIteratorState edge1 = GHUtility.setSpeed(60, true, true, carEncoder, graph.edge(1, 3).setDistance(10));
    final EdgeIteratorState edge2 = GHUtility.setSpeed(60, true, true, carEncoder, graph.edge(3, 4).setDistance(10));
    graph.freeze();
    FastestWeighting weighting = new FastestWeighting(carEncoder);
    CHConfig chConfig = CHConfig.nodeBased("p1", weighting);
    CHStorage chStore = graph.createCHStorage(chConfig);
    CHStorageBuilder chBuilder = new CHStorageBuilder(chStore);
    chBuilder.setIdentityLevels();
    chBuilder.addShortcutNodeBased(1, 4, PrepareEncoder.getScDirMask(), 10, NO_EDGE, NO_EDGE);
    chStore.setSkippedEdges(chStore.toShortcutPointer(0), edge1.getEdge(), edge2.getEdge());
    assertEquals(edge1.getEdge(), chStore.getSkippedEdge1(chStore.toShortcutPointer(0)));
    assertEquals(edge2.getEdge(), chStore.getSkippedEdge2(chStore.toShortcutPointer(0)));
}
Also used : EdgeIteratorState(com.graphhopper.util.EdgeIteratorState) FastestWeighting(com.graphhopper.routing.weighting.FastestWeighting) Test(org.junit.jupiter.api.Test)

Example 70 with EdgeIteratorState

use of com.graphhopper.util.EdgeIteratorState in project graphhopper by graphhopper.

the class OSMRoadAccessParserTest method countryRule.

@Test
void countryRule() {
    EncodingManager em = EncodingManager.create("car");
    EnumEncodedValue<RoadAccess> roadAccessEnc = em.getEnumEncodedValue(RoadAccess.KEY, RoadAccess.class);
    Graph graph = new GraphBuilder(em).create();
    FlagEncoder encoder = em.getEncoder("car");
    EdgeIteratorState e1 = GHUtility.setSpeed(60, true, true, encoder, graph.edge(0, 1).setDistance(100));
    EdgeIteratorState e2 = GHUtility.setSpeed(60, true, true, encoder, graph.edge(1, 2).setDistance(100));
    OSMRoadAccessParser parser = new OSMRoadAccessParser(roadAccessEnc, OSMRoadAccessParser.toOSMRestrictions(TransportationMode.CAR));
    IntsRef relFlags = em.createRelationFlags();
    ReaderWay way = new ReaderWay(27L);
    way.setTag("highway", "track");
    way.setTag("country_rule", new CountryRule() {

        @Override
        public RoadAccess getAccess(ReaderWay readerWay, TransportationMode transportationMode, RoadAccess currentRoadAccess) {
            return RoadAccess.DESTINATION;
        }
    });
    parser.handleWayTags(e1.getFlags(), way, relFlags);
    assertEquals(RoadAccess.DESTINATION, e1.get(roadAccessEnc));
    // if there is no country rule we get the default value
    way.removeTag("country_rule");
    parser.handleWayTags(e2.getFlags(), way, relFlags);
    assertEquals(RoadAccess.YES, e2.get(roadAccessEnc));
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) RoadAccess(com.graphhopper.routing.ev.RoadAccess) TransportationMode(com.graphhopper.routing.util.TransportationMode) FlagEncoder(com.graphhopper.routing.util.FlagEncoder) ReaderWay(com.graphhopper.reader.ReaderWay) Graph(com.graphhopper.storage.Graph) CountryRule(com.graphhopper.routing.util.countryrules.CountryRule) EdgeIteratorState(com.graphhopper.util.EdgeIteratorState) GraphBuilder(com.graphhopper.storage.GraphBuilder) IntsRef(com.graphhopper.storage.IntsRef) Test(org.junit.jupiter.api.Test)

Aggregations

EdgeIteratorState (com.graphhopper.util.EdgeIteratorState)137 Test (org.junit.jupiter.api.Test)55 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)25 Test (org.junit.Test)22 RepeatedTest (org.junit.jupiter.api.RepeatedTest)17 FlagEncoder (com.graphhopper.routing.util.FlagEncoder)13 Snap (com.graphhopper.storage.index.Snap)12 GraphHopperStorage (com.graphhopper.storage.GraphHopperStorage)11 CHEdgeIteratorState (com.graphhopper.util.CHEdgeIteratorState)11 QueryGraph (com.graphhopper.routing.querygraph.QueryGraph)10 FastestWeighting (com.graphhopper.routing.weighting.FastestWeighting)10 NodeAccess (com.graphhopper.storage.NodeAccess)10 GHIntHashSet (com.graphhopper.coll.GHIntHashSet)9 GraphBuilder (com.graphhopper.storage.GraphBuilder)8 QueryRoutingCHGraph (com.graphhopper.routing.querygraph.QueryRoutingCHGraph)7 DecimalEncodedValue (com.graphhopper.routing.ev.DecimalEncodedValue)6 EncodingManager (com.graphhopper.routing.util.EncodingManager)6 GHPoint (com.graphhopper.util.shapes.GHPoint)6 Fun (org.mapdb.Fun)6 IntArrayList (com.carrotsearch.hppc.IntArrayList)5