r/AskComputerScience • • Dec 07 '24

Combinatorial Optimisation - fridge/freezers during a blackout

Wondering if anyone has thoughts on solving a specific optimisation problem many encounter in real-life: how to save food in your fridge/freezer during a blackout.

The idea is to move items between the fridge and the freezer in an optimal way as the temperature drops. It seems like some sort of dual-Knapsack Problem.

One strategy is to move low-value items from the freezer to the fridge, to preserve high-value items in the fridge. (So as your frozen peas thaw in the fridge, they keep your salmon cold for longer.) Later, once the freezer is above freezing and all is lost, it makes sense to move high-value items from the fridge into the freezer.

How could I set up a combinatorial optimisation problem to solve this?

I'm thinking at the start, there are two sets of items, each with a value and a volume (known to you), in the fridge and freezer, respectively.. The fridge and freezer have different total volumes and temperatures. Temperature drops in a predictable way for both. Frozen food is lost when it exceeds zero. Fridge food is lost when it exceeds, say, ten degrees C. Hence, the fridge and freezer are two time-varying knapsacks, right? Your decision space at each time T is to move an item from one to the other. So maybe it's like a dynamic program?

Two variants:

  1. You do know when the power will come back on. How does that change the model?
  2. If you want to move an item, you have to open both the doors, which costs (a known) extra temperature increase on each.

Thoughts?

4 Upvotes

6 comments sorted by

View all comments

Show parent comment

0

u/ghjm MSCS, CS Pro (20+) Dec 07 '24

Right, and the issue is simply that you're wrong about this being a knapsack problem variant. The manner in which the temperatures of objects change is dependent on their temperature differences with other interacting objects. You can't model this using only discrete math.

1

u/not-just-yeti Dec 07 '24 edited Dec 07 '24

I wouldn't say OP is "wrong" — just that they first want to see if their problem is at least as difficult as knapsack. And, to look at what sort of solutions a knapsack-only characterization would give. This seems to me like a fine first step in understanding the total problem.

I agree with you in that IRL, my strategy would crucially involve moving less-valuable freezer stuff into the fridge, to help cool the fridge. The timing of that aspect of the algorithm definitely depends on rates-of-cooling.

In either approach, I think making concrete sense of this definitely needs to specify a loss function. Start with the simplest "power is going to be out for exactly 2hrs" or "exactly k hours". Then upgrade that to some particular belief-distribution [at least two cases for these — a big storm is happening, or it's just a random outage].