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


Python ConcreteModel.c方法代码示例

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


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

示例1: test_is_feasible_function

# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import c [as 别名]
    def test_is_feasible_function(self):
        m = ConcreteModel()
        m.x = Var(bounds=(0, 3), initialize=2)
        m.c = Constraint(expr=m.x == 2)
        self.assertTrue(is_feasible(m, GDPoptSolver.CONFIG()))

        m.c2 = Constraint(expr=m.x <= 1)
        self.assertFalse(is_feasible(m, GDPoptSolver.CONFIG()))

        m = ConcreteModel()
        m.x = Var(bounds=(0, 3), initialize=2)
        m.c = Constraint(expr=m.x >= 5)
        self.assertFalse(is_feasible(m, GDPoptSolver.CONFIG()))

        m = ConcreteModel()
        m.x = Var(bounds=(3, 3), initialize=2)
        self.assertFalse(is_feasible(m, GDPoptSolver.CONFIG()))

        m = ConcreteModel()
        m.x = Var(bounds=(0, 1), initialize=2)
        self.assertFalse(is_feasible(m, GDPoptSolver.CONFIG()))

        m = ConcreteModel()
        m.x = Var(bounds=(0, 1), initialize=2)
        m.d = Disjunct()
        with self.assertRaisesRegexp(NotImplementedError, "Found active disjunct"):
            is_feasible(m, GDPoptSolver.CONFIG())
开发者ID:Pyomo,项目名称:pyomo,代码行数:29,代码来源:test_gdpopt.py

示例2: test_set_expr_inline

# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import c [as 别名]
    def test_set_expr_inline(self):
        """Test expr= option (inline expression)"""
        model = ConcreteModel()
        model.A = RangeSet(1,4)
        model.x = Var(model.A,initialize=2)
        model.c = Constraint(expr=(0, sum(model.x[i] for i in model.A), 1))

        self.assertEqual(model.c(), 8)
        self.assertEqual(value(model.c.body), 8)
开发者ID:Pyomo,项目名称:pyomo,代码行数:11,代码来源:test_con.py

示例3: test_set_expr_explicit_univariate

# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import c [as 别名]
    def test_set_expr_explicit_univariate(self):
        """Test expr= option (univariate expression)"""
        model = ConcreteModel()
        model.x = Var(initialize=2)
        ans = model.x >= 0
        ans = ans <= 1
        model.c = Constraint(expr=ans)

        self.assertEqual(model.c(), 2)
        self.assertEqual(model.c.body(), 2)
        self.assertEqual(value(model.c.body), 2)
开发者ID:Pyomo,项目名称:pyomo,代码行数:13,代码来源:test_con.py

示例4: test_setitem

# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import c [as 别名]
    def test_setitem(self):
        m = ConcreteModel()
        m.x = Var()
        m.c = Constraint()
        self.assertEqual(len(m.c), 0)

        m.c = m.x**2 <= 4
        self.assertEqual(len(m.c), 1)
        self.assertEqual(list(m.c.keys()), [None])
        self.assertEqual(m.c.upper, 4)

        m.c = Constraint.Skip
        self.assertEqual(len(m.c), 0)
开发者ID:Pyomo,项目名称:pyomo,代码行数:15,代码来源:test_con.py

示例5: test_set_expr_undefined_univariate

# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import c [as 别名]
    def test_set_expr_undefined_univariate(self):
        """Test expr= option (univariate expression)"""
        model = ConcreteModel()
        model.x = Var()
        ans = model.x >= 0
        ans = ans <= 1
        model.c = Constraint(expr=ans)

        #self.assertRaises(ValueError, model.c)
        self.assertEqual(model.c(),None)
        model.x = 2
        self.assertEqual(model.c(), 2)
        self.assertEqual(value(model.c.body), 2)
开发者ID:Pyomo,项目名称:pyomo,代码行数:15,代码来源:test_con.py

示例6: test_rule5

# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import c [as 别名]
    def test_rule5(self):
        """Test rule option"""
        model = ConcreteModel()
        model.B = RangeSet(1,4)
        def f(model):
            ans=0
            for i in model.B:
                ans = ans + model.x[i]
            return (ans, 1)
        model.x = Var(model.B, initialize=2)
        model.c = Constraint(rule=f)

        self.assertEqual(model.c(), 8)
        self.assertEqual(value(model.c.body), 8)
开发者ID:Pyomo,项目名称:pyomo,代码行数:16,代码来源:test_con.py

示例7: test_set_expr_explicit_multivariate

# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import c [as 别名]
    def test_set_expr_explicit_multivariate(self):
        """Test expr= option (multivariate expression)"""
        model = ConcreteModel()
        model.A = RangeSet(1,4)
        model.x = Var(model.A, initialize=2)
        ans=0
        for i in model.A:
            ans = ans + model.x[i]
        ans = ans >= 0
        ans = ans <= 1
        model.c = Constraint(expr=ans)

        self.assertEqual(model.c(), 8)
        self.assertEqual(model.c.body(), 8)
        self.assertEqual(value(model.c.body), 8)
开发者ID:Pyomo,项目名称:pyomo,代码行数:17,代码来源:test_con.py

示例8: test_linear

# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import c [as 别名]
    def test_linear(self):
        m = ConcreteModel()
        m.x = Var()
        m.c = Constraint(expr=5*m.x == 10)

        calculate_variable_from_constraint(m.x, m.c)
        self.assertEqual(value(m.x), 2)
开发者ID:Pyomo,项目名称:pyomo,代码行数:9,代码来源:test_calc_var_value.py

示例9: build_model

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

示例10: test_induced_linearity_case2

# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import c [as 别名]
 def test_induced_linearity_case2(self):
     m = ConcreteModel()
     m.x = Var([0], bounds=(-3, 8))
     m.y = Var(RangeSet(4), domain=Binary)
     m.z = Var(domain=Integers, bounds=(-1, 2))
     m.constr = Constraint(
         expr=m.x[0] == m.y[1] + 2 * m.y[2] + m.y[3] + 2 * m.y[4] + m.z)
     m.logical = ConstraintList()
     m.logical.add(expr=m.y[1] + m.y[2] == 1)
     m.logical.add(expr=m.y[3] + m.y[4] == 1)
     m.logical.add(expr=m.y[2] + m.y[4] <= 1)
     m.b = Var(bounds=(-2, 7))
     m.c = Var()
     m.bilinear = Constraint(
         expr=(m.x[0] - 3) * (m.b + 2) - (m.c + 4) * m.b +
         exp(m.b ** 2) * m.x[0] <= m.c)
     TransformationFactory('contrib.induced_linearity').apply_to(m)
     xfrmed_blk = m._induced_linearity_info.x0_b_bilinear
     self.assertSetEqual(
         set(xfrmed_blk.valid_values), set([1, 2, 3, 4, 5]))
     select_one_repn = generate_standard_repn(
         xfrmed_blk.select_one_value.body)
     self.assertEqual(
         ComponentSet(select_one_repn.linear_vars),
         ComponentSet(xfrmed_blk.x_active[i] for i in xfrmed_blk.valid_values))
开发者ID:Pyomo,项目名称:pyomo,代码行数:27,代码来源:test_induced_linearity.py

示例11: test_None_key

# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import c [as 别名]
 def test_None_key(self):
     """Test keys method"""
     model = ConcreteModel()
     model.x = Var()
     model.c = Constraint(expr=model.x == 1)
     self.assertEqual(list(model.c.keys()),[None])
     self.assertEqual(id(model.c),id(model.c[None]))
开发者ID:Pyomo,项目名称:pyomo,代码行数:9,代码来源:test_con.py

示例12: _trivial_constraints_ub_conflict

# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import c [as 别名]
 def _trivial_constraints_ub_conflict(self):
     m = ConcreteModel()
     m.v1 = Var(initialize=1)
     m.c = Constraint(expr=m.v1 <= 0)
     m.v1.fix()
     TransformationFactory(
         'contrib.deactivate_trivial_constraints').apply_to(m)
开发者ID:Pyomo,项目名称:pyomo,代码行数:9,代码来源:test_deactivate_trivial_constraints.py

示例13: test_binary_expressions

# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import c [as 别名]
 def test_binary_expressions(self):
     m = ConcreteModel()
     m.x = Var()
     m.y = Var()
     m.z = Var()
     m.c = Constraint(expr=0 <= m.x + m.y - m.z * m.y / m.x + 7)
     m.o = Objective(expr=m.x)
     self.assertTrue(satisfiable(m))
开发者ID:Pyomo,项目名称:pyomo,代码行数:10,代码来源:test_satsolver.py

示例14: test_solver_arg

# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import c [as 别名]
 def test_solver_arg(self):
     m = ConcreteModel()
     m.x = Var()
     m.c = Constraint(expr=m.x == 2)
     m.o = Objective(expr=m.x)
     os = StringIO()
     m.write(os, format="gams", io_options=dict(solver="gurobi"))
     self.assertIn("option lp=gurobi", os.getvalue())
开发者ID:Pyomo,项目名称:pyomo,代码行数:10,代码来源:test_gams.py

示例15: test_fixed_var_out_of_bounds_ub

# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import c [as 别名]
 def test_fixed_var_out_of_bounds_ub(self):
     m = ConcreteModel()
     m.s = RangeSet(2)
     m.v = Var(m.s, bounds=(0, 5))
     m.c = ConstraintList()
     m.c.add(expr=m.v[1] == m.v[2])
     m.c.add(expr=m.v[1] == 6)
     with self.assertRaises(ValueError):
         TransformationFactory('contrib.aggregate_vars').apply_to(m)
开发者ID:Pyomo,项目名称:pyomo,代码行数:11,代码来源:test_var_aggregator.py


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