Search in sources :

Example 1 with CountryRuleFactory

use of com.graphhopper.routing.util.countryrules.CountryRuleFactory in project graphhopper by graphhopper.

the class OSMReaderTest method testCurvedWayAlongBorder.

@Test
public void testCurvedWayAlongBorder() throws IOException {
    // see https://discuss.graphhopper.com/t/country-of-way-is-wrong-on-road-near-border-with-curvature/6908/2
    EncodingManager em = EncodingManager.start().add(new CarFlagEncoder()).add(new CountryParser()).build();
    EnumEncodedValue<Country> countryEnc = em.getEnumEncodedValue(Country.KEY, Country.class);
    GraphHopperStorage graph = new GraphBuilder(em).build();
    OSMReader reader = new OSMReader(graph, new OSMReaderConfig());
    reader.setCountryRuleFactory(new CountryRuleFactory());
    reader.setAreaIndex(createCountryIndex());
    reader.setFile(new File(getClass().getResource("test-osm12.xml").getFile()));
    reader.readGraph();
    assertEquals(1, graph.getEdges());
    AllEdgesIterator iter = graph.getAllEdges();
    iter.next();
    assertEquals(Country.BGR, iter.get(countryEnc));
}
Also used : CountryParser(com.graphhopper.routing.util.parsers.CountryParser) OSMReaderConfig(com.graphhopper.routing.OSMReaderConfig) CountryRuleFactory(com.graphhopper.routing.util.countryrules.CountryRuleFactory) File(java.io.File) Test(org.junit.jupiter.api.Test) GraphHopperTest(com.graphhopper.GraphHopperTest)

Example 2 with CountryRuleFactory

use of com.graphhopper.routing.util.countryrules.CountryRuleFactory in project graphhopper by graphhopper.

the class CHImportTest method main.

public static void main(String[] args) {
    System.out.println("running for args: " + Arrays.toString(args));
    PMap map = PMap.read(args);
    String vehicle = map.getString("vehicle", "car");
    GraphHopperConfig config = new GraphHopperConfig(map);
    config.putObject("datareader.file", map.getString("pbf", "map-matching/files/leipzig_germany.osm.pbf"));
    config.putObject("graph.location", map.getString("gh", "ch-import-test-gh"));
    config.setProfiles(Arrays.asList(new Profile(vehicle).setVehicle(vehicle).setWeighting("fastest")));
    config.setCHProfiles(Collections.singletonList(new CHProfile(vehicle)));
    config.putObject(CHParameters.PERIODIC_UPDATES, map.getInt("periodic", 0));
    config.putObject(CHParameters.LAST_LAZY_NODES_UPDATES, map.getInt("lazy", 100));
    config.putObject(CHParameters.NEIGHBOR_UPDATES, map.getInt("neighbor", 100));
    config.putObject(CHParameters.NEIGHBOR_UPDATES_MAX, map.getInt("neighbor_max", 2));
    config.putObject(CHParameters.CONTRACTED_NODES, map.getInt("contracted", 100));
    config.putObject(CHParameters.LOG_MESSAGES, map.getInt("logs", 20));
    config.putObject(CHParameters.EDGE_DIFFERENCE_WEIGHT, map.getDouble("edge_diff", 10));
    config.putObject(CHParameters.ORIGINAL_EDGE_COUNT_WEIGHT, map.getDouble("orig_edge", 1));
    config.putObject(CHParameters.MAX_POLL_FACTOR_HEURISTIC_NODE, map.getDouble("mpf_heur", 5));
    config.putObject(CHParameters.MAX_POLL_FACTOR_CONTRACTION_NODE, map.getDouble("mpf_contr", 200));
    GraphHopper hopper = new GraphHopper();
    hopper.init(config);
    if (map.getBool("use_country_rules", false))
        // note that using this requires a new import of the base graph!
        hopper.setCountryRuleFactory(new CountryRuleFactory());
    hopper.importOrLoad();
    runQueries(hopper, vehicle);
}
Also used : CHProfile(com.graphhopper.config.CHProfile) PMap(com.graphhopper.util.PMap) CountryRuleFactory(com.graphhopper.routing.util.countryrules.CountryRuleFactory) GraphHopper(com.graphhopper.GraphHopper) CHProfile(com.graphhopper.config.CHProfile) Profile(com.graphhopper.config.Profile) GraphHopperConfig(com.graphhopper.GraphHopperConfig)

Example 3 with CountryRuleFactory

use of com.graphhopper.routing.util.countryrules.CountryRuleFactory in project graphhopper by graphhopper.

the class OSMReaderTest method testCountries.

@Test
public void testCountries() throws IOException {
    EncodingManager em = EncodingManager.create("car");
    EnumEncodedValue<RoadAccess> roadAccessEnc = em.getEnumEncodedValue(RoadAccess.KEY, RoadAccess.class);
    GraphHopperStorage graph = new GraphBuilder(em).build();
    OSMReader reader = new OSMReader(graph, new OSMReaderConfig());
    reader.setCountryRuleFactory(new CountryRuleFactory());
    reader.setAreaIndex(createCountryIndex());
    // there are two edges, both with highway=track, one in Berlin, one in Paris
    reader.setFile(new File(getClass().getResource("test-osm11.xml").getFile()));
    reader.readGraph();
    EdgeIteratorState edgeBerlin = graph.getEdgeIteratorState(0, Integer.MIN_VALUE);
    EdgeIteratorState edgeParis = graph.getEdgeIteratorState(1, Integer.MIN_VALUE);
    assertEquals("berlin", edgeBerlin.getName());
    assertEquals("paris", edgeParis.getName());
    // for Berlin there is GermanyCountryRule which changes RoadAccess for Tracks
    assertEquals(RoadAccess.DESTINATION, edgeBerlin.get(roadAccessEnc));
    // for Paris there is no such rule, we just get the default RoadAccess.YES
    assertEquals(RoadAccess.YES, edgeParis.get(roadAccessEnc));
}
Also used : OSMReaderConfig(com.graphhopper.routing.OSMReaderConfig) CountryRuleFactory(com.graphhopper.routing.util.countryrules.CountryRuleFactory) File(java.io.File) Test(org.junit.jupiter.api.Test) GraphHopperTest(com.graphhopper.GraphHopperTest)

Example 4 with CountryRuleFactory

use of com.graphhopper.routing.util.countryrules.CountryRuleFactory in project graphhopper by graphhopper.

the class GraphHopperTest method germanyCountryRuleAvoidsTracks.

@Test
public void germanyCountryRuleAvoidsTracks() {
    final String profile = "profile";
    // first we try without country rules (the default)
    GraphHopper hopper = new GraphHopper().setProfiles(new Profile(profile).setVehicle("car").setWeighting("fastest")).setCountryRuleFactory(null).setGraphHopperLocation(GH_LOCATION).setOSMFile(BAYREUTH);
    hopper.importOrLoad();
    GHRequest request = new GHRequest(50.010373, 11.51792, 50.005146, 11.516633);
    request.setProfile(profile);
    GHResponse response = hopper.route(request);
    assertFalse(response.hasErrors());
    double distance = response.getBest().getDistance();
    // The route takes a shortcut through the forest
    assertEquals(1447, distance, 1);
    // this time we enable country rules
    hopper.clean();
    hopper = new GraphHopper().setProfiles(new Profile(profile).setVehicle("car").setWeighting("fastest")).setGraphHopperLocation(GH_LOCATION).setCountryRuleFactory(new CountryRuleFactory()).setOSMFile(BAYREUTH);
    hopper.importOrLoad();
    request = new GHRequest(50.010373, 11.51792, 50.005146, 11.516633);
    request.setProfile(profile);
    response = hopper.route(request);
    assertFalse(response.hasErrors());
    distance = response.getBest().getDistance();
    // since GermanyCountryRule avoids TRACK roads the route will now be much longer as it goes around the forest
    assertEquals(4186, distance, 1);
}
Also used : CountryRuleFactory(com.graphhopper.routing.util.countryrules.CountryRuleFactory) CustomProfile(com.graphhopper.routing.weighting.custom.CustomProfile) Profile(com.graphhopper.config.Profile) CHProfile(com.graphhopper.config.CHProfile) LMProfile(com.graphhopper.config.LMProfile) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

CountryRuleFactory (com.graphhopper.routing.util.countryrules.CountryRuleFactory)4 Test (org.junit.jupiter.api.Test)3 GraphHopperTest (com.graphhopper.GraphHopperTest)2 CHProfile (com.graphhopper.config.CHProfile)2 Profile (com.graphhopper.config.Profile)2 OSMReaderConfig (com.graphhopper.routing.OSMReaderConfig)2 File (java.io.File)2 GraphHopper (com.graphhopper.GraphHopper)1 GraphHopperConfig (com.graphhopper.GraphHopperConfig)1 LMProfile (com.graphhopper.config.LMProfile)1 CountryParser (com.graphhopper.routing.util.parsers.CountryParser)1 CustomProfile (com.graphhopper.routing.weighting.custom.CustomProfile)1 PMap (com.graphhopper.util.PMap)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1