use of net.osmand.router.RoutingConfiguration.RoutingMemoryLimits in project OsmAnd-tools by osmandapp.
the class ImproveRoadConnectivity method calculateDisconnectedRoadsToAddAndDelete.
private TLongObjectHashMap<RouteDataObject> calculateDisconnectedRoadsToAddAndDelete(TLongObjectHashMap<List<RouteDataObject>> mapOfObjectToCheck, TLongObjectHashMap<List<RouteDataObject>> all, BinaryMapIndexReader reader, TLongHashSet setToRemove, TLongHashSet registeredIds) {
RoutePlannerFrontEnd frontEnd = new RoutePlannerFrontEnd();
RoutingMemoryLimits memoryLimit = new RoutingMemoryLimits(1000, RoutingConfiguration.DEFAULT_NATIVE_MEMORY_LIMIT * 10);
RoutingConfiguration config = RoutingConfiguration.getDefault().build("car", memoryLimit);
long[] pointsToCheck = mapOfObjectToCheck.keys();
TLongObjectHashMap<RouteDataObject> toAdd = new TLongObjectHashMap<RouteDataObject>();
TLongHashSet beginIsolated = new TLongHashSet();
TLongHashSet endIsolated = new TLongHashSet();
for (int k = 0; k < pointsToCheck.length; k++) {
long point = pointsToCheck[k];
if (all.get(point).size() == 1) {
RouteDataObject rdo = all.get(point).get(0);
boolean isBeginPoint = calcPointId(rdo, 0) == point;
RoutingContext ctx = frontEnd.buildRoutingContext(config, null, new BinaryMapIndexReader[] { reader }, RouteCalculationMode.NORMAL);
List<RouteDataObject> result = findConnectedRoads(ctx, rdo, isBeginPoint, all);
if (result == null) {
if (isBeginPoint) {
beginIsolated.add(rdo.getId());
} else {
endIsolated.add(rdo.getId());
}
} else {
for (RouteDataObject obj : result) {
if (!registeredIds.contains(obj.id)) {
toAdd.put(obj.id, obj);
}
}
}
}
}
int begSize = beginIsolated.size();
int endSize = endIsolated.size();
beginIsolated.retainAll(endIsolated);
int intersectionSize = beginIsolated.size();
if (setToRemove != null) {
setToRemove.addAll(beginIsolated);
}
System.out.println("All objects in base file " + mapOfObjectToCheck.size() + " to keep isolated " + (begSize + endSize - 2 * intersectionSize) + " to add " + toAdd.size() + " to remove " + beginIsolated.size());
return toAdd;
}
use of net.osmand.router.RoutingConfiguration.RoutingMemoryLimits in project OsmAnd-tools by osmandapp.
the class ImproveRoadConnectivity method clustering.
public void clustering(final ClusteringContext clusterCtx, BinaryMapIndexReader reader) throws IOException {
RoutePlannerFrontEnd router = new RoutePlannerFrontEnd();
Builder builder = RoutingConfiguration.getDefault();
RoutingMemoryLimits memoryLimit = new RoutingMemoryLimits(RoutingConfiguration.DEFAULT_MEMORY_LIMIT * 3, RoutingConfiguration.DEFAULT_NATIVE_MEMORY_LIMIT);
RoutingConfiguration config = builder.build("car", memoryLimit);
RoutingContext ctx = router.buildRoutingContext(config, null, new BinaryMapIndexReader[] { reader }, RouteCalculationMode.BASE);
if (reader.getRoutingIndexes().size() != 1) {
throw new UnsupportedOperationException();
}
RouteRegion reg = reader.getRoutingIndexes().get(0);
List<RouteSubregion> baseSubregions = reg.getBaseSubregions();
List<RoutingSubregionTile> tiles = new ArrayList<RoutingContext.RoutingSubregionTile>();
for (RouteSubregion s : baseSubregions) {
List<RoutingSubregionTile> loadTiles = ctx.loadAllSubregionTiles(reader, s);
tiles.addAll(loadTiles);
}
List<Cluster> allClusters = new ArrayList<ImproveRoadConnectivity.Cluster>();
for (RoutingSubregionTile tile : tiles) {
List<Cluster> clusters = processDataObjects(ctx, tile);
allClusters.addAll(clusters);
}
combineClusters(allClusters, tiles);
}
use of net.osmand.router.RoutingConfiguration.RoutingMemoryLimits in project OsmAnd-tools by osmandapp.
the class OsmAndMapsService method prepareRouterContext.
private RoutingContext prepareRouterContext(String routeMode, QuadRect points, RoutePlannerFrontEnd router, RoutingServerConfigEntry[] serverEntry) throws IOException {
String[] props = routeMode.split("\\,");
Map<String, String> paramsR = new LinkedHashMap<String, String>();
boolean useNativeLib = DEFAULT_USE_ROUTING_NATIVE_LIB;
router.setUseNativeApproximation(false);
RouteCalculationMode paramMode = null;
for (String p : props) {
if (p.length() == 0) {
continue;
}
int ind = p.indexOf('=');
String key = p;
String value = "true";
if (ind != -1) {
key = p.substring(0, ind);
value = p.substring(ind + 1);
}
if (key.equals("nativerouting")) {
useNativeLib = Boolean.parseBoolean(value);
} else if (key.equals("nativeapproximation")) {
router.setUseNativeApproximation(Boolean.parseBoolean(value));
} else if (key.equals("calcmode")) {
if (value.length() > 0) {
paramMode = RouteCalculationMode.valueOf(value.toUpperCase());
}
} else {
paramsR.put(key, value);
}
}
RoutingMemoryLimits memoryLimit = new RoutingMemoryLimits(MEM_LIMIT, MEM_LIMIT);
String routeModeKey = props[0];
if (routingConfig.config.containsKey(routeModeKey)) {
RoutingServerConfigEntry entry = routingConfig.config.get(routeModeKey);
routeModeKey = entry.profile;
if (serverEntry != null && serverEntry.length > 0) {
serverEntry[0] = entry;
}
}
RoutingConfiguration config = RoutingConfiguration.getDefault().build(routeModeKey, /* RoutingConfiguration.DEFAULT_MEMORY_LIMIT */
memoryLimit, paramsR);
config.routeCalculationTime = System.currentTimeMillis();
if (paramMode == null) {
paramMode = GeneralRouterProfile.CAR == config.router.getProfile() ? RouteCalculationMode.COMPLEX : RouteCalculationMode.NORMAL;
}
final RoutingContext ctx = router.buildRoutingContext(config, useNativeLib ? nativelib : null, getObfReaders(points), // RouteCalculationMode.BASE
paramMode);
ctx.leftSideNavigation = false;
return ctx;
}
use of net.osmand.router.RoutingConfiguration.RoutingMemoryLimits in project OsmAnd-tools by osmandapp.
the class MapAddressLayer method whereAmI.
private List<Entity> whereAmI(double lat, double lon, final DataTileManager<Entity> points) throws IOException {
List<Entity> results = new ArrayList<Entity>();
int x = MapUtils.get31TileNumberX(lon);
int y = MapUtils.get31TileNumberY(lat);
List<BinaryMapIndexReader> list = new ArrayList<BinaryMapIndexReader>();
for (File f : new File(DataExtractionSettings.getSettings().getBinaryFilesDir()).listFiles()) {
if (f.getName().endsWith(".obf")) {
// $NON-NLS-1$ //$NON-NLS-2$
RandomAccessFile raf = new RandomAccessFile(f, "r");
BinaryMapIndexReader rd = new BinaryMapIndexReader(raf, f);
if (rd.containsAddressData() && rd.containsRouteData(x, y, x, y, 15)) {
list.add(rd);
} else {
rd.close();
raf.close();
}
}
}
RoutingMemoryLimits memoryLimit = new RoutingMemoryLimits(DEFAULT_MEMORY_LIMIT * 3, DEFAULT_NATIVE_MEMORY_LIMIT);
RoutingConfiguration cfg = DataExtractionSettings.getSettings().getRoutingConfig().build("geocoding", memoryLimit, new HashMap<String, String>());
RoutingContext ctx = new RoutePlannerFrontEnd().buildRoutingContext(cfg, null, list.toArray(new BinaryMapIndexReader[list.size()]));
GeocodingUtilities su = new GeocodingUtilities();
double minBuildingDistance = 0;
List<GeocodingResult> complete = new ArrayList<GeocodingUtilities.GeocodingResult>();
List<GeocodingResult> res = su.reverseGeocodingSearch(ctx, lat, lon, false);
minBuildingDistance = justifyResults(list, su, complete, res);
// complete.addAll(res);
// Collections.sort(complete, GeocodingUtilities.DISTANCE_COMPARATOR);
long lid = -1;
for (GeocodingResult r : complete) {
if (r.building != null && r.getDistance() > minBuildingDistance * GeocodingUtilities.THRESHOLD_MULTIPLIER_SKIP_BUILDINGS_AFTER) {
continue;
}
Node n = new Node(r.getLocation().getLatitude(), r.getLocation().getLongitude(), lid--);
n.putTag(OSMTagKey.NAME.getValue(), r.toString());
results.add(n);
}
for (BinaryMapIndexReader l : list) {
l.close();
}
return results;
}
use of net.osmand.router.RoutingConfiguration.RoutingMemoryLimits in project OsmAnd-tools by osmandapp.
the class ManyToOneRoadCalculation method manyToManyCalculation.
private void manyToManyCalculation(BinaryMapIndexReader reader, double top, double bottom) throws IOException {
RoutePlannerFrontEnd frontEnd = new RoutePlannerFrontEnd();
RoutingMemoryLimits memoryLimit = new RoutingMemoryLimits(1000, RoutingConfiguration.DEFAULT_NATIVE_MEMORY_LIMIT * 10);
RoutingConfiguration config = RoutingConfiguration.getDefault().build("car", memoryLimit);
RouteCalculationMode mode = RouteCalculationMode.BASE;
RoutingContext ctx = frontEnd.buildRoutingContext(config, null, new BinaryMapIndexReader[] { reader }, mode);
RouteRegion reg = reader.getRoutingIndexes().get(0);
List<RouteSubregion> baseSubregions = reg.getBaseSubregions();
List<RoutingSubregionTile> tiles = new ArrayList<RoutingContext.RoutingSubregionTile>();
for (RouteSubregion s : baseSubregions) {
List<RoutingSubregionTile> loadTiles = ctx.loadAllSubregionTiles(reader, s);
tiles.addAll(loadTiles);
}
int st = MapUtils.get31TileNumberY(top);
int sb = MapUtils.get31TileNumberY(bottom);
List<ManyToManySegment> topIntersects = new ArrayList<ManyToManySegment>();
List<ManyToManySegment> bottomIntersects = new ArrayList<ManyToManySegment>();
TLongObjectHashMap<ManyToManySegment> allSegments = initSegments(st, sb, ctx, tiles, topIntersects, bottomIntersects);
filterDisconnected(ctx, allSegments, topIntersects);
filterDisconnected(ctx, allSegments, topIntersects);
System.out.println("TOP " + topIntersects.size());
System.out.println("BOTTOM " + bottomIntersects.size());
calculateManyToMany(ctx, allSegments, topIntersects, bottomIntersects, st, sb);
}
Aggregations