use of com.graphhopper.GHRequest in project graphhopper by graphhopper.
the class GraphHopperOSMTest method testGetPathsDirectionEnforcement6.
@Test
public void testGetPathsDirectionEnforcement6() {
// Test if query results at tower nodes are ignored
instance = createSquareGraphInstance(false);
// QueryPoints directly on TowerNodes
GHPoint start = new GHPoint(0, 0);
GHPoint via = new GHPoint(0.002, 0.000);
GHPoint end = new GHPoint(0.002, 0.002);
GHRequest req = new GHRequest().addPoint(start, 90.).addPoint(via, 270.).addPoint(end, 270.);
GHResponse response = new GHResponse();
List<Path> paths = instance.calcPaths(req, response);
assertFalse(response.hasErrors());
assertArrayEquals(new int[] { 0, 1, 2 }, paths.get(0).calcNodes().toArray());
assertArrayEquals(new int[] { 2, 3, 4 }, paths.get(1).calcNodes().toArray());
}
use of com.graphhopper.GHRequest in project graphhopper by graphhopper.
the class GraphHopperOSMTest method testLoadOSM.
@Test
public void testLoadOSM() {
GraphHopper closableInstance = new GraphHopperOSM().setStoreOnFlush(true).setEncodingManager(new EncodingManager("car")).setGraphHopperLocation(ghLoc).setDataReaderFile(testOsm);
closableInstance.importOrLoad();
GHResponse rsp = closableInstance.route(new GHRequest(51.2492152, 9.4317166, 51.2, 9.4));
assertFalse(rsp.hasErrors());
assertEquals(3, rsp.getBest().getPoints().getSize());
closableInstance.close();
// no encoding manager necessary
closableInstance = new GraphHopperOSM().setStoreOnFlush(true);
assertTrue(closableInstance.load(ghLoc));
rsp = closableInstance.route(new GHRequest(51.2492152, 9.4317166, 51.2, 9.4));
assertFalse(rsp.hasErrors());
assertEquals(3, rsp.getBest().getPoints().getSize());
closableInstance.close();
try {
rsp = closableInstance.route(new GHRequest(51.2492152, 9.4317166, 51.2, 9.4));
assertTrue(false);
} catch (Exception ex) {
assertEquals("You need to create a new GraphHopper instance as it is already closed", ex.getMessage());
}
try {
closableInstance.getLocationIndex().findClosest(51.2492152, 9.4317166, EdgeFilter.ALL_EDGES);
assertTrue(false);
} catch (Exception ex) {
assertEquals("You need to create a new LocationIndex instance as it is already closed", ex.getMessage());
}
}
use of com.graphhopper.GHRequest in project graphhopper by graphhopper.
the class GraphHopperOSMTest method testCustomFactoryForNoneCH.
@Test
public void testCustomFactoryForNoneCH() {
CarFlagEncoder carEncoder = new CarFlagEncoder();
EncodingManager em = new EncodingManager(carEncoder);
// Weighting weighting = new FastestWeighting(carEncoder);
instance = new GraphHopperOSM().setStoreOnFlush(false).setCHEnabled(false).setEncodingManager(em).setGraphHopperLocation(ghLoc).setDataReaderFile(testOsm);
final RoutingAlgorithmFactory af = new RoutingAlgorithmFactorySimple();
instance.addAlgorithmFactoryDecorator(new RoutingAlgorithmFactoryDecorator() {
@Override
public void init(CmdArgs args) {
}
@Override
public RoutingAlgorithmFactory getDecoratedAlgorithmFactory(RoutingAlgorithmFactory algoFactory, HintsMap map) {
return af;
}
@Override
public boolean isEnabled() {
return true;
}
});
instance.importOrLoad();
assertTrue(af == instance.getAlgorithmFactory(null));
// test that hints are passed to algorithm opts
final AtomicInteger cnt = new AtomicInteger(0);
instance.addAlgorithmFactoryDecorator(new RoutingAlgorithmFactoryDecorator() {
@Override
public void init(CmdArgs args) {
}
public RoutingAlgorithmFactory getDecoratedAlgorithmFactory(RoutingAlgorithmFactory algoFactory, HintsMap map) {
return new RoutingAlgorithmFactorySimple() {
@Override
public RoutingAlgorithm createAlgo(Graph g, AlgorithmOptions opts) {
cnt.addAndGet(1);
assertFalse(opts.getHints().getBool("test", true));
return super.createAlgo(g, opts);
}
};
}
@Override
public boolean isEnabled() {
return true;
}
});
GHRequest req = new GHRequest(51.2492152, 9.4317166, 51.2, 9.4);
req.getHints().put("test", false);
instance.route(req);
assertEquals(1, cnt.get());
}
use of com.graphhopper.GHRequest in project graphhopper by graphhopper.
the class GraphHopperOSMTest method testNoNPE_ifLoadNotSuccessful.
@Test
public void testNoNPE_ifLoadNotSuccessful() {
instance = new GraphHopperOSM().setStoreOnFlush(true).setEncodingManager(new EncodingManager("car"));
try {
// loading from empty directory
new File(ghLoc).mkdirs();
assertFalse(instance.load(ghLoc));
instance.route(new GHRequest(10, 40, 12, 32));
assertTrue(false);
} catch (IllegalStateException ex) {
assertEquals("Do a successful call to load or importOrLoad before routing", ex.getMessage());
}
}
use of com.graphhopper.GHRequest in project graphhopper by graphhopper.
the class GraphHopperOSMTest method testVia.
@Test
public void testVia() {
instance = new GraphHopperOSM().setStoreOnFlush(true).init(new CmdArgs().put("datareader.file", testOsm3).put("prepare.min_network_size", "1").put("graph.flag_encoders", "car")).setGraphHopperLocation(ghLoc);
instance.importOrLoad();
// A -> B -> C
GHPoint first = new GHPoint(11.1, 50);
GHPoint second = new GHPoint(12, 51);
GHPoint third = new GHPoint(11.2, 51.9);
GHResponse rsp12 = instance.route(new GHRequest().addPoint(first).addPoint(second));
assertFalse("should find 1->2", rsp12.hasErrors());
assertEquals(147930.5, rsp12.getBest().getDistance(), .1);
GHResponse rsp23 = instance.route(new GHRequest().addPoint(second).addPoint(third));
assertFalse("should find 2->3", rsp23.hasErrors());
assertEquals(176608.9, rsp23.getBest().getDistance(), .1);
GHResponse grsp = instance.route(new GHRequest().addPoint(first).addPoint(second).addPoint(third));
assertFalse("should find 1->2->3", grsp.hasErrors());
PathWrapper rsp = grsp.getBest();
assertEquals(rsp12.getBest().getDistance() + rsp23.getBest().getDistance(), rsp.getDistance(), 1e-6);
assertEquals(5, rsp.getPoints().getSize());
assertEquals(5, rsp.getInstructions().size());
assertEquals(Instruction.REACHED_VIA, rsp.getInstructions().get(1).getSign());
}
Aggregations