$ontext Example from chapter 3: "Some Microeconomic Principles" Reference: Steven A. Gabriel, Antonio J. Conejo, J. David Fuller, Benjamin F. Hobbs, Carlos Ruiz Complementarity Modeling in Energy Markets Springer 2012 $offtext SETS i 'firms' /i1,i2,i3/ b 'production process (mines)' /b1,b2/ ; TABLE c(i,b) 'variable cost' b1 b2 i1 0.55 0.81 i2 0.62 1.25 i3 0.78 1.35 ; TABLE K(i,b) 'process capacities' b1 b2 i1 21000 16000 i2 17000 22000 i3 18000 14000 ; parameters alpha 'inverse demand intercept' / 2.5 / beta 'inverse demand slope' / 0.000016666666667 / ; *------------------------------------------------------------------------------- * Reporting macro *------------------------------------------------------------------------------- parameters Revenue(i), VarCost(i), ProdSurp, TotProdSurp, SocWel; parameters Price, ConsPay, ConsSurp, TotProdSurp; Parameter PResults(*,*,*,*); option PResults:3:2:2; Parameter CResults(*,*); option CResults:3:1:1; $macro report(name) \ Price = alpha-beta*q.l; \ ConsPay = Price*q.l; \ ConsSurp = alpha*q.l -0.5*beta*q.l**2 - Price*q.l; \ Revenue(i) = Price*sum(b, x.l(i,b)); \ VarCost(i)= sum(b, C(i,b)*x.l(i,b)); \ ProdSurp(i) = Revenue(i)-VarCost(i); \ TotProdSurp = sum(i, ProdSurp(i)); \ SocWel = ConsSurp + TotProdSurp; \ display x.l, Revenue, VarCost, ProdSurp; \ display q.l, Price, ConsPay, ConsSurp, TotprodSurp, SocWel; \ \ Presults(name,'x',i,b) = x.l(i,b); \ Presults(name,'revenue',i,'b1') = Revenue(i); \ Presults(name,'var.cost',i,'b1') = VarCost(i); \ Presults(name,'surplus',i,'b1') = ProdSurp(i); \ display PResults; \ \ Cresults(name,'q') = q.l; \ Cresults(name,'p') = Price; \ Cresults(name,'ConsPay') = ConsPay; \ Cresults(name,'ConsSurpl') = ConsSurp; \ Cresults(name,'ProdSurpl') = TotProdSurp; \ Cresults(name,'SocWelfare') = SocWel; \ display CResults; \ *------------------------------------------------------------------------------- * Maximize Social Welfare * NLP Model *------------------------------------------------------------------------------- POSITIVE VARIABLES x(i,b) 'production by i from process b' q 'demand quantity' ; VARIABLES W 'social welfare' ; EQUATIONS SocialWelDef 'social welfare definition' Capacity(i,b) 'upper limit of generating output' MarketClear 'market clearing' ; SocialWelDef.. W =e= alpha*q-0.5*beta*q**2 - sum((i,b), C(i,b)*x(i,b)); Capacity(i,b).. x(i,b) =l= K(i,b); MarketClear.. q =e= sum((i,b), x(i,b)); MODEL SocWelMax /SocialWelDef,Capacity,MarketClear/; SOLVE SocWelMax maximizing W using nlp; report('PriceTakers(NLP)') *------------------------------------------------------------------------------- * Maximize Social Welfare * MCP Model *------------------------------------------------------------------------------- POSITIVE VARIABLES gamma(i,b) 'dual of capacity constraint' ; FREE VARIABLES lambda 'price' ; EQUATIONS PriceDef 'price definition as inverse demand' Mx(i,b) 'KKT condition for derivative w.r.t. x' Capacity2(i,b) '=g= version of capacity constraint' ; PriceDef.. lambda - (alpha-beta*q) =g= 0; MX(i,b).. C(i,b) - lambda + gamma(i,b) =g= 0; Capacity2(i,b).. - x(i,b) + K(i,b) =g= 0; MODEL CompetComplem /PriceDef.q, Mx.x, Capacity2.gamma, MarketClear.lambda/; solve CompetComplem using MCP; report('PriceTakers(MCP)') *------------------------------------------------------------------------------- * Monopoly * NLP Model *------------------------------------------------------------------------------- VARIABLES TotProfit 'total profit' ; EQUATIONS TotalProfit 'Total profit calculation' ; TotalProfit.. TotProfit =e= (alpha-beta*q)*q - sum((i,b), C(i,b)*x(i,b)); MODEL Monopoly /TotalProfit,Capacity,MarketClear/; SOLVE Monopoly maximizing TotProfit using nlp; report('Monopoly') *------------------------------------------------------------------------------- * Oligopoly (Nash-Cournot) * MCP Model *------------------------------------------------------------------------------- alias (b,bb); EQUATIONS Mx2(i,b) 'KKT condition for derivative w.r.t. x' ; MX2(i,b).. C(i,b) - lambda + beta*sum(bb,x(i,bb)) + gamma(i,b) =g= 0; MODEL Oligopoly /PriceDef.q, Mx2.x, Capacity2.gamma, MarketClear.lambda/; solve Oligopoly using MCP; report('Cournot(MCP)') *------------------------------------------------------------------------------- * Oligopoly (Nash-Cournot) * NLP Model *------------------------------------------------------------------------------- VARIABLES CournotObj 'Obj for Cournot model as NLP' ; EQUATIONS DefCournotObj 'Obj for Cournot model as NLP' ; DefCournotObj.. CournotObj =e= alpha*q-0.5*beta*q**2 - sum((i,b), C(i,b)*x(i,b)) - 0.5*sum(i, beta*sqr(sum(b,x(i,b)))); MODEL CournotNLP /DefCournotObj,Capacity,MarketClear/; SOLVE CournotNLP maximizing CournotObj using nlp; report('Cournot(NLP)') *------------------------------------------------------------------------------- * Cournot (firm1) + Price Takers (firm2+3) * NLP Model *------------------------------------------------------------------------------- set iCournot(i) /i1/ ; VARIABLES Obj 'Obj for Cournot/Pricetaking model as NLP' ; EQUATIONS DefObj 'Obj for Cournot/Pricetaking model as NLP' ; DefObj.. Obj =e= alpha*q-0.5*beta*q**2 - sum((i,b), C(i,b)*x(i,b)) - 0.5*sum(iCournot,beta*sqr(sum(b,x(iCournot,b)))); MODEL CombNLP /DefObj,Capacity,MarketClear/; SOLVE CombNLP maximizing Obj using nlp; report('CombA(NLP)') *------------------------------------------------------------------------------- * Cournot (firm1+firm2) + Price Takers (firm3) * NLP Model *------------------------------------------------------------------------------- iCournot('i2') = yes; SOLVE CombNLP maximizing Obj using nlp; report('CombB(NLP)') *------------------------------------------------------------------------------- * Cournot (firm1) + Price Takers (firm2+3) * MCP Model *------------------------------------------------------------------------------- iCournot(i) = no; iCournot('i1') = yes; equation MXComb(i,b) 'First order condition'; MXComb(i,b).. C(i,b) - lambda + (beta*sum(bb,x(i,bb)))$Icournot(i) + gamma(i,b) =g= 0; MODEL Comb1MCP /PriceDef.q, MxComb.x, Capacity2.gamma, MarketClear.lambda/; ; SOLVE Comb1MCP using mcp; report('CombA(MCP)') *------------------------------------------------------------------------------- * Cournot (firm1+firm2) + Price Takers (firm3) * MCP Model *------------------------------------------------------------------------------- iCournot('i2') = yes; SOLVE Comb1MCP using mcp; report('CombB(MCP)')
|