Rail Path Finder modification

Discuss the new AI features ("NoAI") introduced into OpenTTD 0.7, allowing you to implement custom AIs, and the new Game Scripts available in OpenTTD 1.2 and higher.

Moderator: OpenTTD Developers

Post Reply
User avatar
fanioz
Transport Coordinator
Transport Coordinator
Posts: 320
Joined: 19 Dec 2008 05:03
Location: Indonesia
Contact:

Rail Path Finder modification

Post by fanioz »

Rail pathfinder use existing rail.
main.nut
Main RailPF
(23.97 KiB) Downloaded 122 times
The Diff from version 1.0
railpf.diff
Diff from version 1.0
(22.56 KiB) Downloaded 142 times
================ First Post ====================
Since Aystar.5 has been uploaded on to Bananas, and the next version of Road Path Finder library seem nearly on the way to it goal. Here is Rail Path Finder modification. :oops:

Several days ago, I've asked (PM) yexo to start this thread. He said that right now, he is quite busy and let me to start posting.
So here was the proposed library (you could rename the extension to .nut) :D

Current modification ::
  • - Get the working pathfinder that use AyStar.5 feature (max.length, multiplier,.. etc)
  • - Add additional cost that similiar with RoadPF modification (except: no_existing_rail)
  • - Add custom cost call back too
I just have test it a few number and so far was so good. However it still need improvement. :lol:
Thanks for participating ...
Last edited by fanioz on 27 Jul 2009 09:31, edited 1 time in total.
Correct me If I am wrong - PM me if my English was bad :D

**[OpenTTD AI]** Image
***[NewGRF] *** Image

User avatar
GeekToo
Tycoon
Tycoon
Posts: 961
Joined: 03 Jun 2007 22:22

Re: Rail Path Finder modification

Post by GeekToo »

Well done Fanioz.

One remark, for backward compatibility and easier switching between the old and new rail pathfinder for comparison, could you please keep the order of the parameters of the InitializePath function like in the previous version:

So the ignored parameter before the new parameters.

That would prevent changing the caller's code when switching

User avatar
fanioz
Transport Coordinator
Transport Coordinator
Posts: 320
Joined: 19 Dec 2008 05:03
Location: Indonesia
Contact:

Re: Rail Path Finder modification

Post by fanioz »

Ah. I see ....

Code: Select all

/**
     * Initialize a path search between sources and goals.
     * @param sources The source tiles.
     * @param goals The target tiles.
     * @ignored_tiles The ignored tiles while pathfinding.
     * @param max_length_multiplier The multiplier for the maximum route length.
     * @param max_length_offset The minimum value of the maximum length.
     * @see AyStar::InitializePath()
     */
    function InitializePath(sources, goals, ignored_tiles = [], max_length_multiplier = 0, max_length_offset = 10000);
But, the caller format is based on Road Path finder modification. So, we may suggest this change too on them. :?:
One thing I've never check, is squirrel can be used this way ? (blank parameter)

Code: Select all

myclass.InitializePath(from, to, , ,ignored_tiles)


edit:: I really have to learn how to make good diff file :oops:
Correct me If I am wrong - PM me if my English was bad :D

**[OpenTTD AI]** Image
***[NewGRF] *** Image

Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: Rail Path Finder modification

Post by Yexo »

Nice work fanioz, I'll take a closer look as soon as I find the time for it.
fanioz wrote:But, the caller format is based on Road Path finder modification. So, we may suggest this change too on them. :?:
Suggest what you want, but I don't like to change the libraries too often (because a library upgrade requires an AI updated). The road pathfinder will not be changed unless bugs are found or major new features requested.
One thing I've never check, is squirrel can be used this way ? (blank parameter)

Code: Select all

myclass.InitializePath(from, to, , ,ignored_tiles)
I don't think so, but maybe it's possible.

User avatar
fanioz
Transport Coordinator
Transport Coordinator
Posts: 320
Joined: 19 Dec 2008 05:03
Location: Indonesia
Contact:

Re: Rail Path Finder modification

Post by fanioz »

Yexo wrote:
fanioz wrote:But, the caller format is based on Road Path finder modification. So, we may suggest this change too on them.
Suggest what you want, but I don't like to change the libraries too often (because a library upgrade requires an AI updated). The road pathfinder will not be changed unless bugs are found or major new features requested.
Emm... I mean suggest a modification in this thread, to keep InitializePath function like in the previous version of it, as GeekToo said above.
Okay, here is diff file compared to Rail PF ver 1.0 ( I hope I've made it correctly) :lol:

Change Log :
- keep InitializePath function like in the previous version
- Change the default parameter of Cost Call back to

Code: Select all

local args = [this, path, new_tile]
Attachments
Rail.pf.diff
(23.21 KiB) Downloaded 111 times
Correct me If I am wrong - PM me if my English was bad :D

**[OpenTTD AI]** Image
***[NewGRF] *** Image

User avatar
fanioz
Transport Coordinator
Transport Coordinator
Posts: 320
Joined: 19 Dec 2008 05:03
Location: Indonesia
Contact:

Re: Rail Path Finder modification

Post by fanioz »

Because of avoid to use 'call', here is the Rail pathfinder revision. :lol: Still, this rail pathfinder tries to find a buildable and non existing route for rail vehicles.
* This is modified version to :
* - Use Aystar 6
* - Has similiar feature with Road.Path.Finder 4 (additional cost and cost callback function)
* - No longer use 'call' (actually the official version 1.0 never use it) :D
Tested so far with unreleased-TransAI.

=======
(test case to upload .nut file too, thanks to yexo for make suggestion of allowing .nut files)
Attachments
main.nut
Revised: RailPF with Aystar.6
(20 KiB) Downloaded 143 times
railpf.diff
Revised : Diff file
(16.25 KiB) Downloaded 108 times
Last edited by fanioz on 15 Jun 2009 14:31, edited 1 time in total.
Correct me If I am wrong - PM me if my English was bad :D

**[OpenTTD AI]** Image
***[NewGRF] *** Image

Yexo
Tycoon
Tycoon
Posts: 3663
Joined: 20 Dec 2007 12:49

Re: Rail Path Finder modification

Post by Yexo »

Did you really test this exact version? In that case I'd retry without this addition:

Code: Select all

-function Rail::_Cost(path, new_tile, new_direction, self)
+function Rail::_Cost(self, path, new_tile, new_direction)
 {
 	/* path == null means this is the first node of a path, so the cost is 0. */
 	if (path == null) return 0;
+	return path.GetCost() + self._cost_tile;

User avatar
fanioz
Transport Coordinator
Transport Coordinator
Posts: 320
Joined: 19 Dec 2008 05:03
Location: Indonesia
Contact:

Re: Rail Path Finder modification

Post by fanioz »

Yexo wrote:Did you really test this exact version? In that case I'd retry without this addition:

Code: Select all

-function Rail::_Cost(path, new_tile, new_direction, self)
+function Rail::_Cost(self, path, new_tile, new_direction)
 {
 	/* path == null means this is the first node of a path, so the cost is 0. */
 	if (path == null) return 0;
+	return path.GetCost() + self._cost_tile;
My bad :oops: forget to remove that before uploading. That is because I want to test-use only Estimate().

Okay, it's now revised in above post
Correct me If I am wrong - PM me if my English was bad :D

**[OpenTTD AI]** Image
***[NewGRF] *** Image

User avatar
Zutty
Director
Director
Posts: 565
Joined: 22 Jan 2008 16:33

Re: Rail Path Finder modification

Post by Zutty »

Nice job fanioz :)

However, I've had a quick play with your modified pathfinder and for some reason its much slower than the library pathfinder v1. I can't quite figure out why that is. ?(
PathZilla - A networking AI - Now with tram support.

User avatar
fanioz
Transport Coordinator
Transport Coordinator
Posts: 320
Joined: 19 Dec 2008 05:03
Location: Indonesia
Contact:

Re: Rail Path Finder modification

Post by fanioz »

Zutty wrote:Nice job fanioz :)

However, I've had a quick play with your modified pathfinder and for some reason its much slower than the library pathfinder v1. I can't quite figure out why that is. ?(
Thanks to remind me. :D
I still try to optimize it. However, feel free if you have any suggestion. :)
Correct me If I am wrong - PM me if my English was bad :D

**[OpenTTD AI]** Image
***[NewGRF] *** Image

User avatar
fanioz
Transport Coordinator
Transport Coordinator
Posts: 320
Joined: 19 Dec 2008 05:03
Location: Indonesia
Contact:

Re: Rail Path Finder modification

Post by fanioz »

Pufff.... I think it is done now. :D :mrgreen: :lol: :o :)
Uploaded to the first post. However there are (maybe) something arguable (mm... discuss able??) things,, so please comment here. :bow:
Correct me If I am wrong - PM me if my English was bad :D

**[OpenTTD AI]** Image
***[NewGRF] *** Image

Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: No registered users and 4 guests