switch_model/policies/rps_by_load_zone.py
def define_components(mod):
    """
    
    f_rps_eligible[f in FUELS] is a binary parameter that flags each fuel as
    elegible for RPS accounting or not.
    
    RPS_ENERGY_SOURCES is a set enumerating all energy sources that contribute
    to RPS accounting. It is built by union of all fuels that are RPS elegible
    and the NON_FUEL_ENERGY_SOURCES set.
    
    RPS_PERIODS is a subset of PERIODS for which RPS goals are defined.
    
    rps_target[z in LOAD_ZONES, p in RPS_PERIODS] is the fraction of total 
    energy generated in a load zone during a period that has to be provided 
    by RPS-elegible sources.
    
    RPSProjFuelPower[g, t in _FUEL_BASED_GEN_TPS] is an
    expression summarizing the power generated by RPS-elegible fuels in every
    fuel-based project. This cannot be simply taken to be equal to the
    dispatch level of the project, since a mix of RPS-elegible and unelegible
    fuels may be being consumed to produce that power. This expression is only
    valid when unit commitment is being ignored.
    
    RPSFuelEnergy[z, p] is an expression that sums all the energy produced in a 
    load zone z using RPS-elegible fuels in fuel-based projects in a given period.
    
    RPSNonFuelEnergy[z, p] is an expression that sums all the energy produced 
    in a load zone z using non-fuel sources in a given period.
    
    TotalGenerationInPeriod[p] is an expression that sums all the energy
    produced in a given period by all projects. This has to be calculated and
    cannot be taken to be equal to the total load in the period, because
    transmission losses could exist.
    
    RPS_Enforce_Target[z, p] is the constraint that forces energy produced by
    renewable sources in a load zone z to meet a fraction of the total energy 
    produced in the period.
    
    Useful:     
    GENS_IN_ZONE[z in LOAD_ZONES] is an indexed set that lists all
    generation projects within each load zone.
    
    """

    mod.ZONE_PERIODS = Set(
        dimen=2, within=mod.LOAD_ZONES * mod.PERIODS)
            
    mod.f_rps_eligible = Param(
        mod.FUELS,
        within=Boolean,
        default=False)
    mod.RPS_ENERGY_SOURCES = Set(
        initialize=lambda m: set(m.NON_FUEL_ENERGY_SOURCES) | \
            set(f for f in m.FUELS if m.f_rps_eligible[f]))

    mod.RPS_PERIODS = Set(
        dimen=1,
        validate=lambda m, p: p in m.PERIODS)
    mod.rps_target = Param(
        mod.ZONE_PERIODS,
        within=NonNegativeReals,
        validate=lambda m, val, z, p: val <= 1.0)

    mod.RPSFuelEnergy = Expression(
        mod.ZONE_PERIODS,
        rule=lambda m, z, p: sum(
            sum(m.GenFuelUseRate[g, t, f] for f in m.FUELS_FOR_GEN[g]
                if m.f_rps_eligible[f]) / m.gen_full_load_heat_rate[g] *
                m.tp_weight[t]
                    for g in m.FUEL_BASED_GENS if g in m.GENS_IN_ZONE[z]
                    	for t in m.TPS_FOR_GEN_IN_PERIOD[g, p]))
    mod.RPSNonFuelEnergy = Expression(
        mod.ZONE_PERIODS,
        rule=lambda m, z, p: sum(m.DispatchGen[g, t] * m.tp_weight[t]
            for g in m.NON_FUEL_BASED_GENS if g in m.GENS_IN_ZONE[z]
               	for t in m.TPS_FOR_GEN_IN_PERIOD[g, p]))

    mod.RPS_Enforce_Target = Constraint(
        mod.ZONE_PERIODS,
        rule=lambda m, z, p: (m.RPSFuelEnergy[z, p] + m.RPSNonFuelEnergy[z, p] >=
            m.rps_target[z, p] * m.zone_total_demand_in_period_mwh[z, p]))

    
    f_rps_eligible[f in FUELS] is a binary parameter that flags each fuel as
    elegible for RPS accounting or not.
    
    RPS_ENERGY_SOURCES is a set enumerating all energy sources that contribute
    to RPS accounting. It is built by union of all fuels that are RPS elegible
    and the NON_FUEL_ENERGY_SOURCES set.
    
    RPS_PERIODS is a subset of PERIODS for which RPS goals are defined.
    
    rps_target[z in LOAD_ZONES, p in RPS_PERIODS] is the fraction of total 
    energy generated in a load zone during a period that has to be provided 
    by RPS-elegible sources.
    
    RPSProjFuelPower[g, t in _FUEL_BASED_GEN_TPS] is an
    expression summarizing the power generated by RPS-elegible fuels in every
    fuel-based project. This cannot be simply taken to be equal to the
    dispatch level of the project, since a mix of RPS-elegible and unelegible
    fuels may be being consumed to produce that power. This expression is only
    valid when unit commitment is being ignored.
    
    RPSFuelEnergy[z, p] is an expression that sums all the energy produced in a 
    load zone z using RPS-elegible fuels in fuel-based projects in a given period.
    
    RPSNonFuelEnergy[z, p] is an expression that sums all the energy produced 
    in a load zone z using non-fuel sources in a given period.
    
    TotalGenerationInPeriod[p] is an expression that sums all the energy
    produced in a given period by all projects. This has to be calculated and
    cannot be taken to be equal to the total load in the period, because
    transmission losses could exist.
    
    RPS_Enforce_Target[z, p] is the constraint that forces energy produced by
    renewable sources in a load zone z to meet a fraction of the total energy 
    produced in the period.
    
    Useful:     
    GENS_IN_ZONE[z in LOAD_ZONES] is an indexed set that lists all
    generation projects within each load zone.
    
    
f_rps_eligible[f in FUELS] is a binary parameter that flags each fuel as
elegible for RPS accounting or not.

RPS_ENERGY_SOURCES is a set enumerating all energy sources that contribute
to RPS accounting. It is built by union of all fuels that are RPS elegible
and the NON_FUEL_ENERGY_SOURCES set.

RPS_PERIODS is a subset of PERIODS for which RPS goals are defined.

rps_target[z in LOAD_ZONES, p in RPS_PERIODS] is the fraction of total
energy generated in a load zone during a period that has to be provided
by RPS-elegible sources.

RPSProjFuelPower[g, t in _FUEL_BASED_GEN_TPS] is an
expression summarizing the power generated by RPS-elegible fuels in every
fuel-based project. This cannot be simply taken to be equal to the
dispatch level of the project, since a mix of RPS-elegible and unelegible
fuels may be being consumed to produce that power. This expression is only
valid when unit commitment is being ignored.

RPSFuelEnergy[z, p] is an expression that sums all the energy produced in a
load zone z using RPS-elegible fuels in fuel-based projects in a given period.

RPSNonFuelEnergy[z, p] is an expression that sums all the energy produced
in a load zone z using non-fuel sources in a given period.

TotalGenerationInPeriod[p] is an expression that sums all the energy
produced in a given period by all projects. This has to be calculated and
cannot be taken to be equal to the total load in the period, because
transmission losses could exist.

RPS_Enforce_Target[z, p] is the constraint that forces energy produced by
renewable sources in a load zone z to meet a fraction of the total energy
produced in the period.

GENS_IN_ZONE[z in LOAD_ZONES] is an indexed set that lists all
generation projects within each load zone.
f_rps_eligible [ f in FUELS ] is a binary parameter that flags each fuel as elegible for RPS accounting or not . RPS_ENERGY_SOURCES is a set enumerating all energy sources that contribute to RPS accounting . It is built by union of all fuels that are RPS elegible and the NON_FUEL_ENERGY_SOURCES set . RPS_PERIODS is a subset of PERIODS for which RPS goals are defined . rps_target [ z in LOAD_ZONES p in RPS_PERIODS ] is the fraction of total energy generated in a load zone during a period that has to be provided by RPS - elegible sources . RPSProjFuelPower [ g t in _FUEL_BASED_GEN_TPS ] is an expression summarizing the power generated by RPS - elegible fuels in every fuel - based project . This cannot be simply taken to be equal to the dispatch level of the project since a mix of RPS - elegible and unelegible fuels may be being consumed to produce that power . This expression is only valid when unit commitment is being ignored . RPSFuelEnergy [ z p ] is an expression that sums all the energy produced in a load zone z using RPS - elegible fuels in fuel - based projects in a given period . RPSNonFuelEnergy [ z p ] is an expression that sums all the energy produced in a load zone z using non - fuel sources in a given period . TotalGenerationInPeriod [ p ] is an expression that sums all the energy produced in a given period by all projects . This has to be calculated and cannot be taken to be equal to the total load in the period because transmission losses could exist . RPS_Enforce_Target [ z p ] is the constraint that forces energy produced by renewable sources in a load zone z to meet a fraction of the total energy produced in the period . GENS_IN_ZONE [ z in LOAD_ZONES ] is an indexed set that lists all generation projects within each load zone .
def define_components(mod):
    mod.ZONE_PERIODS = Set(
        dimen=2, within=mod.LOAD_ZONES * mod.PERIODS)
    mod.f_rps_eligible = Param(
        mod.FUELS,
        within=Boolean,
        default=False)
    mod.RPS_ENERGY_SOURCES = Set(
        initialize=lambda m: set(m.NON_FUEL_ENERGY_SOURCES) | \
            set(f for f in m.FUELS if m.f_rps_eligible[f]))
    mod.RPS_PERIODS = Set(
        dimen=1,
        validate=lambda m, p: p in m.PERIODS)
    mod.rps_target = Param(
        mod.ZONE_PERIODS,
        within=NonNegativeReals,
        validate=lambda m, val, z, p: val <= 1.0)
    mod.RPSFuelEnergy = Expression(
        mod.ZONE_PERIODS,
        rule=lambda m, z, p: sum(
            sum(m.GenFuelUseRate[g, t, f] for f in m.FUELS_FOR_GEN[g]
                if m.f_rps_eligible[f]) / m.gen_full_load_heat_rate[g] *
                m.tp_weight[t]
                    for g in m.FUEL_BASED_GENS if g in m.GENS_IN_ZONE[z]
                    	for t in m.TPS_FOR_GEN_IN_PERIOD[g, p]))
    mod.RPSNonFuelEnergy = Expression(
        mod.ZONE_PERIODS,
        rule=lambda m, z, p: sum(m.DispatchGen[g, t] * m.tp_weight[t]
            for g in m.NON_FUEL_BASED_GENS if g in m.GENS_IN_ZONE[z]
               	for t in m.TPS_FOR_GEN_IN_PERIOD[g, p]))
    mod.RPS_Enforce_Target = Constraint(
        mod.ZONE_PERIODS,
        rule=lambda m, z, p: (m.RPSFuelEnergy[z, p] + m.RPSNonFuelEnergy[z, p] >=
            m.rps_target[z, p] * m.zone_total_demand_in_period_mwh[z, p]))
def define_components ( mod ) : mod . ZONE_PERIODS = Set ( dimen = 2 , within = mod . LOAD_ZONES * mod . PERIODS ) mod . f_rps_eligible = Param ( mod . FUELS , within = Boolean , default = False ) mod . RPS_ENERGY_SOURCES = Set ( initialize = lambda m : set ( m . NON_FUEL_ENERGY_SOURCES ) | set ( f for f in m . FUELS if m . f_rps_eligible [ f ] ) ) mod . RPS_PERIODS = Set ( dimen = 1 , validate = lambda m , p : p in m . PERIODS ) mod . rps_target = Param ( mod . ZONE_PERIODS , within = NonNegativeReals , validate = lambda m , val , z , p : val <= 1.0 ) mod . RPSFuelEnergy = Expression ( mod . ZONE_PERIODS , rule = lambda m , z , p : sum ( sum ( m . GenFuelUseRate [ g , t , f ] for f in m . FUELS_FOR_GEN [ g ] if m . f_rps_eligible [ f ] ) / m . gen_full_load_heat_rate [ g ] * m . tp_weight [ t ] for g in m . FUEL_BASED_GENS if g in m . GENS_IN_ZONE [ z ] for t in m . TPS_FOR_GEN_IN_PERIOD [ g , p ] ) ) mod . RPSNonFuelEnergy = Expression ( mod . ZONE_PERIODS , rule = lambda m , z , p : sum ( m . DispatchGen [ g , t ] * m . tp_weight [ t ] for g in m . NON_FUEL_BASED_GENS if g in m . GENS_IN_ZONE [ z ] for t in m . TPS_FOR_GEN_IN_PERIOD [ g , p ] ) ) mod . RPS_Enforce_Target = Constraint ( mod . ZONE_PERIODS , rule = lambda m , z , p : ( m . RPSFuelEnergy [ z , p ] + m . RPSNonFuelEnergy [ z , p ] >= m . rps_target [ z , p ] * m . zone_total_demand_in_period_mwh [ z , p ] ) )
f_rps_eligible[f in FUELS] is a binary parameter that flags each fuel as
elegible for RPS accounting or not.
f_rps_eligible [ f in FUELS ] is a binary parameter that flags each fuel as elegible for RPS accounting or not .
"""
    
    f_rps_eligible[f in FUELS] is a binary parameter that flags each fuel as
    elegible for RPS accounting or not.
    
    RPS_ENERGY_SOURCES is a set enumerating all energy sources that contribute
    to RPS accounting. It is built by union of all fuels that are RPS elegible
    and the NON_FUEL_ENERGY_SOURCES set.
    
    RPS_PERIODS is a subset of PERIODS for which RPS goals are defined.
    
    rps_target[z in LOAD_ZONES, p in RPS_PERIODS] is the fraction of total 
    energy generated in a load zone during a period that has to be provided 
    by RPS-elegible sources.
    
    RPSProjFuelPower[g, t in _FUEL_BASED_GEN_TPS] is an
    expression summarizing the power generated by RPS-elegible fuels in every
    fuel-based project. This cannot be simply taken to be equal to the
    dispatch level of the project, since a mix of RPS-elegible and unelegible
    fuels may be being consumed to produce that power. This expression is only
    valid when unit commitment is being ignored.
    
    RPSFuelEnergy[z, p] is an expression that sums all the energy produced in a 
    load zone z using RPS-elegible fuels in fuel-based projects in a given period.
    
    RPSNonFuelEnergy[z, p] is an expression that sums all the energy produced 
    in a load zone z using non-fuel sources in a given period.
    
    TotalGenerationInPeriod[p] is an expression that sums all the energy
    produced in a given period by all projects. This has to be calculated and
    cannot be taken to be equal to the total load in the period, because
    transmission losses could exist.
    
    RPS_Enforce_Target[z, p] is the constraint that forces energy produced by
    renewable sources in a load zone z to meet a fraction of the total energy 
    produced in the period.
    
    Useful:     
    GENS_IN_ZONE[z in LOAD_ZONES] is an indexed set that lists all
    generation projects within each load zone.
    
    """
mod