Adding Constraints to a model inside a loop in GAMS

371 views
Skip to first unread message

visva...@gmail.com

unread,
Feb 11, 2014, 8:39:31 AM2/11/14
to gams...@googlegroups.com
Hi,

According to the GAMS manual, one cannot make declarations or de fine 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.

José Miguel Quesada Pérez

unread,
Feb 11, 2014, 9:33:32 AM2/11/14
to gams...@googlegroups.com

You can formulate in a way that manages what you want.

I can think of two ways now.

 

Mode 1:

Parameter Include/0/;

 

Equation1()..

Equation2()..

EquationToAdd()$(Include=1)..

 

Model MyModel/all/;

 

Loop(i,

                If( i>=5, Include=1)

                Solve MyModel usiong ….);

 

 

*** In this example, you create or not the equation “EquationToAdd” based on the condition that Include is 1 or not. If is 0, that equation is not included. If is 1, it is included.

 

MODE 2:

Equation1()..

Equation2()..

EquationToAdd()..

 

Model MyModel1/Equation1,Equation2/

Model MyModel2/All/

 

Loop(i,

If(i<=5, Solve MyModel1…)

If(i>5,Solve MyModel2…));

 

 

***In this case you generate 2 models, one with the equation to include and one without it, and you run them discriminatively in according to your condition.

 

 

 

Best Regards

JM

--
You received this message because you are subscribed to the Google Groups "gamsworld" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+...@googlegroups.com.
To post to this group, send email to
gams...@googlegroups.com.
Visit this group at http://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/groups/opt_out.

visva...@gmail.com

unread,
Feb 12, 2014, 7:26:25 AM2/12/14
to gams...@googlegroups.com
Thanks a lot for your reply. It was exactly what I needed. Thanks again.

Best Regards,
VisValley
Reply all
Reply to author
Forward
0 new messages