本文整理汇总了Python中pyomo.core.ConcreteModel.s方法的典型用法代码示例。如果您正苦于以下问题:Python ConcreteModel.s方法的具体用法?Python ConcreteModel.s怎么用?Python ConcreteModel.s使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyomo.core.ConcreteModel
的用法示例。
在下文中一共展示了ConcreteModel.s方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: makeTwoTermDisj_IndexedConstraints_BoundedVars
# 需要导入模块: from pyomo.core import ConcreteModel [as 别名]
# 或者: from pyomo.core.ConcreteModel import s [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: test_indexedvar_noindextemplate
# 需要导入模块: from pyomo.core import ConcreteModel [as 别名]
# 或者: from pyomo.core.ConcreteModel import s [as 别名]
def test_indexedvar_noindextemplate(self):
st_model = CreateConcreteTwoStageScenarioTreeModel(1)
st_model.StageVariables['Stage1'].add("x")
st_model.StageDerivedVariables['Stage1'].add("y")
st_model.NodeVariables['RootNode'].add("z")
st_model.NodeDerivedVariables['RootNode'].add("q")
st_model.StageCost['Stage1'] = "FirstStageCost"
st_model.StageCost['Stage2'] = "SecondStageCost"
scenario_tree = ScenarioTree(scenariotreeinstance=st_model)
self.assertEqual(len(scenario_tree.stages), 2)
self.assertEqual(len(scenario_tree.nodes), 2)
self.assertEqual(len(scenario_tree.scenarios), 1)
model = ConcreteModel()
model.s = Set(initialize=[1,2,3])
model.x = Var(model.s)
model.y = Var(model.s)
model.z = Var(model.s)
model.q = Var(model.s)
model.FirstStageCost = Expression(expr=0.0)
model.SecondStageCost = Expression(expr=0.0)
model.obj = Objective(expr=0.0)
scenario_tree.linkInInstances({'Scenario1': model})
root = scenario_tree.findRootNode()
self.assertEqual(len(root._variable_ids), 12)
self.assertEqual(len(root._standard_variable_ids), 6)
self.assertEqual(len(root._derived_variable_ids), 6)
for name in ("x", "y", "z", "q"):
for index in model.s:
self.assertEqual(
(name,index) in root._name_index_to_id, True)
示例3: test_do_not_reactivate_disjuncts_with_abandon
# 需要导入模块: from pyomo.core import ConcreteModel [as 别名]
# 或者: from pyomo.core.ConcreteModel import s [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)
示例4: makeTwoTermIndexedDisjunction_BoundedVars
# 需要导入模块: from pyomo.core import ConcreteModel [as 别名]
# 或者: from pyomo.core.ConcreteModel import s [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
示例5: makeTwoTermMultiIndexedDisjunction
# 需要导入模块: from pyomo.core import ConcreteModel [as 别名]
# 或者: from pyomo.core.ConcreteModel import s [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
示例6: _get_block_model
# 需要导入模块: from pyomo.core import ConcreteModel [as 别名]
# 或者: from pyomo.core.ConcreteModel import s [as 别名]
def _get_block_model(self):
model = ConcreteModel()
model.s = Set(initialize=[1,2])
b = Block(concrete=True)
b.s = Set(initialize=[1,2])
b.x = Var()
b.X = Var(model.s)
model.b1 = b.clone()
model.b2 = b.clone()
model.b3 = b.clone()
model.b4 = b.clone()
model.B1 = Block(model.s, rule=lambda _,i: b.clone())
model.B2 = Block(model.s, rule=lambda _,i: b.clone())
model.B3 = Block(model.s, rule=lambda _,i: b.clone())
model.B4 = Block(model.s, rule=lambda _,i: b.clone())
model.FirstStageCost = Expression(expr=0.0)
model.SecondStageCost = Expression(expr=0.0)
model.obj = Objective(expr=0.0)
return model
示例7: makeThreeTermIndexedDisj
# 需要导入模块: from pyomo.core import ConcreteModel [as 别名]
# 或者: from pyomo.core.ConcreteModel import s [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: makeDisjunctionsOnIndexedBlock
# 需要导入模块: from pyomo.core import ConcreteModel [as 别名]
# 或者: from pyomo.core.ConcreteModel import s [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
示例9: makeTwoTermDisj_IndexedConstraints
# 需要导入模块: from pyomo.core import ConcreteModel [as 别名]
# 或者: from pyomo.core.ConcreteModel import s [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