Search in sources :

Example 51 with EncodingManager

use of com.graphhopper.routing.util.EncodingManager in project graphhopper by graphhopper.

the class PrepareRoutingSubnetworksTest method testPrepareSubnetworks_oneVehicle.

@Test
public void testPrepareSubnetworks_oneVehicle() {
    EncodingManager em = createEncodingManager("car");
    FlagEncoder encoder = em.getEncoder("car");
    GraphHopperStorage g = createSubnetworkTestStorage(em);
    PrepareRoutingSubnetworks instance = new PrepareRoutingSubnetworks(g, Collections.singletonList(createJob(em, encoder, NO_TURN_COST_PROVIDER)));
    // this will make the upper small network a subnetwork
    instance.setMinNetworkSize(4);
    assertEquals(3, instance.doWork());
    assertEquals(IntArrayList.from(7, 8, 9), getSubnetworkEdges(g, encoder));
    // this time we lower the threshold and the upper network won't be set to be a subnetwork
    g = createSubnetworkTestStorage(em);
    instance = new PrepareRoutingSubnetworks(g, Collections.singletonList(createJob(em, encoder, NO_TURN_COST_PROVIDER)));
    instance.setMinNetworkSize(3);
    assertEquals(0, instance.doWork());
    assertEquals(IntArrayList.from(), getSubnetworkEdges(g, encoder));
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) FlagEncoder(com.graphhopper.routing.util.FlagEncoder) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) Test(org.junit.jupiter.api.Test)

Example 52 with EncodingManager

use of com.graphhopper.routing.util.EncodingManager in project graphhopper by graphhopper.

the class PrepareRoutingSubnetworksTest method createEncodingManager.

private static EncodingManager createEncodingManager(String flagEncodersStr) {
    EncodingManager.Builder builder = new EncodingManager.Builder();
    for (String encoderStr : flagEncodersStr.split(",")) {
        encoderStr = encoderStr.trim();
        FlagEncoder encoder = new DefaultFlagEncoderFactory().createFlagEncoder(encoderStr.split("\\|")[0], new PMap(encoderStr));
        builder.add(encoder);
        builder.add(Subnetwork.create(encoder.toString()));
    }
    return builder.build();
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) DefaultFlagEncoderFactory(com.graphhopper.routing.util.DefaultFlagEncoderFactory) FlagEncoder(com.graphhopper.routing.util.FlagEncoder) GraphBuilder(com.graphhopper.storage.GraphBuilder) PMap(com.graphhopper.util.PMap)

Example 53 with EncodingManager

use of com.graphhopper.routing.util.EncodingManager in project graphhopper by graphhopper.

the class OSMMtbRatingParserTest method checkRating.

private void checkRating(int expectedRating, String scaleString) {
    OSMMtbRatingParser parser = new OSMMtbRatingParser();
    EncodingManager em = new EncodingManager.Builder().add(parser).build();
    IntEncodedValue ev = em.getIntEncodedValue(MtbRating.KEY);
    IntsRef edgeFlags = em.createEdgeFlags();
    ReaderWay way = new ReaderWay(0);
    if (scaleString != null)
        way.setTag("mtb:scale", scaleString);
    parser.handleWayTags(edgeFlags, way, em.createRelationFlags());
    assertEquals(expectedRating, ev.getInt(false, edgeFlags), "unexpected rating for mtb:scale=" + scaleString);
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) IntsRef(com.graphhopper.storage.IntsRef) ReaderWay(com.graphhopper.reader.ReaderWay) IntEncodedValue(com.graphhopper.routing.ev.IntEncodedValue)

Example 54 with EncodingManager

use of com.graphhopper.routing.util.EncodingManager in project graphhopper by graphhopper.

the class OSMRoadEnvironmentParserTest method ferry.

@Test
void ferry() {
    OSMRoadEnvironmentParser parser = new OSMRoadEnvironmentParser();
    CarFlagEncoder carEncoder = new CarFlagEncoder();
    EncodingManager em = new EncodingManager.Builder().add(carEncoder).add(parser).build();
    EnumEncodedValue<RoadEnvironment> roadEnvironmentEnc = em.getEnumEncodedValue(RoadEnvironment.KEY, RoadEnvironment.class);
    IntsRef edgeFlags = em.createEdgeFlags();
    ReaderWay way = new ReaderWay(0);
    way.setTag("route", "shuttle_train");
    parser.handleWayTags(edgeFlags, way, em.createRelationFlags());
    RoadEnvironment roadEnvironment = roadEnvironmentEnc.getEnum(false, edgeFlags);
    assertEquals(RoadEnvironment.FERRY, roadEnvironment);
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) RoadEnvironment(com.graphhopper.routing.ev.RoadEnvironment) IntsRef(com.graphhopper.storage.IntsRef) ReaderWay(com.graphhopper.reader.ReaderWay) CarFlagEncoder(com.graphhopper.routing.util.CarFlagEncoder) Test(org.junit.jupiter.api.Test)

Example 55 with EncodingManager

use of com.graphhopper.routing.util.EncodingManager in project graphhopper by graphhopper.

the class HeadingResolverTest method withQueryGraph.

@Test
public void withQueryGraph() {
    // 2
    // 0 -x- 1
    FlagEncoder encoder = new CarFlagEncoder();
    EncodingManager em = EncodingManager.create(encoder);
    GraphHopperStorage graph = new GraphBuilder(em).create();
    NodeAccess na = graph.getNodeAccess();
    na.setNode(0, 48.8611, 1.2194);
    na.setNode(1, 48.8538, 2.3950);
    EdgeIteratorState edge = GHUtility.setSpeed(60, true, true, encoder, graph.edge(0, 1).setDistance(10));
    Snap snap = createSnap(edge, 48.859, 2.00, 0);
    QueryGraph queryGraph = QueryGraph.create(graph, snap);
    HeadingResolver resolver = new HeadingResolver(queryGraph);
    // if the heading points East we get the Western edge 0->2
    assertEquals("0->2", queryGraph.getEdgeIteratorState(1, Integer.MIN_VALUE).toString());
    assertEquals(IntArrayList.from(1), resolver.getEdgesWithDifferentHeading(2, 90));
    // if the heading points West we get the Eastern edge 2->1
    assertEquals("2->1", queryGraph.getEdgeIteratorState(2, Integer.MIN_VALUE).toString());
    assertEquals(IntArrayList.from(2), resolver.getEdgesWithDifferentHeading(2, 270));
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) NodeAccess(com.graphhopper.storage.NodeAccess) CarFlagEncoder(com.graphhopper.routing.util.CarFlagEncoder) FlagEncoder(com.graphhopper.routing.util.FlagEncoder) EdgeIteratorState(com.graphhopper.util.EdgeIteratorState) GraphBuilder(com.graphhopper.storage.GraphBuilder) Snap(com.graphhopper.storage.index.Snap) CarFlagEncoder(com.graphhopper.routing.util.CarFlagEncoder) QueryGraph(com.graphhopper.routing.querygraph.QueryGraph) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) Test(org.junit.jupiter.api.Test)

Aggregations

EncodingManager (com.graphhopper.routing.util.EncodingManager)60 CarFlagEncoder (com.graphhopper.routing.util.CarFlagEncoder)21 FlagEncoder (com.graphhopper.routing.util.FlagEncoder)19 GraphHopperOSM (com.graphhopper.reader.osm.GraphHopperOSM)18 Test (org.junit.jupiter.api.Test)18 GraphBuilder (com.graphhopper.storage.GraphBuilder)17 GraphHopperStorage (com.graphhopper.storage.GraphHopperStorage)15 Test (org.junit.Test)10 ReaderWay (com.graphhopper.reader.ReaderWay)9 FastestWeighting (com.graphhopper.routing.weighting.FastestWeighting)9 Graph (com.graphhopper.storage.Graph)6 EdgeIteratorState (com.graphhopper.util.EdgeIteratorState)6 ShortestWeighting (com.graphhopper.routing.weighting.ShortestWeighting)5 IntsRef (com.graphhopper.storage.IntsRef)5 GraphHopper (com.graphhopper.GraphHopper)4 RAMDirectory (com.graphhopper.storage.RAMDirectory)4 GHPoint (com.graphhopper.util.shapes.GHPoint)4 SRTMProvider (com.graphhopper.reader.dem.SRTMProvider)3 DataFlagEncoder (com.graphhopper.routing.util.DataFlagEncoder)3 Weighting (com.graphhopper.routing.weighting.Weighting)3