當前位置: 首頁>>代碼示例>>Python>>正文


Python ConcreteModel.component_data_objects方法代碼示例

本文整理匯總了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))
開發者ID:Pyomo,項目名稱:pyomo,代碼行數:17,代碼來源:test_reclassify.py

示例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))
開發者ID:Pyomo,項目名稱:pyomo,代碼行數:42,代碼來源:test_component_perf.py


注:本文中的pyomo.core.ConcreteModel.component_data_objects方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。