Click here to Skip to main content
15,892,809 members
Home / Discussions / Algorithms
   

Algorithms

 
GeneralRe: Shortest path related Pin
novice__geek29-Oct-09 23:34
novice__geek29-Oct-09 23:34 
AnswerRe: Shortest path related Pin
ely_bob27-Oct-09 6:28
professionalely_bob27-Oct-09 6:28 
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 
I played around with this many years ago on my NEC APC. I had a matrix of moves for each intersection (think of the path to the next location as a road, and the location having 4 directions to go), each element of the move matrix was a byte, the high nibble had 4 bits indicating the entry direction (for backtracking), the low nibble had 4 bits indicating which directions had been tried. When a direction was tried (when you started to go that direction) you set a bit in the low nibble for the selected direction, and set the bit in the high nibble for the entry direction, and if the move was valid you continued. If this was a barrier or if you had already visited this intersection (some bit set in either high or low nibble, then you backtrack to the first intersection which had some available path and tried a different direction. If you backtrack FROM an intersection, then reset the bit in the high nibble of the intersection you are returning FROM but not the bit in the low nibble you are returning TO. You need to check the original matrix to see if the location is a barrier or if you have found the target.

Note: You do not want to visit an intersection more than once, not to cross (from east to west, crossing a north to south path), not to touch (east to north where there was a path from west to south), and not to follow a prior path (huge loop).

To find the shortest path (maybe more than one the same length), try all paths from the starting point and save the path intersections you visit (deleting the last intersection point for each backtrack) until you find the target. The length of that one path is then known. Continue the searches until all directions from the starting point have been tried.

To find the longest path, modify the test for visiting an intersection to allow either a touch, and/or a cross, and try all paths and select the longest.

I played around with depth first searches (described above), then breadth first searches (harder to implement). Fun exercise!

Dave.
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 
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 

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.