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);
}
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<>()));
}
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());
}
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());
}
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());
}
Aggregations