Page 1 of 1

Even split of remainder

Posted: Mon May 24, 2021 4:14 am
by Impatient
I have 4 train unloading stations (S1, ... S4). Equally named to unload the same things. And depending on demand I calculate how many supply trains (T) should go there. As I want to optimize throughput, I am distributing the supply trains to the 4 stations as equal as possible, using the train limit feature and a combinator setup.

First I do

Code: Select all

S1..S4 = T / 4
to get a rough equal split.

After that I only need to split the remainder evenly to some of the stations. I do

Code: Select all

R4 = T % 4
Split3 = R4 / 3
S1..S3 += Split3
Because if R4 was 3 then the Split3 is 1 and the remainder will be split evenly among S1 ... S3. If it was lower than 3 then the result is 0 and there is no threeway split.

In a next iteration I do

Code: Select all

R3 = R4 % 3
Split2 = R3 / 2 
S1..S2 += Split2
If R3 was 2, these 2 will be split to S1 and S2, if it was 1 then there is no twoway split.

In the last iteration I just do

Code: Select all

R2 = R3 % 2
S1 += R2
This way I take care of all possible remainder cases of 1,2 and 3.

This is how it looks:
remainder of 4.jpg
remainder of 4.jpg (90.64 KiB) Viewed 3560 times
And this is the blueprint:






Do you have any ideas/knowledge if this can be done with less combinators? Thanks!

Re: Even split of remainder

Posted: Mon May 24, 2021 6:44 am
by SoShootMe
Impatient wrote: Mon May 24, 2021 4:14 am Do you have any ideas/knowledge if this can be done with less combinators? Thanks!
There's probably a better way, but a simple approach is to use decider combinators to add one to some of output signals, according to the remainder:


Re: Even split of remainder

Posted: Mon May 24, 2021 11:50 am
by disentius
Hmm... It seems you assume consumption of the materials is always equal for each unload station.
Why not look at the # of items in each station to determine where the next rain has to go?
i am building a trainbase where all load and unload stations have the same name per material shipped, and use trainlimit 0/1 for each. For the unload stations I calculated (roughly) how much time the trains need to get to their destination, and set the minimum buffer needed to bridge that gap based on full throughput accordingly.

Re: Even split of remainder

Posted: Mon May 24, 2021 1:57 pm
by Impatient
Ah, yes of course. Logic instead of arithmetic. This simplifies the combinator setup considerably:
evenSplitRemainderOf4.2.jpg
evenSplitRemainderOf4.2.jpg (45.35 KiB) Viewed 3498 times

Re: Even split of remainder

Posted: Mon May 24, 2021 2:48 pm
by Impatient
disentius wrote: Mon May 24, 2021 11:50 am
That is off topic, but since I failed to hide the context good enough to not make readers curious :D :
Context

Re: Even split of remainder

Posted: Mon May 24, 2021 4:03 pm
by disentius
Aha, context is king:)

So each station has to have a guaranteed throughput of 3K/s -> 1 train every 16.6 seconds. Correct?

Re: Even split of remainder

Posted: Mon May 24, 2021 4:30 pm
by Impatient
More off topic

Re: Even split of remainder

Posted: Mon May 24, 2021 4:54 pm
by disentius
Wandering mind.... :lol: Something along the lines of trainlimits adjusted per time passed.


If you have enough trains and an oversupply of steam, you could also use a constant limit of 2. with 1-2 trains you can get each train its own stacker for the second one if you have room.
2021-05-24 18_53_23-Factorio 1.1.34.png
2021-05-24 18_53_23-Factorio 1.1.34.png (397.51 KiB) Viewed 3474 times

Re: Even split of remainder

Posted: Mon May 24, 2021 5:05 pm
by Impatient
even more off topic

Re: Even split of remainder

Posted: Tue May 25, 2021 1:52 pm
by disentius
You are right. As I said, wandering mind....
We ll discuss NxN stations in another topic.