首页 > 解决方案 > GAMS 中的问题(错误 669、8、37、409)

问题描述

我的代码(与 Matlab 接口)中有一些错误,我无法解决它们。

26  $if exists $ include matdata.gms
****            $668

1 - 无法理解此错误,也无法找到有关它的信息。

 58  PiCalc(b,t)..                    Pi(b,t) =e= P(b,t) + c(b,t) - d(b,t);
****                                     $37,409

 37  '=l=' or '=e=' or '=g=' operator expected

2 - 我不明白这里有什么问题,因为我清楚地使用了 '=e=' 运算符。

59  P_linhaCalc(l,t)..               P_linha(l,t) =e= sum(b, A(l,b)*Pi(b,t));
****                                                                    $8,409
 8  ')' expected
 409  Unrecognizable item - skip to find a new statement
       looking for a ';' or a key word to get started again

3 - 同样,当它出现时,我不明白缺少的 ')'。

任何反馈表示赞赏。

完整代码如下:

** Define the structure to connect with the matlab code
*$onempty
$include matglobs.gms
*$if exists $ include matdata.gms

set      t /1*%timeSteps%/,
         b /1*%bus%/,
         l /1*%lines%/
         ;

Positive Variable d(b,t),
                  c(b,t)
                  ;

Free Variable res;

parameters       size(b), rate(b),lim_linhas(l), P(b,t), A(l,b),
                 cost, soc(b,t),
                 P_linha(l,t),
                 pen, bat(b), preco(t)
                 ;

$if exists $ include matdata.gms

Equations

socCalc1(b,t)
socCalc2(b,t)
maxDischarge(b,t)
maxCharge(b,t)
PiCalc(b,t)
P_linhaCalc(l,t)
penCalc(l,t)
Con10(b)
Con11
Obj
;

socCalc1(b,t)$(ord(t)=1)..      soc(b,t) =e= size(b)/2;
socCalc2(b,t)$(ord(t)>1)..      soc(b,t) =e= soc(b,t-1) + c(b,t) - d(b,t);

maxDischarge(b,t)..              d(b,t) =l= rate(b)*size(b);
maxCharge(b,t)..                 c(b,t) =l= rate(b)*size(b);

PiCalc(b,t)..                    Pi(b,t) =e= P(b,t)+c(b,t)-d(b,t);

P_linhaCalc(l,t)..               P_linha(l,t) =e= sum(b, A(l,b)*Pi(b,t));

penCalc(l,t)$(P_linha(l,t) > lim_linhas(l))..  pen =e= pen - (P_linha(l,t) - lim_linhas(l))*100000;

Con10(b)..                       sum(t, d(b,t)*preco(t) - c(b,t)*preco(t)) =e= bat(b);
Con11..                          sum(b, bat(b)) =e= cost;

Obj..                            cost + pen =e= res;

Model Opt_Bat /all/;

Solve Opt_Bat using MINLP minimizing res;

$libinclude matout res.l

标签: gams-math

解决方案


1:

26  $if exists $ include matdata.gms
****            $668

1 - 无法理解此错误,也无法找到有关它的信息。

错误 668 的解释文本是:“$if [NOT] unquoted command is ambiguous, use quotes around expression”。问题是,您在这里的语法有点不正确。您可能想写以下内容?

$if exist matdata.gms $include matdata.gms

2/3:

58  PiCalc(b,t)..                    Pi(b,t) =e= P(b,t) + c(b,t) - d(b,t);
****                                     $37,409

 37  '=l=' or '=e=' or '=g=' operator expected

2 - 我不明白这里有什么问题,因为我清楚地使用了 '=e=' 运算符。

You do not define any symbol called pi. But there is a GAMS "function" called pi: https://www.gams.com/latest/docs/UG_Parameters.html#INDEX_functions_22_pi This does not have any arguments, so that the opening ( causes the error here. So you probably miss the declaration of "your" pi which would overwrites the GAMS pi. Your point 3 has the same cause


推荐阅读