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


Python ConcreteModel.d方法代码示例

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


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

示例1: test_do_not_reactivate_disjuncts_with_abandon

# 需要导入模块: from pyomo.core import ConcreteModel [as 别名]
# 或者: from pyomo.core.ConcreteModel import d [as 别名]
 def test_do_not_reactivate_disjuncts_with_abandon(self):
     m = ConcreteModel()
     m.x = Var()
     m.s = RangeSet(4)
     m.d = Disjunct(m.s)
     m.d[2].bad_constraint_should_not_be_active = Constraint(expr=m.x >= 1)
     m.disj1 = Disjunction(expr=[m.d[1], m.d[2]])
     m.disj2 = Disjunction(expr=[m.d[3], m.d[4]])
     m.d[1].indicator_var.fix(1)
     m.d[2].deactivate()
     TransformationFactory('gdp.bigm').apply_to(m)
     self.assertFalse(m.d[2].active)
开发者ID:Pyomo,项目名称:pyomo,代码行数:14,代码来源:test_reclassify.py

示例2: build_model

# 需要导入模块: from pyomo.core import ConcreteModel [as 别名]
# 或者: from pyomo.core.ConcreteModel import d [as 别名]
def build_model(use_mccormick=False):
    """Build the GDP model."""
    m = ConcreteModel()
    m.F = Var(bounds=(0, 8), doc="Flow into reactor")
    m.X = Var(bounds=(0, 1), doc="Reactor conversion")
    m.d = Param(initialize=2, doc="Max product demand")
    m.c = Param([1, 2, 'I', 'II'], doc="Costs", initialize={
        1: 2,  # Value of product
        2: 0.2,  # Cost of raw material
        'I': 2.5,  # Cost of reactor I
        'II': 1.5  # Cost of reactor II
    })
    m.alpha = Param(['I', 'II'], doc="Reactor coefficient",
                    initialize={'I': -8, 'II': -10})
    m.beta = Param(['I', 'II'], doc="Reactor coefficient",
                   initialize={'I': 9, 'II': 15})
    m.X_LB = Param(['I', 'II'], doc="Reactor conversion lower bound",
                   initialize={'I': 0.2, 'II': 0.7})
    m.X_UB = Param(['I', 'II'], doc="Reactor conversion upper bound",
                   initialize={'I': 0.95, 'II': 0.99})
    m.C_rxn = Var(bounds=(1.5, 2.5), doc="Cost of reactor")
    m.reactor_choice = Disjunction(expr=[
        # Disjunct 1: Choose reactor I
        [m.F == m.alpha['I'] * m.X + m.beta['I'],
         m.X_LB['I'] <= m.X,
         m.X <= m.X_UB['I'],
         m.C_rxn == m.c['I']],
        # Disjunct 2: Choose reactor II
        [m.F == m.alpha['II'] * m.X + m.beta['II'],
         m.X_LB['II'] <= m.X,
         m.X <= m.X_UB['II'],
         m.C_rxn == m.c['II']]
    ], xor=True)
    if use_mccormick:
        m.P = Var(bounds=(0, 8), doc="McCormick approximation of F*X")
        m.mccormick_1 = Constraint(
            expr=m.P <= m.F.lb * m.X + m.F * m.X.ub - m.F.lb * m.X.ub,
            doc="McCormick overestimator")
        m.mccormick_2 = Constraint(
            expr=m.P <= m.F.ub * m.X + m.F * m.X.lb - m.F.ub * m.X.lb,
            doc="McCormick underestimator")
        m.max_demand = Constraint(expr=m.P <= m.d, doc="product demand")
        m.profit = Objective(
            expr=m.c[1] * m.P - m.c[2] * m.F - m.C_rxn, sense=maximize)
    else:
        m.max_demand = Constraint(expr=m.F * m.X <= m.d, doc="product demand")
        m.profit = Objective(
            expr=m.c[1] * m.F * m.X - m.c[2] * m.F - m.C_rxn, sense=maximize)

    return m
开发者ID:Pyomo,项目名称:pyomo,代码行数:52,代码来源:two_rxn_model.py

示例3: makeThreeTermDisj_IndexedConstraints

# 需要导入模块: from pyomo.core import ConcreteModel [as 别名]
# 或者: from pyomo.core.ConcreteModel import d [as 别名]
def makeThreeTermDisj_IndexedConstraints():
    m = ConcreteModel()
    m.I = [1, 2, 3]
    m.x = Var(m.I, bounds=(0, 10))

    def c_rule(b, i):
        m = b.model()
        return m.x[i] >= i

    def d_rule(d, j):
        m = d.model()
        d.c = Constraint(m.I[:j], rule=c_rule)
    m.d = Disjunct(m.I, rule=d_rule)
    m.disjunction = Disjunction(expr=[m.d[i] for i in m.I])
    return m
开发者ID:Pyomo,项目名称:pyomo,代码行数:17,代码来源:models.py

示例4: makeTwoTermDisj

# 需要导入模块: from pyomo.core import ConcreteModel [as 别名]
# 或者: from pyomo.core.ConcreteModel import d [as 别名]
def makeTwoTermDisj():
    m = ConcreteModel()
    m.a = Var(bounds=(2, 7))
    m.x = Var(bounds=(4, 9))

    def d_rule(disjunct, flag):
        m = disjunct.model()
        if flag:
            disjunct.c1 = Constraint(expr=m.a == 0)
            disjunct.c2 = Constraint(expr=m.x <= 7)
        else:
            disjunct.c = Constraint(expr=m.a >= 5)
    m.d = Disjunct([0, 1], rule=d_rule)
    m.disjunction = Disjunction(expr=[m.d[0], m.d[1]])
    return m
开发者ID:Pyomo,项目名称:pyomo,代码行数:17,代码来源:models.py

示例5: makeTwoTermDisj_Nonlinear

# 需要导入模块: from pyomo.core import ConcreteModel [as 别名]
# 或者: from pyomo.core.ConcreteModel import d [as 别名]
def makeTwoTermDisj_Nonlinear():
    m = ConcreteModel()
    m.w = Var(bounds=(2, 7))
    m.x = Var(bounds=(1, 8))
    m.y = Var(bounds=(-10, -3))

    def d_rule(disjunct, flag):
        m = disjunct.model()
        if flag:
            disjunct.c1 = Constraint(expr=m.x >= 2)
            disjunct.c2 = Constraint(expr=m.w == 3)
            disjunct.c3 = Constraint(expr=(1, m.x, 3))
        else:
            disjunct.c = Constraint(expr=m.x + m.y**2 <= 14)
    m.d = Disjunct([0, 1], rule=d_rule)
    m.disjunction = Disjunction(expr=[m.d[0], m.d[1]])
    return m
开发者ID:Pyomo,项目名称:pyomo,代码行数:19,代码来源:models.py


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