use of com.graphhopper.util.PMap in project graphhopper by graphhopper.
the class ProfileResolverTest method defaultVehicleAllAlgos.
@Test
public void defaultVehicleAllAlgos() {
final String profile1 = "foot_profile";
final String profile2 = "car_profile";
final String vehicle1 = "foot";
final String vehicle2 = "car";
final String weighting = "shortest";
ProfileResolver profileResolver = new ProfileResolver(EncodingManager.create(vehicle1 + "," + vehicle2), Arrays.asList(new Profile(profile1).setVehicle(vehicle1).setWeighting(weighting), new Profile(profile2).setVehicle(vehicle2).setWeighting(weighting)), Arrays.asList(new CHProfile(profile1), new CHProfile(profile2)), Arrays.asList(new LMProfile(profile1), new LMProfile(profile2)));
// when we do not specify vehicle/weighting, we get an error because there are multiple matches
PMap hints = new PMap();
assertMultiMatchError(profileResolver, hints, "There are multiple CH profiles matching your request");
assertMultiMatchError(profileResolver, hints.putObject(Parameters.CH.DISABLE, true), "There are multiple LM profiles matching your request");
assertMultiMatchError(profileResolver, hints.putObject(Parameters.Landmark.DISABLE, true), "There are multiple profiles matching your request");
// using the weighting is not enough, because its the same for both profiles
hints = new PMap().putObject("weighting", "shortest");
assertMultiMatchError(profileResolver, hints, "There are multiple CH profiles matching your request");
assertMultiMatchError(profileResolver, hints.putObject(Parameters.CH.DISABLE, true), "There are multiple LM profiles matching your request");
assertMultiMatchError(profileResolver, hints.putObject(Parameters.Landmark.DISABLE, true), "There are multiple profiles matching your request");
// using the vehicle to select one of the profiles works
hints = new PMap().putObject("vehicle", vehicle1);
assertEquals(profile1, profileResolver.resolveProfile(hints).getName());
assertEquals(profile1, profileResolver.resolveProfile(hints.putObject(Parameters.CH.DISABLE, true)).getName());
assertEquals(profile1, profileResolver.resolveProfile(hints.putObject(Parameters.Landmark.DISABLE, true)).getName());
}
use of com.graphhopper.util.PMap in project graphhopper by graphhopper.
the class ProfileResolverTest method edgeBasedAndTurnCosts.
@Test
public void edgeBasedAndTurnCosts() {
ProfileResolver profileResolver = new ProfileResolver(EncodingManager.create("foot"), Collections.singletonList(new Profile("profile").setVehicle("foot").setWeighting("fastest")), Collections.emptyList(), Collections.emptyList());
assertProfileNotFound(profileResolver, new PMap().putObject(Parameters.Routing.EDGE_BASED, true));
assertEquals("profile", profileResolver.resolveProfile(new PMap()).getName());
assertEquals("profile", profileResolver.resolveProfile(new PMap().putObject(Parameters.Routing.EDGE_BASED, false)).getName());
}
use of com.graphhopper.util.PMap in project graphhopper by graphhopper.
the class RoundTripRoutingTest method testLookupAndCalcPaths_simpleSquareGraph.
@Test
public void testLookupAndCalcPaths_simpleSquareGraph() {
Graph g = createSquareGraph();
// start at node 0 and head south, make sure the round trip is long enough to reach most southern node 6
GHPoint start = new GHPoint(1, -1);
double heading = 180.0;
int numPoints = 2;
double roundTripDistance = 670000;
PMap hints = new PMap();
hints.putObject(Parameters.Algorithms.RoundTrip.POINTS, numPoints);
hints.putObject(Parameters.Algorithms.RoundTrip.DISTANCE, roundTripDistance);
LocationIndex locationIndex = new LocationIndexTree(g, new RAMDirectory()).prepareIndex();
List<Snap> stagePoints = RoundTripRouting.lookup(Collections.singletonList(start), new FiniteWeightFilter(fastestWeighting), locationIndex, new RoundTripRouting.Params(hints, heading, 3));
assertEquals(3, stagePoints.size());
assertEquals(0, stagePoints.get(0).getClosestNode());
assertEquals(6, stagePoints.get(1).getClosestNode());
assertEquals(0, stagePoints.get(2).getClosestNode());
QueryGraph queryGraph = QueryGraph.create(g, stagePoints);
List<Path> paths = RoundTripRouting.calcPaths(stagePoints, new FlexiblePathCalculator(queryGraph, new RoutingAlgorithmFactorySimple(), fastestWeighting, new AlgorithmOptions().setAlgorithm(DIJKSTRA_BI).setTraversalMode(tMode))).paths;
// make sure the resulting paths are connected and form a round trip starting and ending at the start node 0
assertEquals(2, paths.size());
assertEquals(IntArrayList.from(0, 7, 6, 5), paths.get(0).calcNodes());
assertEquals(IntArrayList.from(5, 4, 3, 2, 1, 0), paths.get(1).calcNodes());
}
use of com.graphhopper.util.PMap in project graphhopper by graphhopper.
the class GraphHopperGtfs method interpolateTransfers.
private void interpolateTransfers(HashMap<String, GtfsReader> readers, Map<String, Transfers> allTransfers) {
LOGGER.info("Looking for transfers");
final int maxTransferWalkTimeSeconds = ghConfig.getInt("gtfs.max_transfer_interpolation_walk_time_seconds", 120);
GraphHopperStorage graphHopperStorage = getGraphHopperStorage();
QueryGraph queryGraph = QueryGraph.create(graphHopperStorage, Collections.emptyList());
Weighting transferWeighting = createWeighting(getProfile("foot"), new PMap());
final GraphExplorer graphExplorer = new GraphExplorer(queryGraph, ptGraph, transferWeighting, getGtfsStorage(), RealtimeFeed.empty(), true, true, false, 5.0, false, 0);
getGtfsStorage().getStationNodes().values().stream().distinct().map(n -> {
int streetNode = Optional.ofNullable(gtfsStorage.getPtToStreet().get(n)).orElse(-1);
return new Label.NodeId(streetNode, n);
}).forEach(stationNode -> {
MultiCriteriaLabelSetting router = new MultiCriteriaLabelSetting(graphExplorer, true, false, false, 0, new ArrayList<>());
router.setLimitStreetTime(Duration.ofSeconds(maxTransferWalkTimeSeconds).toMillis());
for (Label label : router.calcLabels(stationNode, Instant.ofEpochMilli(0))) {
if (label.parent != null) {
if (label.edge.getType() == GtfsStorage.EdgeType.EXIT_PT) {
GtfsStorage.PlatformDescriptor fromPlatformDescriptor = label.edge.getPlatformDescriptor();
Transfers transfers = allTransfers.get(fromPlatformDescriptor.feed_id);
for (PtGraph.PtEdge ptEdge : ptGraph.edgesAround(stationNode.ptNode)) {
if (ptEdge.getType() == GtfsStorage.EdgeType.ENTER_PT) {
GtfsStorage.PlatformDescriptor toPlatformDescriptor = ptEdge.getAttrs().platformDescriptor;
LOGGER.debug(fromPlatformDescriptor + " -> " + toPlatformDescriptor);
if (!toPlatformDescriptor.feed_id.equals(fromPlatformDescriptor.feed_id)) {
LOGGER.debug(" Different feed. Inserting transfer with " + (int) (label.streetTime / 1000L) + " s.");
insertInterpolatedTransfer(label, toPlatformDescriptor, readers);
} else {
List<Transfer> transfersToStop = transfers.getTransfersToStop(toPlatformDescriptor.stop_id, routeIdOrNull(toPlatformDescriptor));
if (transfersToStop.stream().noneMatch(t -> t.from_stop_id.equals(fromPlatformDescriptor.stop_id))) {
LOGGER.debug(" Inserting transfer with " + (int) (label.streetTime / 1000L) + " s.");
insertInterpolatedTransfer(label, toPlatformDescriptor, readers);
}
}
}
}
}
}
}
});
}
use of com.graphhopper.util.PMap 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);
}
Aggregations