Page 1 of 1

Sum with limited domain

Posted: Mon Jul 23, 2018 9:07 pm
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

Re: Sum with limited domain

Posted: Mon Jul 23, 2018 9:33 pm
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

Re: Sum with limited domain

Posted: Mon Jul 23, 2018 9:56 pm
by ErickMiranda
thank you very much, your reply was what i needed