1

We have one distribution center ( ware house ) and we are getting orders in real time whose time/distance from ware house and other order locations is known.

time matrix=

    W   O1   O2   O3
W   0   5    20    2
O1  5   0    21   7
O2  20  21    0    11
O3  2   7    11   0

order time of O1= 10:00 AM

order time of O2= 10:20 AM

order time of O3= 10:25 AM

I want to club as many as order possible such that delivery time of any order does not exceed by 2 hours of its order time. Thus the question is to reduce the number of trips(Trip is when delivery agent goes for delivery).

I am trying to come up with algorithm for this. there are two competing factors when

  1. We can combine all the orders in the sequence as they are coming till it satisfies the constraint of delivery of the order within 2 hours of its ordering time.

  2. We can modify above approach to find the bottleneck order(due to which we can not club more order now in approach 1). and pull it out from trip1 and make it a part of trip 2(new order) and wait for other orders to club it with trip1 or trip2 depending.

All the orders are coming in realtime. What will be the best approach to conquer this situation. Let me know if you need more clarity on this.

Vivek
  • 152
  • 1
  • 4
  • 10
  • There is one car or many? In other words, when one car went to O1, can I send another to O2 from W? – Adam Stelmaszczyk Mar 04 '15 at 10:48
  • 2
    Are you sure that the matrix is asymmetric in your problem? In real life it's hard for me to find a situation where coming from A to B is 6 minutes, but from B to A is 20 minutes. But, of course, there could be such situation. I just wanted to assure that the matrix could be be asymmetric. – Adam Stelmaszczyk Mar 04 '15 at 10:50
  • @AdamStelmaszczyk There are many cars available. Matrix is symmetric. I have updated the matrix. This matrix is having moc data. – Vivek Mar 04 '15 at 12:43

1 Answers1

0

Very safe and easy algorithm which is guaranteed to not exceed the maximal waiting time for an order:

  1. Let TSP() be a function which returns the estimate of time spent to visit given places. The estimate is pessimistic, i.e. the actual ride time can be shorter or equals to estimate, but not longer. For the good start you can implement TSP() very easily in a greedy way: from each place go to the nearest place. You can subtract the length of the longer edge coming out from W to have better estimate (so a car will always take the shorter edge coming out of W). If TSP() would happen to be optimal, then the whole algorithm presented here would be also optimal. The overall algorithm is as good as TSP() implementation is, it highly depends on good estimation.

  2. Let earliestOrderTime be a time of the earliest not handled yet order.

  3. Repeat every minute:

  4. If there is a new order: If s is empty, set earliestOrderTime to current time. Add it to a set s. Calculate t = TSP(s + W).

  5. If (current time + t >= earliestOrderTime + 2 hours): send a car for a TSP(s + W) trip. Make s an empty set.

Example

For your exemplary data it will work like this:

10:00. earliestOrderTime = 10:00. s = {O1}. t = TSP({01, W}) = 10 - 5 = 5.

10:00 + 0:05 < 10:00 + 2:00, so we don't send a car yet, we wait.

...

10:20. s = {O1, O2}. t = 46 - 20 = 26.

10:20 + 0:26 < 10:00 + 2:00, so we wait.

...

10:25. s = {O1, O2, O3}. t = 2 + 7 + 21 + 20 - 20 = 30.

10:25 + 0:30 < 10:00 + 2:00, so we wait.

...

11.30.

11:30 + 0:30 >= 10:00 + 2:00, so we send a car to go to O3, O1, O2 and back to W. He visits orders at 11:32, 11:39, 12:00 and come backs at 12:20. Guys where waiting 67, 99 and 100 minutes.

Adam Stelmaszczyk
  • 19,665
  • 4
  • 70
  • 110