final Leg getCurrentLeg() { return (Leg) this.getCurrentPlanElement() ; } @Override
@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
@Override public final PlanElement getCurrentPlanElement() { return basicAgentDelegate.getCurrentPlanElement(); } @Override
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 PlanElement getCurrentPlanElement() { return basicAgentDelegate.getCurrentPlanElement(); }
@Override public final void resetCaches() { if ( this.getCurrentPlanElement() instanceof Activity ) { Activity act = (Activity) this.getCurrentPlanElement() ; this.calculateAndSetDepartureTime(act); } }
@Override public Facility getCurrentFacility() { PlanElement pe = this.getCurrentPlanElement() ; Activity activity ; if ( pe instanceof Activity ) { activity = (Activity) pe; } else if ( pe instanceof Leg ) { activity = this.getPreviousActivity() ; } else { throw new RuntimeException("unexpected type of PlanElement") ; } return getFacility(activity, scenario); }
@Override public final Double getExpectedTravelDistance() { PlanElement currentPlanElement = this.getCurrentPlanElement(); if (!(currentPlanElement instanceof Leg)) { return null; } return ((Leg) currentPlanElement).getRoute().getDistance(); }
if( this.basicPlanAgentDelegate.getCurrentPlanElement()==null ) { throw new RuntimeException("encountered unexpected null pointer" ) ; if (this.basicPlanAgentDelegate.getCurrentPlanElement() instanceof Leg) { if (basicPlanAgentDelegate.getCurrentLeg().getRoute() == null) { log.error("The agent " + this.getId() + " has no route in its leg. Setting agent state to abort." );
@Override public Facility getDestinationFacility() { PlanElement pe = this.getCurrentPlanElement() ; if ( pe instanceof Leg ) { Activity activity = this.getNextActivity() ; ActivityFacility fac = this.scenario.getActivityFacilities().getFacilities().get( activity.getFacilityId() ) ; return getFacility(activity, scenario); // the above assumes alternating acts/legs. I start having the suspicion that we should revoke our decision to give that up. // If not, one will have to use TripUtils to find the preceeding activity ... but things get more difficult. Preferably, the // factility should then sit in the leg (since there it is used for routing). kai, dec'15 } else if ( pe instanceof Activity ) { return null ; } throw new RuntimeException("unexpected type of PlanElement") ; }
@Override public final Double getExpectedTravelTime() { PlanElement currentPlanElement = this.getCurrentPlanElement(); if (!(currentPlanElement instanceof Leg)) { return null; } final double travelTimeFromRoute = ((Leg) currentPlanElement).getRoute().getTravelTime(); if ( travelTimeFromRoute != Time.UNDEFINED_TIME ) { return travelTimeFromRoute ; } else if ( ((Leg) currentPlanElement).getTravelTime() != Time.UNDEFINED_TIME ) { return ((Leg) currentPlanElement).getTravelTime() ; } else { return null ; } }
@Override public final void endActivityAndComputeNextState(final double now) { Activity act = (Activity) this.getCurrentPlanElement() ; this.getEvents().processEvent( new ActivityEndEvent(now, this.getPerson().getId(), this.currentLinkId, act.getFacilityId(), act.getType())); // note that when we are here we don't know if next is another leg, or an activity Therefore, we go to a general method: advancePlan(now); } @Override
private void initializeActivity(Activity act, double now) { this.setState(MobsimAgent.State.ACTIVITY) ; this.getEvents().processEvent( new ActivityStartEvent(now, this.getId(), this.getCurrentLinkId(), act.getFacilityId(), act.getType())); calculateAndSetDepartureTime(act); getModifiablePlan(); // this is necessary to make the plan modifiable, so that setting the start time (next line) is actually feasible. kai/mz, oct'16 ((Activity) getCurrentPlanElement()).setStartTime(now); }