Search in sources :

Example 1 with PathWrapper

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

the class RoundTripRoutingTemplate method isReady.

@Override
public boolean isReady(PathMerger pathMerger, Translation tr) {
    altResponse = new PathWrapper();
    altResponse.setWaypoints(getWaypoints());
    ghResponse.add(altResponse);
    pathMerger.doWork(altResponse, pathList, tr);
    // with potentially retrying, including generating new route points, for now disabled
    return true;
}
Also used : PathWrapper(com.graphhopper.PathWrapper)

Example 2 with PathWrapper

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

the class GraphHopperWebTest method testReadEncoded.

// see also GraphHopperServletIT.testGraphHopperWeb for real routes against local jetty service    
@Test
public void testReadEncoded() throws Exception {
    Downloader downloader = new Downloader("GraphHopper Test") {

        @Override
        public InputStream fetch(HttpURLConnection conn, boolean readErrorStreamNoException) throws IOException {
            return getClass().getResourceAsStream("test_encoded.json");
        }
    };
    GraphHopperWeb instance = new GraphHopperWeb();
    instance.setDownloader(downloader);
    GHResponse rsp = instance.route(new GHRequest(52.47379, 13.362808, 52.4736925, 13.3904394));
    PathWrapper arsp = rsp.getBest();
    assertEquals(2138.3, arsp.getDistance(), 1e-1);
    assertEquals(17, arsp.getPoints().getSize());
    assertEquals(5, arsp.getInstructions().getSize());
    assertEquals("(0,Geradeaus auf A 100,1268.519329705091,65237)", arsp.getInstructions().get(0).toString());
    assertEquals(11, arsp.getInstructions().get(0).getPoints().size());
    assertEquals(43.73595, arsp.getWaypoints().getLat(0), 1e-4);
    assertEquals(7.42015, arsp.getWaypoints().getLon(0), 1e-4);
    assertEquals(43.73761, arsp.getWaypoints().getLat(1), 1e-4);
}
Also used : HttpURLConnection(java.net.HttpURLConnection) PathWrapper(com.graphhopper.PathWrapper) GHRequest(com.graphhopper.GHRequest) Downloader(com.graphhopper.util.Downloader) GHResponse(com.graphhopper.GHResponse) Test(org.junit.Test)

Example 3 with PathWrapper

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

the class ShapeFileReaderTest method testOneWay.

@Test
public void testOneWay() {
    // We setup 2 points very close together on a one-way street.
    // As its a one way street, the ordering of the start and end requires
    // going around the block to serve them.
    // As the scenario is simple, we should get the same results from both
    // shapefile and pbf.
    // We should also get route distance to be many times physical distance
    FromToPair pair = new FromToPair(35.898324, 14.510729, 35.898328, 14.510681);
    PathWrapper shp = pair.getPath(hopperShp, true);
    PathWrapper pbf = pair.getPath(hopperPbf, true);
    double metresShp = shp.getDistance();
    double metresPbf = pbf.getDistance();
    // should be many times the physical separation between the points (as
    // we had to go round the block)
    double straightLineDistMetres = distCalc.calcDist(pair.from.lat, pair.from.lon, pair.to.lat, pair.to.lon);
    assertTrue(metresShp > straightLineDistMetres * 25);
    // should be the same to within 1 cm
    assertEquals(metresShp, metresPbf, 0.01);
}
Also used : PathWrapper(com.graphhopper.PathWrapper) Test(org.junit.Test)

Example 4 with PathWrapper

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

the class ShapeFileReaderTest method testTravelTimesBetweenRandomLocations.

@Test
public void testTravelTimesBetweenRandomLocations() {
    int nTests = 200;
    final Random random = new Random(123);
    final GHPoint min = new GHPoint(35.882931, 14.403076);
    final GHPoint max = new GHPoint(35.913523, 14.448566);
    class RandPointGenerator {

        double rand(double min, double max) {
            return min + random.nextDouble() * (max - min);
        }

        GHPoint randPoint() {
            return new GHPoint(rand(min.lat, max.lat), rand(min.lon, max.lon));
        }
    }
    RandPointGenerator pointGenerator = new RandPointGenerator();
    int nbFails = 0;
    DoubleSummaryStatistics stats = new DoubleSummaryStatistics();
    for (int i = 0; i < nTests; i++) {
        FromToPair pair = new FromToPair(pointGenerator.randPoint(), pointGenerator.randPoint());
        // paths from random points can fail to don't assert on failure
        PathWrapper shpPath = pair.getPath(hopperShp, false);
        PathWrapper pbfPath = pair.getPath(hopperPbf, false);
        // the road network)
        if (shpPath == null || pbfPath == null) {
            nbFails++;
            continue;
        }
        double shpSecs = getSecondsTravel(shpPath);
        double pbfSecs = getSecondsTravel(pbfPath);
        double frac = shpSecs / pbfSecs;
        double percentageDeviation = Math.abs(1.0 - frac) * 100;
        stats.accept(percentageDeviation);
    }
    assertTrue("Number of fails should be small for the chosen box", nbFails < nTests / 3);
    // Test mean fraction. There will be some deviation as not all tags are
    // considered etc,
    // but we expect it to be small for a large number of tests
    double mean = stats.getAverage();
    assertTrue("Should have a mean deviation in travel times of less than 1%", mean < 1.0);
}
Also used : Random(java.util.Random) PathWrapper(com.graphhopper.PathWrapper) DoubleSummaryStatistics(java.util.DoubleSummaryStatistics) GHPoint(com.graphhopper.util.shapes.GHPoint) GHPoint(com.graphhopper.util.shapes.GHPoint) Test(org.junit.Test)

Example 5 with PathWrapper

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

the class GraphHopperWebIT method testSimpleRoute.

@Test
public void testSimpleRoute() {
    // https://graphhopper.com/maps/?point=49.6724%2C11.3494&point=49.655%2C11.418
    GHRequest req = new GHRequest().addPoint(new GHPoint(49.6724, 11.3494)).addPoint(new GHPoint(49.6550, 11.4180));
    req.getHints().put("elevation", false);
    req.getHints().put("instructions", true);
    req.getHints().put("calc_points", true);
    GHResponse res = gh.route(req);
    assertFalse("errors:" + res.getErrors().toString(), res.hasErrors());
    PathWrapper alt = res.getBest();
    isBetween(200, 250, alt.getPoints().size());
    isBetween(11000, 12000, alt.getDistance());
    isBetween(310, 320, alt.getAscend());
    isBetween(235, 245, alt.getDescend());
    isBetween(1000, 1500, alt.getRouteWeight());
    // change vehicle
    res = gh.route(new GHRequest(49.6724, 11.3494, 49.6550, 11.4180).setVehicle("bike"));
    alt = res.getBest();
    assertFalse("errors:" + res.getErrors().toString(), res.hasErrors());
    isBetween(9000, 9500, alt.getDistance());
}
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

PathWrapper (com.graphhopper.PathWrapper)19 GHPoint (com.graphhopper.util.shapes.GHPoint)12 GHResponse (com.graphhopper.GHResponse)9 Test (org.junit.Test)9 GHRequest (com.graphhopper.GHRequest)8 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 PointList (com.graphhopper.util.PointList)2 PathDetail (com.graphhopper.util.details.PathDetail)2 JSONArray (org.json.JSONArray)2 JSONObject (org.json.JSONObject)2 GTFSFeed (com.conveyal.gtfs.GTFSFeed)1 Stop (com.conveyal.gtfs.model.Stop)1 StopTime (com.conveyal.gtfs.model.StopTime)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 GtfsRealtime (com.google.transit.realtime.GtfsRealtime)1 GraphHopperAPI (com.graphhopper.GraphHopperAPI)1 Trip (com.graphhopper.Trip)1 Fares (com.graphhopper.gtfs.fare.Fares)1 Label.reverseEdges (com.graphhopper.reader.gtfs.Label.reverseEdges)1