GAMS 如何编写带变量约束的方程
GAMS 如何編寫帶變量約束的方程
問題描述
| time | 時(shí)間 |
| t1 | 某特定時(shí)間 |
| t2 | 某特定時(shí)間 |
| x(time) | 隨時(shí)間變化的值 |
并且,t2 - t1 = 5,即 t1 到 t2 的時(shí)間長(zhǎng)度是固定的
| t1 ≤ time ≤ t2 | P(t) = 4000 |
| 其余時(shí)間段 | P(t) = 0 |
GMAS中$表?xiàng)l件判斷,理想條件應(yīng)該是
Equation con1(t);con1(t)$(t>t1 and t<t2).. P(t)=4000;但遺憾的是,GAMS不支持在變量在$判斷中
解決方法
用0-1變量作為“開關(guān)”
alias(time,tt);Equation con1(time) con2(time) con3 con4(time) con5(time) ;con1(time)$(ord(time)>=2 and ord(t) <= (T-tcx+1).. sum(tt$((ord(tt) ge ord(time)) and (ord(tt) le (ord(time)+tcx-1))),X(tt)) =g= (X(time)-X(time-1))*tcx; con2(time)$(ord(time)=1).. sum(tt$((ord(tt) ge ord(time)) and (ord(tt) le (ord(time)+tcx-1))),X(tt)) =g= X(time)*tcx; con3.. sum(time,X(time)) =e= tcx; con4(time).. P(time) =e= 4000*X(time);con1約束是持續(xù)時(shí)間約束:
當(dāng)time在大于2,小于T-tcx+1(此處共24個(gè)時(shí)段,T取24;tcx表示持續(xù)時(shí)間,為5)時(shí),對(duì)time(包括time自己)后的5個(gè)時(shí)段的X(time)進(jìn)行求和,這個(gè)和要為5*(X(time)-X(time-1))。X(time)-X(time-1)表示該時(shí)刻是否為開啟時(shí)刻,當(dāng)為開啟時(shí)刻時(shí),X(time)-X(time-1)=1,其余時(shí)間為0。
con2約束也是持續(xù)時(shí)間約束:
與con1的不同之處在于,由于第1個(gè)時(shí)刻沒有time-1,也就無法做X(time)-X(time-1),所以直接就是X(time)。
con3約束保證24個(gè)時(shí)段內(nèi),只有唯一的5個(gè)時(shí)段中X(time)=1。否則就可能1-5時(shí)段內(nèi),X(time)=1,11-15時(shí)段,X(time)也為1。
con4約束是為P(time)賦值。只有當(dāng)X(time)=1時(shí),P(time)=4000。
總結(jié)
以上是生活随笔為你收集整理的GAMS 如何编写带变量约束的方程的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 开发一个领券接口过程
- 下一篇: uniapp小程序使用支付宝商家券领券组