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


Python ConcreteModel.y方法代码示例

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


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

示例1: test_GDP_nonlinear_objective

# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import y [as 别名]
    def test_GDP_nonlinear_objective(self):
        m = ConcreteModel()
        m.x = Var(bounds=(-1, 10))
        m.y = Var(bounds=(2, 3))
        m.d = Disjunction(expr=[
            [m.x + m.y >= 5], [m.x - m.y <= 3]
        ])
        m.o = Objective(expr=m.x ** 2)
        SolverFactory('gdpopt').solve(
            m, strategy='LOA',
            mip_solver=mip_solver,
            nlp_solver=nlp_solver
        )
        self.assertAlmostEqual(value(m.o), 0)

        m = ConcreteModel()
        m.x = Var(bounds=(-1, 10))
        m.y = Var(bounds=(2, 3))
        m.d = Disjunction(expr=[
            [m.x + m.y >= 5], [m.x - m.y <= 3]
        ])
        m.o = Objective(expr=-m.x ** 2, sense=maximize)
        SolverFactory('gdpopt').solve(
            m, strategy='LOA',
            mip_solver=mip_solver,
            nlp_solver=nlp_solver
        )
        self.assertAlmostEqual(value(m.o), 0)
开发者ID:Pyomo,项目名称:pyomo,代码行数:30,代码来源:test_gdpopt.py

示例2: test_induced_linearity_case2

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

示例3: test_bilinear_in_disjuncts

# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import y [as 别名]
 def test_bilinear_in_disjuncts(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.v = Var([1, 2])
     m.v[1].setlb(-2)
     m.v[1].setub(7)
     m.v[2].setlb(-4)
     m.v[2].setub(5)
     m.bilinear = Constraint(
         expr=(m.x[0] - 3) * (m.v[1] + 2) - (m.v[2] + 4) * m.v[1] +
         exp(m.v[1] ** 2) * m.x[0] <= m.v[2])
     m.disjctn = Disjunction(expr=[
         [m.x[0] * m.v[1] <= 4],
         [m.x[0] * m.v[2] >= 6]
     ])
     TransformationFactory('contrib.induced_linearity').apply_to(m)
     self.assertEqual(
         m.disjctn.disjuncts[0].constraint[1].body.polynomial_degree(), 1)
     self.assertEqual(
         m.disjctn.disjuncts[1].constraint[1].body.polynomial_degree(), 1)
开发者ID:Pyomo,项目名称:pyomo,代码行数:30,代码来源:test_induced_linearity.py

示例4: test_unique_component_name

# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import y [as 别名]
    def test_unique_component_name(self):
        m = ConcreteModel()
        m.x = 5
        m.y = Var()
        name = unique_component_name(m, 'z')
        self.assertEqual(name, 'z')

        name = unique_component_name(m, 'x')
        self.assertEqual(len(name), 3)
        self.assertEqual(name[:2], 'x_')
        self.assertIn(name[2], '0123456789')

        name = unique_component_name(m, 'y')
        self.assertEqual(len(name), 3)
        self.assertEqual(name[:2], 'y_')
        self.assertIn(name[2], '0123456789')

        name = unique_component_name(m, 'component')
        self.assertEqual(len(name), 11)
        self.assertEqual(name[:10], 'component_')
        self.assertIn(name[10], '0123456789')

        for i in range(10):
            setattr(m, 'y_%s' % i, 0)

        name = unique_component_name(m, 'y')
        self.assertEqual(len(name), 4)
        self.assertEqual(name[:2], 'y_')
        self.assertIn(name[2], '0123456789')
        self.assertIn(name[3], '0123456789')
开发者ID:Pyomo,项目名称:pyomo,代码行数:32,代码来源:test_modeling.py

示例5: build_model

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

示例6: test_binary_expressions

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

示例7: test_tuple_constraint_create

# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import y [as 别名]
    def test_tuple_constraint_create(self):
        def rule1(model):
            return (0.0,model.x)
        model = ConcreteModel()
        model.x = Var()
        model.y = Var()
        model.z = Var()
        model.o = Constraint(rule=rule1)

        #
        def rule1(model):
            return (model.y,model.x,model.z)
        model = AbstractModel()
        model.x = Var()
        model.y = Var()
        model.z = Var()
        model.o = Constraint(rule=rule1)
        self.assertRaises(ValueError, model.create_instance)
开发者ID:Pyomo,项目名称:pyomo,代码行数:20,代码来源:test_con.py

示例8: test_do_not_tranform_deactivated_constraints

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

示例9: test_var_bound_propagate

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

示例10: test_invalid

# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import y [as 别名]
    def test_invalid(self):
        m = ConcreteModel()
        m.t = ContinuousSet(bounds=(0, 1))
        m.x = ContinuousSet(bounds=(5, 10))
        m.s = Set(initialize=[1, 2, 3])
        m.v = Var(m.t)
        m.v2 = Var(m.s, m.t)
        m.v3 = Var(m.x, m.t)
        m.y = Var()

        # Not passing a Var as the first positional argument
        with self.assertRaises(DAE_Error):
            m.ds = DerivativeVar(m.s)

        # Specifying both option aliases
        with self.assertRaises(TypeError):
            m.dv = DerivativeVar(m.v, wrt=m.t, withrespectto=m.t)

        # Passing in Var not indexed by a ContinuousSet
        with self.assertRaises(DAE_Error):
            m.dy = DerivativeVar(m.y)

        # Not specifying 'wrt' when Var indexed by multiple ContinuousSets
        with self.assertRaises(DAE_Error):
            m.dv3 = DerivativeVar(m.v3)

        # 'wrt' is not a ContinuousSet
        with self.assertRaises(DAE_Error):
            m.dv2 = DerivativeVar(m.v2, wrt=m.s)

        with self.assertRaises(DAE_Error):
            m.dv2 = DerivativeVar(m.v2, wrt=(m.t, m.s))

        # Specified ContinuousSet does not index the Var
        with self.assertRaises(DAE_Error):
            m.dv = DerivativeVar(m.v, wrt=m.x)

        with self.assertRaises(DAE_Error):
            m.dv2 = DerivativeVar(m.v2, wrt=[m.t, m.x])

        # Declaring the same derivative twice
        m.dvdt = DerivativeVar(m.v)
        with self.assertRaises(DAE_Error):
            m.dvdt2 = DerivativeVar(m.v)

        m.dv2dt = DerivativeVar(m.v2, wrt=m.t)
        with self.assertRaises(DAE_Error):
            m.dv2dt2 = DerivativeVar(m.v2, wrt=m.t)

        m.dv3 = DerivativeVar(m.v3, wrt=(m.x, m.x))
        with self.assertRaises(DAE_Error):
            m.dv4 = DerivativeVar(m.v3, wrt=(m.x, m.x))
开发者ID:Pyomo,项目名称:pyomo,代码行数:54,代码来源:test_diffvar.py

示例11: test_skip_trivial_constraints

# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import y [as 别名]
 def test_skip_trivial_constraints(self):
     """Tests handling of zero coefficients."""
     m = ConcreteModel()
     m.x = Var()
     m.y = Var()
     m.z = Var()
     m.c = Constraint(expr=m.x * m.y == m.z)
     m.z.fix(0)
     m.y.fix(0)
     TransformationFactory('contrib.constraints_to_var_bounds').apply_to(m)
     self.assertEqual(m.c.body.polynomial_degree(), 1)
     self.assertTrue(m.c.active)
     self.assertFalse(m.x.has_lb())
     self.assertFalse(m.x.has_ub())
开发者ID:mskarha,项目名称:pyomo,代码行数:16,代码来源:test_bounds_to_vars_xfrm.py

示例12: test_pow

# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import y [as 别名]
    def test_pow(self):
        # Tests the special transformation for x ^ y (both variables)
        with SolverFactory("baron") as opt:

            m = ConcreteModel()
            m.x = Var(bounds=(10,100))
            m.y = Var(bounds=(1,10))
            m.c = Constraint(expr=m.x ** m.y >= 20)
            m.obj = Objective(expr=m.x, sense=minimize)

            results = opt.solve(m)

            self.assertEqual(results.solver.termination_condition,
                             TerminationCondition.optimal)
开发者ID:Pyomo,项目名称:pyomo,代码行数:16,代码来源:test_BARON.py

示例13: test_var_update

# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import y [as 别名]
 def test_var_update(self):
     m = ConcreteModel()
     m.x = Var()
     m.y = Var(bounds=(0, 1))
     m.c = Constraint(expr=m.x == m.y)
     m.o = Objective(expr=m.x)
     TransformationFactory('contrib.aggregate_vars').apply_to(m)
     SolverFactory('glpk').solve(m)
     z = m._var_aggregator_info.z
     self.assertEqual(z[1].value, 0)
     self.assertEqual(m.x.value, None)
     self.assertEqual(m.y.value, None)
     TransformationFactory('contrib.aggregate_vars').update_variables(m)
     self.assertEqual(z[1].value, 0)
     self.assertEqual(m.x.value, 0)
     self.assertEqual(m.y.value, 0)
开发者ID:Pyomo,项目名称:pyomo,代码行数:18,代码来源:test_var_aggregator.py

示例14: test_gams_expanded_connectors

# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import y [as 别名]
 def test_gams_expanded_connectors(self):
     m = ConcreteModel()
     m.x = Var()
     m.y = Var()
     m.CON1 = Connector()
     m.CON1.add(m.x, 'v')
     m.CON2 = Connector()
     m.CON2.add(m.y, 'v')
     m.c = Constraint(expr=m.CON1 + m.CON2 >= 10)
     TransformationFactory("core.expand_connectors").apply_to(m)
     m.o = Objective(expr=m.x)
     os = StringIO()
     io_options = dict(symbolic_solver_labels=True)
     m.write(os, format="gams", io_options=io_options)
     # no error if we're here, but check for some identifying string
     self.assertIn("x + y", os.getvalue())
开发者ID:Pyomo,项目名称:pyomo,代码行数:18,代码来源:test_gams.py

示例15: test_negative_float_double_operator

# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import y [as 别名]
 def test_negative_float_double_operator(self):
     m = ConcreteModel()
     m.x = Var()
     m.y = Var()
     m.z = Var(bounds=(0, 6))
     m.c = Constraint(expr=(m.x * m.y * -2) == 0)
     m.c2 = Constraint(expr=m.z ** -1.5 == 0)
     m.o = Objective(expr=m.z)
     m.y.fix(-7)
     m.x.fix(4)
     lbl = NumericLabeler('x')
     smap = SymbolMap(lbl)
     tc = StorageTreeChecker(m)
     self.assertEqual(expression_to_string(
         m.c.body, tc, smap=smap), "4*(-7)*(-2)")
     self.assertEqual(expression_to_string(
         m.c2.body, tc, smap=smap), "x1 ** (-1.5)")
开发者ID:Pyomo,项目名称:pyomo,代码行数:19,代码来源:test_gams.py


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