use of com.graphhopper.util.EdgeExplorer in project graphhopper by graphhopper.
the class PrincetonReaderTest method testRead.
@Test
public void testRead() {
Graph graph = new GraphBuilder(encodingManager).create();
new PrincetonReader(graph).setStream(PrincetonReader.class.getResourceAsStream("tinyEWD.txt")).read();
assertEquals(8, graph.getNodes());
EdgeExplorer explorer = graph.createEdgeExplorer(carOutEdges);
assertEquals(2, count(explorer.setBaseNode(0)));
assertEquals(3, count(explorer.setBaseNode(6)));
}
use of com.graphhopper.util.EdgeExplorer in project graphhopper by graphhopper.
the class AStar method runAlgo.
private Path runAlgo() {
double currWeightToGoal, estimationFullWeight;
EdgeExplorer explorer = outEdgeExplorer;
while (true) {
int currVertex = currEdge.adjNode;
visitedCount++;
if (isMaxVisitedNodesExceeded())
return createEmptyPath();
if (finished())
break;
EdgeIterator iter = explorer.setBaseNode(currVertex);
while (iter.next()) {
if (!accept(iter, currEdge.edge))
continue;
double alreadyVisitedWeight = weighting.calcWeight(iter, false, currEdge.edge) + currEdge.weightOfVisitedPath;
if (Double.isInfinite(alreadyVisitedWeight))
continue;
int traversalId = traversalMode.createTraversalId(iter, false);
AStarEntry ase = fromMap.get(traversalId);
if (ase == null || ase.weightOfVisitedPath > alreadyVisitedWeight) {
int neighborNode = iter.getAdjNode();
currWeightToGoal = weightApprox.approximate(neighborNode);
estimationFullWeight = alreadyVisitedWeight + currWeightToGoal;
if (ase == null) {
ase = new AStarEntry(iter.getEdge(), neighborNode, estimationFullWeight, alreadyVisitedWeight);
fromMap.put(traversalId, ase);
} else {
// assert (ase.weight > 0.9999999 * estimationFullWeight) : "Inconsistent distance estimate. It is expected weight >= estimationFullWeight but was "
// + ase.weight + " < " + estimationFullWeight + " (" + ase.weight / estimationFullWeight + "), and weightOfVisitedPath:"
// + ase.weightOfVisitedPath + " vs. alreadyVisitedWeight:" + alreadyVisitedWeight + " (" + ase.weightOfVisitedPath / alreadyVisitedWeight + ")";
prioQueueOpenSet.remove(ase);
ase.edge = iter.getEdge();
ase.weight = estimationFullWeight;
ase.weightOfVisitedPath = alreadyVisitedWeight;
}
ase.parent = currEdge;
prioQueueOpenSet.add(ase);
updateBestPath(iter, ase, traversalId);
}
}
if (prioQueueOpenSet.isEmpty())
return createEmptyPath();
currEdge = prioQueueOpenSet.poll();
if (currEdge == null)
throw new AssertionError("Empty edge cannot happen");
}
return extractPath();
}
use of com.graphhopper.util.EdgeExplorer in project graphhopper by graphhopper.
the class PrepareRoutingSubnetworksTest method isConsistent.
public static boolean isConsistent(GraphHopperStorage storage) {
EdgeExplorer edgeExplorer = storage.createEdgeExplorer();
int nNodes = storage.getNodes();
for (int i = 0; i < nNodes; i++) {
if (!check(storage, edgeExplorer, i))
return false;
}
return true;
}
use of com.graphhopper.util.EdgeExplorer in project graphhopper by graphhopper.
the class PrincetonReaderTest method testMediumRead.
@Test
public void testMediumRead() throws IOException {
Graph graph = new GraphBuilder(encodingManager).create();
new PrincetonReader(graph).setStream(new GZIPInputStream(PrincetonReader.class.getResourceAsStream("mediumEWD.txt.gz"))).read();
assertEquals(250, graph.getNodes());
EdgeExplorer explorer = graph.createEdgeExplorer(carOutEdges);
assertEquals(13, count(explorer.setBaseNode(244)));
assertEquals(11, count(explorer.setBaseNode(16)));
}
use of com.graphhopper.util.EdgeExplorer in project graphhopper by graphhopper.
the class FootFlagEncoderTest method testGraph.
@Test
public void testGraph() {
Graph g = new GraphBuilder(encodingManager).create();
g.edge(0, 1).setDistance(10).setFlags(footEncoder.setProperties(10, true, true));
g.edge(0, 2).setDistance(10).setFlags(footEncoder.setProperties(5, true, true));
g.edge(1, 3).setDistance(10).setFlags(footEncoder.setProperties(10, true, true));
EdgeExplorer out = g.createEdgeExplorer(new DefaultEdgeFilter(footEncoder, false, true));
assertEquals(GHUtility.asSet(1, 2), GHUtility.getNeighbors(out.setBaseNode(0)));
assertEquals(GHUtility.asSet(0, 3), GHUtility.getNeighbors(out.setBaseNode(1)));
assertEquals(GHUtility.asSet(0), GHUtility.getNeighbors(out.setBaseNode(2)));
}
Aggregations