use of com.graphhopper.config.Profile in project graphhopper by graphhopper.
the class GraphHopperTest method testNorthBayreuthDestination.
@Test
public void testNorthBayreuthDestination() {
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(49.985307, 11.50628, 49.985731, 11.507465).setProfile(profile);
GHResponse rsp = hopper.route(req);
assertFalse(rsp.hasErrors(), rsp.getErrors().toString());
assertEquals(550, rsp.getBest().getDistance(), 1);
}
use of com.graphhopper.config.Profile in project graphhopper by graphhopper.
the class GraphHopperTest method connectionNotFound.
@Test
public void connectionNotFound() {
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)).setStoreOnFlush(true);
hopper.getCHPreparationHandler().setCHProfiles(new CHProfile("profile"));
hopper.setMinNetworkSize(0);
hopper.importOrLoad();
// here from and to both snap to small subnetworks that are disconnected from the main graph and
// since we set min network size to 0 we expect a connection not found error
GHPoint from = new GHPoint(49.97964, 11.539593);
GHPoint to = new GHPoint(50.029247, 11.582851);
GHRequest req = new GHRequest(from, to).setProfile(profile);
GHResponse res = hopper.route(req);
assertEquals("[com.graphhopper.util.exceptions.ConnectionNotFoundException: Connection between locations not found]", res.getErrors().toString());
}
use of com.graphhopper.config.Profile in project graphhopper by graphhopper.
the class GraphHopperTest method testMonacoWithInstructions.
@Test
public void testMonacoWithInstructions() {
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();
GHResponse rsp = hopper.route(new GHRequest(43.727687, 7.418737, 43.74958, 7.436566).setAlgorithm(ASTAR).setProfile(profile));
// identify the number of counts to compare with CH foot route
assertEquals(706, rsp.getHints().getLong("visited_nodes.sum", 0));
ResponsePath res = rsp.getBest();
assertEquals(3437.1, res.getDistance(), .1);
assertEquals(85, res.getPoints().size());
assertEquals(43.7276852, res.getWaypoints().getLat(0), 1e-7);
assertEquals(43.7495432, res.getWaypoints().getLat(1), 1e-7);
InstructionList il = res.getInstructions();
assertEquals(16, il.size());
// TODO roundabout fine tuning -> enter + leave roundabout (+ two roundabouts -> is it necessary if we do not leave the street?)
Translation tr = hopper.getTranslationMap().getWithFallBack(Locale.US);
assertEquals("continue onto Avenue des Guelfes", il.get(0).getTurnDescription(tr));
assertEquals("turn slight left onto Avenue des Papalins", il.get(1).getTurnDescription(tr));
assertEquals("turn sharp right onto Quai Jean-Charles Rey", il.get(4).getTurnDescription(tr));
assertEquals("turn left", il.get(5).getTurnDescription(tr));
assertEquals("turn right onto Avenue Albert II", il.get(6).getTurnDescription(tr));
assertEquals(11, il.get(0).getDistance(), 1);
assertEquals(96, il.get(1).getDistance(), 1);
assertEquals(178, il.get(2).getDistance(), 1);
assertEquals(13, il.get(3).getDistance(), 1);
assertEquals(10, il.get(4).getDistance(), 1);
assertEquals(42, il.get(5).getDistance(), 1);
assertEquals(7, il.get(0).getTime() / 1000);
assertEquals(69, il.get(1).getTime() / 1000);
assertEquals(128, il.get(2).getTime() / 1000);
assertEquals(9, il.get(3).getTime() / 1000);
assertEquals(7, il.get(4).getTime() / 1000);
assertEquals(30, il.get(5).getTime() / 1000);
assertEquals(85, res.getPoints().size());
}
use of com.graphhopper.config.Profile in project graphhopper by graphhopper.
the class GraphHopperTest method testCompareAlgos.
@ParameterizedTest
@ValueSource(booleans = { true, false })
public void testCompareAlgos(boolean turnCosts) {
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(turnCosts));
hopper.getCHPreparationHandler().setCHProfiles(new CHProfile(profile));
hopper.getLMPreparationHandler().setLMProfiles(new LMProfile(profile));
hopper.importOrLoad();
long seed = System.nanoTime();
Random rnd = new Random(seed);
for (int i = 0; i < 100; i++) {
BBox bounds = hopper.getGraphHopperStorage().getBounds();
double lat1 = bounds.minLat + rnd.nextDouble() * (bounds.maxLat - bounds.minLat);
double lat2 = bounds.minLat + rnd.nextDouble() * (bounds.maxLat - bounds.minLat);
double lon1 = bounds.minLon + rnd.nextDouble() * (bounds.maxLon - bounds.minLon);
double lon2 = bounds.minLon + rnd.nextDouble() * (bounds.maxLon - bounds.minLon);
GHRequest req = new GHRequest(lat1, lon1, lat2, lon2);
req.setProfile(profile);
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();
String failMessage = "seed: " + seed + ", i=" + i;
assertEquals(path.hasErrors(), pathCH.hasErrors(), failMessage);
assertEquals(path.hasErrors(), pathLM.hasErrors(), failMessage);
if (!path.hasErrors()) {
assertEquals(path.getDistance(), pathCH.getDistance(), 0.1, failMessage);
assertEquals(path.getDistance(), pathLM.getDistance(), 0.1, failMessage);
assertEquals(path.getTime(), pathCH.getTime(), failMessage);
assertEquals(path.getTime(), pathLM.getTime(), failMessage);
}
}
}
use of com.graphhopper.config.Profile in project graphhopper by graphhopper.
the class GraphHopperTest method testMonacoPathDetails.
@Test
public void testMonacoPathDetails() {
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 request = new GHRequest();
request.addPoint(new GHPoint(43.727687, 7.418737));
request.addPoint(new GHPoint(43.74958, 7.436566));
request.addPoint(new GHPoint(43.727687, 7.418737));
request.setAlgorithm(ASTAR).setProfile(profile);
request.setPathDetails(Collections.singletonList(Parameters.Details.AVERAGE_SPEED));
GHResponse rsp = hopper.route(request);
ResponsePath res = rsp.getBest();
Map<String, List<PathDetail>> details = res.getPathDetails();
assertEquals(1, details.size());
List<PathDetail> detailList = details.get(Parameters.Details.AVERAGE_SPEED);
assertEquals(9, detailList.size());
assertEquals(5.0, detailList.get(0).getValue());
assertEquals(0, detailList.get(0).getFirst());
assertEquals(3.0, detailList.get(1).getValue());
assertEquals(res.getPoints().size() - 1, detailList.get(8).getLast());
}
Aggregations