-1

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

  1. Intialise intial value of current position is 0, 0

  2. Check whether all jobs have been done

  3. If not, for all remaining jobs, Calculate the total cost=path to get there + some heuristic value of the job.

  4. Put them in jobsToBeDone and sort with shortest path has lower index (like a priorityQueue in java).

  5. repeat instruction from no 2 by updating current position to the job in the first index.

Karussell
  • 17,085
  • 16
  • 97
  • 197
  • What do you mean by "heuristic value"? I know of "heuristic functions", but even these do have a meaning associated. `some heuristic value of the job` is something that you should define more precisely. – SJuan76 May 07 '13 at 10:10
  • Well, if Manhattan distance is your distance metric, then why not use Manhattan distance? – Fred Foo May 07 '13 at 10:15
  • Or you can go with euclidean distance. As you probably know, the A* algorithm will yield perfect solution only if your heuristic for the distance from current point to the target is lesser or equal to the real distance. – NeplatnyUdaj May 07 '13 at 10:21
  • What is the maximum number of deliveries? – nhahtdh May 08 '13 at 10:21
  • Heuristic value is a value that represent how far we are from the goal. At the moment, I cannot find a way to represent current state from the goal state into a number (heuristic value). Manhattan distance is a cost, but not the heuristic value. For example on the sample input, once we have done job (1,1)->(9,2), Manhattan distance to the starting point of job (5,5) and job (3,3) are both the same which are 7 blocks, with some sort of heuristic, I can choose one job than the others(somehow make it 7+heuristicValue). Max number of deliveries expected would around 15, but limited processingtime – Julius Arden May 09 '13 at 06:59
  • I found a solution to similar problem here: http://cs.stackexchange.com/questions/45422/delivery-algorithm-find-shortest-paths – Sachin J Magdum Mar 09 '17 at 15:42

1 Answers1

0

There are two problems. Shortest path and traveling salesman.

You need to calculate all paths between your points and then order the points to get the final shortest route. For the last part you need an heuristic or brute force for a small amount of points.

Instead of A* use Dijkstra as with dijkstra you can easily calculate several paths at once (as it is one to many)

Karussell
  • 17,085
  • 16
  • 97
  • 197