本文整理汇总了Python中pyomo.environ.ConcreteModel.o方法的典型用法代码示例。如果您正苦于以下问题:Python ConcreteModel.o方法的具体用法?Python ConcreteModel.o怎么用?Python ConcreteModel.o使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyomo.environ.ConcreteModel
的用法示例。
在下文中一共展示了ConcreteModel.o方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_GDP_nonlinear_objective
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import o [as 别名]
def test_GDP_nonlinear_objective(self):
m = ConcreteModel()
m.x = Var(bounds=(-1, 10))
m.y = Var(bounds=(2, 3))
m.d = Disjunction(expr=[
[m.x + m.y >= 5], [m.x - m.y <= 3]
])
m.o = Objective(expr=m.x ** 2)
SolverFactory('gdpopt').solve(
m, strategy='LOA',
mip_solver=mip_solver,
nlp_solver=nlp_solver
)
self.assertAlmostEqual(value(m.o), 0)
m = ConcreteModel()
m.x = Var(bounds=(-1, 10))
m.y = Var(bounds=(2, 3))
m.d = Disjunction(expr=[
[m.x + m.y >= 5], [m.x - m.y <= 3]
])
m.o = Objective(expr=-m.x ** 2, sense=maximize)
SolverFactory('gdpopt').solve(
m, strategy='LOA',
mip_solver=mip_solver,
nlp_solver=nlp_solver
)
self.assertAlmostEqual(value(m.o), 0)
示例2: test_multiple_obj
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import o [as 别名]
def test_multiple_obj(self):
m = ConcreteModel()
m.x = Var()
m.o = Objective(expr=m.x)
m.o2 = Objective(expr=m.x)
with self.assertRaisesRegexp(RuntimeError, "multiple active objectives"):
SolverFactory('multistart').solve(m)
示例3: test_multiple_objectives
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import o [as 别名]
def test_multiple_objectives(self):
m = ConcreteModel()
m.x = Var()
m.o = Objective(expr=m.x)
m.o2 = Objective(expr=m.x + 1)
with self.assertRaisesRegexp(ValueError, "Model has multiple active objectives"):
SolverFactory('gdpopt').solve(m)
示例4: test_simple_unsat_model
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import o [as 别名]
def test_simple_unsat_model(self):
m = ConcreteModel()
m.x = Var()
m.c1 = Constraint(expr=1 == m.x)
m.c2 = Constraint(expr=2 == m.x)
m.o = Objective(expr=m.x)
self.assertFalse(satisfiable(m))
示例5: test_binary_expressions
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import o [as 别名]
def test_binary_expressions(self):
m = ConcreteModel()
m.x = Var()
m.y = Var()
m.z = Var()
m.c = Constraint(expr=0 <= m.x + m.y - m.z * m.y / m.x + 7)
m.o = Objective(expr=m.x)
self.assertTrue(satisfiable(m))
示例6: test_solver_arg
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import o [as 别名]
def test_solver_arg(self):
m = ConcreteModel()
m.x = Var()
m.c = Constraint(expr=m.x == 2)
m.o = Objective(expr=m.x)
os = StringIO()
m.write(os, format="gams", io_options=dict(solver="gurobi"))
self.assertIn("option lp=gurobi", os.getvalue())
示例7: test_inactive_constraints
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import o [as 别名]
def test_inactive_constraints(self):
m = ConcreteModel()
m.x = Var()
m.c1 = Constraint(expr=m.x == 1)
m.c2 = Constraint(expr=m.x == 2)
m.o = Objective(expr=m.x)
self.assertFalse(satisfiable(m))
m.c2.deactivate()
self.assertTrue(satisfiable(m))
示例8: test_tuple_constraint_create
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import o [as 别名]
def test_tuple_constraint_create(self):
def rule1(model):
return (0.0,model.x)
model = ConcreteModel()
model.x = Var()
model.y = Var()
model.z = Var()
model.o = Constraint(rule=rule1)
#
def rule1(model):
return (model.y,model.x,model.z)
model = AbstractModel()
model.x = Var()
model.y = Var()
model.z = Var()
model.o = Constraint(rule=rule1)
self.assertRaises(ValueError, model.create_instance)
示例9: test_solve_constant_obj
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import o [as 别名]
def test_solve_constant_obj(self):
m = ConcreteModel()
m.x = Var(bounds=(-5, 5))
m.c = Constraint(expr=m.x >= 1)
m.o = Objective(expr=1)
output = StringIO()
with LoggingIntercept(output, 'pyomo.contrib.gdpopt', logging.INFO):
SolverFactory('gdpopt').solve(m, mip_solver=mip_solver)
self.assertIn("Your model is an LP (linear program).",
output.getvalue().strip())
self.assertAlmostEqual(value(m.o.expr), 1)
示例10: test_model_infeasible
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import o [as 别名]
def test_model_infeasible(self):
m = ConcreteModel()
m.x = Var(bounds=(0, 1))
m.c = Constraint(expr=m.x >= 2)
m.o = Objective(expr=m.x)
SolverFactory('multistart').solve(m, iterations=2)
output = StringIO()
with LoggingIntercept(output, 'pyomo.contrib.multistart', logging.WARNING):
SolverFactory('multistart').solve(
m, iterations=-1, HCS_max_iterations=3)
self.assertIn("High confidence stopping rule was unable to "
"complete after 3 iterations.",
output.getvalue().strip())
示例11: test_infeasible_GDP
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import o [as 别名]
def test_infeasible_GDP(self):
"""Test for infeasible GDP."""
m = ConcreteModel()
m.x = Var(bounds=(0, 2))
m.d = Disjunction(expr=[
[m.x ** 2 >= 3, m.x >= 3],
[m.x ** 2 <= -1, m.x <= -1]])
m.o = Objective(expr=m.x)
result = SolverFactory('gdpbb').solve(
m, tee=False,
solver=minlp_solver,
solver_args=minlp_args,
)
self.assertEqual(result.solver.termination_condition, TerminationCondition.infeasible)
示例12: test_rule
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import o [as 别名]
def test_rule(self):
def rule1(model):
return Constraint.Skip
model = ConcreteModel()
try:
model.o = Constraint(rule=rule1)
except Exception:
e = sys.exc_info()[1]
self.fail("Failure to create empty constraint: %s" % str(e))
#
def rule1(model):
return (0.0,model.x,2.0)
model = ConcreteModel()
model.x = Var(initialize=1.1)
model.o = Constraint(rule=rule1)
self.assertEqual(model.o(),1.1)
#
def rule1(model, i):
return Constraint.Skip
model = ConcreteModel()
model.a = Set(initialize=[1,2,3])
try:
model.o = Constraint(model.a,rule=rule1)
except Exception:
self.fail("Error generating empty constraint")
#
def rule1(model):
return (0.0,1.1,2.0,None)
model = ConcreteModel()
try:
model.o = Constraint(rule=rule1)
self.fail("Can only return tuples of length 2 or 3")
except ValueError:
pass
示例13: test_gams_connector_in_active_constraint
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import o [as 别名]
def test_gams_connector_in_active_constraint(self):
m = ConcreteModel()
m.b1 = Block()
m.b2 = Block()
m.b1.x = Var()
m.b2.x = Var()
m.b1.c = Connector()
m.b1.c.add(m.b1.x)
m.b2.c = Connector()
m.b2.c.add(m.b2.x)
m.c = Constraint(expr=m.b1.c == m.b2.c)
m.o = Objective(expr=m.b1.x)
os = StringIO()
with self.assertRaises(RuntimeError):
m.write(os, format="gams")
示例14: test_gams_expanded_connectors
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import o [as 别名]
def test_gams_expanded_connectors(self):
m = ConcreteModel()
m.x = Var()
m.y = Var()
m.CON1 = Connector()
m.CON1.add(m.x, 'v')
m.CON2 = Connector()
m.CON2.add(m.y, 'v')
m.c = Constraint(expr=m.CON1 + m.CON2 >= 10)
TransformationFactory("core.expand_connectors").apply_to(m)
m.o = Objective(expr=m.x)
os = StringIO()
io_options = dict(symbolic_solver_labels=True)
m.write(os, format="gams", io_options=io_options)
# no error if we're here, but check for some identifying string
self.assertIn("x + y", os.getvalue())
示例15: test_var_update
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import o [as 别名]
def test_var_update(self):
m = ConcreteModel()
m.x = Var()
m.y = Var(bounds=(0, 1))
m.c = Constraint(expr=m.x == m.y)
m.o = Objective(expr=m.x)
TransformationFactory('contrib.aggregate_vars').apply_to(m)
SolverFactory('glpk').solve(m)
z = m._var_aggregator_info.z
self.assertEqual(z[1].value, 0)
self.assertEqual(m.x.value, None)
self.assertEqual(m.y.value, None)
TransformationFactory('contrib.aggregate_vars').update_variables(m)
self.assertEqual(z[1].value, 0)
self.assertEqual(m.x.value, 0)
self.assertEqual(m.y.value, 0)