public static Leg getModifiableCurrentLeg(MobsimAgent agent) { PlanElement currentPlanElement = getCurrentPlanElement(agent); if (!(currentPlanElement instanceof Leg)) { return null; } return (Leg) currentPlanElement; }
private boolean doReplanning(MobsimAgent mobsimAgent, double time, Mobsim mobsim) { PlanAgent planAgent = (PlanAgent) mobsimAgent; Id<Person> agentId = planAgent.getCurrentPlan().getPerson().getId(); PlanElement currentPlanElement = WithinDayAgentUtils.getCurrentPlanElement(mobsimAgent); if (currentPlanElement instanceof Activity) { Activity act = (Activity) currentPlanElement; if (encounteredActivities.contains(act)) { return false; } CarrierDriverAgent driver = carrierAgentTracker.getDriver(agentId); TourActivity plannedActivity = (TourActivity) driver.getPlannedTourElement(WithinDayAgentUtils.getCurrentPlanElementIndex(mobsimAgent)); if (plannedActivity instanceof Start){ encounteredActivities.add(act); return false; } else { double newEndTime = Math.max(time, plannedActivity.getTimeWindow().getStart()) + plannedActivity.getDuration(); // logger.info("[agentId="+ agentId + "][currentTime="+Time.writeTime(time)+"][actDuration="+plannedActivity.getDuration()+ // "[timeWindow="+ plannedActivity.getTimeWindow() + "][plannedActEnd="+ Time.writeTime(act.getEndTime()) + "][newActEnd="+Time.writeTime(newEndTime)+"]"); act.setMaximumDuration(Time.UNDEFINED_TIME); act.setEndTime(newEndTime); // WithinDayAgentUtils.calculateAndSetDepartureTime(mobsimAgent, act); WithinDayAgentUtils.resetCaches( mobsimAgent ); WithinDayAgentUtils.rescheduleActivityEnd(mobsimAgent,mobsim); encounteredActivities.add(act); return true ; } } return true; } }
public boolean isAtRealActivity(MobsimAgent agent) { PlanElement pe = WithinDayAgentUtils.getCurrentPlanElement(agent) ; if ( isRealActivity(pe) ) { return true ; } else { return false ; } } public boolean isRealActivity(PlanElement pe) {
public static boolean isOnReplannableCarLeg(MobsimAgent agent) { // if (plan == null) { // log.info( " we don't have a modifiable plan; returning ... ") ; // return false; // } if ( !(getCurrentPlanElement(agent) instanceof Leg) ) { log.info( "agent not on leg; returning ... ") ; return false ; } if (!((Leg) getCurrentPlanElement(agent)).getMode().equals(TransportMode.car)) { log.info( "not a car leg; can only replan car legs; returning ... ") ; return false; } return true ; }
public final Trip findCurrentTrip( MobsimAgent agent ) { PlanElement pe = WithinDayAgentUtils.getCurrentPlanElement(agent) ; return findTripAtPlanElement(agent, pe); } public Trip findTripAtPlanElement(MobsimAgent agent, PlanElement pe) {
public final boolean replanCurrentTrip(MobsimAgent agent, double now, String routingMode ) { log.debug("entering replanCurrentTrip with routingMode=" + routingMode) ; // I will treat that in the way that it will make the trip consistent with the activities. So if the activity in the // plan has changed, the trip will go to a new location. // what matters is the external interface, which is the method call. Everything below is internal so it does not matter so much. Trip trip = findCurrentTrip( agent ) ; final PlanElement currentPlanElement = WithinDayAgentUtils.getCurrentPlanElement(agent) ; final List<PlanElement> tripElements = trip.getTripElements(); int tripElementsIndex = tripElements.indexOf( currentPlanElement ) ; // final String currentMode = tripRouter.getMainModeIdentifier().identifyMainMode( tripElements ) ; if ( currentPlanElement instanceof Activity ) { // we are on a stage activity. Take it from there: replanCurrentTripFromStageActivity(tripElements, tripElementsIndex, agent, routingMode); } else { // we are on a leg replanCurrentTripFromLeg(trip.getDestinationActivity(), currentPlanElement, routingMode, now, agent); } WithinDayAgentUtils.resetCaches(agent); return true ; } private void replanCurrentTripFromLeg(Activity newAct, final PlanElement currentPlanElement, final String routingMode,
public String getModeOfCurrentOrNextTrip(MobsimAgent agent) { Trip trip ; if ( isAtRealActivity( agent ) ) { Activity activity = (Activity) WithinDayAgentUtils.getCurrentPlanElement(agent) ; trip = editTrips.findTripAfterActivity(WithinDayAgentUtils.getModifiablePlan(agent), activity) ; } else { trip = editTrips.findCurrentTrip(agent) ; } return tripRouter.getMainModeIdentifier().identifyMainMode(trip.getTripElements()) ; } public void flushEverythingBeyondCurrent(MobsimAgent agent) {
@Override public boolean doReplanning(MobsimAgent withinDayAgent) { Plan executedPlan = WithinDayAgentUtils.getModifiablePlan(withinDayAgent); // If we don't have an executed plan if (executedPlan == null) return false; PlanElement currentPlanElement = WithinDayAgentUtils.getCurrentPlanElement(withinDayAgent); if (!(currentPlanElement instanceof Leg)) return false; Leg currentLeg = (Leg) currentPlanElement; int currentLinkIndex = WithinDayAgentUtils.getCurrentRouteLinkIdIndex(withinDayAgent); EditRoutes editRoutes = new EditRoutes( scenario.getNetwork(), pathCalculator, populationFactory ) ; editRoutes.replanCurrentLegRoute(currentLeg, executedPlan.getPerson(), currentLinkIndex, this.time ) ; // Finally reset the cached Values of the PersonAgent - they may have changed! WithinDayAgentUtils.resetCaches(withinDayAgent); return true; }
@Override public boolean doReplanning(MobsimAgent withinDayAgent) { Plan executedPlan = WithinDayAgentUtils.getModifiablePlan(withinDayAgent); // If we don't have an executed plan if (executedPlan == null) return false; // Get the activity currently performed by the agent as well as the subsequent trip. Activity currentActivity = (Activity) WithinDayAgentUtils.getCurrentPlanElement(withinDayAgent); Trip trip = TripStructureUtils.findTripStartingAtActivity(currentActivity, executedPlan, this.tripRouter.getStageActivityTypes() ); // If there is no trip after the activity. if (trip == null) return false; String mainMode = this.tripRouter.getMainModeIdentifier().identifyMainMode(trip.getTripElements()); double departureTime = TripStructureUtils.getDepartureTime(trip); new EditTrips(this.tripRouter, scenario).replanFutureTrip(trip, executedPlan, mainMode, departureTime); return true; }
Activity currentActivity = (Activity) WithinDayAgentUtils.getCurrentPlanElement(agent); currentActivity.setEndTime(e.getSimulationTime() + 60); WithinDayAgentUtils.resetCaches(agent);