How to obtain the dual solution using pyomo

63 views
Skip to first unread message

Palm

unread,
Feb 22, 2011, 11:22:01 PM2/22/11
to coopr forum
Hi, any help is appreciated:)
I am trying to get the dual solution by using:


opt=SolverFactory('cplex')
opt.reset
results=opt.solve(sub_inst)


Then I printed the results as following:

print resluts:

# ==========================================================
# = Solver Results =
# ==========================================================

# ----------------------------------------------------------
# Problem Information
# ----------------------------------------------------------
Problem:
- Name: tmpzlKDia
Lower bound: 15
Upper bound: inf
Number of objectives: 1
Number of constraints: 21
Number of variables: 16
Number of nonzeros: 31
Sense: minimize

# ----------------------------------------------------------
# Solver Information
# ----------------------------------------------------------
Solver:
- Status: ok
User time: 0.0
Termination condition: optimal
Termination message: Dual simplex - Optimal\x3a Objective =
1.5000000000e+01
Error rc: 0

# ----------------------------------------------------------
# Solution Information
# ----------------------------------------------------------
Solution:
- number of solutions: 1
number of solutions displayed: 1
- Gap: 0.0
Status: optimal
Objective:
f:
Id: 0
Value: 15
Variable:
x[C,1]:
Id: 10
Value: 1
x[C,2]:
Id: 11
Value: 1
x[C,3]:
Id: 12
Value: 1
x[C,4]:
Id: 13
Value: 1
x[C,5]:
Id: 14
Value: 1


Nothing about dual variables showed up. I guess cplex will provide
information about dual variables. So how can I obtain that information
using pyomo? Thanks!

David Woodruff

unread,
Feb 27, 2011, 12:32:06 PM2/27/11
to coopr...@googlegroups.com
Try results.write(); this should show the constraints and their duals
as well. Let me know if that does not work for you.
Best,
Dave

Yifan Liu

unread,
Feb 27, 2011, 2:48:17 PM2/27/11
to coopr...@googlegroups.com
Hi, Dave:
             results.write() is not working neither. Is there a detailed documentation of the usage of the SolverFactory(). For example: how to force the cplex use MILP or LP solver. How to get extreme directions of the feasible region... It is really hard for me to figure out how to use a method reading through tutorial papers
            Thanks!!!
--
Yifan Liu               
PhD in Operations Research
Department of Integrated Systems Engineering
The Ohio State University

Watson, Jean-paul

unread,
Feb 27, 2011, 3:08:13 PM2/27/11
to coopr...@googlegroups.com
I'll take a look at this later today – I don't have the correct solvers on my laptop at the moment…

jpw

Watson, Jean-paul

unread,
Feb 27, 2011, 7:35:09 PM2/27/11
to coopr...@googlegroups.com
Give this a try – add a "suffixes" keyword argument to the solve call. For example, as follows:

results=opt.solve(sub_inst, suffixes=['dual','rc'])

We changed this a while back – now that I recall it – due to the cost of extracting and loading the various suffixes. Which most of the time aren't needed.

I need to go back to the Benders example and see if we propagated things correctly there…

jpw

From: Yifan Liu <imliu...@gmail.com>
Reply-To: "coopr...@googlegroups.com" <coopr...@googlegroups.com>
Date: Sun, 27 Feb 2011 12:48:17 -0700
To: "coopr...@googlegroups.com" <coopr...@googlegroups.com>
Subject: Re: How to obtain the dual solution using pyomo

Watson, Jean-paul

unread,
Feb 27, 2011, 7:49:55 PM2/27/11
to coopr...@googlegroups.com
A quick follow-up – you can extract suffixes via the pyomo script as well, using the following keyword argument:

--solver-suffixes=[rc,dual]

jpw

From: Yifan Liu <imliu...@gmail.com>
Reply-To: "coopr...@googlegroups.com" <coopr...@googlegroups.com>
Date: Sun, 27 Feb 2011 12:48:17 -0700
To: "coopr...@googlegroups.com" <coopr...@googlegroups.com>
Subject: Re: How to obtain the dual solution using pyomo

Yifan Liu

unread,
Mar 3, 2011, 10:11:44 PM3/3/11
to coopr...@googlegroups.com
Thanks a lot Watson! It works. And can I ask another two quick questions?

I was trying to run the 'runbenders' python script. A lot of errors showed up:
1.How to get dual variables when I apply solve_all_instances(). Since I checked the source code of coopr.opt.parrel: solve_all_instances(solver_manager, solver, sub_insts, suffixes=['rc''dual']).Suffixes could not be accepted by the function. So inst.Time[t].dual  will not work.
2. If the sub-problem is infeasible, the algorithm stops. If the sub-problem is feasible and bounded, a cut will be added by calculating the subgradient which is the dual variables. If the dual of the subproblem is infeasible, the primal will be unbounded. So how do we get the extreme direction of the feasible region so that a new cut can be added to the master?

Thanks again Watson!

Watson, Jean-paul

unread,
Mar 5, 2011, 12:53:32 AM3/5/11
to coopr...@googlegroups.com
On the "runbenders" front, we had (stupidly) not included that script in our regression tests. Thus, it was failing due to it being incompatible with our recent upgrades. This has now been corrected – your item (1). If you are on the trunk version of Coopr (installed with --trunk), you'll be able to do an "svn update *" in "coopr/src" and pick up the changes. If you are not on the trunk, then you will see the fix when we release Coopr 2.5 (early) next week.

Regarding item (2), it sounds like you are looking for a generalized benders example? The runbenders is really just meant as an illustrative example, specific to the AMPL example that we based the translation on. Unfortunately, there is no automatic way to get the extreme directions – you'll have to do this manually based on the suffix (rc/dual) information that is available from the solver. Please let me know if I'm missing something here, as I feel like I am.

Saulo Ribeiro Silva

unread,
Jul 25, 2013, 10:56:21 AM7/25/13
to coopr...@googlegroups.com
Hi, I'm trying to retrieve information about the dual values of constraints in my problem to run the benders decomposition.

I am trying the following, like the informations I got here:

results = opt.solve(instance,suffixes=['dual'])

pi[i]=instance.Water_Balance.get_suffix_value("dual")

But it's not working, When I print the array p, the values appear as None.

I'm using glpk solver, and I'm thinking that it can be the problem. Does GLPK have support for dual variables?

Thanks
Reply all
Reply to author
Forward
0 new messages