Writing Equations with varying index

Problems with syntax of GAMS
Post Reply
arvindmarandi
User
User
Posts: 8
Joined: 1 year ago

Writing Equations with varying index

Post by arvindmarandi »

Hello GAMS Community,

I am a beginner in GAMS and learning to model things using its syntax.

Here is my problem,

Given,

Code: Select all

set i /1,2/
x(i)
y(i);

How can I write constraints equations say, x1 + y2 <= 1 similarly, x2 + y1 <= 1 ?


I know, defining an equation like this

Code: Select all

eq(i).. x(i) + y(i) <= 1
will cover x(1) + y(1) <= 1 and x(2) + y(2) <= 1.

But How can I do x1 + y2 <= 1?

Do I have to use a condition somewhere?
abhosekar
Moderator
Moderator
Posts: 295
Joined: 3 years ago

Re: Writing Equations with varying index

Post by abhosekar »

Arvind,
In such cases it helps to think in terms of indices and sets. For example, key question to ask here is how many equations do you need? for each i, you need i-1 equations (total i * (i-1) equations) This gives you a hint that your equation should be defined over 2 dimensions. However, in the equation, you need to distinguish between two dimensions. This where you can use an alias. Finally, just a condition that you write this equation only when i is not same as ii. The following code block achieves this.

Code: Select all

alias(i, ii);
eq(i, ii)$(ord(ii) ne ord(i)).. x(i) + y(ii) <= 1;
- Atharv
Post Reply