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
Sum with limited domain
Re: Sum with limited domain
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
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

 User
 Posts: 2
 Joined: 4 weeks ago
Re: Sum with limited domain
thank you very much, your reply was what i needed