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 (class Packet) processing is proportional to the size of the packet + some random time. Then you may do the following: specify Packet as the Generic Parameter of Delay and write processingTimePerDataUnit * agent.size + uniform( timeMin, timeMax ) in the delayTime parameter.

If the capacity of the Delay object is changed dynamically, and the number of currently delayed agents exceeds the capacity, the Delay object 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 object before they finish their delays.

The Delay object 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.

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
Set new value dynamically: set_type(new value)
Valid values: Specified time - Delay.TIMEOUT
           
Until stopDelay() is called - Delay.MANUAL
Delay time [dynamic]
[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 object: the number of agents that can be delayed at the same time.
Syntax: int capacity
Default value: 1
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
By default statistics is collected for all Process Modeling Library blocks. However, you may tune this and switch off the statistics collection to optimize your model performance. To do this, add PML Settings block and deselect there the option Enable statistics by default. This way you switch stats collecting off for all flowchart blocks in the model. However, you can choose some specific blocks to override this setting and collect statistics by selecting this particular option Force statistics collection in the block properties.
Syntax: boolean forceStatisticsCollection
Default value: false
Actions
On enter [code]
Code executed when the agent enters the object.
Local variables: agent - the agent
                          double delayTime - the delay time for the agent (already evaluated)
On at exit [code]
Code executed when the delay for the agent ends and the agent is ready to exit the object.
Local variable: agent - the agent
On exit [code]
Code executed when the agent exits the object.
Local variable: agent - the agent
On remove [code]
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

Variables

StatisticsContinuous statsUtilization
The statistics on the delay utilization (the utilization at each moment of time is calculated as size()/capacity). It is collected only if the parameter Enable statistics by default is enabled in PML Settings.

Functions

void suspend(double dt) - Suspends this delay for the given timeout dt

void suspend() - Suspends this delay. Blocks input port - even if delay isn't full. Timeouts of agents already being delayed are suspended until the resume() function call. Agents which have already finished their delay (and waiting for acceptance at the subsequent block) - are free to exit at any time subsequent block gets ready to consume them.

void resume() - Resumes previously suspended Delay (if was not suspended, throws error). After this method is called, all timeouts of agents being delayed are resumed, thus their timeouts totally get increased by amount of time spent between suspend() and resume() calls. Unblocks input port if there is a room for incoming agents.

Agent resume(Agent agent) - resumes previously suspended Delay (if was not suspended, throws error).

Agent suspend (Agent agent) - suspends this delay for the given timeout dt.

boolean isSuspended() - Returns suspended status of this Delay block: true, if the Delay is suspended, false - if not.

double getRemainingTime(agent) - Returns the remaining delay time for the given agent. Note that when using PULL protocol, if this method returns 0, the agent still may stay in the Delay in case the subsequent block cannot accept the agent immediately.

double getDelayTime(agent) - Returns the initial (chosen) delay time calculated for the given agent in this Delay. In case of PULL protocol, the actual delay may be greater - when subsequent block cannot accept outgoing agents immediately.

double getElapsedTime(Agent agent ) - Returns the time spent by the given agent in this Delay. In case of PULL protocol, the returned value may exceed getDelayTime() - when subsequent block cannot accept agents immediately.

void stopDelay(Agent agent) - Stops delay for the given agent. If the argument evaluates to null all the agents are released.

void stopDelayForAll() - Stops delay for all the agents currently being delayed.

void extendDelay(Agent agent, double dt) - Extends delay for the given agent (if it is possible to pass null as an argument, all delayed agents will be affected).

int size() - Returns the number of agents currently being delayed.

T remove(Agent agent) - removes the given agent from the object and returns it.

T get(int i) - Returns the agent by index i. Note that this method is very slow and moreover the order of agents and their indexes aren't preserved and may be different at the next time moment.

resetStats() - Resets the statistics collected for this object.

Iterator<Agent> iterator() - Returns the iterator over agents (ordering: the first is at the exit, the last has the largest remaining time to be delayed).

Ports

in
The input port.
out
The output port.