How to add Constraints inside a loop in GAMS

Problems with modeling
Post Reply
matteoc5
User
User
Posts: 7
Joined: 3 years ago

How to add Constraints inside a loop in GAMS

Post by matteoc5 »

Dear All,

According to the GAMS manual, one cannot make declarations or define equations inside a loop.

I need to add constraints to the mathematical model inside a loop and execute the solve statement. Is there any other way to add constraints to a model inside a loop?

Thanks in advance.
User avatar
gamsadmin
Site Admin
Site Admin
Posts: 16
Joined: 7 years ago

Re: How to add Constraints inside a loop in GAMS

Post by gamsadmin »

Hi
You could introduce a flag.

Here the idea in code:

Code: Select all

set lnr /1*10/;

parameter flag(lnr);

flag(lnr) = 0;
flag("1") = 1;

equations
   constrflagged   'The constraint you want to be flagged',
   ....
 
 constrflagged$flag(lnr)..
   ...
   
 model mymodel /all/;
 
 loop(lnr,
   solve mymodel ...
 );  
Cheers
Renger
Post Reply