Sorting Gates

8 min read

Tip

Sorting Gates redistribute Resources without collecting them. They have Resource Connections as outputs.

Depending on the Sorting Gate’s distribution mode AND its Resource Connections’ Formula, it will sort the Resources going through them.

Warning

The algorithm is applied for each Resource going through the Gate, even if there are more than 1 Resources going through it in one Step.

​E.g.: If there are 10 Resources going through a Gate in 1 Step, each of these Resources will be redistributed according to the algorithm set by the Gate’s distribution mode, Output Connections’ type, and Output Connections’ Formulas.

Sorting Gates types and their expected actions

Deterministic

Tip

Deterministic Sorting Gates sort Resources according to the Formulas on their output Resource Connections.

A Deterministic Gate has Resource Connections as input and outputs. The Formulas on the Output Resource Connections have numeric values that set the weights for the redistribution algorithm.

Warning

The order in which Resources are being sent towards their targets depends on the order in which the resource connections going from the gate towards its targets were added to the diagram.

Please take a look at examples below and notice the difference between the two:

Here’s how the sorting algorithm works:

  1. The sorting algorithm will be applied to each of the Resources going in
  2. The first Resources will be redistributed towards the upper Pool, through the connection that was added first. They will continue to be directed towards it until the weight is reached. In this case, the first 2 Resources will go towards the first Pool. 1 part out of 4 (1+3) of 8 Resources (1/4 of 8)
  3. The rest of the Resources will go towards the other Pool. 3 parts out of 4 of 8 Resources (3/4 of 8)
Note

If the Resources and their weights do not result in an integer amount of Resources, the algorithm will “even the score” throughout multiple Steps.

Here’s an example:

  1. Mathematically, the redistribution of the 10 Resources would amount to 10*1/4 (2.5) Resources towards the first Pool and 10*3/4 (7.5) Resources towards the second.
  2. Pools cannot collect fractions of a Resource. Therefore the algorithm will send a combination of either 3 and 7 Resources OR 2 and 8 Resources during each consecutive Step of the execution.
  3. In the example above, in the model on the right, we use Sinks to empty the pools at the beginning of each step – Go through this example using Step Play.
Tip

A Deterministic Gate with Resource Connections as input and outputs, for which the Formulas on the Output Resource Connections have weighted rate values that set the probabilities AND the weights for the redistribution algorithm.

The order in which the Resources are redistributed towards the targets is given by the probabilities on the Output Resource Connections’ Formulas.

Each Resource going through the Gate will be redistributed according to the probabilities on the output Resource Connections – this is obvious in the example on the left. The Resources will also be redistributed weighted – see the example on the right.

To better understand this, add this example to your Machinations and perform a Prediction on both examples above.

Warning

If the SUM of the weighted rates is below 100%, the algorithm will drop/destroy the Resources that exceed the redistribution rates.

If the SUM of the weighted rates exceeds 100%, the algorithm will normalize the rates.

In the example above, the working rates are normalized, and become: (50/130*100)%; (60/130*100)% and (20/130*100)%.

Tip

A Deterministic Gate with Resource Connections as input and outputs, for which the Formula on the Output Resource Connections have conditional values that set the rules for the redistribution algorithm.

Deterministic Gates with conditional outcomes take into account the sequence of Resources/Step.

Each Resource that goes through a Gate within a Step will be given an order number (1st Resource, 2nd Resource, etc.) and redistributed accordingly.

Here’s what happens: the algorithm redistributes each Resource depending on its order number – the first 3 Resources go through the <4 Connection, while everything else goes through the >=4 Connection.

Note

In the example above, changing the Gate’s Input Connection Formula so that >4 Resources are produced and redistributed during a Step will determine the algorithm to ALWAYS redistribute the Resources towards the >=4 Connection.

Pro tip: Deterministic sorting gates with conditional outputs can be configured as a resource generator. If multiple conditions on the sorting gate’s outputs are met simultaneously, the gate will generate resources for all active outputs.

Since conditional sorting gates take into account the sequence of input resources, each simulation step will produce 9 output resources even if its input is set to 5:
– Top branch = 4 output resources; 4 numbers are larger than 1 in the input sequence 1..5;
– Middle branch = 3 output resources; 3 numbers are larger than 2 in the input sequence 1..5;
– Bottom branch = 4 output resources; 2 numbers are larger than 3 in the input sequence 1..5;

Additionally, if you want to take all gate inputs and generate the same amount on each output, you can use a sorting gate with the formula >0 on all outputs of the gate. Press play to see it in action:

Random

Tip

A Random Gate with Resource Connections as input and outputs, for which the Formulas on the Output Resource Connections have numeric values that set the weights for the redistribution algorithm.

For each Resource passing through the Gate, the algorithm will throw a die with a number of faces equal to the SUM of weights on the Output Connections. This will determine towards which Connection the Resource will be redistributed also taking into account the weights determined by the Connections’ Formulas.

A Source sends one Token each Step through a Random Gate whose outputs are weighted 1 and 3: about one Token in four goes to Pool A and three in four to Pool B (3 and 9 after 12 Steps here).A Source sends one Token each Step through a Random Gate whose outputs are weighted 1 and 3: about one Token in four goes to Pool A and three in four to Pool B (3 and 9 after 12 Steps here).
Note

The number displayed by the Gate during execution is NOT the result of the die throw, but the order number of the branch the Resource will be distributed through.

Here’s what happens in the example above: For each Resource, the algorithm uses a die with 4 faces (1+3). If the die throws 1, the Gate redistributes the Resource towards the 1st Resource Connection. If the die throws either one of 2, 3, or 4, the Resource will be redistributed towards the second Resource Connection.

Use the pie charts below to visualize the algorithm. The pie chart in the middle represents the 4-faced die and the equal chances for it to throw either one of the numbers on it: 25% chance for each face. The outer pie chart’s sections represent the weights according to which the Resources will be redistributed towards the Output Connections, considering the result of the die throw.

The outer pie chart’s sections represent the weights according to which the Resources will be redistributed towards the…
Tip

A Random Gate with Resource Connections as input and outputs, for which the Formulas on the Output Resource Connections have percentage values.

For each Resource passing through the Gate, the algorithm throws a 100-faced die. This will determine towards which Connection the Resource will be redistributed also taking into account the weighted rates on the Connections’ Formulas.

A Source sends one Token each Step through a Random Gate whose outputs are 20% and 80%: about one Token in five goes to Pool A and four in five to Pool B (3 and 12 after 15 Steps here).A Source sends one Token each Step through a Random Gate whose outputs are 20% and 80%: about one Token in five goes to Pool A and four in five to Pool B (3 and 12 after 15 Steps here).
Note

The number displayed by the Gate during execution is NOT the result of the die throw, but the order number of the branch the Resource will be distributed through.

Here’s what happens in the example above: For each Resource, the algorithm throws the 100-faced die, any result that falls between 1 and 40 will go through the first Resource Connection, all else will go through the second connection.

Same as with the previous example, consider these 2 pie charts to visualize the algorithm.

Same as with the previous example, consider these 2 pie charts to visualize the algorithm

The 100-faced die is the pie chart in the middle, and each of its sections represents the probability of the die to throw 1 of its faces (1% for each). All faces between 1-40 will be redistributed towards the 40% weighted rate Pool, while all others will go through to the 60% weighted rate Pool.

Warning

If the SUM of the weighted rates is below 100%, the algorithm will drop/destroy the Resources that exceed the redistribution rates.

If the SUM of the weighted rates exceeds 100%, the algorithm will normalize the rates. (See Deterministic Gates with probable outcomes for how normalization works)

Tip

A Random Gate with Resource Connections as input and outputs for which the Formulas on the Output Resource Connections have conditional values.

For each resource going through the Gate, the algorithm throws a six-sided die by default and then redistributes the Resources according to which condition the number on the die meets.

A Source sends one Token each Step to a Dice Gate; the Gate rolls a six-sided die for each Token and sends it along the connection whose condition is true: less than 4 into Below 4, or 4 and above into 4 or more.A Source sends one Token each Step to a Dice Gate; the Gate rolls a six-sided die for each Token and sends it along the connection whose condition is true: less than 4 into Below 4, or 4 and above into 4 or more.
Note

In this case, the Gate does not show the number it rolled. Each Output Connection shows true or false for the roll, and the Resource goes through the one that reads true.

The throws that result in a number that’s below 4 will go through the <4 branch, all else through the >=4 one.