本文整理汇总了Python中pyomo.environ.ConcreteModel.obj方法的典型用法代码示例。如果您正苦于以下问题:Python ConcreteModel.obj方法的具体用法?Python ConcreteModel.obj怎么用?Python ConcreteModel.obj使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyomo.environ.ConcreteModel
的用法示例。
在下文中一共展示了ConcreteModel.obj方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_var_on_deactivated_block
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import obj [as 别名]
def test_var_on_deactivated_block(self):
model = ConcreteModel()
model.x = Var()
model.other = Block()
model.other.a = Var()
model.other.deactivate()
model.c = Constraint(expr=model.other.a + 2 * model.x <= 0)
model.obj = Objective(expr=model.x)
self._check_baseline(model)
示例2: test_missing_bounds
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import obj [as 别名]
def test_missing_bounds(self):
m = ConcreteModel()
m.x = Var(domain=NonNegativeReals)
m.obj = Objective(expr=m.x)
output = StringIO()
with LoggingIntercept(output, 'pyomo.contrib.multistart', logging.WARNING):
SolverFactory('multistart').solve(m)
self.assertIn("Unable to reinitialize value of unbounded "
"variable x with bounds (0, None).",
output.getvalue().strip())
示例3: test_no_column_ordering_linear
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import obj [as 别名]
def test_no_column_ordering_linear(self):
model = ConcreteModel()
model.a = Var()
model.b = Var()
model.c = Var()
terms = [model.a, model.b, model.c]
model.obj = Objective(expr=self._gen_expression(terms))
model.con = Constraint(expr=self._gen_expression(terms) <= 1)
self._check_baseline(model)
示例4: test_abs
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import obj [as 别名]
def test_abs(self):
# Tests the special transformation for abs
with SolverFactory("baron") as opt:
m = ConcreteModel()
m.x = Var(bounds=(-100,1))
m.c = Constraint(expr=abs(m.x) >= 2)
m.obj = Objective(expr=m.x, sense=minimize)
results = opt.solve(m)
self.assertEqual(results.solver.termination_condition,
TerminationCondition.optimal)
示例5: test_disjunction_unsat
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import obj [as 别名]
def test_disjunction_unsat(self):
m = ConcreteModel()
m.x1 = Var(bounds=(0, 8))
m.x2 = Var(bounds=(0, 8))
m.obj = Objective(expr=m.x1 + m.x2, sense=minimize)
m.y1 = Disjunct()
m.y2 = Disjunct()
m.y1.c1 = Constraint(expr=m.x1 >= 9)
m.y1.c2 = Constraint(expr=m.x2 >= 2)
m.y2.c1 = Constraint(expr=m.x1 >= 3)
m.y2.c2 = Constraint(expr=m.x2 >= 9)
m.djn = Disjunction(expr=[m.y1, m.y2])
self.assertFalse(satisfiable(m))
示例6: test_pow
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import obj [as 别名]
def test_pow(self):
# Tests the special transformation for x ^ y (both variables)
with SolverFactory("baron") as opt:
m = ConcreteModel()
m.x = Var(bounds=(10,100))
m.y = Var(bounds=(1,10))
m.c = Constraint(expr=m.x ** m.y >= 20)
m.obj = Objective(expr=m.x, sense=minimize)
results = opt.solve(m)
self.assertEqual(results.solver.termination_condition,
TerminationCondition.optimal)
示例7: test_compute_bounds_obbt_prune_disjunct
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import obj [as 别名]
def test_compute_bounds_obbt_prune_disjunct(self):
m = ConcreteModel()
m.x = Var(bounds=(0, 1))
m.d1 = Disjunct()
m.d1.c = Constraint(expr=m.x >= 2)
m.d1.c2 = Constraint(expr=m.x <= 1)
m.d2 = Disjunct()
m.d2.c = Constraint(expr=m.x + 3 == 0)
m.disj = Disjunction(expr=[m.d1, m.d2])
m.obj = Objective(expr=m.x)
TransformationFactory('contrib.compute_disj_var_bounds').apply_to(m, solver='cbc')
self.assertFalse(m.d1.active)
self.assertEqual(m.d1.indicator_var, 0)
self.assertTrue(m.d1.indicator_var.fixed)
示例8: test_var_on_other_model
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import obj [as 别名]
def test_var_on_other_model(self):
other = ConcreteModel()
other.a = Var()
model = ConcreteModel()
model.x = Var()
model.c = Constraint(expr=other.a + 2 * model.x <= 0)
model.obj = Objective(expr=model.x)
baseline_fname, test_fname = self._get_fnames()
self._cleanup(test_fname)
self.assertRaises(
RuntimeError,
model.write, test_fname, format='gams')
self._cleanup(test_fname)
示例9: test_compute_bounds_fbbt
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import obj [as 别名]
def test_compute_bounds_fbbt(self):
"""Test computation of disjunctive bounds."""
m = ConcreteModel()
m.x = Var(bounds=(0, 8))
m.d1 = Disjunct()
m.d1.c = Constraint(expr=m.x >= 2)
m.d2 = Disjunct()
m.d2.c = Constraint(expr=m.x <= 4)
m.disj = Disjunction(expr=[m.d1, m.d2])
m.obj = Objective(expr=m.x)
TransformationFactory('contrib.compute_disj_var_bounds').apply_to(m)
self.assertEqual(m.d1._disj_var_bounds[m.x], (2, 8))
self.assertEqual(m.d2._disj_var_bounds[m.x], (0, 4))
self.assertEqual(disjunctive_lb(m.x, m.d1), 2)
self.assertEqual(disjunctive_ub(m.x, m.d1), 8)
self.assertEqual(disjunctive_lb(m.x, m.d2), 0)
self.assertEqual(disjunctive_ub(m.x, m.d2), 4)
示例10: test_var_on_nonblock
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import obj [as 别名]
def test_var_on_nonblock(self):
class Foo(Block().__class__):
def __init__(self, *args, **kwds):
kwds.setdefault('ctype', Foo)
super(Foo, self).__init__(*args, **kwds)
model = ConcreteModel()
model.x = Var()
model.other = Foo()
model.other.a = Var()
model.c = Constraint(expr=model.other.a + 2 * model.x <= 0)
model.obj = Objective(expr=model.x)
baseline_fname, test_fname = self._get_fnames()
self._cleanup(test_fname)
self.assertRaises(
RuntimeError,
model.write, test_fname, format='gams')
self._cleanup(test_fname)
示例11: build_model
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import obj [as 别名]
def build_model():
m = ConcreteModel()
m.x1 = Var(domain=NonNegativeReals, bounds=(0, 8))
m.x2 = Var(domain=NonNegativeReals, bounds=(0, 8))
m.c = Var(domain=NonNegativeReals, bounds=(1, 3))
m.y1 = Disjunct()
m.y2 = Disjunct()
m.y3 = Disjunct()
m.y1.constr1 = Constraint(expr=m.x1**2 + m.x2**2 - 1 <= 0)
m.y1.constr2 = Constraint(expr=m.c == 2)
m.y2.constr1 = Constraint(expr=(m.x1 - 4)**2 + (m.x2 - 1)**2 - 1 <= 0)
m.y2.constr2 = Constraint(expr=m.c == 1)
m.y3.constr1 = Constraint(expr=(m.x1 - 2)**2 + (m.x2 - 4)**2 - 1 <= 0)
m.y3.constr2 = Constraint(expr=m.c == 3)
m.GPD123 = Disjunction(expr=[m.y1, m.y2, m.y3])
m.obj = Objective(expr=(m.x1 - 3)**2 + (m.x2 - 2)**2 + m.c, sense=minimize)
return m
示例12: test_multiple_disjunctions_sat
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import obj [as 别名]
def test_multiple_disjunctions_sat(self):
m = ConcreteModel()
m.x1 = Var(bounds=(0, 8))
m.x2 = Var(bounds=(0, 8))
m.obj = Objective(expr=m.x1 + m.x2, sense=minimize)
m.y1 = Disjunct()
m.y2 = Disjunct()
m.y1.c1 = Constraint(expr=m.x1 >= 2)
m.y1.c2 = Constraint(expr=m.x2 >= 2)
m.y2.c1 = Constraint(expr=m.x1 >= 1)
m.y2.c2 = Constraint(expr=m.x2 >= 1)
m.djn1 = Disjunction(expr=[m.y1, m.y2])
m.z1 = Disjunct()
m.z2 = Disjunct()
m.z1.c1 = Constraint(expr=m.x1 <= 1)
m.z1.c2 = Constraint(expr=m.x2 <= 1)
m.z2.c1 = Constraint(expr=m.x1 <= 0)
m.z2.c2 = Constraint(expr=m.x2 <= 0)
m.djn2 = Disjunction(expr=[m.z1, m.z2])
self.assertTrue(satisfiable(m))
示例13: test_var_value_None
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import obj [as 别名]
def test_var_value_None(self):
m = ConcreteModel()
m.x = Var(bounds=(0, 1))
m.obj = Objective(expr=m.x)
SolverFactory('multistart').solve(m)
示例14: test_module_example
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import obj [as 别名]
def test_module_example(self):
from pyomo.environ import ConcreteModel, Var, Objective, units # import components and 'units' instance
model = ConcreteModel()
model.acc = Var()
model.obj = Objective(expr=(model.acc*units.m/units.s**2 - 9.81*units.m/units.s**2)**2)
self.assertEqual('m ** 2 / s ** 4', str(units.get_units(model.obj.expr)))