use of com.graphhopper.util.CustomModel in project graphhopper by graphhopper.
the class CustomModelParserTest method testSpeedFactorAndPriorityAndMaxSpeed.
@Test
public void testSpeedFactorAndPriorityAndMaxSpeed() {
EdgeIteratorState primary = graph.edge(0, 1).setDistance(10).set(roadClassEnc, PRIMARY).set(avgSpeedEnc, 80).set(encoder.getAccessEnc(), true, true);
EdgeIteratorState secondary = graph.edge(1, 2).setDistance(10).set(roadClassEnc, SECONDARY).set(avgSpeedEnc, 70).set(encoder.getAccessEnc(), true, true);
CustomModel customModel = new CustomModel();
customModel.addToPriority(If("road_class == PRIMARY", MULTIPLY, 0.9));
customModel.addToSpeed(If("road_class == PRIMARY", MULTIPLY, 0.8));
CustomWeighting.Parameters parameters = CustomModelParser.createWeightingParameters(customModel, encodingManager, avgSpeedEnc, encoder.getMaxSpeed(), null);
assertEquals(0.9, parameters.getEdgeToPriorityMapping().get(primary, false), 0.01);
assertEquals(64, parameters.getEdgeToSpeedMapping().get(primary, false), 0.01);
assertEquals(1, parameters.getEdgeToPriorityMapping().get(secondary, false), 0.01);
assertEquals(70, parameters.getEdgeToSpeedMapping().get(secondary, false), 0.01);
customModel.addToSpeed(If("road_class != PRIMARY", LIMIT, 50));
CustomWeighting.EdgeToDoubleMapping speedMapping = CustomModelParser.createWeightingParameters(customModel, encodingManager, avgSpeedEnc, encoder.getMaxSpeed(), null).getEdgeToSpeedMapping();
assertEquals(64, speedMapping.get(primary, false), 0.01);
assertEquals(50, speedMapping.get(secondary, false), 0.01);
}
use of com.graphhopper.util.CustomModel in project graphhopper by graphhopper.
the class CustomModelParserTest method testIllegalOrder.
@Test
void testIllegalOrder() {
CustomModel customModel = new CustomModel();
customModel.addToPriority(Else(MULTIPLY, 0.9));
customModel.addToPriority(If("road_environment != FERRY", MULTIPLY, 0.8));
assertThrows(IllegalArgumentException.class, () -> CustomModelParser.createWeightingParameters(customModel, encodingManager, avgSpeedEnc, encoder.getMaxSpeed(), null));
CustomModel customModel2 = new CustomModel();
customModel2.addToPriority(ElseIf("road_environment != FERRY", MULTIPLY, 0.9));
customModel2.addToPriority(If("road_class != PRIMARY", MULTIPLY, 0.8));
assertThrows(IllegalArgumentException.class, () -> CustomModelParser.createWeightingParameters(customModel2, encodingManager, avgSpeedEnc, encoder.getMaxSpeed(), null));
}
use of com.graphhopper.util.CustomModel in project graphhopper by graphhopper.
the class CustomModelParserTest method testPriority.
@Test
void testPriority() {
EdgeIteratorState primary = graph.edge(0, 1).setDistance(10).set(roadClassEnc, PRIMARY).set(avgSpeedEnc, 80).set(encoder.getAccessEnc(), true, true);
EdgeIteratorState secondary = graph.edge(1, 2).setDistance(10).set(roadClassEnc, SECONDARY).set(avgSpeedEnc, 70).set(encoder.getAccessEnc(), true, true);
EdgeIteratorState tertiary = graph.edge(1, 2).setDistance(10).set(roadClassEnc, TERTIARY).set(avgSpeedEnc, 70).set(encoder.getAccessEnc(), true, true);
CustomModel customModel = new CustomModel();
customModel.addToPriority(If("road_class == PRIMARY", MULTIPLY, 0.5));
customModel.addToPriority(ElseIf("road_class == SECONDARY", MULTIPLY, 0.7));
customModel.addToPriority(Else(MULTIPLY, 0.9));
customModel.addToPriority(If("road_environment != FERRY", MULTIPLY, 0.8));
CustomWeighting.EdgeToDoubleMapping priorityMapping = CustomModelParser.createWeightingParameters(customModel, encodingManager, avgSpeedEnc, encoder.getMaxSpeed(), null).getEdgeToPriorityMapping();
assertEquals(0.5 * 0.8, priorityMapping.get(primary, false), 0.01);
assertEquals(0.7 * 0.8, priorityMapping.get(secondary, false), 0.01);
assertEquals(0.9 * 0.8, priorityMapping.get(tertiary, false), 0.01);
// force integer value
customModel = new CustomModel();
customModel.addToPriority(If("road_class == PRIMARY", MULTIPLY, 1));
customModel.addToPriority(If("road_class == SECONDARY", MULTIPLY, 0.9));
priorityMapping = CustomModelParser.createWeightingParameters(customModel, encodingManager, avgSpeedEnc, encoder.getMaxSpeed(), null).getEdgeToPriorityMapping();
assertEquals(1, priorityMapping.get(primary, false), 0.01);
assertEquals(0.9, priorityMapping.get(secondary, false), 0.01);
}
use of com.graphhopper.util.CustomModel in project graphhopper by graphhopper.
the class CustomModelParserTest method testString.
@Test
public void testString() {
EdgeIteratorState deu = graph.edge(0, 1).setDistance(10).set(countryEnc, "DEU").set(avgSpeedEnc, 80).set(encoder.getAccessEnc(), true, true);
EdgeIteratorState blup = graph.edge(1, 2).setDistance(10).set(countryEnc, "blup").set(avgSpeedEnc, 70).set(encoder.getAccessEnc(), true, true);
CustomModel customModel = new CustomModel();
customModel.addToPriority(If("country == \"DEU\"", MULTIPLY, 0.9));
customModel.addToPriority(ElseIf("country == \"blup\"", MULTIPLY, 0.7));
customModel.addToPriority(Else(MULTIPLY, 0.5));
CustomWeighting.EdgeToDoubleMapping priorityMapping = CustomModelParser.createWeightingParameters(customModel, encodingManager, avgSpeedEnc, encoder.getMaxSpeed(), null).getEdgeToPriorityMapping();
assertEquals(0.9, priorityMapping.get(deu, false), 0.01);
assertEquals(0.7, priorityMapping.get(blup, false), 0.01);
}
use of com.graphhopper.util.CustomModel in project graphhopper by graphhopper.
the class CustomModelParserTest method testBrackets.
@Test
public void testBrackets() {
EdgeIteratorState primary = graph.edge(0, 1).setDistance(10).set(encoder.getAccessEnc(), true, true).set(roadClassEnc, PRIMARY).set(avgSpeedEnc, 80);
EdgeIteratorState secondary = graph.edge(0, 1).setDistance(10).set(encoder.getAccessEnc(), true, true).set(roadClassEnc, SECONDARY).set(avgSpeedEnc, 40);
CustomModel customModel = new CustomModel();
customModel.addToPriority(If("(road_class == PRIMARY || car$access == true) && car$average_speed > 50", MULTIPLY, 0.9));
CustomWeighting.Parameters parameters = CustomModelParser.createWeightingParameters(customModel, encodingManager, avgSpeedEnc, encoder.getMaxSpeed(), null);
assertEquals(0.9, parameters.getEdgeToPriorityMapping().get(primary, false), 0.01);
assertEquals(1, parameters.getEdgeToPriorityMapping().get(secondary, false), 0.01);
}
Aggregations