Search in sources :

Example 41 with LMProfile

use of com.graphhopper.config.LMProfile in project graphhopper by graphhopper.

the class MapMatching2Test method testIssue127.

@Test
public void testIssue127() throws IOException {
    GraphHopper hopper = new GraphHopper();
    hopper.setOSMFile("../map-matching/files/map-issue13.osm.gz");
    hopper.setGraphHopperLocation(GH_LOCATION);
    hopper.setProfiles(new Profile("my_profile").setVehicle("car").setWeighting("fastest"));
    hopper.getLMPreparationHandler().setLMProfiles(new LMProfile("my_profile"));
    hopper.importOrLoad();
    MapMatching mapMatching = new MapMatching(hopper, new PMap().putObject("profile", "my_profile"));
    // query with two identical points
    Gpx gpx = xmlMapper.readValue(getClass().getResourceAsStream("/issue-127.gpx"), Gpx.class);
    MatchResult mr = mapMatching.match(GpxConversions.getEntries(gpx.trk.get(0)));
    // make sure no virtual edges are returned
    int edgeCount = hopper.getGraphHopperStorage().getAllEdges().length();
    for (EdgeMatch em : mr.getEdgeMatches()) {
        assertTrue(em.getEdgeState().getEdge() < edgeCount, "result contains virtual edges:" + em.getEdgeState().toString());
        validateEdgeMatch(em);
    }
    assertEquals(0, mr.getMatchMillis(), 50);
}
Also used : MapMatching(com.graphhopper.matching.MapMatching) EdgeMatch(com.graphhopper.matching.EdgeMatch) PMap(com.graphhopper.util.PMap) LMProfile(com.graphhopper.config.LMProfile) GraphHopper(com.graphhopper.GraphHopper) MatchResult(com.graphhopper.matching.MatchResult) Profile(com.graphhopper.config.Profile) LMProfile(com.graphhopper.config.LMProfile) Gpx(com.graphhopper.jackson.Gpx) Test(org.junit.jupiter.api.Test)

Example 42 with LMProfile

use of com.graphhopper.config.LMProfile in project graphhopper by graphhopper.

the class GraphHopperLandmarksTest method createConfig.

private static GraphHopperServerConfiguration createConfig() {
    GraphHopperServerConfiguration config = new GraphHopperServerTestConfiguration();
    config.getGraphHopperConfiguration().putObject("graph.flag_encoders", "car").putObject("datareader.file", "../core/files/belarus-east.osm.gz").putObject("prepare.min_network_size", 0).putObject("graph.location", DIR).putObject("prepare.lm.min_network_size", 2).setProfiles(Collections.singletonList(new Profile("car_profile").setVehicle("car").setWeighting("fastest"))).setCHProfiles(Collections.singletonList(new CHProfile("car_profile"))).setLMProfiles(Collections.singletonList(new LMProfile("car_profile")));
    return config;
}
Also used : CHProfile(com.graphhopper.config.CHProfile) GraphHopperServerTestConfiguration(com.graphhopper.application.util.GraphHopperServerTestConfiguration) LMProfile(com.graphhopper.config.LMProfile) CHProfile(com.graphhopper.config.CHProfile) Profile(com.graphhopper.config.Profile) LMProfile(com.graphhopper.config.LMProfile)

Example 43 with LMProfile

use of com.graphhopper.config.LMProfile in project graphhopper by graphhopper.

the class GraphHopperConfig method toString.

@Override
public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append("profiles:\n");
    for (Profile profile : profiles) {
        sb.append(profile);
        sb.append("\n");
    }
    sb.append("profiles_ch:\n");
    for (CHProfile profile : chProfiles) {
        sb.append(profile);
        sb.append("\n");
    }
    sb.append("profiles_lm:\n");
    for (LMProfile profile : lmProfiles) {
        sb.append(profile);
        sb.append("\n");
    }
    sb.append("properties:\n");
    for (Map.Entry<String, Object> entry : map.toMap().entrySet()) {
        sb.append(entry.getKey()).append(": ").append(entry.getValue());
        sb.append("\n");
    }
    return sb.toString();
}
Also used : CHProfile(com.graphhopper.config.CHProfile) LMProfile(com.graphhopper.config.LMProfile) Map(java.util.Map) PMap(com.graphhopper.util.PMap) Profile(com.graphhopper.config.Profile) CHProfile(com.graphhopper.config.CHProfile) LMProfile(com.graphhopper.config.LMProfile)

Example 44 with LMProfile

use of com.graphhopper.config.LMProfile in project graphhopper by graphhopper.

the class GraphHopperTest method testImportCloseAndLoad.

private void testImportCloseAndLoad(boolean ch, boolean lm, boolean sort, boolean custom) {
    final String vehicle = "foot";
    final String profileName = "profile";
    GraphHopper hopper = new GraphHopper().setGraphHopperLocation(GH_LOCATION).setOSMFile(MONACO).setStoreOnFlush(true).setSortGraph(sort);
    Profile profile = new Profile(profileName).setVehicle(vehicle).setWeighting("fastest");
    if (custom) {
        JsonFeature area51Feature = new JsonFeature();
        area51Feature.setGeometry(new GeometryFactory().createPolygon(new Coordinate[] { new Coordinate(7.4174, 43.7345), new Coordinate(7.4198, 43.7355), new Coordinate(7.4207, 43.7344), new Coordinate(7.4174, 43.7345) }));
        CustomModel customModel = new CustomModel().setDistanceInfluence(0);
        customModel.getPriority().add(Statement.If("in_area51", Statement.Op.MULTIPLY, 0.1));
        customModel.getAreas().put("area51", area51Feature);
        profile = new CustomProfile(profileName).setCustomModel(customModel).setVehicle(vehicle);
    }
    hopper.setProfiles(profile);
    if (ch) {
        hopper.getCHPreparationHandler().setCHProfiles(new CHProfile(profileName));
    }
    if (lm) {
        hopper.getLMPreparationHandler().setLMProfiles(new LMProfile(profileName));
    }
    hopper.importAndClose();
    hopper = new GraphHopper().setGraphHopperLocation(GH_LOCATION).setOSMFile(MONACO).setProfiles(profile).setStoreOnFlush(true).setAllowWrites(false);
    if (ch) {
        hopper.getCHPreparationHandler().setCHProfiles(new CHProfile(profileName));
    }
    if (lm) {
        hopper.getLMPreparationHandler().setLMProfiles(new LMProfile(profileName));
    }
    hopper.importOrLoad();
    if (ch) {
        GHRequest req = new GHRequest(43.727687, 7.418737, 43.74958, 7.436566).setProfile(profileName);
        req.putHint(CH.DISABLE, false);
        req.putHint(Landmark.DISABLE, true);
        GHResponse rsp = hopper.route(req);
        ResponsePath bestPath = rsp.getBest();
        long sum = rsp.getHints().getLong("visited_nodes.sum", 0);
        assertNotEquals(sum, 0);
        assertTrue(sum < 155, "Too many nodes visited " + sum);
        assertEquals(3535, bestPath.getDistance(), 1);
        assertEquals(115, bestPath.getPoints().size());
    }
    if (lm) {
        GHRequest req = new GHRequest(43.727687, 7.418737, 43.74958, 7.436566).setProfile(profileName).setAlgorithm(Parameters.Algorithms.ASTAR_BI);
        req.putHint(CH.DISABLE, true);
        req.putHint(Landmark.DISABLE, false);
        GHResponse rsp = hopper.route(req);
        ResponsePath bestPath = rsp.getBest();
        long sum = rsp.getHints().getLong("visited_nodes.sum", 0);
        assertNotEquals(sum, 0);
        assertTrue(sum < 125, "Too many nodes visited " + sum);
        assertEquals(3535, bestPath.getDistance(), 1);
        assertEquals(115, bestPath.getPoints().size());
    }
    // flexible
    GHRequest req = new GHRequest(43.727687, 7.418737, 43.74958, 7.436566).setProfile(profileName);
    req.putHint(CH.DISABLE, true);
    req.putHint(Landmark.DISABLE, true);
    GHResponse rsp = hopper.route(req);
    ResponsePath bestPath = rsp.getBest();
    long sum = rsp.getHints().getLong("visited_nodes.sum", 0);
    assertNotEquals(sum, 0);
    assertTrue(sum > 120, "Too few nodes visited " + sum);
    assertEquals(3535, bestPath.getDistance(), 1);
    assertEquals(115, bestPath.getPoints().size());
    hopper.close();
}
Also used : CHProfile(com.graphhopper.config.CHProfile) GeometryFactory(org.locationtech.jts.geom.GeometryFactory) CustomProfile(com.graphhopper.routing.weighting.custom.CustomProfile) CustomProfile(com.graphhopper.routing.weighting.custom.CustomProfile) Profile(com.graphhopper.config.Profile) CHProfile(com.graphhopper.config.CHProfile) LMProfile(com.graphhopper.config.LMProfile) Coordinate(org.locationtech.jts.geom.Coordinate) LMProfile(com.graphhopper.config.LMProfile)

Example 45 with LMProfile

use of com.graphhopper.config.LMProfile in project graphhopper by graphhopper.

the class GraphHopperTest method testIssue1960.

@Test
public void testIssue1960() {
    final String profile = "car";
    final String vehicle = "car";
    final String weighting = "fastest";
    GraphHopper hopper = new GraphHopper().setGraphHopperLocation(GH_LOCATION).setOSMFile(MOSCOW).setProfiles(new Profile(profile).setVehicle(vehicle).setWeighting(weighting).setTurnCosts(true));
    hopper.getCHPreparationHandler().setCHProfiles(new CHProfile(profile));
    hopper.getLMPreparationHandler().setLMProfiles(new LMProfile(profile));
    hopper.importOrLoad();
    GHRequest req = new GHRequest(55.815670, 37.604613, 55.806151, 37.617823);
    req.setProfile("car");
    req.getHints().putObject(CH.DISABLE, false).putObject(Landmark.DISABLE, true);
    ResponsePath pathCH = hopper.route(req).getBest();
    req.getHints().putObject(CH.DISABLE, true).putObject(Landmark.DISABLE, false);
    ResponsePath pathLM = hopper.route(req).getBest();
    req.getHints().putObject(CH.DISABLE, true).putObject(Landmark.DISABLE, true);
    ResponsePath path = hopper.route(req).getBest();
    assertEquals(1995.38, pathCH.getDistance(), 0.1);
    assertEquals(1995.38, pathLM.getDistance(), 0.1);
    assertEquals(1995.38, path.getDistance(), 0.1);
    assertEquals(149497, pathCH.getTime());
    assertEquals(149497, pathLM.getTime());
    assertEquals(149497, path.getTime());
}
Also used : CHProfile(com.graphhopper.config.CHProfile) LMProfile(com.graphhopper.config.LMProfile) 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

LMProfile (com.graphhopper.config.LMProfile)48 Profile (com.graphhopper.config.Profile)41 CHProfile (com.graphhopper.config.CHProfile)33 Test (org.junit.jupiter.api.Test)24 CustomProfile (com.graphhopper.routing.weighting.custom.CustomProfile)15 PMap (com.graphhopper.util.PMap)12 GraphHopper (com.graphhopper.GraphHopper)10 GraphHopperServerConfiguration (com.graphhopper.application.GraphHopperServerConfiguration)6 GraphHopperServerTestConfiguration (com.graphhopper.application.util.GraphHopperServerTestConfiguration)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 CHProfileSelectorTest (com.graphhopper.routing.ch.CHProfileSelectorTest)4 LMProfileSelectorTest (com.graphhopper.routing.lm.LMProfileSelectorTest)4 File (java.io.File)4 GraphHopperConfig (com.graphhopper.GraphHopperConfig)3 Gpx (com.graphhopper.jackson.Gpx)3 EdgeMatch (com.graphhopper.matching.EdgeMatch)3 MapMatching (com.graphhopper.matching.MapMatching)3 MatchResult (com.graphhopper.matching.MatchResult)3 ProfileResolver (com.graphhopper.routing.ProfileResolver)3 GHPoint (com.graphhopper.util.shapes.GHPoint)3