Search in sources :

Example 71 with Profile

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

the class GraphHopperTest method testMonacoMaxVisitedNodes.

@Test
public void testMonacoMaxVisitedNodes() {
    final String profile = "profile";
    final String vehicle = "foot";
    final String weighting = "fastest";
    GraphHopper hopper = new GraphHopper().setGraphHopperLocation(GH_LOCATION).setOSMFile(MONACO).setProfiles(new Profile(profile).setVehicle(vehicle).setWeighting(weighting)).setStoreOnFlush(true).importOrLoad();
    GHPoint from = new GHPoint(43.741069, 7.426854);
    GHPoint to = new GHPoint(43.744445, 7.429483);
    GHRequest req = new GHRequest(from, to).setProfile(profile);
    req.putHint(Routing.MAX_VISITED_NODES, 5);
    GHResponse rsp = hopper.route(req);
    assertTrue(rsp.hasErrors());
    Throwable throwable = rsp.getErrors().get(0);
    assertTrue(throwable instanceof MaximumNodesExceededException);
    Object nodesDetail = ((MaximumNodesExceededException) throwable).getDetails().get(MaximumNodesExceededException.NODES_KEY);
    assertEquals(5, nodesDetail);
    req = new GHRequest(from, to).setProfile(profile);
    rsp = hopper.route(req);
    assertFalse(rsp.hasErrors(), rsp.getErrors().toString());
}
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) MaximumNodesExceededException(com.graphhopper.util.exceptions.MaximumNodesExceededException) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 72 with Profile

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

the class GraphHopperTest method testAlternativeRoutes.

@Test
public void testAlternativeRoutes() {
    final String profile = "profile";
    final String vehicle = "foot";
    final String weighting = "shortest";
    GraphHopper hopper = new GraphHopper().setGraphHopperLocation(GH_LOCATION).setOSMFile(MONACO).setProfiles(new Profile(profile).setVehicle(vehicle).setWeighting(weighting)).setStoreOnFlush(true).importOrLoad();
    GHRequest req = new GHRequest(43.729057, 7.41251, 43.740298, 7.423561).setAlgorithm(ALT_ROUTE).setProfile(profile);
    GHResponse rsp = hopper.route(req);
    assertFalse(rsp.hasErrors());
    assertEquals(2, rsp.getAll().size());
    assertEquals(1310, rsp.getAll().get(0).getTime() / 1000);
    assertEquals(1431, rsp.getAll().get(1).getTime() / 1000);
    req.putHint("alternative_route.max_paths", 3);
    req.putHint("alternative_route.min_plateau_factor", 0.1);
    rsp = hopper.route(req);
    assertFalse(rsp.hasErrors());
    assertEquals(3, rsp.getAll().size());
    assertEquals(1310, rsp.getAll().get(0).getTime() / 1000);
    assertEquals(1431, rsp.getAll().get(1).getTime() / 1000);
    assertEquals(1492, rsp.getAll().get(2).getTime() / 1000);
}
Also used : 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 73 with Profile

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

the class GraphHopperTest method issue2306_1.

@Test
public void issue2306_1() {
    final String profile = "profile";
    final String vehicle = "car";
    GraphHopper hopper = new GraphHopper().setGraphHopperLocation(GH_LOCATION).setOSMFile("../map-matching/files/leipzig_germany.osm.pbf").setProfiles(new Profile("profile").setVehicle(vehicle).setWeighting("fastest")).setMinNetworkSize(200);
    hopper.importOrLoad();
    Weighting weighting = hopper.createWeighting(hopper.getProfile(profile), new PMap());
    EdgeFilter edgeFilter = new DefaultSnapFilter(weighting, hopper.getEncodingManager().getBooleanEncodedValue(Subnetwork.key(profile)));
    LocationIndexTree locationIndex = ((LocationIndexTree) hopper.getLocationIndex());
    // have to increase the default search radius to find our snap
    locationIndex.setMaxRegionSearch(6);
    Snap snap = locationIndex.findClosest(51.229248, 12.328892, edgeFilter);
    assertTrue(snap.isValid());
    assertTrue(snap.getQueryDistance() < 3_000);
}
Also used : Weighting(com.graphhopper.routing.weighting.Weighting) Snap(com.graphhopper.storage.index.Snap) CustomProfile(com.graphhopper.routing.weighting.custom.CustomProfile) Profile(com.graphhopper.config.Profile) CHProfile(com.graphhopper.config.CHProfile) LMProfile(com.graphhopper.config.LMProfile) LocationIndexTree(com.graphhopper.storage.index.LocationIndexTree) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 74 with Profile

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

the class GraphHopperTest method testMonacoDifferentAlgorithms.

@ParameterizedTest
@CsvSource({ DIJKSTRA + ",false,511", ASTAR + ",false,444", DIJKSTRA_BI + ",false,228", ASTAR_BI + ",false,184", ASTAR_BI + ",true,49", DIJKSTRA_BI + ",true,48" })
public void testMonacoDifferentAlgorithms(String algo, boolean withCH, int expectedVisitedNodes) {
    final String vehicle = "car";
    final String weighting = "fastest";
    GraphHopper hopper = new GraphHopper().setGraphHopperLocation(GH_LOCATION).setOSMFile(MONACO).setProfiles(new Profile("profile").setVehicle(vehicle).setWeighting(weighting)).setStoreOnFlush(true);
    hopper.getCHPreparationHandler().setCHProfiles(new CHProfile("profile"));
    hopper.setMinNetworkSize(0);
    hopper.importOrLoad();
    GHRequest req = new GHRequest(43.727687, 7.418737, 43.74958, 7.436566).setAlgorithm(algo).setProfile("profile");
    req.putHint(CH.DISABLE, !withCH);
    GHResponse rsp = hopper.route(req);
    assertFalse(rsp.hasErrors(), rsp.getErrors().toString());
    assertEquals(expectedVisitedNodes, rsp.getHints().getLong("visited_nodes.sum", 0));
    ResponsePath res = rsp.getBest();
    assertEquals(3586.9, res.getDistance(), .1);
    assertEquals(277112, res.getTime(), 10);
    assertEquals(91, res.getPoints().size());
    assertEquals(43.7276852, res.getWaypoints().getLat(0), 1e-7);
    assertEquals(43.7495432, res.getWaypoints().getLat(1), 1e-7);
}
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) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 75 with Profile

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

the class MapMatchingTest method setup.

@BeforeAll
public static void setup() {
    Helper.removeDir(new File(GH_LOCATION));
    graphHopper = new GraphHopper();
    graphHopper.setOSMFile("../map-matching/files/leipzig_germany.osm.pbf");
    graphHopper.setGraphHopperLocation(GH_LOCATION);
    graphHopper.setProfiles(new Profile("my_profile").setVehicle("car").setWeighting("fastest"));
    graphHopper.getLMPreparationHandler().setLMProfiles(new LMProfile("my_profile"));
    graphHopper.importOrLoad();
}
Also used : LMProfile(com.graphhopper.config.LMProfile) GraphHopper(com.graphhopper.GraphHopper) File(java.io.File) Profile(com.graphhopper.config.Profile) LMProfile(com.graphhopper.config.LMProfile) BeforeAll(org.junit.jupiter.api.BeforeAll)

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