Jump to content

  • Log In with Google      Sign In   
  • Create Account

A* - Keeping track of nodes


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
11 replies to this topic

#1 Silgen   Members   -  Reputation: 178

Like
0Likes
Like

Posted 01 December 2012 - 04:20 PM

Working on my A* implementation - Mostly working fine, but I'm having difficulties in updating the g values of nodes.

When I look at the neighbours of a given node - in order to check whether or not the g value is an improvement on the current node's g value, I have to search both lists, comparing the x/y coordinates of the current node, with each node in the lists. This seems over complicated. What is a good way of keeping track of the neighbours of a given node?

Sponsor:

#2 SiCrane   Moderators   -  Reputation: 9666

Like
0Likes
Like

Posted 01 December 2012 - 04:42 PM

What data structures are you using for your implementation? Ideally you want to use set structures for things like the closed set so you don't have to do things like compare against every node in the sets.

#3 Silgen   Members   -  Reputation: 178

Like
0Likes
Like

Posted 01 December 2012 - 04:51 PM

My code is pretty dirty at the moment - unsorted lists for open/closed, and a 2d array for the map. The path is just a singly linked list of nodes.

#4 SiCrane   Moderators   -  Reputation: 9666

Like
1Likes
Like

Posted 01 December 2012 - 05:15 PM

Using ordinary lists would be suboptimal. Take a look at the algorithm and look at what operations are done on each of the collections. Ex: for the closed set all you ever do is add elements and check if elements are part of the the closed set, so something like a binary search tree or a hash table would work well, and most languages have those kinds of structures as part of their standard library.

#5 ultramailman   Prime Members   -  Reputation: 1585

Like
1Likes
Like

Posted 01 December 2012 - 06:22 PM

Hello
For the open list, a binary min-heap is a good structure to store nodes. After an "insert" / "remove top" operation, he top item will always be the node with the least F score.

For your closed list, you don't actually need a real list to store nodes, if you'll never take things out from the closed list. So instead of adding a node to the closed list, you can just use a flag to indicate whether the node is in closed list, open list, or neither.

These are just what I've found to be useful from my own recent (also first time) implementation.

#6 Silgen   Members   -  Reputation: 178

Like
0Likes
Like

Posted 01 December 2012 - 06:43 PM

I've finished implementing what I believe to be an A* algorithm in some rather heinous code. I hope to try out binary heaps when I revisit this.

These are some images showing it in action. Blue representes an obstacle tile, orange a closed list square (explored) and the white line is the final path. Does this look correct? It moves towards the obstacle, then fills in back toward the starting point, until it can get around the obstacle, then resumes.

Posted Image

Edited by Silgen, 01 December 2012 - 06:43 PM.


#7 SiCrane   Moderators   -  Reputation: 9666

Like
0Likes
Like

Posted 01 December 2012 - 06:47 PM

The first image doesn't look quite right. The final path seems suboptimal; it can save a step by moving diagonally where it moved horizontally right past the obstacle.

#8 Silgen   Members   -  Reputation: 178

Like
0Likes
Like

Posted 01 December 2012 - 06:58 PM

Surely it would have had to make the diagonal movement just before reaching the point though?

#9 ultramailman   Prime Members   -  Reputation: 1585

Like
0Likes
Like

Posted 01 December 2012 - 07:03 PM

I've finished implementing what I believe to be an A* algorithm in some rather heinous code. I hope to try out binary heaps when I revisit this.

These are some images showing it in action. Blue representes an obstacle tile, orange a closed list square (explored) and the white line is the final path. Does this look correct? It moves towards the obstacle, then fills in back toward the starting point, until it can get around the obstacle, then resumes.


The pathes seem good, but aren't the pathes supposed to be completely inside the oranged area? Since you can only know a path if it is explored. Can you try producing these pictures with the open nodes also coloured?

#10 SiCrane   Moderators   -  Reputation: 9666

Like
1Likes
Like

Posted 01 December 2012 - 07:03 PM

Surely it would have had to make the diagonal movement just before reaching the point though?

I'm not sure I follow what you're saying. From the point just above the obstacle, it should make a diagonal step to the lower left. By making a horizontal step left it needs to take an extra vertical step down later.

Edited by SiCrane, 01 December 2012 - 07:04 PM.


#11 Silgen   Members   -  Reputation: 178

Like
0Likes
Like

Posted 01 December 2012 - 07:08 PM

Ah I understand what you are saying - my mistake. I disabled that type of movement to prevent it going through walls that are only one block thick - guess I'll need to revise that then.

#12 Silgen   Members   -  Reputation: 178

Like
0Likes
Like

Posted 01 December 2012 - 07:12 PM

Ultramailman - the white path overwrites the orange path, and the open list just outlines the orange block.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS