Re: Displaying Shadow Prices using pulp

2,910 views
Skip to first unread message

Stuart Mitchell

unread,
Jul 4, 2012, 7:32:54 PM7/4/12
to pulp-or...@googlegroups.com
CBC now produces duals but you do have to keep hold of the constraint

for example:

from pulp import *
prob = LpProblem("test080", LpMinimize)
x = LpVariable("x", 0, 5)
y = LpVariable("y", -1, 1)
z = LpVariable("z", 0)
c1 = x+y <= 5
c2 = x+z >= 10
c3 = -y+z == 7

prob += x + 4*y + 9*z, "obj"
prob += c1, "c1"
prob += c2,"c2"
prob += c3,"c3"

prob.solve()

>>> c1.pi
0.0
>>> c2.pi
1.0
>>> c3.pi
8.0

On Wed, Jul 4, 2012 at 8:07 PM, Nigel Cleland <nigel....@gmail.com> wrote:
I'm currently trying to set up a fairly rudimentary generation dispatch problem using pulp.
I am currently able to solve the solution optimally using both the GLPK and CBC solvers.

I would however like to display the shadow prices/dual values so I can determine nodal pricing.

Any assistance would be highly appreciated

System Particulars:

Ubuntu 12.04
Python 2.7
Pulp 1.5.3
Solvers: GLPK/CBC

Thank you in advance,

Nigel

--
You received this message because you are subscribed to the Google Groups "pulp-or-discuss" group.
To view this discussion on the web visit https://groups.google.com/d/msg/pulp-or-discuss/-/ivjcz8n2FEYJ.
To post to this group, send email to pulp-or...@googlegroups.com.
To unsubscribe from this group, send email to pulp-or-discu...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/pulp-or-discuss?hl=en.



--
Stuart Mitchell
PhD Engineering Science
Extraordinary Freelance Programmer and Optimisation Guru

Nigel Cleland

unread,
Jul 10, 2012, 11:00:33 PM7/10/12
to pulp-or...@googlegroups.com
Thank you, this is perfect

To post to this group, send email to pulp-or-discuss@googlegroups.com.
To unsubscribe from this group, send email to pulp-or-discuss+unsubscribe@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/pulp-or-discuss?hl=en.
Message has been deleted

Stuart Mitchell

unread,
Jun 1, 2013, 6:57:03 PM6/1/13
to pulp-or...@googlegroups.com

Is your problem contain integer variables? If so dual values are not produced as they do not make sense after branch and bound.

On 1 Jun 2013 19:57, "Sean Whipple" <seda...@gmail.com> wrote:
I am having the same issue and found this post and found it quite useful (one difference is I'm using CPLEX to solve).  I tested this solution and it works great.  But when I run on the problem I'm having the constraints don't have a .pi attribute after the solve (unlike these).  The problem has an optimal solution but my constraints don't have duals at the end.  Is there a flag that I need to set?
To unsubscribe from this group and stop receiving emails from it, send an email to pulp-or-discu...@googlegroups.com.

To post to this group, send email to pulp-or...@googlegroups.com.

Sean Whipple

unread,
Jun 2, 2013, 4:58:23 PM6/2/13
to pulp-or...@googlegroups.com
No they it's all continuous.  And if I run from cplex command line I can see the duals in the .sol file

Sean Whipple

unread,
Jun 3, 2013, 1:48:43 PM6/3/13
to pulp-or...@googlegroups.com
Interesting follow up...when I ran the test above I did it with CPLEX 12.4...when I ran my own code it was on a machine with CPLEX 12.5.  Is it possible that it's no longer supported?  (both using the same version of PuLP)

Stuart Mitchell

unread,
Jun 3, 2013, 6:28:47 PM6/3/13
to pulp-or...@googlegroups.com

Could you please run the test on the computer with CPLEX 12.5.


Also can you post the results of

>>> import pulp

>>> pulp.pulpTestAll()

on the machine that is having problems.
Thanks



--

fatzm...@gmail.com

unread,
Jan 13, 2015, 12:11:58 PM1/13/15
to pulp-or...@googlegroups.com
Hello,

I am using pulp with cplex to solve a column generation problem and I need to use the dual variables. I try the constraint.pi but it always returns None even with the small example that has been posted on this discussion. Any idea why?
Thanks in advance

Stuart Mitchell

unread,
Jan 19, 2015, 3:31:21 PM1/19/15
to pulp-or...@googlegroups.com
Are you using the cplex command line or cplex through the python interface?

Stu

--
You received this message because you are subscribed to the Google Groups "pulp-or-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pulp-or-discu...@googlegroups.com.
To post to this group, send email to pulp-or...@googlegroups.com.

Nathan Petty

unread,
Sep 29, 2017, 10:15:15 AM9/29/17
to pulp-or-discuss
Hey Stu,  what about the variable bound constraints automatically generated when you declare a variable?  How do I get those shadow price?  For example I have a continuous variable with bounds [0,1] and I need the shadow price for those constraints.   

Am I going to have to explicitly declare those bounds as constraints?

The other option: For variable bounds in an LP, the shadow price equals the reduced cost on the variable.  So there's no need to add constraints?; just retrieve the reduced cost on the variable?

Nathan Petty

unread,
Oct 12, 2017, 10:05:57 AM10/12/17
to pulp-or-discuss
To answer my own question, I did just use explicit constraints for bounds to get shadows

Rebecca Jeffers

unread,
Jul 9, 2018, 3:48:07 AM7/9/18
to pulp-or-discuss
Hi :)

I am having this same problem using cplex with pulp on a simple problem where all the varlables are continuous. I am using the latest version of pulp with cplex 12.8

Rebecca Jeffers

unread,
Jul 9, 2018, 8:47:54 AM7/9/18
to pulp-or-discuss
It seems that it couldn't find CPLEX_CMD because I had not put the lib, bin and include paths separately in my PATH variable. CPLEX() was therefore using CPLEX_PY and this gave "None"s for the dual variables. Once I had corrected the path I used CPLEX_CMD directly and there were values for the duals

GiaLLuh

unread,
Jun 16, 2019, 6:30:10 PM6/16/19
to pulp-or-discuss
Hi Stu,
I'm having the same problem using the GUROBI_CMD solver (none output).
I know that Gurobi has its own syntax to retrieve shadow prices for constraints (.Pi attribute), but i have already written my model with the pulp syntax since it gets along well with pandas dataframes which I'm importing my input data from.
Do I have to change the variable path into the solver option like Rebecca suggested? Where? How?
Thanks

Il giorno lunedì 19 gennaio 2015 21:31:21 UTC+1, Stuart Mitchell ha scritto:
Are you using the cplex command line or cplex through the python interface?

Stu
On Wed, Jan 14, 2015 at 6:11 AM, <fatzm...@gmail.com> wrote:
Hello,

I am using pulp with cplex to solve a column generation problem and I need to use the dual variables. I try the constraint.pi but it always returns None even with the small example that has been posted on this discussion. Any idea why?
Thanks in advance

--
You received this message because you are subscribed to the Google Groups "pulp-or-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pulp-or...@googlegroups.com.

To post to this group, send email to pulp-or...@googlegroups.com.

GiaLLuh

unread,
Jun 17, 2019, 11:09:30 PM6/17/19
to pulp-or-discuss
Problem solved using the pulp.GUROBI() solver instead of pulp.GUROBI_CMD() solver. Calling the name of the constraint plus .solverConstraint plus .pi or .Pi gives the dual value.
Reply all
Reply to author
Forward
0 new messages