当前位置: 首页>>代码示例>>Python>>正文


Python Options.solver方法代码示例

本文整理汇总了Python中pyutilib.misc.Options.solver方法的典型用法代码示例。如果您正苦于以下问题:Python Options.solver方法的具体用法?Python Options.solver怎么用?Python Options.solver使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyutilib.misc.Options的用法示例。


在下文中一共展示了Options.solver方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: setUp

# 需要导入模块: from pyutilib.misc import Options [as 别名]
# 或者: from pyutilib.misc.Options import solver [as 别名]
 def setUp(self, testcase, options):
     global tmpdir
     tmpdir = os.getcwd()
     os.chdir(options.currdir)
     pyutilib.services.TempfileManager.push()
     pyutilib.services.TempfileManager.sequential_files(0)
     pyutilib.services.TempfileManager.tempdir = options.currdir
     #
     if ':' in options.solver:
         solver, sub_solver = options.solver.split(':')
         if options.solver_options is None:
             _options = Options()
         else:
             _options = options.solver_options
         _options.solver = sub_solver
         testcase.opt = pyomo.opt.SolverFactory(solver, options=_options)
     else:
         testcase.opt = pyomo.opt.SolverFactory(options.solver, options=options.solver_options)
     if testcase.opt is None or not testcase.opt.available(False):
         testcase.skipTest('Solver %s is not available' % options.solver)
开发者ID:Pyomo,项目名称:pyomo,代码行数:22,代码来源:mip.py

示例2: Options

# 需要导入模块: from pyutilib.misc import Options [as 别名]
# 或者: from pyutilib.misc.Options import solver [as 别名]
# Mimic the pyomo script
from pyomo.environ import *
from pyutilib.misc import Options

# set high level options that mimic pyomo comand line
options = Options()
options.model_file = 'DiseaseEstimation.py'
options.data_files = ['DiseaseEstimation.dat']
options.solver = 'ipopt'
options.solver_io = 'nl'
#options.keepfiles = True
#options.tee = True

# mimic the set of function calls done by pyomo command line
scripting.util.setup_environment(options)

# the following imports the model found in options.model_file,
# sets this to options.usermodel, and executes preprocessors
scripting.util.apply_preprocessing(options, parser=None)

# create the wrapper for the model, the data, the instance, and the options
model_data = scripting.util.create_model(options)
instance = model_data.instance

# solve
results, opt = scripting.util.apply_optimizer(options, instance)

# the following simply outputs the final time elapsed
scripting.util.finalize(options)

# load results into instance and print
开发者ID:Pyomo,项目名称:pyomo,代码行数:33,代码来源:scripts_mimicPyomo.py

示例3: create_sudoku_model

# 需要导入模块: from pyutilib.misc import Options [as 别名]
# 或者: from pyutilib.misc.Options import solver [as 别名]
         (6,1,7),(6,5,2),(6,9,6),
         (7,2,6),(7,7,2),(7,8,8),
         (8,4,4),(8,5,1),(8,6,9),(8,9,5),
         (9,5,8),(9,8,7),(9,9,9)]

# create the empty list of cuts to start
cut_on = []
cut_off = []

done = False
while not done:
    model = create_sudoku_model(cut_on, cut_off, board)
    instance = model.create()
    
    options = Options()
    options.solver = 'glpk'
    options.quiet = True
    #options.tee = True

    results, opt = scripting.util.apply_optimizer(options, instance)
    instance.load(results)

    if str(results.Solution.Status) != 'optimal':
        break

    # add cuts
    new_cut_on = []
    new_cut_off = []
    for r in instance.ROWS:
        for c in instance.COLS:
            for v in instance.VALUES:
开发者ID:santiavenda2,项目名称:sudoku,代码行数:33,代码来源:sudoku_run.py

示例4: Objective

# 需要导入模块: from pyutilib.misc import Options [as 别名]
# 或者: from pyutilib.misc.Options import solver [as 别名]
# Objective
#model.obj = Objective(expr = math.sqrt(((model.p - model.x)**2) + ((model.q - model.y)**2)))
model.obj = Objective(expr = (((model.p - model.x)**2) + ((model.q - model.y)**2))**0.5)

# Constraints
model.KeineAhnung = Constraint(expr = ((model.x / model.length)**2) + ((model.y / model.width)**2) - 1 >= 0)

model.pprint()

model.skip_canonical_repn = True # for nonlinear models

instance=model.create()

SolverName = "asl"
so = Options()
so.solver = "ipopt"
opt=SolverFactory(SolverName, options=so)

if opt is None:
    print("Could not construct solver %s : %s" % (SolverName, so.solver))
    sys.exit(1)

results=opt.solve(instance)
results.write()
instance.load(results) # put results in model

# because we know there is a variable named x
x_var = getattr(instance, "x")
x_val = x_var()

print("x was "+str(x_val))
开发者ID:Pyomo,项目名称:pyomo,代码行数:33,代码来源:alltogether.py

示例5: create_test_suite

# 需要导入模块: from pyutilib.misc import Options [as 别名]
# 或者: from pyutilib.misc.Options import solver [as 别名]
def create_test_suite(suite, config, _globals, options):
    #
    # Skip suite creation if the options categores do not intersect with the list of test suite categories
    #
    if len(options.categories) > 0:
        flag = False
        for cat in options.categories:
            if cat in config['suites'][suite].get('categories',[]):
                flag = True
                break
        if not flag:
            return
    #
    # Create test driver
    #
    if suite in _globals:
        raise IOError("Cannot create suite '%s' since there is another symbol with that name in the global namespace!" % suite)
    def setUpClassFn(cls):
        options = cls._options[None]
        cls._test_driver.setUpClass(cls,options)
    _globals[suite] = type(str(suite),(unittest.TestCase,),{'setUpClass': classmethod(setUpClassFn)})
    _globals[suite]._options[None] = options
    setattr(_globals[suite],'_test_driver', _globals['test_driver'])
    setattr(_globals[suite],'suite_categories', config['suites'][suite].get('categories',[]))
    #
    # Create test functions
    #
    tests = []
    if 'tests' in config['suites'][suite]:
        for item in config['suites'][suite]['tests']:
            tests.append( (item['solver'], item['problem'], item) )
    else:
        for solver in config['suites'][suite]['solvers']:
            for problem in config['suites'][suite]['problems']:
                tests.append( (solver, problem, {}) )
    #
    for solver, problem, item in tests:
        ##sname = solver
        if options.testname_format is None:
            test_name = solver+"_"+problem
        else:
            test_name = options.testname_format % (solver, problem)
        #
        def fn(testcase, name, suite):
            options = testcase._options[suite,name]
            fn.test_driver.setUp(testcase, options)
            ans = fn.test_driver.run_test(testcase, name, options)
            fn.test_driver.tearDown(testcase, options)
            return ans
        fn.test_driver = _globals['test_driver']
        #
        _options = Options()
        #
        problem_options = config['suites'][suite]['problems'][problem]
        if not problem_options is None and 'problem' in problem_options:
            _problem = problem_options['problem']
        else:
            _problem = problem
        for attr,value in config['problems'].get(_problem,{}).items():
            _options[attr] = _str(value)
        if not problem_options is None:
            for attr,value in problem_options.items():
                _options[attr] = _str(value)
        #
        solver_options = config['suites'][suite]['solvers'][solver]
        if not solver_options is None and 'solver' in solver_options:
            _solver = solver_options['solver']
        else:
            _solver = solver
        _name = _solver
        for attr,value in config['solvers'].get(_solver,{}).items():
            _options[attr] = _str(value)
            if attr == 'name':
                _name = value
        if not solver_options is None:
            for attr,value in solver_options.items():
                _options[attr] = _str(value)
        #
        for key in item:
            if key not in ['problem','solver']:
                _options[key] = _str(item[key])
        #
        _options.solver = _str(_name)
        _options.problem = _str(_problem)
        _options.suite = _str(suite)
        _options.currdir = _str(options.currdir)
        #
        _globals[suite].add_fn_test(name=test_name, fn=fn, suite=suite, options=_options)
开发者ID:nerdoc,项目名称:pyutilib,代码行数:90,代码来源:driver.py


注:本文中的pyutilib.misc.Options.solver方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。