use of com.graphhopper.routing.weighting.ShortestWeighting 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());
}
use of com.graphhopper.routing.weighting.ShortestWeighting in project graphhopper by graphhopper.
the class PathTest method testCalcInstructionsRoundabout.
/**
* Test roundabout instructions for different profiles
*/
@Test
public void testCalcInstructionsRoundabout() {
for (FlagEncoder encoder : mixedEncoders.fetchEdgeEncoders()) {
Path p = new Dijkstra(roundaboutGraph.g, new ShortestWeighting(encoder), TraversalMode.NODE_BASED).calcPath(1, 8);
assertTrue(p.isFound());
InstructionList wayList = p.calcInstructions(tr);
// Test instructions
List<String> tmpList = pick("text", wayList.createJson());
assertEquals(Arrays.asList("Continue onto MainStreet 1 2", "At roundabout, take exit 3 onto 5-8", "Arrive at destination"), tmpList);
// Test Radian
double delta = roundaboutGraph.getAngle(1, 2, 5, 8);
RoundaboutInstruction instr = (RoundaboutInstruction) wayList.get(1);
assertEquals(delta, instr.getTurnAngle(), 0.01);
// case of continuing a street through a roundabout
p = new Dijkstra(roundaboutGraph.g, new ShortestWeighting(encoder), TraversalMode.NODE_BASED).calcPath(1, 7);
wayList = p.calcInstructions(tr);
tmpList = pick("text", wayList.createJson());
assertEquals(Arrays.asList("Continue onto MainStreet 1 2", "At roundabout, take exit 2 onto MainStreet 4 7", "Arrive at destination"), tmpList);
// Test Radian
delta = roundaboutGraph.getAngle(1, 2, 4, 7);
instr = (RoundaboutInstruction) wayList.get(1);
assertEquals(delta, instr.getTurnAngle(), 0.01);
}
}
use of com.graphhopper.routing.weighting.ShortestWeighting 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());
}
use of com.graphhopper.routing.weighting.ShortestWeighting in project graphhopper by graphhopper.
the class InstructionListTest method testNoInstructionIfSameStreet.
// TODO is this problem fixed with the new instructions?
// problem: we normally don't want instructions if streetname stays but here it is suboptimal:
@Test
public void testNoInstructionIfSameStreet() {
Graph g = new GraphBuilder(carManager).create();
// 2
// \. 5
// \/
// 4
// /
// 3
NodeAccess na = g.getNodeAccess();
na.setNode(2, 10.3, 10.15);
na.setNode(3, 10.0, 10.05);
na.setNode(4, 10.1, 10.10);
na.setNode(5, 10.2, 10.15);
g.edge(3, 4, 100, true).setName("street");
g.edge(4, 5, 100, true).setName("4-5");
EdgeIteratorState iter = g.edge(2, 4, 100, true);
iter.setName("street");
PointList list = new PointList();
list.add(10.20, 10.05);
iter.setWayGeometry(list);
Path p = new Dijkstra(g, new ShortestWeighting(carEncoder), tMode).calcPath(2, 3);
InstructionList wayList = p.calcInstructions(usTR);
List<String> tmpList = pick("text", wayList.createJson());
assertEquals(Arrays.asList("Continue onto street", "Turn right onto street", "Arrive at destination"), tmpList);
}
use of com.graphhopper.routing.weighting.ShortestWeighting in project graphhopper by graphhopper.
the class InstructionListTest method testWayList2.
@Test
public void testWayList2() {
Graph g = new GraphBuilder(carManager).create();
// 2
// \. 5
// \/
// 4
// /
// 3
NodeAccess na = g.getNodeAccess();
na.setNode(2, 10.3, 10.15);
na.setNode(3, 10.0, 10.08);
na.setNode(4, 10.1, 10.10);
na.setNode(5, 10.2, 10.13);
g.edge(3, 4, 100, true).setName("3-4");
g.edge(4, 5, 100, true).setName("4-5");
EdgeIteratorState iter = g.edge(2, 4, 100, true);
iter.setName("2-4");
PointList list = new PointList();
list.add(10.20, 10.05);
iter.setWayGeometry(list);
Path p = new Dijkstra(g, new ShortestWeighting(carEncoder), tMode).calcPath(2, 3);
InstructionList wayList = p.calcInstructions(usTR);
List<String> tmpList = pick("text", wayList.createJson());
assertEquals(Arrays.asList("Continue onto 2-4", "Turn slight right onto 3-4", "Arrive at destination"), tmpList);
p = new Dijkstra(g, new ShortestWeighting(carEncoder), tMode).calcPath(3, 5);
wayList = p.calcInstructions(usTR);
tmpList = pick("text", wayList.createJson());
assertEquals(Arrays.asList("Continue onto 3-4", "Keep right onto 4-5", "Arrive at destination"), tmpList);
}
Aggregations