Better train control

Post your ideas and suggestions how to improve the game.

Moderator: ickputzdirwech

rampelstinskin
Inserter
Inserter
Posts: 45
Joined: Sun May 04, 2014 9:11 am
Contact:

Better train control

Post by rampelstinskin »

Trains control in Factorio requires a lot of micromanagement. To make train network working, player must constantly change train schedule.
For example: If I have 10 iron ore outposts to prevent congestion, I must give different names to train stops. In addition, if I have three iron ore consumers I must constantly monitor each train to prevent starvation.
Moreover, I must do it for each resource.
Mod "logistic train network" (LTN) can solve all problems but it is monolithic do everything by magic. Which is not in Factorio spirit. Well... I also looking at you logistic bots.

I suggest set of independently useful features that working together can do everything what LTN can.
1)Limit how many trains can be sent to train stop. Including train waiting at train stop.
Add 3 new options to train stop GUI:
Manual limit.
Set limit from circuit network.

When no option selected limit is MaxInt.
When both options selected use minimum value as limit.
Usual use case: Manually set how many trains can be parked at train station without clogging train network. Circuit network tells how many trains can be loaded from station storage.

This is simple and surprisingly powerful feature by itself can solve most problems with train control.
To solve example above, all I need to do is set limit for each train stop and add 20-30 trains with identical schedule.
a)Depo. Wait until inactive.
b)Iron ore - Load. Wait until full.
c)Iron ore - Unload. Wait until empty.
In fact, this is a simple LTN working with a single resource.

2)Train stop priority.
Add 2 mutually exclusive options to train stop GUI:
a)Manual priority. Default 0
b)Set priority from circuit network.
Right now train always go to closest train stop. However, it not always what I need.
For example: it is usually good idea send train to load items from train stop with biggest item count.

Train stop selection algorithm:
From all train stops.
Select if stop.IsEnabled
Select if stop.IncomingTrainsCount < stop.MaxIncomingTrainsCount
Select if stop.Name == Name
If remaining stops count <= 1 then end
Select stops with maximum priority
If remaining stops count <= 1 then end
Select stops with minimum incoming trains count
If remaining stops count <= 1 then end
Select stops with shortest distance
If remaining stops count <= 1 then end
Select stops with minimum X coordinate
Select stops with minimum Y coordinate

Two last filters needed to make algorithm deterministic.
After train stop selected train ignores changes in MaxIncomingTrainsCount and priority.

Optimization notes:
Three first filters can be reordered.
Five first filters can be fused into single pass algorithm.

3)Send to circuit network how many trains going to train stop.
By itself, this feature can be used for diagnostics.
In combination with train controller it can be used to send exact number of trains.

4)New building: Train controller.
Contains train schedule.
When connected to train stop by circuit network overrides schedule in train stopped at this train stop, by schedule form controller.
Can be connected to multiple train stops.
Have option to enable/disable by signal from circuit network.
When multiple train controllers connected to same train stop if no controllers enabled or more than one controller enabled erase train schedule.

Use case 1: Change schedule of all trains, which stop at this train stop. Doing it manually for 10+ trains annoying.
Use case 2: LTN
When train station ready to accept train it send to global circuit network signal for providing item.
At depo train controller set to all waiting trans schedule for that item.
Thanks to limit on train stop only one train start moving.
Train stop detects new incoming train and stop sending signal global circuit network.
Train controller become disabled and erases schedule from waiting trains.

Optimization note: Train schedule can be object with reference counting with copy on write when reference counter more than one.
This way, copying schedule to many trains will be cheap operation.

5)New building: Train stop controller.
Contains train stop name.
When connected to train stop by circuit network overrides name of train stop.
Can be connected to multiple train stops.
Have option to enable/disable by signal from circuit network.
When multiple train stop controllers connected to same train stop if no controllers enabled or more than one controller enabled set train stop name to empty string and disable train stop.

Use case: Requesting and/or providing different items at same train stop.
dood
Filter Inserter
Filter Inserter
Posts: 360
Joined: Wed Mar 21, 2018 8:36 am
Contact:

Re: Better train control

Post by dood »

You can actually give all your iron stations the same name.
Trains will auto-pick the nearest free one. If they depart close to each other, 2 trains sometimes pick the same station so you have to account for that and make enough space for a train to wait but for the most part, trains will spread evenly and you never have to touch their schedule.

I don't know where the resource consumer issue lies, if you have 1 centralized storage/smelter, that also functions to focus the throughput of all your ore outposts and you can just have trains go there indefinitely.
rampelstinskin
Inserter
Inserter
Posts: 45
Joined: Sun May 04, 2014 9:11 am
Contact:

Re: Better train control

Post by rampelstinskin »

dood wrote:You can actually give all your iron stations the same name.
Trains will auto-pick the nearest free one. If they depart close to each other, 2 trains sometimes pick the same station so you have to account for that and make enough space for a train to wait but for the most part, trains will spread evenly and you never have to touch their schedule.
I tested in 0.16.35
Train network completely clogged. Now i need manual intervention to unclog it.
dood wrote: I don't know where the resource consumer issue lies, if you have 1 centralized storage/smelter, that also functions to focus the throughput of all your ore outposts and you can just have trains go there indefinitely.
I don't have one location. It not scalable.
Manron
Inserter
Inserter
Posts: 39
Joined: Mon Apr 11, 2016 5:21 pm
Contact:

Re: Better train control

Post by Manron »

rampelstinskin wrote: Train network completely clogged. Now i need manual intervention to unclog it.
if your train network cloggs up you dont have enough stations or waiting bays. also you have to make sure your blocks after every intersection are not shorter than your longest train.
rampelstinskin
Inserter
Inserter
Posts: 45
Joined: Sun May 04, 2014 9:11 am
Contact:

Re: Better train control

Post by rampelstinskin »

Manron wrote:if your train network cloggs up you dont have enough stations or waiting bays. also you have to make sure your blocks after every intersection are not shorter than your longest train.
1)I know everything about trains.
2)I tested in case some magic was added in last versions. It wasn't.
Problem happens when I have 10 trains. And I need send 2 trains to one station. And 8 to another.
Manron
Inserter
Inserter
Posts: 39
Joined: Mon Apr 11, 2016 5:21 pm
Contact:

Re: Better train control

Post by Manron »

it works fine for me. i use some combinator logic to only allow as many trains on the network as needed and keep the rest in stackers. i dont know what you are doing, but i never had 8 trains going to the same station at once and i use about 30 trains in my current game.
Last edited by Manron on Thu Mar 29, 2018 11:07 pm, edited 2 times in total.
bobucles
Smart Inserter
Smart Inserter
Posts: 1708
Joined: Wed Jun 10, 2015 10:37 pm
Contact:

Re: Better train control

Post by bobucles »

1)Limit how many trains can be sent to train stop. Including train waiting at train stop.
This would be a great option. It'd be far superior to the current "Station closed everyone go home" vs. "Yeah I'll take ALL the trains" that enable/disable does.

My current train setup has all my iron ore trains running to a giant smelting base. The smelting base uses multiple stations with a shared name, and was ultimately not too bad to set up. However each ore outpost has vastly different train needs and I simply don't know how to control how many trains go where. My solution was to create a custom train route for each outpost and build the exact number of trains that need to service an outpost. If stations could define an "X trains coming my way" limit then you only need to define one train route to service all the iron outposts. Increasing or decreasing the train supply is a simply matter of changing the station's train limit.

There may be a problem if a certain station name is allotted fewer "train slots" than the number of trains servicing that station name. You'd certainly need to count carefully or some kind of upgraded train interface would be needed.
rampelstinskin
Inserter
Inserter
Posts: 45
Joined: Sun May 04, 2014 9:11 am
Contact:

Re: Better train control

Post by rampelstinskin »

Manron wrote:it works fine for me. i use some combinator logic to only allow as many trains on the network as needed and keep the rest in stackers.
Will not work for uneven stations.
Manron wrote: i dont know what you are doing, but i never had 8 trains going to the same station at once and i use about 30 trains in my current game.
It's factorio...
Do you know LCCCC trains have throughput of 16 blue belts? But you need many trains.
bobucles wrote:There may be a problem if a certain station name is allotted fewer "train slots" than the number of trains servicing that station name. You'd certainly need to count carefully or some kind of upgraded train interface would be needed.
If you have schedule like this
a)Depo. Wait until inactive.
b)Iron ore - Load. Wait until full.
c)Iron ore - Unload. Wait until empty.
All you need is big depo where unused train can wait.
And you can do refueling at depo. This makes all other stations simpler.
Saunis
Burner Inserter
Burner Inserter
Posts: 15
Joined: Tue Jan 09, 2018 2:55 pm
Contact:

Re: Better train control

Post by Saunis »

I need better GUI to work whit trains. Train list is total mess, i'ts hard to find your special trains...

It would be much better, if you can stack trains in to groups. (example, "Iron ore haulers"). Even better would be, if I could set color theme for that group. So every train and station use same color. (and in train list group's background were also in that color so I can easily see whats that group is)
bobucles
Smart Inserter
Smart Inserter
Posts: 1708
Joined: Wed Jun 10, 2015 10:37 pm
Contact:

Re: Better train control

Post by bobucles »

If you have schedule like this
a)Depo. Wait until inactive.
b)Iron ore - Load. Wait until full.
c)Iron ore - Unload. Wait until empty.
All you need is big depo where unused train can wait.
And you can do refueling at depo. This makes all other stations simpler.
What I mean is this:

You have 2 iron ore outposts. One is huge and is set to a limit of 5 trains. One is small and has a limit of 2 trains.
You set up 10 trains to route between "smelter base" and "iron ore outpost".
At SOME point you'll get a train pathing error. There are only 7 slots of "iron ore outpost" while 10 trains may attempt to path it at the same time. If a train fails to path then it may trap itself in the smelter base, for example. Now it's blocking other trains.

Let's change the scenario so the ore outpost has 10 train slots and the ore outpost has 7 slots. You run 15 trains between the 17 slots of these two stations. This creates a potentially serious issue where only 2 slots are open for a train to move freely. As train networks get more spaghettified you may even experience total station-related deadlocks where more trains than slots exist so NOTHING can move.

Obviously the player needs to make sure they don't get in that situation in the first place. The UI can help by showing how many "slots" a station name has available. If the player exceeds the slot count then it'll show a warning somewhere (such as when trying to set more trains on the same route).
rampelstinskin
Inserter
Inserter
Posts: 45
Joined: Sun May 04, 2014 9:11 am
Contact:

Re: Better train control

Post by rampelstinskin »

bobucles wrote: What I mean is this:
I understood you before I started this conversation.
I described solution to this problem in first message.
This is why I have depo in schedule. All trains without destination will wait in depo without blocking anything.
dood
Filter Inserter
Filter Inserter
Posts: 360
Joined: Wed Mar 21, 2018 8:36 am
Contact:

Re: Better train control

Post by dood »

rampelstinskin wrote:All trains without destination will wait in depo without blocking anything.
They don't.
Saunis
Burner Inserter
Burner Inserter
Posts: 15
Joined: Tue Jan 09, 2018 2:55 pm
Contact:

Re: Better train control

Post by Saunis »

rampelstinskin wrote:
bobucles wrote: What I mean is this:
I understood you before I started this conversation.
I described solution to this problem in first message.
This is why I have depo in schedule. All trains without destination will wait in depo without blocking anything.
dood wrote:
rampelstinskin wrote:All trains without destination will wait in depo without blocking anything.
They don't.

Depo wont work, if you have more trains than queuing slots.
Biggest problems I had with depo were when ore pit stations were almost empty and when one opened, about 3-4 trains rush in there...
So first one gets cargo, second (maybe) can load. (but in a very long time) And rest goes in to other ore pit, or if there's no free or active station, they run that round empty.

Later on, when bigger ore pits were far away, trains hustles around those small ore pits and only few trains found them self in that big ore pit.


At 0.16 I started new map and almost solved this problem by mining more ore than I can spend. So now trains queue in smelting...
But this map is so fresh, than I can't know how things really turn out to be...
User avatar
Lubricus
Filter Inserter
Filter Inserter
Posts: 298
Joined: Sun Jun 04, 2017 12:13 pm
Contact:

Re: Better train control

Post by Lubricus »

What if there where some sort of train-schedule combinator that you could send a train to a specific train-station with. Then it would be possible but hard to make an effective train controller jiggamajigg with combinator magic. (Is there a mod that is doing that?)
The trick with name the train stations the same and open close them only scale up to a specific level. With an to big and resource hungry factory the trains are going to hunt i packs and going to the same station. And it's true that we somehow have to limit the amount of trains going towards the same station.
rampelstinskin
Inserter
Inserter
Posts: 45
Joined: Sun May 04, 2014 9:11 am
Contact:

Re: Better train control

Post by rampelstinskin »

Saunis wrote: Depo wont work, if you have more trains than queuing slots.
Biggest problems I had with depo were when ore pit stations were almost empty and when one opened, about 3-4 trains rush in there...
This is misunderstanding.
You talking about current behavior. And I 100% agree about it.
But I assumed first feature of my proposal implemented. I did it because I and bobucles talked about it.
In this case all you need is set limit of a station to one train.
And only one train will go to that station.
Problem solved.
Lubricus wrote:What if there where some sort of train-schedule combinator that you could send a train to a specific train-station with.
Too hard. Only few players in the world will be able use it.
dood
Filter Inserter
Filter Inserter
Posts: 360
Joined: Wed Mar 21, 2018 8:36 am
Contact:

Re: Better train control

Post by dood »

rampelstinskin wrote:
Saunis wrote: Depo wont work, if you have more trains than queuing slots.
Biggest problems I had with depo were when ore pit stations were almost empty and when one opened, about 3-4 trains rush in there...
This is misunderstanding.
You talking about current behavior. And I 100% agree about it.
But I assumed first feature of my proposal implemented. I did it because I and bobucles talked about it.
In this case all you need is set limit of a station to one train.
And only one train will go to that station.
Problem solved.
Unavailable stations get skipped.
Empty trains that can't go to to iron ore load will go back and forth from the depot to to iron ore unload.
If you also limited the unload station to X trains, full trains will skip the congested unload station and go to the depot.
It'll be a huge mess.
rampelstinskin
Inserter
Inserter
Posts: 45
Joined: Sun May 04, 2014 9:11 am
Contact:

Re: Better train control

Post by rampelstinskin »

dood wrote:Unavailable stations get skipped.
No if you add one more train stop with same name and not connect it to rail network by rails.
Just one train stop on one rail track is enough.
In this case train will wait and complain about "no path".
Tested in 0.16.35
Saunis
Burner Inserter
Burner Inserter
Posts: 15
Joined: Tue Jan 09, 2018 2:55 pm
Contact:

Re: Better train control

Post by Saunis »

rampelstinskin wrote:
Saunis wrote: Depo wont work, if you have more trains than queuing slots.
Biggest problems I had with depo were when ore pit stations were almost empty and when one opened, about 3-4 trains rush in there...
This is misunderstanding.
You talking about current behavior. And I 100% agree about it.
But I assumed first feature of my proposal implemented. I did it because I and bobucles talked about it.
In this case all you need is set limit of a station to one train.
And only one train will go to that station.
Problem solved.
I'm just pinpointing what kind of problem this current system have.
Your suggestion is good, and there's is not easy way to get around this kind of problem.
rldml
Fast Inserter
Fast Inserter
Posts: 181
Joined: Sun Mar 06, 2016 2:38 am
Contact:

Re: Better train control

Post by rldml »

The wish to make the train part more dynamic is called often in the ideas and suggestion-forum:

- Assign trains to schedules (viewtopic.php?f=6&t=53473)
- train stop-id and schedule-option to target a train stiop via its id (viewtopic.php?f=6&t=53792)
- Jump on Train-Condition (viewtopic.php?f=6&t=58646)
- Train station skipping condisitions (viewtopic.php?f=6&t=25944)
- Train entry condition (viewtopic.php?f=6&t=49214)
- Train ignore stop if wait condition already met (viewtopic.php?f=6&t=58057)
- Track signals should send train-id to network (viewtopic.php?f=6&t=47541)
- Express/Priority Trains (viewtopic.php?f=6&t=57742)
- Train stations reservations (viewtopic.php?f=6&t=57596)
- Train scheduling algorithm improvement (viewtopic.php?f=6&t=57756)
- for smart-ish trains how about a "repathing train signal" (viewtopic.php?f=6&t=56656)
- Train schedule Stop Offsets (viewtopic.php?f=6&t=56693)

There are possibly some more threads i did not found. But the amount of threads shows, that there is a weak spot in the game logic, which need some improvements.

Actually trains can target a station only by its name, so if you name more than one station identically, the train always choose the one with the shorter distance. One thing, you can do via the API is to exchange a train schedule. So, if you give different names to your stations you could design a mod to make the trains more dynamic. In fact, LGN and SmarterTrains do exactly this. Sadly, they do much more than this... :(

edit:
I've started writing an own mod, but to be honest i am a terrible mod writer and hate LUA, so don't count on me ;). My idea is to create a new entity, a schedule-conservator (looks like a constant combinator), that can store a train schedule. I'll try to implement the copy-mechanic to it, so you should make your train schedule as ususal in a train and copy it to the new enitity. The entity allows to send the schedule over the circuit network. A train stop has to get an option to overwrite a train schedule of a arriving train with a schedule it gets via circuit network.

This should be possible within the existing API. If there is anyone smarter person out there, feel free to steal this idea ;)

Greetings, Ronny
rampelstinskin
Inserter
Inserter
Posts: 45
Joined: Sun May 04, 2014 9:11 am
Contact:

Re: Better train control

Post by rampelstinskin »

rldml wrote: - Assign trains to schedules (viewtopic.php?f=6&t=53473)
Train controller, described in starting message, can do it and more.
rldml wrote: - train stop-id and schedule-option to target a train stiop via its id (viewtopic.php?f=6&t=53792)
It will be very hard to use. But masochists can use train controller to do it.
rldml wrote: - Jump on Train-Condition (viewtopic.php?f=6&t=58646)
- Train station skipping condisitions (viewtopic.php?f=6&t=25944)
- Train entry condition (viewtopic.php?f=6&t=49214)
- Train ignore stop if wait condition already met (viewtopic.php?f=6&t=58057)
Much better solution is replace train schedule with scratch-like language.
https://scratch.mit.edu/
rldml wrote: - Track signals should send train-id to network (viewtopic.php?f=6&t=47541)
I don't see how this can be useful.
rldml wrote: - Express/Priority Trains (viewtopic.php?f=6&t=57742)
- Train scheduling algorithm improvement (viewtopic.php?f=6&t=57756)
Will create more problem than benefits.
rldml wrote: - Train stations reservations (viewtopic.php?f=6&t=57596)
Same as my first suggestion.
rldml wrote: This should be possible within the existing API. If there is anyone smarter person out there, feel free to steal this idea ;)
Do you realize you talking about train controller?
Last edited by rampelstinskin on Tue Apr 03, 2018 8:58 pm, edited 1 time in total.
Post Reply

Return to “Ideas and Suggestions”