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


Python ConcreteModel.z方法代碼示例

本文整理匯總了Python中pyomo.core.ConcreteModel.z方法的典型用法代碼示例。如果您正苦於以下問題:Python ConcreteModel.z方法的具體用法?Python ConcreteModel.z怎麽用?Python ConcreteModel.z使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pyomo.core.ConcreteModel的用法示例。


在下文中一共展示了ConcreteModel.z方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_indexedvar_noindextemplate

# 需要導入模塊: from pyomo.core import ConcreteModel [as 別名]
# 或者: from pyomo.core.ConcreteModel import z [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)
開發者ID:SemanticBeeng,項目名稱:pyomo,代碼行數:36,代碼來源:test_scenariotree.py

示例2: test_singletonvar_wildcardtemplate

# 需要導入模塊: from pyomo.core import ConcreteModel [as 別名]
# 或者: from pyomo.core.ConcreteModel import z [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)
開發者ID:SemanticBeeng,項目名稱:pyomo,代碼行數:35,代碼來源:test_scenariotree.py

示例3: test_lmtd

# 需要導入模塊: from pyomo.core import ConcreteModel [as 別名]
# 或者: from pyomo.core.ConcreteModel import z [as 別名]
 def test_lmtd(self):
     m = ConcreteModel()
     m.x = Var(bounds=(0.1, 500), initialize=33.327)
     m.y = Var(bounds=(0.1, 500), initialize=14.436)
     m.z = Var(bounds=(0, 90), initialize=22.5653)
     mc_expr = mc(m.z - (m.x * m.y * (m.x + m.y) / 2) ** (1/3))
     self.assertAlmostEqual(mc_expr.convex(), -407.95444629965016)
     self.assertAlmostEqual(mc_expr.lower(), -499.99999999999983)
開發者ID:mskarha,項目名稱:pyomo,代碼行數:10,代碼來源:test_mcpp.py

示例4: test_trig

# 需要導入模塊: from pyomo.core import ConcreteModel [as 別名]
# 或者: from pyomo.core.ConcreteModel import z [as 別名]
 def test_trig(self):
     m = ConcreteModel()
     m.x = Var(bounds=(pi / 4, pi / 2), initialize=pi / 4)
     mc_expr = mc(tan(atan((m.x))))
     self.assertAlmostEqual(mc_expr.lower(), pi / 4)
     self.assertAlmostEqual(mc_expr.upper(), pi / 2)
     m.y = Var(bounds=(0, sin(pi / 4)), initialize=0)
     mc_expr = mc(asin((m.y)))
     self.assertEqual(mc_expr.lower(), 0)
     self.assertAlmostEqual(mc_expr.upper(), pi / 4)
     m.z = Var(bounds=(0, cos(pi / 4)), initialize=0)
     mc_expr = mc(acos((m.z)))
     self.assertAlmostEqual(mc_expr.lower(), pi / 4)
     self.assertAlmostEqual(mc_expr.upper(), pi / 2)
開發者ID:mskarha,項目名稱:pyomo,代碼行數:16,代碼來源:test_mcpp.py

示例5: test_powers

# 需要導入模塊: from pyomo.core import ConcreteModel [as 別名]
# 或者: from pyomo.core.ConcreteModel import z [as 別名]
 def test_powers(self):
     m = ConcreteModel()
     m.x = Var(bounds=(0, 2), initialize=1)
     m.y = Var(bounds=(1e-4, 2), initialize=1)
     with self.assertRaisesRegexp(MCPP_Error, "Log with negative values in range"):
         mc(m.x ** 1.5)
     mc_expr = mc(m.y ** 1.5)
     self.assertAlmostEqual(mc_expr.lower(), 1e-4**1.5)
     self.assertAlmostEqual(mc_expr.upper(), 2**1.5)
     mc_expr = mc(m.y ** m.x)
     self.assertAlmostEqual(mc_expr.lower(), 1e-4**2)
     self.assertAlmostEqual(mc_expr.upper(), 4)
     m.z = Var(bounds=(-1, 1), initialize=0)
     mc_expr = mc(m.z ** 2)
     self.assertAlmostEqual(mc_expr.lower(), 0)
     self.assertAlmostEqual(mc_expr.upper(), 1)
開發者ID:mskarha,項目名稱:pyomo,代碼行數:18,代碼來源:test_mcpp.py

示例6: makeNestedDisjunctions

# 需要導入模塊: from pyomo.core import ConcreteModel [as 別名]
# 或者: from pyomo.core.ConcreteModel import z [as 別名]
def makeNestedDisjunctions():
    m = ConcreteModel()
    m.x = Var(bounds=(-9, 9))
    m.z = Var(bounds=(0, 10))
    m.a = Var(bounds=(0, 23))

    def disjunct_rule(disjunct, flag):
        m = disjunct.model()
        if flag:
            def innerdisj_rule(disjunct, flag):
                m = disjunct.model()
                if flag:
                    disjunct.c = Constraint(expr=m.z >= 5)
                else:
                    disjunct.c = Constraint(expr=m.z == 0)
            disjunct.innerdisjunct = Disjunct([0, 1], rule=innerdisj_rule)

            @disjunct.Disjunction([0])
            def innerdisjunction(b, i):
                return [b.innerdisjunct[0], b.innerdisjunct[1]]
            disjunct.c = Constraint(expr=m.a <= 2)
        else:
            disjunct.c = Constraint(expr=m.x == 2)
    m.disjunct = Disjunct([0, 1], rule=disjunct_rule)
    # I want a SimpleDisjunct with a disjunction in it too

    def simpledisj_rule(disjunct):
        m = disjunct.model()

        @disjunct.Disjunct()
        def innerdisjunct0(disjunct):
            disjunct.c = Constraint(expr=m.x <= 2)

        @disjunct.Disjunct()
        def innerdisjunct1(disjunct):
            disjunct.c = Constraint(expr=m.x >= 4)

        disjunct.innerdisjunction = Disjunction(
            expr=[disjunct.innerdisjunct0, disjunct.innerdisjunct1])
    m.simpledisjunct = Disjunct(rule=simpledisj_rule)
    m.disjunction = Disjunction(
        expr=[m.simpledisjunct, m.disjunct[0], m.disjunct[1]])
    return m
開發者ID:Pyomo,項目名稱:pyomo,代碼行數:45,代碼來源:models.py


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