How the pathfinder works with stations.

OpenTTD is a fully open-sourced reimplementation of TTD, written in C++, boasting improved gameplay and many new features.

Moderator: OpenTTD Developers

mauried
Traffic Manager
Traffic Manager
Posts: 148
Joined: 07 Sep 2010 11:35

How the pathfinder works with stations.

Post by mauried »

Simple question , does the pathfinder apply a penalty to trains going via a station when the station isnt in their orders , when there is an alternative route which doesnt involve going thru the station.
eg if there are stations A,B and C and a train has orders to go from A to C , and has 2 options , go directly or go via Station B will it prefer the route which doesnt have station B in it.
tnx
Taschi
Route Supervisor
Route Supervisor
Posts: 425
Joined: 11 Oct 2014 22:58

Re: How the pathfinder works with stations.

Post by Taschi »

A quick test would indicate that there is - see attached photo and closely look at Mr Horsey, who is circled in red.
ottd-horsey.png
(1.03 MiB) Not downloaded yet
A second test might give us an idea on how big the penalty is:
ottd-horsey2.png
(754.7 KiB) Not downloaded yet
Mr Horsey is fine with taking the middle line, but if I remove that one, he will refuse to take the outer loop and go through the Ilkley station.
mauried
Traffic Manager
Traffic Manager
Posts: 148
Joined: 07 Sep 2010 11:35

Re: How the pathfinder works with stations.

Post by mauried »

Thanks, sort of explains what Im seeing.
However if the direct route is substantially shorter than the route thru the station, I still get trains going thru the station even though the station isnt in their orders.
The odd thing is there seems to be some randomness involved as some of the trains which go thru the station dont always do it.
Ill have to play around and try and figure out what the penalty is .
User avatar
Pyoro
Tycoon
Tycoon
Posts: 2558
Joined: 17 Oct 2008 12:17
Location: Virgo Supercluster

Re: How the pathfinder works with stations.

Post by Pyoro »

You can see the value in openttd.cfg :
https://wiki.openttd.org/en/Archive/Man ... ttd.cfg#pf

I'm assuming the various station penalties are for that. Doesn't seem to be too big. If you want vehicles to avoid stations at all cost if not in their orders I guess you could increase it.
Transportman
Tycoon
Tycoon
Posts: 2781
Joined: 22 Feb 2011 18:34

Re: How the pathfinder works with stations.

Post by Transportman »

The pathfinder does not only consider distance, but applies penalties for a lot of things, so maybe your short route sometimes gets additional penalties (because there are trains there that make signals red) making the longer route "cheaper" from a pathfinder perspective.

You can modify the penalties, or add waypoints to force certain routes or make the detour less likely by placing two way path signals against the direction (which trigger the yapf.rail_pbs_signal_back_penalty every time, so that adds quite a penalty quite fast).
Coder of the Dutch Trackset | Development support for the Dutch Trainset | Coder of the 2cc TrainsInNML
Taschi
Route Supervisor
Route Supervisor
Posts: 425
Joined: 11 Oct 2014 22:58

Re: How the pathfinder works with stations.

Post by Taschi »

Perhaps if you share a screenshot of the relevant parts of your network, someone will be able to figure out why your train isn't behaving as you expect it to.
mauried
Traffic Manager
Traffic Manager
Posts: 148
Joined: 07 Sep 2010 11:35

Re: How the pathfinder works with stations.

Post by mauried »

This is a simplified picture of the problem .
The trains all travel from left to right, from the entry points to the exits.
The actual track is much longer than in the picture, the sections A-B,C-D,E-F and G-H are 100 square long undersea tunnels with signals in the tunnels, the entries and the exits are on the land.
The station is on an island , so section D-G is on the land and sect and B-E is a tunnel..
Trains can enter from either entry1 or entry2 , and some of them stop at the station, others dont.
There is no problem with trains which have the station in their orders, as they will either go straight if entering on entry2, or will crossover if entering from entry1 and go thru the station.
The problem is with trains which dont have the station in their orders, and some will randomly still go thru the station regardless of which entry point they enter from.
This can cause the track section from C-D to clog up if there are already trains in the station.
The non station track A,B,E,F is very busy, the station track not so much.
Using JGRs patchpack ver 0.39.
Any ideas welcome.
Attachments
Flarninghead Transport, 1950-03-13.png
(790.61 KiB) Not downloaded yet
Eddi
Tycoon
Tycoon
Posts: 8271
Joined: 17 Jan 2007 00:14

Re: How the pathfinder works with stations.

Post by Eddi »

pathfinder penalties are a delicate thing, a lot of things may go wrong if they are used incorrectly. you can view the current settings when opening the console and typing "list_settings pf.yapf.rail" (most likely the default values)

some basic rules on how to interprete these settings:
  • a basic tile has a penalty of 100. other penalties are usually a multiple of that. this basically means "how many tiles detour are you considering to avoid this tile". whichever path has the lowest cumulative penalties is considered the "shortest"
  • there are "static" and "dynamic" penalties.
  • static penalties are the same across the whole map, and only change when you change the map (e.g. build something), and are independent of where the trains are. these are things like stations, curves, level crossings, etc.
  • dynamic penalties change on their own when trains move. these are things like reserved tiles, red signals or occupied platforms. because these cannot be cached, there is a limit how far ahead of the train this is considered. (default is 10 signals). most notably the results of this will be different whether you use block or path signals
User avatar
LaRoso
Traffic Manager
Traffic Manager
Posts: 134
Joined: 15 Sep 2017 22:29
Location: Augsburg, BY, Germany

Re: How the pathfinder works with stations.

Post by LaRoso »

First of all: pathfinding isn't random. Not at all. It's math. There can be many reasons why trains use certain paths.

The following statements are based on my own knowledge and research and can be wrong. (If this is the case, please correct me in a polite manner.)
YAPF doesn't calculate the best path for infinitely long distances. If the way to the destination is too long, the pathfinder estimates the best path just by the part of each path it can calculate. In your case the problem could be, that the station is just too far away, so it doesn't even appear in the calculation for the best path.
mauried wrote: 18 Nov 2021 00:14 The actual track is much longer than in the picture, the sections A-B,C-D,E-F and G-H are 100 square long undersea tunnels with signals in the tunnels, the entries and the exits are on the land.
I tested your simplified version. All the trains use the correct path around the station. (Except I build the station just 1 tile long and put other trains all along the upper track A-F).
Image
Taschi
Route Supervisor
Route Supervisor
Posts: 425
Joined: 11 Oct 2014 22:58

Re: How the pathfinder works with stations.

Post by Taschi »

I believe that the YAPF pathfinder also takes previously used routes into account when trying to find a route. I. e. if in a train's previous cycle of its order list it went through a station rather than around it because the path bypassing the station was blocked at that time, it will prefer to take the same route again on this cycle, unless that route is blocked (which incurs a pathfinder penalty) or significantly longer than the alternatives.

Regardless of my personal speculation / semi-knowledge, if you want a train to bypass a station with 100% certainty, you should explicitly order it to do so through use of waypoints and "via" orders.
mauried
Traffic Manager
Traffic Manager
Posts: 148
Joined: 07 Sep 2010 11:35

Re: How the pathfinder works with stations.

Post by mauried »

Yes,the via is also the only solution that I think will work reliably too, so todays fun job is a lot of order changes.
tnx all.
mauried
Traffic Manager
Traffic Manager
Posts: 148
Joined: 07 Sep 2010 11:35

Re: How the pathfinder works with stations.

Post by mauried »

I found a fix.
It never seems to amaze me what kind of things exist in this game that you never know about.
JGRs patchpack provides for changing the routefinding on a per signal basis.
So implementing the following route finding restriction on the block signal just to the left of the Letter C fixes the problem.

Start
if current order is not Flarninghead Woods
Deny
endif
End

So any trains that dont specifically have the station name Flarninghead Woods in their orders cant get past the block signal near C , so all get routed onto the thru track.
Exactly what I was trying to achieve.
Transportman
Tycoon
Tycoon
Posts: 2781
Joined: 22 Feb 2011 18:34

Re: How the pathfinder works with stations.

Post by Transportman »

mauried wrote: 18 Nov 2021 00:14 This is a simplified picture of the problem .
The trains all travel from left to right, from the entry points to the exits.
The actual track is much longer than in the picture, the sections A-B,C-D,E-F and G-H are 100 square long undersea tunnels with signals in the tunnels, the entries and the exits are on the land.
The station is on an island , so section D-G is on the land and sect and B-E is a tunnel..
Trains can enter from either entry1 or entry2 , and some of them stop at the station, others dont.
There is no problem with trains which have the station in their orders, as they will either go straight if entering on entry2, or will crossover if entering from entry1 and go thru the station.
The problem is with trains which dont have the station in their orders, and some will randomly still go thru the station regardless of which entry point they enter from.
This can cause the track section from C-D to clog up if there are already trains in the station.
The non station track A,B,E,F is very busy, the station track not so much.
Using JGRs patchpack ver 0.39.
Any ideas welcome.
If the station bypass-track A-B-E-F is very busy, the penalty of the trains on that track might be higher than the penalty of passing the station.
Coder of the Dutch Trackset | Development support for the Dutch Trainset | Coder of the 2cc TrainsInNML
User avatar
LaRoso
Traffic Manager
Traffic Manager
Posts: 134
Joined: 15 Sep 2017 22:29
Location: Augsburg, BY, Germany

Re: How the pathfinder works with stations.

Post by LaRoso »

Transportman wrote: 20 Nov 2021 13:46 If the station bypass-track A-B-E-F is very busy, the penalty of the trains on that track might be higher than the penalty of passing the station.
I don't think this could happen that easily when he didn't change any penalties. The basic penalty for passing stations is 1000 per station tile. The penalty of the red signals for the next 10 signals can get up to about 2000. So if the station is longer than 2 tiles, the penalty should be way higher than the red signals ever are able to be.
Image
Michi_cc
OpenTTD Developer
OpenTTD Developer
Posts: 619
Joined: 14 Jun 2004 23:27
Location: Berlin, Germany
Contact:

Re: How the pathfinder works with stations.

Post by Michi_cc »

Taschi wrote: 18 Nov 2021 21:58 I believe that the YAPF pathfinder also takes previously used routes into account when trying to find a route
It doesn't. YAPF is stateless with respect to the vehicles. It does some global caching, but as Eddi said this only for the static penalties which are not influenced by vehicle movement.
LaRoso wrote: 20 Nov 2021 15:18 I don't think this could happen that easily when he didn't change any penalties. The basic penalty for passing stations is 1000 per station tile. The penalty of the red signals for the next 10 signals can get up to about 2000. So if the station is longer than 2 tiles, the penalty should be way higher than the red signals ever are able to be.
Reserved tiles have a penalty by itself, so it is not just the signals but also the amount and length of trains on the section.
User avatar
LaRoso
Traffic Manager
Traffic Manager
Posts: 134
Joined: 15 Sep 2017 22:29
Location: Augsburg, BY, Germany

Re: How the pathfinder works with stations.

Post by LaRoso »

Michi_cc wrote: 21 Nov 2021 10:50 Reserved tiles have a penalty by itself, so it is not just the signals but also the amount and length of trains on the section.
This is new to me, and I didn't find anything like this in the source code. I know that there is a penalty for red signals and the basic cost for each tile. Would you like to show me the place where this is calculated? (I hope it doesn't spam this thread, so maybe also as private message)
Image
Eddi
Tycoon
Tycoon
Posts: 8271
Joined: 17 Jan 2007 00:14

Re: How the pathfinder works with stations.

Post by Eddi »

take a look at these:

Code: Select all

yapf.rail_pbs_cross_penalty = 300
yapf.rail_pbs_station_penalty = 800
these are the costs for a reserved rail tile (includes occupied tiles even without path signals), and a reserved station tile
User avatar
LaRoso
Traffic Manager
Traffic Manager
Posts: 134
Joined: 15 Sep 2017 22:29
Location: Augsburg, BY, Germany

Re: How the pathfinder works with stations.

Post by LaRoso »

Eddi wrote: 21 Nov 2021 13:56 take a look at these:

Code: Select all

yapf.rail_pbs_cross_penalty = 300
yapf.rail_pbs_station_penalty = 800
these are the costs for a reserved rail tile (includes occupied tiles even without path signals), and a reserved station tile
Oh I see, thank you very much
Image
trainrover
Transport Coordinator
Transport Coordinator
Posts: 283
Joined: 29 Nov 2014 23:23

Re: How the pathfinder works with stations.

Post by trainrover »

Waypoints are a godsend...the longer the distances inherent in your work orders, the more discombobulated dear YAPF becomes around your comprehensive network...you must dance with and pamper it at all costs to reap its abundant rewards.

The lone weakness I've found with YAPF is its glitchiness with duplicate orders...I had the same destination both at the beginning and the end of a work order; having forgot to eliminate one of the duplicates when saving and exiting, upon opening the corresponding save, the vehicle had been skipped to the last one of the duplicates from the first one, and thus had been flipped to the top of the work order...queer vulnerability, I suppose.
User avatar
odisseus
Director
Director
Posts: 568
Joined: 01 Nov 2017 21:19

Re: How the pathfinder works with stations.

Post by odisseus »

That's strange. I have experimented quite a bit with complex order lists, and I have never seen a vehicle skip any orders when it shouldn't. Every time I thought I got such a case, it turned out to be my own error.

For example, if the order list looks like A → A → B → C → .., and there is no direct path from A to A, the train will take the long route through B, C and any other stations on the way. When you spot a train between B and C that's headed for A, this might look as if some orders have been skipped.
Post Reply

Return to “General OpenTTD”

Who is online

Users browsing this forum: No registered users and 16 guests