AnyLogic
Expand
Font size

Match

Synchronizes two streams of agents by matching pairs according to a given criteria. The agents that have not yet been matched are stored in two queues (one for each stream). Once the new agent arrives at either of the input ports, it is checked for match against all agents in the queue for the other stream. If the match is found, onMatch is executed and both agents exit the Match block at the same time. The queues can be fully customized (timeout, priorities, preemption, etc.).

The default match condition is true. It means any two agents match, so the Match block works as a pure stream synchronizer: it will output pairs of agents.

Suppose agents in one of the streams are of type Passenger and in the other — Baggage, both types have field id. Then to match passenger with his baggage item you may write agent1.id == agent2.id (provided the generic parameters of Match are Passenger and Baggage).

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

Parameters

Match condition
Condition evaluated for a pair (just arrived agent, an agent in the opposite queue) when the new agent arrives. Once the new agent arrives at either of the input ports, it is checked for match against all agents in the queue for the other stream. If the match is found, the On match action is executed and both agents exit the block at the same time.
Value type: boolean
Local variables:
T1 agent1 — the agent in queue1.
T2 agent2 — the agent in queue2.
Default value: true
Capacity (1)
[Visible if Maximum capacity (1) is not chosen]
The capacity of the first queue.
Syntax: int capacity1
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 maximum possible (limited by Integer.MAX_VALUE).
Syntax: boolean maximumCapacity1
Set new value at runtime: set_maximumCapacity1(new value)
Capacity (2)
[Visible if Maximum capacity (2) is not chosen]
The capacity of the second queue.
Syntax: int capacity2
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 maximum possible (limited by Integer.MAX_VALUE).
Syntax: boolean maximumCapacity2
Set new value at runtime: set_maximumCapacity2(new value)
Agent location (queue 1)
Space markup shape (node or path) where the agents are located while being in the queue1.
Syntax: AnimationStaticLocationProvider entityLocation1
Agent location (queue 2)
Space markup shape (node or path) where the agents are located while being in the queue2.
Syntax: AnimationStaticLocationProvider entityLocation2

Advanced

Queuing (queue 1)
The queuing discipline for the first queue. Possible disciplines are:
FIFO — First In, First Out. The default policy. The first stored agent will be the first agent to retrieve.
Priority-based — The agents will be placed into the queue according to their priorities (defined in the Agent priority (1) field below).
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 finds the place depending on the results.
LIFO — Last In, First Out. The last stored agent will be the first agent to retrieve.
Syntax: Queue.QueuingMode queuing1
Valid values:
Match.QUEUING_FIFO — FIFO
Match.QUEUING_PRIORITY — Priority-based
Match.QUEUING_COMPARISON — Agent comparison
Match.QUEUING_LIFO — LIFO
Agent priority (1)
[Visible if Queuing (queue 1) is Priority-based]
The priority of the incoming agent in the first stream (the larger the higher).
Value type: double
Default value: 0
Local variable: T1 agent — the agent.
"agent1 is preferred to agent2" (1)
[Visible if Queuing (queue 1) is Entity comparison]
Here you specify the boolean expression that is evaluated for every agent getting into the queue1. The expression compares this agent with the agents that are already in the queue and finds the place depending 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.
Value 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 stored agent will be the first agent to retrieve.
Priority-based — The agents will be placed into the queue according to their priorities (defined in the Agent priority (2) field below).
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 finds the place depending on the results.
LIFO — Last In, First Out. The last stored agent will be the first agent to retrieve.
Syntax: Queue.QueuingMode queuing2
Valid values:
Match.QUEUING_FIFO — FIFO
Match.QUEUING_PRIORITY — Priority-based
Match.QUEUING_COMPARISON — Agent comparison
Match.QUEUING_LIFO — LIFO
Agent priority (2)
[Visible if Queuing (queue 2) is Priority-based]
The priority of the incoming agent in the second stream (the larger the higher).
Value type: double
Default value: 0
Local variable: T2 agent — the agent.
"agent1 is preferred to agent2" (2)
[Visible if Queuing (queue 2) is Agent comparison]
Here you specify the boolean expression that is evaluated for every agent getting into the queue2. The expression compares this agent with the agents that are already in the queue and finds the place depending 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.
Value 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 the queue1 is on. After spending the specified time in the queue1, the agent will leave the block through the outTimeout1 port.
Syntax: boolean enableTimeout1
Default value: false
Timeout (1)
[Visible if Enable exit on timeout (1) is selected] Expression evaluated to obtain the timeout time for the agent in queue1.
Value type: double
Local variable: T1 agent — the agent.
Enable exit on timeout (2)
If the option is selected (true), the timeout option for the queue2 is on. After spending the specified time in the queue2, the agent will leave the block through the outTimeout2 port.
Syntax: boolean enableTimeout2
Default value: false
Timeout (2)
[Visible if Enable exit on timeout (2) is selected]
Expression evaluated to obtain the timeout time for the agent in queue2.
Value type: double
Local variable: T2 agent — the agent.
Enable preemption (1)
If the option is selected (true), the agents are placed in the queue1 according to their priorities and may be preempted by the ones with higher priorities.
Syntax: boolean enablePreemption1
Default value: false
Enable preemption (2)
If the option is selected (true), the agents are placed in the queue2 according to their priorities and may be preempted by the ones with higher priorities.
Syntax: boolean enablePreemption2
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.
Syntax: boolean restoreEntityLocationOnExit
Default value: true
Force statistics collection
This block contains two internal queues that collect statistics on queue size. 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 (1)
Code executed when the agent enters the block via in1 (and has been placed in queue1).
Local variable: T1 agent — the agent.
On enter (2)
Code executed when the agent enters the block via in2 (and has been placed in queue2).
Local variable: T2 agent — the agent.
On match
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)
Code executed when the agent in the first stream that was matched exits the block.
Local variable: T1 agent — the agent.
On exit (2)
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 enabled]
Code executed when the agent exits via 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 enabled]
Code executed when the agent exits via outTimeout2 port as a result of waiting too long.
Local variable: T2 agent — the agent.
On exit (preempted) (1)
[Visible if the preemption 1 option is enabled]
Code executed when the agent exits via outPreempted1 port as a result of preemption.
Local variable: T1 agent — the agent.
On exit (preempted) (2)
[Visible if the preemption 2 option is enabled]
Code executed when the agent exits via outPreempted2 port as a result of preemption.
Local variable: T2 agent — the agent.

Functions

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.

Internal blocks

Queue queue1
The upper internal queue.
Queue queue2
The lower internal queue.

Ports

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 because of timeout.
outTimeout2
The output port for agents exiting the second queue because of timeout.
outPreempted1
The output port for agents exiting the first queue because of preemption.
outPreempted2
The output port for agents exiting the second queue because of preemption.
How can we improve this article?