Sum(i$(i gt 1),X(i))

Problems with syntax of GAMS
Post Reply
mosayebi
User
User
Posts: 1
Joined: 9 months ago

Sum(i$(i gt 1),X(i))

Post by mosayebi » 9 months ago

Hi All,
Sets
i Index /1*20/
j Index /1*20/
R Index /1*20/;
I want to write the code to run for all items in the set except the first item.

For example Sum(i$(i gt 1),W(i)); and it was accepted.

But when I wrote Y(R,I$(i gt 1),J)=L= 2*X(R,I$(i gt 1),J);
It cannot accept . Y is free and x is binary.

How can we solve it?
Thanks

User avatar
bussieck
Moderator
Moderator
Posts: 208
Joined: 2 years ago

Re: Sum(i$(i gt 1),X(i))

Post by bussieck » 9 months ago

Hi,

You first example with the sum is also syntactically incorrect. But if you change 'i gt 1' to 'i.val gt 1' this will work

Code: Select all

Sets
i Index /1*20/
j Index /1*20/
R Index /1*20/;
parameter w(i), wsum;
w(i) = uniform(0,1);
wsum = Sum(i$(i.val gt 1),W(i));
Your other syntax is very different. You don't control a "running index" with some $() command but what to do that in the variable itself. This you have R, I and J controlled by the equation (your example is unfortunately not complete, you need to control I there:

Code: Select all

Sets
i Index /1*20/
j Index /1*20/
R Index /1*20/;
variable Y(R,I,J), X(R,I,J);
equation e(R,I,J); e(R,I,J)$(i.val gt 1).. Y(R,I,J)=L= 2*X(R,I,J);
-Michael

Post Reply