@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());
   }
 }
 @Override
 public void handleEvent(PersonDepartureEvent event) {
   try {
     if (transitDriverIds.contains(event.getPersonId())) return;
     TravellerChain chain = chains.get(event.getPersonId());
     Journey journey;
     Trip trip;
     switch (event.getLegMode()) {
       case TransportMode.walk:
         // fall through to the next
       case TransportMode.transit_walk:
         if (!chain.traveling) {
           chain.traveling = true;
           journey = chain.addJourney();
           journey.setOrig(network.getLinks().get(event.getLinkId()).getCoord());
           journey.setFromAct(chain.getActs().getLast());
           journey.setStartTime(event.getTime());
           Walk walk = journey.addWalk();
           walk.setAccessWalk(true);
           walk.setStartTime(event.getTime());
           walk.setOrig(journey.getOrig());
         } else {
           journey = chain.getJourneys().getLast();
           Walk walk = journey.addWalk();
           walk.setStartTime(event.getTime());
           walk.setOrig(network.getLinks().get(event.getLinkId()).getCoord());
           journey.getPossibleTransfer().getWalks().add(walk);
         }
         break;
       case TransportMode.car:
         chain.inCar = true;
         journey = chain.addJourney();
         journey.setCarJourney(true);
         journey.setOrig(network.getLinks().get(event.getLinkId()).getCoord());
         journey.setFromAct(chain.getActs().getLast());
         journey.setStartTime(event.getTime());
         trip = journey.addTrip();
         trip.setMode("car");
         trip.setStartTime(event.getTime());
         break;
       case TransportMode.pt:
         if (isTransitScenario) {
           // person waits till they enter the vehicle
           journey = chain.getJourneys().getLast();
           Wait wait = journey.addWait();
           if (journey.getWaits().size() == 1) wait.setAccessWait(true);
           wait.setStartTime(event.getTime());
           wait.setCoord(network.getLinks().get(event.getLinkId()).getCoord());
           if (!wait.isAccessWait()) {
             journey.getPossibleTransfer().getWaits().add(wait);
           }
         } else {
           journey = chain.addJourney();
           journey.setTeleportJourney(true);
           journey.setOrig(network.getLinks().get(event.getLinkId()).getCoord());
           journey.setFromAct(chain.getActs().getLast());
           journey.setStartTime(event.getTime());
           journey.setMainmode(event.getLegMode());
           trip = journey.addTrip();
           trip.setMode(event.getLegMode());
           trip.setStartTime(event.getTime());
         }
         break;
       default:
         journey = chain.addJourney();
         journey.setTeleportJourney(true);
         journey.setOrig(network.getLinks().get(event.getLinkId()).getCoord());
         journey.setFromAct(chain.getActs().getLast());
         journey.setStartTime(event.getTime());
         journey.setMainmode(event.getLegMode());
         trip = journey.addTrip();
         trip.setMode(event.getLegMode());
         trip.setStartTime(event.getTime());
         break;
     }
   } catch (Exception e) {
     System.err.println(e.getStackTrace());
     System.err.println(event.toString());
   }
 }