5

A woman watches her cats leave one by one with different speeds in different directions. She took a motorcycle with one extra seat and follows the cats and picks up one cat at a time and brings them back home. Each cat moves with constant individual speed Vi and left home at time Ti. In which order the woman should bring the cats back in order to minimize the time?

I am trying to solve this problem but do not know how to begin.

begincoding123
  • 161
  • 2
  • 13
  • Can you assume all the cats have left by the time the woman starts collecting them? Otherwise, she could just start by locking up the cats that are still at home :) – chepner Feb 02 '17 at 12:32
  • @chepner yeah I was going to say that as well, after going home I made a couple of scenario and I didn't get the expected results. – Patrick Trentin Feb 03 '17 at 08:07

2 Answers2

0

Summary:

Sort the cats according to the metric v / x in descending order, where v is the cat's constant speed and x is the cat's initial displacement at time t = 0. It doesn't matter how you break ties. Once the order is initially established, it will remain the most efficient order in which to get cats as long as it is followed; so follow it.

Candidates debunked:

In both cases, allow the motorcycle speed to be w = 20.

  1. It is proposed that you get cats in order from fastest to slowest. Counterexample: Cat #1 (x, v) = (1, 9) and Cat #2 (x, v) = (100, 10).

  2. It is proposed that you get cats in order from closest to farthest. Counterexample: Cat #1 (x, v) = (1, 1) and Cat #2 (x, v) = (2, 100).

Detailed Derivation:

Let c(k) refer to the kth cat the lady picks up, v(k) refer to the speed of that cat and x(k) to the cat's initial displacement (at time t = 0, which we set a the time the lady starts her motorcycle initially in pursuit of the first cat).

The total time taken to get the first cat is:

t(1) = 2 * x(1) / (w - v(1))

where w is the constant speed of the motorcycle. Since this expression is going to be important we can motivate every part of it:

  1. 2 * comes from the fact that the lady must catch the cat, and then spend the same amount of time to return the cat home;
  2. x(1) / (w - v(1)) is the time taken to reach the cat, that is, close the distance x(1) by traveling w - v(1) faster than the cat's v(1).

The time to get the first two cats is:

t(2) = t(1) + 2 * (x(2) + v(2)t(1)) / (w - v(2))

That is, it takes time equal to the time to get the first cat plus the time to get the second cat. The extra v(2)t(1) term accounts for the fact that the second cat moves while the lady is getting the first cat; otherwise, this part is the same.

Rearranging this expression, we get:

t(2) = t(1)(1 + 2 * v(2) / (w - v(2)))  + 2 * x(2) / (w - v(2))

We define the following derivative terms:

T(k) = 2 * x(k) / (w - v(k))
s(k) = 2 * v(k) / (w - v(k)) + 1

Now we rewrite:

t(1) = T(1)
t(2) = s(2)T(1) + T(2)

and continue

t(1) = T(1)
t(2) = s(2)T(1) + T(2)
t(3) = s(3)s(2)t(1) + s(3)T(2) + T(3)
...
t(n) = s(n)...s(2)T(1) + s(n)...s(3)T(2) + ... + T(n)

This last expression gives us the total time to get all n cats:

s(n)...s(2)T(1) + s(n)...s(3)T(2) + ... + T(n)

Now we assume that we have an optimal solution in that the cats are picked up in the most efficient order possible. To derive useful properties about this hypothetical optimal solution, we can use the supposed optimality to infer that swapping cats produces a solution that is no better. Imagine swapping cats j and j+1:

... + s(n)...s(j+1)T(j) + s(n)...s(j+2)T(j+1) + ...
<= ... + s(n)...s(j)T(j+1) + s(n)...s(j+2)T(j) + ...

Terms involving T(k) for k < j have both s(j) and s(j+1) and by the commutativity of multiplication they are unaffected by the swap. Terms involving T(k) for k > j + 1 have neither s(j) nor s(j+1) and so cannot be affected by the swap. Only the terms with T(k) such that j <= k <= j + 1 are affected by the swap, so we can remove like terms:

s(n)...s(j+2)s(j+1)T(j) + s(n)...s(j+2)T(j+1)
<= s(n)...s(j+2)s(j)T(j+1) + s(n)...s(j+2)T(j)

The partial product s(n)...s(j+2) is common to all remaining terms and must be positive, so we can remove this like term by dividing both sides of the inequality:

s(j+1)T(j) + T(j+1) <= s(j)T(j+1) + T(j)

Rearrange this as follows:

(s(j+1) - 1)T(j) <= (s(j) - 1)T(j+1)

Finally:

(s(j+1) - 1) / T(j+1) <= (s(j) - 1) / T(j)

Recalling our definitions of s(k) and T(k), simplify to put this in terms of v and x:

v(j+1) / x(j+1) <= v(j) / x(j)

That is: if we have an optimal solution, it must be the case that the ratio of cats' speeds to initial displacements must be in descending order. This is a necessary, but perhaps not sufficient, condition.

Note that this result agrees with intuition:

  • Get still cats last (v = 0)
  • Get cats that haven't left yet first (x = 0)
  • Get cats approaching the motorcycle's speed first (or never)
  • Get cats that are really far away last (x -> +inf)

It also gives the correct result for the two-cat case; and in that case, if the ratios of speed to displacement are equal, then it can be easily shown that it doesn't matter which order you get the cats in (if they are unequal, you must get the cat with the higher ratio first).

Now - I have not addressed the case where cats may have the same ratio. It's not immediately obvious to me that the order in which you get cats with the same ratio doesn't matter.

However, suppose you have chosen optimally up until some point k < n. Now you need to decide which of two cats with the same ratio to go after. As we already mentioned, for the two-cat problem, it's a wash: so I think the answer is that it can't matter which one you choose, as either order among the two will take the same time and "look" the same afterwards. To see that two cats that start with the same ratio keep the same ratio:

v(i) / x(i) = c; X(i) = x(i) + v(i)t = x(i) + x(i)ct = x(i)(1 + ct)
v(j) / x(j) = c; X(j) = x(j) + v(j)t = x(j) + x(j)ct = x(j)(1 + ct)

So the ratio changes over time (if you take X as the new initial displacement) but two cats that start out with the same ratio will keep it. The new ratio will be:

v / x = c; v / X = v / x(1 + ct) = c / (1 + ct)

It is important to note that these ratios don't "cross over" each other either; if you start out with a higher or lower ratio, it will change over time, but it will not become higher or lower than other cats' ratios:

c(i) / (1 + c(i)t) > c(j) / (1 + c(j)t)
<=> c(i) + c(i)c(j)t > c(j) + c(i)c(j)t
<=> c(i) > c(j)

Based on all of these considerations, my best answer is:

Sort the cats according to the metric v / x in descending order. It doesn't matter how you break ties. Get the cats in that order.

Patrick87
  • 27,682
  • 3
  • 38
  • 73
0

Update

Thanks to @Patrick87 counterexample, I know my solution does not work in the general case, however, I'm going to leave it here because it provides a simpler solution under the extra assumption that all cats start their moves from the home at time 0. Please see @Patrick87 solution for a general solution.

Short Answer:

She must start with the fastest cat. i.e, order cats by velocity (in decreasing order).

Simplify the problem: Assume there are only two cats, one is running the other one walking very slowly. Which one you will go after first?

Detailed answer:

The total distance of all cats from home at time 0 is 0:

 X(0) = 0 

enter image description here

Therefore, if we assume that the woman catches the last cat at time Tn then the total distance the woman has traveled at Tn is:

 X(Tn) = (V1 * T1) + ... + (Vn * Tn)

Where Ti is the time she catches the n's cat. Vi values are predetermined, so, we need to minimize this equation based on values of Ti.

We have n POSITIVE V values with n positive T coefficients to assign to them. Minimizing it under these conditions is easy:

Give the largest V, the smallest coefficient T and so on.

Which means start with the fastest cat (largest V) and bring it back first (multiply by smallest T) and continue.

Community
  • 1
  • 1
TheEsnSiavashi
  • 1,245
  • 1
  • 14
  • 29
  • Counterexample. Two cats. Cat #1 at x = 1 m traveling v = 9 m/s. Cat #2 at x = 100 m traveling v = 10 m/s. Motorcycle speed is w = 20 m/s. Time to get Cat #2 then Cat #1 (as you recommend) is 20 s for Cat #2 then around 33 seconds to get Cat #1 (it has traveled 180 m). Total time is ~53 s. If you get Cat #1 first, then it takes around 0.2 seconds to get Cat #1, then about 10.2 to get Cat #2 (Cat #2 traveled 2 m). If this calculation is correct it shows that getting the fastest cat first is not always optimal. – Patrick87 Jul 18 '17 at 15:27
  • @Patrick87 I see what you are saying. Give me sometime to see what I'm missing. Thanks! – TheEsnSiavashi Jul 18 '17 at 15:45