Balacing items between multiple warehouses.

Looking for a mod? Have a review on a mod you'd like to share?
Post Reply
mindcraft
Manual Inserter
Manual Inserter
Posts: 2
Joined: Thu Apr 20, 2023 8:55 pm
Contact:

Balacing items between multiple warehouses.

Post by mindcraft »

I want to create a train station with, in my example, with 2 stops. Each train stop will unload mixed items to their respective warehouse. The warehouses must then evenly distribute the items between them.

This is what I came up with: https://factoriobin.com/post/HlKhMJiB (note: this uses AAI warehouses and miniloaders mod)

It does work how I intended it to work, but the design never stays idle. Instead a few items are being shuffle around (I did manage to get it once to stay idle though).

Is there a way to make the design better?




The concept I adopted, is to great a circuit segment between 2 warehouses, that balances items between those two. Therefor:
- the contents of a warehouse is the sum of the items in the warehouse and on the belt that outputs items from that warehouse
- the contents of two warehouses are fed to an arithmetic combinator that does /-2 and outputs the signal to a decider combinator
- the decider combinator outputs 1 "each" if "each" > 6 (i don't know what a good number would be here); the output of the decider combinator is sent to the filter miniloader, which are configured to "set filter" and "read content: pulse"
- the inputs for the decider combinator is the output of the /-2 divider (negative value) and the contents of the associated warehouse (positive value)
- when the inputs to the decider combinator add up to >6, this sets the filter for the filter miniloaders and they dump those items on the belt; a signal is also sent to a memory cell, associated to that warehouse
- when the items arrive to the destination warehouse, they are loaded with miniloaders, configured to only "read content: pulse", and a signal is sent to an arithmetic combinator configured to "each"/-1 output "each"; this signal is then sent to the input of the memory cell of the other warehouse.

mrvn
Smart Inserter
Smart Inserter
Posts: 5710
Joined: Mon Sep 05, 2016 9:10 am
Contact:

Re: Balacing items between multiple warehouses.

Post by mrvn »

The first thing that comes to mind is: WHY?

Simply unload both train stops into a single warehouse. Problem solved.

Otherwise there is a much simpler solution if you only have a few items. Create a filtered loader for each item type at each warehouse with a belt connected to it. Connect both warehouses with a green wire to a arithmetic combinator "each / -2 = each" and connect that to all the belts again with a green wire. Then for each warehouse connect the warehouse with the belts in front of it and set them to enable if "item > 10". Last connect the belts to loaders going into the other warehouses. Unfortunately this only works for few known items in each warehouse.

If you have many items or don't know what items there will be then you have to use filter inserters. The wiring is much like the previous but you also need to subtract 10 (or some other small offset) from each item count to prevent items from getting swapped around over and over. So connect both warehouses to a decider combinator (with the green wire you already have) set to "each > 0: each = 1". Connect that to a arithmetic combiantor "each * -10 = each" and connect that to all filter inserters (again the green wire you already have). Then you can set the filter inserters to "set filter" and they will remove any item from a warehouse that has a count of 10 above average. Put that on a belt and into the other warehouse.

mindcraft
Manual Inserter
Manual Inserter
Posts: 2
Joined: Thu Apr 20, 2023 8:55 pm
Contact:

Re: Balacing items between multiple warehouses.

Post by mindcraft »

mrvn wrote:
Mon Apr 24, 2023 1:17 pm
The first thing that comes to mind is: WHY?
I'm playing Space Exploration with Krastorio 2 and this station will be my main hub, with rockets, mall and all the things I may need.
My thought is that, with this approach, I can slap down a sixth warehouse (and so on), put filter inserters that pull out the items I may need for a build and be done with.

It's sort of like a main bus, but the belts are not dedicated to one item.

The more resource intensive items (ex: low density structures, heat shields) will be made at a dedicated area and shipped here via train.
mrvn wrote:
Mon Apr 24, 2023 1:17 pm
If you have many items or don't know what items there will be then you have to use filter inserters. The wiring is much like the previous but you also need to subtract 10 (or some other small offset) from each item count to prevent items from getting swapped around over and over. So connect both warehouses to a decider combinator (with the green wire you already have) set to "each > 0: each = 1". Connect that to a arithmetic combiantor "each * -10 = each" and connect that to all filter inserters (again the green wire you already have). Then you can set the filter inserters to "set filter" and they will remove any item from a warehouse that has a count of 10 above average. Put that on a belt and into the other warehouse.
I think this is what I did. I had to also keep track of the items traveling on the belt, otherwise, the /-2 of the two warehouse would just go down and down, until the items arrived at the destination warehouse.
This would cause the providing warehouse to send more and more items.

mrvn
Smart Inserter
Smart Inserter
Posts: 5710
Joined: Mon Sep 05, 2016 9:10 am
Contact:

Re: Balacing items between multiple warehouses.

Post by mrvn »

mindcraft wrote:
Mon Apr 24, 2023 7:08 pm
mrvn wrote:
Mon Apr 24, 2023 1:17 pm
The first thing that comes to mind is: WHY?
I'm playing Space Exploration with Krastorio 2 and this station will be my main hub, with rockets, mall and all the things I may need.
My thought is that, with this approach, I can slap down a sixth warehouse (and so on), put filter inserters that pull out the items I may need for a build and be done with.

It's sort of like a main bus, but the belts are not dedicated to one item.

The more resource intensive items (ex: low density structures, heat shields) will be made at a dedicated area and shipped here via train.
mrvn wrote:
Mon Apr 24, 2023 1:17 pm
If you have many items or don't know what items there will be then you have to use filter inserters. The wiring is much like the previous but you also need to subtract 10 (or some other small offset) from each item count to prevent items from getting swapped around over and over. So connect both warehouses to a decider combinator (with the green wire you already have) set to "each > 0: each = 1". Connect that to a arithmetic combiantor "each * -10 = each" and connect that to all filter inserters (again the green wire you already have). Then you can set the filter inserters to "set filter" and they will remove any item from a warehouse that has a count of 10 above average. Put that on a belt and into the other warehouse.
I think this is what I did. I had to also keep track of the items traveling on the belt, otherwise, the /-2 of the two warehouse would just go down and down, until the items arrived at the destination warehouse.
This would cause the providing warehouse to send more and more items.
Hence the "10" in my setup. Only start sending when there is a lot of inbalance and then it goes a fair bit over to the other side. 10 might not sound much but if you balance between 4 warehouses that 10 becomes more like 50 because 10 items in one warehouse changes the average much less.

Post Reply

Return to “Questions, reviews and ratings”