Exemplo n.º 1
0
def _include_feasibility_slack(model, bus_names, bus_p_loads, bus_q_loads,
                               gens_by_bus, gen_attrs,
                               p_marginal_slack_penalty, q_marginal_slack_penalty):
    
    import egret.model_library.decl as decl

    p_over_gen_bounds = {k: (0, tx_utils.over_gen_limit(bus_p_loads[k], gens_by_bus[k], gen_attrs['p_max'])) for k in bus_names}
    decl.declare_var('p_over_generation', model=model, index_set=bus_names,
                     initialize=0., bounds=p_over_gen_bounds
                     )

    p_load_shed_bounds  = {k: (0, tx_utils.load_shed_limit(bus_p_loads[k], gens_by_bus[k], gen_attrs['p_min'])) for k in bus_names}
    decl.declare_var('p_load_shed', model=model, index_set=bus_names,
                     initialize=0., bounds=p_load_shed_bounds
                     )

    q_over_gen_bounds = {k: (0, tx_utils.over_gen_limit(bus_q_loads[k], gens_by_bus[k], gen_attrs['q_max'])) for k in bus_names}
    decl.declare_var('q_over_generation', model=model, index_set=bus_names,
                     initialize=0., bounds=q_over_gen_bounds
                     )

    q_load_shed_bounds  = {k: (0, tx_utils.load_shed_limit(bus_q_loads[k], gens_by_bus[k], gen_attrs['q_min'])) for k in bus_names}
    decl.declare_var('q_load_shed', model=model, index_set=bus_names,
                     initialize=0., bounds=q_load_shed_bounds
                     )
    p_rhs_kwargs = {'include_feasibility_load_shed':'p_load_shed', 'include_feasibility_over_generation':'p_over_generation'}
    q_rhs_kwargs = {'include_feasibility_load_shed':'q_load_shed', 'include_feasibility_over_generation':'q_over_generation'}

    penalty_expr = sum(p_marginal_slack_penalty * (model.p_over_generation[bus_name] + model.p_load_shed[bus_name])
                     + q_marginal_slack_penalty * (model.q_over_generation[bus_name] + model.q_load_shed[bus_name])
                    for bus_name in bus_names)
    return p_rhs_kwargs, q_rhs_kwargs, penalty_expr
def _include_system_feasibility_slack(model, bus_p_loads, gen_attrs,
                                      p_marginal_slack_penalty):
    import egret.model_library.decl as decl
    load = sum(bus_p_loads.values())

    over_gen_bounds = (0,
                       tx_utils.over_gen_limit(load, gen_attrs['names'],
                                               gen_attrs['p_max']))
    decl.declare_var('p_over_generation',
                     model=model,
                     index_set=None,
                     initialize=0.,
                     bounds=over_gen_bounds)

    load_shed_bounds = (0,
                        tx_utils.load_shed_limit(load, gen_attrs['names'],
                                                 gen_attrs['p_min']))
    decl.declare_var('p_load_shed',
                     model=model,
                     index_set=None,
                     initialize=0.,
                     bounds=load_shed_bounds)
    p_rhs_kwargs = {
        'include_feasibility_load_shed': 'p_load_shed',
        'include_feasibility_over_generation': 'p_over_generation'
    }
    penalty_expr = p_marginal_slack_penalty * (model.p_load_shed +
                                               model.p_over_generation)
    return p_rhs_kwargs, penalty_expr