Search in sources :

Example 21 with RAMDirectory

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

the class LocationIndexTreeTest method testSearchWithFilter_issue318.

@Test
public void testSearchWithFilter_issue318() {
    CarFlagEncoder carEncoder = new CarFlagEncoder();
    BikeFlagEncoder bikeEncoder = new BikeFlagEncoder();
    EncodingManager tmpEM = new EncodingManager(carEncoder, bikeEncoder);
    Graph graph = createGHStorage(new RAMDirectory(), tmpEM, false);
    NodeAccess na = graph.getNodeAccess();
    // distance from point to point is roughly 1 km
    int MAX = 5;
    for (int latIdx = 0; latIdx < MAX; latIdx++) {
        for (int lonIdx = 0; lonIdx < MAX; lonIdx++) {
            int index = lonIdx * 10 + latIdx;
            na.setNode(index, 0.01 * latIdx, 0.01 * lonIdx);
            if (latIdx < MAX - 1)
                graph.edge(index, index + 1, 1000, true);
            if (lonIdx < MAX - 1)
                graph.edge(index, index + 10, 1000, true);
        }
    }
    // reduce access for bike to two edges only
    AllEdgesIterator iter = graph.getAllEdges();
    while (iter.next()) {
        iter.setFlags(bikeEncoder.setAccess(iter.getFlags(), false, false));
    }
    for (EdgeIteratorState edge : Arrays.asList(GHUtility.getEdge(graph, 0, 1), GHUtility.getEdge(graph, 1, 2))) {
        edge.setFlags(bikeEncoder.setAccess(edge.getFlags(), true, true));
    }
    LocationIndexTree index = createIndexNoPrepare(graph, 500);
    index.prepareIndex();
    index.setMaxRegionSearch(8);
    EdgeFilter carFilter = new DefaultEdgeFilter(carEncoder, true, true);
    QueryResult qr = index.findClosest(0.03, 0.03, carFilter);
    assertTrue(qr.isValid());
    assertEquals(33, qr.getClosestNode());
    EdgeFilter bikeFilter = new DefaultEdgeFilter(bikeEncoder, true, true);
    qr = index.findClosest(0.03, 0.03, bikeFilter);
    assertTrue(qr.isValid());
    assertEquals(2, qr.getClosestNode());
}
Also used : NodeAccess(com.graphhopper.storage.NodeAccess) RAMDirectory(com.graphhopper.storage.RAMDirectory) GHPoint(com.graphhopper.util.shapes.GHPoint) Graph(com.graphhopper.storage.Graph) Test(org.junit.Test)

Example 22 with RAMDirectory

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

the class Location2IDQuadtreeTest method testNormedDist.

@Test
public void testNormedDist() {
    Location2IDQuadtree index = new Location2IDQuadtree(createGHStorage(new EncodingManager("car")), new RAMDirectory());
    index.initAlgo(5, 6);
    assertEquals(1, index.getNormedDist(0, 1), 1e-6);
    assertEquals(2, index.getNormedDist(0, 7), 1e-6);
    assertEquals(2, index.getNormedDist(7, 2), 1e-6);
    assertEquals(1, index.getNormedDist(7, 1), 1e-6);
    assertEquals(4, index.getNormedDist(13, 25), 1e-6);
    assertEquals(8, index.getNormedDist(15, 25), 1e-6);
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) RAMDirectory(com.graphhopper.storage.RAMDirectory) Test(org.junit.Test)

Example 23 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)

Example 24 with RAMDirectory

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

the class OSMIDMapTest method testUpdateOfLowerKeys.

@Test
public void testUpdateOfLowerKeys() {
    OSMIDMap map = new OSMIDMap(new RAMDirectory());
    map.put(9, 0);
    map.put(10, 1);
    map.put(11, 2);
    map.put(9, 3);
    assertEquals(2, map.get(11));
    assertEquals(3, map.get(9));
}
Also used : RAMDirectory(com.graphhopper.storage.RAMDirectory) Test(org.junit.Test)

Example 25 with RAMDirectory

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

the class OSMIDMapTest method testGet2.

@Test
public void testGet2() {
    OSMIDMap map = new OSMIDMap(new RAMDirectory());
    map.put(9, 0);
    map.put(10, 1);
    map.put(11, 2);
    map.put(12, 3);
    map.put(13, 4);
    map.put(14, 5);
    map.put(16, 6);
    map.put(18, 7);
    map.put(19, 8);
    assertEquals(9, map.getSize());
    assertEquals(-1, map.get(8));
    assertEquals(0, map.get(9));
    assertEquals(1, map.get(10));
    assertEquals(2, map.get(11));
    assertEquals(3, map.get(12));
    assertEquals(4, map.get(13));
    assertEquals(5, map.get(14));
    assertEquals(6, map.get(16));
    assertEquals(-1, map.get(17));
    assertEquals(7, map.get(18));
    assertEquals(8, map.get(19));
}
Also used : 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