## Combinator Help - Even Distribution of Trains and Priority Levels on Stations

Don't know how to use a machine? Looking for efficient setups? Stuck in a mission?
Durr
Inserter
Posts: 42
Joined: Fri Mar 22, 2019 8:12 pm
Contact:

### Combinator Help - Even Distribution of Trains and Priority Levels on Stations

tldr: Can someone help me figure out how the combinators in this setup works, and if there's a way to optimize them?

I was tinkering with some combinators yesterday for a few hours and eventually stumbled upon a configuration that did what I wanted it to do. But looking at it now, I'm not entirely sure how it actually works.

The concept is that I have all my receiving stations for a particular product named the same ([Iron] Receiving), but I want to make sure all of them are serviced once before any station is serviced for a second time. This was easy enough to do by outputting a value of 1 on the signal for that item if the station needs service, and then canceling that signal with a value of -1 when the station is serviced, and then resetting all of them with the signal reaches 0.
To make it more complicated, I wanted to have 3 signals on the same signal, so I could have [Iron] Receiving P1, [Iron] Receiving P2, and [Iron] Receiving P3, and have them serviced independently of each other. My solution was to have the P1 stations use values from 1-99; P2 stations using values 100, 200, 300, 400, through 9900; and P3 stations using values 10000, 20000, 30000, 40000, through 990000. Combined, the full signal could look something like 120305, meaning 12 P3 stations need service, 3 P2 stations need service, and 5 P1 stations need service. The problem I was running into was isolating those numbers from the whole signal.

Here is a blueprint of the setup, just add 1 blank blueprint to each of the 9 sets of 4 chests (1 BP per 4 chests), then fuel and start the trains.

Tired of manually backing up your saves? Check this out! -> Factorio Backup

mmmPI
Smart Inserter
Posts: 1600
Joined: Mon Jun 20, 2016 6:10 pm
Contact:

### Re: Combinator Help - Even Distribution of Trains and Priority Levels on Stations

Durr wrote: β
Fri Jan 21, 2022 5:50 pm
tldr: Can someone help me figure out how the combinators in this setup works, and if there's a way to optimize them?

I was tinkering with some combinators yesterday for a few hours and eventually stumbled upon a configuration that did what I wanted it to do. But looking at it now, I'm not entirely sure how it actually works.
I'm not entirely sure what each combinator do and why it was used this way, i recognize in your sentence what i do when trying out things. Sometimes it works after you changed that little thing here and this other thing there and also this, and now you have something that you wouldn't have come up with from scratch which makes it difficult to read since it's something [thing] with [patch 1] [patch 2] and [patch 3] applied on top of it and one doesn't know what the patches were trying to fix, or if [thing] was done differently [patch 3] wouldn't be needed but you didn't noticed earlier because it only became aparent after [patch2] and now you're left wondering why things are this way and not sure if you could change things ( at least that happens to me )

From the way the whole system function i recognize it because i have done something similar though not starting from the same goal ( viewtopic.php?f=194&t=100617&p=556666). One can simplify it considering each station is a "cell" with a unique number. Then a train goes to visit every cell from the same group before cycling again. This is done by "soft" disabling a station that has been visited by a train until receiving a reset signal. In your example you have 3 "main" station at the top side sending a different reset signal to their dedicated column of 3 receiving stations.

This means if you call your upper most station A and then the other 3 under it station1 station2 station3, that a train should do A=>1=>A=>2=>A=>3=>A=>1.... Which is what you described.

On a circuit logic the 4 chests and the 4 inserters act as memory, it allows each station to have a different state, wether it has already been visited by a train and is waiting the reset signal, or if it hasn't been visited and is therefore set with a limit>0 depending on which chest is containing the blueprint.

The tricky part is the implementation of this logic. How do you make the reset signal work properly. Which you further complicated by using only 1 wire to transmit all data onto the same network. Which you explain yourself :

Durr wrote: β
Fri Jan 21, 2022 5:50 pm
The concept is that I have all my receiving stations for a particular product named the same ([Iron] Receiving), but I want to make sure all of them are serviced once before any station is serviced for a second time. This was easy enough to do by outputting a value of 1 on the signal for that item if the station needs service, and then canceling that signal with a value of -1 when the station is serviced, and then resetting all of them with the signal reaches 0.
To make it more complicated, I wanted to have 3 signals on the same signal, so I could have [Iron] Receiving P1, [Iron] Receiving P2, and [Iron] Receiving P3, and have them serviced independently of each other. My solution was to have the P1 stations use values from 1-99; P2 stations using values 100, 200, 300, 400, through 9900; and P3 stations using values 10000, 20000, 30000, 40000, through 990000. Combined, the full signal could look something like 120305, meaning 12 P3 stations need service, 3 P2 stations need service, and 5 P1 stations need service.
From what i see in your blueprint the use of value 10000 20000 30000 40000 and so on are for now used to choose a target for a train. 4 different numbers meaning 3 intervals ( from 10K to 20K is 1 train, from 20K to 30K is another train and so on). And inside of those range you have used 1 2 3 to name the different stations 1 train could visit. So this would mean 10001 10002 and 10003 can only be visited by 1 train and once all stations belonging to the range [10000 20000] have been visited once , it reset and they are all open again. I'm not sure it is exactly 100% what your wording describe. But also i'm not sure i have 100% understood well your blueprint

I understand this is the tricky part On the link at the top of the post my example uses a minimalist setup for the memory and signal filtering which i think is very similar to what your blueprint is doing. Except in your system with your goal you reset the state of stations once the trains goes back to the main station after each of the 3 similar have been visited whereas in my system the reset occurs after each arrival to a station ( but you can easily configure it to do 1=>2=>1=>3=>1=>4=>1=>2=>1=>3=>1=>4 ..... like yours ). I think my exemple is easier to understand it because there is very few signal isolating required which makes the memory/reset part quite optimized in number of combinators/wire/inserter/chest.

Now there is also a different approach instead of looking at it from far away to get the big picture, if one focuses on the last sentence and the problem of isolating numbers on a network which i learned on this forum through this thread : viewtopic.php?f=193&t=100784

It may not be straightforward how it relate at first, but if one continue to analyze your blueprint as a system that transmit adress store them in memory, and sometimes reset them and all that to guide trains. Then this discussion especially the latest post where it comes down to the binary operation can be seen as powerful tool to help organize all this information on the network and it's the purpose of the different filters of the discussion to isolate numbers on a network . [making sure the reset signal don't add up which in your case is particular because it would seem that the reset signal is "no value on green"].

One thing that come to mind especially with the use of the binary form of the number is that it allows you to send numbers in a form that would look like this 101220, and it would be 10-12-20. You can pack 3 small numbers in 1 larger number with easier method than when you use the decimal form of the number like when you do 10001 10002 and it should be read as 10000-1 and 10000-2.

In short each number in the network can be considered as a block of 32 character 0 or 1 which is the binary notation of the number we read as player when hovering over a power pole. This is pretty advanced so this resume of the other thread would probably make sense only if you are already familiar with the notions , if you are interested i could try to explain more in detail though . In binary form if you write a number using the 16 first character, and another number using the 16 following it is easier to recover the 2 number with combinators than if you use decimal numbers. This is because you can use "bit shifting operation" " >>" and "<<" which allows you to read only the 16 first bit, or only the 16 last bit when used this way. And you can use number like 2^16 or 2^5, which correspond to a 1 at the position 16 or at the position 5 in the 32 characters.

So for example A= 2^5 + 2^6 + 2^7 . This means you write a "1" in position 5 6 and 7. Then if you do A>>4, You have the "1" in position 1 2 and 3 instead. the operation ^and >> are possible to use on arithmetic combinator. While on decimal it correspond to A= 32 + 64 + 128 so A= 224 and after the operation that only makes sense in binary the result would be A=14. because 2^1 + 2^2 + 2^3 = 2+4+8 = 14.

Now hopefully it make sense when you consider 224 is also 0000 0000 0000 0000 0000 0000 0111 0000 and 14 is also 0000 0000 0000 0000 0000 0000 0000 0111 in binary if you write the whole 32 character. In this example you can consider instead of 1 or 2 or 3 as number to identify a station. You use 2^5 and 2^6 and 2^7. ( or 32 64 and 128 ). Why ? well because 1+2=3 but 32+64=/=128 ! If you want to call station 1 and station 2 at the same time, you don't call station 3 by mistake ! 0 risk even you let the signal add up. You can easily recover the information you want.

In other word the way you choose your range of number in your blueprint 10000 20000 30000 40000 make sense in decimal but makes for complicated operation in combinators. But if you where to try out with powers of 2 instead and think about the binary form. Then it would require less combinators. The isolating numbers part of the problem could be simplified in wiring by using powers of 2.

Is that answering your questions or where you more interested into the frame by frame operation that occurs for each combinators and signal value of your blueprint ?

 Oh and in case it wasn't obvious after that novel, i found your system very interesting ! cool stuff

Durr
Inserter
Posts: 42
Joined: Fri Mar 22, 2019 8:12 pm
Contact:

### Re: Combinator Help - Even Distribution of Trains and Priority Levels on Stations

I'll be honest, all of that bit stuff is a bit over my head.

I don't know if I explained it well enough. The green signal I'm using is just a placeholder. This is designed to be expandable, up to 99 stations of all three priority levels all signaling on one signal for a potential of 197 stations for each item in the game (If I played around with it or knew better about how it's working, I could probably use more digits and significantly increase that number). I'm combining three signals into one, using 2 digits for each priority level of the stations, the signals are not ID numbers for the stations. So, using 120305 as an example, the P3 stations simply ignore the last four digits of the number, and the 12 represents how many stations still need service this round. The P2 stations ignore the first two and last two digits, so the 03 is how many stations need service. The P1 stations only look at the last two digits, the 05.

You are spot on with the patch of a patch of a patch, leading to not knowing why it actually works. That's really the main point for me posting this.
Tired of manually backing up your saves? Check this out! -> Factorio Backup

mmmPI
Smart Inserter
Posts: 1600
Joined: Mon Jun 20, 2016 6:10 pm
Contact:

### Re: Combinator Help - Even Distribution of Trains and Priority Levels on Stations

Durr wrote: β
Sat Jan 22, 2022 1:14 am
I'll be honest, all of that bit stuff is a bit over my head.
That's fine, it seem to be the case for everyone that's not doing electronic related studies which is the vast majority of humans, be them under-represented in the combinators thread of the forum.

The binary representation is a possible optimization for this particular thing :
Durr wrote: β
Sat Jan 22, 2022 1:14 am
I'm combining three signals into one, using 2 digits for each priority level of the stations, the signals are not ID numbers for the stations. So, using 120305 as an example, the P3 stations simply ignore the last four digits of the number, and the 12 represents how many stations still need service this round. The P2 stations ignore the first two and last two digits, so the 03 is how many stations need service. The P1 stations only look at the last two digits, the 05.
It would be using different math and numbers to achieve the same result in a way that require fewer combinator but require using the binary form of the number. If that is your thing you got a practical example of application to get started haha, otherwise i understand if you'd want to avoid it

Durr wrote: β
Sat Jan 22, 2022 1:14 am
I don't know if I explained it well enough. The green signal I'm using is just a placeholder. This is designed to be expandable, up to 99 stations of all three priority levels all signaling on one signal for a potential of 197 stations for each item in the game (If I played around with it or knew better about how it's working, I could probably use more digits and significantly increase that number).
That make sense, it look the same if you only have 3 station to illustrate the 3 different priority or if the 3 station are supposed to represent unique ID. Now i understand better the difference. Instead of green signal you would use iron ore , copper ore , stone , coal, uranium and so on. And you would have several station named "1" several station named "2" and several station named "3", their name being their priority level.

Sometimes, when you don't know why it works, it's because it doesn't work, maybe try expanding your system and it will break, requiring [patch 4] which will look like a [reverse-patch2] and makes it clear what is the problem or why it worked earlier .

I should have another look at it because i'm not sure how you dealt with the reset signal being different for all 3 column, it seemed to me that the reset was the absence of green signal. Or when no more priority 3 station are requiring something the signal stops, which cause the priority 1 , 2 and 3 station to all be accessible again. but that cannot work for all 3 different column. Otherwise when one column is done, then they would all reset.

I'm not quite sure if it's the last of your priority 3 station that send the reset signal when it deactivate or if it's the main station once the last of the priority3 station is no longer requesting anything and the train is arriving to it but it's pretty much the same for me i didn't remember when looking at it. Though it may be important once you try to expand that system .

I'm not sure how i can explain why it works x), it look like each station can remember if it has ever been visited this round or not due to the position of the blueprint in one of the 4 chest and the condition on the inserters. Before a train has visited a station , its blueprint cannot go past a certain chest. And then there is a state where the train has visited already, but no reset signal were received, this correspond to another chest in which the blueprint will wait. And once the reset signal is sent, the blueprint goes to a 3rd different chest, triggering a state where it means the station should be visited. Then in this particular state, the signals value are carefully choosen to that they do not sum up in a way that would loose the information, the trains can go to the priority 1 station first then 2nd when no more station 1 is having the blueprint in the wrong chest, then the priority 3 when no more station 2 has the blueprint in the wrong chest. ( i think there is one chest used just to close the loop without condition from memory).

It's a nice automaton ! What kind of help do you need if it works as intented ?

Durr
Inserter
Posts: 42
Joined: Fri Mar 22, 2019 8:12 pm
Contact:

### Re: Combinator Help - Even Distribution of Trains and Priority Levels on Stations

I might play around with the binary system when I have time.

I still need to do more testing, but it seems to be expanding well with the P1 stations in my main world.

The help I'm looking for is an explanation of how my current solution is working since I can't make sense of what I did. You probably already answered my other question with the bit solution - that'll probably be less comparators and more efficient.

Edit: also, the reset signal isn't necessarily the absence of the signal, but a value of zero in the pair of digits. For example, 1205 (or 001205) would reset P3, 130007 would reset P2, and 141100 would reset P1.
Tired of manually backing up your saves? Check this out! -> Factorio Backup

mmmPI
Smart Inserter
Posts: 1600
Joined: Mon Jun 20, 2016 6:10 pm
Contact:

### Re: Combinator Help - Even Distribution of Trains and Priority Levels on Stations

Durr wrote: β
Sat Jan 22, 2022 2:29 am
Edit: also, the reset signal isn't necessarily the absence of the signal, but a value of zero in the pair of digits. For example, 1205 (or 001205) would reset P3, 130007 would reset P2, and 141100 would reset P1.
I am confused because i am trying to imagine what kind of math allows you to read only the 2 middle digits. I would have thought the opposite 1205 reset P1, and 141100 reset P3. Maybe i'm just having them wrong, P1 i thought is the most prioritized. and then P2 and then P3.

Logic i have in mind is If P1 P2 and P3 are priority you only read the middle 2 digits when the first 2 digits are 0, so a simple If A <10000 followed by A/100 would do since the game uses only integer for circuit network it would read the only 2 middle digit, or say 0. and then a simple if A<100 would allow to read only the last 2 digits. ( and to read the first 2 digits A/10000 ).

With this logic though you can't read the 2 middle digits at will, only after the first 2 are 00. It doesn't matter in case of priority, i will try to look at this more carefully next time , using /editor allows to pause the game or go frame by frame and read the value in the wire each tick, it is very useful to try and understand precisely what is happening in your circuit.

This would be like looking with a magnifying glass, you can only do this once you have an idea of where to point it first ( which i have now) , first the shape/logic then the implementation details

Maybe when patching up your design you did something else that is counter-intuitive but works better as it allows to read the middle 2 digit in the conditions that occurs in your circuit when you need it.

One thing that you may have been forced to do is add something to deal with the special case where the signal IS 0 because in this case it becomes an absence of signal. it's not always intuitive how each operation acts when a signal is missing. I know that's a frequent case of patching for me, then i have this combinator i don't remember what it does and look useless so i remove it, until i'm reminded it's the one that is necessary for the system to function when this = 0.

Some of the other combinators must be used to make each station broadcast its state to the network, each P2 station must be sending 100 green, only when the blueprint is in one particular chest. After the train has visited one station P2 the blueprint is moved in another chest at this particular station. but it's 10000 for P1 or P3 and 1 for P1 or P3 (the other). This and their reset condition based on reading different digits explain their differences i guess.

Apart from that for expanding you would need 8 digit if you were to use a P4 this i think is pretty obvious or 9 digits if you want to use up to 999 oupost per ressources and 3 priority level which is not possible because the maximum number for the first digit is 2 when you use a number that is in billions as the maximum number possible in game for circuit is (2^32)-1 , or a bit more than 2 billions here comes binary again !

Durr
Inserter
Posts: 42
Joined: Fri Mar 22, 2019 8:12 pm
Contact:

### Re: Combinator Help - Even Distribution of Trains and Priority Levels on Stations

So part of my thought process was dividing by 10000 to get the P3 values. I tried that same logic for the P2 values by dividing by 100, but I had to ignore any digits on the left (if it was more than two digits) and I don't remember how I made that work, maybe I separately divided by 10000 to get the P3 and subtracted that from the P2? And I think I did something similar to P2 for P1.

The station is constantly broadcasting a 1 (or 100 or 10000) and broadcasts a -1 (or -100 or -10000) if it has been serviced.

The trains aren't set up to service all P1, then P2, then P3. The three priorities are completely separated, the priority is determined at the shipping station, where the chests for P1 fill first, then P2, then P3. The trains are set to pick up at Shipping P1 and deliver to Receiving P1, or Shipping P2 to Receiving P2, etc.

I wouldn't expand past P3, I would only try to expand the quantity of each priority. But I can't imagine needing more than 99 receiving stations for one item. And I could probably go beyond 99 as long as all of them aren't broadcasting for a train at the same time.

I need to play around with the editor more, I didn't know you could step through the ticks.
Tired of manually backing up your saves? Check this out! -> Factorio Backup

Nidan
Long Handed Inserter
Posts: 96
Joined: Sat Nov 21, 2015 1:40 am
Contact:

### Re: Combinator Help - Even Distribution of Trains and Priority Levels on Stations

Durr wrote: β
Sat Jan 22, 2022 4:39 am
So part of my thought process was dividing by 10000 to get the P3 values. I tried that same logic for the P2 values by dividing by 100, but I had to ignore any digits on the left (if it was more than two digits) and I don't remember how I made that work, maybe I separately divided by 10000 to get the P3 and subtracted that from the P2? And I think I did something similar to P2 for P1.
Regrading the question why/how your setup works, in the last part of this quote you answered it yourself. (after "maybe I separately β¦")
The arithmetic combinator's % operation helps. % (or "modulus") returns the remainder of a division. With that you can reduce the four arithmetics you use to check if the system should reset to two: Green / [1, 100, or 10k] -> Green; Green % 100 -> Green; and feed that into the decider.
Then, since that decider is the only thing you're feeding the "cleaned" Green signal to, it can do part of the calculation to throw out another combinator: First we get rid of the groups using larger numbers: Green % [100, 10k, 1M] -> Green; then we check if the group the station belongs to is zero: If Green < [1, 100, 10k] set 0 to 1 (Since we haven't removed the signals of the groups using smaller numbers we can't test against zero, but we know this station's group, if present, is the highest so we can test whether the signal is less than the value this group uses.)
(In case it isn't obvious: I'm using "group" to refer to your P1, P2, P3. "Priorities" doesn't make sense imho since they act independent of each other.)

Since bit arithmetic was already mentioned as a potential alternate solution: What you've been doing, i.e. splitting the Green signal into different parts, is more or less the same, but using base 10 instead of base 2. / and % can be replaced by >> resp. AND if the right side is a power of two (a / 2^b == a >> b; a % 2^b == a AND (2^b - 1) ). Within your design there's no benefit in doing so as all operations can be done in a single arithmetic combinator; IRL however, bit operation require significantly less circuitry: Bit operations are the cheapest to implement, whereas division and modulus are the most expensive and slowest of the basic math operations. (In fact, if you have code dividing by a known constant, a compiler will almost never use a division instruction but use some trickery to turn it into a set of cheaper instructions.)

I've noticed in your blueprint that the trains pick the stations in the order top, middle, top, bottom, β¦, because the station the train is approaching when the system is resetting immediately transitions into the "train was here" state. To fix this I've made the inserter to only react to changes in the number of incoming trains by adding a C * -1 -> C combinator. (Search for "edge detector" or "edge trigger")

Finally, I've replaced your chest/inserter memory with a single decider combinator feeding into itself. It gets set when Green for the stations group is zero and reset when there's a new incoming train. Using the output of that decider-memory are deciders generating the proper Blueprint and Green for the station resp. the global green wire.

quyxkh
Filter Inserter
Posts: 964
Joined: Sun May 08, 2016 9:01 am
Contact:

### Re: Combinator Help - Even Distribution of Trains and Priority Levels on Stations

If the goal was to give yourself a combinator design puzzle, how close are each set of stops to each other? Instead of the modular packing on a global circuit you could use a gate waypoint stop that maintains the count in its own limit, on the magic train-limit wireless broadband network. Make your schedules iron-receiving-p1-gate iron-receiving-p1-delivery.

But if the goal is instead to be achieve what those combinators are apparently trying to achieve, being sure none of those stops get starved of supplies isn't the right solution to build enough production? Starvation is completely avoidable, there's just no reason to ever not have enough of anything.

Tertius
Fast Inserter
Posts: 169
Joined: Fri Mar 19, 2021 5:58 pm
Contact:

### Re: Combinator Help - Even Distribution of Trains and Priority Levels on Stations

I would like to mention a different approach. If you focus on even or prioritized delivery to unloading stations, you might focus on the wrong thing (putting precious time into the wrong thing). You're trying to manage item starvation and try to let everything starve at the same rate.

Instead, focus on mining outpost building (or in general: focus on loading station building), so you have more supply than demand, so nothing will starve. In this case, you simply don't need priority delivery and everything comes together automatically.

If you build for one material more supply (loading) than demand (unloading) stations, and employ exactly one train per supply station (if you have 6 iron ore outposts, employ 6 trains for iron ore), you get all your demand stations supplied automatically.

The only thing that you could and probably should manage is a train limit per individual unload station, so your full trains will not accumulate in front of still full unload stations. This is much more simple than a circuit network distributed all over your base. My proposal for implementing simple train limits is this station circuit setup:

You need to configure the arithmetic combinator. As Quotient, you need to enter a stack size and wagon count specific value (it's about 1 full train load):
Screenshot 2022-01-22 213013.png (143.8 KiB) Viewed 696 times

For trains with 4 wagons and 16 chests, you find the exact numbers in the constant combinator as notice. Copy the exact value depending on the stack size (for ore it's 7600, for plates it's 15200 and so on) from here to to arithmetic combinator:
2.png (145.84 KiB) Viewed 696 times
How to compute the numbers (if you don't use 4 wagons or different chest numbers):
[Maximum train limit] L = floor(station capacity / train capacity)
[Divisor in arith combinator] Divisor = floor((station capacity - train capacity) / L)

Station capacity is chest count * chest stack capacity * stack size
Train capacity is wagon count * wagon stack capacity * stack size

The limit gets reduced while trains fill the chests, until there is not enough free capacity to hold a full additional train, at which point the train limit gets down to 0.

It's true that the nearest station gets filled sooner, but if you have more supply stations than these unloading stations, all unloading stations will get full sooner or later.

Durr
Inserter
Posts: 42
Joined: Fri Mar 22, 2019 8:12 pm
Contact:

### Re: Combinator Help - Even Distribution of Trains and Priority Levels on Stations

I'll respond to more of the comments later when I have more time, but I did want to reply to a couple things right now. Real life priorities get in the way of this game too much...
Tertius wrote: β
Sat Jan 22, 2022 9:31 pm
I would like to mention a different approach. If you focus on even or prioritized delivery to unloading stations, you might focus on the wrong thing (putting precious time into the wrong thing). You're trying to manage item starvation and try to let everything starve at the same rate.

Instead, focus on mining outpost building (or in general: focus on loading station building), so you have more supply than demand, so nothing will starve. In this case, you simply don't need priority delivery and everything comes together automatically.
I know it would be better to have enough surplus production so that I don't have to worry about supplying every station, and that is my end goal. This is just a fun project I was working on and it could help in early/mid game while I'm still scaling up production. I wanted to guarantee, for example, that enough iron gets to the ammo and defense factories before anything else, and then give research a low priority so I can make sure I have the resources available to expand.
quyxkh wrote: β
Sat Jan 22, 2022 6:57 pm
If the goal was to give yourself a combinator design puzzle, how close are each set of stops to each other? Instead of the modular packing on a global circuit you could use a gate waypoint stop that maintains the count in its own limit, on the magic train-limit wireless broadband network. Make your schedules iron-receiving-p1-gate iron-receiving-p1-delivery.
The stops would be spread almost randomly throughout my entire network, my tracks BP have a built in green wire so it's easy to connect everything.
Nidan wrote: β
Sat Jan 22, 2022 4:13 pm
In case it isn't obvious: I'm using "group" to refer to your P1, P2, P3. "Priorities" doesn't make sense imho since they act independent of each other.
I realize now that referring to them as priorities in this scope was confusing. Groups would have been better. In the full use case of this system, priorities does make sense though.

I was trying to figure out how to replace the four chest system with something like an RS latch, but I get too confused when trying to figure out how to do it. I can usually figure out what is happening when I see a logic schematic on paper, but I can't figure out how to make my own and I really can't do it with combinators. Especially when the output of something feeds directly back into it's input. Those loops really confuse me.
Tired of manually backing up your saves? Check this out! -> Factorio Backup

mmmPI
Smart Inserter
Posts: 1600
Joined: Mon Jun 20, 2016 6:10 pm
Contact:

### Re: Combinator Help - Even Distribution of Trains and Priority Levels on Stations

Nidan wrote: β
Sat Jan 22, 2022 4:13 pm
Since bit arithmetic was already mentioned as a potential alternate solution: What you've been doing, i.e. splitting the Green signal into different parts, is more or less the same, but using base 10 instead of base 2. / and % can be replaced by >> resp. AND if the right side is a power of two (a / 2^b == a >> b; a % 2^b == a AND (2^b - 1) ). Within your design there's no benefit in doing so as all operations can be done in a single arithmetic combinator;
It would look like this :

STATION.jpg (256.31 KiB) Viewed 626 times
The whole blueprint i made allow for up to 255 receiver station for each of the 4 different group P1 P2 P3 P4. ( i think i'm not sure maybe the P4 group can only go to up to 128).

It can either enable/disable stations as a variation, or do with the limit 1=>0 for the P4 example in the blueprint and as the original.

Durr wrote: β
Sun Jan 23, 2022 1:25 am
I was trying to figure out how to replace the four chest system with something like an RS latch, but I get too confused when trying to figure out how to do it. I can usually figure out what is happening when I see a logic schematic on paper, but I can't figure out how to make my own and I really can't do it with combinators. Especially when the output of something feeds directly back into it's input. Those loops really confuse me.
I started over from scratch trying to do the same functionning as i understood after the reading of all those explantions about your blueprint and the corrections from Nidan but i made mine using bit shift operation ( >> and << ) to illustrate my previous comment.

While not using a combinator for the memory/latch, but instead similar as yours but with a fish and belts in case you just want to focus on the binary method used to store 4 numbers in 1

Some not so quicks recap :

where in decimal you use the first 2 digits , then 2 other digits, and then the last 2 for 3 groups. For a number of 6 digits.

In binary i used 4 groups of 8 bits for a number of 32 bits. This is same logic.

To "write" in the 2 middle digit in decimal, you multiply by 100. so 37 becomes 3700 which is 003700 in op's convention.

In binary it's all about power of 2. so the stations from the first group are emiting 1, and if there is 12 of them that's 12x1 that's added onto the network. The stations from the second group are emiting 256, and if there are 5 of them, then it would add 5*256=1280.

This is done by multiplying [fish]*256 output [green] when the station hasn't been visited by a train yet. ( when a train arrive 1 inserter moves the fish away to disable the station and stop emiting 1 or 256 ).

I hope it gives a hint as to why 255 maximum station per group. Because if there is 256 station of the first group open, the network would read 256 green. And it would mistaken that for a signal saying there 1 station of the group2 open.

After 1 which is 2^0 , there is 256 which is 2^8 then it's 65536 which is 2^16 and finally 2^24 for the last group which makes 16 777 216.

This is how to "write" in binary only in a specific place of the string of 32 0and1 that compose a 32 bit number which is how factorio the game treats the number we players see in the circuit network.

The operation to read the number i think are visually explained by the 2 picture on this page https://en.wikipedia.org/wiki/Arithmetic_shift.

You just "move" the numbers 8 16 or 24 position to the right to delete the parts you don't want, and then the other, to delete the other part, like scissors keeping only the 8 desired bit. ( because thanks to choosing the previous power of 2, each group of station writes only on its allocated 8 bits like the 2 middle decimal in your example).

you cannot do this operation in decimal but it would like taking 123243 and making it 001232 by shifting the whole number twice on the right side and adding 0 to fill in the gap and then 32000 by doing the operation 4 times the other way. >>2 and then <<4. This makes sure where there is a 3 and a 2 are the only place that can be different from 0.

And then if it is 0 this means no station is emiting its power of 2, this is how the reset signal is generated. The condition is set on an inserter, and they all move the fish back at the same time when it occurs.

That's a lot of over-engineering, but i'm just following up i haven't started this ! and if i had more time it would generate a dynamic limit for each train station but i need to study Tertius blueprint and there's only so much one can do in one day .