Some AI problems with builder of rail networks

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
ilt
Engineer
Engineer
Posts: 18
Joined: 03 Oct 2008 17:49

Some AI problems with builder of rail networks

Post by ilt »

I have a few questions about the construction of the railway network.

An example from the last game. My AI built the railroad copper mine - the factory, which is served by 4 trains. (length ~ 200 tiles)

Copper mine
coppermine.jpg
coppermine.jpg (39.55 KiB) Viewed 2793 times
Factory
factory.jpg
factory.jpg (77.56 KiB) Viewed 469 times
Station for the transport of rubber is attached to this rail. The line of rubber plantation - factory also served four trains. (length ~ 150 tiles)
rubberplantations.jpg
rubberplantations.jpg (89.16 KiB) Viewed 469 times
1) I chose the way of loading cargo on a train at the same time. All the AI I've seen build the station with two ways. And often you can see the loading of cargo on two trains at same time. Which way is better?

2) Trains running in the direction of the copper mine sometimes call in service at the depot near the rubber plantation. Why?
The service interval is set at 250 days. Train forcibly enters the depot immediately after unloading.
I can program the construction of the reverse loop. But this solution does not seem to me successful.
Are there any ideas how to avoid?

3) AI next step is joining another industry to the factory. How I can estimate the limiting density of traffic on this route, that average speed fell slightly relative to the max speed of engine.

4) Is there in part of any other AIs block of optimizer rail network? In some place intersect 3 independent railways built at different times. In some instances need to rebuild the initial rail tracks, when building a third rail routes, for the optimal crossing.
Arie-
Director
Director
Posts: 593
Joined: 20 Jan 2009 16:07

Re: Some AI problems with builder of rail networks

Post by Arie- »

@1
If you have two trains in one station, and they load sequentially, not simultaneously, then your station rating will be a bit higher as there will always be a train waiting: when one is leaving, the next one starts loading and the third train can entre the station.

@2
Maybe you have a savegame so I can check this. But if you'd enter explicit "go to depot" orders, trains should skip other depots than those in the order list.

@3
This I do not know: I have almost no knowledge of the NoAI api and I 2+ track routes with load balancing is hard enough in single player games for a user.

@4
You could take a look at ChooChoo, this AI tries to build a network.
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: Some AI problems with builder of rail networks

Post by Zuu »

3a) Calculating density

Lets start with a single connection. (the simpliest case)

You have X trains over a distance of Y.
K = X/Y gives the density of trains (number of trains per length unit) over the section. If you have different train lengths on different connections, you better calculate K as X/Y * [train length] to get a neutral figure.

You could say that when the density goes over a limit Kmax, then no more trains is allowed on the section. If you then also allow multiple connections to reuse the same track, then you will get sections between each junction for which you have to calculate the density.

I suggest that you see the junctions as nodes, and do not try to figure out the density of the individual track parts of a junction. Later you could try to do that if you want, but leave it out now, as that would add even more complexity.


3b. Denisity limit

I think your best bet is to experiment and find a Kmax value that works good for you. If you know the relation between speed, flow and density , then you could analytically solve which Kmax value that maximize the flow. However, as far as I know, nobody has done any attempts to build any functions to describe the traffic dynamics in OpenTTD. You should also notice that as you get higher and higher density, the system will have a higher chance of flow break downs. So even if you could analytically maximize the flow, you would still not want to use the found Kmax value as that would give a rather unstable system.


Edit: And in the case of railways, you will have to take the signal distance into account as well. If it is constant over all your rail tracks, then you can probably ignore it as a parameter for Kmax. Though it will affect the experimentally found Kmax value.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
ilt
Engineer
Engineer
Posts: 18
Joined: 03 Oct 2008 17:49

Re: Some AI problems with builder of rail networks

Post by ilt »

Arie- wrote:@1
If you have two trains in one station, and they load sequentially, not simultaneously, then your station rating will be a bit higher as there will always be a train waiting: when one is leaving, the next one starts loading and the third train can entre the station.
How can I make that two trains at one station will be loaded sequentially? Usually they are loaded simultaneously.
Arie- wrote: @2
Maybe you have a savegame so I can check this.
I havent savegame. :( Moreover, I havent seen trains that called at this depot. :) I seen only rating of station near cooper mine in debug window. Some years it was below 30%.
Arie- wrote: But if you'd enter explicit "go to depot" orders, trains should skip other depots than those in the order list.
What interval of service need to set in this case?
Arie- wrote:@4
You could take a look at ChooChoo, this AI tries to build a network.
Thx.
ilt
Engineer
Engineer
Posts: 18
Joined: 03 Oct 2008 17:49

Re: Some AI problems with builder of rail networks

Post by ilt »

Zuu wrote:...
Excellent introduction for the beginning! :shock: The first step will be very difficult for me. :)

Kmax value... I need array of all common blocks of network of rail routes. I need list of trains passing through these blocks.

Is it enough functions in the API to build a virtual map of transport routes of the current railway network? Or I need an array that is filled immediately after the construction of the rail routes?
User avatar
Michiel
Transport Coordinator
Transport Coordinator
Posts: 339
Joined: 13 Jul 2008 00:57
Contact:

Re: Some AI problems with builder of rail networks

Post by Michiel »

ilt wrote:Is it enough functions in the API to build a virtual map of transport routes of the current railway network? Or I need an array that is filled immediately after the construction of the rail routes?
It should be possible using just the API and "walking" the tracks found on the map, but it's usually easier to do this as you're building the routes, when you still have higher level "A connects to B through junction C" information available.

By the way, ChooChoo does build networks, but only because it works by building and expanding its four way junctions. It doesn't reuse tracks, nor does it optimize already existing tracks.
User avatar
Zuu
OpenTTD Developer
OpenTTD Developer
Posts: 4553
Joined: 09 Jun 2003 18:21
Location: /home/sweden

Re: Some AI problems with builder of rail networks

Post by Zuu »

ilt wrote:Is it enough functions in the API to build a virtual map of transport routes of the current railway network? Or I need an array that is filled immediately after the construction of the rail routes?
While as Michel said, you have easier access to higher level information while you are building, you will have use for a map-walker. A map-walker can recover crashed AIs and could also be used in your load-code and thus remove the need of storing any extra information in the map. This has the bonus benefit that both the crash-recover code and the load-code is the same code and is thus regularly tested. If you later find that the map-walking code is too slow, and you can't find any way to speed it up for common cases, then you could look into saving extra information in the save games that could speed up the loading.

Having a strict standardized way of building junctions could simplify the map-walking process. You should put some though into building your rail with readability in mind.
My OpenTTD contributions (AIs, Game Scripts, patches, OpenTTD Auto Updater, and some sprites)
Junctioneer (a traffic intersection simulator)
ilt
Engineer
Engineer
Posts: 18
Joined: 03 Oct 2008 17:49

Re: Some AI problems with builder of rail networks

Post by ilt »

I used to planning and building a rail route RailPathFinder library. During last week i found that it works too slow if the distance becomes greater than 150 tiles.

Pathfinding works 1-2-3 years per route ?( I am trying to tweak it settings, but the difference in the speed of his work, i dont see.

Now this is the main problem of my AI. Three 50 tiles rail routes are built for 4-5 months. One 150 tiles rail route are built for 1-3 years.
Why? :)

Solutions:
1. Tweak existing pathfinder. How?
2. Make my own pathfinder.
3. Overwrite existing pathfinder.
4. Use existing pathfinder, but total distance divided into some short parts.
5. Any useable idea?

How do I solve this problem?

P.S. If i press fast forward button AI thinks slowly (more game days / months / years)? or as usual?
Kogut
Tycoon
Tycoon
Posts: 2493
Joined: 26 Aug 2009 06:33
Location: Poland

Re: Some AI problems with builder of rail networks

Post by Kogut »

I reused railway pathfinder from ChooChoo.
Correct me If I am wrong - PM me if my English is bad
AIAI - AI for OpenTTD
User avatar
fanioz
Transport Coordinator
Transport Coordinator
Posts: 320
Joined: 19 Dec 2008 05:03
Location: Indonesia
Contact:

Re: Some AI problems with builder of rail networks

Post by fanioz »

ilt wrote:1. Tweak existing pathfinder. How?
Could be done by :
ilt wrote:2. Make my own pathfinder.
or
ilt wrote:3. Overwrite existing pathfinder.
ilt wrote:4. Use existing pathfinder, but total distance divided into some short parts.
5. Any useable idea?

How do I solve this problem?
You could just overwrite the RailPF._Estimate() to return higher value then it normally return.
See : here
Correct me If I am wrong - PM me if my English was bad :D

**[OpenTTD AI]** Image
***[NewGRF] *** Image
ilt
Engineer
Engineer
Posts: 18
Joined: 03 Oct 2008 17:49

Re: Some AI problems with builder of rail networks

Post by ilt »

My experiments with RailPF moving forward. I have some results! :)

I'm working on the building of a parallel path to the first found. I dont use RailPF here or use for difficult sections of track (short length).

RailPF returns an object Aystar. I dont understand the benefits of working with this object and converts it into an array.

Maybe I dont understand something and reinvent the wheel. Can anyone explain what are the advantages of this object? ?(
Post Reply

Return to “OpenTTD AIs and Game Scripts”

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 8 guests