use of com.graphhopper.storage.GraphBuilder in project graphhopper by graphhopper.
the class PathTest method testFound.
@Test
public void testFound() {
Graph g = new GraphBuilder(carManager).create();
Path p = new Path(g);
assertFalse(p.isFound());
assertEquals(0, p.getDistance(), 1e-7);
assertEquals(0, p.calcNodes().size());
}
use of com.graphhopper.storage.GraphBuilder in project graphhopper by graphhopper.
the class PathTest method testWayList.
@Test
public void testWayList() {
Graph g = new GraphBuilder(carManager).create();
NodeAccess na = g.getNodeAccess();
na.setNode(0, 0.0, 0.1);
na.setNode(1, 1.0, 0.1);
na.setNode(2, 2.0, 0.1);
EdgeIteratorState edge1 = g.edge(0, 1).setDistance(1000).set(carAccessEnc, true, true).set(carAvSpeedEnv, 10.0);
edge1.setWayGeometry(Helper.createPointList(8, 1, 9, 1));
EdgeIteratorState edge2 = g.edge(2, 1).setDistance(2000).set(carAccessEnc, true, true).set(carAvSpeedEnv, 50.0);
edge2.setWayGeometry(Helper.createPointList(11, 1, 10, 1));
SPTEntry e1 = new SPTEntry(edge2.getEdge(), 2, 1);
e1.parent = new SPTEntry(edge1.getEdge(), 1, 1);
e1.parent.parent = new SPTEntry(-1, 0, 1);
FastestWeighting weighting = new FastestWeighting(encoder);
Path path = extractPath(g, weighting, e1);
// 0-1-2
assertPList(Helper.createPointList(0, 0.1, 8, 1, 9, 1, 1, 0.1, 10, 1, 11, 1, 2, 0.1), path.calcPoints());
InstructionList instr = InstructionsFromEdges.calcInstructions(path, path.graph, weighting, carManager, tr);
Instruction tmp = instr.get(0);
assertEquals(3000.0, tmp.getDistance(), 0.0);
assertEquals(504000L, tmp.getTime());
assertEquals("continue", tmp.getTurnDescription(tr));
// assertEquals("[0, 6]", tmp.get("interval").toString());
assertEquals(6, tmp.getLength());
// System.out.println(tmp.getPoints());
tmp = instr.get(1);
assertEquals(0.0, tmp.getDistance(), 0.0);
assertEquals(0L, tmp.getTime());
assertEquals("arrive at destination", tmp.getTurnDescription(tr));
// assertEquals("[6, 6]", tmp.get("interval").toString());
assertEquals(0, tmp.getLength());
// System.out.println(tmp.getPoints());
int acc = 0;
for (Instruction instruction : instr) {
acc += instruction.getLength();
}
assertEquals(path.calcPoints().size() - 1, acc);
// force minor change for instructions
edge2.setName("2");
na.setNode(3, 1.0, 1.0);
g.edge(1, 3).setDistance(1000).set(carAccessEnc, true, true).set(carAvSpeedEnv, 10.0);
e1 = new SPTEntry(edge2.getEdge(), 2, 1);
e1.parent = new SPTEntry(edge1.getEdge(), 1, 1);
e1.parent.parent = new SPTEntry(-1, 0, 1);
path = extractPath(g, weighting, e1);
instr = InstructionsFromEdges.calcInstructions(path, path.graph, weighting, carManager, tr);
tmp = instr.get(0);
assertEquals(1000.0, tmp.getDistance(), 0);
assertEquals(360000L, tmp.getTime());
assertEquals("continue", tmp.getTurnDescription(tr));
assertEquals(3, tmp.getLength());
tmp = instr.get(1);
assertEquals(2000.0, tmp.getDistance(), 0);
assertEquals(144000L, tmp.getTime());
assertEquals("turn sharp right onto 2", tmp.getTurnDescription(tr));
assertEquals(3, tmp.getLength());
acc = 0;
for (Instruction instruction : instr) {
acc += instruction.getLength();
}
assertEquals(path.calcPoints().size() - 1, acc);
// now reverse order
e1 = new SPTEntry(edge1.getEdge(), 0, 1);
e1.parent = new SPTEntry(edge2.getEdge(), 1, 1);
e1.parent.parent = new SPTEntry(-1, 2, 1);
path = extractPath(g, weighting, e1);
// 2-1-0
assertPList(Helper.createPointList(2, 0.1, 11, 1, 10, 1, 1, 0.1, 9, 1, 8, 1, 0, 0.1), path.calcPoints());
instr = InstructionsFromEdges.calcInstructions(path, path.graph, weighting, carManager, tr);
tmp = instr.get(0);
assertEquals(2000.0, tmp.getDistance(), 0);
assertEquals(144000L, tmp.getTime());
assertEquals("continue onto 2", tmp.getTurnDescription(tr));
assertEquals(3, tmp.getLength());
tmp = instr.get(1);
assertEquals(1000.0, tmp.getDistance(), 0);
assertEquals(360000L, tmp.getTime());
assertEquals("turn sharp left", tmp.getTurnDescription(tr));
assertEquals(3, tmp.getLength());
acc = 0;
for (Instruction instruction : instr) {
acc += instruction.getLength();
}
assertEquals(path.calcPoints().size() - 1, acc);
}
use of com.graphhopper.storage.GraphBuilder in project graphhopper by graphhopper.
the class PathTest method testFindInstruction.
@Test
public void testFindInstruction() {
Graph g = new GraphBuilder(carManager).create();
NodeAccess na = g.getNodeAccess();
na.setNode(0, 0.0, 0.0);
na.setNode(1, 5.0, 0.0);
na.setNode(2, 5.0, 0.5);
na.setNode(3, 10.0, 0.5);
na.setNode(4, 7.5, 0.25);
na.setNode(5, 5.0, 1.0);
EdgeIteratorState edge1 = g.edge(0, 1).setDistance(1000).set(carAccessEnc, true, true).set(carAvSpeedEnv, 50.0);
edge1.setWayGeometry(Helper.createPointList());
edge1.setName("Street 1");
EdgeIteratorState edge2 = g.edge(1, 2).setDistance(1000).set(carAccessEnc, true, true).set(carAvSpeedEnv, 50.0);
edge2.setWayGeometry(Helper.createPointList());
edge2.setName("Street 2");
EdgeIteratorState edge3 = g.edge(2, 3).setDistance(1000).set(carAccessEnc, true, true).set(carAvSpeedEnv, 50.0);
edge3.setWayGeometry(Helper.createPointList());
edge3.setName("Street 3");
EdgeIteratorState edge4 = g.edge(3, 4).setDistance(500).set(carAccessEnc, true, true).set(carAvSpeedEnv, 50.0);
edge4.setWayGeometry(Helper.createPointList());
edge4.setName("Street 4");
g.edge(1, 5).setDistance(10000).set(carAccessEnc, true, true).set(carAvSpeedEnv, 50.0);
g.edge(2, 5).setDistance(10000).set(carAccessEnc, true, true).set(carAvSpeedEnv, 50.0);
g.edge(3, 5).setDistance(100000).set(carAccessEnc, true, true).set(carAvSpeedEnv, 50.0);
SPTEntry e1 = new SPTEntry(edge4.getEdge(), 4, 1);
e1.parent = new SPTEntry(edge3.getEdge(), 3, 1);
e1.parent.parent = new SPTEntry(edge2.getEdge(), 2, 1);
e1.parent.parent.parent = new SPTEntry(edge1.getEdge(), 1, 1);
e1.parent.parent.parent.parent = new SPTEntry(-1, 0, 1);
FastestWeighting weighting = new FastestWeighting(encoder);
Path path = extractPath(g, weighting, e1);
InstructionList il = InstructionsFromEdges.calcInstructions(path, path.graph, weighting, carManager, tr);
assertEquals(5, il.size());
assertEquals(Instruction.CONTINUE_ON_STREET, il.get(0).getSign());
assertEquals(Instruction.TURN_RIGHT, il.get(1).getSign());
assertEquals(Instruction.TURN_LEFT, il.get(2).getSign());
assertEquals(Instruction.TURN_SHARP_LEFT, il.get(3).getSign());
assertEquals(Instruction.FINISH, il.get(4).getSign());
}
use of com.graphhopper.storage.GraphBuilder in project graphhopper by graphhopper.
the class PathTest method testCalcInstructionIssue1047.
@Test
public void testCalcInstructionIssue1047() {
final Graph g = new GraphBuilder(carManager).create();
final NodeAccess na = g.getNodeAccess();
// Actual example: point=51.367105%2C14.491246&point=51.369048%2C14.483092
// 1-2 & 2-3 is a road that is turning right, 2-4 is a that is branching off.
// When driving 1-2-4, we should create an instruction notifying the user to continue straight instead of turning and following the road
// When driving 1-2-3, we should create an instruction as well
//
// 1 ---- 2 ---- 4
// |
// 3
na.setNode(1, 51.367544, 14.488209);
na.setNode(2, 51.368046, 14.486525);
na.setNode(3, 51.36875, 14.487019);
na.setNode(4, 51.368428, 14.485173);
EnumEncodedValue<RoadClass> roadClassEnc = carManager.getEnumEncodedValue(RoadClass.KEY, RoadClass.class);
BooleanEncodedValue roadClassLinkEnc = carManager.getBooleanEncodedValue(RoadClassLink.KEY);
GHUtility.setSpeed(60, true, true, encoder, g.edge(1, 2).setDistance(5)).setName("B 156").set(roadClassEnc, RoadClass.PRIMARY).set(roadClassLinkEnc, false);
GHUtility.setSpeed(60, true, true, encoder, g.edge(2, 4).setDistance(5)).setName("S 108").set(roadClassEnc, RoadClass.SECONDARY).set(roadClassLinkEnc, false);
GHUtility.setSpeed(60, true, true, encoder, g.edge(2, 3).setDistance(5)).setName("B 156").set(roadClassEnc, RoadClass.PRIMARY).set(roadClassLinkEnc, false);
ShortestWeighting weighting = new ShortestWeighting(encoder);
Path p = new Dijkstra(g, weighting, TraversalMode.NODE_BASED).calcPath(1, 4);
assertTrue(p.isFound());
InstructionList wayList = InstructionsFromEdges.calcInstructions(p, p.graph, weighting, carManager, tr);
assertEquals(3, wayList.size());
p = new Dijkstra(g, weighting, TraversalMode.NODE_BASED).calcPath(1, 3);
assertTrue(p.isFound());
wayList = InstructionsFromEdges.calcInstructions(p, p.graph, weighting, carManager, tr);
assertEquals(3, wayList.size());
}
use of com.graphhopper.storage.GraphBuilder in project graphhopper by graphhopper.
the class InstructionListTest method testNoInstructionIfSlightTurnAndAlternativeIsSharp2.
@Test
public void testNoInstructionIfSlightTurnAndAlternativeIsSharp2() {
Graph g = new GraphBuilder(carManager).create();
// Real World Example: https://graphhopper.com/maps/?point=48.748493%2C9.322455&point=48.748776%2C9.321889
// https://github.com/graphhopper/graphhopper/issues/1441
// From 1 to 3
//
// 3
// \
// 2--- 1
// \
// 4
NodeAccess na = g.getNodeAccess();
na.setNode(1, 48.748493, 9.322455);
na.setNode(2, 48.748577, 9.322152);
na.setNode(3, 48.748776, 9.321889);
na.setNode(4, 48.74847, 9.322299);
GHUtility.setSpeed(60, true, true, carEncoder, g.edge(1, 2).setDistance(10));
GHUtility.setSpeed(60, true, true, carEncoder, g.edge(2, 3).setDistance(10));
GHUtility.setSpeed(60, true, true, carEncoder, g.edge(2, 4).setDistance(10));
ShortestWeighting weighting = new ShortestWeighting(carEncoder);
Path p = new Dijkstra(g, weighting, tMode).calcPath(1, 3);
InstructionList wayList = InstructionsFromEdges.calcInstructions(p, g, weighting, carManager, usTR);
List<String> tmpList = getTurnDescriptions(wayList);
assertEquals(Arrays.asList("continue", "arrive at destination"), tmpList);
}
Aggregations