use of com.graphhopper.routing.util.HintsMap in project graphhopper by graphhopper.
the class RoutingAlgorithmIT method createAlgos.
public static List<AlgoHelperEntry> createAlgos(final GraphHopper hopper, final HintsMap hints, TraversalMode tMode) {
GraphHopperStorage ghStorage = hopper.getGraphHopperStorage();
LocationIndex idx = hopper.getLocationIndex();
String addStr = "";
if (tMode.isEdgeBased())
addStr = "turn|";
FlagEncoder encoder = hopper.getEncodingManager().getEncoder(hints.getVehicle());
Weighting weighting = hopper.createWeighting(hints, encoder, hopper.getGraphHopperStorage());
HintsMap defaultHints = new HintsMap().put(Parameters.CH.DISABLE, true).put(Parameters.Landmark.DISABLE, true).setVehicle(hints.getVehicle()).setWeighting(hints.getWeighting());
AlgorithmOptions defaultOpts = AlgorithmOptions.start(new AlgorithmOptions("", weighting, tMode)).hints(defaultHints).build();
List<AlgoHelperEntry> prepare = new ArrayList<>();
prepare.add(new AlgoHelperEntry(ghStorage, AlgorithmOptions.start(defaultOpts).algorithm(ASTAR).build(), idx, "astar|beeline|" + addStr + weighting));
// later: include dijkstraOneToMany
prepare.add(new AlgoHelperEntry(ghStorage, AlgorithmOptions.start(defaultOpts).algorithm(DIJKSTRA).build(), idx, "dijkstra|" + addStr + weighting));
AlgorithmOptions astarbiOpts = AlgorithmOptions.start(defaultOpts).algorithm(ASTAR_BI).build();
astarbiOpts.getHints().put(ASTAR_BI + ".approximation", "BeelineSimplification");
AlgorithmOptions dijkstrabiOpts = AlgorithmOptions.start(defaultOpts).algorithm(DIJKSTRA_BI).build();
prepare.add(new AlgoHelperEntry(ghStorage, astarbiOpts, idx, "astarbi|beeline|" + addStr + weighting));
prepare.add(new AlgoHelperEntry(ghStorage, dijkstrabiOpts, idx, "dijkstrabi|" + addStr + weighting));
// add additional preparations if CH and LM preparation are enabled
if (hopper.getLMFactoryDecorator().isEnabled()) {
final HintsMap lmHints = new HintsMap(defaultHints).put(Parameters.Landmark.DISABLE, false);
prepare.add(new AlgoHelperEntry(ghStorage, AlgorithmOptions.start(astarbiOpts).hints(lmHints).build(), idx, "astarbi|landmarks|" + weighting) {
@Override
public RoutingAlgorithmFactory createRoutingFactory() {
return hopper.getAlgorithmFactory(lmHints);
}
});
}
if (hopper.getCHFactoryDecorator().isEnabled()) {
final HintsMap chHints = new HintsMap(defaultHints).put(Parameters.CH.DISABLE, false);
Weighting pickedWeighting = null;
for (Weighting tmpWeighting : hopper.getCHFactoryDecorator().getWeightings()) {
if (tmpWeighting.equals(weighting)) {
pickedWeighting = tmpWeighting;
break;
}
}
if (pickedWeighting == null)
throw new IllegalStateException("Didn't find weighting " + hints.getWeighting() + " in " + hopper.getCHFactoryDecorator().getWeightings());
prepare.add(new AlgoHelperEntry(ghStorage.getGraph(CHGraph.class, pickedWeighting), AlgorithmOptions.start(dijkstrabiOpts).hints(chHints).build(), idx, "dijkstrabi|ch|prepare|" + hints.getWeighting()) {
@Override
public RoutingAlgorithmFactory createRoutingFactory() {
return hopper.getAlgorithmFactory(chHints);
}
});
prepare.add(new AlgoHelperEntry(ghStorage.getGraph(CHGraph.class, pickedWeighting), AlgorithmOptions.start(astarbiOpts).hints(chHints).build(), idx, "astarbi|ch|prepare|" + hints.getWeighting()) {
@Override
public RoutingAlgorithmFactory createRoutingFactory() {
return hopper.getAlgorithmFactory(chHints);
}
});
}
return prepare;
}
use of com.graphhopper.routing.util.HintsMap in project graphhopper by graphhopper.
the class GenericWeightingTest method testRoadAttributeRestriction.
@Test
public void testRoadAttributeRestriction() {
EdgeIteratorState edge = graph.getEdgeIteratorState(0, 1);
Weighting instance = new GenericWeighting(encoder, new HintsMap().put(GenericWeighting.HEIGHT_LIMIT, 4.0));
assertEquals(edgeWeight, instance.calcWeight(edge, false, EdgeIterator.NO_EDGE), 1e-8);
instance = new GenericWeighting(encoder, new HintsMap().put(GenericWeighting.HEIGHT_LIMIT, 5.0));
assertEquals(Double.POSITIVE_INFINITY, instance.calcWeight(edge, false, EdgeIterator.NO_EDGE), 1e-8);
}
use of com.graphhopper.routing.util.HintsMap in project graphhopper by graphhopper.
the class RoutingAlgorithmIT method testPerformance.
@Test
public void testPerformance() throws IOException {
int N = 10;
int noJvmWarming = N / 4;
Random rand = new Random(0);
final EncodingManager eManager = new EncodingManager("car");
final GraphHopperStorage graph = new GraphBuilder(eManager).create();
String bigFile = "10000EWD.txt.gz";
new PrincetonReader(graph).setStream(new GZIPInputStream(PrincetonReader.class.getResourceAsStream(bigFile))).read();
GraphHopper hopper = new GraphHopper() {
{
setCHEnabled(false);
setEncodingManager(eManager);
loadGraph(graph);
}
@Override
protected LocationIndex createLocationIndex(Directory dir) {
return new LocationIndexTree(graph, dir);
}
};
Collection<AlgoHelperEntry> prepares = createAlgos(hopper, new HintsMap().setWeighting("shortest").setVehicle("car"), TraversalMode.NODE_BASED);
for (AlgoHelperEntry entry : prepares) {
StopWatch sw = new StopWatch();
for (int i = 0; i < N; i++) {
int node1 = Math.abs(rand.nextInt(graph.getNodes()));
int node2 = Math.abs(rand.nextInt(graph.getNodes()));
RoutingAlgorithm d = entry.createRoutingFactory().createAlgo(graph, entry.getAlgorithmOptions());
if (i >= noJvmWarming)
sw.start();
Path p = d.calcPath(node1, node2);
// avoid jvm optimization => call p.distance
if (i >= noJvmWarming && p.getDistance() > -1)
sw.stop();
// System.out.println("#" + i + " " + name + ":" + sw.getSeconds() + " " + p.nodes());
}
float perRun = sw.stop().getSeconds() / ((float) (N - noJvmWarming));
System.out.println("# " + getClass().getSimpleName() + " " + entry + ":" + sw.stop().getSeconds() + ", per run:" + perRun);
assertTrue("speed to low!? " + perRun + " per run", perRun < 0.08);
}
}
use of com.graphhopper.routing.util.HintsMap in project graphhopper by graphhopper.
the class GenericWeightingTest method testCalcTime.
@Test
public void testCalcTime() {
GenericWeighting weighting = new GenericWeighting(encoder, new HintsMap());
EdgeIteratorState edge = graph.getEdgeIteratorState(0, 1);
assertEquals(edgeWeight, weighting.calcMillis(edge, false, EdgeIterator.NO_EDGE), .1);
}
use of com.graphhopper.routing.util.HintsMap in project graphhopper by graphhopper.
the class GenericWeightingTest method testDisabledRoadAttributes.
@Test
public void testDisabledRoadAttributes() {
DataFlagEncoder simpleEncoder = new DataFlagEncoder();
EncodingManager simpleEncodingManager = new EncodingManager(simpleEncoder);
Graph simpleGraph = new GraphBuilder(simpleEncodingManager).create();
ReaderWay way = new ReaderWay(27l);
way.setTag("highway", "primary");
way.setTag("maxspeed", "10");
way.setTag("maxheight", "4.4");
// 0-1
simpleGraph.edge(0, 1, 1, true);
AbstractRoutingAlgorithmTester.updateDistancesFor(simpleGraph, 0, 0.00, 0.00);
AbstractRoutingAlgorithmTester.updateDistancesFor(simpleGraph, 1, 0.01, 0.01);
simpleGraph.getEdgeIteratorState(0, 1).setFlags(simpleEncoder.handleWayTags(way, 1, 0));
Weighting instance = new GenericWeighting(simpleEncoder, new HintsMap().put(GenericWeighting.HEIGHT_LIMIT, 5.0));
EdgeIteratorState edge = simpleGraph.getEdgeIteratorState(0, 1);
assertEquals(edgeWeight, instance.calcWeight(edge, false, EdgeIterator.NO_EDGE), 1e-8);
}
Aggregations