Questions about the library road pathfinder (v3)
Moderator: OpenTTD Developers
Questions about the library road pathfinder (v3)
Hi all,
Recently I've been trying to make an AI on my own. My (far-to-achieve) ambition is to make some sort of remake of the old AI, I think that should be quite easy compared to building a really intelligent AI.
I'm a real amateur in programming, I use the library pathfinder according to the guidelines at http://wiki.openttd.org/AI:RoadPathfinder. In fact, I just copied the code.
So, my questions:
1) Is there some way to add a penalty for road-rail level crossings without modifying the code of the pathfinder?
2) I noticed that my pathfinder is slow compared to other AIs that use the library pathfinder (for example, Convoy and TransAI). So, is there some way to make the pathfinder faster? (again, without modifying the library code) I don't mind if the pathfinder doesn't find the optimal route.
3) How do you know that the pathinder failed to find a path? Is it OK to add a time limit?
I hope I will be able develop the AI for some alpha-release. Currently it chooses a service completely randomly, builds the two truck stations and then connects them todether. The next step for me is to build and start the vehicles. Of course my biggest problem will be exception handling, currently there is almost none.
Recently I've been trying to make an AI on my own. My (far-to-achieve) ambition is to make some sort of remake of the old AI, I think that should be quite easy compared to building a really intelligent AI.
I'm a real amateur in programming, I use the library pathfinder according to the guidelines at http://wiki.openttd.org/AI:RoadPathfinder. In fact, I just copied the code.
So, my questions:
1) Is there some way to add a penalty for road-rail level crossings without modifying the code of the pathfinder?
2) I noticed that my pathfinder is slow compared to other AIs that use the library pathfinder (for example, Convoy and TransAI). So, is there some way to make the pathfinder faster? (again, without modifying the library code) I don't mind if the pathfinder doesn't find the optimal route.
3) How do you know that the pathinder failed to find a path? Is it OK to add a time limit?
I hope I will be able develop the AI for some alpha-release. Currently it chooses a service completely randomly, builds the two truck stations and then connects them todether. The next step for me is to build and start the vehicles. Of course my biggest problem will be exception handling, currently there is almost none.
Re: Questions about the library road pathfinder (v3)
Not yet, but a future version of the road pathfinder library will have such a penalty.Brumi wrote:Hi all,
Recently I've been trying to make an AI on my own. My (far-to-achieve) ambition is to make some sort of remake of the old AI, I think that should be quite easy compared to building a really intelligent AI.
I'm a real amateur in programming, I use the library pathfinder according to the guidelines at http://wiki.openttd.org/AI:RoadPathfinder. In fact, I just copied the code.
So, my questions:
1) Is there some way to add a penalty for road-rail level crossings without modifying the code of the pathfinder?
The pathfinder returns false if there is more to search and null if there is no path.3) How do you know that the pathinder failed to find a path? Is it OK to add a time limit?
Good luck with your AII hope I will be able develop the AI for some alpha-release. Currently it chooses a service completely randomly, builds the two truck stations and then connects them todether. The next step for me is to build and start the vehicles. Of course my biggest problem will be exception handling, currently there is almost none.
Re: Questions about the library road pathfinder (v3)
Hi Brumi and good to see another AI developer.
Nothing I'm aware of. One thing you could do is ammend your road/rail builder so that when it encounters and existing road or rail it builds a bridge until it's past the offending item. It's not slick, nor very easy, but it's an option.Brumi wrote:1) Is there some way to add a penalty for road-rail level crossings without modifying the code of the pathfinder?
If your and other peoples AI are all using the same library your results will be the same. The only way to speed it up is to run shorter distances with it. The other thought is the while loop you enter into whilst path finding. If it's got any extra tasks that would affect the speed of things.Brumi wrote:2) I noticed that my pathfinder is slow compared to other AIs that use the library pathfinder (for example, Convoy and TransAI). So, is there some way to make the pathfinder faster? (again, without modifying the library code) I don't mind if the pathfinder doesn't find the optimal route.
Brumi wrote:3) How do you know that the pathinder failed to find a path? Is it OK to add a time limit?
It's perfectly fine to add a timer. I do the following:Wiki wrote:FindPath returns false if it isn't finished with pathfinding. When it's done, it returns either the path it found or null to indicate no route exists.
Code: Select all
local counter = 0;
local path = false;
//MAXIMUM_PATH_TRIES is a constant declared in main.nut
while (path == false && counter < MAXIMUM_PATH_TRIES) {
path = pathfinder.FindPath(100);
counter++;
AIController.Sleep(1);
}
if(path == false){
//Did not find path in time
}
if(path == null){
//Could not find a path
}
Last edited by Xander on 10 Aug 2009 12:19, edited 1 time in total.
Re: Questions about the library road pathfinder (v3)
I hope that's not a copy/paste of your code, since you never update counter.Xander wrote:It's perfectly fine to add a timer. I do the following:
Re: Questions about the library road pathfinder (v3)
fixedYexo wrote:I hope that's not a copy/paste of your code, since you never update counter.Xander wrote:It's perfectly fine to add a timer. I do the following:
Re: Questions about the library road pathfinder (v3)
Thank you both.
Currently I can't promise anything, but I will try my best I'll be studying IT from September and I hope that won't take away all my time, instead it should help a lot (I hope we will learn about A*, I'm really interested in that, but the page on Wikipedia is still very high-level for me).
Currently I can't promise anything, but I will try my best I'll be studying IT from September and I hope that won't take away all my time, instead it should help a lot (I hope we will learn about A*, I'm really interested in that, but the page on Wikipedia is still very high-level for me).
Re: Questions about the library road pathfinder (v3)
ICT or Computer Science? What level (university or high school)?Brumi wrote:Thank you both.
Currently I can't promise anything, but I will try my best I'll be studying IT from September and I hope that won't take away all my time, instead it should help a lot (I hope we will learn about A*, I'm really interested in that, but the page on Wikipedia is still very high-level for me).
Re: Questions about the library road pathfinder (v3)
er... I don't know how it translates properly into English, something like 'Information Specialist Engineer', but I'm not sure about the branches. I'll be studying it at university.Xander wrote:ICT or Computer Science? What level (university or high school)?
Re: Questions about the library road pathfinder (v3)
Ah that's alright then. Over here we have Computer Science - which is programming and such and Information Communication Technology which is stupid.
You'll probably not cover anything as specialised as A* in your first semester but what you will learn are important theories and practices to use when programming
You'll probably not cover anything as specialised as A* in your first semester but what you will learn are important theories and practices to use when programming
Re: Questions about the library road pathfinder (v3)
Brumi wrote:1) Is there some way to add a penalty for road-rail level crossings without modifying the code of the pathfinder?
Code: Select all
import("pathfinder.road", "RoadPathFinder", 3);
class MyRoadPF extends RoadPathFinder {}
function MyRoadPF ::_Cost(path, new_tile, new_direction, self)
{
local cost = ::RoadPathFinder._Cost(path, new_tile, new_direction, self);
if (AITile.HasTransportType(new_tile, AITile.TRANSPORT_RAIL)) cost += your_cost;
return cost;
}
Code: Select all
local pathfinder = RoadPathFinder();
Code: Select all
local pathfinder = MyRoadPF();
Re: Questions about the library road pathfinder (v3)
hurray for inheritance
Re: Questions about the library road pathfinder (v3)
Thank you! I've never thought that it is that easy. I'll try it when I have time.
Re: Questions about the library road pathfinder (v3)
I have a new issue with the road pathfinder:
Any of you has an idea what causes this?
EDIT: If I raise two little hills by the side of the railway, the pathfinder can find a path.
I made a 64x64 scenario with a town, a coal mine and a power station. Then I placed that rail line between the industries. AIs using the library pathfinder (e. g. SimpleAI, TransAI, MogulAI) fail to build a road here, with or without Fanioz's little modification to add a penalty for level crossings. It also failed if I didn't modify the default costs.Any of you has an idea what causes this?
EDIT: If I raise two little hills by the side of the railway, the pathfinder can find a path.
Re: Questions about the library road pathfinder (v3)
It seems, that is because AITile.IsBuildable return false on each rail tile.
AFAIK, road pf3 has been optimized to build bridge on non flat tiles only. Thats why you got a bridge when you made 'hill'.
And with inheritance too, I beleive you can fix this for your AI firstly
Edit:
You need to change the behaviour of Road.Neighbours() and Road.GetTunnelsBridges()
AFAIK, road pf3 has been optimized to build bridge on non flat tiles only. Thats why you got a bridge when you made 'hill'.
And with inheritance too, I beleive you can fix this for your AI firstly
Edit:
You need to change the behaviour of Road.Neighbours() and Road.GetTunnelsBridges()
Re: Questions about the library road pathfinder (v3)
Thank you.
The only thing I can say that I agree with Roujin:
The only thing I can say that I agree with Roujin:
Roujin wrote:hurray for inheritance
Re: Questions about the library road pathfinder (v3)
I changed the pathfinder library to add an extra cost for building over farm tiles and made a new tar file for it.
But reading this thread I notice I should have used inheritance instead. Thanks for the tip!
But reading this thread I notice I should have used inheritance instead. Thanks for the tip!
--------------------------------------------------
MailAI, a casual postal service for openTTD.
--------------------------------------------------
MailAI, a casual postal service for openTTD.
--------------------------------------------------
Who is online
Users browsing this forum: No registered users and 7 guests