public boolean addActivityAtEnd(MobsimAgent agent, Activity activity, String routingMode) { log.debug("entering addActivityAtEnd with routingMode=" + routingMode) ; Plan plan = WithinDayAgentUtils.getModifiablePlan(agent); List<PlanElement> planElements = plan.getPlanElements(); boolean retVal1 = false; if (isAtRealActivity(agent)) { retVal1 = planElements.add(pf.createLeg(routingMode)); } final boolean retVal = planElements.add(activity); // (need the terminating activity in order to find the current trip. kai, nov'17) if (!isAtRealActivity(agent)) { retVal1 = editTrips.replanCurrentTrip(agent,mobsim.getSimTimer().getTimeOfDay(),routingMode); } WithinDayAgentUtils.resetCaches(agent); this.mobsim.rescheduleActivityEnd(agent); return (retVal1 && retVal); } public PlanElement removeActivity(MobsimAgent agent, int index, String mode) {
@Override public boolean handle(String agentID, String actionID, Object[] args) { // assertions: MobsimAgent mobsimAgent = model.getMobsimAgentFromIdString(agentID) ; Gbl.assertNotNull(mobsimAgent) ; Gbl.assertIf( args.length >= 1 ); Gbl.assertIf( args[0] instanceof MATSimModel.RoutingMode) ; // could have some default MATSimModel.RoutingMode routingMode = (MATSimModel.RoutingMode)args[0]; if (WithinDayAgentUtils.isOnReplannableCarLeg(mobsimAgent)) { model.getReplanner().editTrips().replanCurrentTrip(mobsimAgent, 0.0, routingMode.name()); } return true; } }
public PlanElement removeActivity(MobsimAgent agent, int index, String mode) { Plan plan = WithinDayAgentUtils.getModifiablePlan(agent) ; List<PlanElement> planElements = plan.getPlanElements() ; checkIfNotInPastOrCurrent(agent, index); final Trip tripBefore = TripStructureUtils.findTripEndingAtActivity( (Activity) planElements.get(index),plan,tripRouter.getStageActivityTypes() ); final Trip tripAfter = TripStructureUtils.findTripStartingAtActivity( (Activity)planElements.get(index),plan,tripRouter.getStageActivityTypes() ); if ( mode==null ) { final String mainModeBefore = tripRouter.getMainModeIdentifier().identifyMainMode( tripBefore.getTripElements() ); final String mainModeAfter = tripRouter.getMainModeIdentifier().identifyMainMode( tripAfter.getTripElements() ); if ( mainModeBefore.equals( mainModeAfter ) ) { mode = mainModeBefore ; } else { throw new ReplanningException("mode not given and mode before removed activity != mode after removed activity; don't know which mode to use") ; } } PlanElement pe = planElements.remove(index) ; if ( checkIfTripHasAlreadyStarted( agent, tripBefore.getTripElements() ) ) { editTrips.replanCurrentTrip(agent, mobsim.getSimTimer().getTimeOfDay() , mode); } else { editTrips.insertEmptyTrip(plan, tripBefore.getOriginActivity(), tripAfter.getDestinationActivity(), mode ) ; } WithinDayAgentUtils.resetCaches(agent); this.mobsim.rescheduleActivityEnd(agent); return pe ; } public final void rescheduleActivityEndtime( MobsimAgent agent, int index, double newEndTime ) {
this.editTrips.replanCurrentTrip(agent, this.mobsim.getSimTimer().getTimeOfDay(), currentMode ); } else {
public void insertActivity(MobsimAgent agent, int index, Activity activity, String upstreamMode, String downstreamMode ) { Plan plan = WithinDayAgentUtils.getModifiablePlan(agent) ; List<PlanElement> planElements = plan.getPlanElements() ; checkIfNotInPastOrCurrent(agent, index) ; planElements.add( index, activity ) ; { // activity before: Activity actBefore = findRealActBefore(agent, index); if ( actBefore != null ) { if ( WithinDayAgentUtils.indexOfPlanElement(agent, actBefore) < WithinDayAgentUtils.getCurrentPlanElementIndex(agent) ) { // we are already under way editTrips.replanCurrentTrip(agent, this.mobsim.getSimTimer().getTimeOfDay(), upstreamMode ); } else { // we are not yet under way; inserting empty trip: EditTrips.insertEmptyTrip(plan, actBefore, activity, upstreamMode, pf ) ; } } } { // activity after: Activity actAfter = findRealActAfter(agent, index); if ( actAfter != null ) { EditTrips.insertEmptyTrip(plan, activity, actAfter, downstreamMode, pf ) ; } } WithinDayAgentUtils.resetCaches(agent); this.mobsim.rescheduleActivityEnd(agent); }
model.getReplanner().editTrips().replanCurrentTrip( agent, now, routingMode );