private static void checkIfSameMode(String upstreamMode, final String currentMode) { if ( upstreamMode!=null && !upstreamMode.equals(currentMode) ) { throw new ReplanningException( "cannot change mode in trip that has already started. Don't set the mode in the request, " + "or somehow make the agent to abort the current trip first." ) ; } } // private static boolean locationsAreSame(Activity origAct, Activity newAct) {
private static void checkIfNotInPastOrCurrent(MobsimAgent agent, int index) { final Integer currentIndex = WithinDayAgentUtils.getCurrentPlanElementIndex(agent); // make sure we are not yet beyond the to-be-replanned activity: if ( index <= currentIndex ) { throw new ReplanningException("trying to replace an activity that lies in the past or is current; this is not possible") ; } } private static void checkIfSameMode(String upstreamMode, final String currentMode) {
public Trip findTripAtPlanElement(MobsimAgent agent, PlanElement pe) { log.debug("plan element to be found=" + pe ) ; List<Trip> trips = TripStructureUtils.getTrips( WithinDayAgentUtils.getModifiablePlan(agent), tripRouter.getStageActivityTypes() ) ; for ( Trip trip : trips ) { for ( PlanElement te : trip.getTripElements() ) { log.debug("trip element to be compared with=" + te ) ; if ( te==pe ) { log.debug("found trip element") ; return trip; } } } throw new ReplanningException("trip not found") ; } public Trip findTripAtPlanElementIndex( MobsimAgent agent, int index ) {
private void replanCurrentTripFromLeg(Activity newAct, final PlanElement currentPlanElement, final String routingMode, double now, MobsimAgent agent) { log.debug("entering replanCurrentTripFromLeg"); Leg currentLeg = (Leg) currentPlanElement ; if ( currentLeg.getRoute() instanceof NetworkRoute ) { replanCurrentLegWithNetworkRoute(newAct, routingMode, currentLeg, now, agent); } else { throw new ReplanningException("not implemented") ; // Does not feel so hard: // * with teleported legs, push forward to next facility // * with passenger legs, push forward to next possibility of exit } WithinDayAgentUtils.resetCaches(agent); } private void replanCurrentLegWithNetworkRoute(Activity newAct, String mainMode, Leg currentLeg, double now,
private void checkIfNotStageActivity(Activity origAct) { if( this.tripRouter.getStageActivityTypes().isStageActivity(origAct.getType()) ){ throw new ReplanningException("trying to replace a helper activity (stage activity) by a real activity; this is not possible") ; } } private static boolean checkIfTripHasAlreadyStarted(MobsimAgent agent, final List<PlanElement> currentTripElements) {
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 ) {
throw new ReplanningException("trying to replace a non-activity in the plan by an activity; this is not possible") ;