Pathfinding loadbalancing

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
anboni
Engineer
Engineer
Posts: 23
Joined: 21 May 2006 10:12

Pathfinding loadbalancing

Post by anboni »

I ran into some issues with loadbalancing on my train network and after some chatting with KUDr (I'm using the yapf branch), I had some thoughts about how to handle loadbalancing.

The problem I ran into is if there's 2 routes from one station to another, running across the same mainline but inner and outer track, they dont get seen as being 'the same' (which is mathematically correct, but logically incorrect).

My idea is to determine all possible (realistic) routes, calculate the average (tile-based only) cost of those, then set all routes which have a cost within + or - 10% (tunable number, of course) to be equal to the average. Going from that average, then do the signal-based cost-calculation and if all routes still cost the same, pick a random or round-robin route.

I'm probably overlooking some important details, but maybe this will get ideas flowing :)
KUDr
OpenTTD Developer
OpenTTD Developer
Posts: 219
Joined: 11 Jan 2006 21:36
Location: Czech Republic

Post by KUDr »

anboni: try to look at A* algorithm (http://en.wikipedia.org/wiki/A%2A_search_algorithm) and think more about how it can be improved to achieve what you like. Unfortunatelly it has no way how to compare 2 routes and decide. It can only choose betwen two tracks when it reaches junction, but at this moment it has no idea which one leads to the destination. Later on, when binary heap (open list) gives next node to search it follows that node. Everything depends on comparison of cost estimate of nodes. Cost estimate is sum of cost from origin (train's current position) up to the node and distance of that node from destination. Like:
node.estimate = node.cost(org, node) + node.distance(node, destination)

The cost() calculation it the only thing we can play with if it shoul be still A*. In current implementation there is also one very important rule that we must care about: When you follow node to the next node (first one is parent, new one child), the child.estimate must not be less than parent.estimate (maybe you remember one very common
assert(n.m_estimate >= n.m_parent->m_estimate).
In other words it meand that real single node cost must be equal or higher than distance between two nodes (child, parent). If you for example apply negative penalty for down-hill tile, you break this rule and run into problems.

On the other side, any positive penalty (like up-hill move) makes bigger and bigger difference between estimate and real cost of whole path and A* becomes less and less effective. In worst case it can be as ineffective as dijkstra algorithm (http://en.wikipedia.org/wiki/Dijkstra%27s_algorithm).

So try to formulate your idea in relation to this. Otherwise we will not talk about improvement but about different pathfinding algorithm. This can be also good, but more time consuming.
TBOT
Route Supervisor
Route Supervisor
Posts: 441
Joined: 30 Jul 2003 18:36
Location: The Codecave

Post by TBOT »

Take a look at a patch I did a while ago: http://tt-forums.net/viewtopic.php?t=24469
Effectively it gives a higher cost to an occupied route, and therefore less crowded alternatives are used more often. As far as I remember it still had some quirks (I haven't worked on it since), but in general it used to work.
"Peace cannot be kept by force. It can only be achieved by understanding." - Albert Einstein
Post Reply

Return to “OpenTTD Development”

Who is online

Users browsing this forum: No registered users and 16 guests