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