Files
blog/content/quickfacts-1/index.md
2026-03-27 07:57:58 +01:00

334 lines
9.1 KiB
Markdown

+++
title = "Quickfacts - Part 1: The Mental Model"
date = 2026-04-02
description = "Building a Mental Model"
draft = true
[taxonomies]
categories = ["Programming"]
tags = ["Factorio", "Rust"]
[extra]
toc = true
+++
The first real entry in my series about my quickfacts project.
For a small introduction, see the [intro blogpost](@/quickfacts-intro/index.md)
<!-- more -->
# Idea
- Everything is a graph
- Each Entity is a node in the graph
- What extra information to include
- Each Edge represents that certain items can move from one node to the other
- Specify what items can move over the edge (for example because of filters)
- Outgoing and incoming priority
- Capacity ?
- What extra information to include
# Interactions
The Construction basically comes down to a large table mapping the different interactions between all the types of entities.
## Belts
For the purpose of my analysis, you can split a belt into the two sides, as they act independent of one another.
### Belt-Belt
Direct 1-to-1 connection, is the simplest and most common way two belts are connected.
In this configuration you have 1 belt basically forwarding everything onto another belt, where each side of the source belt feeds into the corresponding side of the target belt.
For example if you have a simple line of belts forming a long line, they are all direct 1-to-1 connected.
Sideloading, is a more special case. This happens when the target belt already has another belt connected and now the new source belt is connected from the side (as the name suggests).
In this configuration both sides of the source belt are going into one side of the target belt.
### Belt-Splitter
The splitter can only accept direct 1-to-1 style connections going into it, from belts or the output of underground belts.
The ouput of a splitter basically acts the same way as a normal belt would.
### Belt-UndergroundBelt
The input side of the underground supports direct 1-to-1 connections, if the other source belt is coming from the same direction (so no turn is being made).
The input can also be sideloaded, however opposed to normal belt sideloading, only the upstream side of the source belt will feed into the target belt and the other side of the source belt will not be connected.
The output again acts like a normal belt.
### Belt-Direct output machines (miner, recycler, etc.)
Sideloading
TODO What to do if at the "head" of a beltline
## Inserter
### Inserter-Belt
TODO
# Modelling
Each node essentially has a set of input and output "slots", which have different priorities.
Each slot can have filters attached, from both the upstream and downstream side.
Filters from the upstream side are mostly dependent on configuration, like filters on splitters.
Filters from the downstream dependent on their slot filters and also their type, like machines will apply filters to their upstream slots that constrain it to items that it needs/can process.
For transport nodes (belts, inserter, etc.) they should forward their downward filters and combine them with their own filters
To collect input items, a node goes through its input slots in decreasing priority and collects everything that fits its own criteria.
To distribute the items, a node goes through its output slots in decreasing priority and puts as many items as possible in that slot.
## Constraints
The idea with constraints is basically to have some logic formula that constraints the items and their rates along an edge.
So for example if an inserter has a filter configured, its constraints will only allow the specific items as configured by the filter.
Another example is an assembly machine, which will impose constraints on anything going into it, to only be the items that it needs for the recipe.
Constraints can then be propogated and combined upstream, so that an inserter going into an assembly machine also only selects the items that can actually go into that machine.
For propogation, the constraints will be combined by either an intersection or a union.
For example an inserter will perform an intersection, because it can only accept things that fit its specific configuration and any downstream configuration.
But a belt will perform a union, because might have constraints coming from inserters taking from them and downstream belts so the items can take either path.
Basically the constraints for every edge will be combined using an intersection with the constraints of the node itself, and then all downstream edge constraints will be combined using a union to form the final upstream constraint.
JOIN Operator: used to combine multiple "or" constraints, for example for combining downstream constraints.
This is done by adding all the limits for items together.
CHAIN Operator: used to combine multiple "and" constraints.
### Representation
A tree with 3 levels, each doing something different
The lowest level, selects by item.
The next level limits the rate per item.
The top level limits the total throughput.
### Examples
{% carousel() %}
{% carousel_item() %}
Before propogation
{% mermaid() %}
---
title: Inserter Feeding into Assembler
---
flowchart BT
subgraph assembler
direction BT
root_1["unlimited"]
1_first_limit["<= 5/s"]
1_first_items["iron"]
1_second_limit["<= 10/s"]
1_second_items["copper wire"]
1_first_limit --> root_1
1_second_limit --> root_1
1_first_items --> 1_first_limit
1_second_items --> 1_second_limit
end
subgraph inserter with iron filter
direction BT
root_2["total <= 20/s"]
2_first_limit["<= 20/s"]
2_first_items["iron"]
2_first_limit --> root_2
2_first_items --> 2_first_limit
end
{% end %}
{% end %}
{% carousel_item() %}
After first propogation step
{% mermaid() %}
---
title: Inserter Feeding into Assembler
---
flowchart BT
subgraph assembler
direction BT
root_1["unlimited"]
1_first_limit["<= 5/s"]
1_first_items["iron"]
1_second_limit["<= 10/s"]
1_second_items["copper wire"]
1_first_limit --> root_1
1_second_limit --> root_1
1_first_items --> 1_first_limit
1_second_items --> 1_second_limit
end
subgraph inserter with iron filter
direction BT
root_2["total <= 20/s"]
2_first_limit["<= 20/s && <= 5/s"]
2_first_items["iron"]
2_second_limit["<= 0/s && <= 10/s"]
2_second_items["copper wire"]
2_first_limit --> root_2
2_second_limit --> root_2
2_first_items --> 2_first_limit
2_second_items --> 2_second_limit
end
{% end %}
{% end %}
{% carousel_item() %}
After second propogation step
{% mermaid() %}
---
title: Inserter Feeding into Assembler
---
flowchart BT
subgraph assembler
direction BT
root_1["unlimited"]
1_first_limit["<= 5/s"]
1_first_items["iron"]
1_second_limit["<= 10/s"]
1_second_items["copper wire"]
1_first_limit --> root_1
1_second_limit --> root_1
1_first_items --> 1_first_limit
1_second_items --> 1_second_limit
end
subgraph inserter with iron filter
direction BT
root_2["total <= 20/s"]
2_first_limit["<= 5/s"]
2_first_items["iron"]
2_second_limit["<= 0/s"]
2_second_items["copper wire"]
2_first_limit --> root_2
2_second_limit --> root_2
2_first_items --> 2_first_limit
2_second_items --> 2_second_limit
end
{% end %}
{% end %}
{% carousel_item() %}
After final propogation step
{% mermaid() %}
---
title: Inserter Feeding into Assembler
---
flowchart BT
subgraph assembler
direction BT
root_1["unlimited"]
1_first_limit["<= 5/s"]
1_first_items["iron"]
1_second_limit["<= 10/s"]
1_second_items["copper wire"]
1_first_limit --> root_1
1_second_limit --> root_1
1_first_items --> 1_first_limit
1_second_items --> 1_second_limit
end
subgraph inserter with iron filter
direction BT
root_2["total <= 20/s"]
2_first_limit["<= 5/s"]
2_first_items["iron"]
2_first_limit --> root_2
2_first_items --> 2_first_limit
end
{% end %}
{% end %}
{% end %}
# Examples
## Belt Line with one slower belt
{% carousel() %}
{% carousel_item() %}
Initial configuration
{% mermaid() %}
flowchart LR
Src
T1
T2
T3
Output
Src -->|x <= 20| T1
T1 -->|x <= 20| T2
T2 -->|x <= 10| T3
T3 -->|x <= 20| Output
{% end %}
{% end %}
{% carousel_item() %}
Raw Constraint Propogation
{% mermaid() %}
flowchart LR
Src
T1
T2
T3
Output
Src -->|x <= 20 && x <= 20 && x <= 10 && x <= 20| T1
T1 -->|x <= 20 && x <= 10 && x <= 20| T2
T2 -->|x <= 10 && x <= 20| T3
T3 -->|x <= 20| Output
{% end %}
{% end %}
{% carousel_item() %}
Simplified Constraint Propogation
{% mermaid() %}
flowchart LR
Src
T1
T2
T3
Output
Src -->|x <= 10| T1
T1 -->|x <= 10| T2
T2 -->|x <= 10| T3
T3 -->|x <= 20| Output
{% end %}
{% end %}
{% end %}
## TMP
{% carousel() %}
{% carousel_item() %}
Initial Configuration
{% mermaid() %}
flowchart TD
Src
T1
Splitter
T2
T3
Output1
Output2
Src --> T1
T1 --> Splitter
Splitter --> T2
Splitter --> T3
T2 --> Output1
T3 --> Output2
{% end %}
{% end %}
{% carousel_item() %}
Raw Propogation
{% end %}
{% end %}
# Conclusion