GAMS编写综合能源程序

    学习GAMS 一段时间编写了基于能源枢纽的程序,四节点,九节点的综合能源系统优化程序。本文先介绍一下能源枢纽的编程思路。

综合能源的相关论文有很多,自行查就可以了。

***************************************************************************************************

*先建立了时间T集合,后输入负荷和能源输入参数,

***************************************************************************************************

set t  period of time /1*24/
    tfirst(t);

    tfirst(t)=yes$(ord(t) eq 1);

Parameters p_wind(t) mei xiao shi lai feng liang (KW) /1  3600 ,2  3500,
            3 3100 , 4   2900,  5  2900 ,6  2800 ,
            7 2500 ,8   2200 , 9  2300 , 10  2400 ,
            11 2400 ,12  2400 ,  13 2300 ,14  2200 ,
            15 2100 ,16   2200 , 17 2000 ,18  1900 ,
            19 2000 ,20  2300 , 21 2600 ,22  2800 ,
            23 3200 ,24  3600 /
          Le(t)   load of electric (kw)    /1  1600,  2  1700,
            3  1800,   4  1800,  5  1800,   6   1950,
            7  2100,   8  2200,  9  2300,   10  2300,
            11  2350,  12  2350, 13  2350,  14  2300,
            15  2300,  16  2250, 17  2250,  18  2300,
            19  2350,  20  2450, 21  2400,  22  2100,
            23  1700,  24 1550   /
          Le_1(t)   load of 可平移负荷 (kw)    /1  400,  2  400,
            3  400,   4  400,  5  400,   6   400,
            7  400,   8  400,  9  400,   10  400,
            11  400,  12  400, 13 400,  14  400,
            15  400,  16  400, 17  400,  18  400,
            19  400,  20  400, 21  400,  22  400,
            23  400,  24 400   /
          Lh(t)   load of hot (kw)    /1  1400,  2  1400,
            3  1400,   4  1400,  5  1400,   6   1400,
            7  1100,   8  1100,  9  800,   10  800,
            11  1400,  12  1400, 13  1400,  14  800,
            15  800,  16  800, 17  1100,  18  1100,
            19  1100,  20  1100, 21  1250,  22  1250,
            23  1100,  24 1100   /
           Lg(t)   load of gas (kw)    /1  200,  2  200,
            3  200,   4  300,  5  250,   6   400,
            7  400,   8  450,  9  600,   10  700,
            11  700,  12  700, 13  650,  14  650,
            15  600,  16  700, 17  600,  18  600,
            19  700,  20  750, 21  900,  22  900,
            23  700,  24 650   /
           e(t)   price of electric (kw)    /1  10,  2  10,
            3    8,   4    9,  5   10,   6    13,
            7   18,   8   20,  9   21,   10   21,
            11  21,  12   20,  13  18,   14   17,
            15  16,  16   17,  17  19,   18   23,
            19  26,  20   24,  21  22,   22   20,
            23  17,  24   16   /
           g(t)   price of gas (kw)    /1  8.5,  2  8.5,
            3    8.5,   4    8.5,  5   8.5,   6    8.5,
            7    8.5,   8    8.5,  9   8.5,   10   8.5,
            11   8.5,   12   8.5,  13  8.5,   14   8.5,
            15   8.5,   16   8.5,  17  8.5,   18   8.5,
            19   8.5,   20   8.5,  21  8.5,   22   8.5,

            23   8.5,   24   8.5   /;

*************************************************************************************************************************

*接下来结束输入各种设备的参数,能源间的转化效率,等等

*EB电锅炉;GB气锅炉;MT微燃机,P2G设备;GS,HS,ES 分别是储气,储热,储电

*************************************************************************************************************************

scalar      elta_p2g  The efficiency of power to gas  /0.5/;
scalar      elta_MTe  Micro-gas turbine power generation efficiency /0.26/;
scalar      elta_MTh  Micro-gas turbine heat  efficiency /0.3/;
scalar      elta_EB   Electric boiler thermal efficiency /0.9/;

scalar      elta_GB   Gas boiler thermal efficiency      /0.85/;

scalar      Ebcmax       Electric boiler rated operating                      /1500/;
scalar      Ebcmin       minimum operating power of Electric boiler            /0/;
scalar      Ebc_ratemax     Electric boiler input power change rate              /1000/;
scalar      Ebc_ratemin     Electric boiler input power change rate              /-1000/;

scalar      Gbcmax       Gas boiler ratated operating                       /1000/;
scalar      Gbcmin       minimum operating power of Gas boiler               /0/;
scalar      Gbc_ratemax     Gas boiler input power change rate             /1000/;
scalar      Gbc_ratemin     Gas boiler input power change rate             /-500/;

scalar      MTcmax      micro gas turbine rated operating                     /800/;
scalar      MTcmin      minimum operating power of MT          /0/;
scalar      MT_ratemax     MT input power change rate             /200/;
scalar      MT_ratemin     MT input power change rate             /-200/;

scalar      P2Gcmax         P2G rated operating                     /0/;
scalar      P2Gcmin         minimum operating power of P2G          /0/;
scalar      P2G_ratemax     P2G input power change rate             /0/;
scalar      P2G_ratemin     P2G input power change rate             /0/;

scalar     pemax                     /4000/;
scalar     pemin                     /800/;


scalar     pgmax                     /4000/;
scalar     pgmin                     /0/;

scalar      GSmax       Natural gas tank capacity           /0/;
scalar      GSmin                   /0/ ;
scalar      GS_ratemax              /0/;
scalar      GS_0                    /0/;

scalar      HSmax       Thermal energy storage capacity        /0/;
scalar      HSmin                   /0/ ;
scalar      HS_ratemax              /0/;
scalar      HS_0                    /0/;

scalar      ESmax       Thermal energy storage capacity        /0/;
scalar      ESmin                   /0/ ;
scalar      ES_ratemax              /0/;

scalar      ES_0                    /0/;

 

*********************************************************************************************************************

*后边就是优化变量,方程求解了

*********************************************************************************************************************

positive variables

           pe(t)        Purchase power
           pg(t)        The amount of purchased natural gas
           pw(t)        Wind power generation


           pe2g(t)      power to gas
           pEB(t)       Electricity consumed by electric boilers
           pMT(t)       GAS consumed by micro gas turbine
           pGB(t)       GAS consumed by gas boiler


           WG(t)        GAS storage  xian you liang
           WH(t)        GAS storage  xian you liang
           WE(t)


Free variable
           pgs(t)       "Gas storage capacity"
           phs(t)
           pes(t)
           qifengliang
           Z  objective ;




*binary variable
*          U(t);


Equations p_e(t)           Electric load balancing
          p_h(t)           Heat load balance
          p_g(t)           Natural gas load balance
*shuru ce yue shu
          pwind_conmax(t)     Wind power generation constraints
          pe_conmax(t)
          pe_conmin(t)
          pg_conmax(t)
          pg_conmin(t)
* she bei yun xing yue shu
          Ebc_conmax(t)
          Ebc_conmin(t)
          dEbc_conmax(t)
          dEbc_conmin(t)
          Gbc_conmax(t)
          Gbc_conmin(t)
          dGbc_conmax(t)
          dGbc_conmin(t)
          MTc_conmax(t)
          MTc_conmin(t)
          dMTc_conmax(t)
          dMTc_conmin(t)
          P2Gc_conmax(t)
*         P2Gc_conmin(t)
*         dP2Gc_conmax(t)
* chu neng yue shu
         elc_storage
         ES_conmax(t)
         ES_conmin(t)
         WWE(t)
         WWE_conmax(t)
         WWE_conmin(t)


         gas_storage
         GS_conmax(t)
         GS_conmin(t)
         WWG(t)
         WWG_conmax(t)
         WWG_conmin(t)


         hot_storage
         HS_conmax(t)
         HS_conmin(t)
         WWH(t)
         WWH_conmax(t)
         WWH_conmin(t)




         qifeng
* mu biao han shu
          ff               Objective function    ;

*这几句是能源枢纽模型的主要函数
 p_e(t)..   pe(t)+pw(t)-pe2g(t)-PEB(t)+ elta_MTe*pMT(t)+pes(t)  =e= (Le(t)+Le_1(t));
 p_h(t)..   elta_MTh*pMT(t)+ pEB(t)*elta_EB+elta_GB*pGB(t)+phs(t) =e= Lh(t);
 p_g(t)..   pg(t)+elta_p2g*pe2g(t)- pMT(t)-pGB(t)+pgs(t) =e= Lg(t);


 pwind_conmax(t).. pw(t) =l= p_wind(t);
 pe_conmax(t)..   pe(t)=l= pemax;
 pe_conmin(t)..   pe(t)=g= pemin;
 pg_conmax(t)..   pg(t)=l= pgmax;
 pg_conmin(t)..   pg(t)=g= pgmin;

 Ebc_conmax(t)..  pEB(t) =l= Ebcmax;
 Ebc_conmin(t)..  pEB(t) =g= Ebcmin;
 dEbc_conmax(t)..(PEB(t+1)-PEB(t)) =l= Ebc_ratemax;
 dEbc_conmin(t)..(PEB(t+1)-PEB(t)) =g= Ebc_ratemin;
 Gbc_conmax(t).. pGB(t) =l= Gbcmax;
 Gbc_conmin(t).. pGB(t) =g= Gbcmin;
 dGbc_conmax(t)..(PGB(t+1)-PGB(t)) =l= GBc_ratemax;
 dGbc_conmin(t)..(PGB(t+1)-PGB(t)) =g= GBc_ratemin;
 MTc_conmax(t).. pMT(t) =l= MTcmax;
 MTc_conmin(t).. pMT(t) =g= MTcmin;
 dMTc_conmax(t)..(PMT(t+1)-PMT(t)) =l= MT_ratemax;
 dMTc_conmin(t)..(PMT(t+1)-PMT(t)) =g= MT_ratemin;
 P2Gc_conmax(t).. pe2g(t) =l= P2Gcmax;




elc_storage.. sum(t,pes(t)) =e= 0;
ES_conmax(t)..pes(t) =l= ES_ratemax;
ES_conmin(t)..pes(t) =g= -ES_ratemax;
WWE(t+1)..WE(t+1) =e= WE(t)-pes(t);
WWE_conmax(t).. WE(t) =l= ESmax;
WWE_conmin(t).. WE(t) =g= 0;


gas_storage.. sum(t,pgs(t)) =e= 0;
GS_conmax(t)..pgs(t) =l= GS_ratemax;
GS_conmin(t)..pgs(t) =g= -GS_ratemax;
WWG(t+1)..WG(t+1) =e= WG(t)-pgs(t);
WWG_conmax(t).. WG(t) =l= GSmax;
WWG_conmin(t).. WG(t) =g= 0;


hot_storage.. sum(t,phs(t)) =e= 0;
HS_conmax(t)..phs(t) =l= HS_ratemax;
HS_conmin(t)..phs(t) =g= -HS_ratemax;
WWH(t+1)..WH(t+1) =e= WH(t)-phs(t);
WWH_conmax(t).. WH(t) =l= HSmax;
WWH_conmin(t).. WH(t) =g= 0;


qifeng.. qifengliang =e=sum(t,(P_wind(t)-pw(t))) ;
ff..    z =e= sum(t,(e(t)*pe(t)+ g(t)* pg(t)) )   ;




model P2g /all/;
*---------------------------------------------------------
WG.fx(tfirst) = GS_0;
WH.fx(tfirst) = HS_0;
*---------------------------------------------------------
Solve p2g using LP minimizing z ;
 

display z.l,pe.l,pg.l,pw.l,p_wind,pe2g.l,PgB.l,PEB.l,Pmt.l,pgs.l,WG.L,qifengliang.l;

这个能源枢纽的程序写的很简陋,也很简单。当初初学的时候编写的程序,但是运行应该没问题。

 

 

上面是自己摸索的时候学的,没有太好的编程逻辑。

如果想较系统的学一下,我最近也有分享此类的内容

搜索“GAMS系列分享”,查看GAMS在电力系统(综合能源)中的应用!!!

搜索“GAMS系列分享”,查看GAMS在电力系统(综合能源)中的应用!!!

搜索“GAMS系列分享”,查看GAMS在电力系统(综合能源)中的应用!!!

 

 

 

  • 10
    点赞
  • 47
    收藏
    觉得还不错? 一键收藏
  • 18
    评论
好的,您的问题是如何用GAMS编写基于IEEE33节点配电网的运行成本最小化优化程序。 以下是一些步骤和示例代码: 1. 定义变量: 假设有n个节点,每个节点都有一个电源和若干个负载。我们可以为每个节点定义一个变量,表示从该节点到负载的电流。 ``` Variables i(n,n) flow of current from node i to node j p(n) active power at node i q(n) reactive power at node i v(n) voltage at node i cost total cost of operation ; ``` 2. 定义目标函数: 我们的目标是最小化运行成本,即最小化所有节点的电费和。 ``` Equation obj define objective function ; obj.. cost =e= sum(i, c(i)*p(i)) + sum(i, c(i)*q(i)); ``` 其中c(i)是第i个节点的电费率,p(i)和q(i)是节点i的有功和无功功率。 3. 定义约束条件: 我们需要确保每个节点的电流和功率保持平衡。 ``` Equation node_balance(i) node i power balance ; node_balance(i).. p(i) =e= sum(j, i(j,i)*v(i)*v(j)) - sum(j, i(i,j)*v(i)*v(j)); ``` 其中,i(j,i)表示从节点j到节点i的电流,i(i,j)表示从节点i到节点j的电流,v(i)表示节点i的电压。 4. 定义非线性约束条件: 配电网中有一些非线性元件,例如变压器和容性电容器,需要特殊处理。 ``` Equation transformer(i) transformer constraint capacitor(i) capacitor constraint ; transformer(i).. i(i,t)*v(i) - i(t,i)*v(t) =e= 0; capacitor(i).. q(i) =l= c(i)*v(i)^2; ``` 其中,i(t,i)表示从变压器t到节点i的电流,i(i,t)表示从节点i到变压器t的电流,v(t)表示变压器t的电压,c(i)表示节点i的电容。 5. 定义模型: 将以上定义的变量、目标函数和约束条件组合成一个GAMS模型。 ``` Model distribution /all/; distribution.optcr = 0.01; % set optimality tolerance distribution.solprint = %solprint%; % set solution printing format distribution.objfcn = obj; % set objective function distribution.. node_balance(i) =e= 0; % set power balance constraint distribution.. transformer(i) =e= 0; % set transformer constraint distribution.. capacitor(i) =e= 0; % set capacitor constraint ``` 6. 求解模型: 使用GAMS内置的求解器来求解模型,例如CPLEX、GUROBI等。 ``` solve distribution using %solver% minimizing cost; ``` 7. 分析结果: 分析模型的解决方案,例如查看每个节点的电流和功率等。 ``` Display i.l, p.l, q.l, v.l, cost.l; ``` 以上是一个用GAMS编写基于IEEE33节点配电网的运行成本最小化优化程序的示例代码。
评论 18
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值