use of com.graphhopper.util.EdgeIteratorState in project graphhopper by graphhopper.
the class PrepareRoutingSubnetworksTest method testPrepareSubnetwork_withTurnCosts.
@Test
public void testPrepareSubnetwork_withTurnCosts() {
EncodingManager em = createEncodingManager("car|turn_costs=true");
FlagEncoder encoder = em.fetchEdgeEncoders().iterator().next();
// since the middle edge is blocked the upper component is a subnetwork (regardless of turn costs)
GraphHopperStorage g = createSubnetworkTestStorage(em);
PrepareRoutingSubnetworks instance = new PrepareRoutingSubnetworks(g, Collections.singletonList(createJob(em, encoder, new DefaultTurnCostProvider(encoder, g.getTurnCostStorage(), 0))));
instance.setMinNetworkSize(4);
assertEquals(3, instance.doWork());
assertEquals(IntArrayList.from(7, 8, 9), getSubnetworkEdges(g, encoder));
// if we open the edge it won't be a subnetwork anymore
g = createSubnetworkTestStorage(em);
EdgeIteratorState edge = GHUtility.getEdge(g, 3, 4);
GHUtility.setSpeed(10, true, true, encoder, edge);
instance = new PrepareRoutingSubnetworks(g, Collections.singletonList(createJob(em, encoder, new DefaultTurnCostProvider(encoder, g.getTurnCostStorage(), 0))));
instance.setMinNetworkSize(4);
assertEquals(0, instance.doWork());
assertEquals(IntArrayList.from(), getSubnetworkEdges(g, encoder));
// ... and now for something interesting: if we open the edge *and* apply turn restrictions it will be a
// subnetwork again
g = createSubnetworkTestStorage(em);
edge = GHUtility.getEdge(g, 3, 4);
GHUtility.setSpeed(10, true, true, encoder, edge);
DecimalEncodedValue turnCostEnc = em.getDecimalEncodedValue(TurnCost.key(encoder.toString()));
g.getTurnCostStorage().set(turnCostEnc, 0, 4, 7, 1);
g.getTurnCostStorage().set(turnCostEnc, 0, 4, 9, 1);
instance = new PrepareRoutingSubnetworks(g, Collections.singletonList(createJob(em, encoder, new DefaultTurnCostProvider(encoder, g.getTurnCostStorage(), 0))));
instance.setMinNetworkSize(4);
assertEquals(3, instance.doWork());
assertEquals(IntArrayList.from(7, 8, 9), getSubnetworkEdges(g, encoder));
}
use of com.graphhopper.util.EdgeIteratorState in project graphhopper by graphhopper.
the class HeadingEdgeFilterTest method getHeading.
@Test
public void getHeading() {
GHPoint point = new GHPoint(55.67093, 12.577294);
CarFlagEncoder carEncoder = new CarFlagEncoder();
EncodingManager encodingManager = new EncodingManager.Builder().add(carEncoder).build();
GraphHopperStorage g = new GraphBuilder(encodingManager).create();
EdgeIteratorState edge = g.edge(0, 1);
g.getNodeAccess().setNode(0, 55.671044, 12.5771583);
g.getNodeAccess().setNode(1, 55.6704136, 12.5784324);
// GHUtility.setSpeed(50, 0, carEncoder, edge.getFlags());
assertEquals(131.2, HeadingEdgeFilter.getHeadingOfGeometryNearPoint(edge, point, 20), .1);
}
use of com.graphhopper.util.EdgeIteratorState in project graphhopper by graphhopper.
the class BlockAreaWeightingTest method testBlockedById.
@Test
public void testBlockedById() {
GraphEdgeIdFinder.BlockArea bArea = new GraphEdgeIdFinder.BlockArea(graph);
EdgeIteratorState edge = graph.getEdgeIteratorState(0, 1);
BlockAreaWeighting instance = new BlockAreaWeighting(new FastestWeighting(encoder), bArea);
assertEquals(94.35, instance.calcEdgeWeight(edge, false), .01);
GHIntHashSet set = new GHIntHashSet();
set.add(0);
bArea.add(null, set);
instance = new BlockAreaWeighting(new FastestWeighting(encoder), bArea);
assertEquals(Double.POSITIVE_INFINITY, instance.calcEdgeWeight(edge, false), .01);
}
use of com.graphhopper.util.EdgeIteratorState in project graphhopper by graphhopper.
the class AlternativeRouteEdgeCH method sharedDistanceWithShortest.
private double sharedDistanceWithShortest(Path path) {
double sharedDistance = 0.0;
List<EdgeIteratorState> edges = path.calcEdges();
for (EdgeIteratorState edge : edges) {
if (alternatives.get(0).nodes.contains(edge.getBaseNode()) && alternatives.get(0).nodes.contains(edge.getAdjNode())) {
sharedDistance += edge.getDistance();
}
}
return sharedDistance;
}
use of com.graphhopper.util.EdgeIteratorState in project graphhopper by graphhopper.
the class AlternativeRouteEdgeCH method sharedDistance.
private double sharedDistance(Path path) {
double sharedDistance = 0.0;
List<EdgeIteratorState> edges = path.calcEdges();
for (EdgeIteratorState edge : edges) {
if (nodesInCurrentAlternativeSetContains(edge.getBaseNode()) && nodesInCurrentAlternativeSetContains(edge.getAdjNode())) {
sharedDistance += edge.getDistance();
}
}
return sharedDistance;
}
Aggregations