Add dynamically constraints to a model

Problems with syntax of GAMS
Post Reply
Luca
User
User
Posts: 23
Joined: 6 years ago

Add dynamically constraints to a model

Post by Luca »

Dear all,

I am implemented a kind of branch-and-cut algorithm in GAMS. I need to add dynamically constraints to my model: how can I do it? I think I have to use dynamic set, but I don't know how.
Thanks in advance,
Luca
GabrielYin
User
User
Posts: 72
Joined: 6 years ago
Location: Dallas, TX, USA
Contact:

Re: Add dynamically constraints to a model

Post by GabrielYin »

Hi,

I do not know whether you want to add one more constraint per iteration or not. But here is my example. This is a Benders Decomposition example, and it works for adding one more Benders cut constraint to the master problem in each iteration. I use semi-pseudocode to enhance readability.

Code: Select all

Set
         k  iteration counter /1*100/
         i  /1*10/;

Set      cutset(k)   dynamic set;
cutset(k) = no;

**** Build your Model ****

Parameter  alpha(k), beta(k,i), ...;
Scalar     ...;
Free Variable   objective, eta...;
Positive Variable  x(i), ...;
Negative Variable  ...;

Equations
         obj, con1, con2, BDcut(k);

obj..            objective =e= eta + ...;
con1..           ...;
con2..           ...;
BDcut(cutset)..  alpha(cutset) + sum(i, beta(cutset,i) * x(i)) =l= eta;

Model BDmaster /all/;

Loop(k,
         ...;
         cutset(k) = yes;
         solve BDmaster use LP min objective;
);

display ..;
I have tried to write the codes explicitly. For more reference, you can reach the dynamic set documentation as follows.
https://www.gams.com/latest/docs/UG_DynamicSets.html

Cheers!

Gabriel
Luca
User
User
Posts: 23
Joined: 6 years ago

Re: Add dynamically constraints to a model

Post by Luca »

Thanks very much Gabriel for your answer.
Post Reply