use of com.graphhopper.storage.GraphBuilder in project graphhopper by graphhopper.
the class DepthFirstSearchTest method testDFS2.
@Test
public void testDFS2() {
DepthFirstSearch dfs = new DepthFirstSearch() {
@Override
protected GHBitSet createBitSet() {
return new GHBitSetImpl();
}
@Override
public boolean goFurther(int v) {
counter++;
assertTrue(!set.contains(v), "v " + v + " is already contained in set. iteration:" + counter);
set.add(v);
list.add(v);
return super.goFurther(v);
}
};
EncodingManager em = EncodingManager.create("car");
FlagEncoder encoder = em.getEncoder("car");
Graph g = new GraphBuilder(em).create();
GHUtility.setSpeed(60, true, false, encoder, g.edge(1, 2).setDistance(1));
GHUtility.setSpeed(60, true, true, encoder, g.edge(1, 4).setDistance(1));
GHUtility.setSpeed(60, true, false, encoder, g.edge(1, 3).setDistance(1));
GHUtility.setSpeed(60, true, false, encoder, g.edge(2, 3).setDistance(1));
GHUtility.setSpeed(60, true, true, encoder, g.edge(4, 3).setDistance(1));
dfs.start(g.createEdgeExplorer(AccessFilter.outEdges(encoder.getAccessEnc())), 1);
assertTrue(counter > 0);
assertEquals(list.toString(), "[1, 2, 3, 4]");
}
use of com.graphhopper.storage.GraphBuilder in project graphhopper by graphhopper.
the class DepthFirstSearchTest method testDFS1.
@Test
public void testDFS1() {
DepthFirstSearch dfs = new DepthFirstSearch() {
@Override
protected GHBitSet createBitSet() {
return new GHBitSetImpl();
}
@Override
public boolean goFurther(int v) {
counter++;
assertTrue(!set.contains(v), "v " + v + " is already contained in set. iteration:" + counter);
set.add(v);
list.add(v);
return super.goFurther(v);
}
};
EncodingManager em = EncodingManager.create("car");
FlagEncoder encoder = em.getEncoder("car");
Graph g = new GraphBuilder(em).create();
GHUtility.setSpeed(60, true, false, encoder, g.edge(1, 2).setDistance(1));
GHUtility.setSpeed(60, true, false, encoder, g.edge(1, 5).setDistance(1));
GHUtility.setSpeed(60, true, false, encoder, g.edge(1, 4).setDistance(1));
GHUtility.setSpeed(60, true, false, encoder, g.edge(2, 3).setDistance(1));
GHUtility.setSpeed(60, true, false, encoder, g.edge(3, 4).setDistance(1));
GHUtility.setSpeed(60, true, false, encoder, g.edge(5, 6).setDistance(1));
GHUtility.setSpeed(60, true, false, encoder, g.edge(6, 4).setDistance(1));
dfs.start(g.createEdgeExplorer(AccessFilter.outEdges(encoder.getAccessEnc())), 1);
assertTrue(counter > 0);
assertEquals(list.toString(), "[1, 2, 3, 4, 5, 6]");
}
use of com.graphhopper.storage.GraphBuilder in project graphhopper by graphhopper.
the class BreadthFirstSearchTest method testBFS.
@Test
public void testBFS() {
BreadthFirstSearch bfs = new BreadthFirstSearch() {
@Override
protected GHBitSet createBitSet() {
return new GHTBitSet();
}
@Override
public boolean goFurther(int v) {
counter++;
assertFalse(set.contains(v), "v " + v + " is already contained in set. iteration:" + counter);
set.add(v);
list.add(v);
return super.goFurther(v);
}
};
FlagEncoder encoder = new CarFlagEncoder();
Graph g = new GraphBuilder(EncodingManager.create(encoder)).create();
GHUtility.setSpeed(60, true, true, encoder, g.edge(0, 1).setDistance(85));
GHUtility.setSpeed(60, true, true, encoder, g.edge(0, 2).setDistance(217));
GHUtility.setSpeed(60, true, true, encoder, g.edge(0, 3).setDistance(173));
GHUtility.setSpeed(60, true, true, encoder, g.edge(0, 5).setDistance(173));
GHUtility.setSpeed(60, true, true, encoder, g.edge(1, 6).setDistance(75));
GHUtility.setSpeed(60, true, true, encoder, g.edge(2, 7).setDistance(51));
GHUtility.setSpeed(60, true, true, encoder, g.edge(3, 8).setDistance(23));
GHUtility.setSpeed(60, true, true, encoder, g.edge(4, 8).setDistance(793));
GHUtility.setSpeed(60, true, true, encoder, g.edge(8, 10).setDistance(343));
GHUtility.setSpeed(60, true, true, encoder, g.edge(6, 9).setDistance(72));
GHUtility.setSpeed(60, true, true, encoder, g.edge(9, 10).setDistance(8));
GHUtility.setSpeed(60, true, true, encoder, g.edge(5, 10).setDistance(1));
bfs.start(g.createEdgeExplorer(), 0);
assertTrue(counter > 0);
assertEquals(g.getNodes(), counter);
assertEquals("[0, 5, 3, 2, 1, 10, 8, 7, 6, 9, 4]", list.toString());
}
use of com.graphhopper.storage.GraphBuilder in project graphhopper by graphhopper.
the class BreadthFirstSearchTest method testBFS2.
@Test
public void testBFS2() {
BreadthFirstSearch bfs = new BreadthFirstSearch() {
@Override
protected GHBitSet createBitSet() {
return new GHTBitSet();
}
@Override
public boolean goFurther(int v) {
counter++;
assertFalse(set.contains(v), "v " + v + " is already contained in set. iteration:" + counter);
set.add(v);
list.add(v);
return super.goFurther(v);
}
};
FlagEncoder encoder = new CarFlagEncoder();
Graph g = new GraphBuilder(EncodingManager.create(encoder)).create();
GHUtility.setSpeed(60, true, false, encoder, g.edge(1, 2).setDistance(1));
GHUtility.setSpeed(60, true, false, encoder, g.edge(2, 3).setDistance(1));
GHUtility.setSpeed(60, true, false, encoder, g.edge(3, 4).setDistance(1));
GHUtility.setSpeed(60, true, false, encoder, g.edge(1, 5).setDistance(1));
GHUtility.setSpeed(60, true, false, encoder, g.edge(5, 6).setDistance(1));
GHUtility.setSpeed(60, true, false, encoder, g.edge(6, 4).setDistance(1));
bfs.start(g.createEdgeExplorer(), 1);
assertTrue(counter > 0);
assertEquals("[1, 5, 2, 6, 3, 4]", list.toString());
}
use of com.graphhopper.storage.GraphBuilder 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");
IntsRef relFlags = carManager.createRelationFlags();
EdgeIteratorState tmpEdge;
tmpEdge = GHUtility.setSpeed(60, true, true, carEncoder, g.edge(0, 1).setDistance(10000)).setName("0-1");
assertNotEquals(EncodingManager.Access.CAN_SKIP, carEncoder.getAccess(w));
tmpEdge.setFlags(carManager.handleWayTags(w, relFlags));
tmpEdge = GHUtility.setSpeed(60, true, true, carEncoder, g.edge(1, 2).setDistance(11000)).setName("1-2");
tmpEdge.setFlags(carManager.handleWayTags(w, relFlags));
w.setTag("maxspeed", "20");
tmpEdge = GHUtility.setSpeed(60, true, true, carEncoder, g.edge(0, 3).setDistance(11000));
tmpEdge.setFlags(carManager.handleWayTags(w, relFlags));
tmpEdge = GHUtility.setSpeed(60, true, true, carEncoder, g.edge(1, 4).setDistance(10000)).setName("1-4");
tmpEdge.setFlags(carManager.handleWayTags(w, relFlags));
tmpEdge = GHUtility.setSpeed(60, true, true, carEncoder, g.edge(2, 5).setDistance(11000)).setName("5-2");
tmpEdge.setFlags(carManager.handleWayTags(w, relFlags));
w.setTag("maxspeed", "30");
tmpEdge = GHUtility.setSpeed(60, true, true, carEncoder, g.edge(3, 6).setDistance(11000)).setName("3-6");
tmpEdge.setFlags(carManager.handleWayTags(w, relFlags));
tmpEdge = GHUtility.setSpeed(60, true, true, carEncoder, g.edge(4, 7).setDistance(10000)).setName("4-7");
tmpEdge.setFlags(carManager.handleWayTags(w, relFlags));
tmpEdge = GHUtility.setSpeed(60, true, true, carEncoder, g.edge(5, 8).setDistance(10000)).setName("5-8");
tmpEdge.setFlags(carManager.handleWayTags(w, relFlags));
w.setTag("maxspeed", "40");
tmpEdge = GHUtility.setSpeed(60, true, true, carEncoder, g.edge(6, 7).setDistance(11000)).setName("6-7");
tmpEdge.setFlags(carManager.handleWayTags(w, relFlags));
tmpEdge = GHUtility.setSpeed(60, true, true, carEncoder, g.edge(7, 8).setDistance(10000));
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, relFlags));
w.setTag("maxspeed", "50");
// missing edge name
tmpEdge = GHUtility.setSpeed(60, true, true, carEncoder, g.edge(9, 10).setDistance(10000));
tmpEdge.setFlags(carManager.handleWayTags(w, relFlags));
tmpEdge = GHUtility.setSpeed(60, true, true, carEncoder, g.edge(8, 9).setDistance(20000));
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, relFlags));
// Path is: [0 0-1, 3 1-4, 6 4-7, 9 7-8, 11 8-9, 10 9-10]
ShortestWeighting weighting = new ShortestWeighting(carEncoder);
Path p = new Dijkstra(g, weighting, tMode).calcPath(0, 10);
InstructionList wayList = InstructionsFromEdges.calcInstructions(p, g, weighting, carManager, usTR);
Map<String, List<PathDetail>> details = PathDetailsFromEdges.calcDetails(p, carManager, weighting, Arrays.asList(AVERAGE_SPEED), new PathDetailsBuilderFactory(), 0);
ResponsePath responsePath = new ResponsePath();
responsePath.setInstructions(wayList);
responsePath.addPathDetails(details);
responsePath.setPoints(p.calcPoints());
int numberOfPoints = p.calcPoints().size();
DouglasPeucker douglasPeucker = new DouglasPeucker();
// Do not simplify anything
douglasPeucker.setMaxDistance(0);
PathSimplification.simplify(responsePath, douglasPeucker, true);
assertEquals(numberOfPoints, responsePath.getPoints().size());
responsePath = new ResponsePath();
responsePath.setInstructions(wayList);
responsePath.addPathDetails(details);
responsePath.setPoints(p.calcPoints());
douglasPeucker.setMaxDistance(100000000);
PathSimplification.simplify(responsePath, douglasPeucker, true);
assertTrue(numberOfPoints > responsePath.getPoints().size());
}
Aggregations