Search in sources :

Example 1 with PathDetailsBuilderFactory

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

the class PathTest method testCalcTimeDetails.

@Test
public void testCalcTimeDetails() {
    Path p = new Dijkstra(pathDetailGraph, new ShortestWeighting(encoder), TraversalMode.NODE_BASED).calcPath(1, 5);
    assertTrue(p.isFound());
    Map<String, List<PathDetail>> details = p.calcDetails(Arrays.asList(new String[] { TIME }), new PathDetailsBuilderFactory(), 0);
    assertTrue(details.size() == 1);
    List<PathDetail> timeDetails = details.get(TIME);
    assertEquals(4, timeDetails.size());
    assertEquals(400L, timeDetails.get(0).getValue());
    assertEquals(200L, timeDetails.get(1).getValue());
    assertEquals(1800L, timeDetails.get(2).getValue());
    assertEquals(400L, timeDetails.get(3).getValue());
    assertEquals(0, timeDetails.get(0).getFirst());
    assertEquals(1, timeDetails.get(1).getFirst());
    assertEquals(2, timeDetails.get(2).getFirst());
    assertEquals(3, timeDetails.get(3).getFirst());
    assertEquals(4, timeDetails.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.Test)

Example 2 with PathDetailsBuilderFactory

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

the class PathTest method testCalcEdgeIdDetails.

@Test
public void testCalcEdgeIdDetails() {
    Path p = new Dijkstra(pathDetailGraph, new ShortestWeighting(encoder), TraversalMode.NODE_BASED).calcPath(1, 5);
    assertTrue(p.isFound());
    Map<String, List<PathDetail>> details = p.calcDetails(Arrays.asList(new String[] { EDGE_ID }), new PathDetailsBuilderFactory(), 0);
    assertTrue(details.size() == 1);
    List<PathDetail> edgeIdDetails = details.get(EDGE_ID);
    assertEquals(4, edgeIdDetails.size());
    assertEquals(0, edgeIdDetails.get(0).getValue());
    // This is out of order because we don't create the edges in order
    assertEquals(2, edgeIdDetails.get(1).getValue());
    assertEquals(3, edgeIdDetails.get(2).getValue());
    assertEquals(1, edgeIdDetails.get(3).getValue());
    assertEquals(0, edgeIdDetails.get(0).getFirst());
    assertEquals(1, edgeIdDetails.get(1).getFirst());
    assertEquals(2, edgeIdDetails.get(2).getFirst());
    assertEquals(3, edgeIdDetails.get(3).getFirst());
    assertEquals(4, edgeIdDetails.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.Test)

Example 3 with PathDetailsBuilderFactory

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

the class PathSimplificationTest method testScenario.

@Test
public void testScenario() {
    Graph g = new GraphBuilder(carManager).create();
    // 0-1-2
    // | | |
    // 3-4-5  9-10
    // | | |  |
    // 6-7-8--*
    NodeAccess na = g.getNodeAccess();
    na.setNode(0, 1.2, 1.0);
    na.setNode(1, 1.2, 1.1);
    na.setNode(2, 1.2, 1.2);
    na.setNode(3, 1.1, 1.0);
    na.setNode(4, 1.1, 1.1);
    na.setNode(5, 1.1, 1.2);
    na.setNode(9, 1.1, 1.3);
    na.setNode(10, 1.1, 1.4);
    na.setNode(6, 1.0, 1.0);
    na.setNode(7, 1.0, 1.1);
    na.setNode(8, 1.0, 1.2);
    ReaderWay w = new ReaderWay(1);
    w.setTag("highway", "tertiary");
    w.setTag("maxspeed", "10");
    EdgeIteratorState tmpEdge;
    tmpEdge = g.edge(0, 1, 10000, true).setName("0-1");
    tmpEdge.setFlags(carManager.handleWayTags(w, carManager.acceptWay(w), 0));
    tmpEdge = g.edge(1, 2, 11000, true).setName("1-2");
    tmpEdge.setFlags(carManager.handleWayTags(w, carManager.acceptWay(w), 0));
    w.setTag("maxspeed", "20");
    tmpEdge = g.edge(0, 3, 11000, true);
    tmpEdge.setFlags(carManager.handleWayTags(w, carManager.acceptWay(w), 0));
    tmpEdge = g.edge(1, 4, 10000, true).setName("1-4");
    tmpEdge.setFlags(carManager.handleWayTags(w, carManager.acceptWay(w), 0));
    tmpEdge = g.edge(2, 5, 11000, true).setName("5-2");
    tmpEdge.setFlags(carManager.handleWayTags(w, carManager.acceptWay(w), 0));
    w.setTag("maxspeed", "30");
    tmpEdge = g.edge(3, 6, 11000, true).setName("3-6");
    tmpEdge.setFlags(carManager.handleWayTags(w, carManager.acceptWay(w), 0));
    tmpEdge = g.edge(4, 7, 10000, true).setName("4-7");
    tmpEdge.setFlags(carManager.handleWayTags(w, carManager.acceptWay(w), 0));
    tmpEdge = g.edge(5, 8, 10000, true).setName("5-8");
    tmpEdge.setFlags(carManager.handleWayTags(w, carManager.acceptWay(w), 0));
    w.setTag("maxspeed", "40");
    tmpEdge = g.edge(6, 7, 11000, true).setName("6-7");
    tmpEdge.setFlags(carManager.handleWayTags(w, carManager.acceptWay(w), 0));
    tmpEdge = g.edge(7, 8, 10000, true);
    PointList list = new PointList();
    list.add(1.0, 1.15);
    list.add(1.0, 1.16);
    tmpEdge.setWayGeometry(list);
    tmpEdge.setName("7-8");
    tmpEdge.setFlags(carManager.handleWayTags(w, carManager.acceptWay(w), 0));
    w.setTag("maxspeed", "50");
    // missing edge name
    tmpEdge = g.edge(9, 10, 10000, true);
    tmpEdge.setFlags(carManager.handleWayTags(w, carManager.acceptWay(w), 0));
    tmpEdge = g.edge(8, 9, 20000, true);
    list.clear();
    list.add(1.0, 1.3);
    list.add(1.0, 1.3001);
    list.add(1.0, 1.3002);
    list.add(1.0, 1.3003);
    tmpEdge.setName("8-9");
    tmpEdge.setWayGeometry(list);
    tmpEdge.setFlags(carManager.handleWayTags(w, carManager.acceptWay(w), 0));
    // Path is: [0 0-1, 3 1-4, 6 4-7, 9 7-8, 11 8-9, 10 9-10]
    Path p = new Dijkstra(g, new ShortestWeighting(carEncoder), tMode).calcPath(0, 10);
    InstructionList wayList = p.calcInstructions(usTR);
    Map<String, List<PathDetail>> details = p.calcDetails(Arrays.asList(DETAILS.AVERAGE_SPEED), new PathDetailsBuilderFactory(), 0);
    PathWrapper pathWrapper = new PathWrapper();
    pathWrapper.setInstructions(wayList);
    pathWrapper.addPathDetails(details);
    pathWrapper.setPoints(p.calcPoints());
    int numberOfPoints = p.calcPoints().size();
    DouglasPeucker douglasPeucker = new DouglasPeucker();
    // Do not simplify anything
    douglasPeucker.setMaxDistance(0);
    PathSimplification ps = new PathSimplification(pathWrapper, douglasPeucker, true);
    ps.simplify();
    assertEquals(numberOfPoints, pathWrapper.getPoints().size());
    pathWrapper = new PathWrapper();
    pathWrapper.setInstructions(wayList);
    pathWrapper.addPathDetails(details);
    pathWrapper.setPoints(p.calcPoints());
    douglasPeucker.setMaxDistance(100000000);
    ps = new PathSimplification(pathWrapper, douglasPeucker, true);
    ps.simplify();
    assertTrue(numberOfPoints > pathWrapper.getPoints().size());
}
Also used : Path(com.graphhopper.routing.Path) NodeAccess(com.graphhopper.storage.NodeAccess) ReaderWay(com.graphhopper.reader.ReaderWay) ShortestWeighting(com.graphhopper.routing.weighting.ShortestWeighting) Dijkstra(com.graphhopper.routing.Dijkstra) Graph(com.graphhopper.storage.Graph) PathWrapper(com.graphhopper.PathWrapper) PathDetailsBuilderFactory(com.graphhopper.util.details.PathDetailsBuilderFactory) GraphBuilder(com.graphhopper.storage.GraphBuilder) List(java.util.List) Test(org.junit.Test)

Example 4 with PathDetailsBuilderFactory

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

the class PathTest method testCalcStreetNameDetails.

@Test
public void testCalcStreetNameDetails() {
    Path p = new Dijkstra(pathDetailGraph, new ShortestWeighting(encoder), TraversalMode.NODE_BASED).calcPath(1, 5);
    assertTrue(p.isFound());
    Map<String, List<PathDetail>> details = p.calcDetails(Arrays.asList(new String[] { 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.Test)

Example 5 with PathDetailsBuilderFactory

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

the class PathTest method testCalcAverageSpeedDetails.

@Test
public void testCalcAverageSpeedDetails() {
    Path p = new Dijkstra(pathDetailGraph, new ShortestWeighting(encoder), TraversalMode.NODE_BASED).calcPath(1, 5);
    assertTrue(p.isFound());
    Map<String, List<PathDetail>> details = p.calcDetails(Arrays.asList(new String[] { AVERAGE_SPEED }), new PathDetailsBuilderFactory(), 0);
    assertTrue(details.size() == 1);
    List<PathDetail> averageSpeedDetails = details.get(AVERAGE_SPEED);
    assertEquals(4, averageSpeedDetails.size());
    assertEquals(45.0, averageSpeedDetails.get(0).getValue());
    assertEquals(90.0, averageSpeedDetails.get(1).getValue());
    assertEquals(10.0, averageSpeedDetails.get(2).getValue());
    assertEquals(45.0, averageSpeedDetails.get(3).getValue());
    assertEquals(0, averageSpeedDetails.get(0).getFirst());
    assertEquals(1, averageSpeedDetails.get(1).getFirst());
    assertEquals(2, averageSpeedDetails.get(2).getFirst());
    assertEquals(3, averageSpeedDetails.get(3).getFirst());
    assertEquals(4, averageSpeedDetails.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.Test)

Aggregations

ShortestWeighting (com.graphhopper.routing.weighting.ShortestWeighting)5 PathDetailsBuilderFactory (com.graphhopper.util.details.PathDetailsBuilderFactory)5 Test (org.junit.Test)5 AbstractGraphStorageTester.assertPList (com.graphhopper.storage.AbstractGraphStorageTester.assertPList)4 PathDetail (com.graphhopper.util.details.PathDetail)4 PathWrapper (com.graphhopper.PathWrapper)1 ReaderWay (com.graphhopper.reader.ReaderWay)1 Dijkstra (com.graphhopper.routing.Dijkstra)1 Path (com.graphhopper.routing.Path)1 Graph (com.graphhopper.storage.Graph)1 GraphBuilder (com.graphhopper.storage.GraphBuilder)1 NodeAccess (com.graphhopper.storage.NodeAccess)1 List (java.util.List)1