@Override public final Plan getCurrentPlan() { return basicAgentDelegate.getCurrentPlan(); }
@Override public final String getMode() { if( this.getCurrentPlanElementIndex() >= this.getCurrentPlan().getPlanElements().size() ) { // just having run out of plan elements it not an argument for not being able to answer the "mode?" question, // thus we answer with "null". This will likely result in an "abort". kai, nov'14 return null ; } PlanElement currentPlanElement = this.getCurrentPlanElement(); if (!(currentPlanElement instanceof Leg)) { return null; } return ((Leg) currentPlanElement).getMode() ; } @Override
/** * If this method is called to update a changed ActivityEndTime please * ensure that the ActivityEndsList in the {@link QSim} is also updated. */ private final void calculateAndSetDepartureTime(Activity act) { PlansConfigGroup.ActivityDurationInterpretation activityDurationInterpretation = this.getScenario().getConfig().plans().getActivityDurationInterpretation(); double now = this.getSimTimer().getTimeOfDay() ; double departure = ActivityDurationUtils.calculateDepartureTime(act, now, activityDurationInterpretation); if ( this.getCurrentPlanElementIndex() == this.getCurrentPlan().getPlanElements().size()-1 ) { if ( finalActHasDpTimeWrnCnt < 1 && departure!=Double.POSITIVE_INFINITY ) { log.error( "last activity of person driver agent id " + this.getId() + " has end time < infty; setting it to infty") ; log.error( Gbl.ONLYONCE ) ; finalActHasDpTimeWrnCnt++ ; } departure = Double.POSITIVE_INFINITY ; } this.activityEndTime = departure ; }
private void advancePlan(double now) { this.currentPlanElementIndex++ ; // check if plan has run dry: if ( this.getCurrentPlanElementIndex() >= this.getCurrentPlan().getPlanElements().size() ) { log.error("plan of agent with id = " + this.getId() + " has run empty. Setting agent state to ABORT (but continuing the mobsim).") ; this.setState(MobsimAgent.State.ABORT) ; return; } PlanElement pe = this.getCurrentPlanElement() ; if (pe instanceof Activity) { Activity act = (Activity) pe; initializeActivity(act, now); } else if (pe instanceof Leg) { Leg leg = (Leg) pe; initializeLeg(leg); } else { throw new RuntimeException("Unknown PlanElement of type: " + pe.getClass().getName()); } }
@Override public final Plan getCurrentPlan() { return basicAgentDelegate.getCurrentPlan(); } @Override
/** * Returns a modifiable Plan for use by WithinDayAgentUtils in this package. * This agent retains the copied plan and forgets the original one. However, the original plan remains in the population file * (and will be scored). This is deliberate behavior! */ @Override public final Plan getModifiablePlan() { // yy MZ suggests, and I agree, to always give the agent a full plan, and consume that plan as the agent goes. kai, nov'14 if (firstTimeToGetModifiablePlan) { firstTimeToGetModifiablePlan = false ; Plan newPlan = PopulationUtils.createPlan(this.getCurrentPlan().getPerson()); PopulationUtils.copyFromTo(this.getCurrentPlan(), newPlan); this.plan = newPlan; } return this.getCurrentPlan(); } @Override
public BasicPlanAgentImpl(Plan plan2, Scenario scenario, EventsManager events, MobsimTimer simTimer) { this.plan = PopulationUtils.unmodifiablePlan(plan2) ; // yy MZ suggests, and I agree, to always give the agent a full plan, and consume that plan as the agent goes. kai, nov'14 this.scenario = scenario ; this.events = events ; this.simTimer = simTimer ; List<PlanElement> planElements = this.getCurrentPlan().getPlanElements(); if (planElements.size() > 0) { Activity firstAct = (Activity) planElements.get(0); // this.setCurrentLinkId( firstAct.getLinkId() ) ; final Id<Link> linkId = PopulationUtils.computeLinkIdFromActivity(firstAct, scenario.getActivityFacilities(), scenario.getConfig() ); Gbl.assertIf( linkId!=null ); this.setCurrentLinkId( linkId ); this.setState(MobsimAgent.State.ACTIVITY) ; calculateAndSetDepartureTime(firstAct); } }