Search in sources :

Example 36 with FlagEncoder

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

the class BreadthFirstSearchTest method testBFS2.

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

        @Override
        protected GHBitSet createBitSet() {
            return new GHTBitSet();
        }

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

Example 37 with FlagEncoder

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

the class TurnCostStorageTest method setup.

@BeforeEach
public void setup() {
    FlagEncoder carEncoder = new CarFlagEncoder(5, 5, 3);
    FlagEncoder bikeEncoder = new BikeFlagEncoder(5, 5, 3, false);
    manager = EncodingManager.create(carEncoder, bikeEncoder);
}
Also used : CarFlagEncoder(com.graphhopper.routing.util.CarFlagEncoder) BikeFlagEncoder(com.graphhopper.routing.util.BikeFlagEncoder) FlagEncoder(com.graphhopper.routing.util.FlagEncoder) BikeFlagEncoder(com.graphhopper.routing.util.BikeFlagEncoder) CarFlagEncoder(com.graphhopper.routing.util.CarFlagEncoder) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 38 with FlagEncoder

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

the class HeadingResolverTest method withQueryGraph.

@Test
public void withQueryGraph() {
    // 2
    // 0 -x- 1
    FlagEncoder encoder = new CarFlagEncoder();
    EncodingManager em = EncodingManager.create(encoder);
    GraphHopperStorage graph = new GraphBuilder(em).create();
    NodeAccess na = graph.getNodeAccess();
    na.setNode(0, 48.8611, 1.2194);
    na.setNode(1, 48.8538, 2.3950);
    EdgeIteratorState edge = GHUtility.setSpeed(60, true, true, encoder, graph.edge(0, 1).setDistance(10));
    Snap snap = createSnap(edge, 48.859, 2.00, 0);
    QueryGraph queryGraph = QueryGraph.create(graph, snap);
    HeadingResolver resolver = new HeadingResolver(queryGraph);
    // if the heading points East we get the Western edge 0->2
    assertEquals("0->2", queryGraph.getEdgeIteratorState(1, Integer.MIN_VALUE).toString());
    assertEquals(IntArrayList.from(1), resolver.getEdgesWithDifferentHeading(2, 90));
    // if the heading points West we get the Eastern edge 2->1
    assertEquals("2->1", queryGraph.getEdgeIteratorState(2, Integer.MIN_VALUE).toString());
    assertEquals(IntArrayList.from(2), resolver.getEdgesWithDifferentHeading(2, 270));
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) NodeAccess(com.graphhopper.storage.NodeAccess) CarFlagEncoder(com.graphhopper.routing.util.CarFlagEncoder) FlagEncoder(com.graphhopper.routing.util.FlagEncoder) EdgeIteratorState(com.graphhopper.util.EdgeIteratorState) GraphBuilder(com.graphhopper.storage.GraphBuilder) Snap(com.graphhopper.storage.index.Snap) CarFlagEncoder(com.graphhopper.routing.util.CarFlagEncoder) QueryGraph(com.graphhopper.routing.querygraph.QueryGraph) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) Test(org.junit.jupiter.api.Test)

Example 39 with FlagEncoder

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

the class HeadingResolverTest method curvyEdge.

@Test
public void curvyEdge() {
    // 1 -|
    // |- 0 -|
    // |- 2
    FlagEncoder encoder = new CarFlagEncoder();
    EncodingManager em = EncodingManager.create(encoder);
    GraphHopperStorage graph = new GraphBuilder(em).create();
    NodeAccess na = graph.getNodeAccess();
    na.setNode(1, 0.01, 0.00);
    na.setNode(0, 0.00, 0.00);
    na.setNode(2, -0.01, 0.00);
    GHUtility.setSpeed(60, true, true, encoder, graph.edge(0, 1).setDistance(10)).setWayGeometry(Helper.createPointList(0.00, 0.01, 0.01, 0.01));
    GHUtility.setSpeed(60, true, true, encoder, graph.edge(0, 2).setDistance(10)).setWayGeometry(Helper.createPointList(0.00, -0.01, -0.01, -0.01));
    HeadingResolver resolver = new HeadingResolver(graph);
    resolver.setTolerance(120);
    // asking for the edges not going east returns 0-2
    assertEquals(IntArrayList.from(1), resolver.getEdgesWithDifferentHeading(0, 90));
    // asking for the edges not going west returns 0-1
    assertEquals(IntArrayList.from(0), resolver.getEdgesWithDifferentHeading(0, 270));
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) NodeAccess(com.graphhopper.storage.NodeAccess) CarFlagEncoder(com.graphhopper.routing.util.CarFlagEncoder) FlagEncoder(com.graphhopper.routing.util.FlagEncoder) GraphBuilder(com.graphhopper.storage.GraphBuilder) CarFlagEncoder(com.graphhopper.routing.util.CarFlagEncoder) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) Test(org.junit.jupiter.api.Test)

Example 40 with FlagEncoder

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

the class AlternativeRouteEdgeCHTest method createTestGraph.

public GraphHopperStorage createTestGraph(EncodingManager tmpEM) {
    final GraphHopperStorage graph = new GraphBuilder(tmpEM).withTurnCosts(true).create();
    /*

           9      11
          /\     /  \
         1  2-3-4-10-12
         \   /   \
         5--6-7---8

         */
    // Make all edges the length of T, the distance around v than an s->v->t path
    // has to be locally-shortest to be considered.
    // So we get all three alternatives.
    FlagEncoder encoder = carFE;
    GHUtility.setSpeed(60, true, true, encoder, graph.edge(5, 6).setDistance(10000));
    EdgeIteratorState e6_3 = GHUtility.setSpeed(60, true, true, encoder, graph.edge(6, 3).setDistance(10000));
    EdgeIteratorState e3_4 = GHUtility.setSpeed(60, true, true, encoder, graph.edge(3, 4).setDistance(10000));
    GHUtility.setSpeed(60, true, true, encoder, graph.edge(4, 10).setDistance(10000));
    GHUtility.setSpeed(60, true, true, encoder, graph.edge(6, 7).setDistance(10000));
    GHUtility.setSpeed(60, true, true, encoder, graph.edge(7, 8).setDistance(10000));
    GHUtility.setSpeed(60, true, true, encoder, graph.edge(8, 4).setDistance(10000));
    GHUtility.setSpeed(60, true, true, encoder, graph.edge(5, 1).setDistance(10000));
    GHUtility.setSpeed(60, true, true, encoder, graph.edge(1, 9).setDistance(10000));
    GHUtility.setSpeed(60, true, true, encoder, graph.edge(9, 2).setDistance(10000));
    GHUtility.setSpeed(60, true, true, encoder, graph.edge(2, 3).setDistance(10000));
    EdgeIteratorState e4_11 = GHUtility.setSpeed(60, true, true, encoder, graph.edge(4, 11).setDistance(9000));
    GHUtility.setSpeed(60, true, true, encoder, graph.edge(11, 12).setDistance(9000));
    GHUtility.setSpeed(60, true, true, encoder, graph.edge(12, 10).setDistance(10000));
    TurnCostStorage turnCostStorage = graph.getTurnCostStorage();
    DecimalEncodedValue carTurnCost = em.getDecimalEncodedValue(TurnCost.key(carFE.toString()));
    turnCostStorage.set(carTurnCost, e3_4.getEdge(), 4, e4_11.getEdge(), Double.POSITIVE_INFINITY);
    turnCostStorage.set(carTurnCost, e6_3.getEdge(), 3, e3_4.getEdge(), Double.POSITIVE_INFINITY);
    graph.freeze();
    return graph;
}
Also used : CarFlagEncoder(com.graphhopper.routing.util.CarFlagEncoder) FlagEncoder(com.graphhopper.routing.util.FlagEncoder) EdgeIteratorState(com.graphhopper.util.EdgeIteratorState) DecimalEncodedValue(com.graphhopper.routing.ev.DecimalEncodedValue)

Aggregations

FlagEncoder (com.graphhopper.routing.util.FlagEncoder)46 Test (org.junit.jupiter.api.Test)23 EncodingManager (com.graphhopper.routing.util.EncodingManager)19 CarFlagEncoder (com.graphhopper.routing.util.CarFlagEncoder)14 GraphBuilder (com.graphhopper.storage.GraphBuilder)14 EdgeIteratorState (com.graphhopper.util.EdgeIteratorState)13 GraphHopperStorage (com.graphhopper.storage.GraphHopperStorage)12 NodeAccess (com.graphhopper.storage.NodeAccess)10 Graph (com.graphhopper.storage.Graph)7 GHIntHashSet (com.graphhopper.coll.GHIntHashSet)6 Test (org.junit.Test)6 BikeFlagEncoder (com.graphhopper.routing.util.BikeFlagEncoder)5 FastestWeighting (com.graphhopper.routing.weighting.FastestWeighting)5 DecimalEncodedValue (com.graphhopper.routing.ev.DecimalEncodedValue)4 IntArrayList (com.carrotsearch.hppc.IntArrayList)3 GHBitSetImpl (com.graphhopper.coll.GHBitSetImpl)3 GHIntArrayList (com.graphhopper.coll.GHIntArrayList)3 LMProfile (com.graphhopper.config.LMProfile)3 ReaderWay (com.graphhopper.reader.ReaderWay)3 AllEdgesIterator (com.graphhopper.routing.util.AllEdgesIterator)3