Search code examples
pythonlinear-programmingpulp

Python Linear Programming Binary exclusive or choose only one group


I am trying to identify the designers with best cost to finish the complete dress.

The Conditions:

  1. Need to get complete dress

  2. Either Paul1 or Paul2 can be selected but not both even though the combination of these two could be the best cost.

Dress John Chris Paul1 Paul2
Shirt 6.33 6.62 6.37 6.52
Trouser 6.76 6.62 6.37 6.76
Jacket 6.84 6.62 6.34 6.20

Here is the result of the model from Python and Pulp:

MINIMIZE

6.84 * x_0 + 6.62 * x_1 + 6.37 * x_10 + 6.76 * x_11 + 6.34 * x_2 + 6.2 * x_3 + 6.33 * x_4 + 6.62 * x_5 + 6.37 * x_6 + 6.76 * x_7 + 6.76 * x_8 + 6.62 * x_9 + 0.0

SUBJECT TO

C1: x_0 + x_1 + x_2 + x_3 = 1

C2: x_4 + x_5 + x_6 + x_7 = 1

C3: x_10 + x_11 + x_8 + x_9 = 1

I couldn't figure it out the condition to choose either Paul1 or Paul2 but not both.

Any help would be greatly appreciated.

Note: This is continuous to the question: Linear Programming Binary Variable Grouping


Solution

  • Standard way to choose either paul1 or paul2 isn't introduce 2 binary variable indexed over y[p1] & y[p2]. Then following constraints
    y[p1]<= sum(x[p1,c] over c)<=3y[p1]
    y[p2]<= sum(x[p2,c] over c)<=3y[p2]
    y[p1] + y[p2]<= 1
    where c represents {shirt, trouser, jacket}.

    The above constraints choose either p1 or p2 for all or none of the clothing items.