Search in sources :

Example 6 with EdgeExplorer

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)));
}
Also used : Graph(com.graphhopper.storage.Graph) EdgeExplorer(com.graphhopper.util.EdgeExplorer) GraphBuilder(com.graphhopper.storage.GraphBuilder) Test(org.junit.Test)

Example 7 with EdgeExplorer

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();
}
Also used : EdgeIterator(com.graphhopper.util.EdgeIterator) EdgeExplorer(com.graphhopper.util.EdgeExplorer)

Example 8 with EdgeExplorer

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;
}
Also used : EdgeExplorer(com.graphhopper.util.EdgeExplorer)

Example 9 with EdgeExplorer

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)));
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) Graph(com.graphhopper.storage.Graph) EdgeExplorer(com.graphhopper.util.EdgeExplorer) GraphBuilder(com.graphhopper.storage.GraphBuilder) Test(org.junit.Test)

Example 10 with EdgeExplorer

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)));
}
Also used : Graph(com.graphhopper.storage.Graph) EdgeExplorer(com.graphhopper.util.EdgeExplorer) GraphBuilder(com.graphhopper.storage.GraphBuilder) Test(org.junit.Test)

Aggregations

EdgeExplorer (com.graphhopper.util.EdgeExplorer)16 Test (org.junit.Test)11 Graph (com.graphhopper.storage.Graph)8 GraphBuilder (com.graphhopper.storage.GraphBuilder)6 GraphHopperStorage (com.graphhopper.storage.GraphHopperStorage)4 EdgeIterator (com.graphhopper.util.EdgeIterator)4 SPTEntry (com.graphhopper.storage.SPTEntry)3 AllEdgesIterator (com.graphhopper.routing.util.AllEdgesIterator)2 FastestWeighting (com.graphhopper.routing.weighting.FastestWeighting)2 EdgeIteratorState (com.graphhopper.util.EdgeIteratorState)2 HashMap (java.util.HashMap)2 GZIPInputStream (java.util.zip.GZIPInputStream)2 IntHashSet (com.carrotsearch.hppc.IntHashSet)1 IntIntHashMap (com.carrotsearch.hppc.IntIntHashMap)1 IntLongHashMap (com.carrotsearch.hppc.IntLongHashMap)1 GTFSFeed (com.conveyal.gtfs.GTFSFeed)1 Agency (com.conveyal.gtfs.model.Agency)1 Fare (com.conveyal.gtfs.model.Fare)1 StopTime (com.conveyal.gtfs.model.StopTime)1 Trip (com.conveyal.gtfs.model.Trip)1