@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());
    }
  }
예제 #2
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.");
      }
    }
  }
 @Override
 public void handleEvent(ActivityEndEvent event) {
   if (!event.getPersonId().toString().startsWith("pt_tr"))
     locations.put(event.getPersonId(), network.getLinks().get(event.getLinkId()).getCoord());
 }