本文整理汇总了Python中pyomo.environ.ConcreteModel.z2方法的典型用法代码示例。如果您正苦于以下问题:Python ConcreteModel.z2方法的具体用法?Python ConcreteModel.z2怎么用?Python ConcreteModel.z2使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyomo.environ.ConcreteModel
的用法示例。
在下文中一共展示了ConcreteModel.z2方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: build_model
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import z2 [as 别名]
def build_model(self):
m = ConcreteModel()
m.v1 = Var(initialize=1, bounds=(1, 8))
m.v2 = Var(initialize=2, bounds=(0, 3))
m.v3 = Var(initialize=3, bounds=(-7, 4))
m.v4 = Var(initialize=4, bounds=(2, 6))
m.c1 = Constraint(expr=m.v1 == m.v2)
m.c2 = Constraint(expr=m.v2 == m.v3)
m.c3 = Constraint(expr=m.v3 == m.v4)
m.v2.fix()
m.s = RangeSet(5)
m.x = Var(m.s, initialize=5)
m.c = Constraint(m.s)
m.c.add(1, expr=m.x[1] == m.x[3])
m.c.add(2, expr=m.x[2] == m.x[4])
m.c.add(3, expr=m.x[2] == m.x[3])
m.c.add(4, expr=m.x[1] == 1)
m.c.add(5, expr=(2, m.x[5], 3))
m.y = Var([1, 2], initialize={1: 3, 2: 4})
m.c_too = Constraint(expr=m.y[1] == m.y[2])
m.z1 = Var()
m.z2 = Var()
m.ignore_me = Constraint(expr=m.y[1] + m.z1 + m.z2 <= 0)
m.ignore_me_too = Constraint(expr=m.y[1] * m.y[2] == 0)
m.multiple = Constraint(expr=m.y[1] == 2 * m.y[2])
return m
示例2: test_var_bound_propagate
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import z2 [as 别名]
def test_var_bound_propagate(self):
"""Test for transitivity in a variable equality set."""
m = ConcreteModel()
m.v1 = Var(initialize=1, bounds=(1, 3))
m.v2 = Var(initialize=2, bounds=(0, 8))
m.v3 = Var(initialize=3, bounds=(2, 4))
m.v4 = Var(initialize=4, bounds=(0, 5))
m.c1 = Constraint(expr=m.v1 == m.v2)
m.c2 = Constraint(expr=m.v2 == m.v3)
m.c3 = Constraint(expr=m.v3 == m.v4)
m.s = RangeSet(4)
m.x = Var(m.s, initialize=5)
m.x[2].setlb(-1)
m.c = Constraint(m.s)
m.c.add(1, expr=m.x[1] == m.x[3])
m.c.add(2, expr=m.x[2] == m.x[4])
m.c.add(3, expr=m.x[2] == m.x[3])
m.c.add(4, expr=m.x[1] == 1)
m.y = Var([1, 2], initialize=3)
m.y[1].setub(3)
m.y[2].setub(15)
m.c_too = Constraint(expr=m.y[1] == m.y[2])
m.z1 = Var(bounds=(1, 2))
m.z2 = Var(bounds=(3, 4))
m.ignore_me = Constraint(expr=m.y[1] + m.z1 + m.z2 <= 0)
TransformationFactory('contrib.propagate_eq_var_bounds').apply_to(m)
self.assertEquals(value(m.v1.lb), 2)
self.assertEquals(value(m.v1.lb), value(m.v2.lb))
self.assertEquals(value(m.v1.lb), value(m.v3.lb))
self.assertEquals(value(m.v1.lb), value(m.v4.lb))
self.assertEquals(value(m.v1.ub), 3)
self.assertEquals(value(m.v1.ub), value(m.v2.ub))
self.assertEquals(value(m.v1.ub), value(m.v3.ub))
self.assertEquals(value(m.v1.ub), value(m.v4.ub))
for i in m.s:
self.assertEquals(value(m.x[i].lb), -1)
self.assertEquals(value(m.y[1].ub), 3)
self.assertEquals(value(m.y[2].ub), 3)
self.assertEquals(value(m.y[1].lb), None)
self.assertEquals(value(m.y[1].lb), None)
self.assertEquals(value(m.z1.ub), 2)
self.assertEquals(value(m.z2.ub), 4)
self.assertEquals(value(m.z1.lb), 1)
self.assertEquals(value(m.z2.lb), 3)
示例3: test_fixed_var_propagate
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import z2 [as 别名]
def test_fixed_var_propagate(self):
"""Test for transitivity in a variable equality set."""
m = ConcreteModel()
m.v1 = Var(initialize=1)
m.v2 = Var(initialize=2)
m.v3 = Var(initialize=3)
m.v4 = Var(initialize=4)
m.c1 = Constraint(expr=m.v1 == m.v2)
m.c2 = Constraint(expr=m.v2 == m.v3)
m.c3 = Constraint(expr=m.v3 == m.v4)
m.v2.fix()
m.s = RangeSet(4)
m.x = Var(m.s, initialize=5)
m.c = Constraint(m.s)
m.c.add(1, expr=m.x[1] == m.x[3])
m.c.add(2, expr=m.x[2] == m.x[4])
m.c.add(3, expr=m.x[2] == m.x[3])
m.c.add(4, expr=m.x[1] == 1)
m.y = Var([1, 2], initialize=3)
m.c_too = Constraint(expr=m.y[1] == m.y[2])
m.z1 = Var()
m.z2 = Var()
m.ignore_me = Constraint(expr=m.y[1] + m.z1 + m.z2 <= 0)
TransformationFactory('contrib.propagate_fixed_vars').apply_to(m)
self.assertTrue(m.v1.fixed)
self.assertTrue(m.v2.fixed)
self.assertTrue(m.v3.fixed)
self.assertTrue(m.v4.fixed)
self.assertEquals(value(m.v4), 2)
self.assertTrue(m.x[1].fixed)
self.assertTrue(m.x[2].fixed)
self.assertTrue(m.x[3].fixed)
self.assertTrue(m.x[4].fixed)
self.assertEquals(value(m.x[4]), 1)
self.assertFalse(m.y[1].fixed)
self.assertFalse(m.y[2].fixed)
self.assertFalse(m.z1.fixed)
self.assertFalse(m.z2.fixed)
示例4: test_multiple_disjunctions_sat
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import z2 [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))