@@ -378,6 +378,9 @@ private void processAbandonedRequests(double now) {
378
378
379
379
// Rejections
380
380
381
+ private static final String ABORT_STUCK_REASON = " rejected prebooked request" ;
382
+ private final IdSet <Person > stuckUponActivity = new IdSet <>(Person .class );
383
+
381
384
private void processRejections (double now ) {
382
385
for (Id <Request > requestId : rejectedEventIds ) {
383
386
RequestItem item = requests .remove (requestId );
@@ -401,25 +404,20 @@ private void processRejections(double now) {
401
404
Plan plan = WithinDayAgentUtils .getModifiablePlan (agent );
402
405
PlanElement planElement = plan .getPlanElements ().get (index );
403
406
404
- if (planElement instanceof Activity currentActivity ) {
405
- Activity activity = currentActivity ;
406
- activity .setEndTime (Double .POSITIVE_INFINITY );
407
- activity .setMaximumDurationUndefined ();
408
-
409
- ((HasModifiablePlan ) agent ).resetCaches ();
410
- internalInterface .getMobsim ().rescheduleActivityEnd (agent );
411
- eventsManager .processEvent (new PersonStuckEvent (now , agent .getId (), agent .getCurrentLinkId (),
412
- this .mode ));
413
-
414
- internalInterface .getMobsim ().getAgentCounter ().incLost ();
415
- internalInterface .getMobsim ().getAgentCounter ().decLiving ();
407
+ if (planElement instanceof Activity ) {
408
+ // the agent is on an activity, let it get stuck further below
409
+ stuckUponActivity .add (passengerId );
416
410
} else {
417
- // If the current element is a leg, the agent is walking towards the pickup location
418
- // We make the agent stuck at the interaction activity
411
+ // the agent is on a leg, so we cannot make it stuck directly.
412
+ // instead, we set the next activity to an infinite duration and
413
+ // make the agent get stuck right after the activity starts
414
+
419
415
while (index < plan .getPlanElements ().size ()) {
420
416
if (plan .getPlanElements ().get (index ) instanceof Activity activity ) {
421
- activity .setEndTime (Double .POSITIVE_INFINITY );
417
+ activity .setEndTime (Double .MAX_VALUE ); // very long but not infinite (= regular last activity)
422
418
activity .setMaximumDurationUndefined ();
419
+ stuckUponActivity .add (agent .getId ());
420
+ break ;
423
421
}
424
422
425
423
index ++;
@@ -431,6 +429,40 @@ private void processRejections(double now) {
431
429
}
432
430
433
431
rejectedEventIds .clear ();
432
+
433
+ Iterator <Id <Person >> stuckIterator = stuckUponActivity .iterator ();
434
+ while (stuckIterator .hasNext ()) {
435
+ Id <Person > personId = stuckIterator .next ();
436
+ MobsimAgent agent = internalInterface .getMobsim ().getAgents ().get (personId );
437
+
438
+ PlanElement planElement = WithinDayAgentUtils .getCurrentPlanElement (agent );
439
+ if (planElement instanceof Activity activity ) {
440
+ abortAgent (agent , activity , now );
441
+ stuckIterator .remove ();
442
+ }
443
+ }
444
+ }
445
+
446
+ private void abortAgent (MobsimAgent agent , Activity activity , double now ) {
447
+ // this would be the simple way, but then it looks like the agent is stuck
448
+ // because of something related to the activity. however, we want to make
449
+ //it clear that drt is the cause here
450
+
451
+ // agent.setStateToAbort(now);
452
+ // internalInterface.arrangeNextAgentState(agent);
453
+
454
+ activity .setEndTime (Double .POSITIVE_INFINITY );
455
+ activity .setMaximumDurationUndefined ();
456
+
457
+ ((HasModifiablePlan ) agent ).resetCaches ();
458
+ internalInterface .getMobsim ().rescheduleActivityEnd (agent );
459
+ eventsManager .processEvent (new PersonStuckEvent (now , agent .getId (), agent .getCurrentLinkId (),
460
+ null , mode + ABORT_STUCK_REASON ));
461
+
462
+ internalInterface .getMobsim ().getAgentCounter ().incLost ();
463
+
464
+ // will be called by the activity engine
465
+ // internalInterface.getMobsim().getAgentCounter().decLiving();
434
466
}
435
467
436
468
// Stuck
0 commit comments