org.matsim.core.utils.collections.Tuple类的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(9.8k)|赞(0)|评价(0)|浏览(122)

本文整理了Java中org.matsim.core.utils.collections.Tuple类的一些代码示例,展示了Tuple类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Tuple类的具体详情如下:
包路径:org.matsim.core.utils.collections.Tuple
类名称:Tuple

Tuple介绍

[英]A Tuple stores two values (a "pair") and respects their order. This generic class implements a commonly used data structure which is not present in the current collection framework. Although it could be simulated with a List containing two Objects, this implementation offers type safety and maximizes convenience for programmers.
[中]元组存储两个值(一个“对”),并尊重它们的顺序。这个泛型类实现了当前集合框架中不存在的常用数据结构。虽然可以用一个包含两个对象的列表来模拟它,但这种实现为程序员提供了类型安全性和最大限度的便利。

代码示例

代码示例来源:origin: matsim-org/matsim

/**
 * @param coord
 * @return
 */
private Tuple<Integer, Integer>[] getZoneTuplesForLinks(Coord coord) {
  Tuple<Integer, Integer> zoneTuple = getZoneTupleForLinks(coord);
  int x = zoneTuple.getFirst();
  int y = zoneTuple.getSecond();
  return new Tuple[] {
      zoneTuple,
      new Tuple<Integer, Integer>(x-1, y-1),
      new Tuple<Integer, Integer>(x, y-1),
      new Tuple<Integer, Integer>(x+1, y-1),
      new Tuple<Integer, Integer>(x-1, y),
      new Tuple<Integer, Integer>(x+1, y),
      new Tuple<Integer, Integer>(x-1, y+1),
      new Tuple<Integer, Integer>(x, y+1),
      new Tuple<Integer, Integer>(x+1, y+1)
  };
}

代码示例来源:origin: matsim-org/matsim

@Override
  public int compare(Tuple<String, Double> o1, Tuple<String, Double> o2) {
    double result = o1.getSecond() - o2.getSecond();
    if (result == 0) {
      if (o1.getFirst().equals(o2.getFirst()))
        return 0;
      else
        return o1.hashCode() - o2.hashCode();
    } else if (result < 0)
      return 1;
    else
      return -1;
  }
});

代码示例来源:origin: matsim-org/matsim

public void writeData() {
  for (List<Tuple<Id, Double>> list : this.positions.values()) {
    for (Tuple<Id, Double> info : list) {
      System.out.println(info.getFirst().toString() + "\t" + info.getSecond().toString());
    }
    System.out.println();
  }
}

代码示例来源:origin: matsim-org/matsim

/**
 * Convenience method to create XML Attributes written by startTag()
 */
protected static Tuple<String, String> createTuple(String one, String two){
  return new Tuple<>(one, two);
}
/**

代码示例来源:origin: matsim-org/matsim

/**
 * Scales a vector given by start and end point by a factor. Changes only the start coordinate of the vector.
 * @param scaleFactor a scale factor in [0..1]
 * @return a tuple with the scaled start point as first and the old end point as
 *         second entry
 * @deprecated not used yet
 */
@Deprecated
public static Tuple<Point2D.Double, Point2D.Double> scaleVectorStart(final Point2D.Double start, final Point2D.Double end,
    double scaleFactor) {
  
  Tuple<Point2D.Double, Point2D.Double> scaledVector = calculateScaledVector(start, end, scaleFactor);
  return new Tuple<Point2D.Double, Point2D.Double>(scaledVector.getFirst(), end);
}

代码示例来源:origin: matsim-org/matsim

/**
 * Scales a vector given by start and end point by a factor. Changes only the end coordinate of the vector.
 * @param scaleFactor a scale factor in [0..1]
 * @return a tuple with the old start point as first and the scaled end point as
 *         second entry
 * @deprecated not used yet
 */
@Deprecated
public static Tuple<Point2D.Double, Point2D.Double> scaleVectorEnd(final Point2D.Double start, final Point2D.Double end,
    double scaleFactor) {
  
  Tuple<Point2D.Double, Point2D.Double> scaledVector = calculateScaledVector(start, end, scaleFactor);
  return new Tuple<Point2D.Double, Point2D.Double>(start, scaledVector.getSecond());
}

代码示例来源:origin: matsim-org/matsim

private DataContainer getLinkToLinkTravelTimeData(Tuple<Id<Link>, Id<Link>> fromLinkToLink, final boolean createIfMissing) {
  DataContainer data = this.linkToLinkData.get(fromLinkToLink);
  if ((null == data) && createIfMissing) {
    data = new DataContainer(this.ttDataFactory.createTravelTimeData(fromLinkToLink.getFirst()));
    this.linkToLinkData.put(fromLinkToLink, data);
  }
  return data;
}

代码示例来源:origin: matsim-org/matsim

private HbefaWarmEmissionFactor getEf(Id<Vehicle> vehicleId, Tuple<HbefaVehicleCategory, HbefaVehicleAttributes> vehicleInformationTuple, HbefaWarmEmissionFactorKey efkey) {
  HbefaWarmEmissionFactor ef;
  //The logic has changed here, now it will fall back to aggregate factors per traffic scenario, instead of if any scenarios are missing.
  if(this.detailedHbefaWarmTable != null && this.detailedHbefaWarmTable.get(efkey) != null){
    ef = this.detailedHbefaWarmTable.get(efkey);
  } else {
    vehAttributesNotSpecifiedCnt++;
    efkey.setHbefaVehicleAttributes(new HbefaVehicleAttributes()); //want to check for average vehicle
    ef = this.avgHbefaWarmTable.get(efkey);
    int maxWarnCnt = 3;
    if(this.detailedHbefaWarmTable != null && vehAttributesNotSpecifiedCnt <= maxWarnCnt) {
      logger.warn("Detailed vehicle attributes are not specified correctly for vehicle " + vehicleId + ": " +
          "`" + vehicleInformationTuple.getSecond() + "'. Using fleet average values instead.");
      if(vehAttributesNotSpecifiedCnt == maxWarnCnt) logger.warn(Gbl.FUTURE_SUPPRESSED);
    }
  }
  return ef;
}

代码示例来源:origin: matsim-org/matsim

public void testHashCode_withNull() {
    Integer i1 = Integer.valueOf(1);
    Integer i2 = Integer.valueOf(2);
    Tuple<Integer, Integer> tuple = new Tuple<Integer, Integer>(i1, i2);
    assertEquals(3, tuple.hashCode());
    tuple = new Tuple<Integer, Integer>(null, i2);
    assertEquals(2, tuple.hashCode());
    tuple = new Tuple<Integer, Integer>(i1, null);
    assertEquals(1, tuple.hashCode());
    tuple = new Tuple<Integer, Integer>(null, null);
    assertEquals(0, tuple.hashCode());
  }
}

代码示例来源:origin: matsim-org/matsim

@Deprecated //not tested
private int getNumberOfCarsAtDistancePerSecond(Id<Link> linkId, Double distanceMeter, double timeSeconds){
  Tuple<Double, Double> tuple = this.linkFirstSecondDistanceMeterMap.get(linkId);
  int numberOfCarsFirstDetector = this.getNumberOfCarsInDistance(linkId, tuple.getFirst(), timeSeconds);
  int numberOfCarsSecondDetector = this.getNumberOfCarsInDistance(linkId, tuple.getSecond(), timeSeconds);
  log.error("Link " + linkId + " first pos: " + tuple.getFirst() + " second pos: " + tuple.getSecond());
  log.error("NumberOfCars SecondDetector: " + numberOfCarsSecondDetector + " first detector: " + numberOfCarsFirstDetector);
  return numberOfCarsFirstDetector - numberOfCarsSecondDetector  ;
}

代码示例来源:origin: matsim-org/matsim

private Tuple<Double, Double> getTimeOfOperationFromTimeSlots(int startSlot, int endSlot){
    // convert slots to time
    double startTime = ((double) startSlot) * this.timeBinSize;
    double endTime = ((double) endSlot + 1) * this.timeBinSize;
    
    return new Tuple<>(startTime, endTime);
  }
}

代码示例来源:origin: matsim-org/matsim

for (int i = 0; i < map.size(); i++) {
  it.advance();
  list.add(new Tuple<>(it.key(), it.value()));
  keys[i] = list.get(i).getFirst();

代码示例来源:origin: matsim-org/matsim

return errorValue(stopOId, stopDId);
} else {
  return floorEntry.getValue().getFirst();
  return ceilingEntry.getValue().getFirst();
} else {
  double y1 = floorEntry.getValue().getFirst();
  double y2 = ceilingEntry.getValue().getFirst();
  double m = (y2 - y1) / (x2 - x1);
  double x = time - x1;

代码示例来源:origin: matsim-org/matsim

return 0;
} else {
  return floorEntry.getValue().getSecond();
  return ceilingEntry.getValue().getSecond();
} else {
  double y1 = floorEntry.getValue().getSecond();
  double y2 = ceilingEntry.getValue().getSecond();
  double m = (y2 - y1) / (x2 - x1);
  double x = time - x1;

代码示例来源:origin: matsim-org/matsim

public Tuple<QuadTree<ActivityFacilityWithIndex>, ActivityFacilityImpl[]> getQuadTreeAndFacilities(String activityType) {
  if (this.cacheQuadTrees) {
    QuadTree<ActivityFacilityWithIndex> quadTree = this.quadTreesOfType.get(activityType);
    ActivityFacilityImpl[] facilities = this.facilitiesOfType.get(activityType);
    if (quadTree == null || facilities == null) {				
      Tuple<QuadTree<ActivityFacilityWithIndex>, ActivityFacilityImpl[]> tuple = getTuple(activityType);
      this.quadTreesOfType.put(activityType, tuple.getFirst());
      this.facilitiesOfType.put(activityType, tuple.getSecond());
      
      return tuple;
    } else return new Tuple<QuadTree<ActivityFacilityWithIndex>, ActivityFacilityImpl[]>(quadTree, facilities);
  } else return getTuple(activityType);
}

代码示例来源:origin: matsim-org/matsim

@Override
  public int compare(final Tuple<Double, MobsimAgent> o1, final Tuple<Double, MobsimAgent> o2) {
    int ret = o1.getFirst().compareTo(o2.getFirst()); // first compare time information
    if (ret == 0) {
      ret = o2.getSecond().getId().compareTo(o1.getSecond().getId()); // if they're equal, compare the Ids: the one with the larger Id should be first
    }
    return ret;
  }
}

代码示例来源:origin: matsim-org/matsim

public void addActivityCombination(DistributionClass distributionClass, String fromActivity,
    String toActivity) {
  distributionClass.activityTypesFromTo.add(new Tuple<String, String>(fromActivity, toActivity));
}

代码示例来源:origin: matsim-org/matsim

ActivityFacility activityFacility = tuple.getFirst();
double y = activityFacility.getCoord().getY();
if (!yValues.contains(y)) {
List<Double> xValues = new LinkedList<>();
for (Tuple<ActivityFacility, Double> tuple : accessibilitiesMap.keySet()) {
  ActivityFacility activityFacility = tuple.getFirst();
  double y = activityFacility.getCoord().getY();
  if (y == yGiven) {
for (double x : coordMap.get(y)) {
  for (Tuple<ActivityFacility, Double> tuple : accessibilitiesMap.keySet()) {
    Coord coord = tuple.getFirst().getCoord();
    if (coord.getX() == x && coord.getY() == y) {
      accessibilitiesMap2.put(tuple, accessibilitiesMap.get(tuple));

代码示例来源:origin: matsim-org/matsim

@Override
public void afterSim() {
  double now = internalInterface.getMobsim().getSimTimer().getTimeOfDay();
  for (Tuple<Double, MobsimAgent> entry : teleportationList) {
    MobsimAgent agent = entry.getSecond();
    eventsManager.processEvent(new PersonStuckEvent(now, agent.getId(), agent.getDestinationLinkId(), agent.getMode()));
  }
  teleportationList.clear();
}

代码示例来源:origin: matsim-org/matsim

@Override
public void handleEvent(VehicleArrivesAtFacilityEvent event) {
  if(vehicleIds.contains(event.getVehicleId())) {
    Tuple<Id<TransitStopFacility>, Double> route = inTransitVehicles.remove(event.getVehicleId());
    if(route!=null)
      stopStopTimes.get(new Tuple<Id<TransitStopFacility>, Id<TransitStopFacility>>(route.getFirst(), event.getFacilityId())).addStopStopTime((int) (route.getSecond()/timeSlot), event.getTime()-route.getSecond());
    inTransitVehicles.put(event.getVehicleId(), new Tuple<Id<TransitStopFacility>, Double>(event.getFacilityId(), event.getTime()));
  }
}
@Override

相关文章

微信公众号

最新文章

更多