use of com.graphhopper.routing.util.EncodingManager in project graphhopper by graphhopper.
the class PrepareContractionHierarchiesTest method testMultiplePreparationsDifferentView.
@Test
public void testMultiplePreparationsDifferentView() {
CarFlagEncoder tmpCarEncoder = new CarFlagEncoder();
BikeFlagEncoder tmpBikeEncoder = new BikeFlagEncoder();
EncodingManager tmpEncodingManager = new EncodingManager(tmpCarEncoder, tmpBikeEncoder);
Weighting carWeighting = new FastestWeighting(tmpCarEncoder);
Weighting bikeWeighting = new FastestWeighting(tmpBikeEncoder);
List<Weighting> chWeightings = Arrays.asList(carWeighting, bikeWeighting);
GraphHopperStorage ghStorage = new GraphHopperStorage(chWeightings, dir, tmpEncodingManager, false, new GraphExtension.NoOpExtension()).create(1000);
initShortcutsGraph(ghStorage);
EdgeIteratorState edge = GHUtility.getEdge(ghStorage, 9, 14);
edge.setFlags(tmpBikeEncoder.setAccess(edge.getFlags(), false, false));
ghStorage.freeze();
checkPath(ghStorage, carWeighting, 7, 5, Helper.createTList(3, 9, 14, 16, 13, 12));
// detour around blocked 9,14
checkPath(ghStorage, bikeWeighting, 9, 5, Helper.createTList(3, 10, 14, 16, 13, 12));
}
use of com.graphhopper.routing.util.EncodingManager in project graphhopper by graphhopper.
the class LMAlgoFactoryDecoratorTest method addWeighting.
@Test
public void addWeighting() {
LMAlgoFactoryDecorator dec = new LMAlgoFactoryDecorator().setEnabled(true);
dec.addWeighting("fastest");
assertEquals(Arrays.asList("fastest"), dec.getWeightingsAsStrings());
// special parameters like the maximum weight
dec = new LMAlgoFactoryDecorator().setEnabled(true);
dec.addWeighting("fastest|maximum=65000");
dec.addWeighting("shortest|maximum=20000");
assertEquals(Arrays.asList("fastest", "shortest"), dec.getWeightingsAsStrings());
FlagEncoder car = new CarFlagEncoder();
EncodingManager em = new EncodingManager(car);
dec.addWeighting(new FastestWeighting(car)).addWeighting(new ShortestWeighting(car));
dec.createPreparations(new GraphHopperStorage(new RAMDirectory(), em, false, new GraphExtension.NoOpExtension()), TraversalMode.NODE_BASED, null);
assertEquals(1, dec.getPreparations().get(0).getLandmarkStorage().getFactor(), .1);
assertEquals(0.3, dec.getPreparations().get(1).getLandmarkStorage().getFactor(), .1);
}
use of com.graphhopper.routing.util.EncodingManager 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 PrinctonReader(graph).setStream(new GZIPInputStream(PrinctonReader.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);
}
}
Aggregations