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