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));
}
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();
}
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);
}
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);
}
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));
}
Aggregations