Search in sources :

Example 11 with CustomModel

use of com.graphhopper.util.CustomModel in project graphhopper by graphhopper.

the class CustomModelParserTest method multipleAreas.

@Test
public void multipleAreas() {
    CustomModel customModel = new CustomModel();
    Map<String, JsonFeature> areas = new HashMap<>();
    Coordinate[] area_1_coordinates = new Coordinate[] { new Coordinate(48.019324184801185, 11.28021240234375), new Coordinate(48.019324184801185, 11.53564453125), new Coordinate(48.11843396091691, 11.53564453125), new Coordinate(48.11843396091691, 11.28021240234375), new Coordinate(48.019324184801185, 11.28021240234375) };
    Coordinate[] area_2_coordinates = new Coordinate[] { new Coordinate(48.15509285476017, 11.53289794921875), new Coordinate(48.15509285476017, 11.8212890625), new Coordinate(48.281365151571755, 11.8212890625), new Coordinate(48.281365151571755, 11.53289794921875), new Coordinate(48.15509285476017, 11.53289794921875) };
    areas.put("area_1", new JsonFeature("area_1", "Feature", null, new GeometryFactory().createPolygon(area_1_coordinates), new HashMap<>()));
    areas.put("area_2", new JsonFeature("area_2", "Feature", null, new GeometryFactory().createPolygon(area_2_coordinates), new HashMap<>()));
    customModel.setAreas(areas);
    customModel.addToSpeed(If("in_area_1", LIMIT, 100));
    customModel.addToSpeed(If("!in_area_2", LIMIT, 25));
    customModel.addToSpeed(Else(LIMIT, 15));
    // No exception is thrown during createWeightingParameters
    assertAll(() -> CustomModelParser.createWeightingParameters(customModel, encodingManager, avgSpeedEnc, encoder.getMaxSpeed(), null));
    CustomModel customModel2 = new CustomModel();
    customModel2.setAreas(areas);
    customModel2.addToSpeed(If("in_area_1", LIMIT, 100));
    customModel2.addToSpeed(If("in_area_2", LIMIT, 25));
    customModel2.addToSpeed(If("in_area_3", LIMIT, 150));
    customModel2.addToSpeed(Else(LIMIT, 15));
    assertThrows(IllegalArgumentException.class, () -> CustomModelParser.createWeightingParameters(customModel2, encodingManager, avgSpeedEnc, encoder.getMaxSpeed(), null));
}
Also used : GeometryFactory(org.locationtech.jts.geom.GeometryFactory) HashMap(java.util.HashMap) Coordinate(org.locationtech.jts.geom.Coordinate) CustomModel(com.graphhopper.util.CustomModel) JsonFeature(com.graphhopper.util.JsonFeature) Test(org.junit.jupiter.api.Test)

Example 12 with CustomModel

use of com.graphhopper.util.CustomModel in project graphhopper by graphhopper.

the class RouteResourceCustomModelLMTest method createConfig.

private static GraphHopperServerConfiguration createConfig() {
    GraphHopperServerConfiguration config = new GraphHopperServerTestConfiguration();
    config.getGraphHopperConfiguration().putObject("graph.flag_encoders", "car,foot").putObject("datareader.file", "../core/files/andorra.osm.pbf").putObject("graph.location", DIR).putObject("graph.encoded_values", "surface").setProfiles(Arrays.asList(// give strange profile names to ensure that we do not mix vehicle and profile:
    new CustomProfile("car_custom").setCustomModel(new CustomModel()).setVehicle("car"), new Profile("foot_profile").setVehicle("foot").setWeighting("fastest"), new CustomProfile("foot_custom").setCustomModel(new CustomModel()).setVehicle("foot"))).setLMProfiles(Arrays.asList(new LMProfile("car_custom"), new LMProfile("foot_custom")));
    return config;
}
Also used : GraphHopperServerConfiguration(com.graphhopper.application.GraphHopperServerConfiguration) GraphHopperServerTestConfiguration(com.graphhopper.application.util.GraphHopperServerTestConfiguration) CustomProfile(com.graphhopper.routing.weighting.custom.CustomProfile) LMProfile(com.graphhopper.config.LMProfile) CustomModel(com.graphhopper.util.CustomModel) CustomProfile(com.graphhopper.routing.weighting.custom.CustomProfile) Profile(com.graphhopper.config.Profile) LMProfile(com.graphhopper.config.LMProfile)

Aggregations

CustomModel (com.graphhopper.util.CustomModel)12 Test (org.junit.jupiter.api.Test)8 EdgeIteratorState (com.graphhopper.util.EdgeIteratorState)5 CustomProfile (com.graphhopper.routing.weighting.custom.CustomProfile)4 Profile (com.graphhopper.config.Profile)3 GraphHopperServerConfiguration (com.graphhopper.application.GraphHopperServerConfiguration)2 GraphHopperServerTestConfiguration (com.graphhopper.application.util.GraphHopperServerTestConfiguration)2 CustomWeighting (com.graphhopper.routing.weighting.custom.CustomWeighting)2 GraphBuilder (com.graphhopper.storage.GraphBuilder)2 GraphHopperStorage (com.graphhopper.storage.GraphHopperStorage)2 PMap (com.graphhopper.util.PMap)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 YAMLFactory (com.fasterxml.jackson.dataformat.yaml.YAMLFactory)1 CHProfile (com.graphhopper.config.CHProfile)1 LMProfile (com.graphhopper.config.LMProfile)1 FlagEncoder (com.graphhopper.routing.util.FlagEncoder)1 PriorityWeighting (com.graphhopper.routing.weighting.PriorityWeighting)1 NodeAccess (com.graphhopper.storage.NodeAccess)1 JsonFeature (com.graphhopper.util.JsonFeature)1 File (java.io.File)1