I have to make a program which can calculate the shortest path to finish all deliveries. The map is represent as x, y coordinate and the path is calculated using Manhattan distance(so go along x and then along y). Start point is always (0, 0) and the courier can finish on any point. The courier can only bring 1 packet at any given time.
This could be implemented using A* search algorithm, my question is since A* algorithm is an I formed search, it needs to know heuristic value of its statusNode. What is a good heuristic implementation for this problem? Or even an idea for the heuristic value?
I have a sample input:
Job 3 3 to 5 3 # there is a job from (3,3) to (5,3)
Job 1 1 to 9 2 # there is a job from (1,1) to (9,2)
Job 3 5 to 2 7 # there is a job from (3,5) to (2,7)
Job 5 5 to 5 7 # there is a job from (5,5) to (5,7)
ANd the output:
Cost = 31
Move from 0 0 to 1 1
Carry from 1 1 to 9 2
Move from 9 2 to 3 3
Carry from 3 3 to 5 3
Move from 5 3 to 5 5
Carry from 5 5 to 5 7
Move from 5 7 to 3 5
Carry from 3 5 to 2 7
My current method for the search is:
I have list of jobToBeDone and jobDone
Intialise intial value of current position is 0, 0
Check whether all jobs have been done
If not, for all remaining jobs, Calculate the total cost=path to get there + some heuristic value of the job.
Put them in jobsToBeDone and sort with shortest path has lower index (like a priorityQueue in java).
repeat instruction from no 2 by updating current position to the job in the first index.