本文整理匯總了Python中pyomo.core.ConcreteModel.FirstStageCost方法的典型用法代碼示例。如果您正苦於以下問題:Python ConcreteModel.FirstStageCost方法的具體用法?Python ConcreteModel.FirstStageCost怎麽用?Python ConcreteModel.FirstStageCost使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pyomo.core.ConcreteModel
的用法示例。
在下文中一共展示了ConcreteModel.FirstStageCost方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_indexedvar_noindextemplate
# 需要導入模塊: from pyomo.core import ConcreteModel [as 別名]
# 或者: from pyomo.core.ConcreteModel import FirstStageCost [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)
示例2: test_singletonvar_wildcardtemplate
# 需要導入模塊: from pyomo.core import ConcreteModel [as 別名]
# 或者: from pyomo.core.ConcreteModel import FirstStageCost [as 別名]
def test_singletonvar_wildcardtemplate(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.x = Var()
model.y = Var()
model.z = Var()
model.q = Var()
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), 4)
self.assertEqual(len(root._standard_variable_ids), 2)
self.assertEqual(len(root._derived_variable_ids), 2)
for name in ("x", "y", "z", "q"):
for index in [None]:
self.assertEqual(
(name,index) in root._name_index_to_id, True)
示例3: _get_block_model
# 需要導入模塊: from pyomo.core import ConcreteModel [as 別名]
# 或者: from pyomo.core.ConcreteModel import FirstStageCost [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