Imagine that you go on a road trip with some friends. One of your friends has a video camera and films the best moments of the trip. After the trip, your friend edits the footage and creates a movie with the very best moments. Your friend could then burn a CD (or a DVD) containing the movie, and send it to you via post-mail. However, that solution involves:
- wasting time to go to the mail office.
- spending money on CD’s, stamps, and envelopes.
We could do better than that: why not compress the movie into one or more ZIP files and upload them to a hosting website such as Rapidshare? Bandwidth is cheap these days, and downloading involves only a few mouseclicks. Your friend uploads the ZIP files to a hosting website and sends you the list of URL’s via email, including the size of each file next to each URL. Let us assume that:
- in this hosting website, you need to wait 1 minute for each MB you downloaded in the previous file download.
- you need to download all ZIP files before you can unzip them and watch the movie your friend created.
You then think: “in which order should I download the files”? This is a decision problem under certainty. Let us try to model it!
__________
Mathematical Model
Let us say that we have a total of files to download, where
. We consider the following variables and parameters (and respective units):
: size of the
-th file (unit: Megabytes).
: time it takes to download the
-th file (unit: seconds).
: time one needs to wait after downloading the
-th file (unit: seconds).
: downloading speed (unit: Megabytes per second)
for all , where
. The time it takes to download the
-th file is
and the time one needs to wait after downloading the -th file is
.
The total downloading time is the sum of each file’s downloading time plus the time one needs to wait after downloading each file. Note that after we download the last file, we can unzip the files and obtain the full-length movie. Therefore, when counting the total downloading time, we do not need to include the waiting time of the last downloaded file. Let us denote by
the index of the last downloaded file. Thus, the total downloading time is
,
which can also be written as
,
or, then, as follows
.
__________
Optimal Downloading Strategies
Suppose that our objective is to minimize the total downloading time . Let us introduce the cost function
defined by
.
Note that our decision variable is , i.e., our goal is to find the value of
that minimizes the total downloading time
. Note also that:
is the “fixed cost”.
is the “variable cost”.
We cannot “control” the fixed cost, but we can try to minimize the variable cost. The minimal cost is thus
.
Hence, we can conclude that the optimal is
,
i.e., we should leave the biggest of all files for last! This is quite intuitive. Given that
- the downloading speed,
, is assumed to be constant.
- we need to download all the
files.
we can conclude that the only way to minimize the total downloading time is to minimize the total waiting time, and the way to do that is to download the biggest file at the end.
Alternatively, we could have used the following cost function
where cost equals waiting time (i.e., we ignore the fixed cost). The optimal solution will be the same as before
,
and the only difference will be that the minimum cost will now be the minimum waiting time, not the minimum total downloading time.
__________
Concluding Remarks
The solution we have computed only tells us which file to download in the -th download. The solution tells us nothing on which files to download on the previous
downloads. We can then conclude that:
- there are
distinct ways of downloading the files.
- out of those
ways,
of them are optimal.
If all the files have the same size (i.e., if ), then there are
optimal ways of downloading them. In other words, when all files have the same size, the order in which one downloads them is irrelevant, which is somewhat obvious.
This problem could perhaps be generalized. Any ideas?
__________
DISCLAIMER: please note that downloading copyrighted material is illegal under U.S. law. I do not advocate downloading copyrighted material.
Tags: Operations Research
February 25, 2008 at 01:59 |
Rod,
The first problem could, perhaps, also be solved using the Rearrangement Inequality. Though I don’t come from a (math) olympiad background, I do know this inequality is very much a part of olympiad training when learning the topic of inequalities. It can certainly be used to prove the (familiar) AM-GM, the Cauchy-Schwarz, and the Chebyshev inequalities.
Your solution is, indeed, simple to understand and intuitive!
June 30, 2010 at 23:22 |
Great article. You’re right that the solution is very intuitive.
Regarding generalisation: do you mean what if you’re completely unable to determine file size prior to ending the download? Or what if there’s an extra step involved in determining file size? (loading a “file info” page on the host for example, a process which takes a fixed time and invokes no penalty)
Something about this is reminiscent of bin-packing, but the solution is really just a consequence of the fact that the final downloaded file invokes no penalty. Of course, if you change it such that the time penalty is applied before the download, then all strategies are optimal.
Interesting stuff though.
July 2, 2010 at 16:04 |
Frankly, I have no idea what I was thinking back in Feb. 2008 when I suggested the possibility of generalizing the problem. I edited the last few lines of the post, in which I mentioned generalizations, because I really can’t understand what I meant when I wrote them.
The approach discussed in this post is, essentially, decision under certainty. It’s somewhat austere, as there’s no room at all for uncertainty. How could one generalize the problem under perfect certainty? What if the downloading speed would depend on how many Megabytes one had downloaded before? The more one downloaded, the slower the download, for instance. Or, what if there was a ceiling on how much one could download and, once that ceiling was exceeded, the new rate would become
, where
.
If we introduce uncertainty, then things can get even more interesting. For instance, suppose that one does not know the size of the files and that, instead, one has a probability distribution
for the size of each file. One could then try to minimize the expected downloading time. Is this mathematically interesting? Yes! Does this make sense from a practical viewpoint? I don’t think so. How would one obtain reliable estimates of the probability distributions, after all?