Search in sources :

Example 1 with RoutingMemoryLimits

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;
}
Also used : TLongObjectHashMap(gnu.trove.map.hash.TLongObjectHashMap) RoutingMemoryLimits(net.osmand.router.RoutingConfiguration.RoutingMemoryLimits) RoutingContext(net.osmand.router.RoutingContext) RoutingConfiguration(net.osmand.router.RoutingConfiguration) TLongHashSet(gnu.trove.set.hash.TLongHashSet) RoutePlannerFrontEnd(net.osmand.router.RoutePlannerFrontEnd) RouteDataObject(net.osmand.binary.RouteDataObject)

Example 2 with RoutingMemoryLimits

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);
}
Also used : RouteSubregion(net.osmand.binary.BinaryMapRouteReaderAdapter.RouteSubregion) Builder(net.osmand.router.RoutingConfiguration.Builder) ArrayList(java.util.ArrayList) RoutingMemoryLimits(net.osmand.router.RoutingConfiguration.RoutingMemoryLimits) RoutingContext(net.osmand.router.RoutingContext) RoutingConfiguration(net.osmand.router.RoutingConfiguration) RouteRegion(net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion) RoutePlannerFrontEnd(net.osmand.router.RoutePlannerFrontEnd) RoutingSubregionTile(net.osmand.router.RoutingContext.RoutingSubregionTile)

Example 3 with RoutingMemoryLimits

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;
}
Also used : RoutingMemoryLimits(net.osmand.router.RoutingConfiguration.RoutingMemoryLimits) RoutingContext(net.osmand.router.RoutingContext) RoutingConfiguration(net.osmand.router.RoutingConfiguration) RouteCalculationMode(net.osmand.router.RoutePlannerFrontEnd.RouteCalculationMode) GpxPoint(net.osmand.router.RoutePlannerFrontEnd.GpxPoint) LinkedHashMap(java.util.LinkedHashMap)

Example 4 with RoutingMemoryLimits

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;
}
Also used : Entity(net.osmand.osm.edit.Entity) GeocodingResult(net.osmand.binary.GeocodingUtilities.GeocodingResult) Node(net.osmand.osm.edit.Node) ArrayList(java.util.ArrayList) BinaryMapIndexReader(net.osmand.binary.BinaryMapIndexReader) Point(java.awt.Point) RoutingMemoryLimits(net.osmand.router.RoutingConfiguration.RoutingMemoryLimits) RoutingContext(net.osmand.router.RoutingContext) RandomAccessFile(java.io.RandomAccessFile) RoutingConfiguration(net.osmand.router.RoutingConfiguration) RoutePlannerFrontEnd(net.osmand.router.RoutePlannerFrontEnd) GeocodingUtilities(net.osmand.binary.GeocodingUtilities) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File)

Example 5 with RoutingMemoryLimits

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);
}
Also used : RouteSubregion(net.osmand.binary.BinaryMapRouteReaderAdapter.RouteSubregion) ArrayList(java.util.ArrayList) TLongArrayList(gnu.trove.list.array.TLongArrayList) RoutingMemoryLimits(net.osmand.router.RoutingConfiguration.RoutingMemoryLimits) RoutingContext(net.osmand.router.RoutingContext) RoutingConfiguration(net.osmand.router.RoutingConfiguration) RouteRegion(net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion) RoutePlannerFrontEnd(net.osmand.router.RoutePlannerFrontEnd) RouteCalculationMode(net.osmand.router.RoutePlannerFrontEnd.RouteCalculationMode) RoutingSubregionTile(net.osmand.router.RoutingContext.RoutingSubregionTile)

Aggregations

RoutingConfiguration (net.osmand.router.RoutingConfiguration)8 RoutingMemoryLimits (net.osmand.router.RoutingConfiguration.RoutingMemoryLimits)8 RoutingContext (net.osmand.router.RoutingContext)8 RoutePlannerFrontEnd (net.osmand.router.RoutePlannerFrontEnd)7 ArrayList (java.util.ArrayList)6 RouteRegion (net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion)4 RouteSubregion (net.osmand.binary.BinaryMapRouteReaderAdapter.RouteSubregion)4 RoutingSubregionTile (net.osmand.router.RoutingContext.RoutingSubregionTile)4 RouteCalculationMode (net.osmand.router.RoutePlannerFrontEnd.RouteCalculationMode)3 TLongArrayList (gnu.trove.list.array.TLongArrayList)2 LinkedHashMap (java.util.LinkedHashMap)2 BinaryMapIndexReader (net.osmand.binary.BinaryMapIndexReader)2 RouteDataObject (net.osmand.binary.RouteDataObject)2 Entity (net.osmand.osm.edit.Entity)2 GpxPoint (net.osmand.router.RoutePlannerFrontEnd.GpxPoint)2 Builder (net.osmand.router.RoutingConfiguration.Builder)2 TLongObjectHashMap (gnu.trove.map.hash.TLongObjectHashMap)1 TLongHashSet (gnu.trove.set.hash.TLongHashSet)1 Point (java.awt.Point)1 File (java.io.File)1