Search in sources :

Example 6 with SPTEntry

use of com.graphhopper.storage.SPTEntry in project graphhopper by graphhopper.

the class DijkstraBidirectionRef method updateBestPath.

@Override
protected void updateBestPath(EdgeIteratorState edgeState, SPTEntry entryCurrent, int traversalId) {
    SPTEntry entryOther = bestWeightMapOther.get(traversalId);
    if (entryOther == null)
        return;
    boolean reverse = bestWeightMapFrom == bestWeightMapOther;
    // update μ
    double newWeight = entryCurrent.weight + entryOther.weight;
    if (traversalMode.isEdgeBased()) {
        if (entryOther.edge != entryCurrent.edge)
            throw new IllegalStateException("cannot happen for edge based execution of " + getName());
        if (entryOther.adjNode != entryCurrent.adjNode) {
            // prevents the path to contain the edge at the meeting point twice and subtract the weight (excluding turn weight => no previous edge)
            entryCurrent = entryCurrent.parent;
            newWeight -= weighting.calcWeight(edgeState, reverse, EdgeIterator.NO_EDGE);
        } else if (!traversalMode.hasUTurnSupport())
            // we detected a u-turn at meeting point, skip if not supported
            return;
    }
    if (newWeight < bestPath.getWeight()) {
        bestPath.setSwitchToFrom(reverse);
        bestPath.setSPTEntry(entryCurrent);
        bestPath.setWeight(newWeight);
        bestPath.setSPTEntryTo(entryOther);
    }
}
Also used : SPTEntry(com.graphhopper.storage.SPTEntry)

Example 7 with SPTEntry

use of com.graphhopper.storage.SPTEntry in project graphhopper by graphhopper.

the class PathBidirRefTest method testExtract2.

@Test
public void testExtract2() {
    Graph g = createGraph();
    g.edge(1, 2, 10, false);
    g.edge(2, 3, 20, false);
    EdgeExplorer explorer = g.createEdgeExplorer(carOutEdges);
    EdgeIterator iter = explorer.setBaseNode(1);
    iter.next();
    PathBidirRef pw = new PathBidirRef(g, new FastestWeighting(carEncoder));
    pw.sptEntry = new SPTEntry(iter.getEdge(), 2, 10);
    pw.sptEntry.parent = new SPTEntry(EdgeIterator.NO_EDGE, 1, 0);
    explorer = g.createEdgeExplorer(new DefaultEdgeFilter(carEncoder, true, false));
    iter = explorer.setBaseNode(3);
    iter.next();
    pw.edgeTo = new SPTEntry(iter.getEdge(), 2, 20);
    pw.edgeTo.parent = new SPTEntry(EdgeIterator.NO_EDGE, 3, 0);
    Path p = pw.extract();
    assertEquals(Helper.createTList(1, 2, 3), p.calcNodes());
    assertEquals(30, p.getDistance(), 1e-4);
}
Also used : SPTEntry(com.graphhopper.storage.SPTEntry) EdgeIterator(com.graphhopper.util.EdgeIterator) Graph(com.graphhopper.storage.Graph) EdgeExplorer(com.graphhopper.util.EdgeExplorer) FastestWeighting(com.graphhopper.routing.weighting.FastestWeighting) DefaultEdgeFilter(com.graphhopper.routing.util.DefaultEdgeFilter) Test(org.junit.Test)

Example 8 with SPTEntry

use of com.graphhopper.storage.SPTEntry in project graphhopper by graphhopper.

the class PathBidirRefTest method testExtract.

@Test
public void testExtract() {
    Graph g = createGraph();
    g.edge(1, 2, 10, true);
    PathBidirRef pw = new PathBidirRef(g, new FastestWeighting(carEncoder));
    EdgeExplorer explorer = g.createEdgeExplorer(carOutEdges);
    EdgeIterator iter = explorer.setBaseNode(1);
    iter.next();
    pw.sptEntry = new SPTEntry(iter.getEdge(), 2, 0);
    pw.sptEntry.parent = new SPTEntry(EdgeIterator.NO_EDGE, 1, 10);
    pw.edgeTo = new SPTEntry(EdgeIterator.NO_EDGE, 2, 0);
    Path p = pw.extract();
    assertEquals(Helper.createTList(1, 2), p.calcNodes());
    assertEquals(10, p.getDistance(), 1e-4);
}
Also used : SPTEntry(com.graphhopper.storage.SPTEntry) EdgeIterator(com.graphhopper.util.EdgeIterator) Graph(com.graphhopper.storage.Graph) EdgeExplorer(com.graphhopper.util.EdgeExplorer) FastestWeighting(com.graphhopper.routing.weighting.FastestWeighting) Test(org.junit.Test)

Aggregations

SPTEntry (com.graphhopper.storage.SPTEntry)8 EdgeExplorer (com.graphhopper.util.EdgeExplorer)3 EdgeIterator (com.graphhopper.util.EdgeIterator)3 Test (org.junit.Test)3 FastestWeighting (com.graphhopper.routing.weighting.FastestWeighting)2 Graph (com.graphhopper.storage.Graph)2 DefaultEdgeFilter (com.graphhopper.routing.util.DefaultEdgeFilter)1 PriorityQueue (java.util.PriorityQueue)1 Random (java.util.Random)1