Search in sources :

Example 1 with TLongHashSet

use of gnu.trove.set.hash.TLongHashSet in project OsmAnd-tools by osmandapp.

the class ManyToOneRoadCalculation method filterDisconnected.

private void filterDisconnected(RoutingContext ctx, TLongObjectHashMap<ManyToManySegment> allSegments, List<ManyToManySegment> initialSegments) {
    Iterator<ManyToManySegment> it = initialSegments.iterator();
    while (it.hasNext()) {
        ManyToManySegment init = it.next();
        int iterations = 0;
        int threshold = THRESHOLD_DISCONNECTED;
        LinkedList<ManyToManySegment> mms = new LinkedList<ManyToManySegment>();
        TLongHashSet visited = new TLongHashSet();
        mms.push(init);
        while (iterations < threshold && !mms.isEmpty()) {
            ManyToManySegment o = mms.poll();
            if (!visited.add(o.road.id)) {
                continue;
            }
            int ow = ctx.config.router.isOneWay(o.road);
            int start = ow > 0 ? o.segmentIndex : 0;
            int end = ow < 0 ? o.segmentIndex : o.road.getPointsLength();
            for (int i = start; i < end; i++) {
                long calcLong = calcLong(o.road.getPoint31XTile(i), o.road.getPoint31YTile(i));
                ManyToManySegment ind = allSegments.get(calcLong);
                while (ind != null) {
                    if (!visited.contains(ind.road.id)) {
                        mms.push(ind);
                    }
                    ind = ind.next;
                }
            }
            iterations++;
        }
        if (iterations < threshold) {
            it.remove();
        }
    }
}
Also used : TLongHashSet(gnu.trove.set.hash.TLongHashSet) LinkedList(java.util.LinkedList)

Example 2 with TLongHashSet

use of gnu.trove.set.hash.TLongHashSet in project OsmAnd-tools by osmandapp.

the class ManyToOneRoadCalculation method combineWithLocal.

private void combineWithLocal(List<TLongArrayList> sets, TLongArrayList source) {
    boolean found = false;
    TLongHashSet set = new TLongHashSet(source);
    for (TLongArrayList oneList : sets) {
        int k = 0;
        for (; k < oneList.size(); k++) {
            if (set.contains(oneList.get(k))) {
                break;
            }
        }
        if (k < oneList.size()) {
            oneList.remove(0, k);
            for (k = 0; k < oneList.size(); k++) {
                if (!set.contains(oneList.get(k))) {
                    break;
                }
            }
            if (k < oneList.size()) {
                oneList.remove(k, oneList.size() - k);
            }
            found = true;
        }
        if (found) {
            break;
        }
    }
    if (!found) {
        sets.add(source);
    }
}
Also used : TLongArrayList(gnu.trove.list.array.TLongArrayList) TLongHashSet(gnu.trove.set.hash.TLongHashSet)

Example 3 with TLongHashSet

use of gnu.trove.set.hash.TLongHashSet in project OsmAnd-tools by osmandapp.

the class CheckRoadConnectivity method findConnectedRoads.

private List<RouteDataObject> findConnectedRoads(RoutingContext ctx, RouteDataObject initial, boolean begin, TLongObjectHashMap<List<RouteDataObject>> all) {
    PriorityQueue<RouteSegment> queue = new PriorityQueue<RouteSegment>(10, new Comparator<RouteSegment>() {

        @Override
        public int compare(RouteSegment o1, RouteSegment o2) {
            return Double.compare(o1.getDistanceFromStart(), o2.getDistanceFromStart());
        }
    });
    VehicleRouter router = ctx.getRouter();
    ArrayList<RouteDataObject> next = new ArrayList<RouteDataObject>();
    ctx.loadTileData(initial.getPoint31XTile(0), initial.getPoint31YTile(0), 17, next);
    for (RouteDataObject n : next) {
        if (n.id == initial.id) {
            initial = n;
            break;
        }
    }
    queue.add(new RouteSegment(initial, begin ? 1 : initial.getPointsLength() - 2));
    TLongHashSet visited = new TLongHashSet();
    RouteSegment finalSegment = null;
    while (!queue.isEmpty() && finalSegment == null) {
        RouteSegment segment = queue.poll();
        int oneWay = router.isOneWay(segment.getRoad());
        boolean start = initial.id == segment.getRoad().id;
        if (start) {
            oneWay = begin ? -1 : 1;
        }
        if (oneWay >= 0) {
            finalSegment = processSegment(ctx, segment, queue, visited, all, true, start);
        }
        if (oneWay <= 0) {
            finalSegment = processSegment(ctx, segment, queue, visited, all, false, start);
        }
    }
    if (finalSegment == null) {
        if (TRACE) {
            System.out.println("Isolated " + initial.id);
        }
    } else {
        StringBuilder b = new StringBuilder("Route for " + initial.id + " : ");
        RouteSegment s = finalSegment;
        List<RouteDataObject> rdoToAdd = new ArrayList<RouteDataObject>();
        while (s != null) {
            if (s.getRoad().id != initial.id) {
                b.append(s.getRoad().id).append(", ");
                rdoToAdd.add(s.getRoad());
            }
            s = s.getParentRoute();
        }
        if (TRACE) {
            System.out.println(b);
        }
        return rdoToAdd;
    }
    return null;
}
Also used : ArrayList(java.util.ArrayList) PriorityQueue(java.util.PriorityQueue) TLongHashSet(gnu.trove.set.hash.TLongHashSet) RouteDataObject(net.osmand.binary.RouteDataObject) VehicleRouter(net.osmand.router.VehicleRouter) RouteSegment(net.osmand.router.BinaryRoutePlanner.RouteSegment)

Example 4 with TLongHashSet

use of gnu.trove.set.hash.TLongHashSet in project OsmAnd-tools by osmandapp.

the class OceanTilesCreator method createJOSMFile.

public static void createJOSMFile(String[] args) throws XMLStreamException, IOException {
    String fileLocation = args.length == 0 ? "oceanTiles.osm" : args[0];
    int z = TILE_ZOOMLEVEL;
    BasemapProcessor bmp = new BasemapProcessor();
    bmp.constructBitSetInfo(args.length > 1 ? args[1] : null);
    OsmBaseStorage st = new OsmBaseStorage();
    Set<Entity.EntityId> s = new LinkedHashSet();
    TLongHashSet nodeIds = new TLongHashSet();
    int minzoom = 4;
    BasemapProcessor.SimplisticQuadTree quadTree = bmp.constructTilesQuadTree(z);
    for (int zm = minzoom; zm <= z; zm++) {
        int pz = 1 << zm;
        for (int x = 0; x < pz; x++) {
            for (int y = 0; y < pz; y++) {
                // if((quadTree.getOrCreateSubTree(i, j, z).seaCharacteristic < 0.9 && !bmp.isWaterTile(i, j, z))||
                // bmp.isLandTile(i, j, z) ) {
                boolean parentWater = bmp.isWaterTile(x >> 1, y >> 1, zm - 1);
                boolean parentLand = bmp.isLandTile(x >> 1, y >> 1, zm - 1);
                if (zm > minzoom && (parentLand || parentWater)) {
                    continue;
                }
                boolean landTile = bmp.isLandTile(x, y, zm);
                boolean waterTile = bmp.isWaterTile(x, y, zm);
                if (waterTile || landTile) {
                    Way w = new Way(-getNodeId(x, y, zm));
                    addNode(w, nodeIds, x, y, zm);
                    addNode(w, nodeIds, x, y + 1, zm);
                    addNode(w, nodeIds, x + 1, y + 1, zm);
                    addNode(w, nodeIds, x + 1, y, zm);
                    addNode(w, nodeIds, x, y, zm);
                    if (waterTile) {
                        w.putTag("natural", "water");
                    } else if (landTile) {
                        w.putTag("landuse", "grass");
                    }
                    w.putTag("name", x + " " + y + " " + zm + " " + (waterTile ? 1 : 0));
                    s.addAll(w.getEntityIds());
                    s.add(Entity.EntityId.valueOf(w));
                    st.registerEntity(w, null);
                }
            }
        }
    }
    for (long l : nodeIds.toArray()) {
        st.registerEntity(getNode(l), null);
    }
    new OsmStorageWriter().saveStorage(new FileOutputStream(fileLocation), st, s, true);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) OsmStorageWriter(net.osmand.osm.io.OsmStorageWriter) Way(net.osmand.osm.edit.Way) OsmBaseStorage(net.osmand.osm.io.OsmBaseStorage) TLongHashSet(gnu.trove.set.hash.TLongHashSet) FileOutputStream(java.io.FileOutputStream)

Example 5 with TLongHashSet

use of gnu.trove.set.hash.TLongHashSet in project OsmAnd-tools by osmandapp.

the class MapClusterLayer method searchCluster.

private List<RouteSegment> searchCluster(ClusteringContext cCtx, RoutingContext ctx, RouteSegment st) throws IOException {
    List<RouteSegment> result = new ArrayList<BinaryRoutePlanner.RouteSegment>();
    TLongHashSet visitedIds = new TLongHashSet();
    RouteDataObject startRoad = st.getRoad();
    final int stx = startRoad.getPoint31XTile(st.getSegmentStart());
    final int sty = startRoad.getPoint31YTile(st.getSegmentStart());
    int tileX = startRoad.getPoint31XTile(st.getSegmentStart()) >> cCtx.zm;
    int tileY = startRoad.getPoint31YTile(st.getSegmentStart()) >> cCtx.zm;
    Queue<RouteSegment> queue = new PriorityQueue<RouteSegment>(50, new Comparator<RouteSegment>() {

        @Override
        public int compare(RouteSegment o1, RouteSegment o2) {
            double d1 = MapUtils.squareDist31TileMetric(stx, sty, o1.getRoad().getPoint31XTile(o1.getSegmentStart()), o1.getRoad().getPoint31YTile(o1.getSegmentStart()));
            double d2 = MapUtils.squareDist31TileMetric(stx, sty, o2.getRoad().getPoint31XTile(o2.getSegmentStart()), o2.getRoad().getPoint31YTile(o2.getSegmentStart()));
            return Double.compare(d1, d2);
        }
    });
    queue.add(st);
    while (!queue.isEmpty()) {
        RouteSegment segment = queue.poll();
        if (visitedIds.contains(calculateId(segment))) {
            // System.out.println("contains " + segment.getRoad());
            continue;
        }
        // System.out.println(segment.getRoad());
        visitedIds.add(calculateId(segment));
        // Visualization of steps !
        if (ctx.getVisitor() != null) {
            ctx.getVisitor().visitSegment(segment, -1, true);
        }
        cCtx.roadProcessed++;
        if (cCtx.roadProcessed > 50) {
            float ratio = (float) (queue.size() + cCtx.outOfTile + cCtx.outOfDistance) / cCtx.segmentsProcessed;
            if (ratio < cCtx.minRatio) {
                cCtx.minRatio = ratio;
                cCtx.roadMinProcessed = cCtx.roadProcessed;
            }
        }
        processSegment(cCtx, ctx, segment, queue, result, tileX, tileY, true);
        processSegment(cCtx, ctx, segment, queue, result, tileX, tileY, false);
    }
    System.out.println("Current ratio " + ((float) (queue.size() + cCtx.outOfTile + cCtx.outOfDistance) / cCtx.segmentsProcessed) + " min ratio " + cCtx.minRatio + " min segments procesed " + cCtx.roadMinProcessed);
    String res = "Processed " + cCtx.roadProcessed + " / " + cCtx.segmentsProcessed + " and borders are " + (cCtx.outOfTile + cCtx.outOfDistance) + " out because of distance " + cCtx.outOfDistance;
    log.info(res);
    return result;
}
Also used : BinaryRoutePlanner(net.osmand.router.BinaryRoutePlanner) ArrayList(java.util.ArrayList) PriorityQueue(java.util.PriorityQueue) Point(java.awt.Point) TLongHashSet(gnu.trove.set.hash.TLongHashSet) RouteDataObject(net.osmand.binary.RouteDataObject) RouteSegment(net.osmand.router.BinaryRoutePlanner.RouteSegment)

Aggregations

TLongHashSet (gnu.trove.set.hash.TLongHashSet)22 ArrayList (java.util.ArrayList)11 RouteDataObject (net.osmand.binary.RouteDataObject)6 TLongSet (gnu.trove.set.TLongSet)5 List (java.util.List)5 TLongArrayList (gnu.trove.list.array.TLongArrayList)4 TLongObjectHashMap (gnu.trove.map.hash.TLongObjectHashMap)4 TIntArrayList (gnu.trove.list.array.TIntArrayList)3 BinaryMapIndexReader (net.osmand.binary.BinaryMapIndexReader)3 IOException (java.io.IOException)2 LinkedList (java.util.LinkedList)2 PriorityQueue (java.util.PriorityQueue)2 TimeUnit (java.util.concurrent.TimeUnit)2 VoiceChannel (net.dv8tion.jda.core.entities.VoiceChannel)2 Node (net.osmand.osm.edit.Node)2 BinaryRoutePlanner (net.osmand.router.BinaryRoutePlanner)2 RouteSegment (net.osmand.router.BinaryRoutePlanner.RouteSegment)2 Async (br.com.brjdevs.java.utils.async.Async)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 DiscordBotsAPI (com.github.natanbc.discordbotsapi.DiscordBotsAPI)1