Search in sources :

Example 11 with TLongHashSet

use of gnu.trove.set.hash.TLongHashSet in project Osmand by osmandapp.

the class RoutingContext method loadTileData.

public void loadTileData(int x31, int y31, int zoomAround, final List<RouteDataObject> toFillIn) {
    int t = config.ZOOM_TO_LOAD_TILES - zoomAround;
    int coordinatesShift = (1 << (31 - config.ZOOM_TO_LOAD_TILES));
    if (t <= 0) {
        t = 1;
        coordinatesShift = (1 << (31 - zoomAround));
    } else {
        t = 1 << t;
    }
    TLongHashSet ts = new TLongHashSet();
    long now = System.nanoTime();
    for (int i = -t; i <= t; i++) {
        for (int j = -t; j <= t; j++) {
            ts.add(getRoutingTile(x31 + i * coordinatesShift, y31 + j * coordinatesShift, 0, OPTION_IN_MEMORY_LOAD));
        }
    }
    TLongIterator it = ts.iterator();
    TLongObjectHashMap<RouteDataObject> excludeDuplications = new TLongObjectHashMap<RouteDataObject>();
    while (it.hasNext()) {
        getAllObjects(it.next(), toFillIn, excludeDuplications);
    }
    timeToFindInitialSegments += (System.nanoTime() - now);
}
Also used : TLongHashSet(gnu.trove.set.hash.TLongHashSet) TLongObjectHashMap(gnu.trove.map.hash.TLongObjectHashMap) RouteDataObject(net.osmand.binary.RouteDataObject) TLongIterator(gnu.trove.iterator.TLongIterator)

Example 12 with TLongHashSet

use of gnu.trove.set.hash.TLongHashSet in project gridss by PapenfussLab.

the class DeBruijnGraphBase method debugPrintPaths.

public String debugPrintPaths() {
    Map<Long, Integer> contigLookup = Maps.newHashMap();
    TLongSet remaining = new TLongHashSet(kmers.keySet());
    List<LinkedList<Long>> paths = Lists.newArrayList();
    int contig = 0;
    // enumerate the paths
    while (!remaining.isEmpty()) {
        contig++;
        LinkedList<Long> path = new LinkedList<Long>();
        path.add(remaining.iterator().next());
        remaining.remove(path.getFirst());
        contigLookup.put(path.getFirst(), contig);
        for (List<Long> adj = nextStates(path.getLast(), null, null); adj.size() == 1 && prevStates(adj.get(0), null, null).size() <= 1; adj = nextStates(path.getLast(), null, null)) {
            contigLookup.put(adj.get(0), contig);
            path.addLast(adj.get(0));
            remaining.remove(adj.get(0));
        }
        for (List<Long> adj = prevStates(path.getFirst(), null, null); adj.size() == 1 && nextStates(adj.get(0), null, null).size() <= 1; adj = prevStates(path.getFirst(), null, null)) {
            contigLookup.put(adj.get(0), contig);
            path.addFirst(adj.get(0));
            remaining.remove(adj.get(0));
        }
        paths.add(path);
    }
    return debugPrintPaths(paths, contigLookup);
}
Also used : TLongSet(gnu.trove.set.TLongSet) TLongHashSet(gnu.trove.set.hash.TLongHashSet) LinkedList(java.util.LinkedList)

Example 13 with TLongHashSet

use of gnu.trove.set.hash.TLongHashSet in project MantaroBot by Mantaro.

the class ShardedMantaro method startUpdaters.

private void startUpdaters() {
    Async.task("Carbonitex post task", carbonitex::handle, 30, TimeUnit.MINUTES);
    if (config.dbotsorgToken != null) {
        Async.task("dbots.org update thread", () -> {
            try {
                long count = MantaroBot.getInstance().getGuildCache().size();
                int[] shards = MantaroBot.getInstance().getShardList().stream().mapToInt(shard -> (int) shard.getGuildCache().size()).toArray();
                discordBotsAPI.postStats(shards);
                log.debug("Updated server count ({}) for discordbots.org", count);
            } catch (Exception ignored) {
            }
        }, 1, TimeUnit.HOURS);
        Async.task("discordbots.org upvotes task", () -> {
            if (config.dbotsorgToken == null)
                return;
            try {
                Request request = new Request.Builder().url("https://discordbots.org/api/bots/213466096718708737/votes?onlyids=1").addHeader("Authorization", config.dbotsorgToken).build();
                Response r = Utils.httpClient.newCall(request).execute();
                ResponseBody body = r.body();
                if (body == null)
                    return;
                // It's definitely String.
                @SuppressWarnings("unchecked") List<String> upvoters = objectMapper.readValue(body.string(), List.class);
                List<Long> upvotersLong = upvoters.stream().map(Long::parseLong).distinct().collect(Collectors.toList());
                TLongSet set = new TLongHashSet();
                set.addAll(upvotersLong);
                discordBotsUpvoters = new TUnmodifiableLongSet(set);
                r.close();
            } catch (Exception ignored) {
            }
        }, 5, TimeUnit.MINUTES);
    } else {
        log.warn("discordbots.org token not set in config, cannot start posting stats!");
    }
    String dbotsToken = config.dbotsToken;
    if (dbotsToken != null) {
        Async.task("bots.discord.pw update Thread", () -> {
            try {
                long count = MantaroBot.getInstance().getGuildCache().size();
                RequestBody body = RequestBody.create(JSON, new JSONObject().put("server_count", count).toString());
                Request request = new Request.Builder().url("https://bots.discord.pw/api/bots/213466096718708737/stats").addHeader("User-Agent", MantaroInfo.USER_AGENT).addHeader("Authorization", dbotsToken).addHeader("Content-Type", "application/json").post(body).build();
                Utils.httpClient.newCall(request).execute().close();
                log.debug("Updated server count for bots.discord.pw");
            } catch (Exception ignored) {
            }
        }, 1, TimeUnit.HOURS);
    }
    for (MantaroShard shard : getShards()) {
        shard.updateStatus();
    }
}
Also used : MantaroInfo(net.kodehawa.mantarobot.MantaroInfo) Getter(lombok.Getter) PostLoadEvent(net.kodehawa.mantarobot.core.listeners.events.PostLoadEvent) Async(br.com.brjdevs.java.utils.async.Async) Utils(net.kodehawa.mantarobot.utils.Utils) SHARD_FETCH_FAILURE(net.kodehawa.mantarobot.utils.ShutdownCodes.SHARD_FETCH_FAILURE) LoadState(net.kodehawa.mantarobot.core.LoadState) ICommandProcessor(net.kodehawa.mantarobot.core.processor.core.ICommandProcessor) ArrayList(java.util.ArrayList) MantaroBot(net.kodehawa.mantarobot.MantaroBot) JSONObject(org.json.JSONObject) okhttp3(okhttp3) TLongHashSet(gnu.trove.set.hash.TLongHashSet) SnowflakeCacheView(net.dv8tion.jda.core.utils.cache.SnowflakeCacheView) Collector(java.util.stream.Collector) MantaroCore(net.kodehawa.mantarobot.core.MantaroCore) Config(net.kodehawa.mantarobot.data.Config) PostingException(com.github.natanbc.discordbotsapi.PostingException) VoiceChannel(net.dv8tion.jda.core.entities.VoiceChannel) TLongSet(gnu.trove.set.TLongSet) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SentryHelper(net.kodehawa.mantarobot.utils.SentryHelper) Collectors(java.util.stream.Collectors) DiscordBotsAPI(com.github.natanbc.discordbotsapi.DiscordBotsAPI) MantaroEventManager(net.kodehawa.mantarobot.core.MantaroEventManager) TimeUnit(java.util.concurrent.TimeUnit) ShardWatcher(net.kodehawa.mantarobot.core.shard.watcher.ShardWatcher) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) TUnmodifiableLongSet(gnu.trove.impl.unmodifiable.TUnmodifiableLongSet) Carbonitex(net.kodehawa.mantarobot.services.Carbonitex) MantaroData(net.kodehawa.mantarobot.data.MantaroData) LogUtils(net.kodehawa.mantarobot.log.LogUtils) JSONArray(org.json.JSONArray) PostingException(com.github.natanbc.discordbotsapi.PostingException) JSONObject(org.json.JSONObject) TLongSet(gnu.trove.set.TLongSet) TLongHashSet(gnu.trove.set.hash.TLongHashSet) TUnmodifiableLongSet(gnu.trove.impl.unmodifiable.TUnmodifiableLongSet)

Example 14 with TLongHashSet

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

the class IndexRouteCreator method processingLowLevelWays.

public void processingLowLevelWays(IProgress progress) {
    if (!generateLowLevel) {
        return;
    }
    pointTypes.clear();
    pointNames.clear();
    Collection<GeneralizedCluster> clusters = new ArrayList<IndexRouteCreator.GeneralizedCluster>(generalClusters.valueCollection());
    // 1. roundabouts
    processRoundabouts(clusters);
    // 2. way combination based
    for (GeneralizedCluster cluster : clusters) {
        ArrayList<GeneralizedWay> copy = new ArrayList<GeneralizedWay>(cluster.ways);
        for (GeneralizedWay gw : copy) {
            // already deleted
            if (!cluster.ways.contains(gw)) {
                continue;
            }
            attachWays(gw, true);
            attachWays(gw, false);
        }
    }
    // 3. Douglas peuker simplifications
    douglasPeukerSimplificationStep(clusters);
    // 5. write to db
    TLongHashSet ids = new TLongHashSet();
    for (GeneralizedCluster cluster : clusters) {
        for (GeneralizedWay gw : cluster.ways) {
            if (ids.contains(gw.id)) {
                continue;
            }
            ids.add(gw.id);
            names.clear();
            Iterator<Entry<MapRouteType, String>> its = gw.names.entrySet().iterator();
            while (its.hasNext()) {
                Entry<MapRouteType, String> e = its.next();
                if (e.getValue() != null && !e.getValue().equals(CONFLICT_NAME)) {
                    names.put(e.getKey(), e.getValue());
                }
            }
            ArrayList<Node> nodes = new ArrayList<Node>();
            if (gw.size() == 0) {
                System.err.println(gw.id + " empty ? ");
                continue;
            }
            long prev = 0;
            for (int i = 0; i < gw.size(); i++) {
                long loc = gw.getLocation(i);
                if (loc != prev) {
                    Node c = convertBaseToNode(loc);
                    prev = loc;
                    nodes.add(c);
                }
            }
            outTypes.clear();
            outTypes.add(gw.mainType);
            outTypes.addAll(gw.addtypes);
            try {
                addWayToIndex(gw.id, nodes, basemapRouteInsertStat, baserouteTree, outTypes, pointTypes, pointNames, names);
            } catch (SQLException e) {
                throw new IllegalStateException(e);
            }
        }
    }
}
Also used : SQLException(java.sql.SQLException) Node(net.osmand.osm.edit.Node) TIntArrayList(gnu.trove.list.array.TIntArrayList) ArrayList(java.util.ArrayList) TLongArrayList(gnu.trove.list.array.TLongArrayList) MapRouteType(net.osmand.osm.MapRoutingTypes.MapRouteType) Entry(java.util.Map.Entry) TLongHashSet(gnu.trove.set.hash.TLongHashSet)

Example 15 with TLongHashSet

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

the class IndexVectorMapCreator method processingLowLevelWays.

public void processingLowLevelWays(IProgress progress) throws SQLException {
    mapLowLevelBinaryStat.executeBatch();
    mapLowLevelBinaryStat.close();
    pStatements.remove(mapLowLevelBinaryStat);
    mapLowLevelBinaryStat = null;
    mapConnection.commit();
    PreparedStatement startStat = mapConnection.prepareStatement("SELECT id, end_node, nodes, name, type, addType FROM low_level_map_objects" + " WHERE start_node = ? AND level = ?");
    PreparedStatement endStat = mapConnection.prepareStatement("SELECT id, start_node, nodes, name, type, addType FROM low_level_map_objects" + " WHERE end_node = ? AND level = ?");
    Statement selectStatement = mapConnection.createStatement();
    ResultSet rs = selectStatement.executeQuery("SELECT id, start_node, end_node, nodes, name, type, addType, level FROM low_level_map_objects");
    TLongHashSet visitedWays = new TLongHashSet();
    ArrayList<Float> list = new ArrayList<Float>(100);
    TIntArrayList temp = new TIntArrayList();
    TIntArrayList tempAdd = new TIntArrayList();
    while (rs.next()) {
        if (lowLevelWays != -1) {
            progress.progress(1);
        }
        long id = rs.getLong(1);
        if (visitedWays.contains(id)) {
            continue;
        }
        visitedWays.add(id);
        int level = rs.getInt(8);
        int zoom = mapZooms.getLevel(level).getMaxZoom();
        int minZoom = mapZooms.getLevel(level).getMinZoom();
        long startNode = rs.getLong(2);
        long endNode = rs.getLong(3);
        namesUse.clear();
        decodeNames(rs.getString(5), namesUse);
        parseAndSort(typeUse, rs.getBytes(6));
        parseAndSort(addtypeUse, rs.getBytes(7));
        loadNodes(rs.getBytes(4), list);
        ArrayList<Float> wayNodes = new ArrayList<Float>(list);
        // combine startPoint with EndPoint
        List<LowLevelWayCandidate> candidates = new ArrayList<LowLevelWayCandidate>();
        Comparator<LowLevelWayCandidate> cmpCandidates = new Comparator<LowLevelWayCandidate>() {

            @Override
            public int compare(LowLevelWayCandidate o1, LowLevelWayCandidate o2) {
                return -Integer.compare(o1.namesCount, o2.namesCount);
            }
        };
        boolean combined = true;
        if (minZoom >= LOW_LEVEL_ZOOM_TO_COMBINE) {
            // disable combine
            combined = false;
        }
        while (combined && wayNodes.size() < LOW_LEVEL_COMBINE_WAY_POINS_LIMIT) {
            combined = false;
            endStat.setLong(1, startNode);
            endStat.setShort(2, (short) level);
            ResultSet fs = endStat.executeQuery();
            readLowLevelCandidates(fs, candidates, temp, tempAdd, visitedWays);
            fs.close();
            LowLevelWayCandidate cand = getCandidate(candidates, cmpCandidates);
            if (cand != null) {
                combined = true;
                startNode = cand.otherNodeId;
                visitedWays.add(cand.wayId);
                loadNodes(cand.nodes, list);
                ArrayList<Float> li = new ArrayList<Float>(list);
                // remove first lat/lon point
                wayNodes.remove(0);
                wayNodes.remove(0);
                li.addAll(wayNodes);
                wayNodes = li;
                for (MapRulType rt : new ArrayList<MapRulType>(namesUse.keySet())) {
                    if (!Algorithms.objectEquals(namesUse.get(rt), cand.names.get(rt)) && !checkOneLocaleHasSameName(namesUse, cand.names, rt)) {
                        namesUse.remove(rt);
                    }
                }
            }
        }
        // combined end point
        combined = true;
        if (minZoom >= LOW_LEVEL_ZOOM_TO_COMBINE) {
            // disable combine
            combined = false;
        }
        while (combined && wayNodes.size() < LOW_LEVEL_COMBINE_WAY_POINS_LIMIT) {
            combined = false;
            startStat.setLong(1, endNode);
            startStat.setShort(2, (short) level);
            ResultSet fs = startStat.executeQuery();
            readLowLevelCandidates(fs, candidates, temp, tempAdd, visitedWays);
            fs.close();
            LowLevelWayCandidate cand = getCandidate(candidates, cmpCandidates);
            if (cand != null) {
                combined = true;
                endNode = cand.otherNodeId;
                visitedWays.add(cand.wayId);
                loadNodes(cand.nodes, list);
                for (int i = 2; i < list.size(); i++) {
                    wayNodes.add(list.get(i));
                }
                for (MapRulType rt : new ArrayList<MapRulType>(namesUse.keySet())) {
                    if (!Algorithms.objectEquals(namesUse.get(rt), cand.names.get(rt)) && !checkOneLocaleHasSameName(namesUse, cand.names, rt)) {
                        namesUse.remove(rt);
                    }
                }
            }
        }
        List<Node> wNodes = new ArrayList<Node>();
        int wNsize = wayNodes.size();
        for (int i = 0; i < wNsize; i += 2) {
            wNodes.add(new Node(wayNodes.get(i), wayNodes.get(i + 1), i == 0 ? startNode : endNode));
        }
        boolean skip = false;
        boolean cycle = startNode == endNode;
        if (cycle) {
            skip = checkForSmallAreas(wNodes, zoom + Math.min(zoomWaySmoothness / 2, 3), 3, 4);
        } else {
            // coastline
            if (!typeUse.contains(renderingTypes.getCoastlineRuleType().getInternalId())) {
                skip = checkForSmallAreas(wNodes, zoom + Math.min(zoomWaySmoothness / 2, 3), 2, 8);
            }
        }
        if (!skip) {
            List<Node> res = new ArrayList<Node>();
            OsmMapUtils.simplifyDouglasPeucker(wNodes, zoom - 1 + 8 + zoomWaySmoothness, 3, res, false);
            if (res.size() > 0) {
                insertBinaryMapRenderObjectIndex(mapTree[level], res, null, namesUse, id, false, typeUse, addtypeUse, false);
            }
        }
    // end cycle
    }
}
Also used : PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) Node(net.osmand.osm.edit.Node) TIntArrayList(gnu.trove.list.array.TIntArrayList) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) TIntArrayList(gnu.trove.list.array.TIntArrayList) Comparator(java.util.Comparator) MapRulType(net.osmand.osm.MapRenderingTypes.MapRulType) TLongHashSet(gnu.trove.set.hash.TLongHashSet) ResultSet(java.sql.ResultSet)

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