本文整理匯總了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))