- A Shortest Path Problem
- 06 Feb 2011 05:16:09 pm
- Last edited by MufinMcFlufin on 06 Feb 2011 05:24:05 pm; edited 1 time in total
I'm working on a maze solving program, and was curious if anyone had or knew of any good shortest path problem algorithms?
I was planning to have my program search the maze for all intersections, eliminate dead ends, eliminate loops that only concern one intersection, and loops that concern two intersections (reason why later on) then use all the remaining intersections as vertices for a shortest path algorithm. The weights on edges between the vertices were going to be the actual "traveling" distance in the maze between each intersection, so it wouldn't be inaccurate in trying to get actual distances between intersection.
Since dead ends by nature cannot lead to the exit, they'll be omitted, and the program will fill in that area, acting as if it were never there, then recheck the intersection that lead to it (in the event that the intersection would now have only two "exits" to it, and it no longer qualify as an intersection, but a hallway). Loops that concern one intersections cannot make a line, using only one point, so they'll be treated much like dead ends, and will be omitted, then will recheck the intersection that lead them to the loop. Loops that concern two intersections will lead to unnecessary confusion, by allowing there to be two possible distances between two points, so the longer of them will be omitted, and both intersections involved will be rechecked.
After the maze has been successfully converted, it will begin with it's shortest path algorithm. I know I could always have it recursively check each vertex, with each edge, but I was wondering if there was a faster algorithm to use instead of this. After checking the wiki, it seemed that all of the algorithms posted so far, seem to only check the lowest weighted paths from one vertex to another, or other local methods that don't have much hold on the whole of the graph.
For instance, Dijkstra's algorithm checks the shortest distance from the current vertex, and in the example shown, takes the path (from point A (vertex 1) to point B (vertex 5)) of 1,2,3,6,5 with a total distance of 7+10+2+9=28, where as it could have taken a number of paths that have a shorter total distance than this (the fastest of which I found after a cursory glance being 1,3,6,5 being 9+2+9=20)
Is there a more logical way for me to have it find the lowest value path, or will I have to have it guess and check for the lowest distance among all possible distances, from it's list of possible paths that actually reach the exit.
P.S. The main reason I asked instead of simply implementing the recursive check, was because I had remembered seeing a problem much like this from an AP Statistics student's homework they showed me, and figured there just might then be a logical or mathematical process to find the fastest possible path.
I was planning to have my program search the maze for all intersections, eliminate dead ends, eliminate loops that only concern one intersection, and loops that concern two intersections (reason why later on) then use all the remaining intersections as vertices for a shortest path algorithm. The weights on edges between the vertices were going to be the actual "traveling" distance in the maze between each intersection, so it wouldn't be inaccurate in trying to get actual distances between intersection.
Since dead ends by nature cannot lead to the exit, they'll be omitted, and the program will fill in that area, acting as if it were never there, then recheck the intersection that lead to it (in the event that the intersection would now have only two "exits" to it, and it no longer qualify as an intersection, but a hallway). Loops that concern one intersections cannot make a line, using only one point, so they'll be treated much like dead ends, and will be omitted, then will recheck the intersection that lead them to the loop. Loops that concern two intersections will lead to unnecessary confusion, by allowing there to be two possible distances between two points, so the longer of them will be omitted, and both intersections involved will be rechecked.
After the maze has been successfully converted, it will begin with it's shortest path algorithm. I know I could always have it recursively check each vertex, with each edge, but I was wondering if there was a faster algorithm to use instead of this. After checking the wiki, it seemed that all of the algorithms posted so far, seem to only check the lowest weighted paths from one vertex to another, or other local methods that don't have much hold on the whole of the graph.
For instance, Dijkstra's algorithm checks the shortest distance from the current vertex, and in the example shown, takes the path (from point A (vertex 1) to point B (vertex 5)) of 1,2,3,6,5 with a total distance of 7+10+2+9=28, where as it could have taken a number of paths that have a shorter total distance than this (the fastest of which I found after a cursory glance being 1,3,6,5 being 9+2+9=20)
Is there a more logical way for me to have it find the lowest value path, or will I have to have it guess and check for the lowest distance among all possible distances, from it's list of possible paths that actually reach the exit.
P.S. The main reason I asked instead of simply implementing the recursive check, was because I had remembered seeing a problem much like this from an AP Statistics student's homework they showed me, and figured there just might then be a logical or mathematical process to find the fastest possible path.