Add emission limits and penalties

This commit is contained in:
2025-09-17 15:03:51 -05:00
parent 003922ac70
commit f35c84abe9
8 changed files with 183 additions and 38 deletions

View File

@@ -155,5 +155,15 @@
],
"initial capacity (tonne)": 0
}
},
"emissions": {
"CO2": {
"limit (tonne)": [1000.0, 1100.0, 1200.0, 1300.0],
"penalty ($/tonne)": [50.0, 55.0, 60.0, 65.0]
},
"CH4": {
"limit (tonne)": null,
"penalty ($/tonne)": 1200.0
}
}
}

View File

@@ -68,6 +68,19 @@ function instance_parse_test_1()
@test c2.opening_cost == [1000, 1000, 1000, 1000]
@test c2.fix_operating_cost == [400, 400, 400, 400]
@test c2.var_operating_cost == [5, 5, 5, 5]
# Emissions
@test length(instance.emissions) == 2
co2 = instance.emissions[1]
@test co2.name == "CO2"
@test co2.limit == [1000.0, 1100.0, 1200.0, 1300.0]
@test co2.penalty == [50.0, 55.0, 60.0, 65.0]
@test instance.emissions_by_name["CO2"] === co2
ch4 = instance.emissions[2]
@test ch4.name == "CH4"
@test ch4.limit == [Inf, Inf, Inf, Inf]
@test ch4.penalty == [1200.0, 1200.0, 1200.0, 1200.0]
@test instance.emissions_by_name["CH4"] === ch4
end

View File

@@ -9,8 +9,8 @@ function model_build_test()
y = model[:y]
z_disp = model[:z_disp]
z_input = model[:z_input]
z_tr_em = model[:z_tr_em]
z_plant_em = model[:z_plant_em]
z_em_tr = model[:z_em_tr]
z_em_plant = model[:z_em_plant]
x = model[:x]
obj = objective_function(model)
# print(model)
@@ -47,16 +47,16 @@ function model_build_test()
)
# Variables: Transportation emissions
@test haskey(z_tr_em, ("CO2", "L1", "C3", "P4", 1))
@test haskey(z_tr_em, ("CH4", "L1", "C3", "P4", 1))
@test haskey(z_tr_em, ("CO2", "C2", "L1", "P1", 1))
@test haskey(z_tr_em, ("CH4", "C2", "L1", "P1", 1))
@test haskey(z_em_tr, ("CO2", "L1", "C3", "P4", 1))
@test haskey(z_em_tr, ("CH4", "L1", "C3", "P4", 1))
@test haskey(z_em_tr, ("CO2", "C2", "L1", "P1", 1))
@test haskey(z_em_tr, ("CH4", "C2", "L1", "P1", 1))
# Variables: Plant emissions
@test haskey(z_plant_em, ("CO2", "L1", 1))
@test haskey(z_plant_em, ("CO2", "L1", 2))
@test haskey(z_plant_em, ("CO2", "L1", 3))
@test haskey(z_plant_em, ("CO2", "L1", 4))
@test haskey(z_em_plant, ("CO2", "L1", 1))
@test haskey(z_em_plant, ("CO2", "L1", 2))
@test haskey(z_em_plant, ("CO2", "L1", 3))
@test haskey(z_em_plant, ("CO2", "L1", 4))
# Plants: Definition of total plant input
@test repr(model[:eq_z_input]["L1", 1]) ==
@@ -134,10 +134,23 @@ function model_build_test()
@test ("P4", 1) keys(model[:eq_disposal_limit])
# Products: Transportation emissions
@test repr(model[:eq_tr_em]["CH4", "L1", "C3", "P4", 1]) ==
"eq_tr_em[CH4,L1,C3,P4,1] : -0.333354 y[L1,C3,P4,1] + z_tr_em[CH4,L1,C3,P4,1] = 0"
@test repr(model[:eq_emission_tr]["CH4", "L1", "C3", "P4", 1]) ==
"eq_emission_tr[CH4,L1,C3,P4,1] : -0.333354 y[L1,C3,P4,1] + z_em_tr[CH4,L1,C3,P4,1] = 0"
# Plants: Plant emissions
@test repr(model[:eq_plant_em]["CO2", "L1", 1]) ==
"eq_plant_em[CO2,L1,1] : -0.1 y[C2,L1,P1,1] - 0.1 y[C1,L1,P2,1] + z_plant_em[CO2,L1,1] = 0"
@test repr(model[:eq_emission_plant]["CO2", "L1", 1]) ==
"eq_emission_plant[CO2,L1,1] : -0.1 y[C2,L1,P1,1] - 0.1 y[C1,L1,P2,1] + z_em_plant[CO2,L1,1] = 0"
# Objective function: Emissions penalty costs
@test obj.terms[z_em_plant["CO2", "L1", 1]] == 50.0 # CO2 penalty at time 1
@test obj.terms[z_em_plant["CO2", "L1", 2]] == 55.0 # CO2 penalty at time 2
@test obj.terms[z_em_plant["CO2", "L1", 3]] == 60.0 # CO2 penalty at time 3
@test obj.terms[z_em_plant["CO2", "L1", 4]] == 65.0 # CO2 penalty at time 4
@test obj.terms[z_em_tr["CO2", "L1", "C3", "P4", 1]] == 50.0 # CO2 transportation penalty at time 1
@test obj.terms[z_em_tr["CH4", "L1", "C3", "P4", 1]] == 1200.0 # CH4 transportation penalty at time 1
# Global emissions limit constraints
@test repr(model[:eq_emission_limit]["CO2", 1]) ==
"eq_emission_limit[CO2,1] : z_em_tr[CO2,C2,L1,P1,1] + z_em_tr[CO2,C2,C1,P1,1] + z_em_tr[CO2,C1,L1,P2,1] + z_em_tr[CO2,L1,C3,P4,1] + z_em_plant[CO2,L1,1] ≤ 1000"
@test ("CH4", 1) keys(model[:eq_emission_limit])
end