use of com.graphhopper.config.Profile 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.Profile in project graphhopper by graphhopper.
the class GraphHopperStorageTest method testLoadGraph_implicitEncodedValues_issue1862.
@Test
public void testLoadGraph_implicitEncodedValues_issue1862() {
Helper.removeDir(new File(defaultGraphLoc));
encodingManager = new EncodingManager.Builder().add(createCarFlagEncoder()).add(new BikeFlagEncoder()).build();
graph = newGHStorage(new RAMDirectory(defaultGraphLoc, true), false).create(defaultSize);
NodeAccess na = graph.getNodeAccess();
na.setNode(0, 12, 23);
na.setNode(1, 8, 13);
na.setNode(2, 2, 10);
na.setNode(3, 5, 9);
GHUtility.setSpeed(60, true, true, carEncoder, graph.edge(1, 2).setDistance(10));
GHUtility.setSpeed(60, true, true, carEncoder, graph.edge(1, 3).setDistance(10));
int nodes = graph.getNodes();
int edges = graph.getAllEdges().length();
graph.flush();
Helper.close(graph);
// load without configured FlagEncoders
GraphHopper hopper = new GraphHopper();
hopper.setProfiles(Arrays.asList(new Profile("p_car").setVehicle("car").setWeighting("fastest"), new Profile("p_bike").setVehicle("bike").setWeighting("fastest")));
hopper.setGraphHopperLocation(defaultGraphLoc);
assertTrue(hopper.load());
graph = hopper.getGraphHopperStorage();
assertEquals(nodes, graph.getNodes());
assertEquals(edges, graph.getAllEdges().length());
Helper.close(graph);
hopper = new GraphHopper();
// load via explicitly configured FlagEncoders then we can define only one profile
hopper.getEncodingManagerBuilder().add(createCarFlagEncoder()).add(new BikeFlagEncoder());
hopper.setProfiles(Collections.singletonList(new Profile("p_car").setVehicle("car").setWeighting("fastest")));
hopper.setGraphHopperLocation(defaultGraphLoc);
assertTrue(hopper.load());
graph = hopper.getGraphHopperStorage();
assertEquals(nodes, graph.getNodes());
assertEquals(edges, graph.getAllEdges().length());
Helper.close(graph);
Helper.removeDir(new File(defaultGraphLoc));
}
use of com.graphhopper.config.Profile in project graphhopper by graphhopper.
the class GraphHopperStorageLMTest method testLoad.
@Test
public void testLoad() {
String defaultGraphLoc = "./target/ghstorage_lm";
Helper.removeDir(new File(defaultGraphLoc));
CarFlagEncoder carFlagEncoder = new CarFlagEncoder();
EncodingManager encodingManager = new EncodingManager.Builder().add(carFlagEncoder).add(Subnetwork.create("my_profile")).build();
GraphHopperStorage graph = GraphBuilder.start(encodingManager).setRAM(defaultGraphLoc, true).create();
// 0-1
ReaderWay way_0_1 = new ReaderWay(27l);
way_0_1.setTag("highway", "primary");
way_0_1.setTag("maxheight", "4.4");
GHUtility.setSpeed(60, true, true, carFlagEncoder, graph.edge(0, 1).setDistance(1));
updateDistancesFor(graph, 0, 0.00, 0.00);
updateDistancesFor(graph, 1, 0.01, 0.01);
graph.getEdgeIteratorState(0, 1).setFlags(carFlagEncoder.handleWayTags(encodingManager.createEdgeFlags(), way_0_1));
// 1-2
ReaderWay way_1_2 = new ReaderWay(28l);
way_1_2.setTag("highway", "primary");
way_1_2.setTag("maxweight", "45");
GHUtility.setSpeed(60, true, true, carFlagEncoder, graph.edge(1, 2).setDistance(1));
updateDistancesFor(graph, 2, 0.02, 0.02);
graph.getEdgeIteratorState(1, 2).setFlags(carFlagEncoder.handleWayTags(encodingManager.createEdgeFlags(), way_1_2));
graph.flush();
graph.close();
GraphHopper hopper = new GraphHopper().setGraphHopperLocation(defaultGraphLoc).setProfiles(new Profile("my_profile").setVehicle("car").setWeighting("fastest"));
hopper.getLMPreparationHandler().setLMProfiles(new LMProfile("my_profile"));
// does lm preparation
hopper.importOrLoad();
EncodingManager em = hopper.getEncodingManager();
assertNotNull(em);
assertEquals(1, em.fetchEdgeEncoders().size());
assertEquals(16, hopper.getLMPreparationHandler().getLandmarks());
hopper = new GraphHopper().setGraphHopperLocation(defaultGraphLoc).setProfiles(new Profile("my_profile").setVehicle("car").setWeighting("fastest"));
hopper.getLMPreparationHandler().setLMProfiles(new LMProfile("my_profile"));
// just loads the LM data
hopper.importOrLoad();
assertEquals(1, em.fetchEdgeEncoders().size());
assertEquals(16, hopper.getLMPreparationHandler().getLandmarks());
}
use of com.graphhopper.config.Profile 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.Profile in project graphhopper by graphhopper.
the class RealtimeIT method init.
@BeforeAll
public static void init() {
GraphHopperConfig ghConfig = new GraphHopperConfig();
ghConfig.putObject("gtfs.file", "files/sample-feed");
ghConfig.putObject("graph.location", GRAPH_LOC);
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();
graphHopperGtfs.close();
// Re-load read only
graphHopperGtfs = new GraphHopperGtfs(ghConfig);
graphHopperGtfs.init(ghConfig);
graphHopperGtfs.importOrLoad();
graphHopperFactory = new PtRouterImpl.Factory(ghConfig, new TranslationMap().doImport(), graphHopperGtfs.getGraphHopperStorage(), graphHopperGtfs.getLocationIndex(), graphHopperGtfs.getGtfsStorage());
}
Aggregations