Search in sources :

Example 46 with Profile

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);
    }
}
Also used : RoutingCHGraph(com.graphhopper.storage.RoutingCHGraph) Arrays(java.util.Arrays) GraphHopperConfig(com.graphhopper.GraphHopperConfig) EdgeFilter(com.graphhopper.routing.util.EdgeFilter) QueryRoutingCHGraph(com.graphhopper.routing.querygraph.QueryRoutingCHGraph) com.graphhopper.routing(com.graphhopper.routing) LoggerFactory(org.slf4j.LoggerFactory) Random(java.util.Random) LandmarkStorage(com.graphhopper.routing.lm.LandmarkStorage) LocationIndexTree(com.graphhopper.storage.index.LocationIndexTree) StopWatch(com.graphhopper.util.StopWatch) LMRoutingAlgorithmFactory(com.graphhopper.routing.lm.LMRoutingAlgorithmFactory) MouseWheelEvent(java.awt.event.MouseWheelEvent) DecimalEncodedValue(com.graphhopper.routing.ev.DecimalEncodedValue) Profile(com.graphhopper.config.Profile) MouseAdapter(java.awt.event.MouseAdapter) Graph(com.graphhopper.storage.Graph) GraphHopper(com.graphhopper.GraphHopper) FlagEncoder(com.graphhopper.routing.util.FlagEncoder) IntIndexedContainer(com.carrotsearch.hppc.IntIndexedContainer) Logger(org.slf4j.Logger) BBox(com.graphhopper.util.shapes.BBox) PMap(com.graphhopper.util.PMap) Algorithms(com.graphhopper.util.Parameters.Algorithms) BooleanEncodedValue(com.graphhopper.routing.ev.BooleanEncodedValue) CHProfile(com.graphhopper.config.CHProfile) QueryGraph(com.graphhopper.routing.querygraph.QueryGraph) PointList(com.graphhopper.util.PointList) MouseEvent(java.awt.event.MouseEvent) GHBitSet(com.graphhopper.coll.GHBitSet) java.awt(java.awt) GHTBitSet(com.graphhopper.coll.GHTBitSet) NodeAccess(com.graphhopper.storage.NodeAccess) MouseWheelListener(java.awt.event.MouseWheelListener) Snap(com.graphhopper.storage.index.Snap) FetchMode(com.graphhopper.util.FetchMode) LMProfile(com.graphhopper.config.LMProfile) AllEdgesIterator(com.graphhopper.routing.util.AllEdgesIterator) javax.swing(javax.swing) QueryRoutingCHGraph(com.graphhopper.routing.querygraph.QueryRoutingCHGraph) RoutingCHGraph(com.graphhopper.storage.RoutingCHGraph) QueryRoutingCHGraph(com.graphhopper.routing.querygraph.QueryRoutingCHGraph) LMRoutingAlgorithmFactory(com.graphhopper.routing.lm.LMRoutingAlgorithmFactory) Profile(com.graphhopper.config.Profile) CHProfile(com.graphhopper.config.CHProfile) LMProfile(com.graphhopper.config.LMProfile) LandmarkStorage(com.graphhopper.routing.lm.LandmarkStorage) LMRoutingAlgorithmFactory(com.graphhopper.routing.lm.LMRoutingAlgorithmFactory) QueryGraph(com.graphhopper.routing.querygraph.QueryGraph)

Example 47 with Profile

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();
}
Also used : GraphHopperGtfs(com.graphhopper.gtfs.GraphHopperGtfs) TranslationMap(com.graphhopper.util.TranslationMap) File(java.io.File) Profile(com.graphhopper.config.Profile) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 48 with Profile

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));
}
Also used : GHPoint(com.graphhopper.util.shapes.GHPoint) CustomProfile(com.graphhopper.routing.weighting.custom.CustomProfile) Profile(com.graphhopper.config.Profile) CHProfile(com.graphhopper.config.CHProfile) LMProfile(com.graphhopper.config.LMProfile) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 49 with Profile

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);
}
Also used : CHProfile(com.graphhopper.config.CHProfile) CustomProfile(com.graphhopper.routing.weighting.custom.CustomProfile) Profile(com.graphhopper.config.Profile) CHProfile(com.graphhopper.config.CHProfile) LMProfile(com.graphhopper.config.LMProfile) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 50 with Profile

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());
}
Also used : GHPoint(com.graphhopper.util.shapes.GHPoint) CustomProfile(com.graphhopper.routing.weighting.custom.CustomProfile) Profile(com.graphhopper.config.Profile) CHProfile(com.graphhopper.config.CHProfile) LMProfile(com.graphhopper.config.LMProfile) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

Profile (com.graphhopper.config.Profile)203 LMProfile (com.graphhopper.config.LMProfile)167 CHProfile (com.graphhopper.config.CHProfile)164 Test (org.junit.jupiter.api.Test)138 CustomProfile (com.graphhopper.routing.weighting.custom.CustomProfile)84 GraphHopper (com.graphhopper.GraphHopper)54 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)54 GHPoint (com.graphhopper.util.shapes.GHPoint)35 ArrayList (java.util.ArrayList)29 File (java.io.File)25 GraphHopperServerConfiguration (com.graphhopper.application.GraphHopperServerConfiguration)19 GraphHopperServerTestConfiguration (com.graphhopper.application.util.GraphHopperServerTestConfiguration)19 PMap (com.graphhopper.util.PMap)14 SRTMProvider (com.graphhopper.reader.dem.SRTMProvider)11 BeforeAll (org.junit.jupiter.api.BeforeAll)10 Weighting (com.graphhopper.routing.weighting.Weighting)9 LocationIndexTree (com.graphhopper.storage.index.LocationIndexTree)8 TranslationMap (com.graphhopper.util.TranslationMap)7 Snap (com.graphhopper.storage.index.Snap)6 GHRequest (com.graphhopper.GHRequest)5