Assistance Required for Code Issues and Errors in GAMS

I am writing to seek assistance with several issues and errors I am encountering in my GAMS code. I am currently working on a model that involves importing data from a TXT file. My GAMS code:

* Define sets and parameters based on bank data
Set
   i /1*3/     ! Input categories: labor, physical capital, equity capital
   r /1*2/     ! Output categories: net operating income, non-performing loans
   j /1*2/  ! Banks (DMUs)
   t /2018*2021/  ! Time period
   kh /1*2/;   ! Links between stages: Deposits, Loans, Securities
Alias(j,k);

* Parameters: input and output data for banks
Parameter
   xt(i,j,k,t) "Inputs for bank j in stage k at time t"
   yt(r,j,k,t) "Outputs for bank j in stage k at time t"
   Zfree(kh,t) "Linking intermediate products"
   Zbadcarry(k,t) "Undesirable carry-over activities";

* Including data from external source txt formatted for GAMS
INCLUDE C:\Users\S M T\Desktop\chapter1\Book1.TXT;   ! Bank data inputs in txt format

* Variables for model
Variable lambda(j,k,t), smin(i,k,t), splus(r,k,t);
Variable zfree(j,kh,t), slack(kh,t), zbadcarry(j,k,t), sbadcarry(j,k,t);
Variable theta, Wt(t), wk(k);

* Equation 1: Summation constraint for intensities
Equation eq1;
eq1(j,k,t).. sum(j, lambda(j,k,t)) =e= 1;

* Equation 2: Input-output matrices and slacks
Equation eq2x, eq2y;
eq2x(i,k,t).. xt(i,j,k,t) =g= sum(j, lambda(j,k,t)) + smin(i,k,t);
eq2y(r,k,t).. yt(r,j,k,t) =l= sum(j, lambda(j,k,t)) - splus(r,k,t);

* Equation 3: Free linking of activities between stages
Equation eq3;
eq3(kh,t).. Zfree(kh,t) =e= sum(j, lambda(j,kh,t)) + slack(kh,t);

* Equation 4: Free link slack between stages
Equation eq4;
eq4(kh,t).. zfree(j,kh,t) =e= Zfree(kh,t)*lambda(j,k,t) + slack(kh,t);

* Equation 5: Undesirable carry-over activities
Equation eq5;
eq5(k,t).. zbadcarry(j,k,t) =g= Zbadcarry(k,t)*lambda(j,k,t) + sbadcarry(j,k,t);

* Equation 6: Efficiency objective function
Equation objective;
objective.. theta =e= min(sum(t, Wt(t) * sum(k, wk(k) * (1 - (1/(3+2)) * sum(i, smin(i,k,t)/xt(i,k,t)
                      + sbadcarry(k,t)/Zbadcarry(k,t))))
                      + sum(k, wk(k) * (1 + (1/(2+2)) * sum(r, splus(r,k,t)/yt(r,k,t)))))));

* Model definition and solving
Model efficiencyModel /all/;
Solve efficiencyModel using lp minimizing theta;

* Use 'put' to output the results
File output /'results.txt'/;
put output;
put "Objective Function Value: ", theta.l /;
loop((j,k,t),
   put "Lambda(", j, ",", k, ",", t, "): ", lambda.l(j,k,t) /;
);

There are several syntax issues with your model:

  • If you use ! as an end of line comment symbol, you need to tell GAMS about this via $eolcom !.
  • GAMS is case insensitve, so you can have a parameter Zbadcarry and a variable zbadcarry. You need to rename one of them. Same with Zfree/zfree.
  • smin is a reserved word in GAMS, so you can’t use this as a symbol name.
  • The include needs to start with a $. Also, I would quote the path if there are spaces in the path. Moreover, don’t add a ;. The $include is a compiler directive. Not part of the GAMS language. You did not send the include file, so there might be more syntax errors in this file.
  • Understand the concept of controlling indices. When you reference an index then it needs to be controlled once, either by the equation definition or by an indexed operation (like sum). You have e.g. eq1(k,j,t).. sum(j, lambda(j,k,t)) =e= 1; i.e. you control j twice and in eq2x(i,k,t).. xt(i,j,k,t) =g= sum(j, lambda(j,k,t)) + smin_(i,k,t); the j in xt(i,j,k,t) not at all. I “corrected” this mechanically, but I am not sure if the “corrections” make any sense for your model.
  • In eq3(kh,t).. Zfree(kh,t) =e= sum(j, lambda(j,kh,t)) + slack(kh,t); you use set kh in lambda but that has domain k (which is an alias to j). Even though the elements of set kh and j are the same (namely 1 and 2) they are different for GAMS. So either make kh also an alias of j or create a map between kh and j or relate them in some other way.
  • The min in objective.. theta =e= min(sum(... makes no sense.
  • You objective is non-linear (multiplication of variables), so you can’t solve as an LP.
  • If you print set element labels via put, you need to specigy .tl.

In the attached model I corrected all this and use random data, so I can compile and execute.

All this is well documented in the documentation of GAMS. I suggest that you go through the documentation in more detail.

-Michael

new1.gms (2.6 KB)

I wanted to take a moment to thank you for all your help in resolving the issue I was facing. Your assistance was invaluable, and I truly appreciate the time and effort you put into finding a solution.
Thank you again for everything!