本文整理汇总了Python中pyomo.environ.ConcreteModel.massbal5方法的典型用法代码示例。如果您正苦于以下问题:Python ConcreteModel.massbal5方法的具体用法?Python ConcreteModel.massbal5怎么用?Python ConcreteModel.massbal5使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyomo.environ.ConcreteModel
的用法示例。
在下文中一共展示了ConcreteModel.massbal5方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: build_eight_process_flowsheet
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import massbal5 [as 别名]
def build_eight_process_flowsheet():
"""Build flowsheet for the 8 process problem."""
m = ConcreteModel(name='DuranEx3 Disjunctive')
"""Set declarations"""
m.streams = RangeSet(2, 25, doc="process streams")
m.units = RangeSet(1, 8, doc="process units")
"""Parameter and initial point declarations"""
# FIXED COST INVESTMENT COEFF FOR PROCESS UNITS
# Format: process #: cost
fixed_cost = {1: 5, 2: 8, 3: 6, 4: 10, 5: 6, 6: 7, 7: 4, 8: 5}
CF = m.CF = Param(m.units, initialize=fixed_cost)
# VARIABLE COST COEFF FOR PROCESS UNITS - STREAMS
# Format: stream #: cost
variable_cost = {3: -10, 5: -15, 9: -40, 19: 25, 21: 35, 25: -35,
17: 80, 14: 15, 10: 15, 2: 1, 4: 1, 18: -65, 20: -60,
22: -80}
CV = m.CV = Param(m.streams, initialize=variable_cost, default=0)
# initial point information for stream flows
initX = {2: 2, 3: 1.5, 6: 0.75, 7: 0.5, 8: 0.5, 9: 0.75, 11: 1.5,
12: 1.34, 13: 2, 14: 2.5, 17: 2, 18: 0.75, 19: 2, 20: 1.5,
23: 1.7, 24: 1.5, 25: 0.5}
"""Variable declarations"""
# FLOWRATES OF PROCESS STREAMS
m.flow = Var(m.streams, domain=NonNegativeReals, initialize=initX,
bounds=(0, 10))
# OBJECTIVE FUNCTION CONSTANT TERM
CONSTANT = m.constant = Param(initialize=122.0)
"""Constraint definitions"""
# INPUT-OUTPUT RELATIONS FOR process units 1 through 8
m.use_unit1 = Disjunct()
m.use_unit1.inout1 = Constraint(expr=exp(m.flow[3]) - 1 == m.flow[2])
m.use_unit1.no_unit2_flow1 = Constraint(expr=m.flow[4] == 0)
m.use_unit1.no_unit2_flow2 = Constraint(expr=m.flow[5] == 0)
m.use_unit2 = Disjunct()
m.use_unit2.inout2 = Constraint(
expr=exp(m.flow[5] / 1.2) - 1 == m.flow[4])
m.use_unit2.no_unit1_flow1 = Constraint(expr=m.flow[2] == 0)
m.use_unit2.no_unit1_flow2 = Constraint(expr=m.flow[3] == 0)
m.use_unit3 = Disjunct()
m.use_unit3.inout3 = Constraint(
expr=1.5 * m.flow[9] + m.flow[10] == m.flow[8])
m.no_unit3 = Disjunct()
m.no_unit3.no_unit3_flow1 = Constraint(expr=m.flow[9] == 0)
m.no_unit3.flow_pass_through = Constraint(expr=m.flow[10] == m.flow[8])
m.use_unit4 = Disjunct()
m.use_unit4.inout4 = Constraint(
expr=1.25 * (m.flow[12] + m.flow[14]) == m.flow[13])
m.use_unit4.no_unit5_flow = Constraint(expr=m.flow[15] == 0)
m.use_unit5 = Disjunct()
m.use_unit5.inout5 = Constraint(expr=m.flow[15] == 2 * m.flow[16])
m.use_unit5.no_unit4_flow1 = Constraint(expr=m.flow[12] == 0)
m.use_unit5.no_unit4_flow2 = Constraint(expr=m.flow[14] == 0)
m.no_unit4or5 = Disjunct()
m.no_unit4or5.no_unit5_flow = Constraint(expr=m.flow[15] == 0)
m.no_unit4or5.no_unit4_flow1 = Constraint(expr=m.flow[12] == 0)
m.no_unit4or5.no_unit4_flow2 = Constraint(expr=m.flow[14] == 0)
m.use_unit6 = Disjunct()
m.use_unit6.inout6 = Constraint(
expr=exp(m.flow[20] / 1.5) - 1 == m.flow[19])
m.use_unit6.no_unit7_flow1 = Constraint(expr=m.flow[21] == 0)
m.use_unit6.no_unit7_flow2 = Constraint(expr=m.flow[22] == 0)
m.use_unit7 = Disjunct()
m.use_unit7.inout7 = Constraint(expr=exp(m.flow[22]) - 1 == m.flow[21])
m.use_unit7.no_unit6_flow1 = Constraint(expr=m.flow[19] == 0)
m.use_unit7.no_unit6_flow2 = Constraint(expr=m.flow[20] == 0)
m.no_unit6or7 = Disjunct()
m.no_unit6or7.no_unit7_flow1 = Constraint(expr=m.flow[21] == 0)
m.no_unit6or7.no_unit7_flow2 = Constraint(expr=m.flow[22] == 0)
m.no_unit6or7.no_unit6_flow = Constraint(expr=m.flow[19] == 0)
m.no_unit6or7.no_unit6_flow2 = Constraint(expr=m.flow[20] == 0)
m.use_unit8 = Disjunct()
m.use_unit8.inout8 = Constraint(
expr=exp(m.flow[18]) - 1 == m.flow[10] + m.flow[17])
m.no_unit8 = Disjunct()
m.no_unit8.no_unit8_flow1 = Constraint(expr=m.flow[10] == 0)
m.no_unit8.no_unit8_flow2 = Constraint(expr=m.flow[17] == 0)
m.no_unit8.no_unit8_flow3 = Constraint(expr=m.flow[18] == 0)
# Mass balance equations
m.massbal1 = Constraint(expr=m.flow[13] == m.flow[19] + m.flow[21])
m.massbal2 = Constraint(
expr=m.flow[17] == m.flow[9] + m.flow[16] + m.flow[25])
m.massbal3 = Constraint(expr=m.flow[11] == m.flow[12] + m.flow[15])
m.massbal4 = Constraint(
expr=m.flow[3] + m.flow[5] == m.flow[6] + m.flow[11])
m.massbal5 = Constraint(expr=m.flow[6] == m.flow[7] + m.flow[8])
m.massbal6 = Constraint(expr=m.flow[23] == m.flow[20] + m.flow[22])
m.massbal7 = Constraint(expr=m.flow[23] == m.flow[14] + m.flow[24])
# process specifications
#.........这里部分代码省略.........
示例2: build_eight_process_flowsheet
# 需要导入模块: from pyomo.environ import ConcreteModel [as 别名]
# 或者: from pyomo.environ.ConcreteModel import massbal5 [as 别名]
#.........这里部分代码省略.........
m.flow[2] == 0,
m.flow[3] == 0]
])
m.use_unit_3ornot = Disjunction(
expr=[
# Use unit 3 disjunct
[m.yCF[3] == m.CF[3],
1.5 * m.flow[9] + m.flow[10] == m.flow[8]],
# No unit 3 disjunct
[m.flow[9] == 0,
m.flow[10] == m.flow[8]]
])
m.use_unit_4or5ornot = Disjunction(
expr=[
# Use unit 4 disjunct
[m.yCF[4] == m.CF[4],
1.25 * (m.flow[12] + m.flow[14]) == m.flow[13],
m.flow[15] == 0],
# Use unit 5 disjunct
[m.yCF[5] == m.CF[5],
m.flow[15] == 2 * m.flow[16],
m.flow[12] == 0,
m.flow[14] == 0],
# No unit 4 or 5 disjunct
[m.flow[15] == 0,
m.flow[12] == 0,
m.flow[14] == 0]
])
m.use_unit_6or7ornot = Disjunction(
expr=[
# use unit 6 disjunct
[m.yCF[6] == m.CF[6],
exp(m.flow[20] / 1.5) - 1 == m.flow[19],
m.flow[21] == 0,
m.flow[22] == 0],
# use unit 7 disjunct
[m.yCF[7] == m.CF[7],
exp(m.flow[22]) - 1 == m.flow[21],
m.flow[19] == 0,
m.flow[20] == 0],
# No unit 6 or 7 disjunct
[m.flow[21] == 0,
m.flow[22] == 0,
m.flow[19] == 0,
m.flow[20] == 0]
])
m.use_unit_8ornot = Disjunction(
expr=[
# use unit 8 disjunct
[m.yCF[8] == m.CF[8],
exp(m.flow[18]) - 1 == m.flow[10] + m.flow[17]],
# no unit 8 disjunct
[m.flow[10] == 0,
m.flow[17] == 0,
m.flow[18] == 0]
])
# Mass balance equations
m.massbal1 = Constraint(expr=m.flow[13] == m.flow[19] + m.flow[21])
m.massbal2 = Constraint(
expr=m.flow[17] == m.flow[9] + m.flow[16] + m.flow[25])
m.massbal3 = Constraint(expr=m.flow[11] == m.flow[12] + m.flow[15])
m.massbal4 = Constraint(
expr=m.flow[3] + m.flow[5] == m.flow[6] + m.flow[11])
m.massbal5 = Constraint(expr=m.flow[6] == m.flow[7] + m.flow[8])
m.massbal6 = Constraint(expr=m.flow[23] == m.flow[20] + m.flow[22])
m.massbal7 = Constraint(expr=m.flow[23] == m.flow[14] + m.flow[24])
# process specifications
m.specs1 = Constraint(expr=m.flow[10] <= 0.8 * m.flow[17])
m.specs2 = Constraint(expr=m.flow[10] >= 0.4 * m.flow[17])
m.specs3 = Constraint(expr=m.flow[12] <= 5 * m.flow[14])
m.specs4 = Constraint(expr=m.flow[12] >= 2 * m.flow[14])
# pure integer constraints
m.use4implies6or7 = Constraint(
expr=m.use_unit_6or7ornot.disjuncts[0].indicator_var +
m.use_unit_6or7ornot.disjuncts[1].indicator_var -
m.use_unit_4or5ornot.disjuncts[0].indicator_var == 0)
m.use3implies8 = Constraint(
expr=m.use_unit_3ornot.disjuncts[0].indicator_var
- m.use_unit_8ornot.disjuncts[0].indicator_var <= 0)
"""Profit (objective) function definition"""
m.profit = Objective(expr=sum(
m.yCF[unit]
for unit in m.units) +
sum(m.flow[stream] * CV[stream]
for stream in m.streams) + CONSTANT,
sense=minimize)
"""Bound definitions"""
# x (flow) upper bounds
x_ubs = {3: 2, 5: 2, 9: 2, 10: 1, 14: 1, 17: 2, 19: 2, 21: 2, 25: 3}
for i, x_ub in iteritems(x_ubs):
m.flow[i].setub(x_ub)
# Optimal solution uses units 2, 4, 6, 8 with objective value 68.
return m