switch_model/policies/carbon_policies.py
def post_solve(model, outdir):
    """
    Export annual emissions, carbon cap, and implicit carbon costs (where
    appropriate). The dual values of the carbon cap constraint represent an
    implicit carbon cost for purely linear optimization problems. For mixed
    integer optimization problems, the dual values lose practical
    interpretations, so dual values are only exported for purely linear
    models. If you include minimum build requirements, discrete unit sizes,
    discrete unit commitment, or other integer decision variables, the dual
    values will not be exported.
    """
    def get_row(model, period):
        # Loop through all 4 green house gases (GHG) and add the value to the row.
        GHGs = [
            {"AnnualEmissions": model.AnnualEmissions, "cap": model.carbon_cap_tco2_per_yr,
             "cost_per_t": model.carbon_cost_dollar_per_tco2, "Enforce_Carbon_Cap": "Enforce_Carbon_Cap"},
            {"AnnualEmissions": model.AnnualEmissionsNOx, "cap": model.carbon_cap_tnox_per_yr,
             "cost_per_t": model.carbon_cost_dollar_per_tnox, "Enforce_Carbon_Cap": "Enforce_Carbon_Cap_NOx"},
            {"AnnualEmissions": model.AnnualEmissionsSO2, "cap": model.carbon_cap_tso2_per_yr,
             "cost_per_t": model.carbon_cost_dollar_per_tso2, "Enforce_Carbon_Cap": "Enforce_Carbon_Cap_SO2"},
            {"AnnualEmissions": model.AnnualEmissionsCH4, "cap": model.carbon_cap_tch4_per_yr,
             "cost_per_t": model.carbon_cost_dollar_per_tch4, "Enforce_Carbon_Cap": "Enforce_Carbon_Cap_CH4"},
        ]

        return (period,) + tuple(
            c
            for GHG in GHGs
            for c in
            (
                GHG["AnnualEmissions"][period],
                GHG["cap"][period],
                model.get_dual(
                    GHG["Enforce_Carbon_Cap"],
                    period,
                    divider=model.bring_annual_costs_to_base_year[period]
                ),
                GHG["cost_per_t"][period],
                GHG["cost_per_t"][period] * GHG["AnnualEmissions"][period]
            )
        )

    reporting.write_table(
        model, model.PERIODS,
        output_file=os.path.join(outdir, "emissions.csv"),
        headings=("PERIOD",
                  "AnnualEmissions_tCO2_per_yr", "carbon_cap_tco2_per_yr", "carbon_cap_dual_future_dollar_per_tco2",
                  "carbon_cost_dollar_per_tco2", "carbon_cost_annual_total_co2",
                  "AnnualEmissions_tNOx_per_yr", "carbon_cap_tNOx_per_yr", "carbon_cap_dual_future_dollar_per_tnox",
                  "carbon_cost_dollar_per_tnox", "carbon_cost_annual_total_nox",
                  "AnnualEmissions_tSO2_per_yr", "carbon_cap_tso2_per_yr", "carbon_cap_dual_future_dollar_per_tso2",
                  "carbon_cost_dollar_per_tso2", "carbon_cost_annual_total_so2",
                  "AnnualEmissions_tCH4_per_yr", "carbon_cap_tch4_per_yr", "carbon_cap_dual_future_dollar_per_tch4",
                  "carbon_cost_dollar_per_tch4", "carbon_cost_annual_total_ch4",
                  ),
        values=get_row)

    Export annual emissions, carbon cap, and implicit carbon costs (where
    appropriate). The dual values of the carbon cap constraint represent an
    implicit carbon cost for purely linear optimization problems. For mixed
    integer optimization problems, the dual values lose practical
    interpretations, so dual values are only exported for purely linear
    models. If you include minimum build requirements, discrete unit sizes,
    discrete unit commitment, or other integer decision variables, the dual
    values will not be exported.
    
Export annual emissions, carbon cap, and implicit carbon costs (where
appropriate). The dual values of the carbon cap constraint represent an
implicit carbon cost for purely linear optimization problems. For mixed
integer optimization problems, the dual values lose practical
interpretations, so dual values are only exported for purely linear
models. If you include minimum build requirements, discrete unit sizes,
discrete unit commitment, or other integer decision variables, the dual
values will not be exported.
Export annual emissions carbon cap and implicit carbon costs ( where appropriate ) . The dual values of the carbon cap constraint represent an implicit carbon cost for purely linear optimization problems . For mixed integer optimization problems the dual values lose practical interpretations so dual values are only exported for purely linear models . If you include minimum build requirements discrete unit sizes discrete unit commitment or other integer decision variables the dual values will not be exported .
def post_solve(model, outdir):
    def get_row(model, period):
        GHGs = [
            {"AnnualEmissions": model.AnnualEmissions, "cap": model.carbon_cap_tco2_per_yr,
             "cost_per_t": model.carbon_cost_dollar_per_tco2, "Enforce_Carbon_Cap": "Enforce_Carbon_Cap"},
            {"AnnualEmissions": model.AnnualEmissionsNOx, "cap": model.carbon_cap_tnox_per_yr,
             "cost_per_t": model.carbon_cost_dollar_per_tnox, "Enforce_Carbon_Cap": "Enforce_Carbon_Cap_NOx"},
            {"AnnualEmissions": model.AnnualEmissionsSO2, "cap": model.carbon_cap_tso2_per_yr,
             "cost_per_t": model.carbon_cost_dollar_per_tso2, "Enforce_Carbon_Cap": "Enforce_Carbon_Cap_SO2"},
            {"AnnualEmissions": model.AnnualEmissionsCH4, "cap": model.carbon_cap_tch4_per_yr,
             "cost_per_t": model.carbon_cost_dollar_per_tch4, "Enforce_Carbon_Cap": "Enforce_Carbon_Cap_CH4"},
        ]
        return (period,) + tuple(
            c
            for GHG in GHGs
            for c in
            (
                GHG["AnnualEmissions"][period],
                GHG["cap"][period],
                model.get_dual(
                    GHG["Enforce_Carbon_Cap"],
                    period,
                    divider=model.bring_annual_costs_to_base_year[period]
                ),
                GHG["cost_per_t"][period],
                GHG["cost_per_t"][period] * GHG["AnnualEmissions"][period]
            )
        )
    reporting.write_table(
        model, model.PERIODS,
        output_file=os.path.join(outdir, "emissions.csv"),
        headings=("PERIOD",
                  "AnnualEmissions_tCO2_per_yr", "carbon_cap_tco2_per_yr", "carbon_cap_dual_future_dollar_per_tco2",
                  "carbon_cost_dollar_per_tco2", "carbon_cost_annual_total_co2",
                  "AnnualEmissions_tNOx_per_yr", "carbon_cap_tNOx_per_yr", "carbon_cap_dual_future_dollar_per_tnox",
                  "carbon_cost_dollar_per_tnox", "carbon_cost_annual_total_nox",
                  "AnnualEmissions_tSO2_per_yr", "carbon_cap_tso2_per_yr", "carbon_cap_dual_future_dollar_per_tso2",
                  "carbon_cost_dollar_per_tso2", "carbon_cost_annual_total_so2",
                  "AnnualEmissions_tCH4_per_yr", "carbon_cap_tch4_per_yr", "carbon_cap_dual_future_dollar_per_tch4",
                  "carbon_cost_dollar_per_tch4", "carbon_cost_annual_total_ch4",
                  ),
        values=get_row)
def post_solve ( model , outdir ) : def get_row ( model , period ) : GHGs = [ { "AnnualEmissions" : model . AnnualEmissions , "cap" : model . carbon_cap_tco2_per_yr , "cost_per_t" : model . carbon_cost_dollar_per_tco2 , "Enforce_Carbon_Cap" : "Enforce_Carbon_Cap" } , { "AnnualEmissions" : model . AnnualEmissionsNOx , "cap" : model . carbon_cap_tnox_per_yr , "cost_per_t" : model . carbon_cost_dollar_per_tnox , "Enforce_Carbon_Cap" : "Enforce_Carbon_Cap_NOx" } , { "AnnualEmissions" : model . AnnualEmissionsSO2 , "cap" : model . carbon_cap_tso2_per_yr , "cost_per_t" : model . carbon_cost_dollar_per_tso2 , "Enforce_Carbon_Cap" : "Enforce_Carbon_Cap_SO2" } , { "AnnualEmissions" : model . AnnualEmissionsCH4 , "cap" : model . carbon_cap_tch4_per_yr , "cost_per_t" : model . carbon_cost_dollar_per_tch4 , "Enforce_Carbon_Cap" : "Enforce_Carbon_Cap_CH4" } , ] return ( period , ) + tuple ( c for GHG in GHGs for c in ( GHG [ "AnnualEmissions" ] [ period ] , GHG [ "cap" ] [ period ] , model . get_dual ( GHG [ "Enforce_Carbon_Cap" ] , period , divider = model . bring_annual_costs_to_base_year [ period ] ) , GHG [ "cost_per_t" ] [ period ] , GHG [ "cost_per_t" ] [ period ] * GHG [ "AnnualEmissions" ] [ period ] ) ) reporting . write_table ( model , model . PERIODS , output_file = os . path . join ( outdir , "emissions.csv" ) , headings = ( "PERIOD" , "AnnualEmissions_tCO2_per_yr" , "carbon_cap_tco2_per_yr" , "carbon_cap_dual_future_dollar_per_tco2" , "carbon_cost_dollar_per_tco2" , "carbon_cost_annual_total_co2" , "AnnualEmissions_tNOx_per_yr" , "carbon_cap_tNOx_per_yr" , "carbon_cap_dual_future_dollar_per_tnox" , "carbon_cost_dollar_per_tnox" , "carbon_cost_annual_total_nox" , "AnnualEmissions_tSO2_per_yr" , "carbon_cap_tso2_per_yr" , "carbon_cap_dual_future_dollar_per_tso2" , "carbon_cost_dollar_per_tso2" , "carbon_cost_annual_total_so2" , "AnnualEmissions_tCH4_per_yr" , "carbon_cap_tch4_per_yr" , "carbon_cap_dual_future_dollar_per_tch4" , "carbon_cost_dollar_per_tch4" , "carbon_cost_annual_total_ch4" , ) , values = get_row )
Export annual emissions, carbon cap, and implicit carbon costs (where
appropriate).
Export annual emissions carbon cap and implicit carbon costs ( where appropriate ) .
"""
    Export annual emissions, carbon cap, and implicit carbon costs (where
    appropriate). The dual values of the carbon cap constraint represent an
    implicit carbon cost for purely linear optimization problems. For mixed
    integer optimization problems, the dual values lose practical
    interpretations, so dual values are only exported for purely linear
    models. If you include minimum build requirements, discrete unit sizes,
    discrete unit commitment, or other integer decision variables, the dual
    values will not be exported.
    """ # Loop through all 4 green house gases (GHG) and add the value to the row.
model
outdir