use of com.graphhopper.config.CHProfile in project graphhopper by graphhopper.
the class CHProfileSelectorTest method onlyEdgeBasedPresent.
@Test
public void onlyEdgeBasedPresent() {
List<Profile> profiles = Collections.singletonList(fastCarEdge);
List<CHProfile> chProfiles = Collections.singletonList(new CHProfile("fast_car_edge"));
assertCHProfileSelectionError(NO_MATCH_ERROR, profiles, chProfiles, false, null);
assertCHProfileSelectionError(NO_MATCH_ERROR, profiles, chProfiles, false, 20);
assertProfileFound(profiles.get(0), profiles, chProfiles, true, null);
assertProfileFound(profiles.get(0), profiles, chProfiles, null, null);
}
use of com.graphhopper.config.CHProfile in project graphhopper by graphhopper.
the class Measurement method createConfigFromArgs.
private GraphHopperConfig createConfigFromArgs(PMap args) {
GraphHopperConfig ghConfig = new GraphHopperConfig(args);
String encodingManagerString = args.getString("graph.flag_encoders", "car");
List<FlagEncoder> tmpEncoders = EncodingManager.create(encodingManagerString).fetchEdgeEncoders();
if (tmpEncoders.size() != 1) {
logger.warn("You configured multiple encoders, only the first one is used for the measurements");
}
vehicle = tmpEncoders.get(0).toString();
boolean turnCosts = tmpEncoders.get(0).supportsTurnCosts();
int uTurnCosts = args.getInt("measurement.u_turn_costs", 40);
String weighting = args.getString("measurement.weighting", "fastest");
boolean useCHEdge = args.getBool("measurement.ch.edge", true);
boolean useCHNode = args.getBool("measurement.ch.node", true);
boolean useLM = args.getBool("measurement.lm", true);
String customModelFile = args.getString("measurement.custom_model_file", "");
List<Profile> profiles = new ArrayList<>();
if (!customModelFile.isEmpty()) {
if (!weighting.equals(CustomWeighting.NAME))
throw new IllegalArgumentException("To make use of a custom model you need to set measurement.weighting to 'custom'");
// use custom profile(s) as specified in the given custom model file
CustomModel customModel = loadCustomModel(customModelFile);
profiles.add(new CustomProfile("profile_no_tc").setCustomModel(customModel).setVehicle(vehicle).setTurnCosts(false));
if (turnCosts)
profiles.add(new CustomProfile("profile_tc").setCustomModel(customModel).setVehicle(vehicle).setTurnCosts(true).putHint(U_TURN_COSTS, uTurnCosts));
} else {
// use standard profiles
profiles.add(new Profile("profile_no_tc").setVehicle(vehicle).setWeighting(weighting).setTurnCosts(false));
if (turnCosts)
profiles.add(new Profile("profile_tc").setVehicle(vehicle).setWeighting(weighting).setTurnCosts(true).putHint(U_TURN_COSTS, uTurnCosts));
}
ghConfig.setProfiles(profiles);
List<CHProfile> chProfiles = new ArrayList<>();
if (useCHNode)
chProfiles.add(new CHProfile("profile_no_tc"));
if (useCHEdge)
chProfiles.add(new CHProfile("profile_tc"));
ghConfig.setCHProfiles(chProfiles);
List<LMProfile> lmProfiles = new ArrayList<>();
if (useLM) {
lmProfiles.add(new LMProfile("profile_no_tc"));
if (turnCosts)
// no need for a second LM preparation, we can do cross queries here
lmProfiles.add(new LMProfile("profile_tc").setPreparationProfile("profile_no_tc"));
}
ghConfig.setLMProfiles(lmProfiles);
return ghConfig;
}
use of com.graphhopper.config.CHProfile in project graphhopper by graphhopper.
the class MiniGraphUI method main.
public static void main(String[] strs) {
PMap args = PMap.read(strs);
args.putObject("datareader.file", args.getString("datareader.file", "core/files/monaco.osm.gz"));
args.putObject("graph.location", args.getString("graph.location", "tools/target/mini-graph-ui-gh"));
args.putObject("graph.flag_encoders", args.getString("graph.flag_encoders", "car"));
GraphHopperConfig ghConfig = new GraphHopperConfig(args);
ghConfig.setProfiles(Arrays.asList(new Profile("profile").setVehicle("car").setWeighting("fastest")));
ghConfig.setCHProfiles(Arrays.asList(new CHProfile("profile")));
ghConfig.setLMProfiles(Arrays.asList(new LMProfile("profile")));
GraphHopper hopper = new GraphHopper().init(ghConfig).importOrLoad();
boolean debug = args.getBool("minigraphui.debug", false);
boolean useCH = args.getBool("minigraphui.useCH", false);
new MiniGraphUI(hopper, debug, useCH).visualize();
}
use of com.graphhopper.config.CHProfile 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.config.CHProfile in project graphhopper by graphhopper.
the class GraphHopperOSMTest method testLoadOSM.
@Test
public void testLoadOSM() {
String profile = "car_profile";
String vehicle = "car";
String weighting = "fastest";
GraphHopper hopper = new GraphHopper().setStoreOnFlush(true).setProfiles(new Profile(profile).setVehicle(vehicle).setWeighting(weighting)).setGraphHopperLocation(ghLoc).setOSMFile(testOsm);
hopper.getCHPreparationHandler().setCHProfiles(new CHProfile(profile));
hopper.importOrLoad();
GHResponse rsp = hopper.route(new GHRequest(51.2492152, 9.4317166, 51.2, 9.4).setProfile(profile));
assertFalse(rsp.hasErrors());
assertEquals(3, rsp.getBest().getPoints().size());
hopper.close();
// no encoding manager necessary
hopper = new GraphHopper().setProfiles(new Profile(profile).setVehicle(vehicle).setWeighting(weighting)).setStoreOnFlush(true);
hopper.getCHPreparationHandler().setCHProfiles(new CHProfile(profile));
hopper.setGraphHopperLocation(ghLoc);
assertTrue(hopper.load());
rsp = hopper.route(new GHRequest(51.2492152, 9.4317166, 51.2, 9.4).setProfile(profile));
assertFalse(rsp.hasErrors());
assertEquals(3, rsp.getBest().getPoints().size());
hopper.close();
try {
rsp = hopper.route(new GHRequest(51.2492152, 9.4317166, 51.2, 9.4).setProfile(profile));
fail();
} catch (Exception ex) {
assertEquals("You need to create a new GraphHopper instance as it is already closed", ex.getMessage());
}
try {
hopper.getLocationIndex().findClosest(51.2492152, 9.4317166, EdgeFilter.ALL_EDGES);
fail();
} catch (Exception ex) {
assertEquals("You need to create a new LocationIndex instance as it is already closed", ex.getMessage());
}
}
Aggregations