当前位置: 首页>>代码示例>>Python>>正文


Python environ.value函数代码示例

本文整理汇总了Python中pyomo.environ.value函数的典型用法代码示例。如果您正苦于以下问题:Python value函数的具体用法?Python value怎么用?Python value使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了value函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_acos

 def test_acos(self):
     m = pe.Block(concrete=True)
     m.x = pe.Var()
     m.c = pe.Constraint(expr=pe.inequality(body=pe.acos(m.x), lower=1, upper=2))
     fbbt(m)
     self.assertAlmostEqual(pe.value(m.x.lb), math.cos(2))
     self.assertAlmostEqual(pe.value(m.x.ub), math.cos(1))
开发者ID:mskarha,项目名称:pyomo,代码行数:7,代码来源:test_fbbt.py

示例2: test_GDP_nonlinear_objective

    def test_GDP_nonlinear_objective(self):
        m = ConcreteModel()
        m.x = Var(bounds=(-1, 10))
        m.y = Var(bounds=(2, 3))
        m.d = Disjunction(expr=[
            [m.x + m.y >= 5], [m.x - m.y <= 3]
        ])
        m.o = Objective(expr=m.x ** 2)
        SolverFactory('gdpopt').solve(
            m, strategy='LOA',
            mip_solver=mip_solver,
            nlp_solver=nlp_solver
        )
        self.assertAlmostEqual(value(m.o), 0)

        m = ConcreteModel()
        m.x = Var(bounds=(-1, 10))
        m.y = Var(bounds=(2, 3))
        m.d = Disjunction(expr=[
            [m.x + m.y >= 5], [m.x - m.y <= 3]
        ])
        m.o = Objective(expr=-m.x ** 2, sense=maximize)
        SolverFactory('gdpopt').solve(
            m, strategy='LOA',
            mip_solver=mip_solver,
            nlp_solver=nlp_solver
        )
        self.assertAlmostEqual(value(m.o), 0)
开发者ID:Pyomo,项目名称:pyomo,代码行数:28,代码来源:test_gdpopt.py

示例3: save_cost_components

def save_cost_components(m, outdir):
    """
    Save values for all individual components of total system cost on NPV basis.
    """
    cost_dict = dict()
    for annual_cost in m.Cost_Components_Per_Period:
        cost = getattr(m, annual_cost)
        # note: storing value() instead of the expression may save
        # some memory while this function runs
        cost_dict[annual_cost] = value(sum(
            cost[p] * m.bring_annual_costs_to_base_year[p]
            for p in m.PERIODS
        ))
    for tp_cost in m.Cost_Components_Per_TP:
        cost = getattr(m, tp_cost)
        cost_dict[tp_cost] = value(sum(
            cost[t] * m.tp_weight_in_year[t]
            * m.bring_annual_costs_to_base_year[m.tp_period[t]]
            for t in m.TIMEPOINTS
        ))
    write_table(
        m,
        cost_dict.keys(),
        output_file=os.path.join(outdir, "cost_components.tab"),
        headings=('component', 'npv_cost'),
        values=lambda m, c: (c, cost_dict[c]),
        digits=16
    )
开发者ID:switch-model,项目名称:switch,代码行数:28,代码来源:__init__.py

示例4: test_atan

 def test_atan(self):
     m = pe.Block(concrete=True)
     m.x = pe.Var()
     m.c = pe.Constraint(expr=pe.inequality(body=pe.atan(m.x), lower=-0.5, upper=0.5))
     fbbt(m)
     self.assertAlmostEqual(pe.value(m.x.lb), math.tan(-0.5))
     self.assertAlmostEqual(pe.value(m.x.ub), math.tan(0.5))
开发者ID:mskarha,项目名称:pyomo,代码行数:7,代码来源:test_fbbt.py

示例5: test_ignore_nonlinear

    def test_ignore_nonlinear(self):
        m = ConcreteModel()
        m.v1 = Var()
        m.c1 = Constraint(expr=m.v1 * m.v1 >= 2)

        self.assertEqual(value(m.c1.lower), 2)
        self.assertFalse(m.c1.has_ub())
        TransformationFactory('core.tighten_constraints_from_vars').apply_to(m)
        self.assertEqual(value(m.c1.lower), 2)
        self.assertFalse(m.c1.has_ub())
开发者ID:Pyomo,项目名称:pyomo,代码行数:10,代码来源:test_constraint_tightener.py

示例6: test_pow

 def test_pow(self):
     m = pe.ConcreteModel()
     m.x = pe.Var(initialize=2.0)
     m.y = pe.Var(initialize=3.0)
     e = m.x ** m.y
     derivs = reverse_ad(e)
     symbolic = reverse_sd(e)
     self.assertAlmostEqual(derivs[m.x], pe.value(symbolic[m.x]), tol+3)
     self.assertAlmostEqual(derivs[m.y], pe.value(symbolic[m.y]), tol+3)
     self.assertAlmostEqual(derivs[m.x], approx_deriv(e, m.x), tol)
     self.assertAlmostEqual(derivs[m.y], approx_deriv(e, m.y), tol)
开发者ID:Pyomo,项目名称:pyomo,代码行数:11,代码来源:test_derivs.py

示例7: approx_deriv

def approx_deriv(expr, wrt, delta=0.001):
    numerator = 0
    wrt.value += 2*delta
    numerator -= pe.value(expr)
    wrt.value -= delta
    numerator += 8*pe.value(expr)
    wrt.value -= 2*delta
    numerator -= 8*pe.value(expr)
    wrt.value -= delta
    numerator += pe.value(expr)
    wrt.value += 2*delta
    return numerator / (12*delta)
开发者ID:Pyomo,项目名称:pyomo,代码行数:12,代码来源:test_derivs.py

示例8: test_less_than_constraint

    def test_less_than_constraint(self):
        m = ConcreteModel()
        m.v1 = Var(initialize=7, bounds=(7, 10))
        m.v2 = Var(initialize=2, bounds=(2, 5))
        m.v3 = Var(initialize=6, bounds=(6, 9))
        m.v4 = Var(initialize=1, bounds=(1, 1))
        m.c1 = Constraint(expr=m.v1 <= m.v2 + m.v3 + m.v4)

        self.assertEqual(value(m.c1.upper), 0)
        self.assertFalse(m.c1.has_lb())
        TransformationFactory('core.tighten_constraints_from_vars').apply_to(m)
        self.assertEqual(value(m.c1.upper), 0)
        self.assertEqual(value(m.c1.lower), -8)
开发者ID:Pyomo,项目名称:pyomo,代码行数:13,代码来源:test_constraint_tightener.py

示例9: test_add

 def test_add(self):
     x_bounds = [(-2.5, 2.8), (-2.5, -0.5), (0.5, 2.8), (-2.5, 0), (0, 2.8), (-2.5, -1), (1, 2.8), (-1, -0.5), (0.5, 1)]
     c_bounds = [(-2.5, 2.8), (-2.5, -0.5), (0.5, 2.8), (-2.5, 0), (0, 2.8), (-2.5, -1), (1, 2.8), (-1, -0.5), (0.5, 1)]
     for xl, xu in x_bounds:
         for cl, cu in c_bounds:
             m = pe.Block(concrete=True)
             m.x = pe.Var(bounds=(xl, xu))
             m.y = pe.Var()
             m.p = pe.Param(mutable=True)
             m.p.value = 1
             m.c = pe.Constraint(expr=pe.inequality(body=m.x+m.y+(m.p+1), lower=cl, upper=cu))
             new_bounds = fbbt(m)
             self.assertEqual(new_bounds[m.x], (pe.value(m.x.lb), pe.value(m.x.ub)))
             self.assertEqual(new_bounds[m.y], (pe.value(m.y.lb), pe.value(m.y.ub)))
             x = np.linspace(pe.value(m.x.lb), pe.value(m.x.ub), 100)
             z = np.linspace(pe.value(m.c.lower), pe.value(m.c.upper), 100)
             if m.y.lb is None:
                 yl = -np.inf
             else:
                 yl = m.y.lb
             if m.y.ub is None:
                 yu = np.inf
             else:
                 yu = m.y.ub
             for _x in x:
                 _y = z - _x - m.p.value - 1
                 self.assertTrue(np.all(yl <= _y))
                 self.assertTrue(np.all(yu >= _y))
开发者ID:mskarha,项目名称:pyomo,代码行数:28,代码来源:test_fbbt.py

示例10: test_cos

    def test_cos(self):
        m = pe.Block(concrete=True)
        m.x = pe.Var(bounds=(0, math.pi))
        m.c = pe.Constraint(expr=pe.inequality(body=pe.cos(m.x), lower=-0.5, upper=0.5))
        fbbt(m)
        self.assertAlmostEqual(pe.value(m.x.lb), math.acos(0.5))
        self.assertAlmostEqual(pe.value(m.x.ub), math.acos(-0.5))

        m = pe.Block(concrete=True)
        m.x = pe.Var()
        m.c = pe.Constraint(expr=pe.inequality(body=pe.cos(m.x), lower=-0.5, upper=0.5))
        fbbt(m)
        self.assertEqual(m.x.lb, None)
        self.assertEqual(m.x.ub, None)
开发者ID:mskarha,项目名称:pyomo,代码行数:14,代码来源:test_fbbt.py

示例11: test_unbounded_var

    def test_unbounded_var(self):
        """test with unbounded variables"""
        m = ConcreteModel()
        m.v1 = Var(initialize=7)
        m.v2 = Var(initialize=2, bounds=(2, 5))
        m.v3 = Var(initialize=6, bounds=(6, 9))
        m.v4 = Var(initialize=1, bounds=(1, 1))
        m.c1 = Constraint(expr=m.v1 <= 2 * m.v2 + m.v3 + m.v4)

        self.assertEqual(value(m.c1.upper), 0)
        self.assertFalse(m.c1.has_lb())
        TransformationFactory('core.tighten_constraints_from_vars').apply_to(m)
        self.assertEqual(value(m.c1.upper), 0)
        self.assertFalse(m.c1.has_lb())
开发者ID:Pyomo,项目名称:pyomo,代码行数:14,代码来源:test_constraint_tightener.py

示例12: test_unbounded_one_direction

    def test_unbounded_one_direction(self):
        """Unbounded in one direction"""
        m = ConcreteModel()
        m.v1 = Var(initialize=7, bounds=(-float('inf'), 10))
        m.v2 = Var(initialize=2, bounds=(2, 5))
        m.v3 = Var(initialize=6, bounds=(6, 9))
        m.v4 = Var(initialize=1, bounds=(1, 1))
        m.c1 = Constraint(expr=m.v1 <= 2 * m.v2 + m.v3 + m.v4)

        self.assertEqual(value(m.c1.upper), 0)
        self.assertFalse(m.c1.has_lb())
        TransformationFactory('core.tighten_constraints_from_vars').apply_to(m)
        self.assertEqual(value(m.c1.upper), -1)
        self.assertFalse(m.c1.has_lb())
开发者ID:Pyomo,项目名称:pyomo,代码行数:14,代码来源:test_constraint_tightener.py

示例13: test_nested

 def test_nested(self):
     m = pe.ConcreteModel()
     m.x = pe.Var(initialize=2)
     m.y = pe.Var(initialize=3)
     m.p = pe.Param(initialize=0.5, mutable=True)
     e = pe.exp(m.x**m.p + 3.2*m.y - 12)
     derivs = reverse_ad(e)
     symbolic = reverse_sd(e)
     self.assertAlmostEqual(derivs[m.x], pe.value(symbolic[m.x]), tol+3)
     self.assertAlmostEqual(derivs[m.y], pe.value(symbolic[m.y]), tol+3)
     self.assertAlmostEqual(derivs[m.p], pe.value(symbolic[m.p]), tol+3)
     self.assertAlmostEqual(derivs[m.x], approx_deriv(e, m.x), tol)
     self.assertAlmostEqual(derivs[m.y], approx_deriv(e, m.y), tol)
     self.assertAlmostEqual(derivs[m.p], approx_deriv(e, m.p), tol)
开发者ID:Pyomo,项目名称:pyomo,代码行数:14,代码来源:test_derivs.py

示例14: test_constraint_bound_tightening

    def test_constraint_bound_tightening(self):
        # Check for no coefficients
        m = ConcreteModel()
        m.v1 = Var(initialize=7, bounds=(7, 10))
        m.v2 = Var(initialize=2, bounds=(2, 5))
        m.v3 = Var(initialize=6, bounds=(6, 9))
        m.v4 = Var(initialize=1, bounds=(1, 1))
        m.c1 = Constraint(expr=m.v1 >= m.v2 + m.v3 + m.v4 + 1)

        self.assertEqual(value(m.c1.upper), 0)
        self.assertFalse(m.c1.has_lb())
        TransformationFactory('core.tighten_constraints_from_vars').apply_to(m)
        self.assertEqual(value(m.c1.upper), 0)
        self.assertEqual(value(m.c1.lower), 0)
开发者ID:Pyomo,项目名称:pyomo,代码行数:14,代码来源:test_constraint_tightener.py

示例15: test_constraint_with_coef

    def test_constraint_with_coef(self):
        """Test with coefficient on constraint."""
        m = ConcreteModel()
        m.v1 = Var(initialize=7, bounds=(7, 10))
        m.v2 = Var(initialize=2, bounds=(2, 5))
        m.v3 = Var(initialize=6, bounds=(6, 9))
        m.v4 = Var(initialize=1, bounds=(1, 1))
        m.c1 = Constraint(expr=m.v1 <= 2 * m.v2 + m.v3 + m.v4)

        self.assertEqual(value(m.c1.upper), 0)
        self.assertFalse(m.c1.has_lb())
        TransformationFactory('core.tighten_constraints_from_vars').apply_to(m)
        self.assertEqual(value(m.c1.upper), -1)
        self.assertEqual(value(m.c1.lower), -13)
开发者ID:Pyomo,项目名称:pyomo,代码行数:14,代码来源:test_constraint_tightener.py


注:本文中的pyomo.environ.value函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。