User Tools

Site Tools


gams:the_sum_of_consecutive_four_elements_in_a_vector_should_be_less_than_10

This is an old revision of the document!


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

Q: Say a vector A has ten values (decision variables) Objective: Maximize the sum of A. How do I model this constraint: The sum of consecutive four elements in the vector should be less than 10.

You can use the lag and lead operator (chapter 13.4 in the GAMS User's Guide) as in the following example:

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;

Depending if you want your constraint to interpret “consecutive” in a circular manner, you need to replace + in the loop()-statement by ++.

IMPRESSUM / LEGAL NOTICEPRIVACY POLICY gams/the_sum_of_consecutive_four_elements_in_a_vector_should_be_less_than_10.1222864852.txt.gz · Last modified: 2008/10/01 14:40 by support