本文整理汇总了Python中pyomo.opt.SolverFactory.problem_format方法的典型用法代码示例。如果您正苦于以下问题:Python SolverFactory.problem_format方法的具体用法?Python SolverFactory.problem_format怎么用?Python SolverFactory.problem_format使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyomo.opt.SolverFactory
的用法示例。
在下文中一共展示了SolverFactory.problem_format方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: solve
# 需要导入模块: from pyomo.opt import SolverFactory [as 别名]
# 或者: from pyomo.opt.SolverFactory import problem_format [as 别名]
def solve(self,
solver,
io,
io_options,
solver_options,
symbolic_labels,
load_solutions):
""" Optimize the model """
assert self.model is not None
opt = SolverFactory(solver, solver_io=io)
opt.options.update(solver_options)
if io == 'nl':
assert opt.problem_format() == ProblemFormat.nl
elif io == 'lp':
assert opt.problem_format() == ProblemFormat.cpxlp
elif io == 'mps':
assert opt.problem_format() == ProblemFormat.mps
#elif io == 'python':
# print opt.problem_format()
# assert opt.problem_format() is None
try:
if isinstance(opt, PersistentSolver):
opt.set_instance(self.model, symbolic_solver_labels=symbolic_labels)
if opt.warm_start_capable():
results = opt.solve(warmstart=True,
load_solutions=load_solutions,
**io_options)
else:
results = opt.solve(load_solutions=load_solutions,
**io_options)
else:
if opt.warm_start_capable():
results = opt.solve(
self.model,
symbolic_solver_labels=symbolic_labels,
warmstart=True,
load_solutions=load_solutions,
**io_options)
else:
results = opt.solve(
self.model,
symbolic_solver_labels=symbolic_labels,
load_solutions=load_solutions,
**io_options)
return opt, results
finally:
pass
#opt.deactivate()
del opt
return None, None
示例2: ExtensiveFormAlgorithm
# 需要导入模块: from pyomo.opt import SolverFactory [as 别名]
# 或者: from pyomo.opt.SolverFactory import problem_format [as 别名]
#.........这里部分代码省略.........
generate_weighted_cvar = True
cvar_weight = self.get_option("cvar_weight")
risk_alpha = self.get_option("risk_alpha")
self.instance = create_ef_instance(
self._manager.scenario_tree,
verbose_output=self.get_option("verbose"),
generate_weighted_cvar=generate_weighted_cvar,
cvar_weight=cvar_weight,
risk_alpha=risk_alpha,
cc_indicator_var_name=self.get_option("cc_indicator_var"),
cc_alpha=self.get_option("cc_alpha"))
if self.get_option("verbose") or self.get_option("output_times"):
print("Time to construct extensive form instance=%.2f seconds"
%(time.time() - start_time))
def destroy_ef(self):
if self.instance is not None:
for scenario in self._manager.scenario_tree.scenarios:
self.instance.del_component(scenario.name)
scenario._instance_objective.activate()
self.instance = None
def write(self, filename):
if self.instance is None:
raise RuntimeError(
"The extensive form instance has not been constructed."
"Call the build_ef() method to construct it.")
suf = os.path.splitext(filename)[1]
if suf not in ['.nl','.lp','.mps']:
if self._solver.problem_format() == ProblemFormat.cpxlp:
filename += '.lp'
elif self._solver.problem_format() == ProblemFormat.nl:
filename += '.nl'
elif self._solver.problem_format() == ProblemFormat.mps:
filename += '.mps'
else:
raise ValueError("Could not determine output file format. "
"No recognized ending suffix was provided "
"and no format was indicated was by the "
"--solver-io option.")
start_time = time.time()
print("Writing extensive form to file="+filename)
smap_id = write_ef(self.instance,
filename,
self.get_option("symbolic_solver_labels"))
if self.get_option("verbose") or self.get_option("output_times"):
print("Time to write output file=%.2f seconds"
% (time.time() - start_time))
return filename, smap_id
def solve(self,
check_status=True,
exception_on_failure=True,
output_solver_log=False,
symbolic_solver_labels=False,
keep_solver_files=False,
io_options=None):
# TODO: Does this import need to be delayed because
# it is in a plugins subdirectory
示例3: ExtensiveFormAlgorithm
# 需要导入模块: from pyomo.opt import SolverFactory [as 别名]
# 或者: from pyomo.opt.SolverFactory import problem_format [as 别名]
#.........这里部分代码省略.........
generate_weighted_cvar = True
cvar_weight = self.get_option("cvar_weight")
risk_alpha = self.get_option("risk_alpha")
self.instance = create_ef_instance(
self._manager.scenario_tree,
verbose_output=self.get_option("verbose"),
generate_weighted_cvar=generate_weighted_cvar,
cvar_weight=cvar_weight,
risk_alpha=risk_alpha,
cc_indicator_var_name=self.get_option("cc_indicator_var"),
cc_alpha=self.get_option("cc_alpha"))
if self.get_option("verbose") or self.get_option("output_times"):
print("Time to construct extensive form instance=%.2f seconds"
%(time.time() - start_time))
def destroy_ef(self):
if self.instance is not None:
for scenario in self._manager.scenario_tree.scenarios:
self.instance.del_component(scenario.name)
scenario._instance_objective.activate()
self.instance = None
def write(self, filename):
if self.instance is None:
raise RuntimeError(
"The extensive form instance has not been constructed."
"Call the build_ef() method to construct it.")
suf = os.path.splitext(filename)[1]
if suf not in ['.nl','.lp','.mps']:
if self._solver.problem_format() == ProblemFormat.cpxlp:
filename += '.lp'
elif self._solver.problem_format() == ProblemFormat.nl:
filename += '.nl'
elif self._solver.problem_format() == ProblemFormat.mps:
filename += '.mps'
else:
raise ValueError("Could not determine output file format. "
"No recognized ending suffix was provided "
"and no format was indicated was by the "
"--solver-io option.")
start_time = time.time()
if self.get_option("verbose"):
print("Starting to write extensive form")
smap_id = write_ef(self.instance,
filename,
self.get_option("symbolic_solver_labels"))
print("Extensive form written to file="+filename)
if self.get_option("verbose") or self.get_option("output_times"):
print("Time to write output file=%.2f seconds"
% (time.time() - start_time))
return filename, smap_id
def solve(self,
check_status=True,
exception_on_failure=True,
io_options=None):
if self.instance is None: