Sum with limited domain

Problems with syntax of GAMS
Post Reply
ErickMiranda
User
User
Posts: 4
Joined: 5 years ago

Sum with limited domain

Post by ErickMiranda »

Hello, i'm new in GAMS, i want to know how to do a Sum defined just in a part of the set

example:

Set i /1, 2, 3, 4, 5, 6, 7/

Variable X(i);

Ecuations
pro;
orp;
pro.. sum (i from 1 to 4 , X(i)) =e= 1;
orp.. sum (i from 5 to 7, X(i)) =e= 1;

i hope you can help me

Regards
cbhomia
User
User
Posts: 8
Joined: 5 years ago

Re: Sum with limited domain

Post by cbhomia »

Hi,

You will need to understand the use of conditional statements and dollar($) control over sets.
You may use the syntax of ord(i) which refers to the position of element in a set, or the value function i.val() .

sum (i from 1 to 4 , X(i)) =e= 1 --> sum(i$ [ord(i) <= 4], x(i)) =e= 1;
OR
sum (i from 1 to 4 , X(i)) =e= 1 --> sum(i$ [val(i) <= 4], x(i)) =e= 1;

However, you also have not defined the equations correctly. a ';' is required once all the equations have been declared.

Understanding the GAMS Tutorial might prove useful. One of the links is below.

https://www.gams.com/latest/docs/UG_Tutorial.html

Regards
cbhomia
ErickMiranda
User
User
Posts: 4
Joined: 5 years ago

Re: Sum with limited domain

Post by ErickMiranda »

thank you very much, your reply was what i needed
Post Reply