@Override
 public void handleEvent(ActivityStartEvent event) {
   TravellerChain chain = chains.get(event.getPersonId());
   if (!event.getActType().equals(PtConstants.TRANSIT_ACTIVITY_TYPE)) {
     if (chain == null) {
       chain = new TravellerChain();
       chains.put(event.getPersonId(), chain);
       chain.distances.add(0.0);
       chain.modes.add("walk");
     }
     chains.get(event.getPersonId()).in = false;
     acts.put(
         event.getPersonId(),
         acts.get(event.getPersonId()) == null ? 1 : acts.get(event.getPersonId()) + 1);
   }
   if (chain.modes.get(chain.modes.size() - 1).equals("walk")) {
     Double distance =
         CoordUtils.calcDistance(
             locations.get(event.getPersonId()),
             network.getLinks().get(event.getLinkId()).getCoord());
     if (chain.modes.size() == chain.distances.size()) {
       if (event.getActType().equals(PtConstants.TRANSIT_ACTIVITY_TYPE))
         chain.modes.set(chain.modes.size() - 1, "pt");
       chain.distances.set(chain.distances.size() - 1, distance);
     } else {
       chain.modes.remove(chain.modes.size() - 1);
       chain.distances.set(
           chain.distances.size() - 1, chain.distances.get(chain.distances.size() - 1) + distance);
     }
   }
 }
Esempio n. 2
0
 @Override
 public void handleEvent(ActivityStartEvent event) {
   if (!eventsByPerson.containsKey(event.getPersonId())) {
     eventsByPerson.put(event.getPersonId(), new LinkedList<Event>());
   }
   eventsByPerson.get(event.getPersonId()).add(event);
   allEvents.add(event);
 }
Esempio n. 3
0
 @Override
 public void handleEvent(ActivityStartEvent event) {
   List<String> activityChain = activityChains.get(event.getPersonId());
   if (activityChain == null) {
     activityChain = new ArrayList<String>();
     activityChains.put(event.getPersonId(), activityChain);
   }
   activityChain.add("@" + event.getActType());
 }
  @Override
  public void handleEvent(ActivityStartEvent event) {
    try {
      if (isTransitScenario) {
        if (transitDriverIds.contains(event.getPersonId())) return;
      }
      TravellerChain chain = chains.get(event.getPersonId());
      boolean beforeInPT = chain.isInPT();
      if (event.getActType().equals(PtConstants.TRANSIT_ACTIVITY_TYPE)) {
        chain.setInPT(true);

      } else {
        chain.setInPT(false);
        chain.traveling = false;
        Activity act = chain.addActivity();
        act.setCoord(network.getLinks().get(event.getLinkId()).getCoord());
        act.setFacility(event.getFacilityId());
        act.setStartTime(event.getTime());
        act.setType(event.getActType());
        // end the preceding journey
        Journey journey = chain.getJourneys().getLast();
        journey.setDest(act.getCoord());
        journey.setEndTime(event.getTime());
        journey.setToAct(act);
        if (beforeInPT) journey.getWalks().getLast().setEgressWalk(true);
      }
    } catch (Exception e) {
      System.err.println(e.getStackTrace());
      System.err.println(event.toString());
      ;
    }
  }
Esempio n. 5
0
  @Override
  public void handleEvent(ActivityStartEvent 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 starts for every agent and store these numbers in a map
    if (!activityStartCount.containsKey(personId)) {
      activityStartCount.put(personId, 1);
    } else {
      int numberOfCompletedDepartures = activityStartCount.get(personId);
      activityStartCount.put(personId, numberOfCompletedDepartures + 1);
    }
    // System.out.println("Agent " + personId + " has " + activityEndCount.get(personId) + "
    // activity ends and " + activityStartCount.get(personId) + " activity starts.");

    // add information to the object "Trip"
    Id<Trip> tripId = Id.create(personId + "_" + activityStartCount.get(personId), Trip.class);
    if (trips.get(tripId) != null) {
      trips.get(tripId).setArrivalLinkId(linkId);
      trips.get(tripId).setArrivalTime(time);
      // trips.get(tripId).setArrivalLegMode(legMode);
      trips.get(tripId).setActivityStartActType(actType);
      trips.get(tripId).setTripComplete(true);
    } else {
      this.noPreviousEndOfActivityCounter++;
    }

    // check if number of activity ends and number of activity starts are the same
    if (activityStartCount.get(personId) != activityEndCount.get(personId)) {
      // System.err.println("Activity start count differs from activity end count.");
      throw new RuntimeException("Activity start count differs from activity end count.");
    }

    // checking leg modes is not applicable here
  }
Esempio n. 6
0
 @Override
 public void handleEvent(ActivityStartEvent event) {
   if (pIdsToExclude.contains(event.getPersonId())) {
     return;
   }
   TravellerChain chain = chains.get(event.getPersonId());
   boolean beforeInPT = chain.inPT;
   if (event.getActType().equals(PtConstants.TRANSIT_ACTIVITY_TYPE)) chain.inPT = true;
   else chain.inPT = false;
   if (!chain.inPT && !chain.walk) chain.modes.add("car");
   else if (!chain.inPT && chain.walk && !beforeInPT) chain.modes.add("walk");
   else if (chain.walk) chain.modes.add("transit_walk");
   else
     chain.modes.add(
         getMode(
             transitSchedule
                 .getTransitLines()
                 .get(chain.lineId)
                 .getRoutes()
                 .get(chain.routeId)
                 .getTransportMode(),
             chain.lineId));
   chain.times.add(event.getTime() - chain.lastTime);
 }
 @Override
 public void handleEvent(ActivityStartEvent event) {
   CarrierAgent carrierAgent = getCarrierAgent(event.getPersonId());
   if (carrierAgent == null) return;
   carrierAgent.handleEvent(event);
 }
 @Override
 public void handleEvent(final ActivityStartEvent event) {
   starts.put(event.getPersonId(), event.getTime());
 }
Esempio n. 9
0
 @Override
 public void handleEvent(ActivityStartEvent event) {
   startTimes.put(
       event.getPersonId(), new Tuple<String, Double>(event.getActType(), event.getTime()));
 }
 @Override
 public void handleEvent(ActivityStartEvent event) {
   if (event.getPersonId().equals(filterEventsForAgentId)) {
     System.out.println(event.toString());
   }
 }