Factorio

Factorio

View Stats:
Linck Mar 10, 2023 @ 11:07am
Can trains switch routes?
I have the following scenario:
https://share.sketchpad.app/23/6b6-6559-d903e9.png

There is train A and train B. Train A is trying to go to station 2, and train B is trying to go to station 4. They're both blocking each other. That's what happening in my game, but I was expecting train B to change it's route and take the rail on the right through station 3, even though it's the longer path

Is there any possible reason why that is not happening? And if that's how it's supposed to work, is there anything I can do?
< >
Showing 1-15 of 21 comments
shadain597 Mar 10, 2023 @ 11:39am 
At a guess, your signals are probably telling train B that the route is blocked, even though it isn't physically. Though I don't know if having station 3 on the main line is messing up train B's pathing.

In the future, try to avoid having stations directly on the tracks of a main line. Not only does it potentially block traffic, IIRC even an empty station creates a huge penalty for trains deciding if that path is worth taking. Basically, when deciding the shortest route, any station they have to pass through makes the path count as much longer than it actually is.

Also, I personally don't like using two-way tracks. Other people make it work, but trying to have more than one train on a two-way track is a headache I don't need. Besides, either it's a dead-end style that needs a locomotive on each side of each train (quite inefficient) or it's got some kind of loop anyways, so might as well build out a second line of track in parallel to eliminate these kinds of issues and improve potential throughput.
Drareg Mar 10, 2023 @ 11:48am 
I don't usually answer with the "don't do it that way", but 1 rail with both ways for multiple trains is a bad idea
Trains can block each other, signals are more difficult and it doesn't scale and trains can go through a station but the game tries not to
The best way will always be multiples rails (in pairs) going one direction each with more rails branching off the main rail, like roads

But for your thing, maybe signals, can a train go in the opposite way of the station?
Train fixing is hard without a full view of it
AlexMBrennan Mar 10, 2023 @ 12:12pm 
Trains can switch routes but they usually don't because they try to take the shortest path. A rail being blocked by a train adds a small penalty so eventually the train will try a different path but that will take forever.

Path 3 is 3x as long as path 1 which is why the train will wait a very long time before taking that long detour. Ideally you want paths 1 and 3 to be the same length. Better yet, make 1 and 3 one way tracks to stop trains from being able to choose the wrong path.
Linck Mar 10, 2023 @ 12:35pm 
I built a lot of my tracks as a two-way knowing to a good extent that this would make things difficult. I really liked trains in factorio so I made a lot of things harder than they should be on purpose because I wanted the extra complexity, but there are some problems that I just can't wrap my head around probably because I don't know some of the concepts of how train routing works.

I learned some really useful things from you guys though: That stations in the route add a big penality, and that trains do switch paths but it can take some time. But they WILL eventually switch routes if there is another route available, is that right?

Where do you guys learn these things?

I would like to share the full picture but it's hard to see with just a screenshot because things get too tiny. Is there a convenient way to share these things?

Anyway, thanks for the replies so far. I think for now when that happens again, I'll wait and see if the train eventually switch routes, even if it takes a long time. If I confirm that it does, then maybe I'll think about optimizing it
Linck Mar 10, 2023 @ 12:42pm 
Here is a screenshot though: https://imgur.com/a/nS9RBJS
Science is station 1
Magma is station 2
Pistonolleon is station 3
West Prime is station 4
Chindraba Mar 10, 2023 @ 12:57pm 
Screenshot wise, just take good shots of where the signals are, the long track between won't matter, now knowing that it's long.
Trains will, eventually, switch routes, only if an different route ends up being shorter. If the alternate route is always longer, even after the "penalty" for another train in the way, it will not switch routes.
Since the two-way signals are always chain signals it don't matter so much, but a train sitting at a chain signal will revalidate its path every multiple of 5 seconds. It will also check for a new path every 5 or 30 seconds. 5 seconds when there are multiple stations with the same name as the destination and 30 seconds where there is only one with the same name.
(It's written as "only a single train stop with the same name as the destination" but I think that means not two stops, the current destination and another named the same, but only one stop which happens to have the same name as the train's schedule. Take that part however you want.)
During the repath is when the new route will be checked. It will still pick the "shortest" route, penalties included. And, BTW, there is a penalty for going through a station between stations too, which is "When the path includes a train stop -> Add a penalty of 2000"
All this stuff is in the wiki under Railway/Train_path_finding
https://wiki.factorio.com/Railway/Train_path_finding
Chindraba Mar 10, 2023 @ 1:06pm 
Looking at the screenshot I think the problem might be the section at the junction between station Franc and the roboport. Southbound train A has left the station and reserved the track upto the signal south of the SE curve fork. That reservation blocks B from moving. Though I also see a few other possible issue, and cannot be sure which one is the root of the problem. Signals on in the map is good. If you can, even by manually placing trains, recreate the deadlock and then look at the map with signals on it might help in your search.

I also like playing with odd rail configurations, including mixtures of two-way and one-way as well as one-way and two-way trains on the same rails. Still, any train stop on the main line is asking for trouble. Stubs, sidings or some other plan, need not take too much room, yet still avoid some real headaches later. Such as, the route through station 3, Pistonolleon also included Jolion Norse. Total penalty, 4000, not counting other things which could make it even worse. All added to the already much longer route.

The penalty for a train in the way, which is tied to time is "When the rail block contains a train currently waiting at a rail signal -> Add a penalty of 100 + 0.1 for every tick the train has already waited." It's going to take a very long time for that to add up to exceed the bare-rail cost of the outer loop with a minimum 4000 penalty on it.
Last edited by Chindraba; Mar 10, 2023 @ 1:24pm
Linck Mar 10, 2023 @ 1:09pm 
Ok,
Bottom part: https://imgur.com/a/BT8NvJp
Top part: https://imgur.com/a/NlNhhJ6

Are those ok?

Oh I see, so it's all about the shortest route including penalities, and a train in the way is just another penality, doesn't matter how long it has been stopped there (?)

I'll have a look at that wiki page, thank you!
Hedning Mar 10, 2023 @ 1:34pm 
If you want to make passing lanes try to keep the detour below 100 tiles. That way trains can use the passing lane without having to wait. Best is to make the passing lane right next to the main track.

Originally posted by Linck:
doesn't matter how long it has been stopped there (?)
You get 6 tiles added per second the other train has stood still at its signal.


Originally posted by Linck:
Ok,
Bottom part: https://imgur.com/a/BT8NvJp
Top part: https://imgur.com/a/NlNhhJ6
And what trains are stopped and can't move?
Last edited by Hedning; Mar 10, 2023 @ 1:35pm
Chindraba Mar 10, 2023 @ 1:38pm 
Originally posted by Hedning:
And what trains are stopped and can't move?

The deadlock is not in the screen shots. The description is in a drawing in the OP.

And. looking again at the map, There is no route to West Prime from Magma passing through Pistonolleon. The track with Pistonolleon for east-bound trains has no turn onto the track with Jolion Norse for west-bound trains. The intersection near the SE corner of the image is not a junction. Unless, maybe, signals are set right to allow a lane switch east of Pistonolleon, but cannot tell for sure either way.
Last edited by Chindraba; Mar 10, 2023 @ 1:45pm
Linck Mar 10, 2023 @ 3:07pm 
Yes I think I know what lane switch you're talking about, it is set up. This is the route:
https://imgur.com/a/gKaXlir

I've tested manually triggering it to go from Magma to Jolion Norse, then to West Prime (in automatic mode), and it does make that route without any issues.

I've also played a bit more, and saw the deadlock happen again. It did actually resolve itself after about a minute. It took the long route through Jolion Norse as expected.

So I think it is working. Maybe last time I just didn't wait long enough?

Originally posted by Hedning:
You get 6 tiles added per second the other train has stood still at its signal.

I think it's working because of this then
Linck Mar 10, 2023 @ 3:19pm 
Yep I saw the deadlock happen again, here are some screenshots: https://imgur.com/a/Bdex3vC

It did eventually clear up. I saw the train in the bottom switch routes in the route map =)

I'll have to think what I'll do now to fix this, but things are much clearer now
Chindraba Mar 10, 2023 @ 4:03pm 
If the north-bound train is always 2 cars, like the one in the screenshot and you are willing to loose part of your road, you could put a bypass siding between the crossing gate by Franc and the trio of underground belts. Rail signal on the south (inside the bypass) to allow the train to stop there and chain on the north (inside the bypass). The detour for north-bound is way shorter, so the delay will be also, and the final trip will be shorter as well.
If the north-bound trains could be larger, you might be able to make one between the two crossing gates, loosing the whole road between them by the underground belts.

BTW< I love that you're not using "standard" station names, like Iron Load, Iron Unload. Adding some creativity to the names is more fun. Unless you get stupid crazy with it like I did, then it's a real challenge, and fun.
Linck Mar 10, 2023 @ 4:49pm 
It did cross my mind making the bypass you described, but no way, I like how my road looks like, and it would be too easy. I want to work with the constraint of having that extremely inefficient intersection right in the middle of the factory, and a train using that intersection to move resources within the main factory instead of what could have been just belts, and making other trains painfully queue up around it

The way the rails are set up, trains are not really supposed to go straight from south to north. The only train that should do that is that one that moves resources within the main base. It goes on a triangle pattern from magma > science > pistonolleon, so it always clears up for other trains.

So the rules would be:
- Trains coming from the south can only turn east in the intersection, except one specific train
- Trains coming from the east can only turn north in the intersection

It would look like this:
https://imgur.com/a/bP6LyhY

That's the dream, but I don't think that's possible in factorio



Originally posted by Chindraba:
BTW< I love that you're not using "standard" station names, like Iron Load, Iron Unload. Adding some creativity to the names is more fun. Unless you get stupid crazy with it like I did, then it's a real challenge, and fun.

What kind of stupid crazy? I did name a lot of my stations, but some like "Jolion Norse" are just what the game auto-generated. I do plan to give all of them proper names though =)
Chindraba Mar 10, 2023 @ 8:06pm 
Originally posted by Linck:
That's the dream, but I don't think that's possible in factorio

The dream can become reality, that is, if I've got the correct picture in my mind. In short, the pink line is the "never go here" path which only the interior shuttle can use.

Have you used Google Maps much? It always wants to give the fastest or shortest route, and it's seemingly impossible to make it go some other way - either to avoid a place you don't want to go, like past 5 school zones at super slow speed, or to go through some place you really want to go, like past a nice view that makes the drive a bit better. The answer to both problems is to create a "waypoint". For Google that's adding a "destination" between start and end which is on the road it won't normally take you, which makes it re-plan the route to get there and makes it into what you want. Factorio trains will do the same thing. A stop on the schedule with no wait conditions is a waypoint. A wait condition of zero seconds is not the same as no condition. A zero-second condition will cause the train to stop-and-go, like an airplane doing a touch-and-go landing. Setting a waypoint in the schedule forces a train to go "that way" even if it's not the best choice for getting from the stop before to the stop after it. On you map, set a waypoint station for east-bound trains on the track between the two Pistonolleon stations. Then add it to the schedule of any train which does travel from someplace south of magma to someplace north of science. All those trains will travel past Magma, turn right by Franc and head to the waypoint. From there it will head eastward onto where it's supposed to go.

Originally posted by Linck:
What kind of stupid crazy?

You asked about the "stupid and crazy." Well, I gave the engineer an extra bit of personality. Seems he's a bit lonely, and rather home-sick for Terra. The biters are a real nuisance sometimes. To remind himself of home he's named the different sections of the factory after old-home companies. Well, mostly anyway. I'm guessing that he's managed to salvage some reference material from the crashed ship. Can't imagine he's trapped ALL that knowledge in his head. If it was in his head he wouldn't need to do "research" for new technologies. The reference could also include information about the major companies of Earth, especially as they are probably the ones who were instrumental in creating, building and launching the spaceship and would insist on being included in the on-board computer databases.

The other piece of his personality is that he's a very organized chap. Some of the spaghetti he builds might not look it, but he's even a tad OCD. In keeping his lists he insists that the "source" of something be in the list before it's destination and that all the stations for something are together. It wouldn't do at all to have a list for example, like 'wood burner, oil field, coal load, iron plate drop, coal unload, iron smelter, iron mine, refinery, wood pickup'. It should be wood pickup, wood burner, coal load, coal unload, iron mine, iron smelter, iron plate drop, oil field, refinery'. To complicate things, stations ought to be in the general flow of raw materials, intermediates, finished products. Science ought to have it's own group, as should the recycling system and the launch facilities. Then there's all the internal distribution and perimeter defense stuff. Quite a lot to organize. But, hey, this is one smart engineer, after all.

So, if you're brave enough, here's the list, as given by the train GUI
https://steamcommunity.com/sharedfiles/filedetails/?id=2945450070

TFMG
Last edited by Chindraba; Mar 11, 2023 @ 8:37am
< >
Showing 1-15 of 21 comments
Per page: 1530 50

Date Posted: Mar 10, 2023 @ 11:07am
Posts: 21