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());
}
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");
}
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);
}
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());
}
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());
}
Aggregations