2

I am trying to solve an Integer Programming question (trying to come up with a model). The question goes like this: There are 5 pens a person has. He wants to have all 5 of them at the same time. And he has 10 different weighted bags. He wants to cary minimum weight as he can while having all five of the pens. Different bags carry different pens, the distribution is like this: enter image description here

The weights of the bags are like this: bag 1 --> 4 bag 2 --> 6 bag 3 --> 4 bag 4 --> 2 bag 5 --> 3 bag 6 --> 2 bag 7 --> 4 bag 8 --> 3 bag 9 --> 6 bag 10 --> 3

What I thought is this: Let xi = 1 be that he brings the ith bag and xi = 0 be that he does not bring the ith bag. Then the obj. function is the minimum of sum of all of the x variables multiplied with their weight. And I could think of only one constraint: The sum of all the x variables i = 1..10 should be at most 10 and at least 3.

I could not think of anything else. Dont even know if this is the right path to the solution.

2 Answers2

1

Each bag contains just two pens or one pen, and given that you must have at least $5$ (different) pens, you must have at minimum of $3$ bags. For minimum weight, two bags must each contain $2$ pens and the final bag can contain $1$ pen (if possible).

This is quite easy to achieve.

  • Pick any bag you like containing two pens but not pen 3 (call it bag A).
  • Pick another bag that contains the two pens not in bag A and not pen 3. (Call it bag B.)
  • Pick another bag that contains the only missing pen. (Call it bag C.)

I easily found: $\{ 1,6,5 \}$.

But try others!

  • okay, let's say I found all of them manually. But don't I need to specify a constraint with variables to create a model? – codertryer Nov 01 '20 at 10:24
1

This is a weighted set cover problem. Let $a_{b,p}$ indicate whether bag $b$ contains pen $p$. You want to minimize $\sum_b w_b x_b$ subject to \begin{align} \sum_b a_{b,p} x_b &\ge 1 &&\text{for all $p$}\\ x_b &\in \{0,1\} &&\text{for all $b$} \end{align} For your instance, you want to minimize $$4x_1 + 6x_2 + 4x_3 + 2x_4 + 3x_5 + 2x_6 + 4x_7 + 3x_8 + 6x_9 + 3x_{10}$$ subject to \begin{align} x_1 + x_4 + x_7 &\ge 1 \\ x_2 + x_4 + x_6 + x_9 &\ge 1 \\ x_3 + x_5 + x_8 + x_{10} &\ge 1 \\ x_1 + x_2 + x_7 + x_{10} &\ge 1 \\ x_3 + x_6 + x_9 &\ge 1 \\ x_b &\in \{0,1\} &&\text{for all $b$} \end{align} The unique optimal solution is $x=(0,0,0,1,0,1,0,0,0,1)$, with objective value $2+2+3=7$. For a short certificate of optimality, use the optimal linear programming dual variables $(2, 0, 2, 1, 2)$ for the five constraints and $(1, 5, 0, 0, 1, 0, 1, 1, 4, 0)$ for the lower bounds $x_b \ge 0$.

RobPratt
  • 45,619
  • But didn't we forget about the different weigths of the bags? – codertryer Nov 01 '20 at 10:13
  • And can you explain the summation of "a_b,p*x_b from b = 1 to 10 for all p"?. Like does for al p means ther is actually another summation inside that goes from p = 1 to 5? – codertryer Nov 01 '20 at 10:46
  • The bag weight is already there in the objective function, which I rewrote just now to make more explicit. The “for all $p$” means a separate constraint for each pen. – RobPratt Nov 01 '20 at 13:19
  • Maybe it is because I didnot write it explictly, but each bag has a different weight unrelated to the number of pens it carries. Like bag1 has weight w1, bag 2 has w2, etc.. In the question these weigths are given with numbers but I didnt find it necessary to write every different weight. Because they'll be used in the obj. func. by getting multiplied with x's – codertryer Nov 01 '20 at 13:32
  • Ok then just change the objective function to $\sum_b w_b x_b$. – RobPratt Nov 01 '20 at 13:56
  • Okay I am so sorry I am confused :( This was the obj. func. I was offering in the question, wasn't it? I was asking what to write for constraints – codertryer Nov 01 '20 at 14:06
  • If you provide the weights, I’ll update my answer to clarify. – RobPratt Nov 01 '20 at 14:33
  • Hi, could you have the chance to look? – codertryer Nov 02 '20 at 20:32
  • @codertryer I updated my answer yesterday. – RobPratt Nov 02 '20 at 20:34
  • Oh I didn't realize. Thank you :) – codertryer Nov 02 '20 at 20:38