stochastic programming

Problems with modeling
Post Reply
anan
User
User
Posts: 20
Joined: 5 years ago

stochastic programming

Post by anan »

Hello everyone,
I really appreciate your help and I have a problem in my code I wish it is the last one
it says that the
Wait-See model is infeasible

Code: Select all

$ontext
this code for 6-bus system considering the line constraints when solved as deterministic the cost=110915

after solving the deterministic problem this code has PV uncertainity model considered in Irradiance variability
modeld as two stage stochastic
and considered as Weibull PDF
$offtext


Set
   t 'time'               / t1*t24   /
   i 'generators indices' / g1*g3   /
   k 'cost segments'      / sg1*sg20 /
   char                   / ch1*ch2  /
   l number of lines  /1*7/
   bus        / 1*6   /
   r          /pv1/;
Alias (t,h);
Alias (bus,node);
scalar  eff /0.75/
        irr /0/
        mw   /1000/;
        
Table gendata(i,*) 'generator cost characteristics and limits'
       bus Pmax Pmin a      b      c       CostsD  costst RU   RD   SU   SD   UT   DT   uini U0  S0 fuel
   g1  1   220  100  0.050  10     100     0       100    55   55   105  108  4    4    0    4   0  1
   g2  2   100  10   0.001  40.66  162     0       200    50   50   106  112  2    3    0    0   3  1
   g3  6   20   10   0.006  22.06  171     0       0      20   20   43   45   1    1    0    0   1  1;
   
Table WD(t,*)
        d       solar
   t1   175.19  0
   t2   165.15  0
   t3   158.67  0
   t4   154.73  0
   t5   155.06  0
   t6   160.48  0
   t7   168.39  1
   t8   177.6   1
   t9   186.81  1
   t10  206.96  1
   t11  228.61  1
   t12  236.1   1
   t13  242.18  1
   t14  243.6   1
   t15  248.86  1
   t16  255.79  1
   t17  256     1
   t18  246.74  0
   t19  245.97  0
   t20  237.35  0
   t21  236.31  0
   t22  232.67  0
   t23  208.93  0
   t24  195.6   0   ;
   
Table branch(bus,node,*)
       x        limit  
1.2    0.17     200  
1.4    0.258    100   
2.3    0.037    100   
2.4    0.197    100  
3.6    0.018    100   
4.5    0.037    100  
5.6    0.14     100 ;

Table BusData(bus,*) percent of hourly load of each bus
    Pd
3   0.2
4   0.40
5   0.40;

Set GB(bus,i)
/
   1.g1
   2.g2
   6.g3/;

Parameter pvarea(bus) / 5 10000 /;

* -----------------------------------------------------
* linearizing the quadratic fuel cost FC = a*p*p + b*p + c;
Parameter data(k,i,*);
data(k,i,'DP')       =(gendata(i,"Pmax") - gendata(i,"Pmin"))/card(k);
data(k,i,'Pini')     =(ord(k) - 1)*data(k,i,'DP') + gendata(i,"Pmin");
data(k,i,'Pfin')     = data(k,i,'Pini') + data(k,i,'DP');
data(k,i,'Cini')     = gendata(i,"a")*data(k,i,'Pini')*data(k,i,'Pini')
                     + gendata(i,"b")*data(k,i,'Pini') + gendata(i,"c");
data(k,i,'Cfin')     = gendata(i,"a")*data(k,i,'Pfin')*data(k,i,'Pfin')
                     + gendata(i,"b")*data(k,i,'Pfin') + gendata(i,"c");
data(k,i,'s')        =(data(k,i,'Cfin') - data(k,i,'Cini'))/data(k,i,'DP');
gendata(i,'Mincost') = gendata(i,'a')*gendata(i,"Pmin")*gendata(i,"Pmin")
                     + gendata(i,'b')*gendata(i,"Pmin") + gendata(i,'c');
* -----------------------------------------------------
branch(bus,node,'x')$(branch(bus,node,'x')=0)         =   branch(node,bus,'x');
branch(bus,node,'Limit')$(branch(bus,node,'Limit')=0) =   branch(node,bus,'Limit');
branch(bus,node,'bij')$branch(bus,node,'Limit')       = 100*(1/branch(bus,node,'x'));
branch(bus,node,'z')$branch(bus,node,'Limit')         = branch(bus,node,'x');
branch(node,bus,'z')                                  = branch(bus,node,'z');

Parameter conex(bus,node);
conex(bus,node)$(branch(bus,node,'limit') and branch(node,bus,'limit')) = 1;
conex(bus,node)$(conex(node,bus)) = 1;

* eq. (5.5d) page 122
Parameter unit(i,char);
unit(i,'ch1') = 24;
unit(i,'ch2') =(gendata(i,'UT') - gendata(i,'U0'))*gendata(i,'Uini');
gendata(i,'Lj') = smin(char,unit(i,char));

*eq. (5.6d) page 123
Parameter unit2(i,char);
unit2(i,'ch1')  = 24;
unit2(i,'ch2')  =(gendata(i,'DT') - gendata(i,'S0'))*(1 - gendata(i,'Uini'));
gendata(i,'Fj') = smin(char,unit2(i,char));

Variable costThermal,delta(bus,t),Pij(bus,node,t);
Positive Variable pu(i,t), p(i,t), StC(i,t), SDC(i,t), Pk(i,t,k),pv(bus,t),ir;
Binary Variable u(i,t), y(i,t), z(i,t);

p.up(i,t)    = gendata(i,"Pmax");
p.lo(i,t)    = 0;
Pk.up(i,t,k) = data(k,i,'DP');
Pk.lo(i,t,k) = 0;
p.up(i,t)    = gendata(i,"Pmax");
pu.up(i,h)   = gendata(i,"Pmax");

Equation
   Uptime1, Uptime2, Uptime3, Dntime1, Dntime2, Dntime3, Ramp1, Ramp2,
   startc, shtdnc, genconst1, Genconst2, Genconst3, Genconst4,const1,const2,pvout,irout;
   
*,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
irout.. irr =e= ir;

pvout(bus,t).. pv(bus,t)=e= ir*WD(t,'solar')*pvarea(bus)/mw;


const1(bus,node,t)$(conex(bus,node))..
   Pij(bus,node,t) =e= branch(bus,node,'bij')*(delta(bus,t) - delta(node,t));

const2(bus,t).. sum(i$GB(bus,i), p(i,t))+pv(bus,t) - sum(node$conex(node,bus), Pij(bus,node,t)) =e= BusData(bus,'pd')*(WD(t,'d'));


Pij.up(bus,node,t)$((conex(bus,node))) = 1*branch(bus,node,'Limit');
Pij.lo(bus,node,t)$((conex(bus,node))) =-1*branch(bus,node,'Limit');







* minimum up time constraints
Uptime1(i)$(gendata(i,"Lj")>0)..
   sum(t$(ord(t)<(gendata(i,"Lj")+1)), 1 - U(i,t)) =e= 0;

Uptime2(i)$(gendata(i,"UT")>1)..
   sum(t$(ord(t)>24-gendata(i,"UT")+1), U(i,t) - y(i,t)) =g= 0;

Uptime3(i,t)$(ord(t)>gendata(i,"Lj") and ord(t)<24-gendata(i,"UT")+2 and not(gendata(i,"Lj")>24-gendata(i,"UT")))..
   sum(h$((ord(h)>ord(t)-1) and (ord(h)<ord(t)+gendata(i,"UT"))), U(i,h)) =g= gendata(i,"UT")*y(i,t);

* minimum down time constraints 
Dntime1(i)$(gendata(i,"Fj")>0)..
   sum(t$(ord(t)<(gendata(i,"Fj")+1)), U(i,t)) =e= 0;

Dntime2(i)$(gendata(i,"DT")>1)..
   sum(t$(ord(t)>24-gendata(i,"DT")+1), 1 - U(i,t) - z(i,t)) =g= 0;

Dntime3(i,t)$(ord(t)>gendata(i,"Fj") and ord(t)<24-gendata(i,"DT")+2 and not(gendata(i,"Fj")>24-gendata(i,"DT")))..
   sum(h$((ord(h)>ord(t)-1) and (ord(h)<ord(t)+gendata(i,"DT"))), 1-U(i,h)) =g= gendata(i,"DT")*z(i,t);
   
* start-up and shut-down constraints 
startc(i,t).. StC(i,t) =g= gendata(i,"costst")*y(i,t);
shtdnc(i,t).. SDC(i,t) =g= gendata(i,"CostsD")*z(i,t);

* eq. (5.3d) P lower >= Pmin which PL = Pmin + Pk
genconst1(i,h)..
   p(i,h)    =e= u(i,h)*gendata(i,"Pmin") + sum(k, Pk(i,h,k));

* Eq. (5.4a)
Genconst2(i,h)$(ord(h)>0)..
   U(i,h)    =e= U(i,h-1)$(ord(h)>1) + gendata(i,"Uini")$(ord(h)=1) + y(i,h) - z(i,h);
* Eq. (5.2a)
Genconst3(i,t,k)..
   Pk(i,t,k) =l= U(i,t)*data(k,i,'DP');
   

* ramp rate constraints 
Ramp1(i,t)..             p(i,t+1) - p(i,t) =l= gendata(i,'RU');;
Ramp2(i,t)..             p(i,t-1) - p(i,t) =l= gendata(i,'RD');;


* Objective Function
Genconst4..
   costThermal =e= sum((i,t), StC(i,t) + SDC(i,t))
                +  sum((t,i), u(i,t)*gendata(i,'Mincost') + sum(k, data(k,i,'s')*pk(i,t,k)));
                
Model UCLP / all /;
file emp / '%emp.info%' /; put emp '* problem %gams.i%'/;
$onput
randvar irr weibull 3 0.78


stage 2 irr ir pv p Pij pk delta StC SDC u y z      
stage 2  pvout irout const2 const1 Ramp1 Ramp2 genconst1 genconst2 genconst3 Uptime2 Uptime3 Dntime1 Dntime2 Dntime3 startc shtdnc
$offput
putclose emp;

Set scen        Scenarios / s1*s6 /;
Parameter
    s_irr(scen)   irr by scenarioo;
Set dict / scen .scenario.''
           irr    .randvar .s_irr /;
option emp=lindo;
*option optCr = 0.0;
option reslim = 86400;
*option Savepoint=1;
option optcr=0.005;



solve UCLP min costThermal use emp scenario dict;
Display s_irr;
$ontext
Parameter report(t,bus,*),solar(bus,*);
report(t,bus,'Gen(MW)')    = 1*sum(i$GB(bus,i), P.l(i,t));
solar(bus,'PV output(MW)')    = pv.l(bus)
$ifI %system.fileSys%==Unix $exit
$call MSAppAvail Excel
$ifThen not errorLevel 1
   execute_unload "case2_3.gdx" report
   execute 'gdxxrw.exe  case2_3.gdx o=case2_3.xls par=report rng=report!A1'
   execute_unload "case2_3.gdx" P.l
   execute 'gdxxrw.exe  case2_3.gdx o=case2_3.xls var=P rng=PGen!A1'
   execute_unload "case2_3.gdx" solar
   execute 'gdxxrw.exe  case2_3.gdx o=case2_3.xls par=solar rng=PV!A1'
   execute_unload "case2_3.gdx" costThermal.l
   execute 'gdxxrw.exe  case2_3.gdx o=case2_3.xls var=costThermal rng=costThermal!A1'
$endIf
$offtext
User avatar
bussieck
Moderator
Moderator
Posts: 1038
Joined: 7 years ago

Re: stochastic programming

Post by bussieck »

Have slack variables with high costs to make the second stage problem always feasible.

-Michael
Post Reply