use of com.graphhopper.config.Profile in project graphhopper by graphhopper.
the class GraphHopperOSMTest method testLoadingLMAndCHProfiles.
@Test
public void testLoadingLMAndCHProfiles() {
GraphHopper hopper = new GraphHopper().setGraphHopperLocation(ghLoc).setOSMFile(testOsm).setProfiles(new Profile("car").setVehicle("car").setWeighting("fastest"));
hopper.getLMPreparationHandler().setLMProfiles(new LMProfile("car"));
hopper.getCHPreparationHandler().setCHProfiles(new CHProfile("car"));
hopper.importOrLoad();
hopper.close();
// load without problem
hopper = new GraphHopper().setProfiles(new Profile("car").setVehicle("car").setWeighting("fastest"));
hopper.getLMPreparationHandler().setLMProfiles(new LMProfile("car"));
hopper.getCHPreparationHandler().setCHProfiles(new CHProfile("car"));
hopper.setGraphHopperLocation(ghLoc);
assertTrue(hopper.load());
hopper.close();
// problem: changed weighting in profile although LM preparation was enabled
hopper = new GraphHopper().setProfiles(new Profile("car").setVehicle("car").setWeighting("shortest"));
hopper.getLMPreparationHandler().setLMProfiles(new LMProfile("car"));
hopper.setGraphHopperLocation(ghLoc);
// do not load CH
try {
assertFalse(hopper.load());
fail("load should fail");
} catch (Exception ex) {
assertEquals("LM preparation of car already exists in storage and doesn't match configuration", ex.getMessage());
} finally {
hopper.close();
}
// problem: changed weighting in profile although CH preparation was enabled
hopper = new GraphHopper().setProfiles(new Profile("car").setVehicle("car").setWeighting("shortest"));
hopper.getCHPreparationHandler().setCHProfiles(new CHProfile("car"));
hopper.setGraphHopperLocation(ghLoc);
// do not load LM
try {
assertFalse(hopper.load());
fail("load should fail");
} catch (Exception ex) {
assertEquals("CH preparation of car already exists in storage and doesn't match configuration", ex.getMessage());
} finally {
hopper.close();
}
}
use of com.graphhopper.config.Profile in project graphhopper by graphhopper.
the class GraphHopperOSMTest method testSortedGraph_noCH.
@Test
public void testSortedGraph_noCH() {
final String profile = "profile";
final String vehicle = "car";
final String weighting = "fastest";
instance = new GraphHopper().setProfiles(new Profile(profile).setVehicle(vehicle).setWeighting(weighting)).setStoreOnFlush(false).setSortGraph(true).setGraphHopperLocation(ghLoc).setOSMFile(testOsm);
instance.importOrLoad();
ResponsePath rsp = instance.route(new GHRequest(51.2492152, 9.4317166, 51.2, 9.4).setProfile(profile).setAlgorithm(DIJKSTRA_BI)).getBest();
assertFalse(rsp.hasErrors());
assertEquals(3, rsp.getPoints().size());
assertEquals(new GHPoint(51.24921503475044, 9.431716451757769), rsp.getPoints().get(0));
assertEquals(new GHPoint(52.0, 9.0), rsp.getPoints().get(1));
assertEquals(new GHPoint(51.199999850988384, 9.39999970197677), rsp.getPoints().get(2));
GHRequest req = new GHRequest(51.2492152, 9.4317166, 51.2, 9.4);
req.setProfile(profile);
boolean old = instance.getEncodingManager().isEnableInstructions();
req.putHint("instructions", true);
instance.route(req);
assertEquals(old, instance.getEncodingManager().isEnableInstructions());
req.putHint("instructions", false);
instance.route(req);
assertEquals(old, instance.getEncodingManager().isEnableInstructions(), "route method should not change instance field");
}
use of com.graphhopper.config.Profile in project graphhopper by graphhopper.
the class GraphHopperOSMTest method testPrepare.
@Test
public void testPrepare() {
final String profile = "profile";
final String vehicle = "car";
final String weighting = "shortest";
instance = new GraphHopper().setStoreOnFlush(false).setProfiles(new Profile(profile).setVehicle(vehicle).setWeighting(weighting)).setGraphHopperLocation(ghLoc).setOSMFile(testOsm);
instance.getCHPreparationHandler().setCHProfiles(new CHProfile(profile));
instance.importOrLoad();
GHResponse rsp = instance.route(new GHRequest(51.2492152, 9.4317166, 51.2, 9.4).setProfile(profile).setAlgorithm(DIJKSTRA_BI));
assertFalse(rsp.hasErrors());
assertEquals(Helper.createPointList(51.249215, 9.431716, 52.0, 9.0, 51.2, 9.4), rsp.getBest().getPoints());
assertEquals(3, rsp.getBest().getPoints().size());
}
use of com.graphhopper.config.Profile in project graphhopper by graphhopper.
the class GraphHopperOSMTest method testFootOnly.
@Test
public void testFootOnly() {
// now only footable ways are imported => no A D C and B D E => the other both ways have pillar nodes!
final String profile = "foot_profile";
final String vehicle = "foot";
final String weighting = "fastest";
instance = new GraphHopper().setStoreOnFlush(false).setProfiles(new Profile(profile).setVehicle(vehicle).setWeighting(weighting)).setGraphHopperLocation(ghLoc).setOSMFile(testOsm3);
instance.getCHPreparationHandler().setCHProfiles(new CHProfile(profile));
instance.importOrLoad();
((LocationIndexTree) instance.getLocationIndex()).setMaxRegionSearch(300);
assertEquals(2, instance.getGraphHopperStorage().getNodes());
assertEquals(2, instance.getGraphHopperStorage().getAllEdges().length());
// A to E only for foot
GHResponse grsp = instance.route(new GHRequest(11.1, 50, 11.19, 52).setProfile(profile));
assertFalse(grsp.hasErrors());
ResponsePath rsp = grsp.getBest();
// the last points snaps to the edge
assertEquals(Helper.createPointList(11.1, 50, 10, 51, 11.194015, 51.995013), rsp.getPoints());
}
use of com.graphhopper.config.Profile in project graphhopper by graphhopper.
the class OSMReaderTest method testRoutingRequestFails_issue665.
@Test
public void testRoutingRequestFails_issue665() {
GraphHopper hopper = new GraphHopper().setOSMFile(getClass().getResource(file7).getFile()).setProfiles(new Profile("profile1").setVehicle("car").setWeighting("fastest"), new Profile("profile2").setVehicle("motorcycle").setWeighting("curvature")).setGraphHopperLocation(dir);
hopper.importOrLoad();
GHRequest req = new GHRequest(48.977277, 8.256896, 48.978876, 8.254884).setProfile("profile2");
GHResponse ghRsp = hopper.route(req);
assertFalse(ghRsp.hasErrors(), ghRsp.getErrors().toString());
}
Aggregations