简体   繁体   中英

Pyomo's SolverFactory cannot create Ipopt (OSX) - possibly related to COIN-OR

I'm trying to use Pyomo to find the optimal values of a Python model on OSX. I got the script from https://github.com/shoibalc/recem , and installed Pyomo and COIN-OR following the instructions to the extent that I could, changing a few things that were outdated or didn't seem to work on OSX.

The code that is causing problems is below.

import pyomo
from pyomo.opt.base import *
from pyomo.opt.parallel import SolverManagerFactory
from DICE2007 import createDICE2007
from DICEutils import DICE_results_writer

global start_time
start_time = time.time()

dice = createDICE2007()
dice.doc = 'OPTIMAL SCENARIO'
opt = SolverFactory('ipopt',solver_io='nl') 
tee = False
options =   """
        halt_on_ampl_error=yes"""
solver_manager = SolverManagerFactory('serial')

print '[%8.2f] create model %s OPTIMAL SCENARIO\n' %(time.time()-start_time,dice.name)

instance = dice.create()
print '[%8.2f] created instance\n' %(time.time()-start_time)

results = solver_manager.solve(instance, opt=opt, tee=tee, options=options, suffixes=['dual','rc'])

This crashes on the last ("results") line, with the following error message:

The SolverFactory was unable to create the solver "ipopt" and returned an UnknownSolver object. This error is raised at the point where the UnknownSolver object was used as if it were valid (by calling method "solve").

The original solver was created with the following parameters: solver_io: nl type: ipopt _args: () options: {} _options_str: []

I'm very new to all this, but thought that maybe Pyomo can't access the ipopt file it needs, which I think for me is located in the COIN-OR binaries I downloaded. I tried adding the relevant-seeming files to my PYTHONPATH and also importing them into the script, which didn't help. Any ideas what I should try next to either make this work, or to amend the script to something that would work?

我的一位同事遇到了同样的问题,他设法解决了这个问题,方法是生成带有IPOPT AMPL可执行文件的路由的Solver对象:

opt = SolverFactory('/route/to/ipopt',solver_io='nl')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM