本文整理汇总了Python中pyomo.core.ConcreteModel.q方法的典型用法代码示例。如果您正苦于以下问题:Python ConcreteModel.q方法的具体用法?Python ConcreteModel.q怎么用?Python ConcreteModel.q使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyomo.core.ConcreteModel
的用法示例。
在下文中一共展示了ConcreteModel.q方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_indexedvar_noindextemplate
# 需要导入模块: from pyomo.core import ConcreteModel [as 别名]
# 或者: from pyomo.core.ConcreteModel import q [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 q [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)