0

I am comparing the values for shadow price (pi) calculated with gurobi and pulp. I get different values for the same input and I am not sure how to do it with pulp. Here is the lp file that I use:

Minimize
  x[0] + x[1] + x[2] + x[3]
Subject To
  C[0]: 7 x[0] >= 211
  C[1]: 3 x[1] >= 395
  C[2]: 2 x[2] >= 610
  C[3]: 2 x[3] >= 97
Bounds
End 

For the above lp file, gurobi gives me shadow prices:

[0.14285714285714285, 0.3333333333333333, 0.5, 0.5]

and with pulp I get:

[0.14285714, 0.33333333, 0.5, 0.5]

But If I execute the following lp model:

Minimize
  x[0] + x[1] + x[2] + x[3] + x[4]
Subject To
 C[0]: 7 x[0] + 2 x[4] >= 211
 C[1]: 3 x[1] >= 395
 C[2]: 2 x[2] + 2 x[4] >= 610
 C[3]: 2 x[3] >= 97
Bounds
End

With gurobi I get:

[0.0, 0.3333333333333333, 0.5, 0.5]

and with pulp I get:

[0.14285714, 0.33333333, 0.5, 0.5]

The correct value is the one that gurobi returns (I think ?).

Why I get the same shadow prices with pulp for different models ? How I can get the same results as gurobi ?

(I did not supply the source code because the question will be too long, I think the lp models are enough)

darpet
  • 3,073
  • 3
  • 33
  • 40

1 Answers1

0

In the second example, there are two dual solutions that are optimal: the one PuLP gives you, and the one you get by calling Gurobi directly. The unique optimal primal solution is [0.0, 131.67, 199.5, 48.5, 105.5], which makes the slacks for all the constraints are 0 in the optimal primal solution. For c[0] if you reduce the right hand side, you get no reduction in the objective, but if you increase it, the cheapest way to make the constraint feasible is by increasing x[0]. Gurobi only guarantees that you will produce an optimal primal and dual solution. The specific optimal solution you get is arbitrary.

The first example is just a precision issue.

David Nehme
  • 21,379
  • 8
  • 78
  • 117
  • Is there a way, for the second solution, to get the same result from PuLP as from Gurobi. I need to get [0.0, 0.33, 0.5, 0.5] from PuLP (the precision issue can be ignored) ? – darpet Jun 30 '14 at 07:36
  • The only way to guarantee the same solutions is to send the exact same model to the solver, which you can't do when you use two totally separate modeling systems. – Greg Glockner Jul 06 '14 at 12:45