Пример #1
0
 @Override
 public void handleEvent(ActivityEndEvent event) {
   if (!eventsByPerson.containsKey(event.getPersonId())) {
     eventsByPerson.put(event.getPersonId(), new LinkedList<Event>());
   }
   eventsByPerson.get(event.getPersonId()).add(event);
   allEvents.add(event);
 }
Пример #2
0
    @Override
    public void handleEvent(final ActivityEndEvent event) {
      final Double start = starts.remove(event.getPersonId());
      // first act has no start time
      if (start == null) return;

      try {
        writer.newLine();
        writer.write(
            event.getPersonId() + "\t" + event.getActType() + "\t" + (event.getTime() - start));
      } catch (final IOException e) {
        throw new UncheckedIOException(e);
      }
    }
Пример #3
0
 @Override
 public void handleEvent(ActivityEndEvent event) {
   Tuple<String, Double> startTime = startTimes.get(event.getPersonId());
   startTimes.put(event.getPersonId(), null);
   if (startTime == null) startTime = new Tuple<String, Double>(event.getActType(), 0.0);
   double duration = event.getTime() - startTime.getSecond();
   SortedMap<Double, Integer> typeMap = durations.get(event.getActType());
   if (typeMap == null) {
     typeMap = new TreeMap<Double, Integer>();
     for (double t = timeBin; t < totalTime + timeBin - 1; t += timeBin) typeMap.put(t, 0);
     durations.put(event.getActType(), typeMap);
   }
   typeMap.put(getTimeBin(duration), typeMap.get(getTimeBin(duration)) + 1);
   typeMap = peoplePerforming.get(event.getActType());
   if (typeMap == null) {
     typeMap = new TreeMap<Double, Integer>();
     for (double t = timeBin; t < totalTime + timeBin - 1; t += timeBin) typeMap.put(t, 0);
     peoplePerforming.put(event.getActType(), typeMap);
   }
   Double lastTimeBin = getTimeBin(event.getTime());
   for (double t = getTimeBin(startTime.getSecond()); t <= lastTimeBin; t += timeBin)
     typeMap.put(t, typeMap.get(t) + 1);
 }
Пример #4
0
 @Override
 public void handleEvent(ActivityEndEvent event) {
   List<String> activityChain = activityChains.get(event.getPersonId());
   if (activityChain != null || event.getActType().equals("home"))
     if (activityChain == null) {
       activityChain = new ArrayList<String>();
       activityChain.add(
           "@" + event.getActType() + "(" + numberFormat.format(event.getTime() / 3600) + ")");
       activityChains.put(event.getPersonId(), activityChain);
     } else {
       String lastActivity = activityChain.get(activityChain.size() - 1);
       if (lastActivity.contains(event.getActType())
           && lastActivity.length() == event.getActType().length() + 1)
         activityChain.set(
             activityChain.size() - 1,
             lastActivity + "(" + numberFormat.format(event.getTime() / 3600) + ")");
       else throw new RuntimeException("Activity end without beginning");
     }
   else throw new RuntimeException("Activity end without person");
 }
  @Override
  public void handleEvent(ActivityEndEvent event) {
    try {
      if (isTransitScenario) {
        if (transitDriverIds.contains(event.getPersonId())) return;
      }
      TravellerChain chain = chains.get(event.getPersonId());
      locations.put(event.getPersonId(), network.getLinks().get(event.getLinkId()).getCoord());
      if (chain == null) {
        chain = new TravellerChain();
        chains.put(event.getPersonId(), chain);
        Activity act = chain.addActivity();
        act.setCoord(network.getLinks().get(event.getLinkId()).getCoord());
        act.setEndTime(event.getTime());
        act.setFacility(event.getFacilityId());
        act.setStartTime(0.0);
        act.setType(event.getActType());

      } else if (!event.getActType().equals(PtConstants.TRANSIT_ACTIVITY_TYPE)) {
        Activity act = chain.getActs().getLast();
        act.setEndTime(event.getTime());
      }
    } catch (Exception e) {
      System.err.println(e.getStackTrace());
      System.err.println(event.toString());
    }
  }
Пример #6
0
  @Override
  public void handleEvent(ActivityEndEvent event) {
    // store information from event to variables and print the information on console
    // String eventType = event.getEventType();
    Id<Link> linkId = event.getLinkId();
    // String linkShortened = linkId.toString().substring(0, 10) + "...";
    Id<Person> personId = event.getPersonId();
    double time = event.getTime();
    String actType = event.getActType();
    // Id facilityId =	event.getFacilityId();
    // System.out.println("Type: " + eventType + " - LinkId: " + linkShortened + " - PersonId: " +
    // personId.toString()
    //		+ " - Time: " + time/60/60 + " - ActType: " + actType + " - FacilityId: " + facilityId);

    // count number of activity ends for every agent and store these numbers in a map
    if (!activityEndCount.containsKey(personId)) {
      activityEndCount.put(personId, 1);
    } else {
      int numberOfCompletedDepartures = activityEndCount.get(personId);
      activityEndCount.put(personId, numberOfCompletedDepartures + 1);
    }
    // System.out.println("Agent " + personId + " has " + activityEndCount.get(personId) + "
    // activity ends.");

    // create an instance of the object "Trip"
    Trip trip = new Trip();
    Id<Trip> tripId = Id.create(personId + "_" + activityEndCount.get(personId), Trip.class);
    trip.setTripId(tripId);
    trip.setPersonId(personId);
    trip.setDepartureLinkId(linkId);
    trip.setDepartureTime(time);
    // trip.setDepartureLegMode(legMode);
    trip.setActivityEndActType(actType);
    trips.put(tripId, trip);

    // check if activity end link is the same as previous activity start link
    if (activityEndCount.get(personId) >= 2) {
      int numberOfLastArrival = activityStartCount.get(personId);
      Id<Trip> lastTripId = Id.create(personId + "_" + numberOfLastArrival, Trip.class);
      if (!trips
          .get(tripId)
          .getDepartureLinkId()
          .equals(trips.get(lastTripId).getArrivalLinkId())) {
        // System.err.println("Activity end link differs from previous activity start link.");
        throw new RuntimeException("Activity end link differs from previous activity start link.");
      }
    }

    // check if type of ending activity is the same as type of previously started activity
    if (activityEndCount.get(personId) >= 2) {
      int numberOfLastArrival = activityStartCount.get(personId);
      Id<Trip> lastTripId = Id.create(personId + "_" + numberOfLastArrival, Trip.class);
      if (!trips
          .get(tripId)
          .getActivityEndActType()
          .equals(trips.get(lastTripId).getActivityStartActType())) {
        // System.err.println("Type of ending activity is not the same as type of previously started
        // activity.");
        throw new RuntimeException(
            "Type of ending activity is not the same as type of previously started activity.");
      }
    }
  }
Пример #7
0
 @Override
 public void handleEvent(ActivityEndEvent event) {
   CarrierAgent carrierAgent = getCarrierAgent(event.getPersonId());
   if (carrierAgent == null) return;
   carrierAgent.handleEvent(event);
 }
  @Override
  public void handleEvent(ActivityEndEvent event) {

    if (event.getActType().toString().equals("pt interaction")) {
      // pseudo activities are excluded

    } else {
      // a "real" activity is ended

      if (personId2currentTripNumber.containsKey(event.getPersonId())) {
        // the following trip is at least the person's second trip
        personId2currentTripNumber.put(
            event.getPersonId(), personId2currentTripNumber.get(event.getPersonId()) + 1);

        Map<Integer, Double> tripNumber2departureTime =
            personId2tripNumber2departureTime.get(event.getPersonId());
        tripNumber2departureTime.put(
            personId2currentTripNumber.get(event.getPersonId()), event.getTime());
        personId2tripNumber2departureTime.put(event.getPersonId(), tripNumber2departureTime);

        Map<Integer, Double> tripNumber2tripDistance =
            personId2tripNumber2tripDistance.get(event.getPersonId());
        tripNumber2tripDistance.put(personId2currentTripNumber.get(event.getPersonId()), 0.0);
        personId2tripNumber2tripDistance.put(event.getPersonId(), tripNumber2tripDistance);

        Map<Integer, Double> tripNumber2amount =
            personId2tripNumber2amount.get(event.getPersonId());
        tripNumber2amount.put(personId2currentTripNumber.get(event.getPersonId()), 0.0);
        personId2tripNumber2amount.put(event.getPersonId(), tripNumber2amount);

      } else {
        // the following trip is the person's first trip
        personId2currentTripNumber.put(event.getPersonId(), 1);

        Map<Integer, Double> tripNumber2departureTime = new HashMap<Integer, Double>();
        tripNumber2departureTime.put(1, event.getTime());
        personId2tripNumber2departureTime.put(event.getPersonId(), tripNumber2departureTime);

        Map<Integer, Double> tripNumber2tripDistance = new HashMap<Integer, Double>();
        tripNumber2tripDistance.put(1, 0.0);
        personId2tripNumber2tripDistance.put(event.getPersonId(), tripNumber2tripDistance);

        Map<Integer, Double> tripNumber2amount = new HashMap<Integer, Double>();
        tripNumber2amount.put(1, 0.0);
        personId2tripNumber2amount.put(event.getPersonId(), tripNumber2amount);
      }
    }
  }
 @Override
 public void handleEvent(ActivityEndEvent event) {
   if (event.getPersonId().equals(filterEventsForAgentId)) {
     System.out.println(event.toString());
   }
 }
 @Override
 public void handleEvent(ActivityEndEvent event) {
   if (!event.getPersonId().toString().startsWith("pt_tr"))
     locations.put(event.getPersonId(), network.getLinks().get(event.getLinkId()).getCoord());
 }