use of com.graphhopper.storage.GraphBuilder in project graphhopper by graphhopper.
the class ChangeGraphHelperTest method setUp.
@Before
public void setUp() {
encodingManager = new EncodingManager("car");
graph = new GraphBuilder(encodingManager).create();
ghson = new GHJsonFactory().create();
}
use of com.graphhopper.storage.GraphBuilder 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.GraphBuilder in project graphhopper by graphhopper.
the class DataFlagEncoderTest method testSpatialId.
@Test
public void testSpatialId() {
final GermanySpatialRule germany = new GermanySpatialRule();
germany.setBorders(Collections.singletonList(new Polygon(new double[] { 0, 0, 1, 1 }, new double[] { 0, 1, 1, 0 })));
SpatialRuleLookup index = new SpatialRuleLookup() {
@Override
public SpatialRule lookupRule(double lat, double lon) {
for (Polygon polygon : germany.getBorders()) {
if (polygon.contains(lat, lon)) {
return germany;
}
}
return SpatialRule.EMPTY;
}
@Override
public SpatialRule lookupRule(GHPoint point) {
return lookupRule(point.lat, point.lon);
}
@Override
public int getSpatialId(SpatialRule rule) {
if (germany.equals(rule)) {
return 1;
} else {
return 0;
}
}
@Override
public int size() {
return 2;
}
@Override
public BBox getBounds() {
return new BBox(-180, 180, -90, 90);
}
};
DataFlagEncoder encoder = new DataFlagEncoder(new PMap());
encoder.setSpatialRuleLookup(index);
EncodingManager em = new EncodingManager(encoder);
ReaderWay way = new ReaderWay(27l);
way.setTag("highway", "track");
way.setTag("estimated_center", new GHPoint(0.005, 0.005));
ReaderWay way2 = new ReaderWay(28l);
way2.setTag("highway", "track");
way2.setTag("estimated_center", new GHPoint(-0.005, -0.005));
ReaderWay livingStreet = new ReaderWay(29l);
livingStreet.setTag("highway", "living_street");
livingStreet.setTag("estimated_center", new GHPoint(0.005, 0.005));
ReaderWay livingStreet2 = new ReaderWay(30l);
livingStreet2.setTag("highway", "living_street");
livingStreet2.setTag("estimated_center", new GHPoint(-0.005, -0.005));
Graph graph = new GraphBuilder(em).create();
EdgeIteratorState e1 = graph.edge(0, 1, 1, true);
EdgeIteratorState e2 = graph.edge(0, 2, 1, true);
EdgeIteratorState e3 = graph.edge(0, 3, 1, true);
EdgeIteratorState e4 = graph.edge(0, 4, 1, true);
AbstractRoutingAlgorithmTester.updateDistancesFor(graph, 0, 0.00, 0.00);
AbstractRoutingAlgorithmTester.updateDistancesFor(graph, 1, 0.01, 0.01);
AbstractRoutingAlgorithmTester.updateDistancesFor(graph, 2, -0.01, -0.01);
AbstractRoutingAlgorithmTester.updateDistancesFor(graph, 3, 0.01, 0.01);
AbstractRoutingAlgorithmTester.updateDistancesFor(graph, 4, -0.01, -0.01);
e1.setFlags(encoder.handleWayTags(way, 1, 0));
e2.setFlags(encoder.handleWayTags(way2, 1, 0));
e3.setFlags(encoder.handleWayTags(livingStreet, 1, 0));
e4.setFlags(encoder.handleWayTags(livingStreet2, 1, 0));
assertEquals(index.getSpatialId(new GermanySpatialRule()), encoder.getSpatialId(e1.getFlags()));
assertEquals(index.getSpatialId(SpatialRule.EMPTY), encoder.getSpatialId(e2.getFlags()));
assertEquals(AccessValue.EVENTUALLY_ACCESSIBLE, encoder.getAccessValue(e1.getFlags()));
assertEquals(AccessValue.ACCESSIBLE, encoder.getAccessValue(e2.getFlags()));
assertEquals(5, encoder.getMaxspeed(e3, -1, false), .1);
assertEquals(-1, encoder.getMaxspeed(e4, -1, false), .1);
}
use of com.graphhopper.storage.GraphBuilder 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);
}
use of com.graphhopper.storage.GraphBuilder in project graphhopper by graphhopper.
the class PrincetonReaderTest method testMediumRead.
@Test
public void testMediumRead() throws IOException {
Graph graph = new GraphBuilder(encodingManager).create();
new PrincetonReader(graph).setStream(new GZIPInputStream(PrincetonReader.class.getResourceAsStream("mediumEWD.txt.gz"))).read();
assertEquals(250, graph.getNodes());
EdgeExplorer explorer = graph.createEdgeExplorer(carOutEdges);
assertEquals(13, count(explorer.setBaseNode(244)));
assertEquals(11, count(explorer.setBaseNode(16)));
}
Aggregations