Search in sources :

Example 61 with GHRequest

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());
}
Also used : CmdArgs(com.graphhopper.util.CmdArgs) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GHRequest(com.graphhopper.GHRequest) Test(org.junit.Test)

Example 62 with GHRequest

use of com.graphhopper.GHRequest in project graphhopper by graphhopper.

the class GraphHopperWebIT method testRetrieveOnlyStreetname.

@Test
public void testRetrieveOnlyStreetname() {
    GHRequest req = new GHRequest().addPoint(new GHPoint(52.261434, 13.485718)).addPoint(new GHPoint(52.399067, 13.469238));
    GHResponse res = gh.route(req);
    assertEquals("Continue onto B 96", res.getBest().getInstructions().get(4).getName());
    req.getHints().put("turn_description", false);
    res = gh.route(req);
    assertEquals("B 96", res.getBest().getInstructions().get(4).getName());
}
Also used : GHRequest(com.graphhopper.GHRequest) GHPoint(com.graphhopper.util.shapes.GHPoint) GHResponse(com.graphhopper.GHResponse) Test(org.junit.Test)

Example 63 with GHRequest

use of com.graphhopper.GHRequest in project graphhopper by graphhopper.

the class GraphHopperWebIT method testTimeout.

@Test
public void testTimeout() {
    GHRequest req = new GHRequest().addPoint(new GHPoint(49.6724, 11.3494)).addPoint(new GHPoint(49.6550, 11.4180));
    GHResponse res = gh.route(req);
    assertFalse("errors:" + res.getErrors().toString(), res.hasErrors());
    req.getHints().put(GraphHopperWeb.TIMEOUT, 1);
    try {
        res = gh.route(req);
        fail();
    } catch (RuntimeException e) {
        assertEquals(SocketTimeoutException.class, e.getCause().getClass());
    }
}
Also used : SocketTimeoutException(java.net.SocketTimeoutException) GHRequest(com.graphhopper.GHRequest) GHPoint(com.graphhopper.util.shapes.GHPoint) GHResponse(com.graphhopper.GHResponse) Test(org.junit.Test)

Example 64 with GHRequest

use of com.graphhopper.GHRequest in project graphhopper by graphhopper.

the class GraphHopperWebIT method doNotReadFinishInstruction.

@Test
public void doNotReadFinishInstruction() {
    GHRequest req = new GHRequest().addPoint(new GHPoint(52.261434, 13.485718)).addPoint(new GHPoint(52.399067, 13.469238));
    req.getHints().put("turn_description", false);
    GHResponse res = gh.route(req);
    InstructionList instructions = res.getBest().getInstructions();
    String finishInstructionName = instructions.get(instructions.size() - 1).getName();
    assertEquals("", finishInstructionName);
}
Also used : InstructionList(com.graphhopper.util.InstructionList) GHRequest(com.graphhopper.GHRequest) GHPoint(com.graphhopper.util.shapes.GHPoint) GHResponse(com.graphhopper.GHResponse) Test(org.junit.Test)

Example 65 with GHRequest

use of com.graphhopper.GHRequest in project graphhopper by graphhopper.

the class GraphHopperWebIT method testAlternativeRoute.

@Test
public void testAlternativeRoute() {
    // https://graphhopper.com/maps/?point=52.042989%2C10.373926&point=52.042289%2C10.384043&algorithm=alternative_route&ch.disable=true
    GHRequest req = new GHRequest().addPoint(new GHPoint(52.042989, 10.373926)).addPoint(new GHPoint(52.042289, 10.384043));
    req.setAlgorithm("alternative_route");
    req.getHints().put("instructions", true);
    req.getHints().put("calc_points", true);
    req.getHints().put("ch.disable", true);
    GHResponse res = gh.route(req);
    assertFalse("errors:" + res.getErrors().toString(), res.hasErrors());
    List<PathWrapper> paths = res.getAll();
    assertEquals(2, paths.size());
    PathWrapper path = paths.get(0);
    isBetween(5, 20, path.getPoints().size());
    isBetween(1000, 1100, path.getDistance());
    assertEquals("Wiesenstraße", path.getDescription().get(0));
    path = paths.get(1);
    isBetween(20, 30, path.getPoints().size());
    isBetween(800, 900, path.getDistance());
    assertEquals("Jacobistraße", path.getDescription().get(0));
}
Also used : PathWrapper(com.graphhopper.PathWrapper) GHRequest(com.graphhopper.GHRequest) GHPoint(com.graphhopper.util.shapes.GHPoint) GHResponse(com.graphhopper.GHResponse) Test(org.junit.Test)

Aggregations

GHRequest (com.graphhopper.GHRequest)106 GHResponse (com.graphhopper.GHResponse)86 GHPoint (com.graphhopper.util.shapes.GHPoint)59 Test (org.junit.Test)35 Test (org.junit.jupiter.api.Test)35 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)26 GraphHopperWeb (com.graphhopper.api.GraphHopperWeb)22 ResponsePath (com.graphhopper.ResponsePath)13 EnumSource (org.junit.jupiter.params.provider.EnumSource)11 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)9 JsonNode (com.fasterxml.jackson.databind.JsonNode)8 PathWrapper (com.graphhopper.PathWrapper)8 GraphHopper (com.graphhopper.GraphHopper)7 InstructionList (com.graphhopper.util.InstructionList)7 PathDetail (com.graphhopper.util.details.PathDetail)7 GraphHopperAPI (com.graphhopper.GraphHopperAPI)6 Profile (com.graphhopper.config.Profile)5 Graph (com.graphhopper.storage.Graph)5 NodeAccess (com.graphhopper.storage.NodeAccess)5 LMProfile (com.graphhopper.config.LMProfile)4