Search in sources :

Example 11 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 12 with RAMDirectory

use of com.graphhopper.storage.RAMDirectory in project graphhopper by graphhopper.

the class AlternativeRouteTest method createTestGraph.

public GraphHopperStorage createTestGraph(boolean fullGraph, EncodingManager tmpEM) {
    GraphHopperStorage graph = new GraphHopperStorage(new RAMDirectory(), tmpEM, false, new GraphExtension.NoOpExtension());
    graph.create(1000);
    /* 9
         _/\
         1  2-3-4-10
         \   /   \
         5--6-7---8
        
         */
    graph.edge(1, 9, 1, true);
    graph.edge(9, 2, 1, true);
    if (fullGraph)
        graph.edge(2, 3, 1, true);
    graph.edge(3, 4, 1, true);
    graph.edge(4, 10, 1, true);
    graph.edge(5, 6, 1, true);
    graph.edge(6, 7, 1, true);
    graph.edge(7, 8, 1, true);
    if (fullGraph)
        graph.edge(1, 5, 2, true);
    graph.edge(6, 3, 1, true);
    graph.edge(4, 8, 1, true);
    updateDistancesFor(graph, 5, 0.00, 0.05);
    updateDistancesFor(graph, 6, 0.00, 0.10);
    updateDistancesFor(graph, 7, 0.00, 0.15);
    updateDistancesFor(graph, 8, 0.00, 0.25);
    updateDistancesFor(graph, 1, 0.05, 0.00);
    updateDistancesFor(graph, 9, 0.10, 0.05);
    updateDistancesFor(graph, 2, 0.05, 0.10);
    updateDistancesFor(graph, 3, 0.05, 0.15);
    updateDistancesFor(graph, 4, 0.05, 0.25);
    updateDistancesFor(graph, 10, 0.05, 0.30);
    return graph;
}
Also used : RAMDirectory(com.graphhopper.storage.RAMDirectory) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) GraphExtension(com.graphhopper.storage.GraphExtension)

Example 13 with RAMDirectory

use of com.graphhopper.storage.RAMDirectory in project graphhopper by graphhopper.

the class SubnetworkStorageTest method testSimple.

@Test
public void testSimple() {
    SubnetworkStorage storage = new SubnetworkStorage(new RAMDirectory(), "fastest");
    storage.create(2000);
    storage.setSubnetwork(1, 88);
    assertEquals(88, storage.getSubnetwork(1));
    assertEquals(0, storage.getSubnetwork(0));
    storage.close();
}
Also used : RAMDirectory(com.graphhopper.storage.RAMDirectory) Test(org.junit.Test)

Example 14 with RAMDirectory

use of com.graphhopper.storage.RAMDirectory in project graphhopper by graphhopper.

the class RoundTripRoutingTemplateTest method testCalcRoundTrip.

@Test
public void testCalcRoundTrip() throws Exception {
    Weighting weighting = new FastestWeighting(carFE);
    Graph g = createTestGraph(true);
    RoundTripRoutingTemplate rTripRouting = new RoundTripRoutingTemplate(new GHRequest(), new GHResponse(), null, 1);
    LocationIndex locationIndex = new LocationIndexTree(g, new RAMDirectory()).prepareIndex();
    QueryResult qr4 = locationIndex.findClosest(0.05, 0.25, EdgeFilter.ALL_EDGES);
    assertEquals(4, qr4.getClosestNode());
    QueryResult qr5 = locationIndex.findClosest(0.00, 0.05, EdgeFilter.ALL_EDGES);
    assertEquals(5, qr5.getClosestNode());
    QueryResult qr6 = locationIndex.findClosest(0.00, 0.10, EdgeFilter.ALL_EDGES);
    assertEquals(6, qr6.getClosestNode());
    QueryGraph qGraph = new QueryGraph(g);
    qGraph.lookup(qr4, qr5);
    rTripRouting.setQueryResults(Arrays.asList(qr5, qr4, qr5));
    List<Path> paths = rTripRouting.calcPaths(qGraph, new RoutingAlgorithmFactorySimple(), new AlgorithmOptions(DIJKSTRA_BI, weighting, tMode));
    assertEquals(2, paths.size());
    assertEquals(Helper.createTList(5, 6, 3, 4), paths.get(0).calcNodes());
    assertEquals(Helper.createTList(4, 8, 7, 6, 5), paths.get(1).calcNodes());
    qGraph = new QueryGraph(g);
    qGraph.lookup(qr4, qr6);
    rTripRouting.setQueryResults(Arrays.asList(qr6, qr4, qr6));
    paths = rTripRouting.calcPaths(qGraph, new RoutingAlgorithmFactorySimple(), new AlgorithmOptions(DIJKSTRA_BI, weighting, tMode));
    assertEquals(2, paths.size());
    assertEquals(Helper.createTList(6, 3, 4), paths.get(0).calcNodes());
    assertEquals(Helper.createTList(4, 8, 7, 6), paths.get(1).calcNodes());
}
Also used : GHResponse(com.graphhopper.GHResponse) LocationIndex(com.graphhopper.storage.index.LocationIndex) RAMDirectory(com.graphhopper.storage.RAMDirectory) LocationIndexTree(com.graphhopper.storage.index.LocationIndexTree) QueryResult(com.graphhopper.storage.index.QueryResult) FastestWeighting(com.graphhopper.routing.weighting.FastestWeighting) Weighting(com.graphhopper.routing.weighting.Weighting) Graph(com.graphhopper.storage.Graph) GHRequest(com.graphhopper.GHRequest) FastestWeighting(com.graphhopper.routing.weighting.FastestWeighting) Test(org.junit.Test)

Example 15 with RAMDirectory

use of com.graphhopper.storage.RAMDirectory in project graphhopper by graphhopper.

the class AbstractEdgeElevationInterpolatorTest method setUp.

@SuppressWarnings("resource")
@Before
public void setUp() {
    dataFlagEncoder = new DataFlagEncoder();
    graph = new GraphHopperStorage(new RAMDirectory(), new EncodingManager(Arrays.asList(dataFlagEncoder, new FootFlagEncoder()), 8), true, new GraphExtension.NoOpExtension()).create(100);
    edgeElevationInterpolator = createEdgeElevationInterpolator();
    interpolatableWay = createInterpolatableWay();
    normalWay = new ReaderWay(0);
    normalWay.setTag("highway", "primary");
}
Also used : DataFlagEncoder(com.graphhopper.routing.util.DataFlagEncoder) EncodingManager(com.graphhopper.routing.util.EncodingManager) ReaderWay(com.graphhopper.reader.ReaderWay) FootFlagEncoder(com.graphhopper.routing.util.FootFlagEncoder) RAMDirectory(com.graphhopper.storage.RAMDirectory) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) GraphExtension(com.graphhopper.storage.GraphExtension) Before(org.junit.Before)

Aggregations

RAMDirectory (com.graphhopper.storage.RAMDirectory)22 Test (org.junit.Test)16 Graph (com.graphhopper.storage.Graph)5 DataAccess (com.graphhopper.storage.DataAccess)4 NodeAccess (com.graphhopper.storage.NodeAccess)4 EncodingManager (com.graphhopper.routing.util.EncodingManager)3 GraphHopperStorage (com.graphhopper.storage.GraphHopperStorage)3 FlagEncoder (com.graphhopper.routing.util.FlagEncoder)2 FastestWeighting (com.graphhopper.routing.weighting.FastestWeighting)2 Directory (com.graphhopper.storage.Directory)2 GraphExtension (com.graphhopper.storage.GraphExtension)2 LocationIndex (com.graphhopper.storage.index.LocationIndex)2 LocationIndexTree (com.graphhopper.storage.index.LocationIndexTree)2 GHPoint (com.graphhopper.util.shapes.GHPoint)2 GHRequest (com.graphhopper.GHRequest)1 GHResponse (com.graphhopper.GHResponse)1 JsonFeatureConverter (com.graphhopper.json.JsonFeatureConverter)1 ReaderWay (com.graphhopper.reader.ReaderWay)1 AllEdgesIterator (com.graphhopper.routing.util.AllEdgesIterator)1 CarFlagEncoder (com.graphhopper.routing.util.CarFlagEncoder)1