Search in sources :

Example 6 with RAMDirectory

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()));
}
Also used : AllEdgesIterator(com.graphhopper.routing.util.AllEdgesIterator) InputStreamReader(java.io.InputStreamReader) FlagEncoder(com.graphhopper.routing.util.FlagEncoder) JsonFeatureConverter(com.graphhopper.json.JsonFeatureConverter) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) LocationIndex(com.graphhopper.storage.index.LocationIndex) RAMDirectory(com.graphhopper.storage.RAMDirectory) LocationIndexTree(com.graphhopper.storage.index.LocationIndexTree) Test(org.junit.Test)

Example 7 with RAMDirectory

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;
}
Also used : RAMDirectory(com.graphhopper.storage.RAMDirectory) RAMDirectory(com.graphhopper.storage.RAMDirectory) Directory(com.graphhopper.storage.Directory)

Example 8 with RAMDirectory

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;
}
Also used : NodeAccess(com.graphhopper.storage.NodeAccess) Graph(com.graphhopper.storage.Graph) RAMDirectory(com.graphhopper.storage.RAMDirectory)

Example 9 with RAMDirectory

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));
}
Also used : File(java.io.File) RAMDirectory(com.graphhopper.storage.RAMDirectory) Test(org.junit.Test)

Example 10 with RAMDirectory

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);
}
Also used : NodeAccess(com.graphhopper.storage.NodeAccess) Graph(com.graphhopper.storage.Graph) ArrayList(java.util.ArrayList) RAMDirectory(com.graphhopper.storage.RAMDirectory) Test(org.junit.Test)

Aggregations

RAMDirectory (com.graphhopper.storage.RAMDirectory)25 Test (org.junit.Test)18 Graph (com.graphhopper.storage.Graph)5 NodeAccess (com.graphhopper.storage.NodeAccess)5 DataAccess (com.graphhopper.storage.DataAccess)4 Directory (com.graphhopper.storage.Directory)4 GraphHopperStorage (com.graphhopper.storage.GraphHopperStorage)4 EncodingManager (com.graphhopper.routing.util.EncodingManager)3 FastestWeighting (com.graphhopper.routing.weighting.FastestWeighting)3 GraphExtension (com.graphhopper.storage.GraphExtension)3 FlagEncoder (com.graphhopper.routing.util.FlagEncoder)2 Weighting (com.graphhopper.routing.weighting.Weighting)2 LocationIndex (com.graphhopper.storage.index.LocationIndex)2 LocationIndexTree (com.graphhopper.storage.index.LocationIndexTree)2 GHPoint (com.graphhopper.util.shapes.GHPoint)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2 Before (org.junit.Before)2 JsonFeatureConverter (com.graphhopper.json.JsonFeatureConverter)1 ReaderWay (com.graphhopper.reader.ReaderWay)1