当前位置: 首页>>代码示例>>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;未经允许,请勿转载。