Reputation: 18635
I would like to obtain .rc or .urc suffixes for my variables from the cplex solver, using Pyomo with the NL / ASL interface. This interface is generally faster than the default cplex interface for my models. However I can't seem to get the NL interface to return these suffixes. If I use the cplex solver with default options, I get values for the rc suffix. However, if I use solver_io='nl' or set the solver to 'cplexamp' (which I think does the same thing), then I get no rc values. (I am able to get duals, but not rc's.)
Here's some example code:
from pyomo.environ import *
from pyomo.opt import SolverFactory
def show_rc(m, *args, **kwargs):
opt = SolverFactory(*args, **kwargs)
results = opt.solve(m, suffixes=['rc'])
m.solutions.load_from(results)
m.rc.pprint()
m = ConcreteModel()
m.X = Var(bounds=(0, 1))
m.obj = Objective(rule=lambda m: 3.14 * m.X, sense=maximize)
m.rc = Suffix(direction=Suffix.IMPORT, datatype=Suffix.FLOAT)
show_rc(m, "cplex") # has value 3.14
show_rc(m, "cplex", solver_io="nl") # no value returned
show_rc(m, "cplexamp") # no value returned
The documentation specifically mentions getting reduced costs via a suffix, and the .rc suffix seems to be the standard place for this in AMPL, but I'm having no luck reading this via Pyomo's NL interface. Can anyone point me in the right direction?
Upvotes: 0
Views: 389
Reputation: 1436
Unfortunately, the cplexamp executable does not return reduced costs in the solution file (I just checked). I suppose AMPL must be computing these using the dual solution that is returned. I would open up a ticket on GitHub. Perhaps we can add that functionality to our ASL interface.
In terms of speed, you should try out Pyomo's Python-based interface to Cplex (solver_io="python"). This is usually much faster as it does not require any file I/O. You will need to install the Cplex-Python bindings before you can use that interface through Pyomo. If you can "import cplex", then it should be good to go.
Edit: I forgot to mention that solver_io="python" does return reduced costs for Cplex.
Upvotes: 1