Smart Area Reclaim TSP Optimization

Smart Area Reclaim TSP Optimization

Discuss Lua based Spring scripts (LuaUI widgets, mission scripts, gaia scripts, mod-rules scripts, scripted keybindings, etc...)

Moderator: Moderators

Post Reply
User avatar
aegis
Posts: 2456
Joined: 11 Jul 2007, 17:47

Smart Area Reclaim TSP Optimization

Post by aegis »

Thinking about resurrecting this with a better (well, an actual) traveling salesman implementation:
http://springrts.com/phpbb/viewtopic.php?f=23&t=15835

Telling a unit to reclaim a dense clump of features is pretty easy to optimize... he can just move around it from the outside.
The problem I was running into with the previous algorithms dealt with isolated clusters. I have a possible solution.

Image

When a construction unit is given an area reclaim command, smart area reclaim splits the area into a grid (Figure A). It then splits grid cells containing features into quadrants (green squares). Adjacent quadrants and high-density quadrants are considered to be clusters of features (blue circles) (Figure B).

Further optimization: clusters can be given a value based on their density. When traveling to a new cluster, a builder can factor density and distance to assign a value to each cluster. It will choose the most valuable cluster.

These values could be extrapolated into a true traveling salesman algorithm by factoring future adjacent clusters into a cluster's value. For example, a very dense cluster far off the path with no adjacent clusters will be worth less than a nearby small cluster with several other nearby small clusters.

Thoughts?
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: Smart Area Reclaim TSP Optimization

Post by Argh »

Just an idea, mind you... but if you updated the sectors when new Features are created, you'd probably arrive at a much faster optimization than doing it at command-time.
User avatar
aegis
Posts: 2456
Joined: 11 Jul 2007, 17:47

Re: Smart Area Reclaim TSP Optimization

Post by aegis »

my biggest slowdown will probably be in the cluster relation values though, not the cell creation.

...and I'd need to do a gadget in order to have FeatureCreated() for all features?
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: Smart Area Reclaim TSP Optimization

Post by Argh »

Hrmm, thought Features were Widget-friendly.

As for clusters... well, if you know the weight of each cell already, then you know where to start a given cluster analysis right away. If cell A has 100 dead things in it, and cell B has 10, it's probably going to give you a better TSP result to go to A, every time, even if B is immediately closer but in the opposite direction.
User avatar
aegis
Posts: 2456
Joined: 11 Jul 2007, 17:47

Re: Smart Area Reclaim TSP Optimization

Post by aegis »

it'll be based on both cluster size AND distance from the last point.

value = density / distance

a cluster 3 quadrants away with density of 5m/quadrant == 5/3
a cluster 5 quadrants away with 3m/quadrant == 3/5
a cluster 5 quadrants away with 10m/quadrant == 10/5 == 2/1

so the unit reclaims cluster three first.
after he's done reclaiming cluster three, cluster two is now 2 quadrants away and cluster one is 5 quadrants away.
cluster one is worth 5/5 and cluster 2 is worth 3/2, so the unit continues from highest value to lowest.
Post Reply

Return to “Lua Scripts”