Click here to Skip to main content
15,887,434 members
Home / Discussions / Algorithms
   

Algorithms

 
GeneralRe: Shortest path related Pin
Alivemau530-Oct-09 11:20
Alivemau530-Oct-09 11:20 
GeneralRe: Shortest path related Pin
Alan Balkany28-Oct-09 5:11
Alan Balkany28-Oct-09 5:11 
GeneralRe: Shortest path related Pin
Alivemau528-Oct-09 12:57
Alivemau528-Oct-09 12:57 
GeneralRe: Shortest path related Pin
Member 419459328-Oct-09 15:55
Member 419459328-Oct-09 15:55 
GeneralRe: Shortest path related Pin
Alivemau528-Oct-09 16:29
Alivemau528-Oct-09 16:29 
GeneralRe: Shortest path related Pin
Member 419459328-Oct-09 17:26
Member 419459328-Oct-09 17:26 
GeneralRe: Shortest path related Pin
Alivemau528-Oct-09 18:48
Alivemau528-Oct-09 18:48 
GeneralRe: Shortest path related Pin
Member 419459329-Oct-09 5:02
Member 419459329-Oct-09 5:02 
As I mentioned, you wanted to have someone supply you with an algorithm. Which algorithm, the algorithm to do the refresh, or the algorithm to decide the move?

The algorithm to do the refresh NEEDS to know at least the location of the goal relative to the current location in order to supply a refreshed direction. It also NEEDS the definition of the identifiers used to specify the start location, the goal location, and barrier locations so it can return the array of adjacents. It also NEEDS the definition of the ordering of the returned array - is it N, NE, E, SE, S, SW, W, NW, or is it a two dimensional array (adjacents[3][3]) where the middle element is never filled in? You wanted algorithm correctness as well, and this implies that it NEEDS to know the matrix bounds. It is not correct to allow the caller to step outside of the array and cause a memory access fault or array bound fault. It NEEDS to know what the current location is so it can check in the matrix to return whatever lies in the adjacent 8 locations. What happens when the caller reaches the edge of the

The move algorithm is trivial. It NEEDS to know the current location and the direction desired. It just refreshes the current location x and y indices. Since the caller does not know its current location (your specification says it only knows the the adjacents and the goal direction), it is assumed that the current location is globally known (the current location x and y values).

You can combine the refresh and move algorithms into one by supplying the location of the direction value in the call instead of the just the value itself. The value of the direction at entry would indicate which direction you wanted to go from the current location, and on return could contain the refreshed direction of the goal. This does cause a bit of a problem at the beginning because the caller does not know the initial conditions (what the adjacent locations are) so it cannot supply any meaningful direction for the initial move which would return the initial adjacents and direction to the goal. Maybe it would be appropriate to have a special value (-1) supplied for the first move as an indicator that this is an initial move.

The caller would also NEED to know the definition of the identifiers used to specify the goal location and barrier locations so that it can determine if a barrier is blocking the way in some direction, or if the goal is in one of the adjacent cells (the returned direction should contain the direction to the goal, but the actual).

Note: The Bug algorithm seems to assume that the current location is known to the caller as well as the adjacents and direction to the goal because it "remembers" the location of the barrier encounter and if it sees this location again, it back tracks.

My solution I gave in the three posts below also requires that the caller know the matrix bounds, the identifiers, and the start, goal and barrier locations.

Dave.
GeneralRe: Shortest path related Pin
Alivemau530-Oct-09 5:09
Alivemau530-Oct-09 5:09 
GeneralRe: Shortest path related [modified] Pin
Alivemau530-Oct-09 5:50
Alivemau530-Oct-09 5:50 
GeneralRe: Shortest path related Pin
Alivemau530-Oct-09 11:19
Alivemau530-Oct-09 11:19 
GeneralRe: Shortest path related Pin
Member 419459330-Oct-09 6:05
Member 419459330-Oct-09 6:05 
GeneralRe: Shortest path related Pin
Rozis29-Oct-09 12:31
Rozis29-Oct-09 12:31 
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 
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 

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.