AnyLogic
Expand
Font size

PedSelectOutput

Routes the incoming pedestrians to one of several (up to five) processes depending on specified ratios or conditions. Each process has to be defined with a flowchart connected to one of the block’s output ports.

The block works in three modes: Probabilities, Conditions, or Exit number.

  • In the Probabilities mode, you provide 5 probabilities for five exits (if their sum does not equal 1, they are normalized). The exit the pedestrian takes is defined randomly according to the specified probabilities. For example, if, Probability 1 is 5, Probability 2 is 1, and Probability 3 is 4, pedestrians will use the out1, out2, and out3 ports with average probabilities of 0.5, 0.1, and 0.4.
  • In the Conditions mode, you provide 4 conditions. When a pedestrian arrives, the conditions are evaluated sequentially one by one. If condition 1 is true, the pedestrian leaves the block through the out1 port, otherwise, condition 2 is evaluated, and so on. If all conditions are false, the pedestrian exits via the out5 port — the default exit. The result of the condition’s evaluation may depend on the properties and attributes of the pedestrian — as well as on other external factors.
  • In the Exit number mode, you provide an expression that returns integer numbers in the [1..5] range. When the pedestrian enters the block, the expression is evaluated, and the resulting number determines the number of the output port the pedestrian should use to leave this block. The result of the condition’s evaluation may depend on the properties and attributes of the pedestrian — as well as on other external factors.
In the Probabilities and Conditions modes, it is not necessary to define all five chance ratios or all four conditions. If you want to route pedestrians to only one of two ports, you will only need to define two corresponding parameters.

Use this block to sort pedestrians according to certain criteria, randomly split the pedestrian flow, and so on.

Pedestrians spend zero time in the PedSelectOutput block.

Routing in SelectOutput blocks

The output port that the agent will take in the PedSelectOutput block is determined when the agent completes its operation in the preceding flowchart block, not when the agent enters the PedSelectOutput block. This is necessary because agents do not spend any time in PedSelectOutput and are immediately forwarded to the next one. Therefore, we need to determine in advance whether the next block can accept the agent.

For example, the next block could be a closed Hold block or a full Queue. The availability of the output route and the output selection are calculated before the agent exits the current block.

By default, the expression that defines the routing condition or an exit number of such a block is evaluated at this earlier point, before the On exit action of the preceding block is executed. As a result, any logic you place in that On exit action (such as changing a custom agent attribute used in the routing condition) will not affect the routing outcome.

For pedestrian groups, the routing condition is only evaluated for the first agent in the group. The same route is then used for the rest of the group without additional checks.

To ensure your routing logic works correctly:

  • Move any logic that affects routing from the On exit action to the On at exit action, if the block provides one. This action is executed after the block finishes its operation, but before the routing decision is made.
  • If this is not possible, insert a Delay block with zero Delay time before the PedSelectOutput block to separate the change and the routing decision into two steps.
  • Alternatively, if your routing logic relies on stochastic or volatile expressions, such as calls of the randomTrue() function or expressions dependent on the current state of other blocks or changes in the agent properties, enable the Condition is stochastic or volatile option in the properties of PedSelectOutput. By default, this option is disabled: the routing expressions can be evaluated twice, when the agent finishes the operation in the preceding block and when the agent actually leaves the preceding block. If the value of the expression changes between the two evaluations, AnyLogic raises an error, indicating that the agent can no longer follow the initially selected route.
    Enabling the Condition is stochastic or volatile option disables this check, and the agent will follow the route selected during the first evaluation, even if the result of the expression has changed by the time the agent proceeds.
In probability-based routing mode, the Condition is stochastic or volatile option is ignored. The routing decision is made once by selecting the route according to the specified probabilities when the agent finishes its operation in the previous block. However, the actual probability values themselves are evaluated twice: first, when the decision is made, and again right before the agent leaves the preceding block. If the probabilities have changed between these two evaluations, AnyLogic raises an error because the agent might follow a route that no longer matches the original decision.

Parameters

Use
Defines whether pedestrians will be routed randomly according to specified Probabilities, depending on the specified Conditions, or the specified expression will be evaluated to get the number of the output port the pedestrian will use to leave the block.
Syntax: PedSelectOutput.Type useConditions
Get value: type
Set new value dynamically:set_type(new value)
Valid values:
PedSelectOutput.TYPE_PROBABILITIES — for the Probabilities mode
PedSelectOutput.TYPE_CONDITIONS — for the Conditions mode
PedSelectOutput.TYPE_EXIT_NUMBERS — for the Exit number mode
Probability 1, 2, … 5
[Visible if Use: Probabilities]
Ratio of pedestrian flow that exits the block via the port out1, out2, ….
Value type: double
Local variable: ped — the pedestrian
Condition 1, 2, … 5
[Visible if Use: Conditions]
Condition that checks whether the pedestrian should leave this block via the out1, out2, ... port. If Condition 1 is true, the pedestrian leaves the block via out1, if not, Condition 2 is checked. If Condition 2 is true, the pedestrian leaves the block via out2, if not, the next condition is checked, and so on. If no conditions are met, the pedestrian leaves the block via the last out5 port.
Value type: boolean
Local variable: ped — the pedestrian
Exit number [1 .. 5]
[Visible if Use: Exit number]
Expression evaluating the index of the output port that the agent should take to leave this block. The expression may depend on the agent as well as on any external factors. The result should lie in the [1..5] range.
Value type: int
Local variable: ped — the pedestrian
Default value: uniform_discr( 1, 5 ) — does not depend on the pedestrian; simply splits the pedestrian flow into five equal parts.
Condition is stochastic or volatile
[Visible when Use: Conditions or Exit number]
Specifies that the condition or exit number value may yield different results when evaluated at different times for the same agent. For example, this may occur if the condition uses random functions or depends on the state of other flowchart blocks.
The expression is checked twice by default: first, when the agent is ready to exit the preceding block and, if the next block was busy and could not accept the agent immediately, possibly again later. A built-in check compares the two evaluations and raises an error if the result has changed.
Enable this option to suppress the check and avoid errors in models where such variability is expected. The final routing decision will be based on the most recent evaluation when the agent leaves the block.
Value type: boolean
Default value: false — the expression is assumed to be static between evaluations

Actions

On enter
Code executed when the pedestrian enters the block.
Local variable: ped — the pedestrian
On exit 1, 2, …
Code executed when the pedestrian exits the block via port out1, out2, ….
Local variable: ped — the pedestrian

Ports

in

The input port.

out1, out2, out3, out4, out5

Output ports.

How can we improve this article?