Dynamically choose new path to station if present path is too slow

Forum for technical discussions regarding development. If you have a general suggestion, problem or comment, please use one of the other forums.

Moderator: OpenTTD Developers

Post Reply
Noltibus
Engineer
Engineer
Posts: 9
Joined: 11 Nov 2015 10:02

Dynamically choose new path to station if present path is too slow

Post by Noltibus »

Hi,

is there any way to change the present path of a bus. So imagine the bus drives from A to B and recognizes that there is a traffic jam or something. Is there any way, that it can then take another route?
Until know I see no way but I also don't really know, how the "max speed not greater than" condition in the conditional orders work. So maybe someone can explain those to me?
Thanks in advance!!!
Eddi
Tycoon
Tycoon
Posts: 8272
Joined: 17 Jan 2007 00:14

Re: Dynamically choose new path to station if present path is too slow

Post by Eddi »

no, the pathfinder is not really capable of detecting traffic jams.
User avatar
Expresso
Tycoon
Tycoon
Posts: 1760
Joined: 09 Aug 2004 00:14
Location: Gouda, the Netherlands

Re: Dynamically choose new path to station if present path is too slow

Post by Expresso »

Perhaps it's an idea to maintain a value for each tile (or direction on it) and slowly decrement it as the tile is attended by the tile loop. Each vehicle occupying the tile causes the value to increase by 1 (to an arbitrary maximum). The value then ends up representing how busy the tile is.

The pathfinder could check that value every time it has a choice. This value could be added as an additional penalty for the pathfinder, thus making routes around the "jam" more attractive.

The tile loop can be used to lower the value representing how busy a certain piece of infrastructure is. An additional map view could be used to assist players in figuring out which areas are busiest (and thus need more or smarter infrastructure).
Noltibus
Engineer
Engineer
Posts: 9
Joined: 11 Nov 2015 10:02

Re: Dynamically choose new path to station if present path is too slow

Post by Noltibus »

Ok that helps me a lot! Am I right, that for every vehicle the pathfinder gets called at every tick?
So that at every tick the path can eventually be planned new?
EDIT: And it is not possible to redirect a vehicle using the conditional orders? Maybe by using the "if maximum speed < x" condition?
Noltibus
Engineer
Engineer
Posts: 9
Joined: 11 Nov 2015 10:02

Re: Dynamically choose new path to station if present path is too slow

Post by Noltibus »

Does anybody know when and how many times the pathfinder gets called?
Thanks in advance!
Eddi
Tycoon
Tycoon
Posts: 8272
Joined: 17 Jan 2007 00:14

Re: Dynamically choose new path to station if present path is too slow

Post by Eddi »

every time the vehicle arrives at a crossing.
User avatar
Expresso
Tycoon
Tycoon
Posts: 1760
Joined: 09 Aug 2004 00:14
Location: Gouda, the Netherlands

Re: Dynamically choose new path to station if present path is too slow

Post by Expresso »

The pathfinder gets called when a vehicle gets a choice to make.
Noltibus
Engineer
Engineer
Posts: 9
Joined: 11 Nov 2015 10:02

Re: Dynamically choose new path to station if present path is too slow

Post by Noltibus »

And YAPF chooses the route with the fewest accumulated penalties right?
Does it take the pure distance into account?
Thanks
User avatar
planetmaker
OpenTTD Developer
OpenTTD Developer
Posts: 9432
Joined: 07 Nov 2007 22:44
Location: Sol d

Re: Dynamically choose new path to station if present path is too slow

Post by planetmaker »

Noltibus wrote:And YAPF chooses the route with the fewest accumulated penalties right?
Does it take the pure distance into account?
Thanks
'distance' is an abstract thing with a path finder. The path with the least cost is chosen - that includes distances (as every tile has a certain penalty) as well as other penalties.

Every tile has its own penalty, depending on how the track goes:

Code: Select all

/** Length (penalty) of one tile with YAPF */
static const int YAPF_TILE_LENGTH = 100;

/** Length (penalty) of a corner with YAPF */
static const int YAPF_TILE_CORNER_LENGTH = 71;
Additional penalties, depending on how the tile looks like. From my openttd.cfg (might not be completely default values):

Code: Select all

yapf.rail_firstred_penalty = 1000
yapf.rail_firstred_exit_penalty = 10000
yapf.rail_lastred_penalty = 1000
yapf.rail_lastred_exit_penalty = 10000
yapf.rail_station_penalty = 1000
yapf.rail_slope_penalty = 200
yapf.rail_curve45_penalty = 100
yapf.rail_curve90_penalty = 600
yapf.rail_depot_reverse_penalty = 5000
yapf.rail_crossing_penalty = 300
yapf.rail_look_ahead_max_signals = 10
yapf.rail_look_ahead_signal_p0 = 500
yapf.rail_look_ahead_signal_p1 = -100
yapf.rail_look_ahead_signal_p2 = 5
yapf.rail_pbs_cross_penalty = 300
yapf.rail_pbs_station_penalty = 800
yapf.rail_pbs_signal_back_penalty = 1500
yapf.rail_doubleslip_penalty = 100
yapf.rail_longer_platform_penalty = 800
yapf.rail_longer_platform_per_tile_penalty = 0
yapf.rail_shorter_platform_penalty = 4000
yapf.rail_shorter_platform_per_tile_penalty = 0
yapf.road_slope_penalty = 200
yapf.road_curve_penalty = 100
yapf.road_crossing_penalty = 300
yapf.road_stop_penalty = 800
yapf.road_stop_occupied_penalty = 800
yapf.road_stop_bay_occupied_penalty = 1500
yapf.maximum_go_to_depot_penalty = 2000
Noltibus
Engineer
Engineer
Posts: 9
Joined: 11 Nov 2015 10:02

Re: Dynamically choose new path to station if present path is too slow

Post by Noltibus »

You guys are amazing!!!
Is there a line of code where it is checked if the vehicle reached a crossing and then the pathfinder is called?
Thanks!
Noltibus
Engineer
Engineer
Posts: 9
Joined: 11 Nov 2015 10:02

Re: Dynamically choose new path to station if present path is too slow

Post by Noltibus »

And, as I'm looking through the source code, in which file did you find the variable YAPF_TILE_LENGTH?
Thanks in advance!!!
EDIT: Got it
Noltibus
Engineer
Engineer
Posts: 9
Joined: 11 Nov 2015 10:02

Re: Dynamically choose new path to station if present path is too slow

Post by Noltibus »

Expresso wrote:Perhaps it's an idea to maintain a value for each tile (or direction on it) and slowly decrement it as the tile is attended by the tile loop. Each vehicle occupying the tile causes the value to increase by 1 (to an arbitrary maximum). The value then ends up representing how busy the tile is.
What exactly do you mean with "Tile loop". Can you explain that to me?
I know I ask a lot but I really need you guys.
User avatar
HackaLittleBit
Director
Director
Posts: 550
Joined: 10 Dec 2008 16:08
Location: tile 0x0000

Re: Dynamically choose new path to station if present path is too slow

Post by HackaLittleBit »

You have to read a couple of documents to get a better understandig about the game.
This is the holy grale of the game.
Transport_Tycoon_Deluxe_savegame_internals
in the docs folder study landscape.html and landscape_grid.html and landscape_externals.html
Now about the 'Tile loop'.
You have to look at the game as a 3 dimentional array.
length and width of the map and then deep (8 x 8 bits + 16 bits ,see landscape_grid.html)
Look for RunTileLoop()(genworld.cpp, landscape.cpp, openttd.cpp)
This is the loop that updates the information that is stored in each individual tile in the game.
Eddi
Tycoon
Tycoon
Posts: 8272
Joined: 17 Jan 2007 00:14

Re: Dynamically choose new path to station if present path is too slow

Post by Eddi »

The tile loop goes repeatedly over the map and handles things like grass growth, house construction, snowfall, etc. it only handles a few tiles at a time, but it will come back to the same tile after 256 ticks (about 3.5 game days)

i have done something like that here for trains (just not affecting the pathfinder): http://www.tt-forums.net/viewtopic.php?f=33&t=47095
Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: Ahrefs [Bot] and 54 guests