use of com.graphhopper.storage.GraphHopperStorage in project graphhopper by graphhopper.
the class EdgeBasedRoutingAlgorithmTest method testBlockANode.
@Test
public void testBlockANode() {
GraphHopperStorage g = createStorage(createEncodingManager(true));
initGraph(g);
TurnCostExtension tcs = (TurnCostExtension) g.getExtension();
blockNode3(g, tcs, carEncoder);
for (int i = 0; i <= 7; i++) {
if (i == 3)
continue;
for (int j = 0; j <= 7; j++) {
if (j == 3)
continue;
Path p = createAlgo(g, AlgorithmOptions.start().weighting(createWeighting(carEncoder, tcs, 40)).traversalMode(TraversalMode.EDGE_BASED_2DIR).build()).calcPath(i, j);
// We can go from everywhere to everywhere else without using node 3
assertTrue(p.isFound());
for (IntCursor node : p.calcNodes()) {
assertNotEquals(p.calcNodes().toString(), 3, node.value);
}
}
}
}
use of com.graphhopper.storage.GraphHopperStorage in project graphhopper by graphhopper.
the class FakeWalkNetworkBuilder method buildWalkNetwork.
static void buildWalkNetwork(Collection<GTFSFeed> feeds, GraphHopperStorage graph, PtFlagEncoder encoder, DistanceCalc distCalc) {
Collection<ConstraintVertex> sites = new ArrayList<>();
Map<Vertex, Integer> vertex2nodeId = new HashMap<>();
feeds.stream().flatMap(feed -> feed.stops.values().stream()).forEach(stop -> {
int i = graph.getNodes();
graph.getNodeAccess().setNode(i++, stop.stop_lat, stop.stop_lon);
ConstraintVertex site = new ConstraintVertex(new Coordinate(stop.stop_lon, stop.stop_lat));
sites.add(site);
vertex2nodeId.put(site, i - 1);
});
ConformingDelaunayTriangulator conformingDelaunayTriangulator = new ConformingDelaunayTriangulator(sites, 0.0);
conformingDelaunayTriangulator.setConstraints(new ArrayList(), new ArrayList());
conformingDelaunayTriangulator.formInitialDelaunay();
QuadEdgeSubdivision tin = conformingDelaunayTriangulator.getSubdivision();
List<QuadEdge> edges = tin.getPrimaryEdges(false);
for (QuadEdge edge : edges) {
EdgeIteratorState ghEdge = graph.edge(vertex2nodeId.get(edge.orig()), vertex2nodeId.get(edge.dest()));
double distance = distCalc.calcDist(edge.orig().getY(), edge.orig().getX(), edge.dest().getY(), edge.dest().getX());
ghEdge.setDistance(distance);
ghEdge.setFlags(encoder.setSpeed(ghEdge.getFlags(), 5.0));
ghEdge.setFlags(encoder.setAccess(ghEdge.getFlags(), true, true));
}
}
use of com.graphhopper.storage.GraphHopperStorage 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.storage.GraphHopperStorage 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()), null);
assertEquals(1, dec.getPreparations().get(0).getLandmarkStorage().getFactor(), .1);
assertEquals(0.3, dec.getPreparations().get(1).getLandmarkStorage().getFactor(), .1);
}
use of com.graphhopper.storage.GraphHopperStorage in project graphhopper by graphhopper.
the class PrepareRoutingSubnetworksTest method testAddEdgesAfterwards.
@Test
public void testAddEdgesAfterwards() {
GraphHopperStorage g = createDeadEndUnvisitedNetworkStorage(em);
assertEquals(11, g.getNodes());
PrepareRoutingSubnetworks instance = new PrepareRoutingSubnetworks(g, Collections.singletonList(carFlagEncoder)).setMinOneWayNetworkSize(3);
int removed = instance.removeDeadEndUnvisitedNetworks(new PrepEdgeFilter(carFlagEncoder));
assertEquals(3, removed);
instance.markNodesRemovedIfUnreachable();
g.optimize();
assertEquals(8, g.getNodes());
assertTrue(isConsistent(g));
g.edge(7, 8);
assertTrue(isConsistent(g));
}
Aggregations