AnyLogic
Expand
Font size

Hold

Can block the agent flow along a particular connection. Is used, for example, when the succeeding flowchart block can accept agents, but you (temporarily) do not want the agents to proceed there, or when you wish to block an output of a particular flowchart block that merges with outputs of other blocks.

The state of the block is controlled programmatically by calling setBlocked() function.

Hold does not hold agents inside (even for zero time), and can be treated as an extension to an input or an output port (or ports).

Demo model: Hold Open the model page in AnyLogic Cloud. There you can run the model or download it (by clicking Model source files).

Parameters

Mode
Here you can choose the block/unblock mode for this Hold block. There are three modes supported:
Manual (use block(), unblock() methods) — the block will be blocked upon calling its block() function, and unblocked on unblock() call.
Block automatically after N agents (use unblock() method) — the block will be blocked automatically right after the specified number of agents arrives at its input port. The block will be unblocked by the call of the block’s function unblock().
Conditional (custom decision for each agent) — the block will make the decision whether to block the input, or not, depending on the result of the Blocking condition being evaluated for each incoming agent.
Syntax: Hold.Mode mode
Valid values:
Hold.MANUAL
Hold.BLOCK_AFTER_N_ENTITIES
Hold.CONDITIONAL
N agents for self-block
[Visible if Mode: Block automatically after N agents]
The number of agents that should arrive in the block’s input port to block the Hold.
Syntax: int nEntitiesForSelfBlock
Set new value at runtime: set_nEntitiesForSelfBlock(new value)
Blocking condition
[Visible if Mode: Conditional (custom decision for each agent)]
Here you can specify the condition that will be re-evaluated for each agent. If the condition evaluates to true, this Hold block is blocked. If you change the condition dynamically, in this case you have to call the block’s function recalculateConditions() that tells the Hold block to recalculate blocking conditions for all agents which are currently held by this block. Study the last case in the given demo model - since the event modifies the variable used in the blocking condition, the recalculateConditions() function is called afterwards.
Type of value: boolean
Local variable: agent — the agent
Initially blocked
If the option is selected (true), the block is initially put into blocked state.
Syntax: boolean initiallyBlocked
Default value: false

Actions

On enter
Code executed when the agent enters the block.
Local variable: agent — the agent

Functions

Function Description
void setBlocked(boolean blocked) Blocks or unblocks the input port.

blocked — The Boolean value that indicates whether to block the input port. Pass true to block the port, false otherwise.
boolean isBlocked() Returns true if the input is blocked, false otherwise.
void block() Blocks the input port. Does nothing if the port is already blocked.
void unblock() Unblocks the input port. Does nothing if the port isn’t blocked.
boolean toggleBlock() Toggles the “blocked” state and returns the new state (true for blocked).
void recalculateConditions() Recalculates the blocking conditions for all agents which are currently held by this block.

Ports

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