当前位置: 首页>>代码示例>>Python>>正文


Python ConcreteModel.c4方法代码示例

本文整理汇总了Python中pyomo.environ.ConcreteModel.c4方法的典型用法代码示例。如果您正苦于以下问题:Python ConcreteModel.c4方法的具体用法?Python ConcreteModel.c4怎么用?Python ConcreteModel.c4使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyomo.environ.ConcreteModel的用法示例。


在下文中一共展示了ConcreteModel.c4方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_constraint_to_var_bound

# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import c4 [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)
开发者ID:mskarha,项目名称:pyomo,代码行数:59,代码来源:test_bounds_to_vars_xfrm.py

示例2: test_unary_expressions

# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import c4 [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)
开发者ID:Pyomo,项目名称:pyomo,代码行数:20,代码来源:test_satsolver.py

示例3: test_zero_term_removal

# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import c4 [as 别名]
    def test_zero_term_removal(self):
        """Test for removing zero terms from linear constraints."""
        m = ConcreteModel()
        m.v0 = Var()
        m.v1 = Var()
        m.v2 = Var()
        m.v3 = Var()
        m.c = Constraint(expr=m.v0 == m.v1 * m.v2 + m.v3)
        m.c2 = Constraint(expr=m.v1 * m.v2 + m.v3 <= m.v0)
        m.c3 = Constraint(expr=m.v0 <= m.v1 * m.v2 + m.v3)
        m.c4 = Constraint(expr=EXPR.inequality(1, m.v1 * m.v2 + m.v3, 3))
        m.v1.fix(0)

        TransformationFactory('contrib.remove_zero_terms').apply_to(m)
        m.v1.unfix()
        # Check that the term no longer exists
        self.assertFalse(any(id(m.v1) == id(v)
                             for v in EXPR.identify_variables(m.c.body)))
        self.assertFalse(any(id(m.v1) == id(v)
                             for v in EXPR.identify_variables(m.c2.body)))
        self.assertFalse(any(id(m.v1) == id(v)
                             for v in EXPR.identify_variables(m.c3.body)))
        self.assertFalse(any(id(m.v1) == id(v)
                             for v in EXPR.identify_variables(m.c4.body)))
开发者ID:Pyomo,项目名称:pyomo,代码行数:26,代码来源:test_zero_term_removal.py


注:本文中的pyomo.environ.ConcreteModel.c4方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。