@Override public final void endLegAndComputeNextState(final double now) { this.getEvents().processEvent(new PersonArrivalEvent( now, this.getId(), this.getDestinationLinkId(), getCurrentLeg().getMode())); if( (!(this.getCurrentLinkId() == null && this.getDestinationLinkId() == null)) && !this.getCurrentLinkId().equals(this.getDestinationLinkId())) { log.error("The agent " + this.getPerson().getId() + " has destination link " + this.getDestinationLinkId() + ", but arrived on link " + this.getCurrentLinkId() + ". Setting agent state to ABORT."); this.setState(MobsimAgent.State.ABORT) ; } else { // 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) ; } this.currentLinkIndex = 0 ; }
@Override public final void resetCaches() { if ( this.getCurrentPlanElement() instanceof Activity ) { Activity act = (Activity) this.getCurrentPlanElement() ; this.calculateAndSetDepartureTime(act); } }
@Override public final void endActivityAndComputeNextState(double now) { basicAgentDelegate.endActivityAndComputeNextState(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); }
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." ); this.basicPlanAgentDelegate.setState(MobsimAgent.State.ABORT) ; this.basicPlanAgentDelegate.resetCaches();
@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
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); } }
if ( ! ( this.basicPlanAgentDelegate.getCurrentLeg().getRoute() instanceof NetworkRoute ) ) { return null ; List<Id<Link>> routeLinkIds = ((NetworkRoute) this.basicPlanAgentDelegate.getCurrentLeg().getRoute()).getLinkIds(); if (this.basicPlanAgentDelegate.getCurrentLinkIndex() >= routeLinkIds.size() ) { && this.basicPlanAgentDelegate.getCurrentLinkIndex() > routeLinkIds.size()) { this.cachedNextLinkId = routeLinkIds.get(this.basicPlanAgentDelegate.getCurrentLinkIndex()); return this.cachedNextLinkId;
final Leg getCurrentLeg() { return basicAgentDelegate.getCurrentLeg() ; } @Override
@Override public final Id<Vehicle> getPlannedVehicleId() { NetworkRoute route = (NetworkRoute) this.getCurrentLeg().getRoute(); // if casts fail: illegal state. if (route.getVehicleId() != null) { return route.getVehicleId(); } Gbl.assertIf( scenario.getConfig().qsim().getUsePersonIdForMissingVehicleId() ); return Id.create(this.getId(), Vehicle.class); // we still assume the vehicleId is the agentId if no vehicleId is given. } @Override
@Override public Id<Link> getCurrentLinkId() { return basicAgentDelegate.getCurrentLinkId() ; } @Override
@Override public final int getCurrentLinkIndex() { return basicAgentDelegate.getCurrentLinkIndex() ; } final int getCurrentPlanElementIndex() {
@Override public final void endLegAndComputeNextState(double now) { basicAgentDelegate.endLegAndComputeNextState(now); } @Override
public PersonDriverAgentImpl(final Plan plan1, final Netsim simulation) { basicAgentDelegate = new BasicPlanAgentImpl(plan1, simulation.getScenario(), simulation.getEventsManager(), simulation.getSimTimer() ) ; driverAgentDelegate = new PlanBasedDriverAgentImpl(basicAgentDelegate) ; // deliberately does NOT keep a back pointer to the whole Netsim; this should also be removed in the constructor call. }
@Override public final double getActivityEndTime() { return basicAgentDelegate.getActivityEndTime(); } @Override
@Override public Facility getCurrentFacility() { return this.basicAgentDelegate.getCurrentFacility(); }
@Override public final boolean isWantingToArriveOnCurrentLink( ) { if ( ! ( this.basicPlanAgentDelegate.getCurrentLeg().getRoute() instanceof NetworkRoute ) ) { final List<Id<Link>> routeLinkIds = ((NetworkRoute) this.basicPlanAgentDelegate.getCurrentLeg().getRoute()).getLinkIds(); final int routeLinkIdsSize = routeLinkIds.size(); if ( this.basicPlanAgentDelegate.getCurrentLinkIndex() >= routeLinkIdsSize && this.getCurrentLinkId().equals( this.getDestinationLinkId() ) ) { return true ;
@Override public final Id<Link> getDestinationLinkId() { return this.getCurrentLeg().getRoute().getEndLinkId() ; } @Override
@Override public Id<Link> getCurrentLinkId() { return this.basicPlanAgentDelegate.getCurrentLinkId() ; }
@Override public int getCurrentLinkIndex() { return this.basicAgentDelegate.getCurrentLinkIndex(); }