22 package org.matsim.core.mobsim.qsim.agents;
24 import java.util.List;
26 import jakarta.validation.constraints.NotNull;
28 import org.apache.logging.log4j.LogManager;
29 import org.apache.logging.log4j.Logger;
58 import com.google.common.base.MoreObjects;
59 import com.google.common.base.Preconditions;
97 Preconditions.checkArgument(!planElements.isEmpty(),
"Plan must consist of at least one activity");
101 this.setCurrentLinkId( linkId );
112 +
", but arrived on link " + this.
getCurrentLinkId() +
". Setting agent state to ABORT.");
119 this.currentLinkIndex = 0 ;
129 this.setCurrentLinkId( linkId ) ;
133 this.currentPlanElementIndex++ ;
136 if ( this.getCurrentPlanElementIndex() >= this.
getCurrentPlan().getPlanElements().size() ) {
137 log.error(
"plan of agent with id = " + this.
getId() +
" has run empty. Setting agent state to ABORT (but continuing the mobsim).") ;
144 Activity act = (Activity) pe;
146 }
else if (pe instanceof
Leg) {
150 throw new RuntimeException(
"Unknown PlanElement of type: " + pe.getClass().getName());
156 this.currentLinkIndex = 0 ;
158 log.error(
"The agent " + this.
getPerson().
getId() +
" has no route in its leg. Setting agent state to ABORT.");
159 if ( noRouteWrnCnt < 1 ) {
160 log.info(
"(Route is needed inside Leg even if you want teleportation since Route carries the start/endLinkId info.)") ;
186 if ( finalActHasDpTimeWrnCnt < 1 && departure!=Double.POSITIVE_INFINITY ) {
187 log.error(
"last activity of person driver agent id " + this.
getId() +
" has end time < infty; setting it to infty") ;
189 finalActHasDpTimeWrnCnt++ ;
191 departure = Double.POSITIVE_INFINITY ;
194 this.activityEndTime = departure ;
200 log.warn(
"trying to end an activity but current plan element is not an activity; agentId=" + this.
getId() );
227 if (firstTimeToGetModifiablePlan) {
228 firstTimeToGetModifiablePlan = false ;
246 if( this.getCurrentPlanElementIndex() >= this.
getCurrentPlan().getPlanElements().size() ) {
252 if (!(currentPlanElement instanceof
Leg)) {
255 return ((Leg) currentPlanElement).getMode() ;
265 if (!(currentPlanElement instanceof
Leg)) {
268 return ((Leg) currentPlanElement).getRoute().getDistance();
277 if ( this.currentPlanElementIndex < this.plan.
getPlanElements().size()-1 ) {
278 return this.plan.
getPlanElements().get( this.currentPlanElementIndex+1 ) ;
284 for (
int idx = this.currentPlanElementIndex+1 ; idx < this.plan.
getPlanElements().size(); idx++ ) {
292 for (
int idx = this.currentPlanElementIndex-1 ; idx>=0 ; idx-- ) {
301 if ( this.currentPlanElementIndex >=1 ) {
302 return this.plan.
getPlanElements().get( this.currentPlanElementIndex-1 ) ;
308 final int getCurrentPlanElementIndex() {
356 final void setCurrentLinkId(@NotNull
Id<Link> linkId ) {
357 this.currentLinkId = Preconditions.checkNotNull(linkId);
377 final Leg getCurrentLeg() {
387 final void incCurrentLinkIndex() {
396 activity = (Activity) pe;
397 }
else if ( pe instanceof
Leg ) {
408 if ( pe instanceof
Leg ) {
415 }
else if (pe instanceof
Activity) {
423 return MoreObjects.toStringHelper(
this)
425 .add(
"vehicle", vehicle)
427 .add(
"currentPlanElementIndex", currentPlanElementIndex)
428 .add(
"currentLinkId", currentLinkId)
double orElse(double other)
final Id< Person > getId()
final int getCurrentLinkIndex()
final PlanElement getNextPlanElement()
final TimeInterpretation timeInterpretation
static final String ONLYONCE
final void setVehicle(MobsimVehicle vehicle)
final Id< Link > getCurrentLinkId()
final EventsManager events
static void assertIf(boolean flag)
OptionalTime decideOnActivityEndTime(Activity activity, double startTime)
final OptionalTime getExpectedTravelTime()
final PlanElement getCurrentPlanElement()
final Id< Vehicle > getPlannedVehicleId()
final MobsimAgent.State getState()
final void endLegAndComputeNextState(final double now)
final void calculateAndSetDepartureTime(Activity act)
final void endActivityAndComputeNextState(final double now)
boolean firstTimeToGetModifiablePlan
static Plan createPlan(Person person)
Facility getDestinationFacility()
static Id< Link > computeLinkIdFromActivity(Activity act, ActivityFacilities facs, Config config)
static< T > Id< T > create(final long key, final Class< T > type)
final Id< Link > getDestinationLinkId()
static void copyFromTo(final Plan in, final Plan out)
void processEvent(final Event event)
final Double getExpectedTravelDistance()
OptionalTime decideOnLegTravelTime(Leg leg)
final Activity getPreviousActivity()
void initializeLeg(Leg leg)
Facility getCurrentFacility()
final EventsManager getEvents()
abstract Id< Vehicle > getVehicleId()
final Activity getNextActivity()
List< PlanElement > getPlanElements()
final MobsimTimer simTimer
final MobsimVehicle getVehicle()
int currentPlanElementIndex
final PlanElement getPreviousPlanElement()
static int finalActHasDpTimeWrnCnt
final Scenario getScenario()
Id< ActivityFacility > getFacilityId()
void initializeActivity(Activity act, double now)
final void setStateToAbort(final double now)
ActivityFacilities getActivityFacilities()
final Plan getModifiablePlan()
boolean getUsePersonIdForMissingVehicleId()
final double getActivityEndTime()
final Plan getCurrentPlan()
final void notifyArrivalOnLinkByNonNetworkMode(final Id< Link > linkId)
Id< Link > getEndLinkId()
static Plan unmodifiablePlan(Plan plan)
static Facility toFacility(final Activity toWrap, ActivityFacilities activityFacilities)
BasicPlanAgentImpl(Plan plan2, Scenario scenario, EventsManager events, MobsimTimer simTimer, TimeInterpretation timeInterpretation)
void advancePlan(double now)