Skip to content

Commit

Permalink
Merge pull request #744 from flohump/f_fixOpti
Browse files Browse the repository at this point in the history
bugfixes for more robust feasibility
  • Loading branch information
flohump authored Nov 11, 2024
2 parents 2d3a1de + 0ebe136 commit 321bea6
Show file tree
Hide file tree
Showing 22 changed files with 54 additions and 48 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- **config** SHAPE scenarios start year of dietary shift changed to 2025
- **core** number of age-classes doubled from 150 to 300 years for better match of growth curves with potential natural vegetation.
- **35_natveg** revised age-class initialization of secondary forest
- **modules** update of scaling factors in several modules


### added
- **62_material** added switch to turn off future material demand for bioplastic
Expand All @@ -28,6 +30,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- **29_cropland** treecover age-class growth was not working properly because ac_sub was erroneously not fixed
- **scripts** script/output/extra/resubmit.R
- **28_ageclass** bugfix input data unit and code clean-up. Renamed `feb21` realization to `oct24`
- **70_livestock** bugfix scaling.gms file in wrong folder
- **10_land** bugfix land transition matrix for improved feasibility (variables and parameters have different accuracy)
- **44_biodiversity** avoid division by zero and improved consistency between realisations for fixing variables

## [4.8.2] - 2024-09-24

Expand Down
8 changes: 4 additions & 4 deletions modules/10_land/landmatrix_dec18/declarations.gms
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ positive variables
vm_landreduction(j,land) Land reduction (mio. ha)
vm_cost_land_transition(j) Costs for lu transitions (mio. USD17MER per yr)
vm_lu_transitions(j,land_from,land_to) Land transitions between time steps (mio. ha)
v10_balance_positive(j) Balance variable for land transitions (mio. ha)
v10_balance_negative(j) Balance variable for land transitions (mio. ha)
v10_balance_positive(j,land_from) Balance variable for land transitions (mio. ha)
v10_balance_negative(j,land_from) Balance variable for land transitions (mio. ha)
;

equations
Expand All @@ -43,8 +43,8 @@ parameters
ov_landreduction(t,j,land,type) Land reduction (mio. ha)
ov_cost_land_transition(t,j,type) Costs for lu transitions (mio. USD17MER per yr)
ov_lu_transitions(t,j,land_from,land_to,type) Land transitions between time steps (mio. ha)
ov10_balance_positive(t,j,type) Balance variable for land transitions (mio. ha)
ov10_balance_negative(t,j,type) Balance variable for land transitions (mio. ha)
ov10_balance_positive(t,j,land_from,type) Balance variable for land transitions (mio. ha)
ov10_balance_negative(t,j,land_from,type) Balance variable for land transitions (mio. ha)
oq10_transition_matrix(t,j,type) Land transition constraint cell area (mio. ha)
oq10_transition_to(t,j,land_to,type) Land transition constraint to (mio. ha)
oq10_transition_from(t,j,land_from,type) Land transition constraint from (mio. ha)
Expand Down
9 changes: 4 additions & 5 deletions modules/10_land/landmatrix_dec18/equations.gms
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,16 @@
*' `v10_balance_negative`should deviate from zero only in exceptional cases.

q10_transition_matrix(j2) ..
sum((land_from,land_to), vm_lu_transitions(j2,land_from,land_to))
+ v10_balance_positive(j2) - v10_balance_negative(j2) =e=
sum(land, pcm_land(j2,land));
sum((land_from,land_to), vm_lu_transitions(j2,land_from,land_to)) =e=
sum(land, vm_land(j2,land));

q10_transition_to(j2,land_to) ..
sum(land_from, vm_lu_transitions(j2,land_from,land_to)) =e=
vm_land(j2,land_to);

q10_transition_from(j2,land_from) ..
sum(land_to, vm_lu_transitions(j2,land_from,land_to)) =e=
pcm_land(j2,land_from);
vm_land.l(j2,land_from) + v10_balance_positive(j2,land_from) - v10_balance_negative(j2,land_from);

*' The following two equations calculate land expansion and land contraction based
*' on the above land transition matrix.
Expand All @@ -47,7 +46,7 @@
q10_cost(j2) ..
vm_cost_land_transition(j2) =e=
sum(land, vm_landexpansion(j2,land) + vm_landreduction(j2,land)) * 1
+ (v10_balance_positive(j2) + v10_balance_negative(j2)) * s10_cost_balance;
+ sum(land_from, v10_balance_positive(j2,land_from) + v10_balance_negative(j2,land_from)) * s10_cost_balance;

*' The gross changes in land are calculated based on land expansion, land
*' contraction and land changes from within the modules [35_natveg]
Expand Down
16 changes: 8 additions & 8 deletions modules/10_land/landmatrix_dec18/postsolve.gms
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ pcm_land(j,land) = vm_land.l(j,land);
ov_landreduction(t,j,land,"marginal") = vm_landreduction.m(j,land);
ov_cost_land_transition(t,j,"marginal") = vm_cost_land_transition.m(j);
ov_lu_transitions(t,j,land_from,land_to,"marginal") = vm_lu_transitions.m(j,land_from,land_to);
ov10_balance_positive(t,j,"marginal") = v10_balance_positive.m(j);
ov10_balance_negative(t,j,"marginal") = v10_balance_negative.m(j);
ov10_balance_positive(t,j,land_from,"marginal") = v10_balance_positive.m(j,land_from);
ov10_balance_negative(t,j,land_from,"marginal") = v10_balance_negative.m(j,land_from);
oq10_transition_matrix(t,j,"marginal") = q10_transition_matrix.m(j);
oq10_transition_to(t,j,land_to,"marginal") = q10_transition_to.m(j,land_to);
oq10_transition_from(t,j,land_from,"marginal") = q10_transition_from.m(j,land_from);
Expand All @@ -30,8 +30,8 @@ pcm_land(j,land) = vm_land.l(j,land);
ov_landreduction(t,j,land,"level") = vm_landreduction.l(j,land);
ov_cost_land_transition(t,j,"level") = vm_cost_land_transition.l(j);
ov_lu_transitions(t,j,land_from,land_to,"level") = vm_lu_transitions.l(j,land_from,land_to);
ov10_balance_positive(t,j,"level") = v10_balance_positive.l(j);
ov10_balance_negative(t,j,"level") = v10_balance_negative.l(j);
ov10_balance_positive(t,j,land_from,"level") = v10_balance_positive.l(j,land_from);
ov10_balance_negative(t,j,land_from,"level") = v10_balance_negative.l(j,land_from);
oq10_transition_matrix(t,j,"level") = q10_transition_matrix.l(j);
oq10_transition_to(t,j,land_to,"level") = q10_transition_to.l(j,land_to);
oq10_transition_from(t,j,land_from,"level") = q10_transition_from.l(j,land_from);
Expand All @@ -45,8 +45,8 @@ pcm_land(j,land) = vm_land.l(j,land);
ov_landreduction(t,j,land,"upper") = vm_landreduction.up(j,land);
ov_cost_land_transition(t,j,"upper") = vm_cost_land_transition.up(j);
ov_lu_transitions(t,j,land_from,land_to,"upper") = vm_lu_transitions.up(j,land_from,land_to);
ov10_balance_positive(t,j,"upper") = v10_balance_positive.up(j);
ov10_balance_negative(t,j,"upper") = v10_balance_negative.up(j);
ov10_balance_positive(t,j,land_from,"upper") = v10_balance_positive.up(j,land_from);
ov10_balance_negative(t,j,land_from,"upper") = v10_balance_negative.up(j,land_from);
oq10_transition_matrix(t,j,"upper") = q10_transition_matrix.up(j);
oq10_transition_to(t,j,land_to,"upper") = q10_transition_to.up(j,land_to);
oq10_transition_from(t,j,land_from,"upper") = q10_transition_from.up(j,land_from);
Expand All @@ -60,8 +60,8 @@ pcm_land(j,land) = vm_land.l(j,land);
ov_landreduction(t,j,land,"lower") = vm_landreduction.lo(j,land);
ov_cost_land_transition(t,j,"lower") = vm_cost_land_transition.lo(j);
ov_lu_transitions(t,j,land_from,land_to,"lower") = vm_lu_transitions.lo(j,land_from,land_to);
ov10_balance_positive(t,j,"lower") = v10_balance_positive.lo(j);
ov10_balance_negative(t,j,"lower") = v10_balance_negative.lo(j);
ov10_balance_positive(t,j,land_from,"lower") = v10_balance_positive.lo(j,land_from);
ov10_balance_negative(t,j,land_from,"lower") = v10_balance_negative.lo(j,land_from);
oq10_transition_matrix(t,j,"lower") = q10_transition_matrix.lo(j);
oq10_transition_to(t,j,land_to,"lower") = q10_transition_to.lo(j,land_to);
oq10_transition_from(t,j,land_from,"lower") = q10_transition_from.lo(j,land_from);
Expand Down
4 changes: 2 additions & 2 deletions modules/10_land/landmatrix_dec18/scaling.gms
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
*** | Contact: [email protected]

vm_landdiff.scale = 10e3;
v10_balance_positive.scale(j) = 10e-10;
v10_balance_negative.scale(j) = 10e-10;
v10_balance_positive.scale(j,land_from) = 10e-7;
v10_balance_negative.scale(j,land_from) = 10e-7;
2 changes: 1 addition & 1 deletion modules/20_processing/substitution_may21/scaling.gms
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
*** | MAgPIE License Exception, version 1.0 (see LICENSE file).
*** | Contact: [email protected]

vm_secondary_overproduction.scale(i,kall,kpr) = 10e-3;
vm_secondary_overproduction.scale(i,kall,kpr) = 10e-4;
vm_cost_processing.scale(i) = 10e5;
vm_processing_substitution_cost.scale(i) = 10e4;
4 changes: 3 additions & 1 deletion modules/38_factor_costs/sticky_labor/scaling.gms
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@
*** | MAgPIE License Exception, version 1.0 (see LICENSE file).
*** | Contact: [email protected]

vm_cost_prod_crop.scale(i,factors) = 10e4;
vm_cost_prod_crop.scale(i,factors) = 10e5;
v38_investment_immobile.scale(j,kcr) = 10e3;
v38_capital_need.scale(j,kcr,mobil38) = 10e3;
3 changes: 2 additions & 1 deletion modules/44_biodiversity/bii_target/equations.gms
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
*' The Biodiversity Intactness Index (BII) is calculated at the level of 71 biomes.
*' The regional layer is needed for compatibility with the high resolution parallel optimization output script (scripts/output/extra/highres.R)

q44_bii(i2,biome44)$(sum(cell(i2,j2), f44_biome(j2,biome44)) > 1e-10) .. v44_bii(i2,biome44) * sum((cell(i2,j2),land), pcm_land(j2,land) * f44_biome(j2,biome44))
q44_bii(i2,biome44)$(sum(cell(i2,j2), f44_biome(j2,biome44)) > 1e-10) ..
v44_bii(i2,biome44) * sum((cell(i2,j2),land), pcm_land(j2,land) * f44_biome(j2,biome44))
=e=
sum((cell(i2,j2),potnatveg,landcover44), vm_bv(j2,landcover44,potnatveg) * f44_biome(j2,biome44));

Expand Down
2 changes: 1 addition & 1 deletion modules/44_biodiversity/bii_target/presolve.gms
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ else
);
p44_bii_lower_bound(t2,i,biome44)$(p44_bii_lower_bound(t2,i,biome44) >= 1) = 1;
p44_bii_lower_bound(t2,i,biome44)$(m_year(t2) < s44_start_year) = 0;
p44_bii_lower_bound(t2,i,biome44)$(sum(cell(i,j), f44_biome(j,biome44)) = 0) = 0;
p44_bii_lower_bound(t2,i,biome44)$(sum(cell(i,j), f44_biome(j,biome44)) <= 1e-10) = 0;
* The lower bound of `v44_bii` is set to `p44_bii_lower_bound` to avoid a reduction of BII in combination with `v44_bii_missing`.
v44_bii.lo(i,biome44) = p44_bii_lower_bound(t,i,biome44);
display p44_bii_lower_bound;
Expand Down
7 changes: 4 additions & 3 deletions modules/44_biodiversity/bii_target_apr24/equations.gms
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@
*' Biodiversity stock weighted by range-rarity restoration prioritization layer (`f44_rr_layer`)
*' The regional layer is needed for compatibility with the high resolution parallel optimization output script (scripts/output/extra/highres.R)

q44_bii(i2,biome44)$(sum(cell(i2,j2), f44_biome(j2,biome44)) > 0) .. v44_bii(i2,biome44)
q44_bii(i2,biome44)$(sum(cell(i2,j2), f44_biome(j2,biome44)*f44_rr_layer(j2)) > 1e-10) ..
v44_bii(i2,biome44) * sum((cell(i2,j2),land), pcm_land(j2,land) * f44_rr_layer(j2) * f44_biome(j2,biome44))
=e=
(sum((cell(i2,j2),potnatveg,landcover44), vm_bv(j2,landcover44,potnatveg) * f44_rr_layer(j2) * f44_biome(j2,biome44)) / sum((cell(i2,j2),land), pcm_land(j2,land) * f44_rr_layer(j2) * f44_biome(j2,biome44)));
sum((cell(i2,j2),potnatveg,landcover44), vm_bv(j2,landcover44,potnatveg) * f44_rr_layer(j2) * f44_biome(j2,biome44));

*' For each of the 71 biomes, the BII has to meet a minium level based on `s44_bii_lower_bound`.
*' `v44_bii_missing` is a technical variable to maintain feasibility in case `v44_bii` cannot be increased.

q44_bii_target(i2,biome44)$(sum(cell(i2,j2), f44_biome(j2,biome44)) > 0) ..
q44_bii_target(i2,biome44)$(sum(cell(i2,j2), f44_biome(j2,biome44)*f44_rr_layer(j2)) > 1e-10) ..
v44_bii(i2,biome44) + v44_bii_missing(i2,biome44) =g= sum(ct, p44_bii_lower_bound(ct,i2,biome44));

*' Costs accrue only for `v44_bii_missing`. In the best case costs should be zero or close to zero.
Expand Down
4 changes: 2 additions & 2 deletions modules/44_biodiversity/bii_target_apr24/preloop.gms
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

v44_bii.l(i,biome44) = 0.75;

v44_bii.fx(i,biome44)$(sum(cell(i,j), f44_biome(j,biome44)) = 0) = 0;
v44_bii_missing.fx(i,biome44)$(sum(cell(i,j), f44_biome(j,biome44)) = 0) = 0;
v44_bii.fx(i,biome44)$(sum(cell(i,j), f44_biome(j,biome44)*f44_rr_layer(j)) <= 1e-10) = 0;
v44_bii_missing.fx(i,biome44)$(sum(cell(i,j), f44_biome(j,biome44)*f44_rr_layer(j)) <= 1e-10) = 0;
p44_bii_lower_bound(t,i,biome44) = 0;

vm_bv.l(j,landcover44,potnatveg) = 0;
2 changes: 1 addition & 1 deletion modules/44_biodiversity/bii_target_apr24/presolve.gms
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ else
);
p44_bii_lower_bound(t2,i,biome44)$(p44_bii_lower_bound(t2,i,biome44) >= 1) = 1;
p44_bii_lower_bound(t2,i,biome44)$(m_year(t2) < s44_start_year) = 0;
p44_bii_lower_bound(t2,i,biome44)$(sum(cell(i,j), f44_biome(j,biome44)) = 0) = 0;
p44_bii_lower_bound(t2,i,biome44)$(sum(cell(i,j), f44_biome(j,biome44)*f44_rr_layer(j)) <= 1e-10) = 0;
* The lower bound of `v44_bii` is set to `p44_bii_lower_bound` to avoid a reduction of BII in combination with `v44_bii_missing`.
v44_bii.lo(i,biome44) = p44_bii_lower_bound(t,i,biome44);
display p44_bii_lower_bound;
Expand Down
1 change: 1 addition & 0 deletions modules/70_livestock/fbask_jan16/realization.gms
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ $Ifi "%phase%" == "sets" $include "./modules/70_livestock/fbask_jan16/sets.gms"
$Ifi "%phase%" == "declarations" $include "./modules/70_livestock/fbask_jan16/declarations.gms"
$Ifi "%phase%" == "input" $include "./modules/70_livestock/fbask_jan16/input.gms"
$Ifi "%phase%" == "equations" $include "./modules/70_livestock/fbask_jan16/equations.gms"
$Ifi "%phase%" == "scaling" $include "./modules/70_livestock/fbask_jan16/scaling.gms"
$Ifi "%phase%" == "preloop" $include "./modules/70_livestock/fbask_jan16/preloop.gms"
$Ifi "%phase%" == "presolve" $include "./modules/70_livestock/fbask_jan16/presolve.gms"
$Ifi "%phase%" == "postsolve" $include "./modules/70_livestock/fbask_jan16/postsolve.gms"
Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions modules/70_livestock/fbask_jan16_sticky/realization.gms
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ $Ifi "%phase%" == "sets" $include "./modules/70_livestock/fbask_jan16_sticky/set
$Ifi "%phase%" == "declarations" $include "./modules/70_livestock/fbask_jan16_sticky/declarations.gms"
$Ifi "%phase%" == "input" $include "./modules/70_livestock/fbask_jan16_sticky/input.gms"
$Ifi "%phase%" == "equations" $include "./modules/70_livestock/fbask_jan16_sticky/equations.gms"
$Ifi "%phase%" == "scaling" $include "./modules/70_livestock/fbask_jan16_sticky/scaling.gms"
$Ifi "%phase%" == "preloop" $include "./modules/70_livestock/fbask_jan16_sticky/preloop.gms"
$Ifi "%phase%" == "presolve" $include "./modules/70_livestock/fbask_jan16_sticky/presolve.gms"
$Ifi "%phase%" == "postsolve" $include "./modules/70_livestock/fbask_jan16_sticky/postsolve.gms"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
*** | MAgPIE License Exception, version 1.0 (see LICENSE file).
*** | Contact: [email protected]

vm_costs_additional_mon.scale(i) = 10e4;
*Don't scale this variable. Model is very sensitive to scaling this variable and might become infeasible or very slow.
*v71_feed_balanceflow.scale(j,kforage) = 10e3;

vm_cost_prod_livst.scale(i,factors) = 10e5;
vm_cost_prod_fish.scale(i) = 10e5;
1 change: 0 additions & 1 deletion modules/71_disagg_lvst/foragebased_aug18/realization.gms
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
$Ifi "%phase%" == "sets" $include "./modules/71_disagg_lvst/foragebased_aug18/sets.gms"
$Ifi "%phase%" == "declarations" $include "./modules/71_disagg_lvst/foragebased_aug18/declarations.gms"
$Ifi "%phase%" == "equations" $include "./modules/71_disagg_lvst/foragebased_aug18/equations.gms"
$Ifi "%phase%" == "scaling" $include "./modules/71_disagg_lvst/foragebased_aug18/scaling.gms"
$Ifi "%phase%" == "preloop" $include "./modules/71_disagg_lvst/foragebased_aug18/preloop.gms"
$Ifi "%phase%" == "postsolve" $include "./modules/71_disagg_lvst/foragebased_aug18/postsolve.gms"
*######################## R SECTION END (PHASES) ###############################
10 changes: 0 additions & 10 deletions modules/71_disagg_lvst/foragebased_aug18/scaling.gms

This file was deleted.

1 change: 0 additions & 1 deletion modules/71_disagg_lvst/foragebased_jul23/realization.gms
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
$Ifi "%phase%" == "sets" $include "./modules/71_disagg_lvst/foragebased_jul23/sets.gms"
$Ifi "%phase%" == "declarations" $include "./modules/71_disagg_lvst/foragebased_jul23/declarations.gms"
$Ifi "%phase%" == "equations" $include "./modules/71_disagg_lvst/foragebased_jul23/equations.gms"
$Ifi "%phase%" == "scaling" $include "./modules/71_disagg_lvst/foragebased_jul23/scaling.gms"
$Ifi "%phase%" == "preloop" $include "./modules/71_disagg_lvst/foragebased_jul23/preloop.gms"
$Ifi "%phase%" == "postsolve" $include "./modules/71_disagg_lvst/foragebased_jul23/postsolve.gms"
$Ifi "%phase%" == "nl_fix" $include "./modules/71_disagg_lvst/foragebased_jul23/nl_fix.gms"
Expand Down
2 changes: 1 addition & 1 deletion scripts/projects/fsec.R
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ fsecScenario <- function(scenario) {
"rds_report")
cfg$force_download <- TRUE
cfg$gms$s80_optfile <- 0
cfg$gms$s80_maxiter <- 100
cfg$gms$s80_maxiter <- 30

return(cfg)
}
12 changes: 10 additions & 2 deletions scripts/start/projects/paper_peatlandTax.R
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ source("scripts/start_functions.R")
source("config/default.cfg")

# create additional information to describe the runs
cfg$info$flag <- "PTax35"
cfg$info$flag <- "PTax36"

cfg$results_folder <- "output/:title:"
cfg$results_folder_highres <- "output"
Expand Down Expand Up @@ -69,13 +69,20 @@ calc_ghgprice <- function() {
T200[, , "n2o_n_indirect"] <- T200[, , "co2_c"] * 265 * 44 / 28
T200[, , "co2_c"] <- T200[, , "co2_c"] * 44 / 12

T25 <- T200 * 0.125
T50 <- T200 * 0.25
T100 <- T200 * 0.5
T400 <- T200 * 2
T800 <- T200 * 4

GHG <- mbind(
add_dimension(T0, dim = 3.2, add = "scen", nm = "T0-GHG"),
add_dimension(
T25,
dim = 3.2,
add = "scen",
nm = "T25-GHG"
),
add_dimension(
T50,
dim = 3.2,
Expand Down Expand Up @@ -158,7 +165,8 @@ for (res in c("c400")) {
start_run(cfg, codeCheck = FALSE)

## Policy scenarios
for (tax in c("T50-CO2",
for (tax in c("T25-CO2",
"T50-CO2",
"T100-CO2",
"T200-CO2",
"T400-CO2",
Expand Down
2 changes: 1 addition & 1 deletion scripts/start/projects/project_ABCDR.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ source("config/default.cfg")
#download_and_update(cfg)

# create additional information to describe the runs
cfg$info$flag <- "ABCDR16"
cfg$info$flag <- "ABCDR18"

cfg$results_folder <- "output/:title:"
cfg$force_replace <- TRUE
Expand Down

0 comments on commit 321bea6

Please sign in to comment.