コード例 #1
0
 /** {@inheritDoc} */
 public void putAll(TIntIntMap map) {
   ensureCapacity(map.size());
   TIntIntIterator iter = map.iterator();
   while (iter.hasNext()) {
     iter.advance();
     this.put(iter.key(), iter.value());
   }
 }
コード例 #2
0
ファイル: MyArrays.java プロジェクト: jilen/snlp
 /**
  * @param freqmap
  * @return
  */
 public static TreeMap<Integer, Integer> countFrequency(TIntIntHashMap freqmap) {
   TreeMap<Integer, Integer> map = new TreeMap<Integer, Integer>();
   TIntIntIterator it = freqmap.iterator();
   while (it.hasNext()) {
     it.advance();
     int freq = it.value();
     if (map.containsKey(freq)) {
       map.put(freq, map.get(freq) + 1);
     } else map.put(freq, 1);
   }
   return map;
 }
コード例 #3
0
  @Override
  public Set<org.getspout.spoutapi.material.Block> getModifiedBlocks() {
    // hit cache first
    if (cachedBlockData != null) {
      return cachedBlockData;
    }
    Set<org.getspout.spoutapi.material.Block> modified =
        new HashSet<org.getspout.spoutapi.material.Block>();
    TLongFloatIterator i = originalFriction.iterator();
    while (i.hasNext()) {
      i.advance();
      int id = TIntPairHashSet.longToKey1(i.key());
      int data = TIntPairHashSet.longToKey2(i.key());

      org.getspout.spoutapi.material.Block block = MaterialData.getBlock(id, (short) data);
      if (block != null) {
        modified.add(block);
      }
    }

    i = originalHardness.iterator();
    while (i.hasNext()) {
      i.advance();
      int id = TIntPairHashSet.longToKey1(i.key());
      int data = TIntPairHashSet.longToKey2(i.key());
      org.getspout.spoutapi.material.Block block = MaterialData.getBlock(id, (short) data);
      if (block != null) {
        modified.add(block);
      }
    }

    TIntIntIterator j = originalLight.iterator();
    while (j.hasNext()) {
      j.advance();
      org.getspout.spoutapi.material.Block block = MaterialData.getBlock(j.key());
      if (block != null) {
        modified.add(block);
      }
    }

    TIntByteIterator k = originalOpacity.iterator();
    while (k.hasNext()) {
      k.advance();
      org.getspout.spoutapi.material.Block block = MaterialData.getBlock(k.key());
      if (block != null) {
        modified.add(block);
      }
    }
    cachedBlockData = modified; // save to cache
    return modified;
  }
コード例 #4
0
  private double calcDotProduct(TIntIntHashMap entityVec, TIntIntHashMap contextVec) {
    int dotProduct = 0;

    for (TIntIntIterator it = entityVec.iterator(); it.hasNext(); ) {
      it.advance();
      int wordA = it.key();

      int expandedA = AidaManager.expandTerm(wordA);

      // get counts of word in both vectors
      int wordAcount = entityVec.get(wordA);
      int wordBcount = contextVec.get(wordA);

      wordBcount += contextVec.get(expandedA); // add expanded count if available

      int temp = wordAcount * wordBcount;
      dotProduct += temp;
    }

    return dotProduct;
  }
コード例 #5
0
ファイル: PointToPointQuery.java プロジェクト: conveyal/r5
  /**
   * Combine the results of several street searches using different modes into a single map It also
   * saves with which mode was stop reached into stopModeMap. This map is then used to create
   * itineraries in response
   */
  private TIntIntMap combineMultimodalRoutingAccessTimes(
      Map<LegMode, StreetRouter> routers,
      TIntObjectMap<LegMode> stopModeMap,
      ProfileRequest request) {
    // times at transit stops
    TIntIntMap times = new TIntIntHashMap();

    // weights at transit stops
    TIntIntMap weights = new TIntIntHashMap();

    for (Map.Entry<LegMode, StreetRouter> entry : routers.entrySet()) {
      int maxTime = 30;
      int minTime = 0;
      int penalty = 0;

      LegMode mode = entry.getKey();
      switch (mode) {
        case BICYCLE:
          maxTime = request.maxBikeTime;
          minTime = request.minBikeTime;
          penalty = BIKE_PENALTY;
          break;
        case BICYCLE_RENT:
          // TODO this is not strictly correct, bike rent is partly walking
          maxTime = request.maxBikeTime;
          minTime = request.minBikeTime;
          penalty = BIKESHARE_PENALTY;
          break;
        case WALK:
          maxTime = request.maxWalkTime;
          break;
        case CAR:
          // TODO this is not strictly correct, CAR PARK is partly walking
        case CAR_PARK:
          maxTime = request.maxCarTime;
          minTime = request.minCarTime;
          penalty = CAR_PENALTY;
          break;
      }

      maxTime *= 60; // convert to seconds
      minTime *= 60; // convert to seconds

      final int maxTimeFinal = maxTime;
      final int minTimeFinal = minTime;
      final int penaltyFinal = penalty;

      StreetRouter router = entry.getValue();
      router
          .getReachedStops()
          .forEachEntry(
              (stop, time) -> {
                if (time > maxTimeFinal || time < minTimeFinal) return true;
                // Skip stops that can't be used with wheelchairs if wheelchair routing is requested
                if (request.wheelchair
                    && !transportNetwork.transitLayer.stopsWheelchair.get(stop)) {
                  return true;
                }

                int weight = time + penaltyFinal;

                // There are penalties for using certain modes, to avoid bike/car trips that are
                // only marginally faster
                // than walking, so we use weights to decide which mode "wins" to access a
                // particular stop.
                if (!weights.containsKey(stop) || weight < weights.get(stop)) {
                  times.put(stop, time);
                  weights.put(stop, weight);
                  stopModeMap.put(stop, mode);
                }

                return true; // iteration should continue
              });
    }

    // we don't want to explore a boatload of access/egress stops. Pick only the closest several
    // hundred.
    // What this means is that in urban environments you'll get on the bus nearby, in suburban
    // environments
    // you may walk/bike/drive a very long way.
    // NB in testing it's not clear this actually does a lot for performance, maybe 1-1.5s
    int stopsFound = times.size();
    if (stopsFound > MAX_ACCESS_STOPS) {
      TIntList timeList = new TIntArrayList();
      times.forEachValue(timeList::add);

      timeList.sort();

      // This gets last time in timeList
      int cutoff =
          timeList.get(
              MAX_ACCESS_STOPS); // it needs to be same as MAX_ACCESS_STOPS since if there are
      // minimally MAX_ACCESS_STOPS + 1 stops the indexes are from
      // 0-MAX_ACCESS_STOPS

      for (TIntIntIterator it = times.iterator(); it.hasNext(); ) {
        it.advance();

        if (it.value() > cutoff) it.remove();
      }

      LOG.warn("{} stops found, using {} nearest", stopsFound, times.size());
    } else {

      LOG.info("{} stops found", stopsFound);
    }

    // return the times, not the weights
    return times;
  }