Smart Train Deliveries with Combinator Magick [0.13/0.14]

This board is to show, discuss and archive useful combinator- and logic-creations.
Smart triggering, counters and sensors, useful circuitry, switching as an art :), computers.
Please provide if possible always a blueprint of your creation.
User avatar
siggboy
Filter Inserter
Filter Inserter
Posts: 988
Joined: Tue Mar 29, 2016 11:47 am
Contact:

Smart Train Deliveries with Combinator Magick [0.13/0.14]

Post by siggboy »

Update 19/08/2016: I've uploaded a new demo map (simpler) with a new depot circuit that runs a lot better than the beta version. Please upgrade if you use it. viewtopic.php?f=8&t=25311&start=140#p191133

Use the version linked above. Do not use any older version in 0.13 (it won't work). For 0.12 maps you can still use the published version 2.
The information below is outdated but I'll leave it here for the moment since it's still valuable for those who want to learn how to make such a system.


What does it do?

Your trains will dynamically react to supply and demand and mostly do "the right thing" by themselves. Rail capacity is used efficiently and management is made easy.

It's a Logistic Network of Trains. Trains are sent from a central depot (roboport), go to outposts to pick up resources (providers), drop them off where they are needed (requesters), then return to the depot. There's only one train line (logistic network), and the trains can go anywhere, like robots.
  • Only one supply line: Run all trains on a single logical line, out of a single train depot (hub). Adding trains to the network is trivial: just plop down the train anywhere, preferably in the correct driving direction, assign it to the supply line, and start it. Done.
  • Dynamic train assignment: Trains don't have to be assigned to certain outposts or certain resources. Every train on the line can service any outpost. It's not necessary anymore to figure out how many trains to assign to each outpost, and you won't have to reassign trains all the time when outposts run dry or new ones are opened.
  • Supply detection: Outposts are not visited unless they're offering enough resources. No more half empty trains clogging up your railway. Use your own combinator logic to set the resource condition (it can be as simple as "> 1k ore" or as complex as you want).
  • No more train monkey business! While an outpost is being serviced, i.e. has a train en route to pick up resources, no other trains will visit that outpost. The common problem of two trains arriving at an outpost in short succession is completely avoided!
  • Demand detection: Demand from your factory is taken into consideration. A resource is not even eligible for pickup unless your factory requests it. For example, while your coal bunkers are full, your trains won't waste time making roundtrips to your coal mines. You also won't have trains full of coal sitting around at the coal unload.
  • Easy refueling, since all trains run through the same hub (Smart Trains does have a great refueling solution, but you won't even need it).
  • Flexible: the system is not limited to ore, it can be used to ferry intermediate products, too, even on the same logical line with the ore trains.
  • Practical, easy setup: no rewiring shenanigans necessary, combinator knowledge is not required. Two values need to be changed at each new outpost, and you're good to go. The station number can be taken verbatim from the Smart Trains UI, no desktop calculator required.
  • No outpost limit: the circuit handles as many outposts as you need (no limit at 31 bits or anything like that).
Major Update (30.05.2016): The new and improved version with actual requesters (like requester chests) is finished. The new demo map and blueprints are here. This post will be updated in time with the new version and documentation, after more testing.

My smart train controller requires the "Smart Train" mod by Choumiko; no other mods are needed, but FARL is a practical requirement because you need signal wire to connect all your outposts with the main depot.

Here's an animation that shows off some trains running:
Smart train controller in action
Screen shots of combinator setups are boring, but "no pix, no clix", so here you go:

Here's how the depot looks in game:
Screen shot of depot
This is an outpost:
Screen shot of outpost
(Diagrams of the circuits are found in the explanations below, so I have not annotated these screen shots.)

How does it work?

The system requires a combinator setup at the depot and at each outpost. It also requires red signal wire to connect all outposts and the depot.

All train stations need to be "smart train stations" as provided by the Smart Trains mod.

I'm now going in great detail over the workings of the outpost circuit and the depot circuit. Keep in mind that most of the signals that are processed are exactly 1 tick wide. Some of the contraptions only work because of this.

Before I go on, let me thank users Lupoviridae and XKnight for giving me various ideas in their forum postings. I could not have come up with some of that stuff on my own...

You should know how combinators and signals work and you should be familiar with the Smart Trains mod.
The outpost circuit
The depot circuit
How to set up Smart Trains
Here are the blueprint strings:
Blueprint for the smart depot
Update 24.05.2016: Made the smart outpost a little easier to setup (logic unchanged), added picture with explanations. The demo map does not use this version of the blueprint yet.
Blueprint for the smart outpost


Update 23.05.2016: Improved the demo map, demand from the unload is now calculated and used as input for the depot circuit. The dummy demand combinator has been removed. I've also streamlined the loading and unloading a little.

A demo map is attached to this post, and a collection of mods (only Smart Trains and Test Mode are required for the demo map, the others are for convenience).

The demand flags from the unload are transmitted with green wire and used as input for the depot circuit. The lights at the unload indicate if the unload is running low (the threshold is set to 7k ore, you can change this value as you see fit).
The combinator at the depot powerpole (north of the rail) can be used to suppress polling and reset the flags at the outposts (it will practically suspend all delivery and the trains will return to the depot). If you want to activate it, just connect it with red wire to the power pole right next to it.

Update: There's a new version here. It's much better than this one, but might still contain bugs. Edit: The new version seems to work fine, if you use the latest pre-release of SmartTrains (don't use the version from the mod pack). I've found no issues so far and I'm currently using it in a real game.

The stuff below is OBSOLETE. Only here for archival purposes. It will work in 0.12 though with the provided mods.
Attachments
Smart Train Demo.zip
(4.22 MiB) Downloaded 431 times
mods.zip
(233 KiB) Downloaded 520 times
Last edited by siggboy on Sun Oct 23, 2016 2:03 pm, edited 29 times in total.
Is your railroad worrying you? Doctor T-Junction recommends: Smart, dynamic train deliveries with combinator Magick
NoriSilverrage
Fast Inserter
Fast Inserter
Posts: 159
Joined: Mon Mar 21, 2016 1:19 pm
Contact:

Re: Smart, dynamic train deliveries with combinator Magick

Post by NoriSilverrage »

This looks/sounds amazing and it's essentially what I've been trying to do. Yours looks better though. Thanks for sharing and the very detailed post.

~edit: One question though. It's looking like you can only have 1 unload location at once. Granted you can put the same name on multiple stations though that may not balance the resources.
User avatar
siggboy
Filter Inserter
Filter Inserter
Posts: 988
Joined: Tue Mar 29, 2016 11:47 am
Contact:

Re: Smart, dynamic train deliveries with combinator Magick

Post by siggboy »

NoriSilverrage wrote:This looks/sounds amazing and it's essentially what I've been trying to do. Yours looks better though. Thanks for sharing and the very detailed post.

~edit: One question though. It's looking like you can only have 1 unload location at once. Granted you can put the same name on multiple stations though that may not balance the resources.
You can have as many unload stations as you want. You have to configure SmartTrains so that it sends the train from the outpost to the correct unload station (look at the example SmartTrains configuration at the bottom of the article and you see how it's done correctly). If you want multiple unload stations for the same resource, and balance those, you have to do that manually (e.g. assign Iron 1 and Iron 2 to Iron Unload A, assign Iron 3 and Iron 4 to Iron Unload B, etc.).

In fact, this is a limitation of the current design. The system would actually be a Logistic Network with trains if the unload stations were chosen dynamically as well. In fact, this is going to be the next version, because I'm pretty sure my system can be expanded that way. Somebody in the SmartTrains thread gave me the idea.

A Logistic Network for trains. Depot = Roboport, Unload Stations = Requester Chests, Outposts = Passive Provider Chests, Trains = Robots. We're almost there :).
Is your railroad worrying you? Doctor T-Junction recommends: Smart, dynamic train deliveries with combinator Magick
User avatar
ssilk
Global Moderator
Global Moderator
Posts: 12889
Joined: Tue Apr 16, 2013 10:35 pm
Contact:

Re: Smart, dynamic train deliveries with combinator Magick

Post by ssilk »

I stickied this, cause it's worth reading.

Maybe not forever, but the ideas go into the right direction and will be helpful with v0.13.
Cool suggestion: Eatable MOUSE-pointers.
Have you used the Advanced Search today?
Need help, question? FAQ - Wiki - Forum help
I still like small signatures...
User avatar
siggboy
Filter Inserter
Filter Inserter
Posts: 988
Joined: Tue Mar 29, 2016 11:47 am
Contact:

Re: Smart, dynamic train deliveries with combinator Magick

Post by siggboy »

Thanks for the sticky, much appreciated :mrgreen:

It was a lot of work writing this up, and making the diagrams (yEd is great for this, BTW, somebody on these forums recommended it, I forgot who it was). I hope that I can make the design truly complete and we have a real logistic network (the current design is already pretty close, though).
Is your railroad worrying you? Doctor T-Junction recommends: Smart, dynamic train deliveries with combinator Magick
ratchetfreak
Filter Inserter
Filter Inserter
Posts: 952
Joined: Sat May 23, 2015 12:10 pm
Contact:

Re: Smart, dynamic train deliveries with combinator Magick

Post by ratchetfreak »

To be able to select the unload you would need to send the requesting station to the loading station as well.
User avatar
siggboy
Filter Inserter
Filter Inserter
Posts: 988
Joined: Tue Mar 29, 2016 11:47 am
Contact:

Re: Smart, dynamic train deliveries with combinator Magick

Post by siggboy »

Yes, that's the plan. Probably we'll turn the "toggle register" in the outpost circuit into a general purpose register and store the value there. That way we'll still have the toggle flag and can also use it to send the train to the correct unload.

We'll also need to make a circuit to put at the unloading stations. A second polling signal will be necessary, so we can poll the unloading stations for requests/demand. It's not sufficient anymore that we know about demand for something, we also need to know where to bring it.

The trickiest part is on a higher level, though:

Let's say we have 1 coal outpost and plenty of demand for coal. So we poll for demand and get "coal", we then send a train to the outpost. Now the coal route is locked down until that train has finished loading, let's say for 1 minute. We poll for demand, and again get "coal". Nothing will happen until the coal outpost is ready again, we've blocked the supply route.

So I think we need to poll the provider side (outposts) first, using a resource filter as in the current version. We'll somehow have to build that filter from all the resources that are requested at any given time. When we found our provider, we then poll the requesters to find one that wants the resource.

The protocol gets a lot more complicated with that change.
Is your railroad worrying you? Doctor T-Junction recommends: Smart, dynamic train deliveries with combinator Magick
jcaferjr
Burner Inserter
Burner Inserter
Posts: 5
Joined: Tue May 17, 2016 1:43 am
Contact:

Re: Smart, dynamic train deliveries with combinator Magick

Post by jcaferjr »

Demand detection: Demand from your factory is taken into consideration. A resource is not even eligible for pickup unless your factory requests it. For example, while your coal bunkers are full, your trains won't waste time making roundtrips to your coal mines. You also won't have trains full of coal sitting around at the coal unload.
First off thank you for this amazing creation! I'm testing the on-demand factory requesting and cannot get it to work. I've downloaded your demo and have the mods installed. I run the game and everything works fine, then I fill the "copper Unload" chests full and cut off the belt system. The trains still come and wait.

Am I doing something wrong or perhaps didn't understand the comment above?

Thanks

My first post ;o)
User avatar
siggboy
Filter Inserter
Filter Inserter
Posts: 988
Joined: Tue Mar 29, 2016 11:47 am
Contact:

Re: Smart, dynamic train deliveries with combinator Magick

Post by siggboy »

jcaferjr wrote:First off thank you for this amazing creation! I'm testing the on-demand factory requesting and cannot get it to work. I've downloaded your demo and have the mods installed. I run the game and everything works fine, then I fill the "copper Unload" chests full and cut off the belt system. The trains still come and wait.

Am I doing something wrong or perhaps didn't understand the comment above?
In the demo map the "demand detection" is only a dummy, it's coming straight from a constant combinator (the one right next to the depot). If you look into the combinator you will see that it does have "Iron 1; Coal 1; Copper 1" signals. This indicates to the depot that all three resources are "in demand".

If you want to simulate actual demand detection on the demo map, you have to create your own little circuit that will output, for example, "Iron 1" when the iron level in the respective unload station is below a certain number. This is very easy, just connect all the smart chests with a decider combinator and set that to something like "If Iron < 10k -> Output Iron = 1" and connect it to the depot. You also need to remove the dummy output from the constant combinator.

Then you can run a more realistic test by filling chests at the unload and observe what happens.

Of course if you only want to simulate a saturated unload there's no need to build an actual circuit for it. Simply remove one of the constants (e.g. Iron 1) from the combinator and then you'll see that the iron "outposts" get skipped, until you set the "Iron 1" constant again.

It's important that in the current implementation these values need to be either "1" or "0" (no signal). So if you have two iron unloads it's not going to work if they both output "Iron 1", because that would get summed up to "Iron 2" and the depot won't handle it correctly. In that case (with multiple unload stations for the same resource) you need to consolidate these into a single signal that can be either "1" or "0" -- which is really not a problem and very easy to do, but I'm mentioning it just in case.
(OK, strictly speaking "Iron 2" is a permitted value, but it would be equivalent to "Iron 0"; any value other than "Resource = 1" disables that resource).
Is your railroad worrying you? Doctor T-Junction recommends: Smart, dynamic train deliveries with combinator Magick
jcaferjr
Burner Inserter
Burner Inserter
Posts: 5
Joined: Tue May 17, 2016 1:43 am
Contact:

Re: Smart, dynamic train deliveries with combinator Magick

Post by jcaferjr »

siggboy wrote:
jcaferjr wrote:First off thank you for this amazing creation! I'm testing the on-demand factory requesting and cannot get it to work. I've downloaded your demo and have the mods installed. I run the game and everything works fine, then I fill the "copper Unload" chests full and cut off the belt system. The trains still come and wait.

Am I doing something wrong or perhaps didn't understand the comment above?
In the demo map the "demand detection" is only a dummy, it's coming straight from a constant combinator (the one right next to the depot). If you look into the combinator you will see that it does have "Iron 1; Coal 1; Copper 1" signals. This indicates to the depot that all three resources are "in demand".

If you want to simulate actual demand detection on the demo map, you have to create your own little circuit that will output, for example, "Iron 1" when the iron level in the respective unload station is below a certain number. This is very easy, just connect all the smart chests with a decider combinator and set that to something like "If Iron < 10k -> Output Iron = 1" and connect it to the depot. You also need to remove the dummy output from the constant combinator.

Then you can run a more realistic test by filling chests at the unload and observe what happens.

Of course if you only want to simulate a saturated unload there's no need to build an actual circuit for it. Simply remove one of the constants (e.g. Iron 1) from the combinator and then you'll see that the iron "outposts" get skipped, until you set the "Iron 1" constant again.

It's important that in the current implementation these values need to be either "1" or "0" (no signal). So if you have two iron unloads it's not going to work if they both output "Iron 1", because that would get summed up to "Iron 2" and the depot won't handle it correctly. In that case (with multiple unload stations for the same resource) you need to consolidate these into a single signal that can be either "1" or "0" -- which is really not a problem and very easy to do, but I'm mentioning it just in case.
(OK, strictly speaking "Iron 2" is a permitted value, but it would be equivalent to "Iron 0"; any value other than "Resource = 1" disables that resource).
Ah, ok. I thought you figured out a way to demand resources without running the wires from each "factory." Sounds like your an electrical engineer. We did all the gates and flip-flops stuff. ;o)
User avatar
siggboy
Filter Inserter
Filter Inserter
Posts: 988
Joined: Tue Mar 29, 2016 11:47 am
Contact:

Re: Smart, dynamic train deliveries with combinator Magick

Post by siggboy »

jcaferjr wrote:Ah, ok. I thought you figured out a way to demand resources without running the wires from each "factory."
Yeah, I have: set the flags manually in the combinator :-).

But seriously, it's not possible until we get wireless transmission for the combinator network.
Sounds like your an electrical engineer. We did all the gates and flip-flops stuff. ;o)
I'm a software developer. The combinators work quite differently from discrete electronic circuits (not least due to the fact that there is no current and no voltages). It's a strange mixture of digital computer and basic electronic circuit.

One of my first naive attempts to build a flip-flop started by me looking at an electronics book and imitating a flip-flop made from transistors in Factorio. Of course that's not the best way to do it, but in order to understand that you have to first figure out how feedback-loops work. I think it's arcane, and conventional electrical engineering knowledge hurts more that it helps (BTW I know next to nothing about EE).
Is your railroad worrying you? Doctor T-Junction recommends: Smart, dynamic train deliveries with combinator Magick
kann_
Inserter
Inserter
Posts: 44
Joined: Fri Apr 15, 2016 4:36 pm
Contact:

Re: Smart, dynamic train deliveries with combinator Magick

Post by kann_ »

That looks cool. I will have a deeper look how you did it.
I don't want to steal the show or anything. But I recently posted something similar on reddit, which might be interesting for you as-well: https://www.reddit.com/r/factorio/comme ... _provider/

Our setups are insanely similar. Did you know about mine?
That is really interesting.
I have difficulties to read your diagrams, but I will have a look at the demo map later.
My system has some problems/issues, maybe you can help me on those. Or we can put some work together.
I think there are a few things that are better in my system, for example my train counter at the outpost allows more throughput.
Also the requesting stations are on the multiplexing bus in my system. So it is possible to request resources from everywhere, but currently it only supports only one request station per resources same as in your setup.
But yours seem to be much more compact, which is a problem with mine.
To match requested resources and outpost resources I just add negative requests with positive supply of 1 and ignore every channel with positive result. I like your 2^31 approach, which seems much more compact.

How do you handle Oil? Can the system work with different trains?
You plan to have dynamic routing from loading station to different unloading stations?
How does your system chooses an outpost? In mine it just picks the first that satisfies the request, which prefers the first channels. Initially I used random numbers to looks for channels, but I dropped that idea.

I think with some extra work there could be a fully dynamic request/supply network with trains. With multiple request stations per resource.
User avatar
siggboy
Filter Inserter
Filter Inserter
Posts: 988
Joined: Tue Mar 29, 2016 11:47 am
Contact:

Re: Smart, dynamic train deliveries with combinator Magick

Post by siggboy »

kann_ wrote:That looks cool. I will have a deeper look how you did it.
I don't want to steal the show or anything. But I recently posted something similar on reddit, which might be interesting for you as-well: https://www.reddit.com/r/factorio/comme ... _provider/

Our setups are insanely similar. Did you know about mine?
That is really interesting.
I did not know about your setup but I'm excited that somebody else did have the same idea. We should work together to improve the project. I need to make some changes to make it more flexible and behave more like a real logistic network.

Xeteth has mentioned his own project (he also made a video) in the SmartTrains thread, here: viewtopic.php?f=97&t=14432&start=300#p159944

I'll look at your stuff and then probably reply some more.
Is your railroad worrying you? Doctor T-Junction recommends: Smart, dynamic train deliveries with combinator Magick
NoriSilverrage
Fast Inserter
Fast Inserter
Posts: 159
Joined: Mon Mar 21, 2016 1:19 pm
Contact:

Re: Smart, dynamic train deliveries with combinator Magick

Post by NoriSilverrage »

I downloaded your demo and watched the trains for a while and I'm quite impressed by the setup. It's really nice. I'm also amazed that you are able to do all that with so few combinators.
Got a question for you though. You have the depot (dispatcher) which waits for a station to signal it is ready to receive a train. But what happens if more than 1 station is ready at the same time?
User avatar
siggboy
Filter Inserter
Filter Inserter
Posts: 988
Joined: Tue Mar 29, 2016 11:47 am
Contact:

Re: Smart, dynamic train deliveries with combinator Magick

Post by siggboy »

NoriSilverrage wrote:I downloaded your demo and watched the trains for a while and I'm quite impressed by the setup. It's really nice. I'm also amazed that you are able to do all that with so few combinators.
I've done the same thing after I was done: watching the trains being quite impressed by myself. And I hate myself for it, but only a little :). It took me quite long to arrive at this design, somebody with real talent could have done it in an afternoon.

It doesn't require more combinators because I spent a LOT of effort making it as compact and efficient as possible. My earlier designs weren't as compact.

Also, don't forget that this circuit does no train counting (beyond the locking of stations) and no resource counting. The designs by kann_ and Xeteth are more advanced in that area, but they also require way more combinators.

This design needs to become more similar to kann_'s, I don't want to do train counting but probably some resource bookkeeping, and most importantly, select the unloading stations dynamically, you won't have to set that up in SmartTrains and it'll be more like a logistic network with robots (so the "requesters" will actually be requesters with an active role on the network).
Got a question for you though. You have the depot (dispatcher) which waits for a station to signal it is ready to receive a train. But what happens if more than 1 station is ready at the same time?
That does not matter. Every train that arrives at the depot (the actual station, the front of the row of trains) starts a new polling process and then some (arbitrary) station with resources will be selected for that train, as long as the resource is requested.
Is your railroad worrying you? Doctor T-Junction recommends: Smart, dynamic train deliveries with combinator Magick
kann_
Inserter
Inserter
Posts: 44
Joined: Fri Apr 15, 2016 4:36 pm
Contact:

Re: Smart, dynamic train deliveries with combinator Magick

Post by kann_ »

Maybe we can setup a "creative" server just to combine some of the ideas.
Although, with the next version coming up it might be worth of delaying it a bit.
With the deactivate function of train stations there will be some interesting possibilities.
If all outposts of the same resource have the same name we can just deactivate every outpost without resources. The same with unloading stations. There could be easily several unloading stations of the same resource that deactivate them self when full.

The new problems will be that the closest outpost will get crowded and it will be impossible to "reserve resources" since we don't know where the train ends up exactly.
NoriSilverrage
Fast Inserter
Fast Inserter
Posts: 159
Joined: Mon Mar 21, 2016 1:19 pm
Contact:

Re: Smart, dynamic train deliveries with combinator Magick

Post by NoriSilverrage »

siggboy wrote:
NoriSilverrage wrote:I downloaded your demo and watched the trains for a while and I'm quite impressed by the setup. It's really nice. I'm also amazed that you are able to do all that with so few combinators.
I've done the same thing after I was done: watching the trains being quite impressed by myself. And I hate myself for it, but only a little :). It took me quite long to arrive at this design, somebody with real talent could have done it in an afternoon.

It doesn't require more combinators because I spent a LOT of effort making it as compact and efficient as possible. My earlier designs weren't as compact.

Also, don't forget that this circuit does no train counting (beyond the locking of stations) and no resource counting. The designs by kann_ and Xeteth are more advanced in that area, but they also require way more combinators.

This design needs to become more similar to kann_'s, I don't want to do train counting but probably some resource bookkeeping, and most importantly, select the unloading stations dynamically, you won't have to set that up in SmartTrains and it'll be more like a logistic network with robots (so the "requesters" will actually be requesters with an active role on the network).
Got a question for you though. You have the depot (dispatcher) which waits for a station to signal it is ready to receive a train. But what happens if more than 1 station is ready at the same time?
That does not matter. Every train that arrives at the depot (the actual station, the front of the row of trains) starts a new polling process and then some (arbitrary) station with resources will be selected for that train, as long as the resource is requested.
Well I setup a system that selects a station to unload based on which one is least full. I ended up having to compare each station individually to get it to work right. And then I had to compare the go to station signals because otherwise a train might double up on a station. I believe I have about 15 combinators. I've no doubt there is a better way to do this which is partly why I asked the question about the train signal.

So theoretically, if you were running with 1 train, it could go to the same outpost over and over assuming it continues to broadcast as needing a pickup?
User avatar
siggboy
Filter Inserter
Filter Inserter
Posts: 988
Joined: Tue Mar 29, 2016 11:47 am
Contact:

Re: Smart, dynamic train deliveries with combinator Magick

Post by siggboy »

kann_ wrote:Maybe we can setup a "creative" server just to combine some of the ideas.
Not a problem, I have a dedicated server where I can run a Factorio instance.
Although, with the next version coming up it might be worth of delaying it a bit.
Yes, I agree. Choumiko also has to update SmartTrains for 0.13.
With the deactivate function of train stations there will be some interesting possibilities.
If all outposts of the same resource have the same name we can just deactivate every outpost without resources. The same with unloading stations. There could be easily several unloading stations of the same resource that deactivate them self when full.
The new problems will be that the closest outpost will get crowded and it will be impossible to "reserve resources" since we don't know where the train ends up exactly.
I don't think that this new function will have any impact at all for our projects. We use SmartTrains to send trains from depot -> outpost and from outpost -> unload, and the trains always go from unload -> depot. Deactivating stations does not change anything, and it won't make any of the circuits any simpler. I really don't care much about these changes.

What we need is a vastly improved train UI and a good chunk of the functionality of SmartTrains, FARL and FatController in the base game. Anything short of that really doesn't make much difference in my opinion.
Is your railroad worrying you? Doctor T-Junction recommends: Smart, dynamic train deliveries with combinator Magick
User avatar
siggboy
Filter Inserter
Filter Inserter
Posts: 988
Joined: Tue Mar 29, 2016 11:47 am
Contact:

Re: Smart, dynamic train deliveries with combinator Magick

Post by siggboy »

NoriSilverrage wrote:Well I setup a system that selects a station to unload based on which one is least full. I ended up having to compare each station individually to get it to work right. And then I had to compare the go to station signals because otherwise a train might double up on a station. I believe I have about 15 combinators. I've no doubt there is a better way to do this which is partly why I asked the question about the train signal.
My circuit does not distinguish between unload stations. The trains don't get directed from outpost (loading) to unloading by the circuit, the SmartTrains mod does that.

I wouldn't try to make a circuit that sends the train to the "least full" unload. That does not solve an actual problem. In a good setup the unload, which are your requester stations, should be able to request their resource and then a train should service that request ASAP (best effort). After a couple of deliveries (ideally only one), the requester will be "satisfied" or "saturated" and stop requesting resources for a while.

It's really not necessary to "balance unloading" among stations and count resources and all of this. As long as your requesters have resources to work with (i.e. not "running dry"), you're in an acceptable state. The entire setup should work towards that acceptable state, but not more than that.
So theoretically, if you were running with 1 train, it could go to the same outpost over and over assuming it continues to broadcast as needing a pickup?
OK, first of all the stations don't really "broadcast" that they need pickup. Each outpost (provider) may signal that it does have at least "X" of its resource ready for pickup (I like to put the threshold close to the capacity of a train; so while I'm using single-wagon trains a station will signal "ready" when it does have at least 1500 resources in the buffer).

Now, when a train arrives at the depot, the depot will immediate go through the list of all outposts and ask them, in turn, if they are "ready", that is, if they have "enough" of their resource to fill a train. They will reply "yes" if they do. Now we will compare this "yes" answer to the list of resources that are currently in demand, and we will simply ignore it if we're not interested in the resource. So, for example, if an iron outpost answers "yes", but we currently have no demand for iron, we'll just proceed to the next outpost -- and so on, until we've found an outpost that offers a resource that we want.

Then we go to that outpost.

Now, to answer your question: yes, if we only have 1 train and a constant need for, say, coal, and there's a coal outpost that offers a lot of coal, we'll send that train there over and over again. We will skip the other outposts. In this regard, the system is completely arbitrary, it will send the trains to the first acceptable station it finds.

In your example with 1 train the system is probably not going to be able to meet the demand of the factory. The system needs more trains. But if you were to schedule the train manually you'd have the same problem. The system isn't "broken" it just doesn't have enough trains to work with. It's not possible to design a circuit that meets impossible throughput requirements.

You can't fix a lack of trains with a circuit network, no matter how clever your setup. Focus on realistic scenarios, that are (a) not starved for resources (b) not overprovisioned with trains (c) not underprovisioned and (d) have a healthy, balanced, demand from your factory. And don't assume outlandish scenarios such as "my trains need to travel 5 minutes to reach an outpost, but they only carry 1 wagon each".

Or else you'll solve problems that don't exist and you'll end up with 50-combinator circuits that are impossible to debug.
Is your railroad worrying you? Doctor T-Junction recommends: Smart, dynamic train deliveries with combinator Magick
NoriSilverrage
Fast Inserter
Fast Inserter
Posts: 159
Joined: Mon Mar 21, 2016 1:19 pm
Contact:

Re: Smart, dynamic train deliveries with combinator Magick

Post by NoriSilverrage »

Cool. Thanks for the pointers and explanation.
Reading over your post I feel like my station balancing setup is very clunky and like you said, doesn't really solve the specific problem. I was actually going to need to redo it anyway as I changed from 3 to 4 stations so once again I shall dive into logic systems.. :shock:
Post Reply

Return to “Combinator Creations”