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).- 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.Get value: 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 -
[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.Value type: 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
- On enter
- Code executed when the agent enters the block.
Type: code
Local variable: agent — the agent
Function | Description |
void setBlocked(boolean blocked) | Blocks the input port if true is passed as the argument, and unblocks it otherwise. |
boolean isBlocked() | Returns true if the input is blocked, otherwise false. |
void block() | Blocks the input port. Does nothing if port is already blocked. |
void unblock() | Unblocks the input port. Does nothing if port isn’t blocked. |
boolean toggleBlock() | Changes “blocked” state and returns the new state (blocked = true). |
void recalculateConditions() | Use this function to tell the Hold block to recalculate blocking conditions for all agents which are currently held by this block. |
- in
- The input port.
- out
- The output port.
-
How can we improve this article?
-