use of com.graphhopper.routing.util.CarFlagEncoder in project graphhopper by graphhopper.
the class InstructionListTest method setUp.
@Before
public void setUp() {
carEncoder = new CarFlagEncoder();
carManager = new EncodingManager(carEncoder);
}
use of com.graphhopper.routing.util.CarFlagEncoder in project graphhopper by graphhopper.
the class OSMTurnRelationTest method testGetRestrictionAsEntries.
@Test
public void testGetRestrictionAsEntries() {
CarFlagEncoder encoder = new CarFlagEncoder(5, 5, 1);
final Map<Long, Integer> osmNodeToInternal = new HashMap<Long, Integer>();
final Map<Integer, Long> internalToOSMEdge = new HashMap<Integer, Long>();
osmNodeToInternal.put(3L, 3);
// edge ids are only stored if they occured before in an OSMRelation
internalToOSMEdge.put(3, 3L);
internalToOSMEdge.put(4, 4L);
GraphHopperStorage ghStorage = new GraphBuilder(new EncodingManager(encoder)).create();
EdgeBasedRoutingAlgorithmTest.initGraph(ghStorage);
OSMReader osmReader = new OSMReader(ghStorage) {
@Override
public int getInternalNodeIdOfOsmNode(long nodeOsmId) {
return osmNodeToInternal.get(nodeOsmId);
}
@Override
public long getOsmIdOfInternalEdge(int edgeId) {
Long l = internalToOSMEdge.get(edgeId);
if (l == null)
return -1;
return l;
}
};
EdgeExplorer edgeExplorer = ghStorage.createEdgeExplorer();
// TYPE == ONLY
OSMTurnRelation instance = new OSMTurnRelation(4, 3, 3, Type.ONLY);
Collection<OSMTurnRelation.TurnCostTableEntry> result = instance.getRestrictionAsEntries(encoder, edgeExplorer, edgeExplorer, osmReader);
assertEquals(2, result.size());
Iterator<OSMTurnRelation.TurnCostTableEntry> iter = result.iterator();
OSMTurnRelation.TurnCostTableEntry entry = iter.next();
assertEquals(4, entry.edgeFrom);
assertEquals(6, entry.edgeTo);
assertEquals(3, entry.nodeVia);
entry = iter.next();
assertEquals(4, entry.edgeFrom);
assertEquals(2, entry.edgeTo);
assertEquals(3, entry.nodeVia);
// TYPE == NOT
instance = new OSMTurnRelation(4, 3, 3, Type.NOT);
result = instance.getRestrictionAsEntries(encoder, edgeExplorer, edgeExplorer, osmReader);
assertEquals(1, result.size());
iter = result.iterator();
entry = iter.next();
assertEquals(4, entry.edgeFrom);
assertEquals(3, entry.edgeTo);
assertEquals(3, entry.nodeVia);
}
use of com.graphhopper.routing.util.CarFlagEncoder in project graphhopper by graphhopper.
the class PrepareContractionHierarchiesTest method testMultiplePreparationsIdenticalView.
@Test
public void testMultiplePreparationsIdenticalView() {
CarFlagEncoder tmpCarEncoder = new CarFlagEncoder();
BikeFlagEncoder tmpBikeEncoder = new BikeFlagEncoder();
EncodingManager tmpEncodingManager = new EncodingManager(tmpCarEncoder, tmpBikeEncoder);
// FastestWeighting would lead to different shortcuts due to different default speeds for bike and car
Weighting carWeighting = new ShortestWeighting(tmpCarEncoder);
Weighting bikeWeighting = new ShortestWeighting(tmpBikeEncoder);
List<Weighting> chWeightings = Arrays.asList(carWeighting, bikeWeighting);
GraphHopperStorage ghStorage = new GraphHopperStorage(chWeightings, dir, tmpEncodingManager, false, new GraphExtension.NoOpExtension()).create(1000);
initShortcutsGraph(ghStorage);
ghStorage.freeze();
for (Weighting w : chWeightings) {
checkPath(ghStorage, w, 7, 5, Helper.createTList(3, 9, 14, 16, 13, 12));
}
}
use of com.graphhopper.routing.util.CarFlagEncoder 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.CarFlagEncoder 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());
}
Aggregations