Search in sources :

Example 6 with DefaultEdgeFilter

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

the class PathBidirRefTest method testExtract2.

@Test
public void testExtract2() {
    Graph g = createGraph();
    g.edge(1, 2, 10, false);
    g.edge(2, 3, 20, false);
    EdgeExplorer explorer = g.createEdgeExplorer(carOutEdges);
    EdgeIterator iter = explorer.setBaseNode(1);
    iter.next();
    PathBidirRef pw = new PathBidirRef(g, new FastestWeighting(carEncoder));
    pw.sptEntry = new SPTEntry(iter.getEdge(), 2, 10);
    pw.sptEntry.parent = new SPTEntry(EdgeIterator.NO_EDGE, 1, 0);
    explorer = g.createEdgeExplorer(new DefaultEdgeFilter(carEncoder, true, false));
    iter = explorer.setBaseNode(3);
    iter.next();
    pw.edgeTo = new SPTEntry(iter.getEdge(), 2, 20);
    pw.edgeTo.parent = new SPTEntry(EdgeIterator.NO_EDGE, 3, 0);
    Path p = pw.extract();
    assertEquals(Helper.createTList(1, 2, 3), p.calcNodes());
    assertEquals(30, p.getDistance(), 1e-4);
}
Also used : SPTEntry(com.graphhopper.storage.SPTEntry) EdgeIterator(com.graphhopper.util.EdgeIterator) Graph(com.graphhopper.storage.Graph) EdgeExplorer(com.graphhopper.util.EdgeExplorer) FastestWeighting(com.graphhopper.routing.weighting.FastestWeighting) DefaultEdgeFilter(com.graphhopper.routing.util.DefaultEdgeFilter) Test(org.junit.Test)

Example 7 with DefaultEdgeFilter

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

the class GraphEdgeIdFinderTest method testParseStringHints.

@Test
public void testParseStringHints() {
    FlagEncoder encoder = new CarFlagEncoder();
    EncodingManager em = new EncodingManager(encoder);
    GraphHopperStorage graph = new GraphBuilder(em).create();
    // 0-1-2
    // | |
    // 3-4
    graph.edge(0, 1, 1, true);
    graph.edge(1, 2, 1, true);
    graph.edge(3, 4, 1, true);
    graph.edge(0, 3, 1, true);
    graph.edge(1, 4, 1, true);
    AbstractRoutingAlgorithmTester.updateDistancesFor(graph, 0, 0.01, 0.00);
    AbstractRoutingAlgorithmTester.updateDistancesFor(graph, 1, 0.01, 0.01);
    AbstractRoutingAlgorithmTester.updateDistancesFor(graph, 2, 0.01, 0.02);
    AbstractRoutingAlgorithmTester.updateDistancesFor(graph, 3, 0.00, 0.00);
    AbstractRoutingAlgorithmTester.updateDistancesFor(graph, 4, 0.00, 0.01);
    LocationIndex locationIndex = new LocationIndexTree(graph, new RAMDirectory()).prepareIndex();
    HintsMap hints = new HintsMap();
    hints.put(Parameters.Routing.BLOCK_AREA, "0.01,0.005,1");
    ConfigMap cMap = new ConfigMap();
    GraphEdgeIdFinder graphFinder = new GraphEdgeIdFinder(graph, locationIndex);
    ConfigMap result = graphFinder.parseStringHints(cMap, hints, new DefaultEdgeFilter(encoder));
    GHIntHashSet blockedEdges = new GHIntHashSet();
    blockedEdges.add(0);
    assertEquals(blockedEdges, result.get(BLOCKED_EDGES, new GHIntHashSet()));
    List<Shape> blockedShapes = new ArrayList<>();
    assertEquals(blockedShapes, result.get(BLOCKED_SHAPES, new ArrayList<>()));
    // big area converts into shapes
    hints.put(Parameters.Routing.BLOCK_AREA, "0,0,1000");
    result = graphFinder.parseStringHints(cMap, hints, new DefaultEdgeFilter(encoder));
    blockedEdges.clear();
    assertEquals(blockedEdges, result.get(BLOCKED_EDGES, new GHIntHashSet()));
    blockedShapes.add(new Circle(0, 0, 1000));
    assertEquals(blockedShapes, result.get(BLOCKED_SHAPES, new ArrayList<>()));
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) HintsMap(com.graphhopper.routing.util.HintsMap) Circle(com.graphhopper.util.shapes.Circle) GHIntHashSet(com.graphhopper.coll.GHIntHashSet) Shape(com.graphhopper.util.shapes.Shape) ConfigMap(com.graphhopper.util.ConfigMap) CarFlagEncoder(com.graphhopper.routing.util.CarFlagEncoder) FlagEncoder(com.graphhopper.routing.util.FlagEncoder) ArrayList(java.util.ArrayList) LocationIndex(com.graphhopper.storage.index.LocationIndex) DefaultEdgeFilter(com.graphhopper.routing.util.DefaultEdgeFilter) LocationIndexTree(com.graphhopper.storage.index.LocationIndexTree) CarFlagEncoder(com.graphhopper.routing.util.CarFlagEncoder) Test(org.junit.Test)

Example 8 with DefaultEdgeFilter

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

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

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

DefaultEdgeFilter (com.graphhopper.routing.util.DefaultEdgeFilter)10 Test (org.junit.Test)5 EdgeFilter (com.graphhopper.routing.util.EdgeFilter)4 EncodingManager (com.graphhopper.routing.util.EncodingManager)4 FlagEncoder (com.graphhopper.routing.util.FlagEncoder)3 Graph (com.graphhopper.storage.Graph)3 GraphBuilder (com.graphhopper.storage.GraphBuilder)3 GHIntHashSet (com.graphhopper.coll.GHIntHashSet)2 CarFlagEncoder (com.graphhopper.routing.util.CarFlagEncoder)2 FastestWeighting (com.graphhopper.routing.weighting.FastestWeighting)2 GHPoint (com.graphhopper.util.shapes.GHPoint)2 IntArrayList (com.carrotsearch.hppc.IntArrayList)1 IntCursor (com.carrotsearch.hppc.cursors.IntCursor)1 GHIntArrayList (com.graphhopper.coll.GHIntArrayList)1 HintsMap (com.graphhopper.routing.util.HintsMap)1 MultiPointTour (com.graphhopper.routing.util.tour.MultiPointTour)1 TourStrategy (com.graphhopper.routing.util.tour.TourStrategy)1 CHGraph (com.graphhopper.storage.CHGraph)1 GraphHopperStorage (com.graphhopper.storage.GraphHopperStorage)1 SPTEntry (com.graphhopper.storage.SPTEntry)1