/** * Convenience method, clarifying that this can be called without giving the mode. */ public final Activity replaceActivity(MobsimAgent agent, int index, Activity newAct) { return replaceActivity( agent, index, newAct, null, null ) ; } /**
/** Convenience method, to be consistent with earlier syntax. kai, may'16 * @param trip * @param plan * @param mainMode * @param departureTime * @param network * @param tripRouter */ public static boolean relocateFutureTrip(Trip trip, Plan plan, String mainMode, double departureTime, Network network, TripRouter tripRouter) { return replanFutureTrip(trip, plan, mainMode, departureTime, tripRouter ); } public StageActivityTypes getStageActivities() {
/** * Convenience method, clarifying that this can be called without giving the mode. */ public PlanElement removeActivity(MobsimAgent agent, int index) { return removeActivity( agent, index, null ) ; } /**
@Inject Replanner(QSim qSim2, TripRouter tripRouter, Map<String,TravelTime> travelTimes ) { Scenario scenario = qSim2.getScenario(); this.travelTimes = travelTimes ; { TravelTime travelTime = TravelTimeUtils.createFreeSpeedTravelTime(); TravelDisutility travelDisutility = TravelDisutilityUtils.createFreespeedTravelTimeAndDisutility(scenario.getConfig().planCalcScore()); LeastCostPathCalculator pathCalculator = new FastAStarLandmarksFactory().createPathCalculator(scenario.getNetwork(), travelDisutility, travelTime); this.editRoutes = new EditRoutes(scenario.getNetwork(), pathCalculator, scenario.getPopulation().getFactory()); } this.editTrips = new EditTrips(tripRouter, qSim2.getScenario() ) ; this.editPlans = new EditPlans(qSim2, tripRouter, editTrips, scenario.getPopulation().getFactory() ) ; }
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) {
/** * Convenience method, clarifying that this can be called without giving the mode. */ public void insertActivity(MobsimAgent agent, int index, Activity activity ) { String mode = tripRouter.getMainModeIdentifier().identifyMainMode( editTrips.findCurrentTrip(agent).getTripElements() ) ; insertActivity( agent, index, activity, mode, mode ) ; }
/** * @author cdobler */ private void createScenario() { scenario = ScenarioUtils.createScenario(ConfigUtils.createConfig()); createSampleNetwork(); createTripRouter(); createSamplePlan(); }
public void rescheduleCurrentActivityEndtime(MobsimAgent agent, double newEndTime) { Integer index = WithinDayAgentUtils.getCurrentPlanElementIndex(agent) ; this.rescheduleActivityEndtime(agent, index, newEndTime); }
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,
/** * Re-plans a future route. The route is given by its leg. It is expected that the * leg's route is not null and that the start- and end link Ids are set properly. * * If the start- and or end-location of the leg have changed, use relocateFutureLegRoute(...)! * * @return true when replacing the route worked, false when something went wrong */ public boolean replanFutureLegRoute(Leg leg, Person person ) { // just a pointer to that other method, but this one (which does not change the destination) is still ok also with access/egress // routing return relocateFutureLegRoute( leg, leg.getRoute().getStartLinkId(), leg.getRoute().getEndLinkId(), person ) ; }
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) {
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 insertEmptyTrip( Plan plan, Activity fromActivity, Activity toActivity, String mainMode ) { return insertEmptyTrip( plan, fromActivity, toActivity, mainMode, this.pf ) ; } /**
public boolean isAtRealActivity(MobsimAgent agent) { PlanElement pe = WithinDayAgentUtils.getCurrentPlanElement(agent) ; if ( isRealActivity(pe) ) { return true ; } else { return false ; } } public boolean isRealActivity(PlanElement pe) {
public Activity findRealActAfter(MobsimAgent agent, int index) { Plan plan = WithinDayAgentUtils.getModifiablePlan(agent) ; List<PlanElement> planElements = plan.getPlanElements() ; return (Activity) planElements.get( findIndexOfRealActAfter(agent, index) ) ; } public int findIndexOfRealActAfter(MobsimAgent agent, int index) {
@Override public void install() { install(AbstractModule.override(Arrays.asList(new TripRouterModule()), new AbstractModule() { @Override public void install() { install(new ScenarioByInstanceModule(scenario)); addTravelTimeBinding("car").toInstance(new FreeSpeedTravelTime()); addTravelDisutilityFactoryBinding("car").toInstance(new OnlyTimeDependentTravelDisutilityFactory()); } })); } });
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 final boolean replanFutureTrip(Trip trip, Plan plan, String routingMode, double departureTime) { return replanFutureTrip(trip, plan, routingMode, departureTime, tripRouter); }
public Trip findTripAtPlanElementIndex( MobsimAgent agent, int index ) { return findTripAtPlanElement( agent, WithinDayAgentUtils.getModifiablePlan(agent).getPlanElements().get(index) ) ; } // current trip:
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) {