Search code examples
javascheduled-taskswaitanylogic

Anylogic: how to link a wait block to a schedule of different agents


I've got a boat with capacity 1750 pp, that leaves the port every 2 hours based on a schedule. The passengers arrives at a waiting area, they can leave this area if:

  • there is a boat at the dock
  • (the number of passengers already embarked + passengers that left the waiting area) < 1750

All these conditions are working properly, but since it takes time to get to the dock and due to safety protocols, I want to stop the passengers flow 2 minutes before the departure of the boat, in order to not have passengers not embarked on the dock.

How can I link the boat schedule (named schDepartureBoat1) with passengers Wait block (named waitForBoat1)? At the moment I have the following code in the On enter action of the Wait block:

if(cllBoatDock1.size()>0 && (cllPedOnDock1.size()+cllPedOnBoat1.size()) < 1750) {
 waitForBoat1.freeAll();
}

Thank you in advance for your help


Solution

  • Most natural in this case would probably be a "Hold" block downstream of the "Wait" block.

    2 minutes before departure, you call myHoldBlock.block(). No more agents leave the "Wait" block and they will have to stay until the next departure.

    Just ensure to call myHoldBlock.unblock() when the next ship wants boarding to start.