
The Match block synchronizes two streams of agents by matching pairs according to specified criteria. The agents that have not yet been matched are stored in two queues (one for each stream). When the new agent arrives at one of the input ports, it is checked for a match against all the agents in the queue for the other stream. If a match is found, the On match action is executed and both agents exit the Match block at the same time. The queues are fully customizable (timeout, priorities, preemption, and so on).
The default match condition is true. This means that any two agents match,, so the Match block works as a pure stream synchronizer: it will output pairs of agents.
For example, we have two streams of agents. One stream provides agents of type Passenger, while the other stream provides agents of type Baggage. Both types have an id field.
In this scenario, the generic parameters of Match are Passenger and Baggage. To match a passenger to their luggage, write the following Match condition:
agent1.id == agent2.idDemo model: Match Open the model page in AnyLogic Cloud. There you can run the model or download it (by clicking Model source files). Demo model: MatchOpen the model in your AnyLogic desktop installation.
-
The condition that is evaluated for a pair of agents, one being the agent that just arrived and the other being the agent in the opposite queue, when the new agent arrives. When the new agent arrives at one of the input ports, it is checked for a match against all the agents in the queue from the other stream. If a match is found, the On match action is performed and both agents exit the block at the same time.
Type: boolean
Default value: true
Local variables:
T1 agent1 — the agent in queue1
T2 agent2 — the agent in queue2 - Capacity (1)
-
[Visible unless the Maximum capacity (1) option is selected]
The capacity of the first queue.Name: capacity1
Type: int
Default value: 100
Set new value at runtime: set_capacity1(new value) - Maximum capacity (1)
-
If the option is selected (true), the capacity of the first queue is the maximum possible (limited by Integer.MAX_VALUE).
Name: maximumCapacity1
Type: boolean
Set new value at runtime: set_maximumCapacity1(new value) - Capacity (2)
-
[Visible unless the Maximum capacity (2) option is selected]
The capacity of the second queue.Name: capacity2
Type: int
Default value: 100
Set new value at runtime: set_capacity2(new value) - Maximum capacity (2)
-
If the option is selected (true), the capacity of the second queue is the maximum possible (limited by Integer.MAX_VALUE).
Name: maximumCapacity2
Type: boolean
Set new value at runtime: set_maximumCapacity2(new value) - Agent location (queue 1)
-
The space markup shape (node or path) where the agents are located while being in queue1.
Name: entityLocation1
Type: AnimationStaticLocationProvider - Agent location (queue 2)
-
The space markup shape (node or path) where the agents are located while being in queue2.
Name: entityLocation2
Type: AnimationStaticLocationProvider
- Queuing (queue 1)
-
The queuing discipline for the first queue. Possible disciplines are:
FIFO — First In, First Out. The default policy. The first agent stored is the first agent to be retrieved.
Priority-based — Agents are queued according to their priority (defined in the Agent priority (1) field).
Agent comparison — In this mode, the Boolean expression is evaluated for every incoming agent. It compares this agent with the agents that are already in the queue and determines the queue position based on the results.
LIFO — Last In, First Out. The last agent stored will be the first to be retrieved.
Name: queuing1
Type: Queue.QueuingMode
Valid values:
Match.QUEUING_FIFO — FIFO
Match.QUEUING_PRIORITY — Priority-based
Match.QUEUING_COMPARISON — Agent comparison
Match.QUEUING_LIFO — LIFO -
[Visible if Queuing (queue 1): Priority-based]
The priority of the incoming agent in the first stream (the greater the higher).Type: double
Default value: 0
Local variable: T1 agent — the agent -
[Visible if Queuing (queue 1): Entity comparison]
The Boolean expression to evaluate for each agent entering queue1. The expression compares this agent to the agents already in the queue and determines the queue position based on the results. If the expression returns true, the new agent is put closer to the queue head than the agent from the queue1 being compared with it.Type: boolean
Local variables:
T1 agent1 — the incoming agent
T1 agent2 — the agent being compared with the incoming agent - Queuing (queue 2)
-
The queuing discipline for the second queue. Possible policies are:
FIFO — First In, First Out. The default policy. The first agent stored is the first agent to be retrieved.
Priority-based — Agents are queued according to their priority (defined in the Agent priority (1) field).
Agent comparison — In this mode, the Boolean expression is evaluated for every incoming agent. It compares this agent with the agents that are already in the queue and determines the queue position based on the results.
LIFO — Last In, First Out. The last agent stored will be the first to be retrieved.
Name: queuing2
Type: Queue.QueuingMode
Valid values:
Match.QUEUING_FIFO — FIFO
Match.QUEUING_PRIORITY — Priority-based
Match.QUEUING_COMPARISON — Agent comparison
Match.QUEUING_LIFO — LIFO -
[Visible if Queuing (queue 2): Priority-based]
The priority of the incoming agent in the second stream (the greater the higher).Type: double
Default value: 0
Local variable: T2 agent — the agent -
[Visible if Queuing (queue 2): Agent comparison]
The Boolean expression to evaluate for each agent entering queue2. The expression compares this agent with the agents that are already in the queue and determines the queue position based on the results. If the expression returns true, the new agent is put closer to the queue head than the agent from the queue2 being compared with it.Type: boolean
Local variables:
T2 agent1 — the incoming agent
T2 agent2 — the agent being compared with the incoming agent - Enable exit on timeout (1)
-
If the option is selected (true), the timeout option for queue1 is on. After spending the specified time in queue1, the agent will leave the block through the outTimeout1 port.
Name: enableTimeout1
Type: boolean
Default value: false -
[Visible if the Enable exit on timeout (1) option is selected]
The expression evaluated to obtain the timeout time for the agent in queue1.Type: double
Local variable: T1 agent — the agent - Enable exit on timeout (2)
-
If the option is selected (true), the timeout option for queue2 is on. After spending the specified time in queue2, the agent will leave the block through the outTimeout2 port.
Name: enableTimeout2
Type: boolean
Default value: false -
[Visible if the Enable exit on timeout (2) option is selected]
The expression evaluated to obtain the timeout time for the agent in queue2.Type: double
Local variable: T2 agent — the agent - Enable preemption (1)
-
If the option is selected (true), the agents are placed in queue1 according to their priorities and may be preempted by agents with higher priorities.
Name: enablePreemption1
Type: boolean
Default value: false - Enable preemption (2)
-
If the option is selected (true), the agents are placed in queue2 according to their priorities and may be preempted by agents with higher priorities.
Name: enablePreemption2
Type: boolean
Default value: false - Restore agent location on exit
-
If the option is selected, after being animated in the Agent location (queue1, queue 2) shapes, the agents will return to their original location (node or path) where they were before entering this block.
Name: restoreEntityLocationOnExit
Type: boolean
Default value: true - Force statistics collection
-
This block contains two internal queues that collect queue size statistics. If the statistics collection is turned off for all Process Modeling Library blocks in the model by the PMLSettings block, this option enables you to override this setting and collect the statistics for this specific block. Otherwise, statistics are collected regardless of this setting.
Name: forceStatisticsCollection
Type: boolean
Default value: false
- On enter (1)
-
The code executed when the agent enters the block through the in1 port (and has been placed in queue1).
Local variable: T1 agent — the agent
- On enter (2)
-
The code executed when the agent enters the block through the in2 port (and has been placed in queue2).
Local variable: T2 agent — the agent
- On match
-
The code executed for the two agents that match each other.
Local variables:
T1 agent1 — the current agent in queue1
T2 agent2 — the current agent in queue2 - On exit (1)
-
The code executed when the agent in the first stream that was matched exits the block.
Local variable: T1 agent — the agent
- On exit (2)
-
The code executed when the agent in the second stream that was matched exits the block.
Local variable: T2 agent — the agent
- On exit (timeout) (1)
-
[Visible if the Timeout (1) option is selected]
The code executed when the agent exits through the outTimeout1 port as a result of waiting too long.Local variable: T1 agent — the agent - On exit (timeout) (2)
-
[Visible if the Timeout (2) option is selected]
The code executed when the agent exits through the outTimeout2 port as a result of waiting too long.Local variable: T2 agent — the agent - On exit (preempted) (1)
-
[Visible if the Enable preemption (1) option is selected]
The code executed when the agent exits through the outPreempted1 port as a result of preemption.Local variable: T1 agent — the agent - On exit (preempted) (2)
-
[Visible if the Enable preemption (2) option is selected]
The code executed when the agent exits through the outPreempted2 port as a result of preemption.Local variable: T2 agent — the agent
| Function | Description |
|---|---|
| int size1() | Returns the number of agents in the queue1 queue. |
| int size2() | Returns the number of agents in the queue2 queue. |
| T1 remove1(T1 agent) |
Removes the specified agent from the queue1 and returns it. If the agent is not contained in the queue, returns null. agent — the agent to remove |
| T2 remove2(T2 agent) |
Removes the specified agent from the queue2 and returns it. If the agent is not contained in the queue, returns null. agent — the agent to remove |
| boolean isStatisticsCollected() | Returns true if the block collects statistics. |
- Queue queue1
- The upper internal queue.
- Queue queue2
- The lower internal queue.
- in1
- The first input port.
- in2
- The second input port.
- out1
- The first output port
- out2
- The second output port.
- outTimeout1
- The output port for agents exiting the first queue due to a timeout.
- outTimeout2
- The output port for agents exiting the second queue due to a timeout.
- outPreempted1
- The output port for agents exiting the first queue due to preemption.
- outPreempted2
- The output port for agents exiting the second queue due to preemption.
-
How can we improve this article?
-