I am working on an assignment which requires the use of A* algorithm but I cannot figure out how.
The assignment is, imagine a postman sending parcels on a grid map from (0,0)
to infinity. He takes a list of tasks at the beginning of a day, with each task assigned a starting point (x1,y1)
and an ending point (x2,y2)
. Since he cannot handle two tasks at the same time, he will have to arrange those tasks, so that when he finishes one task and move from the end point to the next start point, he could have the minimum travelling distance overall during the whole day. The distance is calculated as Manhattan distance which is d(x1,y1,x2,y2) = abs(x2 - x1) + abs(y2 - y1)
.
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)
sample output:
n nodes explored
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
In my point of view, though a graph(or map) is mentioned here, it is not required since the only essential part is to sort those tasks for a minimum while the distance can be easily calculated. Something stupid would be permutation and select the one with the least cost but never to adopt that. I have also tried Greedy but it may not get the global best solution.
So the question is, since A* algo. is designed for path finding, how can we apply that or a variation of that to this problem of finding the correct way?