本文整理汇总了Python中pyomo.environ.ConcreteModel.c7方法的典型用法代码示例。如果您正苦于以下问题:Python ConcreteModel.c7方法的具体用法?Python ConcreteModel.c7怎么用?Python ConcreteModel.c7使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyomo.environ.ConcreteModel
的用法示例。
在下文中一共展示了ConcreteModel.c7方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_constraint_to_var_bound
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import c7 [as 别名]
def test_constraint_to_var_bound(self):
"""Test converting explicit constraints into variable bounds."""
m = ConcreteModel()
m.v1 = Var(initialize=1)
m.v2 = Var(initialize=2)
m.v3 = Var(initialize=3)
m.v4 = Var(initialize=4)
m.v5 = Var(initialize=5)
m.v6 = Var()
m.v7 = Var(domain=Integers)
m.v8 = Var(domain=Integers)
m.c1 = Constraint(expr=m.v1 == 2)
m.c2 = Constraint(expr=m.v2 >= -2)
m.c3 = Constraint(expr=m.v3 <= 5)
m.c4 = Constraint(expr=m.v4 <= m.v5)
m.v5.fix()
m.c6 = Constraint(expr=m.v6 >= 2)
m.c7 = Constraint(expr=m.v7 + 2 >= 2.01)
m.c8 = Constraint(expr=m.v8 + 2 >= 2.0001)
m2 = TransformationFactory(
'contrib.constraints_to_var_bounds').create_using(m)
self.assertEqual(value(m2.v1.lb), 2)
self.assertEqual(value(m2.v1.ub), 2)
self.assertTrue(m2.v1.fixed)
self.assertEqual(value(m2.v2.lb), -2)
self.assertFalse(m2.v2.has_ub())
self.assertEqual(value(m2.v3.ub), 5)
self.assertFalse(m2.v3.has_lb())
self.assertEqual(value(m2.v4.ub), 5)
self.assertFalse(m2.v4.has_lb())
self.assertEqual(value(m2.v6.lb), 2)
self.assertFalse(m2.v6.has_ub())
self.assertEqual(value(m2.v6, exception=False), None)
del m2 # to keep from accidentally using it below
TransformationFactory('contrib.constraints_to_var_bounds').apply_to(m, tolerance=1e-3)
self.assertEqual(value(m.v1.lb), 2)
self.assertEqual(value(m.v1.ub), 2)
self.assertTrue(m.v1.fixed)
self.assertEqual(value(m.v2.lb), -2)
self.assertFalse(m.v2.has_ub())
self.assertEqual(value(m.v3.ub), 5)
self.assertFalse(m.v3.has_lb())
self.assertEqual(value(m.v4.ub), 5)
self.assertFalse(m.v4.has_lb())
self.assertEqual(value(m.v7.lb), 1)
self.assertEqual(value(m.v8.lb), 0)
示例2: test_unary_expressions
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import c7 [as 别名]
def test_unary_expressions(self):
m = ConcreteModel()
m.x = Var()
m.y = Var()
m.z = Var()
m.a = Var()
m.b = Var()
m.c = Var()
m.d = Var()
m.c1 = Constraint(expr=0 <= sin(m.x))
m.c2 = Constraint(expr=0 <= cos(m.y))
m.c3 = Constraint(expr=0 <= tan(m.z))
m.c4 = Constraint(expr=0 <= asin(m.a))
m.c5 = Constraint(expr=0 <= acos(m.b))
m.c6 = Constraint(expr=0 <= atan(m.c))
m.c7 = Constraint(expr=0 <= sqrt(m.d))
m.o = Objective(expr=m.x)
self.assertTrue(satisfiable(m) is not False)