Search in sources :

Example 1 with DijkstraOneToMany

use of com.graphhopper.routing.DijkstraOneToMany in project graphhopper by graphhopper.

the class NodeContractorTest method testShortestPathSkipNode2.

@Test
public void testShortestPathSkipNode2() {
    createExampleGraph();
    final double normalDist = new Dijkstra(graph, weighting, traversalMode).calcPath(4, 2).getDistance();
    assertEquals(3, normalDist, 1e-5);
    DijkstraOneToMany algo = new DijkstraOneToMany(graph, weighting, traversalMode);
    setMaxLevelOnAllNodes();
    algo.setEdgeFilter(new NodeContractor.IgnoreNodeFilter(lg, graph.getNodes() + 1).setAvoidNode(3));
    algo.setWeightLimit(10);
    int nodeEntry = algo.findEndNode(4, 2);
    assertEquals(4, algo.getWeight(nodeEntry), 1e-5);
    nodeEntry = algo.findEndNode(4, 1);
    assertEquals(4, algo.getWeight(nodeEntry), 1e-5);
}
Also used : DijkstraOneToMany(com.graphhopper.routing.DijkstraOneToMany) Dijkstra(com.graphhopper.routing.Dijkstra) Test(org.junit.Test)

Example 2 with DijkstraOneToMany

use of com.graphhopper.routing.DijkstraOneToMany in project graphhopper by graphhopper.

the class NodeContractor method initFromGraph.

void initFromGraph() {
    // todo: do we really need this method ? the problem is that ghStorage/prepareGraph can potentially be modified
    // between the constructor call and contractNode,calcShortcutCount etc. ...
    maxLevel = prepareGraph.getNodes() + 1;
    maxEdgesCount = ghStorage.getAllEdges().getMaxId();
    ignoreNodeFilter = new IgnoreNodeFilter(prepareGraph, maxLevel);
    FlagEncoder prepareFlagEncoder = prepareWeighting.getFlagEncoder();
    vehicleInExplorer = prepareGraph.createEdgeExplorer(new DefaultEdgeFilter(prepareFlagEncoder, true, false));
    vehicleOutExplorer = prepareGraph.createEdgeExplorer(new DefaultEdgeFilter(prepareFlagEncoder, false, true));
    prepareAlgo = new DijkstraOneToMany(prepareGraph, prepareWeighting, traversalMode);
}
Also used : FlagEncoder(com.graphhopper.routing.util.FlagEncoder) DijkstraOneToMany(com.graphhopper.routing.DijkstraOneToMany) DefaultEdgeFilter(com.graphhopper.routing.util.DefaultEdgeFilter)

Example 3 with DijkstraOneToMany

use of com.graphhopper.routing.DijkstraOneToMany in project graphhopper by graphhopper.

the class NodeContractorTest method testShortestPathLimit.

@Test
public void testShortestPathLimit() {
    createExampleGraph();
    DijkstraOneToMany algo = new DijkstraOneToMany(graph, weighting, traversalMode);
    setMaxLevelOnAllNodes();
    algo.setEdgeFilter(new NodeContractor.IgnoreNodeFilter(lg, graph.getNodes() + 1).setAvoidNode(0));
    algo.setWeightLimit(2);
    int endNode = algo.findEndNode(4, 1);
    // did not reach endNode
    assertNotEquals(1, endNode);
}
Also used : DijkstraOneToMany(com.graphhopper.routing.DijkstraOneToMany) Test(org.junit.Test)

Example 4 with DijkstraOneToMany

use of com.graphhopper.routing.DijkstraOneToMany in project graphhopper by graphhopper.

the class NodeContractorTest method testShortestPathSkipNode.

@Test
public void testShortestPathSkipNode() {
    createExampleGraph();
    final double normalDist = new Dijkstra(graph, weighting, traversalMode).calcPath(4, 2).getDistance();
    DijkstraOneToMany algo = new DijkstraOneToMany(graph, weighting, traversalMode);
    CHGraph lg = graph.getGraph(CHGraph.class);
    setMaxLevelOnAllNodes();
    algo.setEdgeFilter(new NodeContractor.IgnoreNodeFilter(lg, graph.getNodes() + 1).setAvoidNode(3));
    algo.setWeightLimit(100);
    int nodeEntry = algo.findEndNode(4, 2);
    assertTrue(algo.getWeight(nodeEntry) > normalDist);
    algo.clear();
    algo.setMaxVisitedNodes(1);
    nodeEntry = algo.findEndNode(4, 2);
    assertEquals(-1, nodeEntry);
}
Also used : DijkstraOneToMany(com.graphhopper.routing.DijkstraOneToMany) Dijkstra(com.graphhopper.routing.Dijkstra) Test(org.junit.Test)

Aggregations

DijkstraOneToMany (com.graphhopper.routing.DijkstraOneToMany)4 Test (org.junit.Test)3 Dijkstra (com.graphhopper.routing.Dijkstra)2 DefaultEdgeFilter (com.graphhopper.routing.util.DefaultEdgeFilter)1 FlagEncoder (com.graphhopper.routing.util.FlagEncoder)1