use of com.graphhopper.routing.util.FlagEncoder 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.routing.util.FlagEncoder in project graphhopper by graphhopper.
the class TurnCostStorageTest method setup.
@BeforeEach
public void setup() {
FlagEncoder carEncoder = new CarFlagEncoder(5, 5, 3);
FlagEncoder bikeEncoder = new BikeFlagEncoder(5, 5, 3, false);
manager = EncodingManager.create(carEncoder, bikeEncoder);
}
use of com.graphhopper.routing.util.FlagEncoder in project graphhopper by graphhopper.
the class HeadingResolverTest method withQueryGraph.
@Test
public void withQueryGraph() {
// 2
// 0 -x- 1
FlagEncoder encoder = new CarFlagEncoder();
EncodingManager em = EncodingManager.create(encoder);
GraphHopperStorage graph = new GraphBuilder(em).create();
NodeAccess na = graph.getNodeAccess();
na.setNode(0, 48.8611, 1.2194);
na.setNode(1, 48.8538, 2.3950);
EdgeIteratorState edge = GHUtility.setSpeed(60, true, true, encoder, graph.edge(0, 1).setDistance(10));
Snap snap = createSnap(edge, 48.859, 2.00, 0);
QueryGraph queryGraph = QueryGraph.create(graph, snap);
HeadingResolver resolver = new HeadingResolver(queryGraph);
// if the heading points East we get the Western edge 0->2
assertEquals("0->2", queryGraph.getEdgeIteratorState(1, Integer.MIN_VALUE).toString());
assertEquals(IntArrayList.from(1), resolver.getEdgesWithDifferentHeading(2, 90));
// if the heading points West we get the Eastern edge 2->1
assertEquals("2->1", queryGraph.getEdgeIteratorState(2, Integer.MIN_VALUE).toString());
assertEquals(IntArrayList.from(2), resolver.getEdgesWithDifferentHeading(2, 270));
}
use of com.graphhopper.routing.util.FlagEncoder in project graphhopper by graphhopper.
the class HeadingResolverTest method curvyEdge.
@Test
public void curvyEdge() {
// 1 -|
// |- 0 -|
// |- 2
FlagEncoder encoder = new CarFlagEncoder();
EncodingManager em = EncodingManager.create(encoder);
GraphHopperStorage graph = new GraphBuilder(em).create();
NodeAccess na = graph.getNodeAccess();
na.setNode(1, 0.01, 0.00);
na.setNode(0, 0.00, 0.00);
na.setNode(2, -0.01, 0.00);
GHUtility.setSpeed(60, true, true, encoder, graph.edge(0, 1).setDistance(10)).setWayGeometry(Helper.createPointList(0.00, 0.01, 0.01, 0.01));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(0, 2).setDistance(10)).setWayGeometry(Helper.createPointList(0.00, -0.01, -0.01, -0.01));
HeadingResolver resolver = new HeadingResolver(graph);
resolver.setTolerance(120);
// asking for the edges not going east returns 0-2
assertEquals(IntArrayList.from(1), resolver.getEdgesWithDifferentHeading(0, 90));
// asking for the edges not going west returns 0-1
assertEquals(IntArrayList.from(0), resolver.getEdgesWithDifferentHeading(0, 270));
}
use of com.graphhopper.routing.util.FlagEncoder in project graphhopper by graphhopper.
the class AlternativeRouteEdgeCHTest method createTestGraph.
public GraphHopperStorage createTestGraph(EncodingManager tmpEM) {
final GraphHopperStorage graph = new GraphBuilder(tmpEM).withTurnCosts(true).create();
/*
9 11
/\ / \
1 2-3-4-10-12
\ / \
5--6-7---8
*/
// Make all edges the length of T, the distance around v than an s->v->t path
// has to be locally-shortest to be considered.
// So we get all three alternatives.
FlagEncoder encoder = carFE;
GHUtility.setSpeed(60, true, true, encoder, graph.edge(5, 6).setDistance(10000));
EdgeIteratorState e6_3 = GHUtility.setSpeed(60, true, true, encoder, graph.edge(6, 3).setDistance(10000));
EdgeIteratorState e3_4 = GHUtility.setSpeed(60, true, true, encoder, graph.edge(3, 4).setDistance(10000));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(4, 10).setDistance(10000));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(6, 7).setDistance(10000));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(7, 8).setDistance(10000));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(8, 4).setDistance(10000));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(5, 1).setDistance(10000));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(1, 9).setDistance(10000));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(9, 2).setDistance(10000));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(2, 3).setDistance(10000));
EdgeIteratorState e4_11 = GHUtility.setSpeed(60, true, true, encoder, graph.edge(4, 11).setDistance(9000));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(11, 12).setDistance(9000));
GHUtility.setSpeed(60, true, true, encoder, graph.edge(12, 10).setDistance(10000));
TurnCostStorage turnCostStorage = graph.getTurnCostStorage();
DecimalEncodedValue carTurnCost = em.getDecimalEncodedValue(TurnCost.key(carFE.toString()));
turnCostStorage.set(carTurnCost, e3_4.getEdge(), 4, e4_11.getEdge(), Double.POSITIVE_INFINITY);
turnCostStorage.set(carTurnCost, e6_3.getEdge(), 3, e3_4.getEdge(), Double.POSITIVE_INFINITY);
graph.freeze();
return graph;
}
Aggregations