本文整理汇总了Python中pyomo.core.ConcreteModel.a方法的典型用法代码示例。如果您正苦于以下问题:Python ConcreteModel.a方法的具体用法?Python ConcreteModel.a怎么用?Python ConcreteModel.a使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyomo.core.ConcreteModel
的用法示例。
在下文中一共展示了ConcreteModel.a方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: makeTwoTermDisj_IndexedConstraints_BoundedVars
# 需要导入模块: from pyomo.core import ConcreteModel [as 别名]
# 或者: from pyomo.core.ConcreteModel import a [as 别名]
def makeTwoTermDisj_IndexedConstraints_BoundedVars():
# same concept as above, but bounded variables
m = ConcreteModel()
m.s = Set(initialize=[1, 2])
m.lbs = Param(m.s, initialize={1: 2, 2: 4})
m.ubs = Param(m.s, initialize={1: 7, 2: 6})
def bounds_rule(m, s):
return (m.lbs[s], m.ubs[s])
m.a = Var(m.s, bounds=bounds_rule)
def d_rule(disjunct, flag):
m = disjunct.model()
def true_rule(d, s):
return m.a[s] == 0
def false_rule(d, s):
return m.a[s] >= 5
if flag:
disjunct.c = Constraint(m.s, rule=true_rule)
else:
disjunct.c = Constraint(m.s, rule=false_rule)
m.disjunct = Disjunct([0, 1], rule=d_rule)
m.disjunction = Disjunction(expr=[m.disjunct[0], m.disjunct[1]])
return m
示例2: makeTwoTermDisj
# 需要导入模块: from pyomo.core import ConcreteModel [as 别名]
# 或者: from pyomo.core.ConcreteModel import a [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
示例3: makeTwoTermIndexedDisjunction_BoundedVars
# 需要导入模块: from pyomo.core import ConcreteModel [as 别名]
# 或者: from pyomo.core.ConcreteModel import a [as 别名]
def makeTwoTermIndexedDisjunction_BoundedVars():
m = ConcreteModel()
m.s = Set(initialize=[1, 2, 3])
m.a = Var(m.s, bounds=(-100, 100))
def disjunct_rule(d, s, flag):
m = d.model()
if flag:
d.c = Constraint(expr=m.a[s] >= 6)
else:
d.c = Constraint(expr=m.a[s] <= 3)
m.disjunct = Disjunct(m.s, [0, 1], rule=disjunct_rule)
def disjunction_rule(m, s):
return [m.disjunct[s, flag] for flag in [0, 1]]
m.disjunction = Disjunction(m.s, rule=disjunction_rule)
return m
示例4: makeTwoTermMultiIndexedDisjunction
# 需要导入模块: from pyomo.core import ConcreteModel [as 别名]
# 或者: from pyomo.core.ConcreteModel import a [as 别名]
def makeTwoTermMultiIndexedDisjunction():
m = ConcreteModel()
m.s = Set(initialize=[1, 2])
m.t = Set(initialize=['A', 'B'])
m.a = Var(m.s, m.t, bounds=(2, 7))
def d_rule(disjunct, flag, s, t):
m = disjunct.model()
if flag:
disjunct.c = Constraint(expr=m.a[s, t] == 0)
else:
disjunct.c = Constraint(expr=m.a[s, t] >= 5)
m.disjunct = Disjunct([0, 1], m.s, m.t, rule=d_rule)
def disj_rule(m, s, t):
return [m.disjunct[0, s, t], m.disjunct[1, s, t]]
m.disjunction = Disjunction(m.s, m.t, rule=disj_rule)
return m
示例5: makeNestedDisjunctions
# 需要导入模块: from pyomo.core import ConcreteModel [as 别名]
# 或者: from pyomo.core.ConcreteModel import a [as 别名]
def makeNestedDisjunctions():
m = ConcreteModel()
m.x = Var(bounds=(-9, 9))
m.z = Var(bounds=(0, 10))
m.a = Var(bounds=(0, 23))
def disjunct_rule(disjunct, flag):
m = disjunct.model()
if flag:
def innerdisj_rule(disjunct, flag):
m = disjunct.model()
if flag:
disjunct.c = Constraint(expr=m.z >= 5)
else:
disjunct.c = Constraint(expr=m.z == 0)
disjunct.innerdisjunct = Disjunct([0, 1], rule=innerdisj_rule)
@disjunct.Disjunction([0])
def innerdisjunction(b, i):
return [b.innerdisjunct[0], b.innerdisjunct[1]]
disjunct.c = Constraint(expr=m.a <= 2)
else:
disjunct.c = Constraint(expr=m.x == 2)
m.disjunct = Disjunct([0, 1], rule=disjunct_rule)
# I want a SimpleDisjunct with a disjunction in it too
def simpledisj_rule(disjunct):
m = disjunct.model()
@disjunct.Disjunct()
def innerdisjunct0(disjunct):
disjunct.c = Constraint(expr=m.x <= 2)
@disjunct.Disjunct()
def innerdisjunct1(disjunct):
disjunct.c = Constraint(expr=m.x >= 4)
disjunct.innerdisjunction = Disjunction(
expr=[disjunct.innerdisjunct0, disjunct.innerdisjunct1])
m.simpledisjunct = Disjunct(rule=simpledisj_rule)
m.disjunction = Disjunction(
expr=[m.simpledisjunct, m.disjunct[0], m.disjunct[1]])
return m
示例6: makeTwoTermDisjOnBlock
# 需要导入模块: from pyomo.core import ConcreteModel [as 别名]
# 或者: from pyomo.core.ConcreteModel import a [as 别名]
def makeTwoTermDisjOnBlock():
m = ConcreteModel()
m.b = Block()
m.a = Var(bounds=(0, 5))
# On a whim, verify that the decorator notation works
@m.b.Disjunct([0, 1])
def disjunct(disjunct, flag):
m = disjunct.model()
if flag:
disjunct.c = Constraint(expr=m.a <= 3)
else:
disjunct.c = Constraint(expr=m.a == 0)
@m.b.Disjunction()
def disjunction(m):
return [m.disjunct[0], m.disjunct[1]]
return m
示例7: makeThreeTermIndexedDisj
# 需要导入模块: from pyomo.core import ConcreteModel [as 别名]
# 或者: from pyomo.core.ConcreteModel import a [as 别名]
def makeThreeTermIndexedDisj():
m = ConcreteModel()
m.s = Set(initialize=[1, 2])
m.a = Var(m.s, bounds=(2, 7))
def d_rule(disjunct, flag, s):
m = disjunct.model()
if flag == 0:
disjunct.c = Constraint(expr=m.a[s] == 0)
elif flag == 1:
disjunct.c = Constraint(expr=m.a[s] >= 5)
else:
disjunct.c = Constraint(expr=inequality(2, m.a[s], 4))
m.disjunct = Disjunct([0, 1, 2], m.s, rule=d_rule)
def disj_rule(m, s):
return [m.disjunct[0, s], m.disjunct[1, s], m.disjunct[2, s]]
m.disjunction = Disjunction(m.s, rule=disj_rule)
return m
示例8: makeDisjunctInMultipleDisjunctions_no_deactivate
# 需要导入模块: from pyomo.core import ConcreteModel [as 别名]
# 或者: from pyomo.core.ConcreteModel import a [as 别名]
def makeDisjunctInMultipleDisjunctions_no_deactivate():
m = ConcreteModel()
m.a = Var(bounds=(-10, 50))
def d1_rule(disjunct, flag):
m = disjunct.model()
if flag:
disjunct.c = Constraint(expr=m.a == 0)
else:
disjunct.c = Constraint(expr=m.a >= 5)
m.disjunct1 = Disjunct([0, 1], rule=d1_rule)
def d2_rule(disjunct, flag):
if not flag:
disjunct.c = Constraint(expr=m.a >= 30)
else:
disjunct.c = Constraint(expr=m.a == 100)
m.disjunct2 = Disjunct([0, 1], rule=d2_rule)
m.disjunction1 = Disjunction(expr=[m.disjunct1[0], m.disjunct1[1]])
m.disjunction2 = Disjunction(expr=[m.disjunct2[0], m.disjunct1[1]])
return m
示例9: makeDisjunctionsOnIndexedBlock
# 需要导入模块: from pyomo.core import ConcreteModel [as 别名]
# 或者: from pyomo.core.ConcreteModel import a [as 别名]
def makeDisjunctionsOnIndexedBlock():
m = ConcreteModel()
m.s = Set(initialize=[1, 2])
m.a = Var(m.s, bounds=(0, 70))
@m.Disjunct(m.s, [0, 1])
def disjunct1(disjunct, s, flag):
m = disjunct.model()
if not flag:
disjunct.c = Constraint(expr=m.a[s] == 0)
else:
disjunct.c = Constraint(expr=m.a[s] >= 7)
def disjunction1_rule(m, s):
return [m.disjunct1[s, flag] for flag in [0, 1]]
m.disjunction1 = Disjunction(m.s, rule=disjunction1_rule)
m.b = Block([0, 1])
m.b[0].x = Var(bounds=(-2, 2))
def disjunct2_rule(disjunct, flag):
if not flag:
disjunct.c = Constraint(expr=m.b[0].x <= 0)
else:
disjunct.c = Constraint(expr=m.b[0].x >= 0)
m.b[0].disjunct = Disjunct([0, 1], rule=disjunct2_rule)
def disjunction(b, i):
return [b.disjunct[0], b.disjunct[1]]
m.b[0].disjunction = Disjunction([0], rule=disjunction)
m.b[1].y = Var(bounds=(-3, 3))
m.b[1].disjunct0 = Disjunct()
m.b[1].disjunct0.c = Constraint(expr=m.b[1].y <= 0)
m.b[1].disjunct1 = Disjunct()
m.b[1].disjunct1.c = Constraint(expr=m.b[1].y >= 0)
m.b[1].disjunction = Disjunction(
expr=[m.b[1].disjunct0, m.b[1].disjunct1])
return m
示例10: makeTwoTermDisj_IndexedConstraints
# 需要导入模块: from pyomo.core import ConcreteModel [as 别名]
# 或者: from pyomo.core.ConcreteModel import a [as 别名]
def makeTwoTermDisj_IndexedConstraints():
m = ConcreteModel()
m.s = Set(initialize=[1, 2])
m.a = Var(m.s)
m.b = Block()
def disj1_rule(disjunct):
m = disjunct.model()
def c_rule(d, s):
return m.a[s] == 0
disjunct.c = Constraint(m.s, rule=c_rule)
m.b.simpledisj1 = Disjunct(rule=disj1_rule)
def disj2_rule(disjunct):
m = disjunct.model()
def c_rule(d, s):
return m.a[s] <= 3
disjunct.c = Constraint(m.s, rule=c_rule)
m.b.simpledisj2 = Disjunct(rule=disj2_rule)
m.b.disjunction = Disjunction(expr=[m.b.simpledisj1, m.b.simpledisj2])
return m