Search in sources :

Example 21 with EncodingManager

use of com.graphhopper.routing.util.EncodingManager in project graphhopper by graphhopper.

the class BreadthFirstSearchTest method testBFS.

@Test
public void testBFS() {
    BreadthFirstSearch bfs = new BreadthFirstSearch() {

        @Override
        public boolean goFurther(int v) {
            counter++;
            assertTrue("v " + v + " is already contained in set. iteration:" + counter, !set.contains(v));
            set.add(v);
            list.add(v);
            return super.goFurther(v);
        }
    };
    Graph g = new GraphBuilder(new EncodingManager("car")).create();
    g.edge(0, 1, 85, true);
    g.edge(0, 2, 217, true);
    g.edge(0, 3, 173, true);
    g.edge(0, 5, 173, true);
    g.edge(1, 6, 75, true);
    g.edge(2, 7, 51, true);
    g.edge(3, 8, 23, true);
    g.edge(4, 8, 793, true);
    g.edge(8, 10, 343, true);
    g.edge(6, 9, 72, true);
    g.edge(9, 10, 8, true);
    g.edge(5, 10, 1, true);
    bfs.start(g.createEdgeExplorer(), 0);
    assertTrue(counter > 0);
    assertEquals(g.getNodes(), counter);
    assertEquals("[0, 5, 3, 2, 1, 10, 8, 7, 6, 9, 4]", list.toString());
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) Graph(com.graphhopper.storage.Graph) GraphBuilder(com.graphhopper.storage.GraphBuilder) Test(org.junit.Test)

Example 22 with EncodingManager

use of com.graphhopper.routing.util.EncodingManager in project graphhopper by graphhopper.

the class BreadthFirstSearchTest method testBFS2.

@Test
public void testBFS2() {
    BreadthFirstSearch bfs = new BreadthFirstSearch() {

        @Override
        public boolean goFurther(int v) {
            counter++;
            assertTrue("v " + v + " is already contained in set. iteration:" + counter, !set.contains(v));
            set.add(v);
            list.add(v);
            return super.goFurther(v);
        }
    };
    Graph g = new GraphBuilder(new EncodingManager("car")).create();
    g.edge(1, 2, 1, false);
    g.edge(2, 3, 1, false);
    g.edge(3, 4, 1, false);
    g.edge(1, 5, 1, false);
    g.edge(5, 6, 1, false);
    g.edge(6, 4, 1, false);
    bfs.start(g.createEdgeExplorer(), 1);
    assertTrue(counter > 0);
    assertEquals("[1, 5, 2, 6, 3, 4]", list.toString());
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) Graph(com.graphhopper.storage.Graph) GraphBuilder(com.graphhopper.storage.GraphBuilder) Test(org.junit.Test)

Example 23 with EncodingManager

use of com.graphhopper.routing.util.EncodingManager in project graphhopper by graphhopper.

the class CHEdgeIteratorTest method testUpdateFlags.

@Test
public void testUpdateFlags() {
    CarFlagEncoder carFlagEncoder = new CarFlagEncoder();
    EncodingManager encodingManager = new EncodingManager(carFlagEncoder);
    FastestWeighting weighting = new FastestWeighting(carFlagEncoder);
    EdgeFilter carOutFilter = new DefaultEdgeFilter(carFlagEncoder, false, true);
    GraphHopperStorage ghStorage = new GraphBuilder(encodingManager).setCHGraph(weighting).create();
    CHGraph g = ghStorage.getGraph(CHGraph.class, weighting);
    g.edge(0, 1).setDistance(12).setFlags(carFlagEncoder.setProperties(10, true, true));
    g.edge(0, 2).setDistance(13).setFlags(carFlagEncoder.setProperties(20, true, true));
    ghStorage.freeze();
    assertEquals(2, GHUtility.count(g.getAllEdges()));
    assertEquals(1, GHUtility.count(g.createEdgeExplorer(carOutFilter).setBaseNode(1)));
    EdgeIteratorState iter = GHUtility.getEdge(g, 0, 1);
    assertEquals(1, iter.getAdjNode());
    assertEquals(carFlagEncoder.setProperties(10, true, true), iter.getFlags());
    // update setProperties
    iter.setFlags(carFlagEncoder.setProperties(20, true, false));
    assertEquals(12, iter.getDistance(), 1e-4);
    // update distance
    iter.setDistance(10);
    assertEquals(10, iter.getDistance(), 1e-4);
    assertEquals(0, GHUtility.count(g.createEdgeExplorer(carOutFilter).setBaseNode(1)));
    iter = GHUtility.getEdge(g, 0, 1);
    assertEquals(carFlagEncoder.setProperties(20, true, false), iter.getFlags());
    assertEquals(10, iter.getDistance(), 1e-4);
    assertEquals(1, GHUtility.getNeighbors(g.createEdgeExplorer().setBaseNode(1)).size());
    assertEquals(0, GHUtility.getNeighbors(g.createEdgeExplorer(carOutFilter).setBaseNode(1)).size());
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) CHGraph(com.graphhopper.storage.CHGraph) EdgeFilter(com.graphhopper.routing.util.EdgeFilter) DefaultEdgeFilter(com.graphhopper.routing.util.DefaultEdgeFilter) FastestWeighting(com.graphhopper.routing.weighting.FastestWeighting) GraphBuilder(com.graphhopper.storage.GraphBuilder) CarFlagEncoder(com.graphhopper.routing.util.CarFlagEncoder) DefaultEdgeFilter(com.graphhopper.routing.util.DefaultEdgeFilter) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) Test(org.junit.Test)

Example 24 with EncodingManager

use of com.graphhopper.routing.util.EncodingManager in project graphhopper by graphhopper.

the class DepthFirstSearchTest method testDFS1.

@Test
public void testDFS1() {
    DepthFirstSearch dfs = new DepthFirstSearch() {

        @Override
        public boolean goFurther(int v) {
            counter++;
            assertTrue("v " + v + " is already contained in set. iteration:" + counter, !set.contains(v));
            set.add(v);
            list.add(v);
            return super.goFurther(v);
        }
    };
    EncodingManager em = new EncodingManager("car");
    FlagEncoder fe = em.getEncoder("car");
    Graph g = new GraphBuilder(em).create();
    g.edge(1, 2, 1, false);
    g.edge(1, 5, 1, false);
    g.edge(1, 4, 1, false);
    g.edge(2, 3, 1, false);
    g.edge(3, 4, 1, false);
    g.edge(5, 6, 1, false);
    g.edge(6, 4, 1, false);
    dfs.start(g.createEdgeExplorer(new DefaultEdgeFilter(fe, false, true)), 1);
    assertTrue(counter > 0);
    assertEquals("[1, 2, 3, 4, 5, 6]", list.toString());
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) Graph(com.graphhopper.storage.Graph) FlagEncoder(com.graphhopper.routing.util.FlagEncoder) GraphBuilder(com.graphhopper.storage.GraphBuilder) DefaultEdgeFilter(com.graphhopper.routing.util.DefaultEdgeFilter) Test(org.junit.Test)

Example 25 with EncodingManager

use of com.graphhopper.routing.util.EncodingManager 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)

Aggregations

EncodingManager (com.graphhopper.routing.util.EncodingManager)33 Test (org.junit.Test)15 GraphHopperOSM (com.graphhopper.reader.osm.GraphHopperOSM)14 GraphBuilder (com.graphhopper.storage.GraphBuilder)10 CarFlagEncoder (com.graphhopper.routing.util.CarFlagEncoder)8 GraphHopperStorage (com.graphhopper.storage.GraphHopperStorage)7 FlagEncoder (com.graphhopper.routing.util.FlagEncoder)6 Graph (com.graphhopper.storage.Graph)5 File (java.io.File)5 DefaultEdgeFilter (com.graphhopper.routing.util.DefaultEdgeFilter)4 FastestWeighting (com.graphhopper.routing.weighting.FastestWeighting)4 SRTMProvider (com.graphhopper.reader.dem.SRTMProvider)3 ShortestWeighting (com.graphhopper.routing.weighting.ShortestWeighting)3 RAMDirectory (com.graphhopper.storage.RAMDirectory)3 Before (org.junit.Before)3 GraphHopper (com.graphhopper.GraphHopper)2 ReaderWay (com.graphhopper.reader.ReaderWay)2 BikeFlagEncoder (com.graphhopper.routing.util.BikeFlagEncoder)2 DataFlagEncoder (com.graphhopper.routing.util.DataFlagEncoder)2 HintsMap (com.graphhopper.routing.util.HintsMap)2