Hi, all!
This is my first post in this forum.
I'm on my first game, but if I know that somthing can be done in an efficient way, then I can't let it go and settle for something less efficient, so I'm kinda stuck and can't progress.
I've been trying to set up a loading/unloading system for trains that loads evenly both into and out of the buffer chests at my train stations, both when I'm loading and unloading.
I quickly found Madzuri's clever design and I read that it doesn't deadlock. For a long time, (when I finally got it right) it worked perfectly, but now I find myself in a position where I need a lot more train stations, and that's when I decided I wanted to balance "both ways", as it were.
However, I've found out I'm not as clever as I'd like to be, because I can't seem to understand how to make this work, especially considering the deadlocks.
I made a simple test environment (on the right in the attached image) for unloading evenly. You can disregard the fast inserter on the top there, that's just remnants of an earlier attempt.
I thought that I could keep the combinators' settings the same if I just switched from "blacklist" to "whitelist" in the filter inserters' settings, but as you will see in the image, I also produced a deadlock, and for some reason, I can't figure out how to avoid it.
I found the following post, asking the same question, but for all the answers he got, none of them actually helped him, as far as I could see.
viewtopic.php?t=63583
Did you ever figure this out, @gerrg? (Is it possible to tag people using @ in forums?)
If anyone would be able to help me with this, it would be much appreciated!
Madzuir's balancer prone to deadlocks?
Madzuir's balancer prone to deadlocks?
- Attachments
-
- Deadlock.png (3.35 MiB) Viewed 3872 times
Re: Madzuir's balancer prone to deadlocks?
Filter inserter won't grab any material that is not set as a filter. ( using the whitelist)
If i understand correctly what you tried is to "blacklist" nothing. In this case a filter inserter could be replaced by a regular fast inserter(blue) or a stack inseter(green).
Now with the "blacklist" box ticked and also the "set filter" box ticked. The inserter should take everything except the thing that it receive as a signal, since those would be set as what is actually being blacklisted. (might be 1 case of deadlock)
I don't understand what you mean by :
maybe it's because i didn't understand properly the previous quote, but i would say you don't need to control the inserters located between the buffer chest and the wagon as those will be synchronized by the train arrival or departure. So as long as the chest are balanced they will stay balanced when train comes and/or leave.
You call it "Madzuri's" but it seemed to me that if it was, there would only be 1 combinator, the arithmetic one. The check you do with the decider combinator i think you can implement it directly on the inserter, if you tick the "enable/disable" box on each inserter and use the menu that opens up. ( or maybe there is a Madzuir somewhere that came up with another similar setup )
To explain i need to describe with my words how i see it function:
When loading, materials are coming from a belt, let say from the bottom side. What (i think?) you want to do is to load the chests evenly with those materials, and to achieve that the general logic is to compare the average of the chests you have with the quantity in each individual chests, then activating only the inserters that feed the chests that are under said average. ( or you only activate the inserter for chest above average when unloading).
For this you first link all the chests with the same color of wire let say red. This will give you the total amount. Then you divide by 6 to get the average, using the arithmetic combinator. And you send that number to all the inserter in the row using the same color of wire.
Then the idea is to link each inserter with its own chest using the other color of wire green.
At this point you have the inserter receiving 2 positive numbers, you can't compare them easily. What you could have though, would be 1 positive number and 1 negative number. This way , to compare them you would just have to sum them up. Hence why instead of dividing by 6 as i earlier said, you divide by -6.
At this point each inserters receive the negative average from the red wire. And each individual quantity in their dedicated chests on the green wire.
The "sum" is calculated automatically, and would yield a positive OR negative number OR a null result.
By ticking the "enable/disable" box on inserter, you can give them a condition like be active only if number of [signal barrel]/[anything] is >0 , or <0.
this would allow the inserters to balance their own chest relative to the average of the station.
Which can deadlock if they all have the same perfect quantity. so you can use ≥0 or ≤0 instead.
that leaves the case where all chests are empty , it would deadlock. To avoid that i think the original design relies onto having the last inserter of the row always active ( not wired), in case of a loading where materials comes from a vertical belt going up, it is the inserter at the top.
At this point when everything is empty you should see the last inserter active, putting stuff on chest, triggering the logic, then all other inserter will swing too but "only once" in case you want to load a train and the train is stationned, because the time needed for the 5 inserter to swing, the last chest would be empty again, already loaded into the train.
It is not a deadlock but it's not so fast, it should be pretty rare though, if your buffer chest are not empty on a regular basis. ( this might be easier to understand when looking at it slowly function since i'm not sure my wording is very clear )
To avoid that, if you know that the buffer chest could often stay empty, you can trick your system by offsetting the average: use constant combinator set to emit signal saying "12 barrels" for example, and you send it right into the arithmetic.
This means even if everything is empty, the average would still be [-2 barrels] which in case of a loading would allow all the inserters to be active , in this case you don't need to have the last inserter not wired. but it requires setting up 1 additionnal constant combinator on each station.
It also allow to set a margin : typically if i do that with iron i want my chest to be roughly balanced, let say 30 or 50 difference between them is ok, so i could write into the constant 180 or 300. meaning the average would be offset by -30 or -50, if my chest have 0-20-40-50-60-70 iron ore the real negative average is 240/-6 : -40 , with the offset it is -70 or - 90;
without offset, only half of the inserter would be active , those that load onto the chests that have 0-20-40, they would equalize with the others, the average will move and eventually all of them would be active.
with the offset , all of them are active right away. it makes it higher throuput, while still maintaining a rough balance with 30 or 50 difference between chests.
( choosing example quantities that have 70 difference wasn't wise but hopefully you get the idea and it helps )
if i was unclear or if i made math mistake that make the explanation unclear lemme know
Also i gotta say this is a tough task you are giving yourself for a first game, and you can't use @Bolletott on the forum, but one way to poke similarly would be to quote the person from the previous post it would send notification.
If i understand correctly what you tried is to "blacklist" nothing. In this case a filter inserter could be replaced by a regular fast inserter(blue) or a stack inseter(green).
Now with the "blacklist" box ticked and also the "set filter" box ticked. The inserter should take everything except the thing that it receive as a signal, since those would be set as what is actually being blacklisted. (might be 1 case of deadlock)
I don't understand what you mean by :
From experience, the logic you use is best used to control the inserters that are located between the belt and the buffer chest for loading and unloading.
maybe it's because i didn't understand properly the previous quote, but i would say you don't need to control the inserters located between the buffer chest and the wagon as those will be synchronized by the train arrival or departure. So as long as the chest are balanced they will stay balanced when train comes and/or leave.
You call it "Madzuri's" but it seemed to me that if it was, there would only be 1 combinator, the arithmetic one. The check you do with the decider combinator i think you can implement it directly on the inserter, if you tick the "enable/disable" box on each inserter and use the menu that opens up. ( or maybe there is a Madzuir somewhere that came up with another similar setup )
To explain i need to describe with my words how i see it function:
When loading, materials are coming from a belt, let say from the bottom side. What (i think?) you want to do is to load the chests evenly with those materials, and to achieve that the general logic is to compare the average of the chests you have with the quantity in each individual chests, then activating only the inserters that feed the chests that are under said average. ( or you only activate the inserter for chest above average when unloading).
For this you first link all the chests with the same color of wire let say red. This will give you the total amount. Then you divide by 6 to get the average, using the arithmetic combinator. And you send that number to all the inserter in the row using the same color of wire.
Then the idea is to link each inserter with its own chest using the other color of wire green.
At this point you have the inserter receiving 2 positive numbers, you can't compare them easily. What you could have though, would be 1 positive number and 1 negative number. This way , to compare them you would just have to sum them up. Hence why instead of dividing by 6 as i earlier said, you divide by -6.
At this point each inserters receive the negative average from the red wire. And each individual quantity in their dedicated chests on the green wire.
The "sum" is calculated automatically, and would yield a positive OR negative number OR a null result.
By ticking the "enable/disable" box on inserter, you can give them a condition like be active only if number of [signal barrel]/[anything] is >0 , or <0.
this would allow the inserters to balance their own chest relative to the average of the station.
Which can deadlock if they all have the same perfect quantity. so you can use ≥0 or ≤0 instead.
that leaves the case where all chests are empty , it would deadlock. To avoid that i think the original design relies onto having the last inserter of the row always active ( not wired), in case of a loading where materials comes from a vertical belt going up, it is the inserter at the top.
At this point when everything is empty you should see the last inserter active, putting stuff on chest, triggering the logic, then all other inserter will swing too but "only once" in case you want to load a train and the train is stationned, because the time needed for the 5 inserter to swing, the last chest would be empty again, already loaded into the train.
It is not a deadlock but it's not so fast, it should be pretty rare though, if your buffer chest are not empty on a regular basis. ( this might be easier to understand when looking at it slowly function since i'm not sure my wording is very clear )
To avoid that, if you know that the buffer chest could often stay empty, you can trick your system by offsetting the average: use constant combinator set to emit signal saying "12 barrels" for example, and you send it right into the arithmetic.
This means even if everything is empty, the average would still be [-2 barrels] which in case of a loading would allow all the inserters to be active , in this case you don't need to have the last inserter not wired. but it requires setting up 1 additionnal constant combinator on each station.
It also allow to set a margin : typically if i do that with iron i want my chest to be roughly balanced, let say 30 or 50 difference between them is ok, so i could write into the constant 180 or 300. meaning the average would be offset by -30 or -50, if my chest have 0-20-40-50-60-70 iron ore the real negative average is 240/-6 : -40 , with the offset it is -70 or - 90;
without offset, only half of the inserter would be active , those that load onto the chests that have 0-20-40, they would equalize with the others, the average will move and eventually all of them would be active.
with the offset , all of them are active right away. it makes it higher throuput, while still maintaining a rough balance with 30 or 50 difference between chests.
( choosing example quantities that have 70 difference wasn't wise but hopefully you get the idea and it helps )
if i was unclear or if i made math mistake that make the explanation unclear lemme know
Also i gotta say this is a tough task you are giving yourself for a first game, and you can't use @Bolletott on the forum, but one way to poke similarly would be to quote the person from the previous post it would send notification.
Re: Madzuir's balancer prone to deadlocks?
Hi Bolletott, and welcome to the forums!
Unloading with a Madzuri config is seldom used, because the unload speed is low. search these forums for alternate solutions. they mostly use output balancing to make sure the chests are unloaded evenly.
(over 4 blue belts balanced unload per wagon is possible, and posted here somewhere .
As example one yellow belt per wagon side. Draws evenly from all four chests.
Re: Madzuir's balancer prone to deadlocks?
My friends, thank you for these answers!
They were both very much appreciated, but I have to give a special thanks to mmmPI, who gave the longest and most thorough answer I've ever gotten in any forum in my life.
I'd buy you a beer, provided you are old enough (hey, it's the internet, who knows), if you even drink beer, and if you weren't a stranger on the internet.
Thanks, man/woman! Very kind of you to take the time to write all that!
Goes for both of you, of course.
Anyway, back to the topic!
You're probably right I'm giving myself a harder task than I should with all this, considering it's my first game, but I can't help myself. Too painful to make something that I know is less efficient and something I'll eventually stop doing anyway in subsequent games. Also, I like the challenge, even if I have to rely on the help of others to manage it. (Cue Joe Cocker, With A Little Help From My Friends (sorry, Beatles fans))
So it seems you both agree that going through the trouble of unloading evenly isn't worth it, and I understand the logic of that. I can't really remember why I had the thought that I need that, but I'll just not do that for a while, and maybe I'll remember.
What I do remember is the reason I added the decider combinators. It's because I want to be able to send multiple items to the train using the same belt. The filter inserters can't use the "Each"-signal, so I added the dicider combinators to handle that. This way, the inserters can balance up to five items instead of just one. Unless I'm missing something, which is probably the case.
Then, in one of my train stations (not the one in this new picture, originally), more than five items was sent there, overloading the filter inserters, so I though that if I instead made a system where "The factory" informed the train station that it was running low on certain items (achieved by reading belt contents further down the line, e.g. "when there are no items in this single piece of belt, send more items". This is done by the deciders in orange circles), it would "order more" by whitelisting them.
That is just an easier way to organize this in my head, I guess.
That works fine, but now it gets complicated (for me, at least).
Because certain stations handle different items, that stack differently, I had to avoid getting too many of one item, filling up the buffer chests, blocking other items from arriving at the factory. Therefore, I added another set of combinators (blue/cyan cirlce). One arithmetic that gets the average (not the negative avg.) of each item in the chests, and then a decider that says that "if there are more than 'n' of each item on average, output one of each." (n is currently 450). That is sent to the filter inserters (FI, from now on) between the wagon and the buffer chests, blocking more items from coming in, until theres room, because the factory has consumed them.
Again, this works as intended, but this is where my wings are seared off, like my man Icarus' were before me, because now I'm remembering why I need to unload evenly. It's because the FI between the wagon and the buffer chests are always unloading evenly because they get access to the items at exactly the same time (as mmmPI wrote), but when the items are unloaded from the buffer chests, the belt is filling up from further down the line, eventually catching up with the inserters furthest to the back of the line. This means that a few more items are unloaded from the chests in the back (green circle), than from the chests at the front (red circle) every time the train arrives.
To combat this, I wanted the FIs to unload from the chest that has more items than average.
If anyone has read this far, let me first say I'm impressed! Now we're finally at the heart of my challenge, and I'm realising that this question is very different from the one I first posted. Sorry about that.
So, the decider with an orange cirlce, marked "1" is currently outputting 1 sulfur, because the factory needs more sulfur, as described above. However, no sulfur is sent to the factory, and the reason for that is that the arithmetic in the shameful, yellow circle is doing it's job, outputing the negativ average of sulfur, in an attempt to balance these chests, and that is my undoing. No sulfur is sent because the FIs are getting a much bigger negative number from our friend the yellow arithmetic decider, making this a perfect example of a "catch 22", if I'm not mistaken.
God, my head is spinning. I'm really not sure if I've explained all this well enough , but I've tried. Maybe someone who likes a challenge will try to help me figure this out.
So I guess my question ultimately is this: How can I balance the unloading of the chests, while at the same time having the factory "order" items by whitelisting what it needs? Is it possible without sorting everything first (taking up a lot of space), or do I have to abandon this challenge?
I'm posting one picture now, but I'm planning to post another with cut outs of the information in alle the relevant inserters, combinators and chests. I'm just tired right now and I have the get dinner going.
On another, final note: Thanks for all the tips regaring Madzuri's design and how to avoid deadlocks and the offputting of the signals, mmmPI. That is really nice, and something I'll definitely check out later.
Cheers, people!
They were both very much appreciated, but I have to give a special thanks to mmmPI, who gave the longest and most thorough answer I've ever gotten in any forum in my life.
I'd buy you a beer, provided you are old enough (hey, it's the internet, who knows), if you even drink beer, and if you weren't a stranger on the internet.
Thanks, man/woman! Very kind of you to take the time to write all that!
Goes for both of you, of course.
Anyway, back to the topic!
You're probably right I'm giving myself a harder task than I should with all this, considering it's my first game, but I can't help myself. Too painful to make something that I know is less efficient and something I'll eventually stop doing anyway in subsequent games. Also, I like the challenge, even if I have to rely on the help of others to manage it. (Cue Joe Cocker, With A Little Help From My Friends (sorry, Beatles fans))
So it seems you both agree that going through the trouble of unloading evenly isn't worth it, and I understand the logic of that. I can't really remember why I had the thought that I need that, but I'll just not do that for a while, and maybe I'll remember.
What I do remember is the reason I added the decider combinators. It's because I want to be able to send multiple items to the train using the same belt. The filter inserters can't use the "Each"-signal, so I added the dicider combinators to handle that. This way, the inserters can balance up to five items instead of just one. Unless I'm missing something, which is probably the case.
Then, in one of my train stations (not the one in this new picture, originally), more than five items was sent there, overloading the filter inserters, so I though that if I instead made a system where "The factory" informed the train station that it was running low on certain items (achieved by reading belt contents further down the line, e.g. "when there are no items in this single piece of belt, send more items". This is done by the deciders in orange circles), it would "order more" by whitelisting them.
That is just an easier way to organize this in my head, I guess.
That works fine, but now it gets complicated (for me, at least).
Because certain stations handle different items, that stack differently, I had to avoid getting too many of one item, filling up the buffer chests, blocking other items from arriving at the factory. Therefore, I added another set of combinators (blue/cyan cirlce). One arithmetic that gets the average (not the negative avg.) of each item in the chests, and then a decider that says that "if there are more than 'n' of each item on average, output one of each." (n is currently 450). That is sent to the filter inserters (FI, from now on) between the wagon and the buffer chests, blocking more items from coming in, until theres room, because the factory has consumed them.
Again, this works as intended, but this is where my wings are seared off, like my man Icarus' were before me, because now I'm remembering why I need to unload evenly. It's because the FI between the wagon and the buffer chests are always unloading evenly because they get access to the items at exactly the same time (as mmmPI wrote), but when the items are unloaded from the buffer chests, the belt is filling up from further down the line, eventually catching up with the inserters furthest to the back of the line. This means that a few more items are unloaded from the chests in the back (green circle), than from the chests at the front (red circle) every time the train arrives.
To combat this, I wanted the FIs to unload from the chest that has more items than average.
If anyone has read this far, let me first say I'm impressed! Now we're finally at the heart of my challenge, and I'm realising that this question is very different from the one I first posted. Sorry about that.
So, the decider with an orange cirlce, marked "1" is currently outputting 1 sulfur, because the factory needs more sulfur, as described above. However, no sulfur is sent to the factory, and the reason for that is that the arithmetic in the shameful, yellow circle is doing it's job, outputing the negativ average of sulfur, in an attempt to balance these chests, and that is my undoing. No sulfur is sent because the FIs are getting a much bigger negative number from our friend the yellow arithmetic decider, making this a perfect example of a "catch 22", if I'm not mistaken.
God, my head is spinning. I'm really not sure if I've explained all this well enough , but I've tried. Maybe someone who likes a challenge will try to help me figure this out.
So I guess my question ultimately is this: How can I balance the unloading of the chests, while at the same time having the factory "order" items by whitelisting what it needs? Is it possible without sorting everything first (taking up a lot of space), or do I have to abandon this challenge?
I'm posting one picture now, but I'm planning to post another with cut outs of the information in alle the relevant inserters, combinators and chests. I'm just tired right now and I have the get dinner going.
On another, final note: Thanks for all the tips regaring Madzuri's design and how to avoid deadlocks and the offputting of the signals, mmmPI. That is really nice, and something I'll definitely check out later.
Cheers, people!
- Attachments
-
- My attempt.png (3.93 MiB) Viewed 3779 times
Re: Madzuir's balancer prone to deadlocks?
I've spend a bit of time trying to understand what you have built already, but i have to admit i'm not following.
I understood the "catch22" reference after some research.
I think there are some mechanism that you may want to experiment with : the ability to connect the train station to circuit network.
From here you can read train content and/or train ID. Train ID is a fragile mechanism since their ID is changed everytime you add/remove wagon.
but maybe with this additionnal interaction you will find a way to identify which train/which material is at bay, and setting inserter filters according to this.
"Order more item by whitelisting them and also dynamically settings the filters according to this" this i'm lost, it is outside of the scope of what i'm familiar with due to my factorio experience .
You are trying to make a system that i would consider too complicated for myself for which (most) people would use mods, or multiple stations, or other alternative means but there are some (rare) complex systems that exists too.
I'm interested in the development of your system. I have lots of Factorio experience but i am no professionnal programmer, where i can help the most would be describing "solutions" that are popular or systems that people use already, lemme know if there is something i can help with, i'm enjoying a lot those problem solving and i tend to have less and less since i'm usually lazily relying on methods that have become familiar to me and this one isn't for sure
I understood the "catch22" reference after some research.
I think there are some mechanism that you may want to experiment with : the ability to connect the train station to circuit network.
From here you can read train content and/or train ID. Train ID is a fragile mechanism since their ID is changed everytime you add/remove wagon.
but maybe with this additionnal interaction you will find a way to identify which train/which material is at bay, and setting inserter filters according to this.
"Order more item by whitelisting them and also dynamically settings the filters according to this" this i'm lost, it is outside of the scope of what i'm familiar with due to my factorio experience .
You are trying to make a system that i would consider too complicated for myself for which (most) people would use mods, or multiple stations, or other alternative means but there are some (rare) complex systems that exists too.
I'm interested in the development of your system. I have lots of Factorio experience but i am no professionnal programmer, where i can help the most would be describing "solutions" that are popular or systems that people use already, lemme know if there is something i can help with, i'm enjoying a lot those problem solving and i tend to have less and less since i'm usually lazily relying on methods that have become familiar to me and this one isn't for sure
Re: Madzuir's balancer prone to deadlocks?
Man, I think I did it!
The day after my second post in this discussion (so on monday), I sat down and had a good think about this, and had an idea that I had a feeling might just work.
Several hours (!) later, I had made something that is now happily running in my world, working just as I've been dreaming about ever since my first train station overloaded.
Not only that, but I had also written a very detailed, 9 page (!!!) document (with illustrations, though), explaining how it all works by describing the process of making different versions, then realising their shortcomings, and fixing those issues.
I just want to run this station for a while, so I can be absolutely sure that it works as intended, and then I'm planning to submit the document somewhere here in the forums for peer review, in the hopes that someone will get a kick out of reading and trying to understand my design. Maybe someone will spot a way to make my design even cleaner and more elegant. Maybe someone will want to use it, too. That would be great.
I'm not getting my hopes up, though. I honestly don't think anyone will care to read something some guy wrote about a train station design. But you never know. It's the internet, after all.
I'll let you know when it's been posted, so you can have a look if you want. No pressure, of course.
As always, thanks for taking the time to read my posts so far, trying to understand them, and to help me!
Re: Madzuir's balancer prone to deadlocks?
Now I think we really need to start a peer-reviewed Factorio Forums Scientific Journal...Bolletott wrote: ↑Thu Apr 16, 2020 9:33 am Not only that, but I had also written a very detailed, 9 page (!!!) document (with illustrations, though), explaining how it all works by describing the process of making different versions, then realising their shortcomings, and fixing those issues.
I just want to run this station for a while, so I can be absolutely sure that it works as intended, and then I'm planning to submit the document somewhere here in the forums for peer review
There are 10 types of people: those who get this joke and those who don't.
Re: Madzuir's balancer prone to deadlocks?
Bolletott wrote: ↑Thu Apr 16, 2020 9:33 am Not only that, but I had also written a very detailed, 9 page (!!!) document (with illustrations, though), explaining how it all works by describing the process of making different versions, then realising their shortcomings, and fixing those issues.
I just want to run this station for a while, so I can be absolutely sure that it works as intended, and then I'm planning to submit the document somewhere here in the forums for peer review, in the hopes that someone will get a kick out of reading and trying to understand my design.
don't let it go to waste even if it's not working exactly as intended/fully finished before you change objectives/interest ! i'd gladly try to understand a step by step approach that may be more of my level ( with pictures ), i catch things fast when people make long and detailled explanation and then i FEEL smart
I'm not qualified to review those maps as a scientist would, but i'd sure enjoy it as a tourist would in this time of quarantine !
Re: Madzuir's balancer prone to deadlocks?
Hey!
Awesome that you want to read the thing. I'm the same as you in that I enjoy a good puzzle.
I took your advice and just posted it, so it's now available here: viewtopic.php?f=194&t=83860
I feel like I should say, though, that I'm starting to fear I've played this up a bit too much. After all, I am just a beginner on my first game.
I looks like it works, and I'm happy with it, but maybe someone will read it, understand it and go: I'll let anyone who reads it be the judge of that, I guess.
Well, if you do read it, I hope you have fun with it. You've been following this for quite a while. Let's hope it wasn't a complete waste of time.
All the best!
Awesome that you want to read the thing. I'm the same as you in that I enjoy a good puzzle.
I took your advice and just posted it, so it's now available here: viewtopic.php?f=194&t=83860
I feel like I should say, though, that I'm starting to fear I've played this up a bit too much. After all, I am just a beginner on my first game.
I looks like it works, and I'm happy with it, but maybe someone will read it, understand it and go: I'll let anyone who reads it be the judge of that, I guess.
Well, if you do read it, I hope you have fun with it. You've been following this for quite a while. Let's hope it wasn't a complete waste of time.
All the best!