Search in sources :

Example 16 with FlagEncoder

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

the class GraphHopperStorageForDataFlagEncoderTest method testStorageProperties.

@Test
public void testStorageProperties() {
    graph = new GraphBuilder(encodingManager).setStore(true).setLocation(defaultGraphLoc).create();
    // 0-1
    ReaderWay way_0_1 = new ReaderWay(27l);
    way_0_1.setTag("highway", "primary");
    way_0_1.setTag("maxheight", "4.4");
    graph.edge(0, 1, 1, true);
    AbstractRoutingAlgorithmTester.updateDistancesFor(graph, 0, 0.00, 0.00);
    AbstractRoutingAlgorithmTester.updateDistancesFor(graph, 1, 0.01, 0.01);
    graph.getEdgeIteratorState(0, 1).setFlags(encoder.handleWayTags(way_0_1, 1, 0));
    // 1-2
    ReaderWay way_1_2 = new ReaderWay(28l);
    way_1_2.setTag("highway", "primary");
    way_1_2.setTag("maxweight", "45");
    graph.edge(1, 2, 1, true);
    AbstractRoutingAlgorithmTester.updateDistancesFor(graph, 2, 0.02, 0.02);
    graph.getEdgeIteratorState(1, 2).setFlags(encoder.handleWayTags(way_1_2, 1, 0));
    // 2-0
    ReaderWay way_2_0 = new ReaderWay(29l);
    way_2_0.setTag("highway", "primary");
    way_2_0.setTag("maxwidth", "5");
    graph.edge(2, 0, 1, true);
    graph.getEdgeIteratorState(2, 0).setFlags(encoder.handleWayTags(way_2_0, 1, 0));
    graph.flush();
    graph.close();
    GraphHopper hopper = new GraphHopper().setGraphHopperLocation(defaultGraphLoc).setCHEnabled(false).importOrLoad();
    EncodingManager em = hopper.getEncodingManager();
    assertNotNull(em);
    assertEquals(1, em.fetchEdgeEncoders().size());
    FlagEncoder flagEncoder = em.fetchEdgeEncoders().get(0);
    assertTrue(flagEncoder instanceof DataFlagEncoder);
    DataFlagEncoder dataFlagEncoder = (DataFlagEncoder) flagEncoder;
    assertTrue(dataFlagEncoder.isStoreHeight());
    assertTrue(dataFlagEncoder.isStoreWeight());
    assertFalse(dataFlagEncoder.isStoreWidth());
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) DataFlagEncoder(com.graphhopper.routing.util.DataFlagEncoder) DataFlagEncoder(com.graphhopper.routing.util.DataFlagEncoder) FlagEncoder(com.graphhopper.routing.util.FlagEncoder) ReaderWay(com.graphhopper.reader.ReaderWay) GraphHopper(com.graphhopper.GraphHopper) Test(org.junit.Test)

Example 17 with FlagEncoder

use of com.graphhopper.routing.util.FlagEncoder 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 18 with FlagEncoder

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

the class DepthFirstSearchTest method testDFS2.

@Test
public void testDFS2() {
    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, 4, 1, true);
    g.edge(1, 3, 1, false);
    g.edge(2, 3, 1, false);
    g.edge(4, 3, 1, true);
    dfs.start(g.createEdgeExplorer(new DefaultEdgeFilter(fe, false, true)), 1);
    assertTrue(counter > 0);
    assertEquals("[1, 2, 3, 4]", 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)

Aggregations

FlagEncoder (com.graphhopper.routing.util.FlagEncoder)18 Test (org.junit.Test)10 EncodingManager (com.graphhopper.routing.util.EncodingManager)8 IntArrayList (com.carrotsearch.hppc.IntArrayList)4 GHIntArrayList (com.graphhopper.coll.GHIntArrayList)4 CarFlagEncoder (com.graphhopper.routing.util.CarFlagEncoder)4 DefaultEdgeFilter (com.graphhopper.routing.util.DefaultEdgeFilter)4 GraphBuilder (com.graphhopper.storage.GraphBuilder)3 GraphHopperStorage (com.graphhopper.storage.GraphHopperStorage)3 LocationIndex (com.graphhopper.storage.index.LocationIndex)3 ArrayList (java.util.ArrayList)3 BikeFlagEncoder (com.graphhopper.routing.util.BikeFlagEncoder)2 DataFlagEncoder (com.graphhopper.routing.util.DataFlagEncoder)2 Graph (com.graphhopper.storage.Graph)2 RAMDirectory (com.graphhopper.storage.RAMDirectory)2 LocationIndexTree (com.graphhopper.storage.index.LocationIndexTree)2 EdgeIteratorState (com.graphhopper.util.EdgeIteratorState)2 InputStreamReader (java.io.InputStreamReader)2 IntIndexedContainer (com.carrotsearch.hppc.IntIndexedContainer)1 GHRequest (com.graphhopper.GHRequest)1