## Summation with variable lower and upper bound

Problems with syntax of GAMS
mogue92
User Posts: 4
Joined: 4 months ago

### Summation with variable lower and upper bound

Dear all,

Im trying to sum over my binary decision variable X(f,g,t) which equals 1 if family f cooks meal g on day t and 0 otherwise. I want at least 10 days between am family cooking twice in a month.

For example:

f1*f17;
g1*g30;
t1*t20*

Some of the families have to cook twice. To have a break between the two cooking days I used the following restriction which is working perfectly fine:

Code: Select all

``whatIwant(f,t)\$(ord(t)>1)..         Sum(g,X(f,g,t))+Sum(g,X(f,g,t+1))+Sum(g,X(f,g,t+2))+Sum(g,X(f,g,t+3))+Sum(g,X(f,g,t+4))+Sum(g,X(f,g,t+5))+Sum(g,X(f,g,t+6))+Sum(g,X(f,g,t+7))+Sum(g,X(f,g,t+8))+Sum(g,X(f,g,t+9)) =L= 1;``
Wouldnt it be possible to formulate the equation this way also?

Code: Select all

``WhatItried(f)..                      Sum(t\$( (ord(t) = ord(t)+1) and (ord(t) <= ord(t)+10) ), Sum(g,X(f,g,t))) =L= 1;``
I tried it with every possible constellation of ord and \$ but didnt manage to make it work.

Best regards
Moritz

suprafluid
User Posts: 7
Joined: 3 months ago

### Re: Summation with variable lower and upper bound

Hi Moritz,

could you find any solution to your question that you'd like to share? It feels like you have a similar problem to solve as I do as specified in my post "bounds on sum for looping through sets".

Best regards
supra

mogue92
User Posts: 4
Joined: 4 months ago

### Re: Summation with variable lower and upper bound

Hi supra,

I did not find an a satisfying answer yet. I’ll let you know as when I find a solution to our problem.

Best regards
Moritz

Fred
Posts: 144
Joined: 2 years ago

### Re: Summation with variable lower and upper bound

Hi Moritz,

Not sure why your whatIwant constraint starts with ord(t)>1. Seems that cooking on t1 and t2 would be allowed with that formulation.

Your whatItried formulation has several flaws. In the sum you restrict to ord(t)=ord(t)+1. That condition is always false. Since this is one and the same t on the left hand side and right hand side it can obviously never be true. Also, it seem to me that there is no way to write such a constraint wthout controlling the time set in the domain of the equation.

The following should do the trick

Code: Select all

``````[...]
alias (t,tt);
whatShouldDoTheTrick(f,t)\$(ord(t)<=card(t)-9).. sum((g,tt)\$(ord(tt)>=ord(t) and ord(tt)<=ord(t)+9), X(f,g,tt)) =l= 1;
[...]
``````
If you are not familiar with the alias statement, you can read about it in the documentation: https://www.gams.com/latest/docs/UG_Set ... mesForASet

I hope this helps!

Fred

mogue92
User Posts: 4
Joined: 4 months ago

### Re: Summation with variable lower and upper bound

Hi Fred,

it does help indeed. Thank you very much for clearing that up!

Moritz