<commit_before>"""
constraint for curtailment requirements for a single timestep `t` 
for collection of fluctuating generetors `RES`

- ``\\sum_{\\forall i \\in RES}\\left(\\boldsymbol{p_{i,g}}^t-p_{i,g}^t\\right)= \\boldsymbol{P^t_{curtail}}``

### Arguments

- `pm::GenericPowerModel{T} where T <: PowerModels.AbstractBFForm` PowerModel
- `nw::Int` timestep
"""
function constraint_curtailment_single(pm;nw::Int=pm.cnw)
    # get collection of fluctuating generators
    RES = ids(pm,:fluct_gen)
    pg = var(pm,nw,:pg)
    qg = var(pm,nw,:pg)
    # make RES controllable
    for i in RES
        setlowerbound(pg[i],0)
        @constraint(pm.model, qg[i] == pg[i] * getupperbound(qg[i]) / getupperbound(pg[i]))
    end

    look_up_load_ids = Dict()
    for (load_ids, val) in nw_ref[:load]
       look_up_load_ids[val["load_bus"]] = load_ids
    end
    loads = Set(values(look_up_load_ids))

    pd = var(pm,nw,:pd)
    qd = var(pm,nw,:qd)
    for i in loads
        @constraint(pm.model, qd[i] == pd[i] * getupperbound(qd[i]) / getupperbound(pd[i]))
    end

    # get requirement for curtailment in timestep nw
    # P_curtail = ref(pm,nw,:curtailment)
    #P_curtail = pm.data["curtailment_requirement_series"][nw]
    #@constraint(pm.model, sum(getupperbound(pg[i]) - pg[i] for i in RES)==P_curtail)
end

"""
constraint for acceptable curtailment over entire time horizon `T`
for collection of fluctuating generetors `RES`

- ``\\sum_{\\forall t \\in T}\\left[\\sum_{\\forall i \\in E}\\left(\\boldsymbol{p_{i,g}}^t-p_{i,g}^t\\right)\\right]\\leq \\boldsymbol{P_{curtail,tot}}``

### Arguments

- `pm::GenericPowerModel{T} where T <: PowerModels.AbstractBFForm` PowerModel
"""
function constraint_curtailment_allowed(pm)
    RES = ids(pm,:fluct_gen)
    sum_curtail = 0
    for (nw,net) in nws(pm)
        pg = var(pm,nw,:pg)
        # make RES controllable
        for i in RES
            setlowerbound(pg[i],0)
        end
        sum_curtail += sum(getupperbound(pg[i]) - pg[i] for i in RES)
    end
    P_curtail_tot = pm.data["curtailment_total"]
    @constraint(pm.model,sum_curtail<=P_curtail_tot)
    return sum_curtail<commit_msg>Comment load reactive power constraint<commit_after>"""
constraint for curtailment requirements for a single timestep `t` 
for collection of fluctuating generetors `RES`

- ``\\sum_{\\forall i \\in RES}\\left(\\boldsymbol{p_{i,g}}^t-p_{i,g}^t\\right)= \\boldsymbol{P^t_{curtail}}``

### Arguments

- `pm::GenericPowerModel{T} where T <: PowerModels.AbstractBFForm` PowerModel
- `nw::Int` timestep
"""
function constraint_curtailment_single(pm;nw::Int=pm.cnw)
    # get collection of fluctuating generators
    RES = ids(pm,:fluct_gen)
    pg = var(pm,nw,:pg)
    qg = var(pm,nw,:pg)
    # make RES controllable
    for i in RES
        setlowerbound(pg[i],0)
        @constraint(pm.model, qg[i] == pg[i] * getupperbound(qg[i]) / getupperbound(pg[i]))
    end

#     pd = var(pm,nw,:pd)
#     qd = var(pm,nw,:qd)
#     for i in ids(pm, nw, :load)
#         try
#             @constraint(pm.model, qd[i] == pd[i] * getupperbound(qd[i]) / getupperbound(pd[i]))
#         catch e
#             println
#         end
#     end

    # get requirement for curtailment in timestep nw
    # P_curtail = ref(pm,nw,:curtailment)
    #P_curtail = pm.data["curtailment_requirement_series"][nw]
    #@constraint(pm.model, sum(getupperbound(pg[i]) - pg[i] for i in RES)==P_curtail)
end

"""
constraint for acceptable curtailment over entire time horizon `T`
for collection of fluctuating generetors `RES`

- ``\\sum_{\\forall t \\in T}\\left[\\sum_{\\forall i \\in E}\\left(\\boldsymbol{p_{i,g}}^t-p_{i,g}^t\\right)\\right]\\leq \\boldsymbol{P_{curtail,tot}}``

### Arguments

- `pm::GenericPowerModel{T} where T <: PowerModels.AbstractBFForm` PowerModel
"""
function constraint_curtailment_allowed(pm)
    RES = ids(pm,:fluct_gen)
    sum_curtail = 0
    for (nw,net) in nws(pm)
        pg = var(pm,nw,:pg)
        # make RES controllable
        for i in RES
            setlowerbound(pg[i],0)
        end
        sum_curtail += sum(getupperbound(pg[i]) - pg[i] for i in RES)
    end
    P_curtail_tot = pm.data["curtailment_total"]
    @constraint(pm.model,sum_curtail<=P_curtail_tot)
    return sum_curtail
{'fraction_non_alphanumeric': 0.15763430725730443, 'fraction_numerical': 0.001413760603204524, 'mean_word_length': 3.496822033898305, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4232581', 'n_tokens_mistral': 1606, 'n_tokens_neox': 1564, 'n_words': 326}