use of com.graphhopper.routing.Dijkstra in project graphhopper by graphhopper.
the class GpxConversionsTest method testInstructionsWithTimeAndPlace.
@Test
public void testInstructionsWithTimeAndPlace() {
Graph g = new GraphBuilder(carManager).create();
// n-4-5 (n: pillar node)
// |
// 7-3-2-6
// |
// 1
NodeAccess na = g.getNodeAccess();
na.setNode(1, 15.0, 10);
na.setNode(2, 15.1, 10);
na.setNode(3, 15.1, 9.9);
na.setNode(4, 15.2, 9.9);
na.setNode(5, 15.2, 10);
na.setNode(6, 15.1, 10.1);
na.setNode(7, 15.1, 9.8);
GHUtility.setSpeed(63, true, true, carEncoder, g.edge(1, 2).setDistance(7000).setName("1-2"));
GHUtility.setSpeed(72, true, true, carEncoder, g.edge(2, 3).setDistance(8000).setName("2-3"));
GHUtility.setSpeed(9, true, true, carEncoder, g.edge(2, 6).setDistance(10000).setName("2-6"));
GHUtility.setSpeed(81, true, true, carEncoder, g.edge(3, 4).setDistance(9000).setName("3-4"));
GHUtility.setSpeed(9, true, true, carEncoder, g.edge(3, 7).setDistance(10000).setName("3-7"));
GHUtility.setSpeed(90, true, true, carEncoder, g.edge(4, 5).setDistance(10000).setName("4-5"));
ShortestWeighting weighting = new ShortestWeighting(carEncoder);
Path p = new Dijkstra(g, weighting, TraversalMode.NODE_BASED).calcPath(1, 5);
InstructionList wayList = InstructionsFromEdges.calcInstructions(p, g, weighting, carManager, trMap.getWithFallBack(Locale.US));
PointList points = p.calcPoints();
assertEquals(4, wayList.size());
assertEquals(34000, p.getDistance(), 1e-1);
assertEquals(34000, sumDistances(wayList), 1e-1);
assertEquals(5, points.size());
assertEquals(1604120, p.getTime());
assertEquals(Instruction.CONTINUE_ON_STREET, wayList.get(0).getSign());
assertEquals(15, wayList.get(0).getPoints().getLat(0), 1e-3);
assertEquals(10, wayList.get(0).getPoints().getLon(0), 1e-3);
assertEquals(Instruction.TURN_LEFT, wayList.get(1).getSign());
assertEquals(15.1, wayList.get(1).getPoints().getLat(0), 1e-3);
assertEquals(10, wayList.get(1).getPoints().getLon(0), 1e-3);
assertEquals(Instruction.TURN_RIGHT, wayList.get(2).getSign());
assertEquals(15.1, wayList.get(2).getPoints().getLat(0), 1e-3);
assertEquals(9.9, wayList.get(2).getPoints().getLon(0), 1e-3);
String gpxStr = GpxConversions.createGPX(wayList, "test", (long) 0, false, true, true, true, Constants.VERSION, trMap.getWithFallBack(Locale.US));
verifyGPX(gpxStr);
// System.out.println(gpxStr);
assertTrue(gpxStr.contains("<trkpt lat=\"15.0\" lon=\"10.0\"><time>1970-01-01T00:00:00Z</time>"), gpxStr);
assertTrue(gpxStr.contains("<extensions>") && gpxStr.contains("</extensions>"), gpxStr);
assertTrue(gpxStr.contains("<rtept lat=\"15.1\" lon=\"10.0\">"), gpxStr);
assertTrue(gpxStr.contains("<gh:distance>8000.0</gh:distance>"), gpxStr);
assertTrue(gpxStr.contains("<desc>turn left onto 2-3</desc>"), gpxStr);
assertTrue(gpxStr.contains("<gh:sign>-2</gh:sign>"), gpxStr);
assertTrue(gpxStr.contains("<gh:direction>N</gh:direction>"), gpxStr);
assertTrue(gpxStr.contains("<gh:azimuth>0.0</gh:azimuth>"), gpxStr);
assertFalse(gpxStr.contains("NaN"));
}
Aggregations