redistribute Resources

Sorting Gates redistribute Resources without collecting them.

Sorting Gates have **Resource Connections** as outputs.

â€‹ Depending on the **Sorting Gate's distribution mode** AND its **Resource Connections' Labels**, it will sort the Resources going through them.

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

â€‹ E.g.: If there are 10 Resources going through a Gate in 1 Time 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' Labels.**

Here are all types of Sorting Gates and their expected actions.

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

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

â€‹ The **order** in which Resources are being sent towards their targets depends on the order in which these targets were added to the diagram.

â€‹ Here's what happens in the example above:

The sorting algorithm will be applied on each of the Resources going in

The first Resources will be redistributed towards the upper Pool (the one we first added to the diagram) and 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)

The rest of the Resources will go towards the other Pool. 3 parts out of 4 of 8 Resources (3/4 of 8)

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

â€‹ Here's an example:

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.

Pools cannot collect fractions of a Resource, therefore the algorithm will send 3 Resources towards the first Pool and 7 towards the second Pool during the first execution Time Step

On the next Time Step, it will send 2 Resources towards the 1st Pool and 8 towards the second

At the end of Time Step 2, the result will be 20 Resources perfectly distributed between the 2 Pools, according to their weights

A Deterministic Gate with Resource Connections as input and outputs, for which the Labels 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' Labels.

â€‹ 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 right. The Resources will also be redistributed weighted - see the example on the right.

â€‹ To better understand this, perform a Multiple Run on both examples above.

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 **normalise** the rates.

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

A Deterministic Gate with Resource Connections as input and outputs, for which the Labels 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/Time Step**.

â€‹ Each Resource that goes through a Gate within a Time Step will be given an order number (1st Resource, 2nd Resource, etc) and will be 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.

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

**Random Gates generate random values** which will determine the redistribution of incoming Resources.

â€‹ During execution, the Random Gate displays the random number it generated.

A Random Gate with Resource Connections as input and outputs, for which the Labels 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' Labels.

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 redistribute towards the second Resource Connection.

**Use the 2 pie charts below to visualise 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.

A Random Gate with Resource Connections as input and outputs, for which the Labels 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' Labels.

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 visualise 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, whilst all others will go through to the 60% weighted rate Pool.

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 **normalise** the rates. (See Deterministic Gates with probable outcome for how normalisation works)

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

â€‹ For each resource going through the Gate, the algorithm throws a die with a number of faces equal to the die set at diagram level (`Diagram Functional Panel > Dice`

) and then redistributes the Resources according to which condition the number on the die meets.

In this case, **the Gate displays the result of the die throw.**

â€‹ In the example above, the die is a D10. The throws that result in a number that's below 4 will go through the <4 branch, all else through the >=4 one.