Search in sources :

Example 31 with GraphHopperStorage

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

the class CHEdgeIteratorTest method testUpdateFlags.

@Test
public void testUpdateFlags() {
    CarFlagEncoder carFlagEncoder = new CarFlagEncoder();
    EncodingManager encodingManager = new EncodingManager(carFlagEncoder);
    FastestWeighting weighting = new FastestWeighting(carFlagEncoder);
    EdgeFilter carOutFilter = new DefaultEdgeFilter(carFlagEncoder, false, true);
    GraphHopperStorage ghStorage = new GraphBuilder(encodingManager).setCHGraph(weighting).create();
    CHGraph g = ghStorage.getGraph(CHGraph.class, weighting);
    g.edge(0, 1).setDistance(12).setFlags(carFlagEncoder.setProperties(10, true, true));
    g.edge(0, 2).setDistance(13).setFlags(carFlagEncoder.setProperties(20, true, true));
    ghStorage.freeze();
    assertEquals(2, GHUtility.count(g.getAllEdges()));
    assertEquals(1, GHUtility.count(g.createEdgeExplorer(carOutFilter).setBaseNode(1)));
    EdgeIteratorState iter = GHUtility.getEdge(g, 0, 1);
    assertEquals(1, iter.getAdjNode());
    assertEquals(carFlagEncoder.setProperties(10, true, true), iter.getFlags());
    // update setProperties
    iter.setFlags(carFlagEncoder.setProperties(20, true, false));
    assertEquals(12, iter.getDistance(), 1e-4);
    // update distance
    iter.setDistance(10);
    assertEquals(10, iter.getDistance(), 1e-4);
    assertEquals(0, GHUtility.count(g.createEdgeExplorer(carOutFilter).setBaseNode(1)));
    iter = GHUtility.getEdge(g, 0, 1);
    assertEquals(carFlagEncoder.setProperties(20, true, false), iter.getFlags());
    assertEquals(10, iter.getDistance(), 1e-4);
    assertEquals(1, GHUtility.getNeighbors(g.createEdgeExplorer().setBaseNode(1)).size());
    assertEquals(0, GHUtility.getNeighbors(g.createEdgeExplorer(carOutFilter).setBaseNode(1)).size());
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) CHGraph(com.graphhopper.storage.CHGraph) EdgeFilter(com.graphhopper.routing.util.EdgeFilter) DefaultEdgeFilter(com.graphhopper.routing.util.DefaultEdgeFilter) FastestWeighting(com.graphhopper.routing.weighting.FastestWeighting) GraphBuilder(com.graphhopper.storage.GraphBuilder) CarFlagEncoder(com.graphhopper.routing.util.CarFlagEncoder) DefaultEdgeFilter(com.graphhopper.routing.util.DefaultEdgeFilter) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) Test(org.junit.Test)

Example 32 with GraphHopperStorage

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

the class AbstractEdgeElevationInterpolatorTest method setUp.

@SuppressWarnings("resource")
@Before
public void setUp() {
    dataFlagEncoder = new DataFlagEncoder();
    graph = new GraphHopperStorage(new RAMDirectory(), new EncodingManager(Arrays.asList(dataFlagEncoder, new FootFlagEncoder()), 8), true, new GraphExtension.NoOpExtension()).create(100);
    edgeElevationInterpolator = createEdgeElevationInterpolator();
    interpolatableWay = createInterpolatableWay();
    normalWay = new ReaderWay(0);
    normalWay.setTag("highway", "primary");
}
Also used : DataFlagEncoder(com.graphhopper.routing.util.DataFlagEncoder) EncodingManager(com.graphhopper.routing.util.EncodingManager) ReaderWay(com.graphhopper.reader.ReaderWay) FootFlagEncoder(com.graphhopper.routing.util.FootFlagEncoder) RAMDirectory(com.graphhopper.storage.RAMDirectory) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) GraphExtension(com.graphhopper.storage.GraphExtension) Before(org.junit.Before)

Example 33 with GraphHopperStorage

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

the class AlternativeRouteTest method testCalcAlternatives.

@Test
public void testCalcAlternatives() throws Exception {
    Weighting weighting = new FastestWeighting(carFE);
    GraphHopperStorage g = createTestGraph(true, em);
    AlternativeRoute altDijkstra = new AlternativeRoute(g, weighting, traversalMode);
    altDijkstra.setMaxShareFactor(0.5);
    altDijkstra.setMaxWeightFactor(2);
    List<AlternativeRoute.AlternativeInfo> pathInfos = altDijkstra.calcAlternatives(5, 4);
    checkAlternatives(pathInfos);
    assertEquals(2, pathInfos.size());
    DijkstraBidirectionRef dijkstra = new DijkstraBidirectionRef(g, weighting, traversalMode);
    Path bestPath = dijkstra.calcPath(5, 4);
    Path bestAlt = pathInfos.get(0).getPath();
    Path secondAlt = pathInfos.get(1).getPath();
    assertEquals(bestPath.calcNodes(), bestAlt.calcNodes());
    assertEquals(bestPath.getWeight(), bestAlt.getWeight(), 1e-3);
    assertEquals(Helper.createTList(5, 6, 3, 4), bestAlt.calcNodes());
    // Note: here plateau is longer, even longer than optimum, but path is longer
    // so which alternative is better? longer plateau.weight with bigger path.weight or smaller path.weight with smaller plateau.weight
    // assertEquals(Helper.createTList(5, 1, 9, 2, 3, 4), secondAlt.calcNodes());
    assertEquals(Helper.createTList(5, 6, 7, 8, 4), secondAlt.calcNodes());
    assertEquals(1667.9, secondAlt.getWeight(), .1);
}
Also used : FastestWeighting(com.graphhopper.routing.weighting.FastestWeighting) Weighting(com.graphhopper.routing.weighting.Weighting) FastestWeighting(com.graphhopper.routing.weighting.FastestWeighting) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) Test(org.junit.Test)

Example 34 with GraphHopperStorage

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

the class DijkstraOneToManyTest method testIssue182.

@Test
public void testIssue182() {
    GraphHopperStorage storage = createGHStorage(false);
    initGraph(storage);
    RoutingAlgorithm algo = createAlgo(storage);
    Path p = algo.calcPath(0, 8);
    assertEquals(Helper.createTList(0, 7, 8), p.calcNodes());
    // expand SPT
    p = algo.calcPath(0, 10);
    assertEquals(Helper.createTList(0, 1, 2, 3, 4, 10), p.calcNodes());
}
Also used : GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) Test(org.junit.Test)

Example 35 with GraphHopperStorage

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

the class DijkstraOneToManyTest method testDifferentEdgeFilter.

@Test
public void testDifferentEdgeFilter() {
    GraphHopperStorage g = new GraphBuilder(encodingManager).setCHGraph(new FastestWeighting(carEncoder)).create();
    g.edge(4, 3, 10, true);
    g.edge(3, 6, 10, true);
    g.edge(4, 5, 10, true);
    g.edge(5, 6, 10, true);
    DijkstraOneToMany algo = (DijkstraOneToMany) createAlgo(g);
    algo.setEdgeFilter(new EdgeFilter() {

        @Override
        public boolean accept(EdgeIteratorState iter) {
            return iter.getAdjNode() != 5;
        }
    });
    Path p = algo.calcPath(4, 6);
    assertEquals(Helper.createTList(4, 3, 6), p.calcNodes());
    // important call!
    algo.clear();
    algo.setEdgeFilter(new EdgeFilter() {

        @Override
        public boolean accept(EdgeIteratorState iter) {
            return iter.getAdjNode() != 3;
        }
    });
    p = algo.calcPath(4, 6);
    assertEquals(Helper.createTList(4, 5, 6), p.calcNodes());
}
Also used : EdgeIteratorState(com.graphhopper.util.EdgeIteratorState) EdgeFilter(com.graphhopper.routing.util.EdgeFilter) GraphBuilder(com.graphhopper.storage.GraphBuilder) FastestWeighting(com.graphhopper.routing.weighting.FastestWeighting) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) Test(org.junit.Test)

Aggregations

GraphHopperStorage (com.graphhopper.storage.GraphHopperStorage)40 Test (org.junit.Test)28 GraphBuilder (com.graphhopper.storage.GraphBuilder)8 PrepEdgeFilter (com.graphhopper.routing.subnetwork.PrepareRoutingSubnetworks.PrepEdgeFilter)7 EncodingManager (com.graphhopper.routing.util.EncodingManager)7 EdgeIteratorState (com.graphhopper.util.EdgeIteratorState)6 FastestWeighting (com.graphhopper.routing.weighting.FastestWeighting)5 TurnCostExtension (com.graphhopper.storage.TurnCostExtension)5 IntArrayList (com.carrotsearch.hppc.IntArrayList)4 RAMDirectory (com.graphhopper.storage.RAMDirectory)4 EdgeExplorer (com.graphhopper.util.EdgeExplorer)4 CarFlagEncoder (com.graphhopper.routing.util.CarFlagEncoder)3 FlagEncoder (com.graphhopper.routing.util.FlagEncoder)3 Weighting (com.graphhopper.routing.weighting.Weighting)3 GraphExtension (com.graphhopper.storage.GraphExtension)3 Random (java.util.Random)3 GraphHopper (com.graphhopper.GraphHopper)2 EdgeFilter (com.graphhopper.routing.util.EdgeFilter)2 HintsMap (com.graphhopper.routing.util.HintsMap)2 AlgoHelperEntry (com.graphhopper.routing.util.TestAlgoCollector.AlgoHelperEntry)2