use of com.graphhopper.config.Profile in project graphhopper by graphhopper.
the class MiniGraphUI method createAlgo.
private RoutingAlgorithm createAlgo(GraphHopper hopper) {
Profile profile = hopper.getProfiles().iterator().next();
if (useCH) {
RoutingCHGraph chGraph = hopper.getCHGraphs().get(profile.getName());
logger.info("CH algo, profile: " + profile.getName());
QueryGraph qGraph = QueryGraph.create(hopper.getGraphHopperStorage(), fromRes, toRes);
QueryRoutingCHGraph queryRoutingCHGraph = new QueryRoutingCHGraph(chGraph, qGraph);
return new CHDebugAlgo(queryRoutingCHGraph, mg);
} else {
LandmarkStorage landmarks = hopper.getLandmarks().get(profile.getName());
RoutingAlgorithmFactory algoFactory = (g, w, opts) -> {
RoutingAlgorithm algo = new LMRoutingAlgorithmFactory(landmarks).createAlgo(g, w, opts);
if (algo instanceof AStarBidirection) {
return new DebugAStarBi(g, w, opts.getTraversalMode(), mg).setApproximation(((AStarBidirection) algo).getApproximation());
} else if (algo instanceof AStar) {
return new DebugAStar(g, w, opts.getTraversalMode(), mg);
} else if (algo instanceof DijkstraBidirectionRef) {
return new DebugDijkstraBidirection(g, w, opts.getTraversalMode(), mg);
} else if (algo instanceof Dijkstra) {
return new DebugDijkstraSimple(g, w, opts.getTraversalMode(), mg);
}
return algo;
};
AlgorithmOptions algoOpts = new AlgorithmOptions().setAlgorithm(Algorithms.ASTAR_BI);
logger.info("algoOpts:" + algoOpts + ", weighting: " + landmarks.getWeighting() + ", profile: " + profile.getName());
QueryGraph qGraph = QueryGraph.create(graph, fromRes, toRes);
return algoFactory.createAlgo(qGraph, landmarks.getWeighting(), algoOpts);
}
}
use of com.graphhopper.config.Profile in project graphhopper by graphhopper.
the class ExtendedRouteTypeIT method init.
@BeforeAll
public static void init() {
GraphHopperConfig ghConfig = new GraphHopperConfig();
ghConfig.putObject("graph.location", GRAPH_LOC);
ghConfig.putObject("gtfs.file", "files/another-sample-feed-extended-route-type.zip");
ghConfig.setProfiles(Arrays.asList(new Profile("foot").setVehicle("foot").setWeighting("fastest"), new Profile("car").setVehicle("car").setWeighting("fastest")));
Helper.removeDir(new File(GRAPH_LOC));
graphHopperGtfs = new GraphHopperGtfs(ghConfig);
graphHopperGtfs.init(ghConfig);
graphHopperGtfs.importOrLoad();
ptRouter = new PtRouterImpl.Factory(ghConfig, new TranslationMap().doImport(), graphHopperGtfs.getGraphHopperStorage(), graphHopperGtfs.getLocationIndex(), graphHopperGtfs.getGtfsStorage()).createWithoutRealtimeFeed();
}
use of com.graphhopper.config.Profile in project graphhopper by graphhopper.
the class GraphHopperTest method testUTurn.
@Test
public void testUTurn() {
final String profile = "profile";
final String vehicle = "car";
final String weighting = "shortest";
GraphHopper hopper = new GraphHopper().setGraphHopperLocation(GH_LOCATION).setOSMFile(MONACO).setProfiles(new Profile(profile).setVehicle(vehicle).setWeighting(weighting));
hopper.importOrLoad();
Translation tr = hopper.getTranslationMap().getWithFallBack(Locale.US);
GHRequest request = new GHRequest();
request.addPoint(new GHPoint(43.743887, 7.431151));
request.addPoint(new GHPoint(43.744007, 7.431076));
// Force initial U-Turn
request.setHeadings(Arrays.asList(200.));
request.setAlgorithm(ASTAR).setProfile(profile);
GHResponse rsp = hopper.route(request);
assertFalse(rsp.hasErrors());
ResponsePath res = rsp.getBest();
InstructionList il = res.getInstructions();
assertEquals(4, il.size());
// Initial U-turn
assertEquals("make a U-turn onto Avenue Princesse Grace", il.get(1).getTurnDescription(tr));
// Second U-turn to get to destination
assertEquals("make a U-turn onto Avenue Princesse Grace", il.get(2).getTurnDescription(tr));
}
use of com.graphhopper.config.Profile in project graphhopper by graphhopper.
the class GraphHopperTest method testNodeBasedCHOnlyButTurnCostForNonCH.
@Test
public void testNodeBasedCHOnlyButTurnCostForNonCH() {
final String profile1 = "car_profile_tc";
final String profile2 = "car_profile_notc";
final String weighting = "fastest";
// before edge-based CH was added a common case was to use edge-based without CH and CH for node-based
GraphHopper hopper = new GraphHopper().setGraphHopperLocation(GH_LOCATION).setOSMFile(MOSCOW).setProfiles(Arrays.asList(new Profile(profile1).setVehicle("car").setWeighting(weighting).setTurnCosts(true), new Profile(profile2).setVehicle("car").setWeighting(weighting).setTurnCosts(false))).setStoreOnFlush(true);
hopper.getCHPreparationHandler().setCHProfiles(new CHProfile(profile2));
hopper.importOrLoad();
GHRequest req = new GHRequest(55.813357, 37.5958585, 55.811042, 37.594689);
// without CH, turn turn costs on and off
req.putHint(CH.DISABLE, true);
req.setProfile(profile1);
assertEquals(1044, hopper.route(req).getBest().getDistance(), 1);
req.setProfile(profile2);
assertEquals(400, hopper.route(req).getBest().getDistance(), 1);
// with CH, turn turn costs on and off, since turn costs not supported for CH throw an error
req.putHint(CH.DISABLE, false);
req.setProfile(profile2);
assertEquals(400, hopper.route(req).getBest().getDistance(), 1);
req.setProfile(profile1);
GHResponse rsp = hopper.route(req);
assertEquals(1, rsp.getErrors().size());
String expected = "Cannot find CH preparation for the requested profile: 'car_profile_tc'" + "\nYou can try disabling CH using ch.disable=true" + "\navailable CH profiles: [car_profile_notc]";
assertTrue(rsp.getErrors().toString().contains(expected), "unexpected error:\n" + rsp.getErrors().toString() + "\nwhen expecting an error containing:\n" + expected);
}
use of com.graphhopper.config.Profile in project graphhopper by graphhopper.
the class GraphHopperTest method testPathDetailsSamePoint.
@Test
public void testPathDetailsSamePoint() {
final String profile = "profile";
final String vehicle = "car";
final String weighting = "fastest";
GraphHopper hopper = new GraphHopper().setGraphHopperLocation(GH_LOCATION).setOSMFile(BAYREUTH).setProfiles(new Profile(profile).setVehicle(vehicle).setWeighting(weighting));
hopper.importOrLoad();
GHRequest req = new GHRequest().addPoint(new GHPoint(49.984352, 11.498802)).addPoint(new GHPoint(49.984352, 11.498802)).setProfile(profile).setPathDetails(Collections.singletonList(Parameters.Details.AVERAGE_SPEED));
GHResponse rsp = hopper.route(req);
assertFalse(rsp.hasErrors());
}
Aggregations