How do I model that constraint: The sum of consecutive four elements in a vector should be less than 10?

Frequently asked questions about GAMS

Moderator: aileen

Forum rules
Please ask questions in the other sub-forums
Locked
aileen
User
User
Posts: 136
Joined: 4 years ago

How do I model that constraint: The sum of consecutive four elements in a vector should be less than 10?

Post by aileen »

Say a vector x has ten values (decision variables). Objective: Maximize the sum of x. How do I model this constraint: The sum of consecutive four elements in the vector should be less than 10.
aileen
User
User
Posts: 136
Joined: 4 years ago

Re: How do I model that constraint: The sum of consecutive four elements in a vector should be less than 10?

Post by aileen »

You can use the lag and lead operator as in the following example:

Code: Select all

Set i /1*10/; Alias (i,j);
Set iconseq(i,j);
Scalar cnt;

loop(i, for(cnt=0 to 3, iconseq(i,i+cnt) = yes));
display iconseq;

Variable x(i);
Equation e(i);
e(i).. sum(iconseq(i,j), x(i)) =l= 10;
If you want your constraint to interpret "consecutive" in a circular manner, you will have to replace + in the loop-statement by ++ like this:

Code: Select all

loop(i, for(cnt=0 to 3, iconseq(i,i++cnt) = yes));
Locked