3
$\begingroup$

We have a set of $n$ products, each $i$th product can be kept in a temperature between $c_i$ and $h_i$.

We have to buy fewest number of fridges for these products. The fridges can only have a fixed temperature.

For me I think of this problem as intervals of product temperatures that are placed on the axis. enter image description here

My idea to solve it is to see which product's temperature range overlaps with most other products temperature ranges, then we can place these products in one fridge.

But the algorithm for this would be inefficient..

What's a simple greedy solution for this? any ideas?

$\endgroup$
1
  • $\begingroup$ I'm missing how many items fit into each fridge. Or if there are different fridge sizes at different cost. $\endgroup$
    – gnasher729
    Commented Feb 14, 2020 at 23:24

2 Answers 2

4
$\begingroup$

The formalized problem here is selecting the minimum number of points such that for each temperature interval $\ell_i\in L$ we have at least one point that covers it. Let each interval $\ell_i$ be represented by $(c_i, h_i)$

  1. Order all $\ell_i\in L$ by their $h_i$.
  2. While there are still items that need fridges.
    1. Buy a fridge and set it to $h_1$.
    2. For every item with $c_i\leq h_1$, put item $i$ in the fridge and discard the interval from $L$

The runs in $O(n\lg n)$ time.

We can show this is optimal. Let the solution obtained above be $S$ and let any feasible solution be $R$. We can show that for any point $x_i\in R$, there is at most one point from $S$ between $x_{i-1}$ and $x_i$.

If the above is not true then we have some $x_{i-1}\leq y_{j-1} < y_j < x_i$ for both $x\in R$ and both $y\in S$. In this case, the interval $\ell_k$ ending at $y_j$ would not be covered by $R$. $x_i$ can’t cover it, since by definition $y_j < x_i$. $x_{i-1}$ can’t cover it either. If it did, that would mean the start point of $\ell_k$ would be less than $x_{i-1}$ and thus also less than $y_{j-1}$. This can’t be the case, though, because then $y_{j-1}$ would have covered $\ell_k$, therefore removing it from the list of intervals in the next step our algorithm. Thus we have shown that for any point $x_i\in R$, there is at most one point from $S$ between $x_{i-1}$ and $x_i$ and therefore $S$ is optimal.

$\endgroup$
3
  • 1
    $\begingroup$ I wonder if the fridge problem is the dual of the interval scheduling problem. The greedy algorithm for the interval scheduling is essentially the same. $\endgroup$
    – Daniel
    Commented Feb 15, 2020 at 22:09
  • $\begingroup$ @Daniel, great insight! Yes, there is a dual. Given a set of intervals, the minimum number of points that hit every interval is equal to the maximum number of non-overlapping intervals. $\endgroup$
    – John L.
    Commented Feb 21, 2020 at 0:49
  • $\begingroup$ That duality is just Mirsky theorem on the intervals with $\prec$, where $I\prec J$ if interval $I$ and interval $J$ are disjoint and the endpoints of $I$ are smaller than the endpoints of $J$. $\endgroup$
    – John L.
    Commented Feb 21, 2020 at 3:27
0
$\begingroup$

I'd start with the shortest temperature range, stash everything that fits in it into a refrigerator, rinse and repeat. But a temperature range may overlap several that don't overlap among themselves, among those that do overlap search for a temperature that hits most ranges. This heuristic sounds like it should give a good solution, but I'd first look if there are is some counterexample (and I'd be thrilled to see a proof that it gives an optimum...).

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.