/** * Executes <tt>procedure</tt> for each element in the set. * * @param procedure a <code>TObjectProcedure</code> value * @return false if the loop over the set terminated because * the procedure returned false for some value. */ @Override public boolean forEach(TObjectProcedure<? super E> procedure) { ForEachProcedure forEachProcedure = new ForEachProcedure(_set, procedure); return order.forEach(forEachProcedure); } }
@Override protected void writeEntries(ObjectOutput out) throws IOException { // ENTRIES WriteProcedure writeProcedure = new WriteProcedure(out); if (!order.forEach(writeProcedure)) throw writeProcedure.getIoException(); }
indices.forEach(value -> { if (value < 0 || value >= vertices.length) { throw new JsonParseException("Face value out of range: " + value + ", max vertex is " + (vertices.length - 1));
/** Mark patterns at touched stops, to be explored in a subsequent round */ private void markPatterns () { this.touchedPatterns.clear(); for (int stop = touchedStops.nextSetBit(0); stop >= 0; stop = touchedStops.nextSetBit(stop + 1)) { network.transitLayer.patternsForStop.get(stop).forEach(pat -> { this.touchedPatterns.set(pat); return true; }); } this.touchedStops.clear(); }
/** Mark patterns at touched stops, to be explored in a subsequent round */ private void markPatterns () { this.touchedPatterns.clear(); for (int stop = touchedStops.nextSetBit(0); stop >= 0; stop = touchedStops.nextSetBit(stop + 1)) { network.transitLayer.patternsForStop.get(stop).forEach(pat -> { this.touchedPatterns.set(pat); return true; }); } this.touchedStops.clear(); }
/** * Executes <tt>procedure</tt> for each element in the set. * * @param procedure a <code>TObjectProcedure</code> value * @return false if the loop over the set terminated because * the procedure returned false for some value. */ @Override public boolean forEach(TObjectProcedure<? super E> procedure) { ForEachProcedure forEachProcedure = new ForEachProcedure(_set, procedure); return order.forEach(forEachProcedure); } }
/** * Executes <tt>procedure</tt> for each element in the set. * * @param procedure a <code>TObjectProcedure</code> value * @return false if the loop over the set terminated because * the procedure returned false for some value. */ @Override public boolean forEach(TObjectProcedure<? super E> procedure) { ForEachProcedure forEachProcedure = new ForEachProcedure(_set, procedure); return order.forEach(forEachProcedure); } }
transit.patternsForStop.get(stop).forEach(originalPattern -> { int filteredPattern = index[originalPattern];
transit.patternsForStop.get(stop).forEach(originalPattern -> { int filteredPattern = index[originalPattern];
@Override protected void writeEntries(ObjectOutput out) throws IOException { // ENTRIES WriteProcedure writeProcedure = new WriteProcedure(out); if (!order.forEach(writeProcedure)) throw writeProcedure.getIoException(); }
@Override protected void writeEntries(ObjectOutput out) throws IOException { // ENTRIES WriteProcedure writeProcedure = new WriteProcedure(out); if (!order.forEach(writeProcedure)) throw writeProcedure.getIoException(); }
/** Remove the permissions around a vertex for the desired mode. Returns the number of edges affected */ public void removePermissionsAroundVertex (int vertex) { for (TIntList edgeList : new TIntList[] { streets.outgoingEdges.get(vertex), streets.incomingEdges.get(vertex) }) { edgeList.forEach(eidx -> { edgeCursor.seek(eidx); switch (mode) { case CAR: edgeCursor.clearFlag(EdgeStore.EdgeFlag.ALLOWS_CAR); break; case BICYCLE: edgeCursor.clearFlag(EdgeStore.EdgeFlag.ALLOWS_BIKE); break; case WALK: edgeCursor.clearFlag(EdgeStore.EdgeFlag.ALLOWS_PEDESTRIAN); break; default: throw new IllegalArgumentException(String.format("Unsupported mode %s for island removal", mode)); } return true; // continue iteration }); } } }
/** Remove the permissions around a vertex for the desired mode. Returns the number of edges affected */ public void removePermissionsAroundVertex (int vertex) { for (TIntList edgeList : new TIntList[] { streets.outgoingEdges.get(vertex), streets.incomingEdges.get(vertex) }) { edgeList.forEach(eidx -> { edgeCursor.seek(eidx); switch (mode) { case CAR: edgeCursor.clearFlag(EdgeStore.EdgeFlag.ALLOWS_CAR); break; case BICYCLE: edgeCursor.clearFlag(EdgeStore.EdgeFlag.ALLOWS_BIKE); break; case WALK: edgeCursor.clearFlag(EdgeStore.EdgeFlag.ALLOWS_PEDESTRIAN); break; default: throw new IllegalArgumentException(String.format("Unsupported mode %s for island removal", mode)); } return true; // continue iteration }); } } }
/** Loop over every outgoing edge for a particular mode */ public void forEachOutgoingEdge (int vertex, Consumer<EdgeStore.Edge> consumer) { streets.outgoingEdges.get(vertex).forEach(eidx -> { edgeCursor.seek(eidx); // filter by mode switch (mode) { case WALK: if (!edgeCursor.getFlag(EdgeStore.EdgeFlag.ALLOWS_PEDESTRIAN)) return true; else break; case CAR: if (!edgeCursor.getFlag(EdgeStore.EdgeFlag.ALLOWS_CAR)) return true; else break; case BICYCLE: // include ped mode here, because walking bikes is a thing you can do. boolean allowsBike = edgeCursor.getFlag(EdgeStore.EdgeFlag.ALLOWS_BIKE) || edgeCursor.getFlag(EdgeStore.EdgeFlag.ALLOWS_PEDESTRIAN); if (!allowsBike) return true; else break; default: throw new IllegalArgumentException(String.format("Unsupported mode %s for island removal", mode)); } consumer.accept(edgeCursor); return true; // continue iteration over outgoing edges }); }
/** Loop over every outgoing edge for a particular mode */ public void forEachOutgoingEdge (int vertex, Consumer<EdgeStore.Edge> consumer) { streets.outgoingEdges.get(vertex).forEach(eidx -> { edgeCursor.seek(eidx); // filter by mode switch (mode) { case WALK: if (!edgeCursor.getFlag(EdgeStore.EdgeFlag.ALLOWS_PEDESTRIAN)) return true; else break; case CAR: if (!edgeCursor.getFlag(EdgeStore.EdgeFlag.ALLOWS_CAR)) return true; else break; case BICYCLE: // include ped mode here, because walking bikes is a thing you can do. boolean allowsBike = edgeCursor.getFlag(EdgeStore.EdgeFlag.ALLOWS_BIKE) || edgeCursor.getFlag(EdgeStore.EdgeFlag.ALLOWS_PEDESTRIAN); if (!allowsBike) return true; else break; default: throw new IllegalArgumentException(String.format("Unsupported mode %s for island removal", mode)); } consumer.accept(edgeCursor); return true; // continue iteration over outgoing edges }); }
transitLayer.patternsForStop.get(stopIdx).forEach(p -> { patternidx[0] = p; return false;
transitLayer.patternsForStop.get(stopIdx).forEach(p -> { patternidx[0] = p; return false;
streetLayer.outgoingEdges.get(fromEdgeToVertex).forEach(eidx -> { if (eidx == next[0]) { return true;
/** * Filter down a map from target stop indexes to distances so it only includes those stops that are the * closest on some pattern. This is technically incorrect (think of transfers to a U shaped metro from a bus line * running across the legs of the U, a situation which actually exists in Washington, DC with the * red line and the Q4) but anecdotally it speeds up computation by up to 40 percent. We may want to look into * other ways to optimize transfers (or why the transfers are making routing so much slower) if this turns out to * affect results. */ private void retainClosestStopsOnPatterns(TIntIntMap timesToReachedStops) { TIntIntMap bestStopOnPattern = new TIntIntHashMap(50, 0.5f, -1, -1); // For every reached stop, timesToReachedStops.forEachEntry((stopIndex, distanceToStop) -> { // For every pattern passing through that stop, transitLayer.patternsForStop.get(stopIndex).forEach(patternIndex -> { int currentBestStop = bestStopOnPattern.get(patternIndex); // Record this stop if it's the closest one yet seen on that pattern. if (currentBestStop == -1) { bestStopOnPattern.put(patternIndex, stopIndex); } else { int currentBestTime = timesToReachedStops.get(currentBestStop); if (currentBestTime > distanceToStop) { bestStopOnPattern.put(patternIndex, stopIndex); } } return true; // iteration should continue }); return true; // iteration should continue }); timesToReachedStops.retainEntries((stop, distance) -> bestStopOnPattern.containsValue(stop)); }
/** * Filter down a map from target stop indexes to distances so it only includes those stops that are the * closest on some pattern. This is technically incorrect (think of transfers to a U shaped metro from a bus line * running across the legs of the U, a situation which actually exists in Washington, DC with the * red line and the Q4) but anecdotally it speeds up computation by up to 40 percent. We may want to look into * other ways to optimize transfers (or why the transfers are making routing so much slower) if this turns out to * affect results. */ private void retainClosestStopsOnPatterns(TIntIntMap timesToReachedStops) { TIntIntMap bestStopOnPattern = new TIntIntHashMap(50, 0.5f, -1, -1); // For every reached stop, timesToReachedStops.forEachEntry((stopIndex, distanceToStop) -> { // For every pattern passing through that stop, transitLayer.patternsForStop.get(stopIndex).forEach(patternIndex -> { int currentBestStop = bestStopOnPattern.get(patternIndex); // Record this stop if it's the closest one yet seen on that pattern. if (currentBestStop == -1) { bestStopOnPattern.put(patternIndex, stopIndex); } else { int currentBestTime = timesToReachedStops.get(currentBestStop); if (currentBestTime > distanceToStop) { bestStopOnPattern.put(patternIndex, stopIndex); } } return true; // iteration should continue }); return true; // iteration should continue }); timesToReachedStops.retainEntries((stop, distance) -> bestStopOnPattern.containsValue(stop)); }