AnyLogic
Expand
Font size

Delay

Delays agents for a given amount of time. The delay time is evaluated dynamically, may be stochastic and may depend on the agent as well as on any other conditions. Optionally, it may be calculated as the length of the animation path of the Delay divided by the “speed” of the agent. Multiple agents (up to the given Delay capacity) can be delayed simultaneously and independently.

An example of delay time definition: let the delay time of e.g. a data packet (agent type Packet) processing is proportional to the size of the packet (to define the packet size you should create the size parameter in the Packet agent type). Then you may do the following: specify Packet as the Agent type of Delay and write processingTimePerDataUnit * agent.size in the delayTime parameter.

If the capacity of the Delay block is changed dynamically, and the number of currently delayed agents exceeds the capacity, the Delay block will let them complete their delay times and will not let new agents in until the number falls below the new capacity.

You can access the agents being delayed, in particular you can get their remaining times and even remove agents from the block before they finish their delays.

The Delay block can animate the agents either as moving along the specified path or as staying at the specified positions. In case the agents are moving, they will cover the full path during the delay time.

You can extend the delay time dynamically for agents that are currently in the state of delay using the extendDelay() function.

Parameters

Type
The type of agent release trigger:
Specified time — the delay ends when the specified time elapses.
Until stopDelay() is called — the user should end the delay and release the agent by calling the Delay function stopDelay().
Get value: type
Valid values:
Delay.TIMEOUT — Specified time
Delay.MANUAL — Until stopDelay() is called
Delay time
[Visible if Type is Specified time]
Expression evaluated to obtain the delay time for the agent.
Value type: double
Local variable: agent — the current agent.
Capacity
The capacity of Delay block: the number of agents that can be delayed at the same time.
Syntax: int capacity
Default value: 1
Set new value dynamically: set_capacity(new value)
Maximum capacity
If the option is selected (true), the capacity of the Delay is maximum possible (limited by Integer.MAX_VALUE).
Syntax: boolean maximumCapacity
Default value: false
Agent location
Space markup shape (node or path) where the agents are located while being in this Delay.
Get value: entityLocation

Advanced

Forced pushing
If the option is selected (true), when agents finish processing at the block, they are instantly pushed further regardless the state of the succeeding block.
If the option is not selected, agents are not pushed, but pulled: only when the succeeding block is ready to accept one more agent, it requests the agent from this block, and only then this agent passes further.
Syntax: boolean pushProtocol
Default value: false
Restore agent location on exit
If the option is selected, after being animated in the Agent location shape, the agents will return to their original location (node or path) where they were before entering this block.
Syntax: boolean restoreEntityLocationOnExit
Force statistics collection
This block collects statistics. If the statistics collection is turned off for all Process Modeling Library blocks in the model by the PML Settings block, this option enables you to override this setting and collect the statistics for this specific block. Otherwise, the statistics will be collected regardless this setting.
Syntax: boolean forceStatisticsCollection
Default value: false

Actions

On enter
Code executed when the agent enters the block.
Local variables:
agent — the agent.
double delayTime — the delay time for the agent (already evaluated).
On at exit
Code executed when the delay for the agent ends and the agent is ready to exit the block.
Local variable: agent — the agent.
On exit
Code executed when the agent exits the block.
Local variable: agent — the agent.
On remove
Code executed when the agent is intentionally removed from this block by calling the agent’s function remove(). This code is automatically executed after the remove() function call.
Local variable: agent — the agent.

Statistics

StatisticsContinuous statsUtilization
Continuous statistics on the delay utilization (the utilization at each moment of time is calculated as size()/capacity). Is collected if the statistics collection is not turned off by PML Settings block.

Functions

Stop delay
Function Description
void stopDelay(Agent agent) Stops the delay for the specified agent. If the agent argument evaluates to null, then all the agents are released.

agent — The agent to free.
void stopDelayForAll() Stops delay for all currently delayed agents.
Suspend/resume
Function Description
void suspend() Suspends this Delay block. Blocks the input port, even if the block isn’t full. Timeouts of agents already being delayed are suspended until the resume() function is called. Agents that have already finished their delay and are waiting for the next block to accept them are free to leave whenever the next block is ready to accept them.
void suspend(double dt) Suspends this Delay block for the given timeout dt.

dt — the timeout, in model time units.
void suspend(double timeout, TimeUnits units) Suspends this Delay block for the given timeout in the given time units.

dt — the timeout value.
units — The time units.
void resume() Resumes the previously suspended delay (if not suspended, throws an error). After this function is called, all timeouts of delayed agents are resumed, so their total timeouts are increased by the amount of time elapsed between suspend() and resume() calls. Unblocks the input port if there is room for incoming agents.
Agent resume(Agent agent) Resumes the flowchart movement of the previously suspended agent within this Delay block. If the agent was not suspended, throws an error.

agent — The agent whose flowchart movement should be resumed.
Agent suspend(Agent agent) Suspends the specified agent within this Delay block. Do not confuse this function with Delay.suspend().

agent — The agent to suspend.
boolean isSuspended() Returns true if the Delay block is suspended, false if not.
boolean isSuspended(Agent agent) Returns true if the specified agent within is suspended within this Delay block, false if not.

agent — The agent whose suspension status to check.
Extend/reduce delay
Function Description
void extendDelay(Agent agent, double dt) Extends the delay for the given agent (if it is possible to pass null as an argument, all delayed agents will be affected). The dt argument is measured in model time units. If a negative value of this argument is passed, the function reduces the delay for the given agent.
This function doesn’t affect agents that have finished their delay and are currently waiting to be accepted by subsequent blocks (due to the “pull” protocol).
If the delay time has been reduced to 0 after calling this function, the stopDelay() function is automatically called for that agent. This function is only available for the Delay blocks of the Specified time type and has no effect if the initial delay time was set to 0.

agent — The agent to delay.
dt — The delay extension time (in model time units).
void extendDelay(Agent agent, double dt, TimeUnits units) Extends the delay for the given agent (if it is possible to pass null as an argument, all delayed agents will be affected). The dt argument is measured in specified time units. If a negative value of this argument is passed, the function reduces the delay for the given agent.
This function doesn’t affect agents that have finished their delay and are currently waiting to be accepted by subsequent blocks (due to the “pull” protocol).
If the delay time has been reduced to 0 after calling this function, the stopDelay() function is automatically called for that agent. This function is only available for the Delay blocks of the Specified time type and has no effect if the initial delay time was set to 0.

agent — The agent to delay.
dt — The delay extension time.
units — The time units.
void reduceDelay(Agent agent, double dt) Reduces the delay for the given agent (if it is possible to pass null as an argument, all delayed agents will be affected). The dt argument is measured in model time units
. This function doesn’t affect agents that have finished their delay and are currently waiting to be consumed by subsequent blocks (due to the “pull” protocol).
If the delay time has been reduced to 0 after calling this function, the stopDelay() function is automatically called for that agent. This function is only available for the Delay blocks of the Specified time type.

agent — The agent whose delay time is being reduced.
dt — The amount to decrease the delay time (in model time units).
void reduceDelay(Agent agent, double dt, TimeUnits units) Reduces the delay for the given agent (if it is possible to pass null as an argument, all delayed agents will be affected) in specified time units.
This function doesn’t affect agents that have finished their delay and are currently waiting to be consumed by subsequent blocks (due to the “pull” protocol).
If the delay time has been reduced to 0 after calling this function, the stopDelay() function is automatically called for that agent. This function is only available for the Delay blocks of the Specified time type.

agent — The agent whose delay time is being reduced.
dt — The amount to decrease the delay time.
units — The time units.
Delay time
Function Description
double getRemainingTime(Agent agent) Returns the remaining delay time for the specified agent, in model time units. Note that when using the “pull” protocol, if this function returns 0, the agent may still remain in the Delay block if the next block cannot accept the agent immediately.

agent — The agent whose remaining delay time is to be retrieved.
double getRemainingTime(Agent agent, TimeUnits units) Returns the remaining delay time for the specified agent, in specified time units. Note that when using the “pull” protocol, if this function returns 0, the agent may still remain in the Delay block if the next block cannot accept the agent immediately.

agent — The agent whose remaining delay time is to be retrieved.
units — The time units.
double getDelayTime(Agent agent) Returns the initial (chosen) delay time calculated for the specified agent in this Delay block, in model time units. This function takes into account possible delay extensions from extendDelay() function calls. In the case of the “pull” protocol, the actual delay may be greater — if the next block cannot accept outgoing agents immediately.

agent — The agent whose initial delay time is to be retrieved.
double getDelayTime(Agent agent, TimeUnits units) Returns the initial (chosen) delay time calculated for the specified agent in this Delay block, in specified time units. This function takes into account possible delay extensions from extendDelay() function calls. In the case of the “pull” protocol, the actual delay may be greater — if the next block cannot accept outgoing agents immediately.

agent — The agent whose initial delay time is to be retrieved.
units — The time units.
double getElapsedTime(Agent agent) Returns the time that the specified agent has spent in this Delay block, in model time units. In the case of the “pull” protocol, the returned value may exceed getDelayTime() — if the next block cannot accept agents immediately.

agent — The agent whose elapsed delay time is to be retrieved.
double getElapsedTime(Agent agent, TimeUnits units) Returns the time that the specified agent has spent in this Delay block, in specified time units. In the case of the “pull” protocol, the returned value may exceed getDelayTime() — if the next block cannot accept agents immediately.

agent — The agent whose elapsed delay time is to be retrieved.
units — The time units.
Agent
Function Description
int size() Returns the number of agents currently being delayed.
T remove(Agent agent) Removes the specified agent from the block and returns it.

agent — the agent to remove.
T get(int i) Returns the agent with index i. Note that this function is very slow and that the order of agents and their indices isn’t preserved and may be different at the next time moment.

i — the index of the agent to receive.
Iterator<Agent> iterator() Returns the iterator over agents (order: the first is at the exit, the last has the most time left in the delay).
Statistics
Function Description
boolean isStatisticsCollected() Returns true if the block collects statistics.
resetStats() Resets the statistics collected for this block.

Ports

in
The input port.
out
The output port.
How can we improve this article?