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());
}
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);
}
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);
}
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);
}
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();
}
Aggregations