use of com.carrotsearch.hppc.cursors.IntCursor in project graphhopper by graphhopper.
the class PrepareRoutingSubnetworks method setSubnetworks.
private int setSubnetworks(Weighting weighting, BooleanEncodedValue subnetworkEnc) {
// partition graph into strongly connected components using Tarjan's algorithm
StopWatch sw = new StopWatch().start();
EdgeBasedTarjanSCC.ConnectedComponents ccs = EdgeBasedTarjanSCC.findComponents(ghStorage, (prev, edge) -> Double.isFinite(GHUtility.calcWeightWithTurnWeightWithAccess(weighting, edge, false, prev)), false);
List<IntArrayList> components = ccs.getComponents();
BitSet singleEdgeComponents = ccs.getSingleEdgeComponents();
long numSingleEdgeComponents = singleEdgeComponents.cardinality();
logger.info(subnetworkEnc.getName().replaceAll("_subnetwork", "") + " - Found " + ccs.getTotalComponents() + " subnetworks (" + numSingleEdgeComponents + " single edges and " + components.size() + " components with more than one edge, total nodes: " + ccs.getEdgeKeys() + "), took: " + sw.stop().getSeconds() + "s");
final int minNetworkSizeEdgeKeys = 2 * minNetworkSize;
// make all small components subnetworks, but keep the biggest (even when its smaller than the given min_network_size)
sw = new StopWatch().start();
int subnetworks = 0;
int markedEdges = 0;
int smallestNonSubnetwork = ccs.getBiggestComponent().size();
int biggestSubnetwork = 0;
for (IntArrayList component : components) {
if (component == ccs.getBiggestComponent())
continue;
if (component.size() < minNetworkSizeEdgeKeys) {
for (IntCursor cursor : component) markedEdges += setSubnetworkEdge(cursor.value, weighting, subnetworkEnc);
subnetworks++;
biggestSubnetwork = Math.max(biggestSubnetwork, component.size());
} else {
smallestNonSubnetwork = Math.min(smallestNonSubnetwork, component.size());
}
}
if (minNetworkSizeEdgeKeys > 0) {
BitSetIterator iter = singleEdgeComponents.iterator();
for (int edgeKey = iter.nextSetBit(); edgeKey >= 0; edgeKey = iter.nextSetBit()) {
markedEdges += setSubnetworkEdge(edgeKey, weighting, subnetworkEnc);
subnetworks++;
biggestSubnetwork = Math.max(biggestSubnetwork, 1);
}
} else if (numSingleEdgeComponents > 0) {
smallestNonSubnetwork = Math.min(smallestNonSubnetwork, 1);
}
int allowedMarked = ghStorage.getEdges() / 2;
if (markedEdges / 2 > allowedMarked)
throw new IllegalStateException("Too many total (directed) edges were marked as subnetwork edges: " + markedEdges + " out of " + (2 * ghStorage.getEdges()) + "\n" + "The maximum number of subnetwork edges is: " + (2 * allowedMarked));
logger.info(subnetworkEnc.getName().replaceAll("_subnetwork", "") + " - Marked " + subnetworks + " subnetworks (biggest: " + biggestSubnetwork + " edges) -> " + (ccs.getTotalComponents() - subnetworks) + " components(s) remain (smallest: " + smallestNonSubnetwork + ", biggest: " + ccs.getBiggestComponent().size() + " edges)" + ", total marked edges: " + markedEdges + ", took: " + sw.stop().getSeconds() + "s");
return markedEdges;
}
use of com.carrotsearch.hppc.cursors.IntCursor in project graphhopper by graphhopper.
the class EdgeBasedTarjanSCC method findComponentsForStartEdges.
private ConnectedComponents findComponentsForStartEdges(IntContainer startEdges) {
initForStartEdges(startEdges.size());
for (IntCursor edge : startEdges) {
// todo: using getEdgeIteratorState here is not efficient
EdgeIteratorState edgeState = graph.getEdgeIteratorState(edge.value, Integer.MIN_VALUE);
if (!edgeTransitionFilter.accept(NO_EDGE, edgeState))
continue;
findComponentsForEdgeState(edgeState);
}
return components;
}
use of com.carrotsearch.hppc.cursors.IntCursor in project graphhopper by graphhopper.
the class PtLocationSnapper method snapAll.
public Result snapAll(List<GHLocation> locations, List<EdgeFilter> snapFilters) {
PointList points = new PointList(2, false);
ArrayList<Snap> pointSnaps = new ArrayList<>();
ArrayList<Supplier<Label.NodeId>> allSnaps = new ArrayList<>();
for (int i = 0; i < locations.size(); i++) {
GHLocation location = locations.get(i);
if (location instanceof GHPointLocation) {
GHPoint point = ((GHPointLocation) location).ghPoint;
final Snap closest = locationIndex.findClosest(point.lat, point.lon, snapFilters.get(i));
if (!closest.isValid()) {
IntHashSet result = new IntHashSet();
gtfsStorage.getStopIndex().findEdgeIdsInNeighborhood(point.lat, point.lon, 0, result::add);
gtfsStorage.getStopIndex().findEdgeIdsInNeighborhood(point.lat, point.lon, 1, result::add);
if (result.isEmpty()) {
throw new PointNotFoundException("Cannot find point: " + point, i);
}
IntCursor stopNodeId = result.iterator().next();
for (Map.Entry<GtfsStorage.FeedIdWithStopId, Integer> e : gtfsStorage.getStationNodes().entrySet()) {
if (e.getValue() == stopNodeId.value) {
Stop stop = gtfsStorage.getGtfsFeeds().get(e.getKey().feedId).stops.get(e.getKey().stopId);
final Snap stopSnap = new Snap(stop.stop_lat, stop.stop_lon);
stopSnap.setClosestNode(stopNodeId.value);
allSnaps.add(() -> new Label.NodeId(Optional.ofNullable(gtfsStorage.getPtToStreet().get(stopSnap.getClosestNode())).orElse(-1), stopSnap.getClosestNode()));
points.add(stopSnap.getQueryPoint().lat, stopSnap.getQueryPoint().lon);
}
}
} else {
pointSnaps.add(closest);
allSnaps.add(() -> new Label.NodeId(closest.getClosestNode(), Optional.ofNullable(gtfsStorage.getStreetToPt().get(closest.getClosestNode())).orElse(-1)));
points.add(closest.getSnappedPoint());
}
} else if (location instanceof GHStationLocation) {
final Snap stopSnap = findByStopId((GHStationLocation) location, i);
allSnaps.add(() -> new Label.NodeId(Optional.ofNullable(gtfsStorage.getPtToStreet().get(stopSnap.getClosestNode())).orElse(-1), stopSnap.getClosestNode()));
points.add(stopSnap.getQueryPoint().lat, stopSnap.getQueryPoint().lon);
}
}
// modifies pointSnaps!
QueryGraph queryGraph = QueryGraph.create(graphHopperStorage, pointSnaps);
List<Label.NodeId> nodes = new ArrayList<>();
for (Supplier<Label.NodeId> supplier : allSnaps) {
nodes.add(supplier.get());
}
return new Result(queryGraph, nodes, points);
}
use of com.carrotsearch.hppc.cursors.IntCursor in project crate by crate.
the class JobSetup method prepareOnHandler.
public List<CompletableFuture<StreamBucket>> prepareOnHandler(SessionSettings sessionInfo, Collection<? extends NodeOperation> nodeOperations, RootTask.Builder taskBuilder, List<Tuple<ExecutionPhase, RowConsumer>> handlerPhases, SharedShardContexts sharedShardContexts) {
Context context = new Context(clusterService.localNode().getId(), sessionInfo, taskBuilder, LOGGER, distributingConsumerFactory, nodeOperations, sharedShardContexts);
for (Tuple<ExecutionPhase, RowConsumer> handlerPhase : handlerPhases) {
context.registerLeaf(handlerPhase.v1(), handlerPhase.v2());
}
registerContextPhases(nodeOperations, context);
LOGGER.trace("prepareOnHandler: nodeOperations={}, handlerPhases={}, targetSourceMap={}", nodeOperations, handlerPhases, context.opCtx.targetToSourceMap);
IntHashSet leafs = new IntHashSet();
for (Tuple<ExecutionPhase, RowConsumer> handlerPhase : handlerPhases) {
ExecutionPhase phase = handlerPhase.v1();
createContexts(phase, context);
leafs.add(phase.phaseId());
}
leafs.addAll(context.opCtx.findLeafs());
for (IntCursor cursor : leafs) {
prepareSourceOperations(cursor.value, context);
}
assert context.opCtx.allNodeOperationContextsBuilt() : "some nodeOperations haven't been processed";
return context.directResponseFutures;
}
use of com.carrotsearch.hppc.cursors.IntCursor in project crate by crate.
the class NodeFetchRequest method writeTo.
@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeLong(jobId.getMostSignificantBits());
out.writeLong(jobId.getLeastSignificantBits());
out.writeVInt(fetchPhaseId);
out.writeBoolean(closeContext);
if (toFetch == null) {
out.writeVInt(0);
} else {
out.writeVInt(toFetch.size());
for (IntObjectCursor<? extends IntContainer> toFetchCursor : toFetch) {
out.writeVInt(toFetchCursor.key);
out.writeVInt(toFetchCursor.value.size());
for (IntCursor docCursor : toFetchCursor.value) {
out.writeInt(docCursor.value);
}
}
}
}
Aggregations