Pathfinder penalty for road vehicles (r17469)

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

Roujin
Tycoon
Tycoon
Posts: 1884
Joined: 08 Apr 2007 04:07

Pathfinder penalty for road vehicles (r17469)

Post by Roujin »

This is not exactly a new patch, but one I made some time ago that never got much attention. I didn't make an own thread for it back then, so I'm catching up with that now.

Newest version: r17469

The newest version works with both NPF and YAPF as pathfinder for road vehicles.
If you want to customize the settings (e.g. via console), they are named as follows:
for NPF: pf.npf.npf_road_vehicle_penalty
for YAPF: pf.yapf.road_vehicle_penalty

---
Older versions:
r17455
---
Description:
What does it do?
In technical terms, it adds a new pathfinder penalty to YAPF (note: current version also NPF) that applies to all tiles that have a roadvehicle on them which goes in the same direction as the planned path of the currently pathfinding vehicle.
In simple terms, it makes vehicles avoid routes where there already are vehicles. This means that if there are multiple routes with roughly the same distance available, the vehicle will choose the one with less traffic.

Here's an example:
It's a simple sort-of-highway (only that the lanes are not LLRR but LRLR), and as you can see some vehicles are using the left, some the right lane, despite having the same destination.
yapf_vehicle_penalty.png
yapf_vehicle_penalty.png (89.07 KiB) Viewed 5339 times
I hope some of you will enjoy this patch. I'd say it's 50-50 eyecandy and useful. Eyecandy because it (hopefully) makes traffic look more natural; useful because it might help avoid some congestions if a fleet of buses with the same orders won't always take one specific, predetermined path, but diversify a bit...
Last edited by Roujin on 08 Sep 2009 10:49, edited 4 times in total.
* @Belugas wonders what is worst... a mom or a wife...
<Lakie> Well, they do the same thing but the code is different.

______________
My patches
check my wiki page (sticky button) for a complete list

ImageImage
ImageImageImageImageImageImageImage
petert
Tycoon
Tycoon
Posts: 3008
Joined: 02 Apr 2009 22:43
Location: Massachusetts, USA

Re: Pathfinder penalty for road vehicles (r17438)

Post by petert »

So its something like this (I'm not sure):

This train picks the path with less traffic instead of waiting until the first path is open, may have been glitched because trains have no orders
Attachments
Peter Transport, 7th Jun 2065.png
Peter Transport, 7th Jun 2065.png (15.7 KiB) Viewed 5334 times
Roujin
Tycoon
Tycoon
Posts: 1884
Joined: 08 Apr 2007 04:07

Re: Pathfinder penalty for road vehicles (r17438)

Post by Roujin »

Uhm, I wrote "road vehicles" in several places, most noticeable in the title of this thread. How come you're expecting this patch to do anything on trains? :?
* @Belugas wonders what is worst... a mom or a wife...
<Lakie> Well, they do the same thing but the code is different.

______________
My patches
check my wiki page (sticky button) for a complete list

ImageImage
ImageImageImageImageImageImageImage
petert
Tycoon
Tycoon
Posts: 3008
Joined: 02 Apr 2009 22:43
Location: Massachusetts, USA

Re: Pathfinder penalty for road vehicles (r17438)

Post by petert »

I was simply suggesting that trains already preform the same feature, and comparing this patch to the behavior of trains.

Not the reaction I was aiming for.
User avatar
Zephyris
Tycoon
Tycoon
Posts: 2897
Joined: 16 May 2007 16:59

Re: Pathfinder penalty for road vehicles (r17438)

Post by Zephyris »

Mmm, like it, does it produce noticeable differences in towns? Is there any significant performance hit? And does it take into account trams?
Terkhen
OpenTTD Developer
OpenTTD Developer
Posts: 1034
Joined: 11 Sep 2008 07:32
Location: Spain

Re: Pathfinder penalty for road vehicles (r17438)

Post by Terkhen »

This seems very useful. A road vehicle that is loading/unloading in a drive through station in the same direction than the current vehicle gives penalties too?. I think that could help with the problem reported at FS#1944.

Edit: Another question... why do you increment SAVEGAME_VERSION to 200 instead of by 1?. And in the SDT_CONDVAR you use 100 instead of 200.
Last edited by Terkhen on 07 Sep 2009 10:07, edited 1 time in total.
User avatar
pavel1269
Route Supervisor
Route Supervisor
Posts: 473
Joined: 03 Dec 2006 13:22
Location: Czech Republic
Contact:

Re: Pathfinder penalty for road vehicles (r17438)

Post by pavel1269 »

Terkhen wrote:This seems very useful. A road vehicle that is loading/unloading in a drive through station in the same direction than the current vehicle gives penalties too?. I think that could help with the problem reported at FS#1944.
It should, as there is another a route, with less traffic :-)

Looks very promising ;-)
Roujin
Tycoon
Tycoon
Posts: 1884
Joined: 08 Apr 2007 04:07

Re: Pathfinder penalty for road vehicles (r17438)

Post by Roujin »

Zephyris wrote:Mmm, like it, does it produce noticeable differences in towns?
Probably depends on the value you set it to. Choose a high value and your vehicle will take any detour if it sees another vehicle in front of it (shy vehicle :lol: )
Is there any significant performance hit?
Good question. I haven't done any big-scale tests with the patch. In theory, it shouldn't be too bad - iirc YAPF doesn't run continuously, but only when needed (e.g. on a crossing where the vehicle could take different routes). Then, I'm using the existing check VehicleFromPos on each tile the pf walks - it kind of depends on how well this function works. It's not working naively, but using some sort of hash, so I assume it's more or less efficient.
If anyone makes a big-scale game with this and notices performance hits (outside the usual), please inform me :)
And does it take into account trams?
Not tested, but it should.
edit: tested, works like a charm ;) see attached savegame
yapf_vehicle tram test.sav
(40.53 KiB) Downloaded 129 times
Terkhen wrote:This seems very useful. A road vehicle that is loading/unloading in a drive through station in the same direction than the current vehicle gives penalties too?. I think that could help with the problem reported at FS#1944.
The cost is calculated for road stops too, so it should work. However, I do not know the details of the mentioned problem - maybe my patch helps, maybe not. But please see for yourself, if it does help "accidentally", that's fine :lol:
Edit: Another question... why do you increment SAVEGAME_VERSION to 200 instead of by 1?. And in the SDT_CONDVAR you use 100 instead of 200.
The first one - well, why not. Saves me from changing it every time trunk bumps. Of course if it were to be included to trunk, I'd change it to +1 instead.
The second one is a bug, thanks for noticing. Will fix soon.
PS: I made this last mistake (not updating saveload properly) on all three patches of mine I updated yesterday night. Gah :(
Last edited by Roujin on 07 Sep 2009 14:28, edited 2 times in total.
* @Belugas wonders what is worst... a mom or a wife...
<Lakie> Well, they do the same thing but the code is different.

______________
My patches
check my wiki page (sticky button) for a complete list

ImageImage
ImageImageImageImageImageImageImage
Roujin
Tycoon
Tycoon
Posts: 1884
Joined: 08 Apr 2007 04:07

Re: Pathfinder penalty for road vehicles (r17438)

Post by Roujin »

Here is a new version for r17455.
yapf_vehicle_penalty_r17455.diff
vehicle penalty for r17455
(5.3 KiB) Downloaded 143 times
Fix: Loading trunk games. (thanks Terkhen)
* @Belugas wonders what is worst... a mom or a wife...
<Lakie> Well, they do the same thing but the code is different.

______________
My patches
check my wiki page (sticky button) for a complete list

ImageImage
ImageImageImageImageImageImageImage
Terkhen
OpenTTD Developer
OpenTTD Developer
Posts: 1034
Joined: 11 Sep 2008 07:32
Location: Spain

Re: Pathfinder penalty for road vehicles (r17438)

Post by Terkhen »

Roujin wrote:
Terkhen wrote:This seems very useful. A road vehicle that is loading/unloading in a drive through station in the same direction than the current vehicle gives penalties too?. I think that could help with the problem reported at FS#1944.
The cost is calculated for road stops too, so it should work. However, I do not know the details of the mentioned problem - if vehicles ignore penalties on going to road stops and just take the closest part they can find, my patch won't be of any help. But please see for yourself, if it does help "accidentally", that's fine :lol:
The drive-through stop problem is *almost* completely solved with this patch. The real problem remains, but since road vehicles tend to choose empty stops they seem to work way better. I will do more serious tests later, but I don't remember being able to put 200 coal trucks between two maximum sized road stops in a 128x128 scenario :D
User avatar
Gedemon
Traffic Manager
Traffic Manager
Posts: 150
Joined: 29 Apr 2004 21:53

Re: Pathfinder penalty for road vehicles (r17455)

Post by Gedemon »

I was thinking of something like that yesterday while looking at my buses bloked by a full loading AI, this one will be very usefull :D
2007Alain2007
Chief Executive
Chief Executive
Posts: 658
Joined: 11 Nov 2007 12:06
Contact:

Re: Pathfinder penalty for road vehicles (r17455)

Post by 2007Alain2007 »

Dose it work with all path finders or just YAPF?
For Community Integrated Version http://code.google.com/p/civopenttd/
Roujin
Tycoon
Tycoon
Posts: 1884
Joined: 08 Apr 2007 04:07

Re: Pathfinder penalty for road vehicles (r17455)

Post by Roujin »

Currently only YAPF is supported.

Which pathfinder are you using? A different one?
Is there a good reason not to use YAPF (for road vehicles)?
* @Belugas wonders what is worst... a mom or a wife...
<Lakie> Well, they do the same thing but the code is different.

______________
My patches
check my wiki page (sticky button) for a complete list

ImageImage
ImageImageImageImageImageImageImage
petert
Tycoon
Tycoon
Posts: 3008
Joined: 02 Apr 2009 22:43
Location: Massachusetts, USA

Re: Pathfinder penalty for road vehicles (r17455)

Post by petert »

Some cool screenshots from how this great patch works:
Attachments
Prundwood Transport, 13th Mar 2025#1.png
Prundwood Transport, 13th Mar 2025#1.png (2.77 KiB) Viewed 4978 times
Prundwood Transport, 13th Mar 2025.png
Prundwood Transport, 13th Mar 2025.png (32.61 KiB) Viewed 4978 times
Roujin
Tycoon
Tycoon
Posts: 1884
Joined: 08 Apr 2007 04:07

Re: Pathfinder penalty for road vehicles (r17455)

Post by Roujin »

Anyway, here's a new version (for r17469) that also works with NPF. Beware that npf got its own setting, not shared with the one from YAPF.

Note: This version works with both NPF and YAPF, despite the name
yapf_vehicle_penalty_r17469.diff
vehicle penalty for r17469
(7.31 KiB) Downloaded 152 times
Last edited by Roujin on 08 Sep 2009 10:43, edited 1 time in total.
* @Belugas wonders what is worst... a mom or a wife...
<Lakie> Well, they do the same thing but the code is different.

______________
My patches
check my wiki page (sticky button) for a complete list

ImageImage
ImageImageImageImageImageImageImage
2007Alain2007
Chief Executive
Chief Executive
Posts: 658
Joined: 11 Nov 2007 12:06
Contact:

Re: Pathfinder penalty for road vehicles (r17469)

Post by 2007Alain2007 »

I just askinged about it becuse a patch has to keep all settings in the game working

I did not know if it would break/ not work at all

Thank you very much
For Community Integrated Version http://code.google.com/p/civopenttd/
Roujin
Tycoon
Tycoon
Posts: 1884
Joined: 08 Apr 2007 04:07

Re: Pathfinder penalty for road vehicles (r17469)

Post by Roujin »

I see. Well I think regarding pathfinders this is not necessarily a must - there are already things in trunk that only work with YAPF, not NPF (nor original PF). But in any case now my patch works with both YAPF and NPF (sh... I just noticed I named the patch "yapf_...", that's a misnomer).

I think YAPF and NPF should suffice. Original PF is strongly discouraged to use anyway. And I don't know at all how it works and if it's even possible to apply any penalties or such.
* @Belugas wonders what is worst... a mom or a wife...
<Lakie> Well, they do the same thing but the code is different.

______________
My patches
check my wiki page (sticky button) for a complete list

ImageImage
ImageImageImageImageImageImageImage
2007Alain2007
Chief Executive
Chief Executive
Posts: 658
Joined: 11 Nov 2007 12:06
Contact:

Re: Pathfinder penalty for road vehicles (r17469)

Post by 2007Alain2007 »

Thank now all we need for roads is to make 1way roads use both sides but that would be a patch in its own
For Community Integrated Version http://code.google.com/p/civopenttd/
petert
Tycoon
Tycoon
Posts: 3008
Joined: 02 Apr 2009 22:43
Location: Massachusetts, USA

Re: Pathfinder penalty for road vehicles (r17469)

Post by petert »

2007Alain2007 wrote:Thank now all we need for roads is to make 1way roads use both sides but that would be a patch in its own
Such a patch exists.
Terkhen
OpenTTD Developer
OpenTTD Developer
Posts: 1034
Joined: 11 Sep 2008 07:32
Location: Spain

Re: Pathfinder penalty for road vehicles (r17469)

Post by Terkhen »

He means that in a one way road, vehicles only use one side of the road, leaving the other only to overtake vehicles. This patch allows vehicles to choose between different roads, but they still only use one side of the road.
Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: No registered users and 27 guests