Train Station Scheduling

Don't know how to use a machine? Looking for efficient setups? Stuck in a mission?
Post Reply
rcp27
Long Handed Inserter
Long Handed Inserter
Posts: 61
Joined: Wed Apr 26, 2017 3:34 pm
Contact:

Train Station Scheduling

Post by rcp27 »

I'm experimenting setting up a more intelligent trains system, something I've not really done before, and I'm observing some unintended behaviour. I have a setup with a pickup station, drop-off station and depot station. I have it set up so that the pick up and drop off stations only open if there is sufficient supply or demand, and my intention is that the train visits the depot station between pickup and drop off in both directions. I have a "5 seconds inactivity" on the depot to allow for refuelling. I am also sending a signal along wires so that the train will wait at the depot until the pickup or drop-off station is open. My schedule is therefore depot "5 s inactivity" and "pickup open signal" - pickup station inventory full - depot "5 s inactivity" and "drop-off open" - drop-off station inventory empty.

I'm in a situation where the base was idle for a while, so the train collected a full load, but the drop-off is full, so it's waiting at the depot for the "drop-off open" signal. I start production up, the drop-off station empties, station opens and train gets the signal. What I would expect is the train goes to drop off, returns to the depot, then goes to pick up (because the pickup station is full and sending its signal). What I'm observing is when the drop-off station opens, the train gets the signal, sets off, goes straight back to the depot, waits 5 s, then goes to the pickup station, then back to the depot, then goes to the drop-off.

My best guess about what is happening is that I'm seeing something like a race condition. The signal "need more stuff" gets sent to the train and to the station at the same moment, so the train decides what to do at the same time the station does. When the train gets the signal to go, the station is still reporting as closed, so the train skips that step. I want to control open and closed stations so that I can run with a multiple pickup and drop-off system with the same name. Am I interpreting this correctly, or is there something I might have got wrong? Any idea how to make it work as I intend?

Pi-C
Smart Inserter
Smart Inserter
Posts: 1652
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: Train Station Scheduling

Post by Pi-C »

rcp27 wrote:
Sun Apr 28, 2019 12:40 pm
I'm experimenting setting up a more intelligent trains system, something I've not really done before, and I'm observing some unintended behaviour. I have a setup with a pickup station, drop-off station and depot station. I have it set up so that the pick up and drop off stations only open if there is sufficient supply or demand, and my intention is that the train visits the depot station between pickup and drop off in both directions.
What do you mean by "stations open"? Do you deactivate the entire station to close it? I've been building a similar system, but I never deactivated stations. It worked on the premise that all stations had the same name, and all trains had the same schedule (either combinator signal = GREEN, or inactivity=5s), so any train could transport anything, and I had lots of mixed cargo trains. If a station needed something, it sent a signal on a pulse to register its request with the depot; the same signal was also sent constantly until a train fulfilling that request arrived.
I have a "5 seconds inactivity" on the depot to allow for refuelling. I am also sending a signal along wires so that the train will wait at the depot until the pickup or drop-off station is open. My schedule is therefore depot "5 s inactivity" and "pickup open signal" - pickup station inventory full - depot "5 s inactivity" and "drop-off open" - drop-off station inventory empty.
In my case, the depot regularly checked if any of the waiting trains carried something which was needed at the moment. That check went down the tracks, from left to right; first train that matched something would be released, and the request count for the matched item was decreased. Refuelling was done at a station right before the depot. That refueling point would take fuel from cargo wagons if the train that stopped there carried fuel (coal or solid fuel), and put fuel into the locomotives.
I'm in a situation where the base was idle for a while, so the train collected a full load, but the drop-off is full, so it's waiting at the depot for the "drop-off open" signal. I start production up, the drop-off station empties, station opens and train gets the signal. What I would expect is the train goes to drop off, returns to the depot, then goes to pick up (because the pickup station is full and sending its signal). What I'm observing is when the drop-off station opens, the train gets the signal, sets off, goes straight back to the depot, waits 5 s, then goes to the pickup station, then back to the depot, then goes to the drop-off.
That couldn't happen in my case because trains only were sent off when there was demand. However, it could happen that one station required something, say iron plates. A train carrying iron plates would be released by the depot, but that train would need to travel for some time until it arrived. If another train had been released because another station required stone walls and it carried both iron plates and stone walls, it could happen that this train was snatched up by the station that requested iron plates -- and the first train, that was supposed to bring in the iron plates, would have to go looking for another station that needed iron plates. If it could find any, it would return to the depot in the end, wasting fuel for nothing. :-)

I've still not given up on getting that system to work, but it will take time until I'll get around to that again. It worked on a small scale, kind of. But throughput wasn't good enough as the way routing trains to their destination worked wasn't optimal.

By the way, I didn't come up with the design by myself, but was heavily inspired by this series on YouTube (starting at episode 5 or 6). I actually copied the circuit logic setup from there -- not using any blueprints, but literally rebuilding everything, rewinding the video time and again to see what combinators were connected with red or green wires. I took me hours until I got even the simpler designs to work because it was so easy to make a wrong connection and mess everything up! However, it forced me to really try to understand how the designs worked, so it was an effective way to learn the ropes of combinator circuit logic. Unfortunately, the series stopped right at the point where things got interesting, so I finally had to come up with my own designs for routing trains. :-)
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

rcp27
Long Handed Inserter
Long Handed Inserter
Posts: 61
Joined: Wed Apr 26, 2017 3:34 pm
Contact:

Re: Train Station Scheduling

Post by rcp27 »

Pi-C wrote:
Sun Apr 28, 2019 2:09 pm
rcp27 wrote:
Sun Apr 28, 2019 12:40 pm
I'm experimenting setting up a more intelligent trains system, something I've not really done before, and I'm observing some unintended behaviour. I have a setup with a pickup station, drop-off station and depot station. I have it set up so that the pick up and drop off stations only open if there is sufficient supply or demand, and my intention is that the train visits the depot station between pickup and drop off in both directions.
What do you mean by "stations open"? Do you deactivate the entire station to close it? I've been building a similar system, but I never deactivated stations.
I mean I use the "deactivate station" circuit condition on the station. For a supply station, I read the contents of the station chests, and if contents > train capacity, I open the station, and I also use a decider combinator to send a signal of "1 [product]" on the wire. For demand stations, I read the contents of the chests and send a signal of "1 [demand]" on the wire, and also activate/deactivate the station on the same condition. To make things simple I use the item itself for supply and the letters for demand, so it sends 1 "C" for a copper ore inbound station. If you have more than one station with the same name (what I want to make this work), the train will go to the nearest active station of that name, regardless of which one is actually open. I therefore use the activate/deactivate station condition to deactivate the same-name stations that don't actually want to be used.

rcp27
Long Handed Inserter
Long Handed Inserter
Posts: 61
Joined: Wed Apr 26, 2017 3:34 pm
Contact:

Re: Train Station Scheduling

Post by rcp27 »

Pi-C wrote:
Sun Apr 28, 2019 2:09 pm
rcp27 wrote:
Sun Apr 28, 2019 12:40 pm
I'm experimenting setting up a more intelligent trains system, something I've not really done before, and I'm observing some unintended behaviour. I have a setup with a pickup station, drop-off station and depot station. I have it set up so that the pick up and drop off stations only open if there is sufficient supply or demand, and my intention is that the train visits the depot station between pickup and drop off in both directions.
What do you mean by "stations open"? Do you deactivate the entire station to close it? I've been building a similar system, but I never deactivated stations.
I mean I use the "deactivate station" circuit condition on the station. For a supply station, I read the contents of the station chests, and if contents > train capacity, I open the station, and I also use a decider combinator to send a signal of "1 [product]" on the wire. For demand stations, I read the contents of the chests and send a signal of "1 [demand]" on the wire, and also activate/deactivate the station on the same condition. To make things simple I use the item itself for supply and the letters for demand, so it sends 1 "C" for a copper ore inbound station. If you have more than one station with the same name (what I want to make this work), the train will go to the nearest active station of that name, regardless of which one is actually open. I therefore use the activate/deactivate station condition to deactivate the same-name stations that don't actually want to be used.

Pi-C
Smart Inserter
Smart Inserter
Posts: 1652
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: Train Station Scheduling

Post by Pi-C »

rcp27 wrote:
Sun Apr 28, 2019 12:40 pm
My best guess about what is happening is that I'm seeing something like a race condition. The signal "need more stuff" gets sent to the train and to the station at the same moment, so the train decides what to do at the same time the station does. When the train gets the signal to go, the station is still reporting as closed, so the train skips that step. I want to control open and closed stations so that I can run with a multiple pickup and drop-off system with the same name. Am I interpreting this correctly, or is there something I might have got wrong? Any idea how to make it work as I intend?
One thing you could do on pick-up/drop-off station: Check for opening condition. If condition is fulfilled, send out a signal on two wires. One wire goes directly from the combinator to the train stop to open that station. The other wire goes through a timer that activates once it receives something on input, but waits for some ticks before it lets the signal go through to the depot (and thus, the train). That should make sure that the station already is open once the train starts moving, so it can find a path to it.
rcp27 wrote:
Sun Apr 28, 2019 3:27 pm
I mean I use the "deactivate station" circuit condition on the station. For a supply station, I read the contents of the station chests, and if contents > train capacity, I open the station, and I also use a decider combinator to send a signal of "1 [product]" on the wire.
How about mining outposts that have run out of ore? Suppose they end up with contents < train capacity, that last load would never be picked up.
For demand stations, I read the contents of the chests and send a signal of "1 [demand]" on the wire, and also activate/deactivate the station on the same condition. To make things simple I use the item itself for supply and the letters for demand, so it sends 1 "C" for a copper ore inbound station.
That could get quite messy with lots of different products! If you use "C" for copper, what would you use for coal? In the worst case, you might run out of letters for all the products you want to transport by train; and even if there are enough signals available, you'd have to remember what letter you've used for which product. Would it be possible in your design to use the same signal (the icon of the thing you want to transport) for both demand and supply, but using different wires? Say, "1 iron ore" on red wire signifies a station needs iron ore, while "1 iron ore" on green signifies there's a train load of iron ore to pick up?
If you have more than one station with the same name (what I want to make this work), the train will go to the nearest active station of that name, regardless of which one is actually open. I therefore use the activate/deactivate station condition to deactivate the same-name stations that don't actually want to be used.
In my case, stations needing a train sent out a constant guiding signal on the global network of either "1 [demanded item]" or "1 C" (if they needed an empty train to pick up solid cargo) or "1 F" (if they needed an empty train to pick up fluids). Once a train stopped at that station the guiding signal was turned off.

Whenever I had rails branch off the main line, I'd add a guiding station where every train would stop. Then I determined whether that train was one needed on the branch-off and set the signals accordingly. Unfortunately, that delayed every train -- and sometimes, stations behind a branch would compete for the same train (say, the station off the main line would constantly have enough iron ore to load a whole train, so all empty cargo trains would go to the station providing iron ore and none would arrive at the station further behind on the main line that provided copper ore). To work around that, I added a condition at the supply stations. They would only request an empty train "IF contents >= train capacity AND IF [item supplied by the station] == [item demanded on global network]". In effect, that deactivated the station without turning it off.
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

rcp27
Long Handed Inserter
Long Handed Inserter
Posts: 61
Joined: Wed Apr 26, 2017 3:34 pm
Contact:

Re: Train Station Scheduling

Post by rcp27 »

Pi-C wrote:
Sun Apr 28, 2019 5:17 pm
rcp27 wrote:
Sun Apr 28, 2019 12:40 pm
My best guess about what is happening is that I'm seeing something like a race condition. The signal "need more stuff" gets sent to the train and to the station at the same moment, so the train decides what to do at the same time the station does. When the train gets the signal to go, the station is still reporting as closed, so the train skips that step. I want to control open and closed stations so that I can run with a multiple pickup and drop-off system with the same name. Am I interpreting this correctly, or is there something I might have got wrong? Any idea how to make it work as I intend?
One thing you could do on pick-up/drop-off station: Check for opening condition. If condition is fulfilled, send out a signal on two wires. One wire goes directly from the combinator to the train stop to open that station. The other wire goes through a timer that activates once it receives something on input, but waits for some ticks before it lets the signal go through to the depot (and thus, the train). That should make sure that the station already is open once the train starts moving, so it can find a path to it.
Yeah, I could, that seems a bit extreme, though
Pi-C wrote:
Sun Apr 28, 2019 5:17 pm
rcp27 wrote:
Sun Apr 28, 2019 3:27 pm
I mean I use the "deactivate station" circuit condition on the station. For a supply station, I read the contents of the station chests, and if contents > train capacity, I open the station, and I also use a decider combinator to send a signal of "1 [product]" on the wire.
How about mining outposts that have run out of ore? Suppose they end up with contents < train capacity, that last load would never be picked up.
No different than just having a point to point train that is set to wait for inventory full. At some point when a mine runs out there will be a part train load. In the process of tearing everything down, manually bringing a train in to take out the last partial load is not too big a problem.
Pi-C wrote:
Sun Apr 28, 2019 5:17 pm
For demand stations, I read the contents of the chests and send a signal of "1 [demand]" on the wire, and also activate/deactivate the station on the same condition. To make things simple I use the item itself for supply and the letters for demand, so it sends 1 "C" for a copper ore inbound station.
That could get quite messy with lots of different products! If you use "C" for copper, what would you use for coal? In the worst case, you might run out of letters for all the products you want to transport by train; and even if there are enough signals available, you'd have to remember what letter you've used for which product. Would it be possible in your design to use the same signal (the icon of the thing you want to transport) for both demand and supply, but using different wires? Say, "1 iron ore" on red wire signifies a station needs iron ore, while "1 iron ore" on green signifies there's a train load of iron ore to pick up?
I don't expect to be in a position of sending 36 items by train, so 26 letters and 10 numbers is probably going to be enough. I thought about using red for request and green for supply, but I'm not sure how to make a circuit condition for a train departing the depot station that discriminates between the signal coming in over the red or green wire. There are ways of discriminating using combinators, but I'll deal with that problem once I've got this system working.

Pi-C
Smart Inserter
Smart Inserter
Posts: 1652
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: Train Station Scheduling

Post by Pi-C »

rcp27 wrote:
Sun Apr 28, 2019 10:00 pm
Pi-C wrote:
Sun Apr 28, 2019 5:17 pm
rcp27 wrote:
Sun Apr 28, 2019 12:40 pm
My best guess about what is happening is that I'm seeing something like a race condition. The signal "need more stuff" gets sent to the train and to the station at the same moment, so the train decides what to do at the same time the station does. When the train gets the signal to go, the station is still reporting as closed, so the train skips that step. I want to control open and closed stations so that I can run with a multiple pickup and drop-off system with the same name. Am I interpreting this correctly, or is there something I might have got wrong? Any idea how to make it work as I intend?
One thing you could do on pick-up/drop-off station: Check for opening condition. If condition is fulfilled, send out a signal on two wires. One wire goes directly from the combinator to the train stop to open that station. The other wire goes through a timer that activates once it receives something on input, but waits for some ticks before it lets the signal go through to the depot (and thus, the train). That should make sure that the station already is open once the train starts moving, so it can find a path to it.
Yeah, I could, that seems a bit extreme, though
Perhaps you don't even need a complete timer: A signal needs one tick to pass through a combinator. You could try whether one tick delay would be sufficient. If so, one wire could go directly to the train stop, the other could go through an arithmetic (condition: "EACH*1") or decider (condition: "EACH>0" in, EACH input count" out) combinator to the train depot.

rcp27 wrote:
Sun Apr 28, 2019 12:40 pm
I don't expect to be in a position of sending 36 items by train, so 26 letters and 10 numbers is probably going to be enough. I thought about using red for request and green for supply, but I'm not sure how to make a circuit condition for a train departing the depot station that discriminates between the signal coming in over the red or green wire. There are ways of discriminating using combinators, but I'll deal with that problem once I've got this system working.
Do I understand you right that each of your trains will only carry one item at any time? In that case, you could discriminate between full and empty trains and use two depots. You could then check for demand signals at the depot for full trains, and for supply signals at the depot for empty trains. It gets a bit complicated if you want to use cargo and fluid wagons because you wouldn't want to send off an empty cargo train to pick up oil. You could discriminate between cargo and fluid trains by reserving one stack for a token item (something that you'd never transport regularly, e.g. a pistol) on cargo trains, though.
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

rcp27
Long Handed Inserter
Long Handed Inserter
Posts: 61
Joined: Wed Apr 26, 2017 3:34 pm
Contact:

Re: Train Station Scheduling

Post by rcp27 »

Pi-C wrote:
Mon Apr 29, 2019 12:16 am
Do I understand you right that each of your trains will only carry one item at any time? In that case, you could discriminate between full and empty trains and use two depots. You could then check for demand signals at the depot for full trains, and for supply signals at the depot for empty trains. It gets a bit complicated if you want to use cargo and fluid wagons because you wouldn't want to send off an empty cargo train to pick up oil. You could discriminate between cargo and fluid trains by reserving one stack for a token item (something that you'd never transport regularly, e.g. a pistol) on cargo trains, though.
With the current system I am working with each train is dedicated to a particular item type. Separate in and out depots is one option, but one I would prefer not to take because it doubles the size of the depot stations and imposes extra routing constraints on the trains. I could do something clever with arithmetic combinators to distinguish between supply and demand signals to be able to use the same item for each, but there are enough signal types that I can’t foresee running out, but getting confused is a potential issue.

Pi-C
Smart Inserter
Smart Inserter
Posts: 1652
Joined: Sun Oct 14, 2018 8:13 am
Contact:

Re: Train Station Scheduling

Post by Pi-C »

rcp27 wrote:
Mon Apr 29, 2019 6:10 am
With the current system I am working with each train is dedicated to a particular item type. Separate in and out depots is one option, but one I would prefer not to take because it doubles the size of the depot stations and imposes extra routing constraints on the trains.
You could have one huge depot for both empty and full trains, or two smaller ones. Shouldn't matter that much in terms of space -- you could waste some on presorting the trains (but releasing trains would be very simple), or you could waste space on additional combinators per train (more clearly arranged combinators could lead to wider spaces between tracks).
I could do something clever with arithmetic combinators to distinguish between supply and demand signals to be able to use the same item for each, but there are enough signal types that I can’t foresee running out, but getting confused is a potential issue.
Yes, the number of available signals would be more relevant if mods with lots of new ores etc. are used, but getting confused is the real issue here! It's so easy to mix up one-letter codes (now, was "C" coal or copper, and was that copper ore or copper plates?), using the icons is more intuitive -- especially if you want to change something later on. I prefer using separate depots for IN/OUT, but if you come up with an ingenious design for a single depot handling everything, I'd be interested in seeing it. :-)
A good mod deserves a good changelog. Here's a tutorial (WIP) about Factorio's way too strict changelog syntax!

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

Re: Train Station Scheduling

Post by mrvn »

When using deactivated stations it's best to use schedules with exactly 2 stops and only ever deactivate one of them. For mines I deactivate the mines if they don't have enough ores for a train. I never deactivate the smelter and the smelter acts as depot for the trains and refuels as well. Since the furnaces need fuel anyway refueling there is easy.

The logic becomes much simpler too. All trains are set to wait till empty/full. They unload at the smelter and then wait for a mine to activate the station and off they go.

When a mine is depleted a partial load will be sitting there and never get collected. So when you want to tear it down simply enable the station one more time and then deconstruct. I never found it worth implementing circuit logic to collect that last bit automatically but it could be done with a simple time. If no more ore appears within a minute but some is present: enable station.

Post Reply

Return to “Gameplay Help”