use of com.graphhopper.routing.util.FlagEncoder in project graphhopper by graphhopper.
the class RoutingAlgorithmIT method createAlgos.
public static List<AlgoHelperEntry> createAlgos(final GraphHopper hopper, final HintsMap hints, TraversalMode tMode) {
GraphHopperStorage ghStorage = hopper.getGraphHopperStorage();
LocationIndex idx = hopper.getLocationIndex();
String addStr = "";
if (tMode.isEdgeBased())
addStr = "turn|";
FlagEncoder encoder = hopper.getEncodingManager().getEncoder(hints.getVehicle());
Weighting weighting = hopper.createWeighting(hints, encoder, hopper.getGraphHopperStorage());
HintsMap defaultHints = new HintsMap().put(Parameters.CH.DISABLE, true).put(Parameters.Landmark.DISABLE, true).setVehicle(hints.getVehicle()).setWeighting(hints.getWeighting());
AlgorithmOptions defaultOpts = AlgorithmOptions.start(new AlgorithmOptions("", weighting, tMode)).hints(defaultHints).build();
List<AlgoHelperEntry> prepare = new ArrayList<>();
prepare.add(new AlgoHelperEntry(ghStorage, AlgorithmOptions.start(defaultOpts).algorithm(ASTAR).build(), idx, "astar|beeline|" + addStr + weighting));
// later: include dijkstraOneToMany
prepare.add(new AlgoHelperEntry(ghStorage, AlgorithmOptions.start(defaultOpts).algorithm(DIJKSTRA).build(), idx, "dijkstra|" + addStr + weighting));
AlgorithmOptions astarbiOpts = AlgorithmOptions.start(defaultOpts).algorithm(ASTAR_BI).build();
astarbiOpts.getHints().put(ASTAR_BI + ".approximation", "BeelineSimplification");
AlgorithmOptions dijkstrabiOpts = AlgorithmOptions.start(defaultOpts).algorithm(DIJKSTRA_BI).build();
prepare.add(new AlgoHelperEntry(ghStorage, astarbiOpts, idx, "astarbi|beeline|" + addStr + weighting));
prepare.add(new AlgoHelperEntry(ghStorage, dijkstrabiOpts, idx, "dijkstrabi|" + addStr + weighting));
// add additional preparations if CH and LM preparation are enabled
if (hopper.getLMFactoryDecorator().isEnabled()) {
final HintsMap lmHints = new HintsMap(defaultHints).put(Parameters.Landmark.DISABLE, false);
prepare.add(new AlgoHelperEntry(ghStorage, AlgorithmOptions.start(astarbiOpts).hints(lmHints).build(), idx, "astarbi|landmarks|" + weighting) {
@Override
public RoutingAlgorithmFactory createRoutingFactory() {
return hopper.getAlgorithmFactory(lmHints);
}
});
}
if (hopper.getCHFactoryDecorator().isEnabled()) {
final HintsMap chHints = new HintsMap(defaultHints).put(Parameters.CH.DISABLE, false);
Weighting pickedWeighting = null;
for (Weighting tmpWeighting : hopper.getCHFactoryDecorator().getWeightings()) {
if (tmpWeighting.equals(weighting)) {
pickedWeighting = tmpWeighting;
break;
}
}
if (pickedWeighting == null)
throw new IllegalStateException("Didn't find weighting " + hints.getWeighting() + " in " + hopper.getCHFactoryDecorator().getWeightings());
prepare.add(new AlgoHelperEntry(ghStorage.getGraph(CHGraph.class, pickedWeighting), AlgorithmOptions.start(dijkstrabiOpts).hints(chHints).build(), idx, "dijkstrabi|ch|prepare|" + hints.getWeighting()) {
@Override
public RoutingAlgorithmFactory createRoutingFactory() {
return hopper.getAlgorithmFactory(chHints);
}
});
prepare.add(new AlgoHelperEntry(ghStorage.getGraph(CHGraph.class, pickedWeighting), AlgorithmOptions.start(astarbiOpts).hints(chHints).build(), idx, "astarbi|ch|prepare|" + hints.getWeighting()) {
@Override
public RoutingAlgorithmFactory createRoutingFactory() {
return hopper.getAlgorithmFactory(chHints);
}
});
}
return prepare;
}
use of com.graphhopper.routing.util.FlagEncoder in project graphhopper by graphhopper.
the class ChangeGraphHelperTest method testApplyChanges.
@Test
public void testApplyChanges() {
// 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();
FlagEncoder encoder = encodingManager.getEncoder("car");
double defaultSpeed = encoder.getSpeed(GHUtility.getEdge(graph, 0, 1).getFlags());
AllEdgesIterator iter = graph.getAllEdges();
while (iter.next()) {
long flags = GHUtility.getEdge(graph, 0, 1).getFlags();
assertEquals(defaultSpeed, encoder.getSpeed(flags), .1);
assertTrue(encoder.isForward(flags));
}
Reader reader = new InputStreamReader(getClass().getResourceAsStream("overlaydata1.json"), Helper.UTF_CS);
ChangeGraphHelper instance = new ChangeGraphHelper(graph, locationIndex);
JsonFeatureConverter converter = new JsonFeatureConverter(ghson, instance, encodingManager);
long updates = converter.applyChanges(reader);
assertEquals(2, updates);
// assert changed speed and access
double newSpeed = encoder.getSpeed(GHUtility.getEdge(graph, 0, 1).getFlags());
assertEquals(10, newSpeed, .1);
assertTrue(newSpeed < defaultSpeed);
assertFalse(encoder.isForward(GHUtility.getEdge(graph, 3, 4).getFlags()));
}
use of com.graphhopper.routing.util.FlagEncoder in project graphhopper by graphhopper.
the class PrepareRoutingSubnetworks method removeEdges.
/**
* This method removes the access to edges available from the nodes contained in the components.
* But only if a components' size is smaller then the specified min value.
* <p>
*
* @return number of removed edges
*/
int removeEdges(final PrepEdgeFilter bothFilter, List<IntArrayList> components, int min) {
// remove edges determined from nodes but only if less than minimum size
FlagEncoder encoder = bothFilter.getEncoder();
EdgeExplorer explorer = ghStorage.createEdgeExplorer(bothFilter);
int removedEdges = 0;
for (IntArrayList component : components) {
removedEdges += removeEdges(explorer, encoder, component, min);
}
return removedEdges;
}
use of com.graphhopper.routing.util.FlagEncoder in project graphhopper by graphhopper.
the class PrepareRoutingSubnetworks method findSubnetworks.
/**
* This method finds the double linked components according to the specified filter.
*/
List<IntArrayList> findSubnetworks(PrepEdgeFilter filter) {
final FlagEncoder encoder = filter.getEncoder();
final EdgeExplorer explorer = ghStorage.createEdgeExplorer(filter);
int locs = ghStorage.getNodes();
List<IntArrayList> list = new ArrayList<IntArrayList>(100);
final GHBitSet bs = new GHBitSetImpl(locs);
for (int start = 0; start < locs; start++) {
if (bs.contains(start))
continue;
final IntArrayList intList = new IntArrayList(20);
list.add(intList);
new BreadthFirstSearch() {
int tmpCounter = 0;
@Override
protected GHBitSet createBitSet() {
return bs;
}
@Override
protected final boolean goFurther(int nodeId) {
if (tmpCounter > maxEdgesPerNode.get())
maxEdgesPerNode.set(tmpCounter);
tmpCounter = 0;
intList.add(nodeId);
return true;
}
@Override
protected final boolean checkAdjacent(EdgeIteratorState edge) {
if (encoder.isForward(edge.getFlags()) || encoder.isBackward(edge.getFlags())) {
tmpCounter++;
return true;
}
return false;
}
}.start(explorer, start);
intList.trimToSize();
}
return list;
}
use of com.graphhopper.routing.util.FlagEncoder in project graphhopper by graphhopper.
the class PrepareRoutingSubnetworks method keepLargeNetworks.
/**
* Deletes all but the largest subnetworks.
*/
int keepLargeNetworks(PrepEdgeFilter filter, List<IntArrayList> components) {
if (components.size() <= 1)
return 0;
int maxCount = -1;
IntIndexedContainer oldComponent = null;
int allRemoved = 0;
FlagEncoder encoder = filter.getEncoder();
EdgeExplorer explorer = ghStorage.createEdgeExplorer(filter);
for (IntArrayList component : components) {
if (maxCount < 0) {
maxCount = component.size();
oldComponent = component;
continue;
}
int removedEdges;
if (maxCount < component.size()) {
// new biggest area found. remove old
removedEdges = removeEdges(explorer, encoder, oldComponent, minNetworkSize);
maxCount = component.size();
oldComponent = component;
} else {
removedEdges = removeEdges(explorer, encoder, component, minNetworkSize);
}
allRemoved += removedEdges;
}
if (allRemoved > ghStorage.getAllEdges().getMaxId() / 2)
throw new IllegalStateException("Too many total edges were removed: " + allRemoved + ", all edges:" + ghStorage.getAllEdges().getMaxId());
return allRemoved;
}
Aggregations