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


Python ConcreteModel.c1方法代码示例

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


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

示例1: test_var_bound_propagate_revert

# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import c1 [as 别名]
 def test_var_bound_propagate_revert(self):
     """Test to make sure bound propagation revert works."""
     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)
     xfrm = TransformationFactory('contrib.propagate_eq_var_bounds')
     xfrm.apply_to(m, tmp=True)
     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))
     xfrm.revert(m)
     self.assertEquals(value(m.v1.lb), 1)
     self.assertEquals(value(m.v2.lb), 0)
     self.assertEquals(value(m.v3.lb), 2)
     self.assertEquals(value(m.v4.lb), 0)
     self.assertEquals(value(m.v1.ub), 3)
     self.assertEquals(value(m.v2.ub), 8)
     self.assertEquals(value(m.v3.ub), 4)
     self.assertEquals(value(m.v4.ub), 5)
开发者ID:Pyomo,项目名称:pyomo,代码行数:31,代码来源:test_equality_propagate.py

示例2: build_model

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

示例3: test_simple_unsat_model

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

示例4: test_not_transform_improperly

# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import c1 [as 别名]
 def test_not_transform_improperly(self):
     """Tests that invalid constraints are not transformed."""
     m = ConcreteModel()
     m.v1 = Var(initialize=0, domain=Binary)
     m.c1 = Constraint(expr=-1 * m.v1 <= 0)
     TransformationFactory('contrib.propagate_zero_sum').apply_to(m)
     self.assertFalse(m.v1.fixed)
开发者ID:Pyomo,项目名称:pyomo,代码行数:9,代码来源:test_zero_sum_propagate.py

示例5: test_inactive_constraints

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

示例6: test_constraint_to_var_bound

# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import c1 [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

示例7: test_var_bound_propagate_crossover

# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import c1 [as 别名]
 def test_var_bound_propagate_crossover(self):
     """Test for error message when variable bound crosses over."""
     m = ConcreteModel()
     m.v1 = Var(initialize=1, bounds=(1, 3))
     m.v2 = Var(initialize=5, bounds=(4, 8))
     m.c1 = Constraint(expr=m.v1 == m.v2)
     xfrm = TransformationFactory('contrib.propagate_eq_var_bounds')
     with self.assertRaises(ValueError):
         xfrm.apply_to(m)
开发者ID:Pyomo,项目名称:pyomo,代码行数:11,代码来源:test_equality_propagate.py

示例8: test_ignore_nonlinear

# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import c1 [as 别名]
    def test_ignore_nonlinear(self):
        m = ConcreteModel()
        m.v1 = Var()
        m.c1 = Constraint(expr=m.v1 * m.v1 >= 2)

        self.assertEqual(value(m.c1.lower), 2)
        self.assertFalse(m.c1.has_ub())
        TransformationFactory('core.tighten_constraints_from_vars').apply_to(m)
        self.assertEqual(value(m.c1.lower), 2)
        self.assertFalse(m.c1.has_ub())
开发者ID:Pyomo,项目名称:pyomo,代码行数:12,代码来源:test_constraint_tightener.py

示例9: test_non_negative_propagate

# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import c1 [as 别名]
    def test_non_negative_propagate(self):
        """Test zero sum propagation for non-negative vars."""
        m = ConcreteModel()
        m.v1 = Var(initialize=0)
        m.v2 = Var(initialize=2, domain=NonNegativeReals)
        m.v3 = Var(initialize=3, domain=NonNegativeReals)
        m.v4 = Var(initialize=4, domain=NonNegativeReals)
        m.c1 = Constraint(expr=m.v1 == m.v2 + m.v3 + m.v4)
        m.v1.fix()
        # Because v1 = 0, all the other values must be zero
        TransformationFactory('contrib.propagate_zero_sum').apply_to(m)
        self.assertTrue(m.v1.fixed)
        self.assertTrue(m.v2.fixed)
        self.assertTrue(m.v3.fixed)
        self.assertTrue(m.v4.fixed)
        del m

        m = ConcreteModel()
        m.v1 = Var(initialize=0)
        m.v2 = Var(initialize=2, domain=NonNegativeReals)
        m.v3 = Var(initialize=3, domain=NonNegativeReals)
        m.v4 = Var(initialize=4, domain=NonNegativeReals)
        m.c1 = Constraint(expr=m.v2 + m.v3 + m.v4 == m.v1)
        m.v1.fix()
        TransformationFactory('contrib.propagate_zero_sum').apply_to(m)
        self.assertTrue(m.v1.fixed)
        self.assertTrue(m.v2.fixed)
        self.assertTrue(m.v3.fixed)
        self.assertTrue(m.v4.fixed)
        del m

        m = ConcreteModel()
        m.v1 = Var(initialize=0)
        m.v2 = Var(initialize=2, domain=NonNegativeReals)
        m.v3 = Var(initialize=3, domain=NonNegativeReals)
        m.v4 = Var(initialize=4, domain=NonNegativeReals)
        m.c1 = Constraint(expr=m.v1 >= m.v2 + m.v3 + m.v4)
        m.v1.fix()
        TransformationFactory('contrib.propagate_zero_sum').apply_to(m)
        self.assertTrue(m.v1.fixed)
        self.assertTrue(m.v2.fixed)
        self.assertTrue(m.v3.fixed)
        self.assertTrue(m.v4.fixed)
开发者ID:Pyomo,项目名称:pyomo,代码行数:45,代码来源:test_zero_sum_propagate.py

示例10: test_do_not_tranform_deactivated_constraints

# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import c1 [as 别名]
 def test_do_not_tranform_deactivated_constraints(self):
     m = ConcreteModel()
     m.x = Var()
     m.y = Var()
     m.c1 = Constraint(expr=m.x == m.y)
     m.c2 = Constraint(expr=(2, m.x, 3))
     m.c3 = Constraint(expr=m.x == 0)
     m.c3.deactivate()
     TransformationFactory('contrib.aggregate_vars').apply_to(m)
     self.assertIs(m.c2.body, m._var_aggregator_info.z[1])
     self.assertIs(m.c3.body, m.x)
开发者ID:Pyomo,项目名称:pyomo,代码行数:13,代码来源:test_var_aggregator.py

示例11: test_var_bound_propagate

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

示例12: test_less_than_constraint

# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import c1 [as 别名]
    def test_less_than_constraint(self):
        m = ConcreteModel()
        m.v1 = Var(initialize=7, bounds=(7, 10))
        m.v2 = Var(initialize=2, bounds=(2, 5))
        m.v3 = Var(initialize=6, bounds=(6, 9))
        m.v4 = Var(initialize=1, bounds=(1, 1))
        m.c1 = Constraint(expr=m.v1 <= m.v2 + m.v3 + m.v4)

        self.assertEqual(value(m.c1.upper), 0)
        self.assertFalse(m.c1.has_lb())
        TransformationFactory('core.tighten_constraints_from_vars').apply_to(m)
        self.assertEqual(value(m.c1.upper), 0)
        self.assertEqual(value(m.c1.lower), -8)
开发者ID:Pyomo,项目名称:pyomo,代码行数:15,代码来源:test_constraint_tightener.py

示例13: test_constraint_bound_tightening

# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import c1 [as 别名]
    def test_constraint_bound_tightening(self):
        # Check for no coefficients
        m = ConcreteModel()
        m.v1 = Var(initialize=7, bounds=(7, 10))
        m.v2 = Var(initialize=2, bounds=(2, 5))
        m.v3 = Var(initialize=6, bounds=(6, 9))
        m.v4 = Var(initialize=1, bounds=(1, 1))
        m.c1 = Constraint(expr=m.v1 >= m.v2 + m.v3 + m.v4 + 1)

        self.assertEqual(value(m.c1.upper), 0)
        self.assertFalse(m.c1.has_lb())
        TransformationFactory('core.tighten_constraints_from_vars').apply_to(m)
        self.assertEqual(value(m.c1.upper), 0)
        self.assertEqual(value(m.c1.lower), 0)
开发者ID:Pyomo,项目名称:pyomo,代码行数:16,代码来源:test_constraint_tightener.py

示例14: test_constraint_with_coef

# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import c1 [as 别名]
    def test_constraint_with_coef(self):
        """Test with coefficient on constraint."""
        m = ConcreteModel()
        m.v1 = Var(initialize=7, bounds=(7, 10))
        m.v2 = Var(initialize=2, bounds=(2, 5))
        m.v3 = Var(initialize=6, bounds=(6, 9))
        m.v4 = Var(initialize=1, bounds=(1, 1))
        m.c1 = Constraint(expr=m.v1 <= 2 * m.v2 + m.v3 + m.v4)

        self.assertEqual(value(m.c1.upper), 0)
        self.assertFalse(m.c1.has_lb())
        TransformationFactory('core.tighten_constraints_from_vars').apply_to(m)
        self.assertEqual(value(m.c1.upper), -1)
        self.assertEqual(value(m.c1.lower), -13)
开发者ID:Pyomo,项目名称:pyomo,代码行数:16,代码来源:test_constraint_tightener.py

示例15: test_unbounded_var

# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import c1 [as 别名]
    def test_unbounded_var(self):
        """test with unbounded variables"""
        m = ConcreteModel()
        m.v1 = Var(initialize=7)
        m.v2 = Var(initialize=2, bounds=(2, 5))
        m.v3 = Var(initialize=6, bounds=(6, 9))
        m.v4 = Var(initialize=1, bounds=(1, 1))
        m.c1 = Constraint(expr=m.v1 <= 2 * m.v2 + m.v3 + m.v4)

        self.assertEqual(value(m.c1.upper), 0)
        self.assertFalse(m.c1.has_lb())
        TransformationFactory('core.tighten_constraints_from_vars').apply_to(m)
        self.assertEqual(value(m.c1.upper), 0)
        self.assertFalse(m.c1.has_lb())
开发者ID:Pyomo,项目名称:pyomo,代码行数:16,代码来源:test_constraint_tightener.py


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