use of com.graphhopper.GraphHopper in project graphhopper by graphhopper.
the class RoutingExampleTC method createGraphHopperInstance.
// see RoutingExample for more details
static GraphHopper createGraphHopperInstance(String ghLoc) {
GraphHopper hopper = new GraphHopper();
hopper.setOSMFile(ghLoc);
hopper.setGraphHopperLocation("target/routing-tc-graph-cache");
// by enabling turn costs for the FlagEncoder, turn restriction constraints like 'no_left_turn' will be taken
// from OSM
Profile profile = new Profile("car").setVehicle("car").setWeighting("fastest").setTurnCosts(true).putHint("u_turn_costs", 40);
hopper.setProfiles(profile);
// enable CH for our profile. since turn costs are enabled this will take more time and memory to prepare than
// without turn costs.
hopper.getCHPreparationHandler().setCHProfiles(new CHProfile(profile.getName()));
hopper.importOrLoad();
return hopper;
}
use of com.graphhopper.GraphHopper in project graphhopper by graphhopper.
the class LocationIndexExample method graphhopperLocationIndex.
public static void graphhopperLocationIndex(String relDir) {
GraphHopper hopper = new GraphHopper();
hopper.setProfiles(new Profile("car").setVehicle("car").setWeighting("fastest"));
hopper.setOSMFile(relDir + "core/files/andorra.osm.pbf");
hopper.setGraphHopperLocation("./target/locationindex-graph-cache");
hopper.importOrLoad();
LocationIndex index = hopper.getLocationIndex();
// now you can fetch the closest edge via:
Snap snap = index.findClosest(42.508552, 1.532936, EdgeFilter.ALL_EDGES);
EdgeIteratorState edge = snap.getClosestEdge();
assert edge.getName().equals("Avinguda Meritxell");
}
use of com.graphhopper.GraphHopper in project graphhopper by graphhopper.
the class RoutingExample method customizableRouting.
public static void customizableRouting(String ghLoc) {
GraphHopper hopper = new GraphHopper();
hopper.setOSMFile(ghLoc);
hopper.setGraphHopperLocation("target/routing-custom-graph-cache");
hopper.setProfiles(new CustomProfile("car_custom").setCustomModel(new CustomModel()).setVehicle("car"));
// The hybrid mode uses the "landmark algorithm" and is up to 15x faster than the flexible mode (Dijkstra).
// Still it is slower than the speed mode ("contraction hierarchies algorithm") ...
hopper.getLMPreparationHandler().setLMProfiles(new LMProfile("car_custom"));
hopper.importOrLoad();
// ... but for the hybrid mode we can customize the route calculation even at request time:
// 1. a request with default preferences
GHRequest req = new GHRequest().setProfile("car_custom").addPoint(new GHPoint(42.506472, 1.522475)).addPoint(new GHPoint(42.513108, 1.536005));
GHResponse res = hopper.route(req);
if (res.hasErrors())
throw new RuntimeException(res.getErrors().toString());
assert Math.round(res.getBest().getTime() / 1000d) == 96;
// 2. now avoid primary roads and reduce maximum speed, see docs/core/custom-models.md for an in-depth explanation
// and also the blog posts https://www.graphhopper.com/?s=customizable+routing
CustomModel model = new CustomModel();
model.addToPriority(If("road_class == PRIMARY", MULTIPLY, 0.5));
// unconditional limit to 100km/h
model.addToPriority(If("true", LIMIT, 100));
req.setCustomModel(model);
res = hopper.route(req);
if (res.hasErrors())
throw new RuntimeException(res.getErrors().toString());
assert Math.round(res.getBest().getTime() / 1000d) == 165;
}
use of com.graphhopper.GraphHopper in project graphhopper by graphhopper.
the class RoutingAlgorithmWithOSMTest method testMonacoFoot3D.
@Test
public void testMonacoFoot3D() {
// most routes have same number of points as testMonaceFoot results but longer distance due to elevation difference
List<Query> queries = createMonacoFoot();
queries.get(0).getPoints().get(1).expectedDistance = 1627;
queries.get(2).getPoints().get(1).expectedDistance = 2250;
queries.get(3).getPoints().get(1).expectedDistance = 1482;
// or slightly longer tour with less nodes: list.get(1).setDistance(1, 3610);
queries.get(1).getPoints().get(1).expectedDistance = 3573;
queries.get(1).getPoints().get(1).expectedPoints = 149;
GraphHopper hopper = createHopper(MONACO, new Profile("foot").setVehicle("foot").setWeighting("shortest"));
hopper.setElevationProvider(new SRTMProvider(DIR));
hopper.importOrLoad();
checkQueries(hopper, queries);
}
use of com.graphhopper.GraphHopper in project graphhopper by graphhopper.
the class RoutingAlgorithmWithOSMTest method testKremsBikeRelation.
@Test
public void testKremsBikeRelation() {
List<Query> queries = new ArrayList<>();
queries.add(new Query(48.409523, 15.602394, 48.375466, 15.72916, 12491, 159));
queries.add(new Query(48.410061, 15.63951, 48.411386, 15.604899, 3077, 79));
queries.add(new Query(48.412294, 15.62007, 48.398306, 15.609667, 3965, 94));
GraphHopper hopper = createHopper(KREMS, new Profile("bike").setVehicle("bike").setWeighting("fastest"));
hopper.importOrLoad();
checkQueries(hopper, queries);
hopper.getGraphHopperStorage();
Helper.removeDir(new File(GH_LOCATION));
hopper = createHopper(KREMS, new Profile("bike").setVehicle("bike").setWeighting("fastest"), new Profile("car").setVehicle("car").setWeighting("fastest"));
hopper.importOrLoad();
checkQueries(hopper, queries);
}
Aggregations