CGE 3 GAMS * Date: 2018/07/24, Version 1.1 1 2 2 GAMSIDE 3 2.1 GAMS................................. 3 2.2 GAMSIDE................................ 3 2.3 GAMSIDE............................. 7 3 GAMS 11 3.1 GAMS...................................... 11 3.1.1................... 11 3.1.2 GAMS........................ 12 3.1.3 GAMS.......................... 12 3.1.4..................................... 13 3.1.5 GAMS........................ 14 3.2................................ 14 3.3 GAMS.................................... 15 3.4.................................... 15 3.4.1................................ 15 3.4.2 display................................... 16 3.4.3 $........................ 17 3.4.4 alias.......................... 17 3.4.5............................ 17 3.4.6................................... 19 3.4.7..................................... 20 3.4.8..................................... 20 3.4.9.............................. 21 3.4.10........................ 22 3.4.11 solve.................................... 22 * : http://shirotakeda.org/ja/research-ja/cge-howto.html Website: http://shirotakeda.org/ja/ 1
1. 3.4.12................................... 23 3.5..................................... 23 3.5.1 Solution Report................................. 24 3.5.2.............................. 25 3.5.3 MCP Marginal................... 25 4 GAMS 26 5 26 6 26 1 ˆ 3 CGE GAMS (General Algebraic Modelling System) GAMS CGE GAMS ˆ GAMS ˆ GAMS User's Guide ž GAMS GAMS corporation ž HTML : https://www.gams.com/latest/docs/ug_main.html ˆ Bruce McCarl ž GAMS ž McCarl ž gdxxrw.exe ž PDF : https://www.gams.com/fileadmin/community/contrib/doc/mccarlgamsuserguide. pdf ž HTML : https://www.gams.com/mccarlguide/gams_user_guide_2005.htm 2
2. GAMSIDE 2 GAMSIDE GAMS Windows GAMS GAMS GAMSIDE 1 GAMSIDE GAMS Windows GAMS 2.1 GAMS GAMS https://www.gams.com/download/ Windows 32bit 64bit 64bit Windows 64bit 2.2 GAMSIDE GAMSIDE GAMSIDE GAMSIDE GAMSIDE 1 GAMSIDE UNIX Mac GAMS Windows GAMS GAMSIDE Emacs Emacs GAMS mode for Emacs GAMSIDE 3
2. GAMSIDE C:YUserYstYDocumentsYgamsdirYprojdirYgamsproj.gpr GAMS C:YUserYstYDocumentsYgamsdirYprojdir GAMSIDE GAMS Project New Project g:ydropboxygams_practice practice New Project g:ydropboxygams_practice practice 4
2. GAMSIDE.gpr GAMSIDE GAMSIDE ide_howto.gms GAMSIDE File Open File Options MS 11pt MS 5
2. GAMSIDE File Options Colors Comment Italic Set associated text Bold 6
2. GAMSIDE 2.3 GAMSIDE GAMSIDE 1) GAMS 2) GAMSIDE GAMSIDE Bruce McCarl ˆ https://www.gams.com/fileadmin/community/contrib/doc/mccarlgamsuserguide.pdf ˆ https://www.gams.com/mccarlguide/gams_user_guide_2005.htm ide_howto.gms GAMS F9 Process Window GAMS 7
2. GAMSIDE *** Error 140 in G:DropboxYGAMS_practiceYide_howto.gms Unkown symbol Error 140 140 Unknown symbol GAMS diplay i, j; j j unknown symbol j diplay i, j alias j F9 unknown symbol GAMS paramter paramter unknown symbol parameter paramter paramter 8
2. GAMSIDE GAMSIDE GAMS unrecognizable item ; gms gms gamma gamma(i) = 1 ; GAMS ; ; ; 1 Error at line 24 Compilation error Execution error division by zero 24 0 gms gms 24 GAMSIDE 18:14 18 14 24 9
2. GAMSIDE 24 gamma(i) = gamma(i) / sigma; sigma sigma 0 division by zero sigma 0 10 Status: Normal completion GAMS ide_howto.gms ide_howto.lst LST 10
Display sigma LST sigma LST GAMSIDE GAMS ˆ ˆ GMS ˆ 3 GAMS 3.1 GAMS GAMS 3.1.1 ˆ GAMS gms ž ˆ 11
ž GAMS ž sample.gms sample.lst lst LST 3.1.2 GAMS ˆ declaration ˆ ž price Price PRICE GAMS ž GAMS ˆ ; ž GAMS ž ˆ ž * * ž $ontext $offtext 3.1.3 GAMS ˆ ž j = {1,, n} f = {labor, capital, land} j f GAMS set ˆ ž GAMS parameter ž 2 CES ž ˆ 2 12
ž GAMS variable ž ˆ ž GAMS equation ˆ ž ž 3.1.4 GAMS variable 4 x ˆ level value ž x x ž x.l x display x.l; x 10 x.l = 10; ˆ lower value upper value ž lower bound upper bound ž x.lo x.up x 0 x.lo = 0 ž GAM -inf GAMS +inf ˆ Marginal marginal value ž marginal ž 13
GAMS LP NLP MCP MIP 1: GAMS linear programming non-linear programming Mixed complementarity problem 3.1.5 GAMS GAMS solver Solver GAMS 15 1 GAMS MCP MCP mixed complementarity problem MCP MCP MCP 4 3.2 non-linear programming [ ] σ σ 1 max u = γ i (d i ) σ 1 σ {d 1,,d n} s.t. i i p i d i = m u d i i p i i m γ i σ 1 CGE GAMS CGE 3 L = [ i γ i (d i ) σ 1 σ ] σ [ σ 1 λ i p i d i m 3 CGE CGE ] 14
1 L = σ 1 γ j (d j ) σ 1 σ γ i (d i ) 1 σ λpi = 0 {d i } i=1,,n (1) d i j [ ] L λ = p i d i m = 0 {λ} (2) i {d i } n (1) 1 (2) n + 1 GAMS 3.3 GAMS utility_max.gms GAMS GAM- SIDE GAMS 3.4 $title $ontext Time-stamp: <2013-10-14 17:48:30 st> First-written: <2013/10/11> $offtext $title LST $ontext $offtext 3.4.1 * * set i Index of goods / agr Agricultural goods man Manufacturing goods ser Services /; 15
set i set set set i Index of goods / agr Agricultural goods man Manufacturing goods ser Services /; / i agr man ser Index of goods i Agricultural goods set i / agr, man, ser /; set GAMS User Manual 3.4.2 display display i; i display display GAMSIDE i agr man ser 16
3.4.3 $ $title $ set Dollar Control Option $ dollar control option GAMS compilation time execution time GAMS $ 3.4.4 alias * i j alias(i,j); display j; alias i j alias static set static set dynamic set 3.4.5 $ontext 17
$offtext parameter p(i) m ; Goods price Income p(i) m 2 parameter parameter parameter p(i) m Goods price Income ; p(i) m Goods price Income p(i) m p i i agr man ser p("agr") p("man") p("ser") 3 p p("agr")=1 p(i) parameter p(i), m; p("agr") = 1; p("man") = 2; p("ser") = 3; m = 100; display p, m; p m display p i i p Parameter p(i) Goods price / agr 1 man 2 ser 3 / m Income / 100 / 18
; / $ontext $offtext parameter gamma(i) Weight parameter sigma Elasticity of substitution ; * gamma gamma(i) = 1; gamma(i) = gamma(i)/sum(j, gamma(j)); display gamma; sigma = 0.5; display sigma; gamma sigma gamma(i) = 1; gamma(i) = gamma(i)/sum(j, gamma(j)); gamma(i) 1/3 2 GAMS = 3.4.6 $ontext variables $offtext variables d(i) Demand lambda Lagrange multiplier ; variables variable ˆ variables parameter ˆ variables d(i) lambda 19
3.4.7 * * $ontext equations e_ + $offtext equations e_d(i) 1st order condition for d(i) e_lambda 1st order condition for lambda ; equation equations equations variables ˆ (1) e_d(i) ˆ lambda (2) e_lambda 3.4.8 * * e_d(i).. (sum(j, gamma(j)*(d(j))**((sigma-1)/sigma)))**(1/(sigma-1)) * gamma(i) * (d(i))**(-1/sigma) - lambda * p(i) =e= 0; e_lambda.. - (sum(i, p(i)*d(i)) - m) =e= 0;.. ; 2 ; = =e= =g= =l= 4 (1) (2) 4 3.4.5 GAMS = 20
3.4.9 * * $ontext. e_d.d e_d d $offtext model utility_max Utility maximization / e_d.d, e_lambda.lambda /; model model / /; MCP. / e_d.d, e_lambda.lambda / e_d e_lambda 2 2 e_d d e_lambda lambda 4 1) 2) MCP NLP MCP 4 21
3.4.10 * * d.lo(i) = 0; lambda.lo = 0; * * d.l(i) = 10; lambda.l = 10; 3.1.4.lo d lambda 0 2 3.1 d lambda 10 10 3.4.11 solve * * option mcp = path; solve utility_max using mcp; solve MCP NLP LP solve MCP solve utility_max using mcp; solve using mcp; option mcp = path; Solver MCP PATH 22
Solver Solver Solver 3.4.12 5 Parameter results ; results(i,"price") = p(i); results("/","income") = m; results(i,"demand") = d.l(i); results("/","lambda") = lambda.l; results(i,"exp") = p(i)*d.l(i); results("sum","exp") = sum(i, results(i,"exp")); results("/","utility") = (sum(i, gamma(i)*(d.l(i))**((sigma-1)/sigma)))**(sigma/(sigma-1)); display results; results d(i) lambda results.l d.l(i) lambda.l 3.5 3.3 MCP Solution Report REPORT SUMMARY 5 CGE 23
3.5.1 Solution Report Solution Report SOLVE SUMMARY ˆ MODEL ˆ TYPE MCP ˆ SOLVER solver MCP solver PATH SOVER STATUS MODEL STATUS STATUS 1 S O L V E S U M M A R Y MODEL utility_max TYPE MCP SOLVER PATH FROM LINE 115 **** SOLVER STATUS 1 Normal Completion **** MODEL STATUS 1 Optimal SOVER STATUS MODEL STATUS 1 S O L V E S U M M A R Y 24
MODEL utility_max TYPE MCP SOLVER PATH FROM LINE 115 **** SOLVER STATUS 2 Iteration Interrupt **** MODEL STATUS 6 Intermediate Infeasible utility_max.gms 3.5.2 SolVAR VAR d Demand LOWER LEVEL UPPER MARGINAL agr. 24.118 +INF 2.4569E-7 man. 17.054 +INF -1.246E-7 ser. 13.925 +INF -2.042E-8 LOWER LEVEL UPPER MARGINAL VAR lambda. 0.175 +INF. lambda Lagrange multiplier 3.1 GAMS lower value upper value level value marginal marginal value 4 LST LOWER LEVEL UPPER MARGINAL d("agr") 0 0 +INF 24.118 marginal 2.4569E-7=2.4569/10 7 3.5.3 MCP Marginal Marginal MCP marginal d(i) 3.4.9 e_d(i) e_d(i) e_d(i).. (sum(j, gamma(j)*(d(j))**((sigma-1)/sigma)))**(1/(sigma-1)) 25
4. GAMS * gamma(i) * (d(i))**(-1/sigma) - lambda * p(i) =e= 0; d(i) marginal 10 (sum(j, gamma(j)*(d(j))**((sigma-1)/sigma)))**(1/(sigma-1)) * gamma(i) * (d(i))**(-1/sigma) - lambda * p(i) = 10 d("agr") marginal e_d("agr") e_d("agr") e_d("agr") d("agr") marginal marginal 4 GAMS 5 1 min {h 1,,h n} e = i p i h i s.t. [ i γ i (h i ) σ 1 σ ] σ σ 1 = u GAMS γ i σ 3.3 u 3.3 6 ˆ 2018-07-20: ˆ 2017-03-15: 26