Esempio n. 1
0
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
Esempio n. 2
0
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
Esempio n. 3
0
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
Esempio n. 4
0
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
Esempio n. 5
0
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
Esempio n. 6
0
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
Esempio n. 7
0
#  Pyomo: Python Optimization Modeling Objects
#  Copyright (c) 2014 Sandia Corporation.
#  Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
#  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', {})