use of com.graphhopper.storage.RAMDirectory in project graphhopper by graphhopper.
the class ChangeGraphHelperTest method testApplyChanges.
@Test
public void testApplyChanges() {
// 0-1-2
// | |
// 3-4
graph.edge(0, 1, 1, true);
graph.edge(1, 2, 1, true);
graph.edge(3, 4, 1, true);
graph.edge(0, 3, 1, true);
graph.edge(1, 4, 1, true);
AbstractRoutingAlgorithmTester.updateDistancesFor(graph, 0, 0.01, 0.00);
AbstractRoutingAlgorithmTester.updateDistancesFor(graph, 1, 0.01, 0.01);
AbstractRoutingAlgorithmTester.updateDistancesFor(graph, 2, 0.01, 0.02);
AbstractRoutingAlgorithmTester.updateDistancesFor(graph, 3, 0.00, 0.00);
AbstractRoutingAlgorithmTester.updateDistancesFor(graph, 4, 0.00, 0.01);
LocationIndex locationIndex = new LocationIndexTree(graph, new RAMDirectory()).prepareIndex();
FlagEncoder encoder = encodingManager.getEncoder("car");
double defaultSpeed = encoder.getSpeed(GHUtility.getEdge(graph, 0, 1).getFlags());
AllEdgesIterator iter = graph.getAllEdges();
while (iter.next()) {
long flags = GHUtility.getEdge(graph, 0, 1).getFlags();
assertEquals(defaultSpeed, encoder.getSpeed(flags), .1);
assertTrue(encoder.isForward(flags));
}
Reader reader = new InputStreamReader(getClass().getResourceAsStream("overlaydata1.json"), Helper.UTF_CS);
ChangeGraphHelper instance = new ChangeGraphHelper(graph, locationIndex);
JsonFeatureConverter converter = new JsonFeatureConverter(ghson, instance, encodingManager);
long updates = converter.applyChanges(reader);
assertEquals(2, updates);
// assert changed speed and access
double newSpeed = encoder.getSpeed(GHUtility.getEdge(graph, 0, 1).getFlags());
assertEquals(10, newSpeed, .1);
assertTrue(newSpeed < defaultSpeed);
assertFalse(encoder.isForward(GHUtility.getEdge(graph, 3, 4).getFlags()));
}
use of com.graphhopper.storage.RAMDirectory in project graphhopper by graphhopper.
the class LocationIndexTreeTest method createIndexNoPrepare.
public LocationIndexTree createIndexNoPrepare(Graph g, int resolution) {
Directory dir = new RAMDirectory(location);
LocationIndexTree tmpIDX = new LocationIndexTree(g, dir);
tmpIDX.setResolution(resolution);
return tmpIDX;
}
use of com.graphhopper.storage.RAMDirectory in project graphhopper by graphhopper.
the class LocationIndexTreeTest method createTestGraph2.
// see testgraph2.jpg
Graph createTestGraph2() {
Graph graph = createGHStorage(new RAMDirectory(), encodingManager, false);
NodeAccess na = graph.getNodeAccess();
na.setNode(8, 49.94553, 11.57214);
na.setNode(9, 49.94553, 11.57314);
na.setNode(10, 49.94553, 11.57414);
na.setNode(11, 49.94553, 11.57514);
na.setNode(12, 49.94553, 11.57614);
na.setNode(13, 49.94553, 11.57714);
na.setNode(0, 49.94653, 11.57114);
na.setNode(1, 49.94653, 11.57214);
na.setNode(2, 49.94653, 11.57314);
na.setNode(3, 49.94653, 11.57414);
na.setNode(4, 49.94653, 11.57514);
na.setNode(5, 49.94653, 11.57614);
na.setNode(6, 49.94653, 11.57714);
na.setNode(7, 49.94653, 11.57814);
na.setNode(14, 49.94753, 11.57214);
na.setNode(15, 49.94753, 11.57314);
na.setNode(16, 49.94753, 11.57614);
na.setNode(17, 49.94753, 11.57814);
na.setNode(18, 49.94853, 11.57114);
na.setNode(19, 49.94853, 11.57214);
na.setNode(20, 49.94853, 11.57814);
na.setNode(21, 49.94953, 11.57214);
na.setNode(22, 49.94953, 11.57614);
na.setNode(23, 49.95053, 11.57114);
na.setNode(24, 49.95053, 11.57214);
na.setNode(25, 49.95053, 11.57314);
na.setNode(26, 49.95053, 11.57514);
na.setNode(27, 49.95053, 11.57614);
na.setNode(28, 49.95053, 11.57714);
na.setNode(29, 49.95053, 11.57814);
na.setNode(30, 49.95153, 11.57214);
na.setNode(31, 49.95153, 11.57314);
na.setNode(32, 49.95153, 11.57514);
na.setNode(33, 49.95153, 11.57614);
na.setNode(34, 49.95153, 11.57714);
na.setNode(34, 49.95153, 11.57714);
// to create correct bounds
// bottom left
na.setNode(100, 49.941, 11.56614);
// top right
na.setNode(101, 49.96053, 11.58814);
graph.edge(0, 1, 10, true);
graph.edge(1, 2, 10, true);
graph.edge(2, 3, 10, true);
graph.edge(3, 4, 10, true);
graph.edge(4, 5, 10, true);
graph.edge(6, 7, 10, true);
graph.edge(8, 2, 10, true);
graph.edge(9, 2, 10, true);
graph.edge(10, 3, 10, true);
graph.edge(11, 4, 10, true);
graph.edge(12, 5, 10, true);
graph.edge(13, 6, 10, true);
graph.edge(1, 14, 10, true);
graph.edge(2, 15, 10, true);
graph.edge(5, 16, 10, true);
graph.edge(14, 15, 10, true);
graph.edge(16, 17, 10, true);
graph.edge(16, 20, 10, true);
graph.edge(16, 25, 10, true);
graph.edge(18, 14, 10, true);
graph.edge(18, 19, 10, true);
graph.edge(18, 21, 10, true);
graph.edge(19, 21, 10, true);
graph.edge(21, 24, 10, true);
graph.edge(23, 24, 10, true);
graph.edge(24, 25, 10, true);
graph.edge(26, 27, 10, true);
graph.edge(27, 28, 10, true);
graph.edge(28, 29, 10, true);
graph.edge(24, 30, 10, true);
graph.edge(24, 31, 10, true);
graph.edge(26, 32, 10, true);
graph.edge(27, 33, 10, true);
graph.edge(28, 34, 10, true);
return graph;
}
use of com.graphhopper.storage.RAMDirectory in project graphhopper by graphhopper.
the class NameIndexTest method testFlush.
@Test
public void testFlush() {
String location = "./target/nameindex-store";
Helper.removeDir(new File(location));
NameIndex index = new NameIndex(new RAMDirectory(location, true).create()).create(1000);
long pointer = index.put("test");
index.flush();
index.close();
index = new NameIndex(new RAMDirectory(location, true));
assertTrue(index.loadExisting());
assertEquals("test", index.get(pointer));
// make sure bytePointer is correctly set after loadExisting
long newPointer = index.put("testing");
assertEquals(newPointer + ">" + pointer, pointer + "test".getBytes().length + 1, newPointer);
index.close();
Helper.removeDir(new File(location));
}
use of com.graphhopper.storage.RAMDirectory in project graphhopper by graphhopper.
the class LocationIndexTreeTest method testFindNClosest.
// 0---1---2
// | | |
// |10 | |
// | | | |
// 3-9-4---5
// | | |
// 6---7---8
@Test
public void testFindNClosest() {
Graph graph = createGHStorage(new RAMDirectory(), encodingManager, false);
NodeAccess na = graph.getNodeAccess();
na.setNode(0, 0.0010, 0.0000);
na.setNode(1, 0.0010, 0.0005);
na.setNode(2, 0.0010, 0.0010);
na.setNode(3, 0.0005, 0.0000);
na.setNode(4, 0.0005, 0.0005);
na.setNode(5, 0.0005, 0.0010);
na.setNode(6, 0.0000, 0.0000);
na.setNode(7, 0.0000, 0.0005);
na.setNode(8, 0.0000, 0.0010);
na.setNode(9, 0.0005, 0.0002);
na.setNode(10, 0.0007, 0.0002);
graph.edge(0, 1);
graph.edge(1, 2);
graph.edge(0, 3);
graph.edge(1, 4);
graph.edge(2, 5);
graph.edge(3, 9);
graph.edge(9, 4);
EdgeIteratorState edge4_5 = graph.edge(4, 5);
graph.edge(10, 9);
graph.edge(3, 6);
EdgeIteratorState edge4_7 = graph.edge(4, 7);
graph.edge(5, 8);
graph.edge(6, 7);
graph.edge(7, 8);
LocationIndexTree index = createIndexNoPrepare(graph, 500);
index.prepareIndex();
// query node 4 => get at least 4-5, 4-7
List<QueryResult> result = index.findNClosest(0.0004, 0.0006, EdgeFilter.ALL_EDGES, 15);
List<Integer> ids = new ArrayList<Integer>();
for (QueryResult qr : result) {
ids.add(qr.getClosestEdge().getEdge());
}
Collections.sort(ids);
assertEquals("edge ids do not match", Arrays.asList(edge4_5.getEdge(), edge4_7.getEdge()), ids);
}
Aggregations