Page 1 of 2

Train pathing through station

Posted: Sun Nov 12, 2017 2:34 pm
by Mimos
Hi,

as far as I understand https://wiki.factorio.com/Railway/Train_path_finding trains should not path through unused stations if nothing extraordinary happens. But still I have this issue quite often. As you can see below, the light blue has a train station but still the trains like to path through it. Even adding a 2nd station to increase the penalty doesn't help.
Stupid route.jpg
Stupid route.jpg (317.87 KiB) Viewed 8211 times
This happens to me quite often in a complicated station which causes many congestions. Maybe this issue is somehow caused by my long train paths (several thousand tiles)?
Does anyone have a solution, or is this maybe a bug that I should report?

Thanks for your help.

Re: Train pathing through station

Posted: Sun Nov 12, 2017 2:45 pm
by Jap2.0
There are no circuits on the main rail and both stations are enabled?

Re: Train pathing through station

Posted: Sun Nov 12, 2017 2:47 pm
by sillyfly
Could there be a signalling issue with the part of the track aside the station?
What happens if you completely break the station part off? Do you get any "No Path" errors?
It may help to upload your save file, as it is hard to see all the details just form the screenshot.

Re: Train pathing through station

Posted: Sun Nov 12, 2017 7:54 pm
by Mimos
Jap2.0 wrote:There are no circuits on the main rail and both stations are enabled?
I got no circuits controlling signals at all. Both stations are enabled.
sillyfly wrote:Could there be a signalling issue with the part of the track aside the station?
What happens if you completely break the station part off? Do you get any "No Path" errors?
I don't think there is a signalling issue, most trains just drive straight and skip the station.
Also no "No Path" errors.

Savegame:
Station issue small.7z
(18.49 MiB) Downloaded 108 times
You need to extract it and then repack is as a .zip, this saves some file size for up/downloading. I also used the ups-up-mod to reduce the size even further.

If you want to find the station, just take a train to: "Iron Ore 15 Bhf"
So you may take a look at the station. The error is pretty rare in this place though, not a lot of trains driving there.

Re: Train pathing through station

Posted: Sun Nov 12, 2017 8:02 pm
by Zavian
If there is a train on the straight section, then the path-finder might consider the longer route through the station as better. Typically though I would only expect that to happen if the 'loop' was otherwise empty, which means it shouldn't cause delays for a train that wants to use the station.

This post viewtopic.php?f=194&t=52544 has a setup that is designed to solve your porblem. (I haven't used it myself, but Aaargha generally knows what he is talking about with the train network).

Re: Train pathing through station

Posted: Sun Nov 12, 2017 9:30 pm
by Mimos
As far as I understand the penalty for another train, especially if it is a long distance away, should not be higher than the penalty for a station.

Also, even if the loop/station is empty at the time of the pathfinding, another train may still arrive before the train taking the detour. This happens sometimes in my tightly packed main station with one train that stops for a long time, the "wrong" train blocks the main track, a long queue builds up end everything comes to a standstill.


Thanks for your link, I'll give it a try. although I don't think it will help, considered a station should give 2k penalty, a signal, that is red by circuit, only 1k. At least it's a pretty nice Idea, though.
Update: I overlooked the chain signal at the station entrance, it should probably work. Although queues requires a dummy station.

Re: Train pathing through station

Posted: Sun Nov 12, 2017 9:34 pm
by Zavian
Well mrvn also described his approach to solving the same problem in that thread I linked.

Re: Train pathing through station

Posted: Sun Nov 12, 2017 10:09 pm
by Jap2.0
Yeah - the penalty for a full block is 2*length, which shouldn't be a penalty of more than a few hundred here. Each station adds a penalty to 1000.

Re: Train pathing through station

Posted: Sun Nov 12, 2017 10:48 pm
by Mimos
I think the penalty of a station is even 2k. A signal red by circuit is 1k according to https://wiki.factorio.com/Railway/Train_path_finding.

Re: Train pathing through station

Posted: Mon Nov 13, 2017 12:15 am
by Mimos
Zavian wrote:This post viewtopic.php?f=194&t=52544 has a setup that is designed to solve your porblem.
Well, in my post before I overlooked the chain signal at the entrance to the train station track. After some test it looks like this still does not prevent bad pathing but it might prevent the train to enter if it actually arrives. Although designing queues requires one dummy station for each entry path.

I also have a savegame where a bad path is planned less than 1min after loading. It still is changed again a few seconds later. I can provide it in case the devs are interested.

Re: Train pathing through station

Posted: Mon Nov 13, 2017 12:48 am
by eradicator
You say that your problem is that trains "path through" the sation instead of going around it. But i'm guessing your problem is actually trains blocking the whole track when a train attempts to path through the station in a situation where the station is already occupied. Because if the station wasn't occupied a train driving through it at full speed would not pose any problems. So ...based on that assumption of your problem, i think you can simply solve it by encasing the whole parralel tracks section into a singular chain signal block (compressed example below). That way any train attempting to pass the block will wait before the block and then use whichever side of the track is free. Hopefully resulting in trains more often using the shorter track that doesn't get the 2K Station penalty. (Btw, yea. it's 2K not 1K as some ppl say)
chain-station.jpg
chain-station.jpg (175.2 KiB) Viewed 8159 times
If you have similar problems on larger setups you might want to consider reading more about the magic of signals (or call me an idiot for being completly wrong :P).

Re: Train pathing through station

Posted: Mon Nov 13, 2017 2:55 pm
by Mimos
eradicator wrote:You say that your problem is that trains "path through" the sation instead of going around it. But i'm guessing your problem is actually trains blocking the whole track when a train attempts to path through the station in a situation where the station is already occupied.
Yes, you are right. So a train passing through an empty station is still ugly, but I can live with it.

Thanks for your solution. I like it, because it is quite simple. Although stations using a queue or even a stacker require more complicated solutions (as suggested in the previous posts).

Re: Train pathing through station

Posted: Tue Nov 14, 2017 9:32 pm
by Xeorm
I know it's also the equivalent of asking if the computer is plugged in, but you are playing with the latest version right? Non-experimental builds shouldn't have the station pathfinding increase.

Re: Train pathing through station

Posted: Tue Nov 14, 2017 10:04 pm
by Mimos
Xeorm wrote:I know it's also the equivalent of asking if the computer is plugged in, but you are playing with the latest version right? Non-experimental builds shouldn't have the station pathfinding increase.
I'm using 0.15.37 which is the newest stable version as of now. Starting with 0.15 the station penalty should be applied according to https://wiki.factorio.com/Railway/Train_path_finding.

Re: Train pathing through station

Posted: Wed Nov 15, 2017 3:41 am
by impetus maximus
Mimos, aside from the chain signal, did you try the entire solution Zavian linked to?

Re: Train pathing through station

Posted: Wed Nov 15, 2017 5:44 am
by eradicator
impetus maximus wrote:Mimos, aside from the chain signal, did you try the entire solution Zavian linked to?
I missed that post at first. But that really is a nice solution. I experiemented before with that kind of block-detection but didn't have a good usecase for it :). Aesthetically it's not very pleasing though, sadly.

Re: Train pathing through station

Posted: Wed Nov 15, 2017 10:53 am
by Mimos
impetus maximus wrote:Mimos, aside from the chain signal, did you try the entire solution Zavian linked to?
Yes, I did. At least if I didn't overlooked something. I made some screenshots, right before the train plans the worong path and right after it. Sadly it's pretty zoomed out and thus a little hard to see. You cannot see the circuits, but you can see that the controlled signal is red both times. You can also see a train passing by which is probably causing this mess.
Before after.png
Before after.png (549.82 KiB) Viewed 8049 times

Re: Train pathing through station

Posted: Fri Nov 17, 2017 4:25 pm
by aaargha
I think I've figured out what is happening. The reason that the path through the station becomes cheaper is that the train on the main path is in the arrive_station state. From what I can tell from some testing the major part of the "train is waiting at station" penalty, which is huge for most wait conditions (I got bored with testing at about 200k), is also applied for that state and not only for wait_station.

What happens is that as a train is calculating its path another train is on the main line outside the loop station and is braking for entering a nearby station (they start really far away). As the penalty for the braking train is gigantic the path through the station is shorter. As far as I can tell from trying your save, if the train is only passing by it does not cause this behaviour.

Unfortunately it's hard to get around this problem in a nice way, though placing this contraption at the split before the stations might help. Some uglier alternatives include moving the stations far away from the main line so the trains are off the main line when they change to arrive_station. Another ugly solution would be to add an additional train stop before the final stop that trains would wait at for 0 seconds, this would remove the excessive penalty.

There are already changes planned to how trains work for 0.16 but I'll do some testing to try to confirm this behaviour and then perhaps file a bug report. (EDIT: Bug report here for those interested)

Re: Train pathing through station

Posted: Sat Nov 18, 2017 1:28 pm
by Mimos
Thanks for your explaination! You are right, the coal train just starts braking when it's on this intersection.

But how can you see the exact state of a train? I looked at the color of its "show-train-stop-point" indicator, but the names you use suggest you know another way.

Re: Train pathing through station

Posted: Sat Nov 18, 2017 3:25 pm
by aaargha
I'm using

Code: Select all

/c game.player.print(game.player.selected.train.state)
to see which entry from the list here it is (0 based) while hovering over a train. 6 is arrive_station and 7 is wait_station.

The Lua API holds a lot of goodies once you know where to look :)

I'm thinking of making a mod that would change the colours of trains depending on which state they're in so that it's easier to debug these kinds of issues. It shouldn't be that hard, but we'll see.