Search in sources :

Example 11 with PMap

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());
}
Also used : CHProfile(com.graphhopper.config.CHProfile) PMap(com.graphhopper.util.PMap) LMProfile(com.graphhopper.config.LMProfile) Profile(com.graphhopper.config.Profile) CHProfile(com.graphhopper.config.CHProfile) LMProfile(com.graphhopper.config.LMProfile) Test(org.junit.jupiter.api.Test) CHProfileSelectorTest(com.graphhopper.routing.ch.CHProfileSelectorTest) LMProfileSelectorTest(com.graphhopper.routing.lm.LMProfileSelectorTest)

Example 12 with PMap

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());
}
Also used : PMap(com.graphhopper.util.PMap) Profile(com.graphhopper.config.Profile) CHProfile(com.graphhopper.config.CHProfile) LMProfile(com.graphhopper.config.LMProfile) Test(org.junit.jupiter.api.Test) CHProfileSelectorTest(com.graphhopper.routing.ch.CHProfileSelectorTest) LMProfileSelectorTest(com.graphhopper.routing.lm.LMProfileSelectorTest)

Example 13 with PMap

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());
}
Also used : PMap(com.graphhopper.util.PMap) LocationIndex(com.graphhopper.storage.index.LocationIndex) Snap(com.graphhopper.storage.index.Snap) GHPoint(com.graphhopper.util.shapes.GHPoint) RAMDirectory(com.graphhopper.storage.RAMDirectory) LocationIndexTree(com.graphhopper.storage.index.LocationIndexTree) QueryGraph(com.graphhopper.routing.querygraph.QueryGraph) Graph(com.graphhopper.storage.Graph) GHPoint(com.graphhopper.util.shapes.GHPoint) QueryGraph(com.graphhopper.routing.querygraph.QueryGraph) Test(org.junit.jupiter.api.Test)

Example 14 with PMap

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);
                                }
                            }
                        }
                    }
                }
            }
        }
    });
}
Also used : IndexStructureInfo(com.graphhopper.storage.index.IndexStructureInfo) java.util(java.util) Logger(org.slf4j.Logger) Transfer(com.conveyal.gtfs.model.Transfer) EdgeIteratorState(com.graphhopper.util.EdgeIteratorState) BBox(com.graphhopper.util.shapes.BBox) GraphHopperConfig(com.graphhopper.GraphHopperConfig) PMap(com.graphhopper.util.PMap) LoggerFactory(org.slf4j.LoggerFactory) Instant(java.time.Instant) QueryGraph(com.graphhopper.routing.querygraph.QueryGraph) Collectors(java.util.stream.Collectors) File(java.io.File) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) Weighting(com.graphhopper.routing.weighting.Weighting) Duration(java.time.Duration) GraphHopper(com.graphhopper.GraphHopper) LineIntIndex(com.graphhopper.storage.index.LineIntIndex) InMemConstructionIndex(com.graphhopper.storage.index.InMemConstructionIndex) PMap(com.graphhopper.util.PMap) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) Weighting(com.graphhopper.routing.weighting.Weighting) Transfer(com.conveyal.gtfs.model.Transfer) QueryGraph(com.graphhopper.routing.querygraph.QueryGraph)

Example 15 with PMap

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);
}
Also used : CHProfile(com.graphhopper.config.CHProfile) PMap(com.graphhopper.util.PMap) CountryRuleFactory(com.graphhopper.routing.util.countryrules.CountryRuleFactory) GraphHopper(com.graphhopper.GraphHopper) CHProfile(com.graphhopper.config.CHProfile) Profile(com.graphhopper.config.Profile) GraphHopperConfig(com.graphhopper.GraphHopperConfig)

Aggregations

PMap (com.graphhopper.util.PMap)50 Test (org.junit.jupiter.api.Test)27 LMProfile (com.graphhopper.config.LMProfile)12 Profile (com.graphhopper.config.Profile)12 FastestWeighting (com.graphhopper.routing.weighting.FastestWeighting)12 CHProfile (com.graphhopper.config.CHProfile)10 ArrayList (java.util.ArrayList)10 GraphHopper (com.graphhopper.GraphHopper)6 MapMatching (com.graphhopper.matching.MapMatching)5 MatchResult (com.graphhopper.matching.MatchResult)5 CHProfileSelectorTest (com.graphhopper.routing.ch.CHProfileSelectorTest)5 CHRoutingAlgorithmFactory (com.graphhopper.routing.ch.CHRoutingAlgorithmFactory)5 LMProfileSelectorTest (com.graphhopper.routing.lm.LMProfileSelectorTest)5 QueryGraph (com.graphhopper.routing.querygraph.QueryGraph)5 GraphHopperStorage (com.graphhopper.storage.GraphHopperStorage)5 Gpx (com.graphhopper.jackson.Gpx)4 ReaderWay (com.graphhopper.reader.ReaderWay)4 ProfileResolver (com.graphhopper.routing.ProfileResolver)4 Weighting (com.graphhopper.routing.weighting.Weighting)4 LocationIndexTree (com.graphhopper.storage.index.LocationIndexTree)4