本文整理匯總了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)
示例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
示例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
示例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
示例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