use of com.graphhopper.routing.util.EncodingManager 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.EncodingManager in project graphhopper by graphhopper.
the class EdgeBasedRoutingAlgorithmTest method testRandomGraph.
@ParameterizedTest
@ArgumentsSource(FixtureProvider.class)
public void testRandomGraph(String algoStr) {
long seed = System.nanoTime();
final int numQueries = 100;
Random rnd = new Random(seed);
EncodingManager em = createEncodingManager(false);
GraphHopperStorage g = createStorage(em);
GHUtility.buildRandomGraph(g, rnd, 50, 2.2, true, true, carEncoder.getAccessEnc(), carEncoder.getAverageSpeedEnc(), null, 0.8, 0.8, 0.8);
GHUtility.addRandomTurnCosts(g, seed, em, carEncoder, 3, tcs);
g.freeze();
int numPathsNotFound = 0;
// todo: reduce redundancy with RandomCHRoutingTest
List<String> strictViolations = new ArrayList<>();
for (int i = 0; i < numQueries; i++) {
int from = rnd.nextInt(g.getNodes());
int to = rnd.nextInt(g.getNodes());
Weighting w = createWeighting();
RoutingAlgorithm refAlgo = new Dijkstra(g, w, EDGE_BASED);
Path refPath = refAlgo.calcPath(from, to);
double refWeight = refPath.getWeight();
if (!refPath.isFound()) {
numPathsNotFound++;
continue;
}
Path path = calcPath(g, from, to, algoStr);
if (!path.isFound()) {
fail("path not found for " + from + "->" + to + ", expected weight: " + refWeight);
}
double weight = path.getWeight();
if (Math.abs(refWeight - weight) > 1.e-2) {
LOGGER.warn("expected: " + refPath.calcNodes());
LOGGER.warn("given: " + path.calcNodes());
fail("wrong weight: " + from + "->" + to + ", dijkstra: " + refWeight + " vs. " + algoStr + ": " + path.getWeight());
}
if (Math.abs(path.getDistance() - refPath.getDistance()) > 1.e-1) {
strictViolations.add("wrong distance " + from + "->" + to + ", expected: " + refPath.getDistance() + ", given: " + path.getDistance());
}
if (Math.abs(path.getTime() - refPath.getTime()) > 50) {
strictViolations.add("wrong time " + from + "->" + to + ", expected: " + refPath.getTime() + ", given: " + path.getTime());
}
}
if (numPathsNotFound > 0.9 * numQueries) {
fail("Too many paths not found: " + numPathsNotFound + "/" + numQueries);
}
if (strictViolations.size() > 0.05 * numQueries) {
fail("Too many strict violations: " + strictViolations.size() + "/" + numQueries + "\n" + Helper.join("\n", strictViolations));
}
}
use of com.graphhopper.routing.util.EncodingManager in project graphhopper by graphhopper.
the class HeadingRoutingTest method createSquareGraphWithTunnel.
private GraphHopperStorage createSquareGraphWithTunnel() {
CarFlagEncoder carEncoder = new CarFlagEncoder();
EncodingManager encodingManager = new EncodingManager.Builder().add(carEncoder).add(Subnetwork.create("profile")).build();
GraphHopperStorage g = new GraphBuilder(encodingManager).create();
// 2----3---4
// | | |
// 1->- 8 >-5 (edge 1->5 is not connected to 8)
// | | |
// 0----7---6
NodeAccess na = g.getNodeAccess();
na.setNode(0, 0.000, 0.000);
na.setNode(1, 0.001, 0.000);
na.setNode(2, 0.002, 0.000);
na.setNode(3, 0.002, 0.001);
na.setNode(4, 0.002, 0.002);
na.setNode(5, 0.001, 0.002);
na.setNode(6, 0.000, 0.002);
na.setNode(7, 0.000, 0.001);
na.setNode(8, 0.001, 0.001);
GHUtility.setSpeed(60, true, true, carEncoder, g.edge(0, 1).setDistance(100));
GHUtility.setSpeed(60, true, true, carEncoder, g.edge(1, 2).setDistance(100));
GHUtility.setSpeed(60, true, true, carEncoder, g.edge(2, 3).setDistance(100));
GHUtility.setSpeed(60, true, true, carEncoder, g.edge(3, 4).setDistance(100));
GHUtility.setSpeed(60, true, true, carEncoder, g.edge(4, 5).setDistance(100));
GHUtility.setSpeed(60, true, true, carEncoder, g.edge(5, 6).setDistance(100));
GHUtility.setSpeed(60, true, true, carEncoder, g.edge(6, 7).setDistance(100));
GHUtility.setSpeed(60, true, true, carEncoder, g.edge(7, 0).setDistance(100));
GHUtility.setSpeed(60, true, false, carEncoder, g.edge(1, 5).setDistance(110));
GHUtility.setSpeed(60, true, true, carEncoder, g.edge(3, 8).setDistance(110));
GHUtility.setSpeed(60, true, true, carEncoder, g.edge(7, 8).setDistance(110));
return g;
}
use of com.graphhopper.routing.util.EncodingManager 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.routing.util.EncodingManager 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]");
}
Aggregations