Different errors to solve

Problems with syntax of GAMS
Post Reply
mgarnhamo
User
User
Posts: 5
Joined: 2 years ago

Different errors to solve

Post by mgarnhamo »

Hi! I'm new to this forum!

I have some questions regarding a code I made for the reuse of water in a household based on a paper I read. The code's purpose is to minimize freshwater use while maintaining the limit water conditions of contaminants j for the operations i, and waters are treated in treatment plants t.

I have a couple errors i got stuck with for a while and i hope i could get some help :)

The code is this one:

Code: Select all

option limrow = 0;
option limcol = 0;
option solprint = on;
option sysout = off;

option LP=CPLEX;
option MIP=CPLEX;
option NLP=SNOPT;
option MINLP=DICOPT;
option OPTCR=0;
$ontext

a = 0.25
Wi >= a*(sum(F(t,i))+ sum(FWi))



CFW(i,j)*FW(i) + M(i,j) = W(i)*CW(i,j) + F(i,t)*CF(i,j,t)
Sum[i,*F(i,t)*CF(i,j,t)]*R(t,j) = Sum[i,F(t,i)]*CT(i,t,j)
fw(5)=0 y f(5,t)=0

                                        [M(i,j)] [W(i),CF(i,j)]
                                              ||      /\
                                              V       ||
[Agua potable,CFW] =FW(i)=> [Operación i] =F(i,t),CF(i,j)=> [Tratamiento t, R(t,j)]
                                 /\                                                           ||
                                 \\                                                          //
                                   ========FT(i,t),CT(t,j)=========
$offtext
SETS
j contaminante /j1*j4/
i operacion /i1*i5/
t tratamientos /t1*t2/

PARAMETERS


x(i) flujo minimo de agua por operacion /i1=72,i2=152,i3=32,i4=164,i5=144/
cfw(j) restricciones para j en operaciones con agua potable /j1=0,j2=0,j3=1,j4=10/
cnp(j) restricciones para j en operaciones con agua no potable /j1=4.2,j2=5.0,j3=0.5,j4=3.2/ ;

Table Cin(i,j) max que puede ingresar de contaminante j a la operación i (CFW*FW+CT*FT):(FT+FW)=C'in<Cin

         j1      j2      j3      j4
     i1  0       0       1       10
     i2  10      15      3       25.4
     i3  10      15      3       25.4
     i4  10      15      3       25.4
     i5  10      15      3       25.4    ;

Table Cout(i,j) max que puede salir de cont. j de la operación i  M+C'in-W*CW=F(i.t)*CF<Cout

         j1      j2      j3      j4
     i1  463.3   245     23.33   50.1
     i2  81.32   59.47   3.95    50.19
     i3  232.5   59.47   73.25   50.28
     i4  361.2   267.6   52.44   50.67
     i5  297.8   347.8   15.28   50.76   ;

Table M(i,j) mass of pollutant j added in operation i. it is not a restriction it is a data

         j1      j2      j3      j4
     i1  33.36   17.64   1.61    2.89
     i2  10.84   6.76    0.14    3.77
     i3  7.12    1.42    2.25    0.80
     i4  57.6    41.42   8.11    4.14
     i5  41.44   47.92   1.77    3.65    ;

Table R(t,j) 1 - factor removal of the contaminant j in the treatment t 

         j1      j2      j3      j4
     t1  0.14    0.03    1       0.93
     t2  0.6     0.01    0.01    0.04    ;


VARIABLES

apot
fw(i)     agua potable que entra para cada proceso i
w(i)      aguas negras de cada proceso i
f(i,t)    aguas que serán reutilizadas en t luego de ser usadas en i
ft(i,t)   agua reutilizada luego del tratamiento t para el proceso i
cf(i,j)   concentracion de j en las aguas que salen de i
ct(t,j)   concentracion de j de las aguas que salen de t



;

POSITIVE VARIABLES
apot
fw(i)     fresh water that goes into the operation i (L/day)
w(i)      waste water from operation i (L/day)
f(i,t)    grey water that will be treated in t after being used in i (L/day)
ft(i,t)   reused water from treatment t going to be used in i (L/day)
cf(i,j)   concentration of j in waters coming from i (mg/L)
ct(t,j)   concentration of j in waters coming from t (mg/L)

;
EQUATIONS
funobj, volumenin, toilet1, toilet2, waste,eq1, eq2, eq3, eq4
;
funobj.. apot =E= sum(i,fw(i)) ;
volumenin(i)..  sum(t,ft(i,t))+fw(i)=G=x(i)     ;
toilet1(i).. fw('i5')=E=0 ;
toilet2(i).. sum(t,f('i5',t))=E=0 ;
waste(i)..  w(i) =G= 0.25*(sum(t,ft(i,t))+fw(i))
eq1(i,j)..  (fw(i)*cfw(j)+sum(t,ct(t,j)*ft(i,t)))/(sum(t,ft(i,t))+fw(i)))=L= Cin(i,j)  ;
eq2(i,j)..  M(i,j)+(fw(i)*cfw(j)+sum(t,ct(t,j)*ft(i,t)))/(sum(t,ft(i,t))+fw(i)))=E= w(i)*cf(i,j)+sum(t,f(i,t))*cf(i,j) ;
eq3(t,j)..  sum(i,f(i,t)*cf(i,j))*R(t,j) =E= sum(i,ft(i,t))*ct(t,j) ;
eq4(i,j)..  sum(t,f(i,t))*cf(i,j) =L= Cout(i,j) ;
MODEL  aguapotable /all/

SOLVE  aguapotable using nlp minimizing apot ;
And the output is this one:

Code: Select all

GAMS 34.3.0  rac355f3 Released Feb 25, 2021 WEX-WEI x86 64bit/MS Windows - 07/25/21 18:08:12 Page 1
G e n e r a l   A l g e b r a i c   M o d e l i n g   S y s t e m
C o m p i l a t i o n


   1  option limrow = 0;
   2  option limcol = 0;
   3  option solprint = on;
   4  option sysout = off;
   5   
   6  option LP=CPLEX;
   7  option MIP=CPLEX;
   8  option NLP=SNOPT;
   9  option MINLP=DICOPT;
  10  option OPTCR=0;
      FW1 >= 72
      FW2 >= 152
      Ft2,i3 >= 32
      FW4 + Ft1,i4 + Ft2,i4 >=164
      Ft1,i5 + Ft2,i5 >= 144
      a = 0.25
      Wi >= a*(sum(F(t,i))+ sum(FWi))
       
       
       
      CFW(i,j)*FW(i) + M(i,j) = W(i)*CW(i,j) + F(i,t)*CF(i,j,t)
      Sum[i,*F(i,t)*CF(i,j,t)]*R(t,j) = Sum[i,F(t,i)]*CT(i,t,j)
      fw(5)=0 y f(5,t)=0
       
                                [M(i,j)] [W(i),CF(i,j)]
                                    ||      /\
                                    V       ||
      [Agua potable,CFW] =FW(i)=> [Operación i] =F(i,t),CF(i,j)=> [Tratamiento t
      , R(t,j)]
                                       /\                                 ||
                                       \\                                //
                                         ========FT(i,t),CT(t,j)=========
  34  SETS
  35  j contaminante /j1*j4/
  36  i operacion /i1*i5/
  37  t tratamientos /t1*t2/
  38   
  39  PARAMETERS
  40   
  41   
  42  x(i) flujo minimo de agua por operacion /i1=72,i2=152,i3=32,i4=164,i5=144/
  43  cfw(j) restricciones para j en operaciones con agua potable /j1=0,j2=0,j3=
      1,j4=10/
  44  cnp(j) restricciones para j en operaciones con agua no potable /j1=4.2,j2=
      5.0,j3=0.5,j4=3.2/ ;
  45   
  46  Table Cin(i,j) max que puede ingresar de contaminante j a la operación i (
      CFW*FW+CT*FT):(FT+FW)=C'in<Cin
  47   
  48           j1      j2      j3      j4
  49       i1  0       0       1       10
  50       i2  10      15      3       25.4
  51       i3  10      15      3       25.4
  52       i4  10      15      3       25.4
  53       i5  10      15      3       25.4    ;
  54   
  55  Table Cout(i,j) max que puede salir de cont. j de la operación i  M+C'in-W
      *CW=F(i.t)*CF<Cout
  56   
  57           j1      j2      j3      j4
  58       i1  463.3   245     23.33   50.1
  59       i2  81.32   59.47   3.95    50.19
  60       i3  232.5   59.47   73.25   50.28
  61       i4  361.2   267.6   52.44   50.67
  62       i5  297.8   347.8   15.28   50.76   ;
  63   
  64  Table M(i,j) masa de contaminante j que se agrega en la operación i. no es
       una restricción es un dato
  65   
  66           j1      j2      j3      j4
  67       i1  33.36   17.64   1.61    2.89
  68       i2  10.84   6.76    0.14    3.77
  69       i3  7.12    1.42    2.25    0.80
  70       i4  57.6    41.42   8.11    4.14
  71       i5  41.44   47.92   1.77    3.65    ;
  72   
  73  Table R(t,j) 1 - el factor de remoción del contaminante j en el tratamient
      o t
  74   
  75           j1      j2      j3      j4
  76       t1  0.14    0.03    1       0.93
  77       t2  0.6     0.01    0.01    0.04    ;
  78   
  79   
  80  VARIABLES
  81   
  82  apot
  83  fw(i)     agua potable que entra para cada proceso i
  84  w(i)      aguas negras de cada proceso i
  85  f(i,t)    aguas que serán reutilizadas en t luego de ser usadas en i
  86  ft(i,t)   agua reutilizada luego del tratamiento t para el proceso i
  87  cf(i,j)   concentracion de j en las aguas que salen de i
  88  ct(t,j)   concentracion de j de las aguas que salen de t
  89   
  90   
  91   
  92  ;
  93   
  94  POSITIVE VARIABLES
  95  apot
  96  fw(i)     agua potable que entra para cada proceso i
  97  w(i)      aguas negras de cada proceso i
  98  f(i,t)    aguas que serán reutilizadas en t luego de ser usadas en i
  99  ft(i,t)   agua reutilizada luego del tratamiento t para el proceso i
 100  cf(i,j)   concentracion de j en las aguas que salen de i
 101  ct(t,j)
 102   
 103  ;
 104  EQUATIONS
 105  funobj, volumenin, toilet1, toilet2, waste,eq1, eq2, eq3, eq4
 106  ;
 107  funobj.. apot =E= sum(i,fw(i)) ;
 108  volumenin(i)..  sum(t,ft(i,t))+fw(i)=G=x(i)     ;
 109  toilet1(i).. fw('i5')=E=0 ;
 110  toilet2(i).. sum(t,f('i5',t))=E=0 ;
 111  waste(i)..  w(i) =G= 0.25*(sum(t,ft(i,t))+fw(i))
 112  eq1(i,j)..  (fw(i)*cfw(j)+sum(t,ct(t,j)*ft(i,t)))/(sum(t,ft(i,t))+fw(i)))=
****    $409
      L= Cin(i,j)  ;
**** 409  Unrecognizable item - skip to find a new statement
****        looking for a ';' or a key word to get started again
 113  eq2(i,j)..  M(i,j)+(fw(i)*cfw(j)+sum(t,ct(t,j)*ft(i,t)))/(sum(t,ft(i,t))+f
      w(i)))=E= w(i)*cf(i,j)+sum(t,f(i,t))*cf(i,j) ;
****       $37,408,409
****  37  '=l=' or '=e=' or '=g=' operator expected
**** 408  Too many ),] or }
**** 409  Unrecognizable item - skip to find a new statement
****        looking for a ';' or a key word to get started again
 114  eq3(t,j)..  sum(i,f(i,t)*cf(i,j))*R(t,j) =E= sum(i,ft(i,t))*ct(t,j) ;
 115  eq4(i,j)..  sum(t,f(i,t))*cf(i,j) =L= Cout(i,j) ;
 116  MODEL  aguapotable /all/
 117   
 118  SOLVE  aguapotable using nlp minimizing apot ;
****                                             $246,257
**** 246  Objective variable is not a free variable
**** 257  Solve statement not checked because of previous errors

**** 6 ERROR(S)   0 WARNING(S)


COMPILATION TIME     =        0.093 SECONDS      3 MB  34.3.0 rac355f3 WEX-WEI
I hope i could get help asap
User avatar
bussieck
Moderator
Moderator
Posts: 1033
Joined: 7 years ago

Re: Different errors to solve

Post by bussieck »

The gms code and the lst do not match. I worked off the gms code. There were some syntax errors (better quote text with '/', too many closing parenthesis, other minor stuff) but the main issue was uninitialized variable level. You should read about the importance of a starting point for local NLP solvers at https://www.gams.com/latest/docs/S_CONO ... IAL_VALUES. I did not pay too much attention on initialization, but kept it away from 0. This was sufficient to get a solution of 0. The corrected code is in the attachment.
new12.gms
(3.99 KiB) Downloaded 180 times
-Michael
mgarnhamo
User
User
Posts: 5
Joined: 2 years ago

Re: Different errors to solve

Post by mgarnhamo »

Thanks for the input and the working code, i still have a question though, in my variable table i have a parameter that i know is constant ( f(i5)=0) , and the equation that i made doesn´t make a difference, so the result is not correct. Any advice for that issue?
Inmensely graetful
- Matías
Post Reply