Click here to Skip to main content
15,914,780 members
Home / Discussions / Algorithms
   

Algorithms

 
GeneralRe: Shortest path related Pin
Alivemau527-Oct-09 10:37
Alivemau527-Oct-09 10:37 
GeneralRe: Shortest path related Pin
Luc Pattyn27-Oct-09 11:23
sitebuilderLuc Pattyn27-Oct-09 11:23 
GeneralRe: Shortest path related Pin
Alivemau527-Oct-09 12:58
Alivemau527-Oct-09 12:58 
GeneralRe: Shortest path related Pin
Member 419459329-Oct-09 13:31
Member 419459329-Oct-09 13:31 
GeneralRe: Shortest path related Pin
Luc Pattyn29-Oct-09 13:36
sitebuilderLuc Pattyn29-Oct-09 13:36 
AnswerRe: Shortest path related Pin
Member 419459327-Oct-09 14:05
Member 419459327-Oct-09 14:05 
AnswerRe: Shortest path related Pin
Member 419459327-Oct-09 14:17
Member 419459327-Oct-09 14:17 
AnswerRe: Shortest path related Pin
Member 419459327-Oct-09 18:02
Member 419459327-Oct-09 18:02 
I just thought of a simpler way to log the paths - use a character 0-7 to log the outbound direction from the current location. The path starts at the specified location, thus is unique, and the string length is the length of the path. Note: The maximum string length could be (for an X by Y matrix) (max(((x/2)*y), (x*(y/2)))+1) to allow for snaking around barriers.

To avoid special checks at the edges, simply border the matrix with a barrier (on the top, bottom, left, and right) which has to be checked for anyway, even in interior locations (the edge barriers would have to be included in the matrix sizes). If you joined the left to the right you would have a cylinder, and if you also joined top to bottom, you would have a torus and would not have a need for the barriers at those joined edges - there would be no edges at the joints.

The calculations for indexing between locations could easily be done with table lookup to get two decrementers/incrementers (-1, 0, or +1), one for east west and another for north south, the table indexed by the direction (0 for north - decrement north south, no change for east west, 1 for north-east - decrement both north south and east west, etc. To handle the cylinder or torus situation, the current location would be incremented/decremented, then the resulting value used to index another array (assume a matrix of 10x10, this new array would be: (9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0). If x and y were different, then two arrays would be needed, one to adjust x another to adjust y. With table lookup, no complicated edge checking is needed. The only checking would be to see what direction to check next, and that could also be done with a 256 element lookup table (i.e. for a direction byte with bit 0 reset, go north, for bit 1 reset go NE, for bit 2 reset go east, etc).

Both the matrix and the movement matrix could be combined into one DWORD matrix with the upper WORD for the location specifier (simple location, start location, target location, barrier location), and the lower WORD the two direction BYTES.

One speedup would be to check the entire array for barrier locations, and set the corresponding bits in all of the 8 locations adjacent to each barrier location so that it would appear that the path had already tried to go that way. With edge barriers, two solutions are available. First, do edge checking for the edge barriers, then no further edge checking needed. Second, add an extra column outside of all edges, then no edge checking need be done (you would be setting bits in columns/rows that would never be examined), but the matrix is 4 columns/rows bigger.

If you have any questions, just ask.

Dave.
QuestionBinary Search Tree "Floor" Search Pin
Bachowny22-Oct-09 1:44
Bachowny22-Oct-09 1:44 
AnswerRe: Binary Search Tree "Floor" Search Pin
Alan Balkany22-Oct-09 3:45
Alan Balkany22-Oct-09 3:45 
AnswerRe: Binary Search Tree "Floor" Search Pin
Member 419459322-Oct-09 7:02
Member 419459322-Oct-09 7:02 
AnswerRe: Binary Search Tree "Floor" Search Pin
ely_bob27-Oct-09 6:58
professionalely_bob27-Oct-09 6:58 
AnswerRe: Binary Search Tree "Floor" Search Pin
Bachowny29-Oct-09 17:25
Bachowny29-Oct-09 17:25 
QuestionPixar Pin
David Crow16-Oct-09 5:14
David Crow16-Oct-09 5:14 
AnswerRe: Pixar Pin
Fatbuddha 116-Oct-09 5:39
Fatbuddha 116-Oct-09 5:39 
GeneralRe: Pixar Pin
David Crow16-Oct-09 5:42
David Crow16-Oct-09 5:42 
GeneralRe: Pixar Pin
Richard MacCutchan16-Oct-09 5:46
mveRichard MacCutchan16-Oct-09 5:46 
GeneralRe: Pixar Pin
Fatbuddha 116-Oct-09 5:47
Fatbuddha 116-Oct-09 5:47 
AnswerRe: Pixar Pin
harold aptroot16-Oct-09 5:53
harold aptroot16-Oct-09 5:53 
AnswerRe: Pixar Pin
Ray Cassick16-Oct-09 6:56
Ray Cassick16-Oct-09 6:56 
AnswerRe: Pixar Pin
Tim Craig16-Oct-09 18:25
Tim Craig16-Oct-09 18:25 
AnswerRe: Pixar Pin
ely_bob27-Oct-09 7:09
professionalely_bob27-Oct-09 7:09 
AnswerRe: Pixar Pin
enhzflep29-Oct-09 10:11
enhzflep29-Oct-09 10:11 
GeneralRe: Pixar Pin
David Crow29-Oct-09 10:23
David Crow29-Oct-09 10:23 
QuestionComparison or travel algorithm for n-ary tree Pin
sampath_dr13-Oct-09 1:46
sampath_dr13-Oct-09 1:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.