How to use the pyomo.environ.value function in Pyomo

To help you get started, we’ve selected a few Pyomo examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github grid-parity-exchange / Egret / egret / models / acopf.py View on Github external
b_dict['vm'] = value(m.vm[b])
            b_dict['va'] = value(m.va[b])

    for k, k_dict in branches.items():
        if hasattr(m,'pf'):
            k_dict['pf'] = value(m.pf[k])
            k_dict['pt'] = value(m.pt[k])
            k_dict['qf'] = value(m.qf[k])
            k_dict['qt'] = value(m.qt[k])
        if hasattr(m,'irf'):
            b = k_dict['from_bus']
            k_dict['pf'] = value(tx_calc.calculate_p(value(m.ifr[k]), value(m.ifj[k]), value(m.vr[b]), value(m.vj[b])))
            k_dict['qf'] = value(tx_calc.calculate_q(value(m.ifr[k]), value(m.ifj[k]), value(m.vr[b]), value(m.vj[b])))
            b = k_dict['to_bus']
            k_dict['pt'] = value(tx_calc.calculate_p(value(m.itr[k]), value(m.itj[k]), value(m.vr[b]), value(m.vj[b])))
            k_dict['qt'] = value(tx_calc.calculate_q(value(m.itr[k]), value(m.itj[k]), value(m.vr[b]), value(m.vj[b])))


    unscale_ModelData_to_pu(md, inplace=True)

    if return_model and return_results:
        return md, m, results
    elif return_model:
        return md, m
    elif return_results:
        return md, results
    return md
github IDAES / idaes-pse / idaes / core / util / scaling.py View on Github external
large: Magnitude that is considered to be too large
        small: Magnitude that is considered to be too small
        zero: Magnitude that is considered to be zero, variables with a value of
            zero are okay, and not reported.

    Yields:
        variable data object, current absolute value of scaled value
    """
    for v in blk.component_data_objects(pyo.Var):
        if v.fixed:
            continue
        try:
            sf = v.parent_block().scaling_factor.get(v, 1)
        except AttributeError:  # no scaling factor suffix
            sf = 1
        sv = abs(pyo.value(v) * sf)  # scaled value
        if sv > large:
            yield v, sv
        elif sv < zero:
            continue
        elif sv < small:
            yield v, sv
github sandialabs / chama / chama / design.py View on Github external
"""
        
        # Right now, this function expects a multiindex, but that will change....
        impact = impact.set_index(['Scenario', 'Sensor'])

        model = self._create_pyomo_model(impact, sensor_dict, sensor_budget)
        self._solve_pyomo_model(model, tee=tee, keepfiles=keepfiles)

        selected_sensors = []
        sensor_impact = dict()
        for key in model.y:
            if pe.value(model.y[key]) > 0.5:
                sensor_impact[key] = 0
                selected_sensors.append(key)

        obj_value = pe.value(model.obj)

        for key in model.x:
            if pe.value(model.x[key]) > 0.5:
                sensor_impact[key[1]] += 1
                
        return {'selected_sensors': selected_sensors, 'objective_value': obj_value, 'sensor_impact': sensor_impact}
github Pyomo / pyomo / pyomo / contrib / pynumero / examples / gas_network_model.py View on Github external
def s_bounds_rule(m, k, j, t):
        return 0.01, aml.value(m.smax[j])
    model.s = aml.Var(model.SCEN, model.SUP, model.TIME, bounds=s_bounds_rule, initialize=10.0)
github IDAES / idaes-pse / idaes / core / util / scaling.py View on Github external
sf = 1
            r[id(v)] = v / sf
            v.value = orig[i] * sf
        vis = EXPR.ExpressionReplacementVisitor(
            substitute=r,
            remove_named_expressions=True,
        )
        e = vis.dfs_postorder_stack(ex)
    else:
        e = ex

    for i, v in enumerate(vars):
        ov = pyo.value(v)  # original variable value
        f1 = pyo.value(e)
        v.value = ov + h
        f2 = pyo.value(e)
        v.value = ov
        if scaled:
            try:
                sf = c.parent_block().scaling_factor.get(c, 1)
            except AttributeError:
                sf = 1
            grad[i] = sf * (f2 - f1) / h
        else:
            grad[i] = (f2 - f1) / h

    if scaled:
        for i, v in enumerate(vars):
            v.value = orig[i]

    return grad, vars
github Pyomo / pyomo / pyomo / contrib / benders / benders_cuts.py View on Github external
b.objective = pe.Objective(expr=b._z)
    b.dual = pe.Suffix(direction=pe.Suffix.IMPORT)
    b._eta = pe.Var()

    b.aux_cons = pe.ConstraintList()
    for c in list(b.component_data_objects(pe.Constraint, descend_into=True, active=True, sort=True)):
        if c.equality:
            body = c.body
            rhs = pe.value(c.lower)
            body -= rhs
            b.aux_cons.add(body - b._z <= 0)
            b.aux_cons.add(-body - b._z <= 0)
            _del_con(c)
        else:
            body = c.body
            lower = pe.value(c.lower)
            upper = pe.value(c.upper)
            if upper is not None:
                body_upper = body - upper - b._z
                b.aux_cons.add(body_upper <= 0)
            if lower is not None:
                body_lower = body - lower
                body_lower = -body_lower
                body_lower -= b._z
                b.aux_cons.add(body_lower <= 0)
            _del_con(c)

    b.obj_con = pe.Constraint(expr=orig_obj_expr - b._eta - b._z <= 0)
github grid-parity-exchange / Egret / egret / models / copperplate_dispatch.py View on Github external
symbolic_solver_labels=symbolic_solver_labels,solver_options=options)

    md = model_data.clone_in_service()

    # save results data to ModelData object
    gens = dict(md.elements(element_type='generator'))
    buses = dict(md.elements(element_type='bus'))

    md.data['system']['total_cost'] = value(m.obj)

    for g,g_dict in gens.items():
        g_dict['pg'] = value(m.pg[g])

    for b,b_dict in buses.items():
        b_dict['pl'] = value(m.pl[b])
        b_dict['lmp'] = value(m.dual[m.eq_p_balance])

    unscale_ModelData_to_pu(md, inplace=True)

    if return_model and return_results:
        return md, m, results
    elif return_model:
        return md, m
    elif return_results:
        return md, results
    return md
github IDAES / idaes-pse / idaes / property_models / examples / BFW_properties.py View on Github external
def model_check(blk):
        """Model checks for property block."""
        # Check temperature bounds
        if value(blk.temperature) < blk.temperature.lb:
            _log.error('{} Temperature set below lower bound.'
                       .format(blk.name))
        if value(blk.temperature) > blk.temperature.ub:
            _log.error('{} Temperature set above upper bound.'
                       .format(blk.name))

        # Check pressure bounds
        if value(blk.pressure) < blk.pressure.lb:
            _log.error('{} Pressure set below lower bound.'.format(blk.name))
        if value(blk.pressure) > blk.pressure.ub:
            _log.error('{} Pressure set above upper bound.'.format(blk.name))