@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."); } } }