Example #1
0
  public void handleEvent(PersonEntersVehicleEvent event) {
    Id perId = event.getPersonId();
    double enterVehTime /* [s] */ = event.getTime();
    Id vehId = event.getVehicleId();

    List<Tuple<Double, Integer>> enterVehTimeList = enterVehTimes.get(vehId);
    if (enterVehTimeList == null) enterVehTimeList = new ArrayList<Tuple<Double, Integer>>();

    try {
      double arrTimeAtStop = departures.remove(perId) /*
															 * departureTime/arrivalTimeAtBusStop
															 */;

      int timeBin = (int) arrTimeAtStop / this.binSize;
      enterVehTimeList.add(new Tuple<Double, Integer>(enterVehTime, timeBin));
      enterVehTimes.put(vehId, enterVehTimeList);

      double waitTimeOutOfBus = enterVehTime - arrTimeAtStop;

      // vehIdTimeBins.put(vehId, timeBin);

      // Double wtobSum = wtobSums.get(timeBin);
      // if (wtobSum == null)
      // wtobSum = 0.0;
      // wtobSums.put(timeBin, waitTimeOutOfBus + wtobSum);

      Map<Integer, Double> tmpWtobSums = WtobSumsOfVeh.get(vehId);
      if (tmpWtobSums == null) tmpWtobSums = new TreeMap<Integer, Double>();
      Double tmpWtobSum = tmpWtobSums.get(timeBin);
      if (tmpWtobSum == null) tmpWtobSum = 0.0;
      tmpWtobSums.put(timeBin, waitTimeOutOfBus + tmpWtobSum);
      WtobSumsOfVeh.put(vehId, tmpWtobSums);

      // Integer wtobCount = wtobCounts.get(timeBin);
      // if (wtobCount == null)
      // wtobCount = 0;
      // wtobCounts.put(timeBin, ++wtobCount);

      Map<Integer, Integer> tmpWtobCounts = WtobCountsOfVeh.get(vehId);
      if (tmpWtobCounts == null) tmpWtobCounts = new TreeMap<Integer, Integer>();
      Integer tmpWtobCount = tmpWtobCounts.get(timeBin);
      if (tmpWtobCount == null) tmpWtobCount = 0;
      tmpWtobCounts.put(timeBin, ++tmpWtobCount);
      WtobCountsOfVeh.put(vehId, tmpWtobCounts);

      // System.out.println(">>>>>wtobCounts put\ttimeBin\t" + timeBin
      // + "\twtobCount\t" + wtobCount);

    } catch (NullPointerException npe) {
      System.err.println(
          "WARN:\tthere is not the departure time record of agent:\t"
              + perId
              + "\twith event\t"
              + event.toString());
    }
  }
 @Override
 public void handleEvent(PersonEntersVehicleEvent event) {
   try {
     if (transitDriverIds.contains(event.getPersonId())) return;
     if (ptVehicles.keySet().contains(event.getVehicleId())) {
       TravellerChain chain = chains.get(event.getPersonId());
       Journey journey = chain.getJourneys().getLast();
       // first, handle the end of the wait
       journey.getWaits().getLast().setEndTime(event.getTime());
       // now, create a new trip
       ptVehicles.get(event.getVehicleId()).addPassenger(event.getPersonId());
       Trip trip = journey.addTrip();
       PTVehicle vehicle = ptVehicles.get(event.getVehicleId());
       trip.setLine(vehicle.transitLineId);
       trip.setMode(
           transitSchedule
               .getTransitLines()
               .get(vehicle.transitLineId)
               .getRoutes()
               .get(vehicle.transitRouteId)
               .getTransportMode());
       trip.setBoardingStop(vehicle.lastStop);
       trip.setOrig(journey.getWaits().getLast().getCoord());
       trip.setRoute(ptVehicles.get(event.getVehicleId()).transitRouteId);
       trip.setStartTime(event.getTime());
       // check for the end of a transfer
       if (journey.getPossibleTransfer() != null) {
         journey.getPossibleTransfer().setToTrip(trip);
         journey.getPossibleTransfer().setEndTime(event.getTime());
         journey.addTransfer(journey.getPossibleTransfer());
         journey.setPossibleTransfer(null);
       }
     } else {
       // add the person to the map that keeps track of who drives what
       // vehicle
       driverIdFromVehicleId.put(event.getVehicleId(), event.getPersonId());
     }
   } catch (Exception e) {
     System.err.println(e.getStackTrace());
     System.err.println(event.toString());
   }
 }