SETS
t        /1*6/
w        /1*3/
;

SCALAR  Cost  /20/;
SCALAR  Pmax  /150/;
SCALAR  Pmin  /50/;
SCALAR  RU  /50/;
SCALAR  RD  /50/;
SCALAR  Alfa /0/;

Table Price(w,t)
         1       2       3       4       5       6
1        25      15      26      16      27      17
2        22      22      22      22      22      22
3        15      25      14      24      13      23
;

PARAMETER Prob(w)
/1       0.3
2        0.4
3        0.3/;

PARAMETER AvergPrice(t);  AvergPrice(t) = sum(w,Prob(w)*Price(w,t));

VARIABLES
CVaR
VaR
etta(w)
PG(t)
Profit(w)
;

*PG.fx('1')=50;
*PG.fx('2')=100;
*PG.fx('3')=50;
*PG.fx('4')=50;
*PG.fx('5')=50;
*PG.fx('6')=67;

EQUATIONS
FO
ProfitEq
MaxPower
MinPower
RUlimit
RDlimit
Risk1
Risk2
;

FO..             CVaR =e= VaR - sum(w,(1/(1-Alfa))*Prob(w)*etta(w));

ProfitEq(w)..    Profit(w) =e= sum(t,(Price(w,t)-Cost)*PG(t));

MaxPower(t)..    PG(t) =l= Pmax;

MinPower(t)..    PG(t) =g= Pmin;

RUlimit(t)$(ord(t) gt 1)..
                 PG(t) =l= PG(t-1) + RU;

RDlimit(t)$(ord(t) gt 1)..
                 PG(t) =g= PG(t-1) - RD;

Risk1(w)..       -Profit(w) + VaR - etta(w) =l= 0;

Risk2(w)..       etta(w) =g= 0;

MODEL SelfSche /all/;

SOLVE SelfSche maximizing CVaR using lp;

display AvergPrice;
