Search in sources :

Example 21 with PathDetail

use of com.graphhopper.util.details.PathDetail in project graphhopper by graphhopper.

the class PathTest method testCalcAverageSpeedDetailsWithShortDistances_issue1848.

@Test
public void testCalcAverageSpeedDetailsWithShortDistances_issue1848() {
    ShortestWeighting weighting = new ShortestWeighting(encoder);
    Path p = new Dijkstra(pathDetailGraph, weighting, TraversalMode.NODE_BASED).calcPath(1, 6);
    assertTrue(p.isFound());
    Map<String, List<PathDetail>> details = PathDetailsFromEdges.calcDetails(p, carManager, weighting, Arrays.asList(AVERAGE_SPEED), new PathDetailsBuilderFactory(), 0);
    assertTrue(details.size() == 1);
    List<PathDetail> averageSpeedDetails = details.get(AVERAGE_SPEED);
    assertEquals(4, averageSpeedDetails.size());
    // reverse path includes 'null' value as first
    p = new Dijkstra(pathDetailGraph, weighting, TraversalMode.NODE_BASED).calcPath(6, 1);
    assertTrue(p.isFound());
    details = PathDetailsFromEdges.calcDetails(p, carManager, weighting, Arrays.asList(AVERAGE_SPEED), new PathDetailsBuilderFactory(), 0);
    assertTrue(details.size() == 1);
    averageSpeedDetails = details.get(AVERAGE_SPEED);
    assertEquals(5, averageSpeedDetails.size());
    assertNull(averageSpeedDetails.get(0).getValue());
}
Also used : PathDetailsBuilderFactory(com.graphhopper.util.details.PathDetailsBuilderFactory) PathDetail(com.graphhopper.util.details.PathDetail) AbstractGraphStorageTester.assertPList(com.graphhopper.storage.AbstractGraphStorageTester.assertPList) ShortestWeighting(com.graphhopper.routing.weighting.ShortestWeighting) Test(org.junit.jupiter.api.Test)

Example 22 with PathDetail

use of com.graphhopper.util.details.PathDetail in project graphhopper by graphhopper.

the class PathTest method testCalcStreetNameDetails.

@Test
public void testCalcStreetNameDetails() {
    ShortestWeighting weighting = new ShortestWeighting(encoder);
    Path p = new Dijkstra(pathDetailGraph, weighting, TraversalMode.NODE_BASED).calcPath(1, 5);
    assertTrue(p.isFound());
    Map<String, List<PathDetail>> details = PathDetailsFromEdges.calcDetails(p, carManager, weighting, Arrays.asList(STREET_NAME), new PathDetailsBuilderFactory(), 0);
    assertTrue(details.size() == 1);
    List<PathDetail> streetNameDetails = details.get(STREET_NAME);
    assertTrue(details.size() == 1);
    assertEquals(4, streetNameDetails.size());
    assertEquals("1-2", streetNameDetails.get(0).getValue());
    assertEquals("2-3", streetNameDetails.get(1).getValue());
    assertEquals("3-4", streetNameDetails.get(2).getValue());
    assertEquals("4-5", streetNameDetails.get(3).getValue());
    assertEquals(0, streetNameDetails.get(0).getFirst());
    assertEquals(1, streetNameDetails.get(1).getFirst());
    assertEquals(2, streetNameDetails.get(2).getFirst());
    assertEquals(3, streetNameDetails.get(3).getFirst());
    assertEquals(4, streetNameDetails.get(3).getLast());
}
Also used : PathDetailsBuilderFactory(com.graphhopper.util.details.PathDetailsBuilderFactory) PathDetail(com.graphhopper.util.details.PathDetail) AbstractGraphStorageTester.assertPList(com.graphhopper.storage.AbstractGraphStorageTester.assertPList) ShortestWeighting(com.graphhopper.routing.weighting.ShortestWeighting) Test(org.junit.jupiter.api.Test)

Example 23 with PathDetail

use of com.graphhopper.util.details.PathDetail in project graphhopper by graphhopper.

the class RouteResourceClientHCTest method testPathDetails.

@ParameterizedTest
@EnumSource(value = TestParam.class)
public void testPathDetails(TestParam p) {
    GraphHopperWeb gh = createGH(p);
    GHRequest req = new GHRequest().addPoint(new GHPoint(42.507065, 1.529846)).addPoint(new GHPoint(42.510383, 1.533392)).setProfile("my_car");
    req.getPathDetails().add("average_speed");
    GHResponse res = gh.route(req);
    assertFalse(res.hasErrors(), "errors:" + res.getErrors().toString());
    ResponsePath alt = res.getBest();
    assertEquals(1, alt.getPathDetails().size());
    List<PathDetail> details = alt.getPathDetails().get("average_speed");
    assertFalse(details.isEmpty());
    assertTrue((Double) details.get(0).getValue() > 20);
    assertTrue((Double) details.get(0).getValue() < 70);
}
Also used : ResponsePath(com.graphhopper.ResponsePath) PathDetail(com.graphhopper.util.details.PathDetail) GHRequest(com.graphhopper.GHRequest) GraphHopperWeb(com.graphhopper.api.GraphHopperWeb) GHPoint(com.graphhopper.util.shapes.GHPoint) GHResponse(com.graphhopper.GHResponse) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 24 with PathDetail

use of com.graphhopper.util.details.PathDetail in project graphhopper by graphhopper.

the class RouteResourceTest method testPathDetails.

@Test
public void testPathDetails() {
    GraphHopperWeb client = new GraphHopperWeb(clientUrl(app, "/route"));
    GHRequest request = new GHRequest(42.554851, 1.536198, 42.510071, 1.548128).setProfile("my_car");
    request.setPathDetails(Arrays.asList("average_speed", "edge_id", "time"));
    GHResponse rsp = client.route(request);
    assertFalse(rsp.hasErrors(), rsp.getErrors().toString());
    assertTrue(rsp.getErrors().isEmpty(), rsp.getErrors().toString());
    Map<String, List<PathDetail>> pathDetails = rsp.getBest().getPathDetails();
    assertFalse(pathDetails.isEmpty());
    assertTrue(pathDetails.containsKey("average_speed"));
    assertTrue(pathDetails.containsKey("edge_id"));
    assertTrue(pathDetails.containsKey("time"));
    List<PathDetail> averageSpeedList = pathDetails.get("average_speed");
    assertEquals(13, averageSpeedList.size());
    assertEquals(30.0, averageSpeedList.get(0).getValue());
    assertEquals(14, averageSpeedList.get(0).getLength());
    assertEquals(60.0, averageSpeedList.get(1).getValue());
    assertEquals(5, averageSpeedList.get(1).getLength());
    List<PathDetail> edgeIdDetails = pathDetails.get("edge_id");
    assertEquals(77, edgeIdDetails.size());
    assertEquals(882L, edgeIdDetails.get(0).getValue());
    assertEquals(2, edgeIdDetails.get(0).getLength());
    assertEquals(883L, edgeIdDetails.get(1).getValue());
    assertEquals(8, edgeIdDetails.get(1).getLength());
    long expectedTime = rsp.getBest().getTime();
    long actualTime = 0;
    List<PathDetail> timeDetails = pathDetails.get("time");
    for (PathDetail pd : timeDetails) {
        actualTime += (Long) pd.getValue();
    }
    assertEquals(expectedTime, actualTime);
}
Also used : PathDetail(com.graphhopper.util.details.PathDetail) GHRequest(com.graphhopper.GHRequest) InstructionList(com.graphhopper.util.InstructionList) GraphHopperWeb(com.graphhopper.api.GraphHopperWeb) GHResponse(com.graphhopper.GHResponse) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 25 with PathDetail

use of com.graphhopper.util.details.PathDetail in project graphhopper by graphhopper.

the class RouteResourceTest method testPathDetailsRoadClass.

@Test
public void testPathDetailsRoadClass() {
    GraphHopperWeb client = new GraphHopperWeb(clientUrl(app, "/route"));
    GHRequest request = new GHRequest(42.546757, 1.528645, 42.520573, 1.557999).setProfile("my_car");
    request.setPathDetails(Arrays.asList(RoadClass.KEY, Surface.KEY, RoadEnvironment.KEY, "average_speed", RoadClassLink.KEY));
    GHResponse rsp = client.route(request);
    assertFalse(rsp.hasErrors(), rsp.getErrors().toString());
    assertEquals(4, rsp.getBest().getPathDetails().get(RoadClass.KEY).size());
    assertEquals(RoadClass.PRIMARY.toString(), rsp.getBest().getPathDetails().get(RoadClass.KEY).get(3).getValue());
    assertFalse((Boolean) rsp.getBest().getPathDetails().get(RoadClassLink.KEY).get(0).getValue());
    List<PathDetail> roadEnvList = rsp.getBest().getPathDetails().get(RoadEnvironment.KEY);
    assertEquals(10, roadEnvList.size());
    assertEquals(RoadEnvironment.ROAD.toString(), roadEnvList.get(0).getValue());
    assertEquals(RoadEnvironment.TUNNEL.toString(), roadEnvList.get(6).getValue());
}
Also used : PathDetail(com.graphhopper.util.details.PathDetail) GHRequest(com.graphhopper.GHRequest) GraphHopperWeb(com.graphhopper.api.GraphHopperWeb) GHResponse(com.graphhopper.GHResponse) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

PathDetail (com.graphhopper.util.details.PathDetail)30 Test (org.junit.jupiter.api.Test)14 PathDetailsBuilderFactory (com.graphhopper.util.details.PathDetailsBuilderFactory)10 ShortestWeighting (com.graphhopper.routing.weighting.ShortestWeighting)8 AbstractGraphStorageTester.assertPList (com.graphhopper.storage.AbstractGraphStorageTester.assertPList)8 GHPoint (com.graphhopper.util.shapes.GHPoint)8 GHRequest (com.graphhopper.GHRequest)7 GHResponse (com.graphhopper.GHResponse)7 ResponsePath (com.graphhopper.ResponsePath)5 List (java.util.List)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 GraphHopperWeb (com.graphhopper.api.GraphHopperWeb)3 PathDetailsFromEdges (com.graphhopper.util.details.PathDetailsFromEdges)3 GTFSFeed (com.conveyal.gtfs.GTFSFeed)2 Stop (com.conveyal.gtfs.model.Stop)2 StopTime (com.conveyal.gtfs.model.StopTime)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 Iterables (com.google.common.collect.Iterables)2 Lists (com.google.common.collect.Lists)2 Maps (com.google.common.collect.Maps)2