Software Design
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreSoftware Design

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old August 19th, 2003, 11:43 AM
Maldor's Avatar
Maldor Maldor is offline
Muhhnnn !!
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Apr 2003
Posts: 1,530 Maldor User rank is Second Lieutenant (5000 - 10000 Reputation Level)Maldor User rank is Second Lieutenant (5000 - 10000 Reputation Level)Maldor User rank is Second Lieutenant (5000 - 10000 Reputation Level)Maldor User rank is Second Lieutenant (5000 - 10000 Reputation Level)Maldor User rank is Second Lieutenant (5000 - 10000 Reputation Level)Maldor User rank is Second Lieutenant (5000 - 10000 Reputation Level)Maldor User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 1 Day 7 h 38 m 2 sec
Reputation Power: 83
A* Path finding.

Hi,

I implemented the A* Algorithm and now I am trying to optimize it...

The problem is usual, I have to go from A to B, calculating the *shortest* path. I am using as Euristic the Euclidienne distance from each evaluated point to the final destination.

Now, I have a limited movement points, therefore, to optimize the calculation time, I don't want to use as destination B, but I would like to use a point C. C being on (AB) at a distance cost a bit over the allowed movement. The idea behind that being to restrict the area of calculation.

Can anyone help me to find the lower cost solution to find C coordinates?

Thanks =)
__________________
"The ultimate knowledge is reached when it does not bring new questions..."
-- Usaphdas encyclopedia XV.4


Reply With Quote
  #2  
Old August 19th, 2003, 01:16 PM
M.Hirsch M.Hirsch is offline
Contributing User
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: Oct 2000
Location: Back in the real world.
Posts: 5,969 M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Month 1 Day 22 h 42 m 50 sec
Reputation Power: 185
I would "virtually walk" the path (AB) and add up the costs per step. if costs > allowed { return C(x,y) }.

I donīt know much theory, the "Euclidienne distance", is that sqrt(deltax+deltay)? This would be the first optimization, getting rid of the square root.
__________________
--
Manuel Hirsch - Linux, FreeBSD, programming, administration articles, tutorials and more.

Reply With Quote
  #3  
Old August 20th, 2003, 04:08 AM
Maldor's Avatar
Maldor Maldor is offline
Muhhnnn !!
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Apr 2003
Posts: 1,530 Maldor User rank is Second Lieutenant (5000 - 10000 Reputation Level)Maldor User rank is Second Lieutenant (5000 - 10000 Reputation Level)Maldor User rank is Second Lieutenant (5000 - 10000 Reputation Level)Maldor User rank is Second Lieutenant (5000 - 10000 Reputation Level)Maldor User rank is Second Lieutenant (5000 - 10000 Reputation Level)Maldor User rank is Second Lieutenant (5000 - 10000 Reputation Level)Maldor User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 1 Day 7 h 38 m 2 sec
Reputation Power: 83
Hirsch,

if I "virtually walk" the path (AB), then I have to calculate the moving cost from A to B which is the heavy part of A*.

In my specific case, the working area is 50*50. A* can have to evaluate 2500 cost. My max movement being around 6. The idea is to calculate a partial destinal to reduce the cost calculation to a 7*7 square, and to reproduce that for each turn antil b is reached.

As for the "Euclidienne distance", it is what you described. Thanks for the tips, was already implemented this way =)

Reply With Quote
  #4  
Old August 20th, 2003, 01:46 PM
M.Hirsch M.Hirsch is offline
Contributing User
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: Oct 2000
Location: Back in the real world.
Posts: 5,969 M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Month 1 Day 22 h 42 m 50 sec
Reputation Power: 185
From my understanding of the algorithm this is impossible. You need the full run to get the shortest path.

What kind of program is this? A Game? Maybe you can precalculate all possible paths when the map file is being compiled or something...

You could also use another less precise distance model like this:
1 step vertical or horizontal = 10 units
1 step diagonal = (ca.) 14 units
And thus you can easily sum up the costs in steps without knowing the "real" distance. "add" is a good operation for optimization too

Reply With Quote
  #5  
Old August 21st, 2003, 04:26 AM
Maldor's Avatar
Maldor Maldor is offline
Muhhnnn !!
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Apr 2003
Posts: 1,530 Maldor User rank is Second Lieutenant (5000 - 10000 Reputation Level)Maldor User rank is Second Lieutenant (5000 - 10000 Reputation Level)Maldor User rank is Second Lieutenant (5000 - 10000 Reputation Level)Maldor User rank is Second Lieutenant (5000 - 10000 Reputation Level)Maldor User rank is Second Lieutenant (5000 - 10000 Reputation Level)Maldor User rank is Second Lieutenant (5000 - 10000 Reputation Level)Maldor User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 1 Day 7 h 38 m 2 sec
Reputation Power: 83
The program is in fact a "battle engine" for a web game (http://www.holy-war.com). People are planning the way their troops act/react. In the actual version of it, troops can walk on the same "square" as other troops. I want to avoid that, therefore, I have to generate some path finding.

I cannot precalculate the path because my obstacles (other troops) are moving.

I know that if I am cutting the global path in several parts, it will no more be the shortest path, but I think that it will still be quite efficient.

Reply With Quote
  #6  
Old August 21st, 2003, 01:39 PM
M.Hirsch M.Hirsch is offline
Contributing User
Dev Shed God 1st Plane (5500 - 5999 posts)
 
Join Date: Oct 2000
Location: Back in the real world.
Posts: 5,969 M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level)M.Hirsch User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Month 1 Day 22 h 42 m 50 sec
Reputation Power: 185
I got an idea:
You could calculate the "ideal" path with the A* (the full path) and cache it for the next steps. In this step you donīt consider the other troops at all yet.
Then you find only the troops inside your 7x7 and re-do the A* with destination C on (AB) for this part only. Do until you reached B.

Considering that from one round to the next the othersī troops will probably have moved too, it should bring you to the destination still quite quickly.
IMHO this would need some hours of simulation before going public to see if no ships can get stuck circulating around each other (I have seen this effect many times in older games ).

Another idea: move the A* calculations for each user to the client ("delegate" the work LOL). They could supply input like "I want to go to place B using the path (1,1)(1,2),(1,3),..." and youīd only check if it is a valid way to walk or not...

Reply With Quote
  #7  
Old August 21st, 2003, 02:53 PM
sam@pcm's Avatar
sam@pcm sam@pcm is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Location: South Africa - Johannesburg
Posts: 30 sam@pcm User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 40 sec
Reputation Power: 7
Hi There Guys

I have worked many times using this algorithm. One that that you must remember is that A* calculates the shortest distance from your root to all nodes with a lesser distance from the root than your destination.

If you had to closely trace the algorithm you rarely follow a nice path but the.

Keeping an array for each node of distance from the root and a parent child relationship is the trick to the algorithm.

I studied the theory of this algorihm during University and it can be proved that there is no better, more efficient, way of calculating the shorted path to a node. Using a heuristic like euclidean distance does not ensure you will 100* always get the shortest path.

Hope this helps
Sam

Reply With Quote
  #8  
Old August 22nd, 2003, 04:02 AM
Maldor's Avatar
Maldor Maldor is offline
Muhhnnn !!
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Apr 2003
Posts: 1,530 Maldor User rank is Second Lieutenant (5000 - 10000 Reputation Level)Maldor User rank is Second Lieutenant (5000 - 10000 Reputation Level)Maldor User rank is Second Lieutenant (5000 - 10000 Reputation Level)Maldor User rank is Second Lieutenant (5000 - 10000 Reputation Level)Maldor User rank is Second Lieutenant (5000 - 10000 Reputation Level)Maldor User rank is Second Lieutenant (5000 - 10000 Reputation Level)Maldor User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 1 Day 7 h 38 m 2 sec
Reputation Power: 83
I made a quick drawing to illustrate my concern.

http://maldor.free.fr/holywar/a-star.gif

The top schema is the basic A-star effect on the first attempt of move, the bottom one detail the effect of what i want to implement.

Color code:
-> Blue = affected area by the calculation. Cost are calculated for this whle area. on the second schema, a purple line delimit this area for each turn.
-> Red = start / end / intermediate destinations
-> Yellow = shortest flying path not taking into account obstacles and cost
-> Green = resulting path.

I know that my suggestion can result on weird move and will surely not give the same result as the overall calculation. However, it will optimize the calculation amount drastically.

So my basic aim is now to find the most efficient way to calculate those intermediate red spots. (they should not be occupied as well)

Thanks for your help guys =)
Matt

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreSoftware Design > A* Path finding.


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT