本文整理汇总了Python中pyomo.core.ConcreteModel.component_data_objects方法的典型用法代码示例。如果您正苦于以下问题:Python ConcreteModel.component_data_objects方法的具体用法?Python ConcreteModel.component_data_objects怎么用?Python ConcreteModel.component_data_objects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyomo.core.ConcreteModel
的用法示例。
在下文中一共展示了ConcreteModel.component_data_objects方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_deactivate_nested_disjunction
# 需要导入模块: from pyomo.core import ConcreteModel [as 别名]
# 或者: from pyomo.core.ConcreteModel import component_data_objects [as 别名]
def test_deactivate_nested_disjunction(self):
m = ConcreteModel()
m.d1 = Disjunct()
m.d1.d1 = Disjunct()
m.d1.d2 = Disjunct()
m.d1.disj = Disjunction(expr=[m.d1.d1, m.d1.d2])
m.d2 = Disjunct()
m.disj = Disjunction(expr=[m.d1, m.d2])
m.d1.deactivate()
TransformationFactory('gdp.bigm').apply_to(m)
# for disj in m.component_data_objects(Disjunction, active=True):
# print(disj.name)
# There should be no active Disjunction objects.
self.assertIsNone(
next(m.component_data_objects(Disjunction, active=True), None))
示例2: ComponentPerformanceBase
# 需要导入模块: from pyomo.core import ConcreteModel [as 别名]
# 或者: from pyomo.core.ConcreteModel import component_data_objects [as 别名]
class ComponentPerformanceBase(object):
@classmethod
def _create_model(self, ctype, **kwds):
self.model = ConcreteModel()
self.model.x = Var()
self.model.IDX = Set(initialize=sorted(range(1000000)))
self.model.del_component('test_component')
self.model.test_component = \
ctype(self.model.IDX, **kwds)
@classmethod
def setUp(self):
if self.model is None:
self._setup()
@classmethod
def setUpClass(self):
self.model = None
@classmethod
def tearDownClass(self):
self.model = None
def test_0_setup(self):
# Needed so that the time to set up the model is not included in
# the subsequent performance tests. This test is named so that
# it should appear first in the set of tests run by this test class
pass
def test_iteration(self):
cnt = 0
for cdata in self.model.component_data_objects(self.model.test_component.type()):
cnt += 1
self.assertTrue(cnt > 0)
if self.model.test_component.type() in (Set, Var):
self.assertEqual(cnt,
len(self.model.test_component) + 1)
else:
self.assertEqual(cnt,
len(self.model.test_component))