def initialize(**kwds): obj = Options(**kwds) # # Set obj.available # opt = None try: opt = SolverFactory(obj.name, solver_io=obj.io) except: pass if opt is None or isinstance(opt, UnknownSolver): obj.available = False elif (obj.name == "gurobi") and (not GUROBISHELL.license_is_valid()): obj.available = False elif (obj.name == "baron") and (not BARONSHELL.license_is_valid()): obj.available = False else: obj.available = (opt.available(exception_flag=False)) and ( (not hasattr(opt, "executable")) or (opt.executable() is not None) ) # # Check capabilities # if obj.available: for _c in obj.capabilities: if not _c in opt._capabilities: raise ValueError("Solver %s does not support capability %s!" % (obj.name, _c)) # # Get version # obj.version = opt.version() return obj
def check_available_solvers(*args): from pyomo.solvers.plugins.solvers.GUROBI import GUROBISHELL from pyomo.solvers.plugins.solvers.BARON import BARONSHELL logging.disable(logging.WARNING) ans = [] for arg in args: if not isinstance(arg, tuple): name = arg arg = (arg, ) else: name = arg[0] opt = SolverFactory(*arg) if opt is None or isinstance(opt, UnknownSolver): available = False elif (arg[0] == "gurobi") and \ (not GUROBISHELL.license_is_valid()): available = False elif (arg[0] == "baron") and \ (not BARONSHELL.license_is_valid()): available = False else: available = \ (opt.available(exception_flag=False)) and \ ((not hasattr(opt,'executable')) or \ (opt.executable() is not None)) if available: ans.append(name) logging.disable(logging.NOTSET) return ans
def initialize(**kwds): obj = Options(**kwds) # # Set obj.available # opt = None try: opt = SolverFactory(obj.name, solver_io=obj.io) except: pass if opt is None or isinstance(opt, UnknownSolver): obj.available = False elif (obj.name == "gurobi") and \ (not GUROBISHELL.license_is_valid()): obj.available = False elif (obj.name == "baron") and \ (not BARONSHELL.license_is_valid()): obj.available = False else: obj.available = \ (opt.available(exception_flag=False)) and \ ((not hasattr(opt,'executable')) or \ (opt.executable() is not None)) # # Check capabilities # if obj.available: for _c in obj.capabilities: if not _c in opt._capabilities: raise ValueError("Solver %s does not support capability %s!" % (obj.name, _c)) # # Get version # obj.version = opt.version() return obj
def check_available_solvers(*args): from pyomo.solvers.plugins.solvers.GUROBI import GUROBISHELL from pyomo.solvers.plugins.solvers.BARON import BARONSHELL logging.disable(logging.WARNING) ans = [] for arg in args: if not isinstance(arg,tuple): name = arg arg = (arg,) else: name = arg[0] opt = SolverFactory(*arg) if opt is None or isinstance(opt, UnknownSolver): available = False elif (arg[0] == "gurobi") and \ (not GUROBISHELL.license_is_valid()): available = False elif (arg[0] == "baron") and \ (not BARONSHELL.license_is_valid()): available = False else: available = \ (opt.available(exception_flag=False)) and \ ((not hasattr(opt,'executable')) or \ (opt.executable() is not None)) if available: ans.append(name) logging.disable(logging.NOTSET) return ans
def initialize(**kwds): obj = Options(**kwds) # # Set the limits for the solver's "demo" (unlicensed) mode: # ( nVars, nCons, nNonZeros ) obj.demo_limits = (None, None, None) if (obj.name == "baron") and \ (not BARONSHELL.license_is_valid()): obj.demo_limits = (10, 10, 50) # # # Set obj.available # opt = None try: opt = SolverFactory(obj.name, solver_io=obj.io) except: pass if opt is None or isinstance(opt, UnknownSolver): obj.available = False elif (obj.name == "gurobi") and \ (not GUROBISHELL.license_is_valid()): obj.available = False elif (obj.name == "mosek") and \ (not MosekDirect.license_is_valid()): obj.available = False else: obj.available = \ (opt.available(exception_flag=False)) and \ ((not hasattr(opt,'executable')) or \ (opt.executable() is not None)) # # Check capabilities, even if the solver is not available # if not (opt is None or isinstance(opt, UnknownSolver)): for _c in obj.capabilities: if not _c in opt._capabilities: raise ValueError("Solver %s does not support capability %s!" % (obj.name, _c)) # # Get version # if obj.available: obj.version = opt.version() return obj
def check_available_solvers(*args): from pyomo.solvers.plugins.solvers.GUROBI import GUROBISHELL from pyomo.solvers.plugins.solvers.BARON import BARONSHELL logger_solvers = logging.getLogger('pyomo.solvers') _level_solvers = logger_solvers.getEffectiveLevel() logger_solvers.setLevel(logging.ERROR) logger_opt = logging.getLogger('pyomo.opt') _level_opt = logger_opt.getEffectiveLevel() logger_opt.setLevel(logging.ERROR) ans = [] for arg in args: if not isinstance(arg, tuple): name = arg arg = (arg, ) else: name = arg[0] opt = SolverFactory(*arg) if opt is None or isinstance(opt, UnknownSolver): available = False elif (arg[0] == "gurobi") and \ (not GUROBISHELL.license_is_valid()): available = False elif (arg[0] == "baron") and \ (not BARONSHELL.license_is_valid()): available = False else: available = \ (opt.available(exception_flag=False)) and \ ((not hasattr(opt,'executable')) or \ (opt.executable() is not None)) if available: ans.append(name) logger_opt.setLevel(_level_opt) logger_solvers.setLevel(_level_solvers) return ans
# the U.S. Government retains certain rights in this software. # This software is distributed under the BSD License. # _________________________________________________________________________ import os from pyomo.opt import SolverFactory from pyomo.opt.base.solvers import UnknownSolver import pyomo.environ from six import iteritems from pyomo.solvers.plugins.solvers.GUROBI import GUROBISHELL has_gurobi_license = GUROBISHELL.license_is_valid() from pyomo.solvers.plugins.solvers.BARON import BARONSHELL has_baron_license = BARONSHELL.license_is_valid() class SolverTestCase(object): def __init__(self, name=None, io=None, **kwds): assert (name is not None) and (type(name) is str) assert (io is not None) and (type(io) is str) self.name = name self.io = io self.capabilities = kwds.pop('capabilities', []) self.export_suffixes = kwds.pop('export_suffixes', []) self.import_suffixes = kwds.pop('import_suffixes', []) self.options = kwds.pop('options', {}) self.io_options = kwds.pop('io_options', {}) assert type(self.capabilities) in [list, tuple] assert type(self.export_suffixes) in [list, tuple]