use of com.graphhopper.util.EdgeIteratorState in project graphhopper by graphhopper.
the class BlockAreaWeightingTest method testBlockedByShape.
@Test
public void testBlockedByShape() {
EdgeIteratorState edge = graph.getEdgeIteratorState(0, 1);
GraphEdgeIdFinder.BlockArea bArea = new GraphEdgeIdFinder.BlockArea(graph);
BlockAreaWeighting instance = new BlockAreaWeighting(new FastestWeighting(encoder), bArea);
assertEquals(94.35, instance.calcEdgeWeight(edge, false), 0.01);
bArea.add(new Circle(0.01, 0.01, 100));
assertEquals(Double.POSITIVE_INFINITY, instance.calcEdgeWeight(edge, false), .01);
bArea = new GraphEdgeIdFinder.BlockArea(graph);
instance = new BlockAreaWeighting(new FastestWeighting(encoder), bArea);
// Do not match 1,1 of edge
bArea.add(new Circle(0.1, 0.1, 100));
assertEquals(94.35, instance.calcEdgeWeight(edge, false), .01);
}
use of com.graphhopper.util.EdgeIteratorState in project graphhopper by graphhopper.
the class ShortFastestWeightingTest method testShort.
@Test
public void testShort() {
EdgeIteratorState edge = createMockedEdgeIteratorState(10, GHUtility.setSpeed(50, 0, encoder, encodingManager.createEdgeFlags()));
Weighting instance = new ShortFastestWeighting(encoder, 0.03);
assertEquals(1.02, instance.calcEdgeWeight(edge, false), 1e-8);
// more influence from distance
instance = new ShortFastestWeighting(encoder, 0.1);
assertEquals(1.72, instance.calcEdgeWeight(edge, false), 1e-8);
}
use of com.graphhopper.util.EdgeIteratorState in project graphhopper by graphhopper.
the class CustomModelParserTest method setPriorityForRoadClass.
@Test
void setPriorityForRoadClass() {
CustomModel customModel = new CustomModel();
customModel.addToPriority(If("road_class == PRIMARY", MULTIPLY, 0.5));
CustomWeighting.EdgeToDoubleMapping priorityMapping = CustomModelParser.createWeightingParameters(customModel, encodingManager, avgSpeedEnc, encoder.getMaxSpeed(), null).getEdgeToPriorityMapping();
GraphHopperStorage graph = new GraphBuilder(encodingManager).create();
EdgeIteratorState edge1 = graph.edge(0, 1).setDistance(100).set(roadClassEnc, RoadClass.PRIMARY);
EdgeIteratorState edge2 = graph.edge(1, 2).setDistance(100).set(roadClassEnc, RoadClass.SECONDARY);
assertEquals(0.5, priorityMapping.get(edge1, false), 1.e-6);
assertEquals(1.0, priorityMapping.get(edge2, false), 1.e-6);
}
use of com.graphhopper.util.EdgeIteratorState in project graphhopper by graphhopper.
the class OSMMaxSpeedParserTest method countryRule.
@Test
void countryRule() {
EncodingManager em = EncodingManager.create("car");
DecimalEncodedValue maxSpeedEnc = em.getDecimalEncodedValue(MaxSpeed.KEY);
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));
OSMMaxSpeedParser parser = new OSMMaxSpeedParser(maxSpeedEnc);
IntsRef relFlags = em.createRelationFlags();
ReaderWay way = new ReaderWay(29L);
way.setTag("highway", "living_street");
way.setTag("country_rule", new CountryRule() {
@Override
public double getMaxSpeed(ReaderWay readerWay, TransportationMode transportationMode, double currentMaxSpeed) {
return 5;
}
});
parser.handleWayTags(e1.getFlags(), way, relFlags);
assertEquals(5, e1.get(maxSpeedEnc), .1);
// without a country_rule we get the default value
way.removeTag("country_rule");
parser.handleWayTags(e2.getFlags(), way, relFlags);
assertEquals(MaxSpeed.UNSET_SPEED, e2.get(maxSpeedEnc), .1);
}
use of com.graphhopper.util.EdgeIteratorState in project graphhopper by graphhopper.
the class PrepareRoutingSubnetworksTest method testRemoveNode.
@Test
public void testRemoveNode() {
FlagEncoder carEncoder = new CarFlagEncoder();
BikeFlagEncoder bikeEncoder = new BikeFlagEncoder();
EncodingManager em2 = new EncodingManager(carEncoder, bikeEncoder);
GraphHopperStorage g = createSubnetworkTestStorage2(em2);
PrepareRoutingSubnetworks instance = new PrepareRoutingSubnetworks(g, em2.fetchEdgeEncoders());
EdgeExplorer edgeExplorer = g.createEdgeExplorer();
assertFalse(instance.detectNodeRemovedForAllEncoders(edgeExplorer, 4));
assertFalse(instance.detectNodeRemovedForAllEncoders(edgeExplorer, 5));
assertFalse(instance.detectNodeRemovedForAllEncoders(edgeExplorer, 6));
// mark certain edges inaccessible for all encoders
for (EdgeIteratorState edge : Arrays.asList(GHUtility.getEdge(g, 5, 6), GHUtility.getEdge(g, 4, 5), GHUtility.getEdge(g, 4, 6))) {
for (FlagEncoder encoders : em2.fetchEdgeEncoders()) {
edge.setFlags(encoders.setAccess(0, false, false));
}
}
assertTrue(instance.detectNodeRemovedForAllEncoders(edgeExplorer, 4));
assertTrue(instance.detectNodeRemovedForAllEncoders(edgeExplorer, 5));
assertTrue(instance.detectNodeRemovedForAllEncoders(edgeExplorer, 6));
}
Aggregations