Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recursive dynamic tutorial updates #1

Open
wants to merge 34 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
aa0ffdd
Update MESSAGE_master.gms
ywpratama Mar 7, 2023
13bfa5d
Recursive Dynamic Module
ywpratama Mar 10, 2023
e178624
Tutorial to activate recursive dynamic module
ywpratama Mar 10, 2023
e3d7dc1
Tutorial to add DACCS to a MESSAGE model/scenario
ywpratama Mar 10, 2023
2fcce43
Add technology learning activation instruction
ywpratama Mar 10, 2023
eaf963e
Revert "Add technology learning activation instruction"
ywpratama Mar 10, 2023
92a4dd8
Delete westeros_baseline_recursive-dynamic.ipynb
ywpratama Mar 13, 2023
dd4d665
Create westeros_baseline_recursive-dynamic.ipynb
ywpratama Mar 13, 2023
8c92531
Create westeros_emissions_bounds_daccs.ipynb
ywpratama Mar 13, 2023
88b52de
Update westeros_baseline_recursive-dynamic.ipynb
ywpratama Mar 13, 2023
53dd7c7
Merge branch 'iiasa:main' into main
ywpratama Mar 13, 2023
25fac62
Recursive dynamic tutorial updates
ywpratama Mar 16, 2023
02d0c91
Revise year4 to fix the "Fixed year bug"
ywpratama Mar 16, 2023
41061f1
Fixing parameters to show differences between the scenarios
Mar 17, 2023
a2d7460
Minor update on tutorials
ywpratama Mar 28, 2023
cfa9883
Remove project file to avoid conflict
ywpratama Apr 3, 2023
de2c0f9
Merge branch 'iiasa:main' into main
ywpratama May 9, 2023
9eb324b
Merge branch 'main' into recursive-dynamic-tutorial-updpate
ywpratama May 9, 2023
90477d5
manual trial
ywpratama May 15, 2023
d0d27d6
Revert "manual trial"
ywpratama May 15, 2023
2c1a928
Tutorials trial
ywpratama May 17, 2023
06e1095
Fix learning equation's bugs
ywpratama May 19, 2023
35ee711
Fix cost calculation bugs
ywpratama May 22, 2023
2d38514
Add learning for perfect foresight
ywpratama May 22, 2023
b2efe4f
Remove iter number parameter
ywpratama May 22, 2023
f21b691
Merge branch 'iiasa:main' into recursive-dynamic-tutorial-updpate
ywpratama May 22, 2023
aa9ce94
Adding parameters estimation and foresight learning tutorials
May 24, 2023
6a8cfb0
update data
May 24, 2023
49aa22a
Arbitrary changes on tutorials
ywpratama May 25, 2023
bee89a4
Add new technology data
ywpratama May 30, 2023
201bc97
Update technology learning data
ywpratama Jun 1, 2023
a8742fb
Fixing bugs on year definition
ywpratama Jun 1, 2023
173429b
Merge branch 'iiasa:main' into recursive-dynamic-tutorial-updpate
ywpratama Jun 11, 2023
9b47cfb
Improve flows on parameters estimation model
ywpratama Jun 23, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions message_ix/model/Fix Learning/Learning_dummy.CAPEX_TEC.gchf
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
object TChart
Left = 0
Top = 33
Width = 1912
Height = 876
HelpContext = 520
Legend.LegendStyle = lsSeries
SubTitle.Text.Strings = (
'capital cost in dollar per kW')
Title.Text.Strings = (
'CAPEX_TEC')
View3D = False
Align = alClient
Color = clWhite
TabOrder = 1
object TBarSeries
Tag = 104
Marks.Callout.Brush.Color = clBlack
Marks.Visible = True
Title = 'CAPEX_TEC'
Gradient.Direction = gdTopBottom
XValues.Name = 'X'
XValues.Order = loAscending
YValues.Name = 'Bar'
YValues.Order = loNone
end
end
73 changes: 73 additions & 0 deletions message_ix/model/Fix Learning/Learning_dummy.gms
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
SETS
year 'year' /1*14/
size 'size' / small, medium, large /
newtec new technology / wind_ppl /;
ALIAS (size,size2);
ALIAS (year,year2);
PARAMETERS
cap_new2(newtec,year) 'annual newly installed capacity'
/ wind_ppl.1 247.65
wind_ppl.2 237.95
wind_ppl.3 167.65
wind_ppl.4 255.25
wind_ppl.5 170.7
wind_ppl.6 566.2
wind_ppl.7 411.95
wind_ppl.8 465.5
wind_ppl.9 553.65
wind_ppl.10 1528.7
wind_ppl.11 1757
wind_ppl.12 1881.9
wind_ppl.13 2961
wind_ppl.14 3731 /
bin_cap_new(newtec,year) 'binary of newly installed capacity'
rho(newtec) 'economy of scale parameter' / wind_ppl 0.91 /
*0.91
b(newtec) 'technology cost learning parameter' / wind_ppl 0.11 /
u(size) 'unit size'
/ small 0.04
medium 0.1
large 0.5 /
inv_cost_ref(newtec) 'initial capex'
nbr_unit_ref(newtec) 'initial number of unit' / wind_ppl 4220 /
u_ref(newtec) 'reference size' / wind_ppl 0.04 / ;
inv_cost_ref(newtec) = 1490 ;
bin_cap_new(newtec,year) = 1;

SCALAR hist_length the length of historical periods;
hist_length = card(year);

VARIABLES
NBR_UNIT(newtec,size,year) number of units for each size every year
CAPEX_TEC(newtec,year) capital cost in dollar per kW
OBJECT objective function ;

POSITIVE VARIABLES
NBR_UNIT ;

EQUATIONS
OBJECTIVE_INNER total investment cost
CAP_NEW_BALANCE installed capacity balance
CAPEX_ESTIMATE estimating average capex
NO_BUILT_YEAR annual investment cost
;


OBJECTIVE_INNER.. OBJECT =e= sum((newtec,year), CAPEX_TEC(newtec,year)*cap_new2(newtec,year)) ;
CAP_NEW_BALANCE(newtec,year).. sum(size, NBR_UNIT(newtec,size,year)*u(size)) =e= cap_new2(newtec,year) ;
CAPEX_ESTIMATE(newtec,year).. CAPEX_TEC(newtec,year)*cap_new2(newtec,year) =g= sum(size,inv_cost_ref(newtec)
* NBR_UNIT(newtec,size,year)*u(size)
* [(((sum((size2,year2)$(ord(year2) le ord(year)-1), NBR_UNIT(newtec,size2,year2))+nbr_unit_ref(newtec))/nbr_unit_ref(newtec))**(-b(newtec)))]
* [((u(size)/u_ref(newtec))**rho(newtec))/(u(size)/u_ref(newtec))]) ;
NO_BUILT_YEAR(newtec,year).. CAPEX_TEC(newtec,year) =e= bin_cap_new(newtec,year)*CAPEX_TEC(newtec,year)
+ (1-bin_cap_new(newtec,year))*CAPEX_TEC(newtec,year-1) ;

model learningeos / all /;
solve learningeos using nlp minimizing OBJECT;

PARAMETERS
new_cap_by_size(newtec,size,year) new capacity by size;

new_cap_by_size(newtec,size,year) = NBR_UNIT.l(newtec,size,year)*u(size);

Execute_Unload "Learning_dummy.gdx";
Binary file added message_ix/model/Fix Learning/Manual.xlsx
Binary file not shown.
45 changes: 45 additions & 0 deletions message_ix/model/Fix Learning/While test 1.gms
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
$title Prime Number Generation (PRIME,SEQ=157)

$onText
This example shows how to use a WHILE statement to find a set of prime numbers.


GAMS Development Corporation, Formulation and Language Example.

Keywords: GAMS formulation and language example, prime number generation, mathematics
$offText

$eolCom //

Set
s 'set of prime numbers' / 1*200 /
ss(s) 'primes found until now';

Scalar
more 'temporary flag'
candidate 'prime candidate';

Parameter ps(s) 'first s prime numbers';

ps(s) = 0; // clear prime array
ss(s) = no; // make primes found set empty

candidate = 3; // set prime to get started

loop(s,
more = 1; // turn on the search
while(more, // search until found
loop(ss, // only test if still a candidate
break$(sqr(ps(ss)) > candidate);// leave loop if we check sufficient large prime factors
more = mod(candidate,ps(ss)); // a prime must have a remainder
break$(not more); // leave loop if we found a divisor with remainer 0
);
if(more, // check if we got one
ss(s) = yes; // bump set of found primes
ps(s) = candidate; // save prime number
);
more = not more; // flip the search flag
candidate = candidate + 2; // next candidate has to be odd
);
);
display ps;
37 changes: 37 additions & 0 deletions message_ix/model/Fix Learning/While test.gms
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
Scalars
prev_OBJ previous objective value / 10 /
delta_OBJ difference between current and previous OBJ values / 2 /
count_iter iteration counts / 1 /
OBJ objective function / 0 / ;
$SETGLOBAL foresight "0"
$SETGLOBAL learningmode "1"
*$ontext
if (%foresight% = 0,
IF(%learningmode% = 1,
while(count_iter <= 10 and delta_OBJ >= 0.1,
OBJ = prev_OBJ**0.5 ;
delta_OBJ = (prev_OBJ - OBJ)/prev_OBJ ;
prev_OBJ = OBJ ;

display count_iter, OBJ, delta_OBJ, prev_OBJ;

count_iter = count_iter + 1 ;
);
);
ELSE
* write a status update to the log file, solve the model
put_utility 'log' /'+++ Solve the perfect-foresight version of MESSAGEix +++ ' ;
);

*$offtext
$ontext
Scalar j, k;
j = 1;
k = 10;

While(j <= 5 and k >= 6,
Display j, k;
j = j + 1;
k = k - 1;
);
$offtext
2 changes: 2 additions & 0 deletions message_ix/model/MESSAGE/data_load.gms
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ Set rating_unrated(rating) ;
rating_unrated(rating) = yes ;
rating_unrated('unrated') = no ;

Set newtec(tec) / wind_ppl / ;

*----------------------------------------------------------------------------------------------------------------------*
* assignment and computation of MESSAGE-specific auxiliary parameters *
*----------------------------------------------------------------------------------------------------------------------*
Expand Down
49 changes: 49 additions & 0 deletions message_ix/model/MESSAGE/model_learningeos.gms
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
SETS
size 'size' / small, medium, large / ;

ALIAS (size,size2);
PARAMETERS
cap_new2(node,newtec,year_all2) 'annual newly installed capacity'
bin_cap_new(node,newtec,year_all2) 'binary of newly installed capacity'
rho(newtec) 'economy of scale parameter' / wind_ppl 1 / #0.8
b(newtec) 'technology cost learning parameter' / wind_ppl 0 / #0.9
u(size) 'unit size'
/ small 5
medium 10
large 50 /
inv_cost_ref(node,newtec) 'initial capex'
nbr_unit_ref(newtec) 'initial number of unit' / wind_ppl 100 /
u_ref(newtec) 'reference size' / wind_ppl 5 / ;
inv_cost_ref(node,newtec) = 1500;

SCALAR hist_length the length of historical periods;
hist_length = card(year_all2) - card(model_horizon);

VARIABLES
NBR_UNIT(node,newtec,size,year_all2) number of units for each size every year
CAPEX_TEC(node,newtec,year_all2) capital cost in dollar per kW
OBJECT objective function ;

POSITIVE VARIABLES
NBR_UNIT ;

EQUATIONS
OBJECTIVE_INNER total investment cost
CAP_NEW_BALANCE installed capacity balance
CAPEX_ESTIMATE estimating average capex
INITIAL_YEAR annual investment cost
NO_BUILT_YEAR annual investment cost
;


OBJECTIVE_INNER.. OBJECT =e= sum((node,newtec,year_all2), CAPEX_TEC(node,newtec,year_all2)*cap_new2(node,newtec,year_all2)) ;
CAP_NEW_BALANCE(node,newtec,year_all2).. sum(size, NBR_UNIT(node,newtec,size,year_all2)*u(size)) =e= cap_new2(node,newtec,year_all2) ;
CAPEX_ESTIMATE(node,newtec,year_all2).. CAPEX_TEC(node,newtec,year_all2)*cap_new2(node,newtec,year_all2) =g= sum(size,inv_cost_ref(node,newtec)
* NBR_UNIT(node,newtec,size,year_all2)*u(size)
* [(((sum((size2,year_all3)$(ord(year_all3) le (ord(year_all2)-1) and ord(year_all3) gt hist_length), NBR_UNIT(node,newtec,size2,year_all3))+nbr_unit_ref(newtec))/nbr_unit_ref(newtec))**(-b(newtec)))]
* [((u(size)/u_ref(newtec))**rho(newtec))/(u(size)/u_ref(newtec))]) ;
INITIAL_YEAR(node,newtec,year_all2)$(ord(year_all2) eq 1).. CAPEX_TEC(node,newtec,year_all2) =e= inv_cost_ref(node,newtec) ;
NO_BUILT_YEAR(node,newtec,year_all2)$(ord(year_all2) gt 1).. CAPEX_TEC(node,newtec,year_all2) =e= bin_cap_new(node,newtec,year_all2)*CAPEX_TEC(node,newtec,year_all2)
+ (1-bin_cap_new(node,newtec,year_all2))*CAPEX_TEC(node,newtec,year_all2-1) ;

model learningeos / all /;
6 changes: 6 additions & 0 deletions message_ix/model/MESSAGE/model_setup.gms
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ $IF NOT SET out $SETGLOBAL out "output/MsgOutput.gdx"
* rolling horizon (period-by-period, recursive-dynamic with limited foresight - 'number of years of foresight'
$IF NOT SET foresight $SETGLOBAL foresight "0"

** define learning mode (active / inactive) **
* deactivate - 0 (assumed as default if not specified)
* activate - 1
$IF NOT SET learningmode $SETGLOBAL learningmode "0"

** specify optional additional calibration output **
$IF NOT SET calibration $SETGLOBAL calibration ""
* mark with * to include detailed calibration information in outputs and get an extended GAMS listing (.lst) file
Expand Down Expand Up @@ -84,3 +89,4 @@ $INCLUDE MESSAGE/scaling_investment_costs.gms
*----------------------------------------------------------------------------------------------------------------------*

$INCLUDE MESSAGE/model_core.gms
$INCLUDE MESSAGE/model_learningeos.gms
Loading