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:

f1f17;
g1
g30;
t1t20

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:

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?

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.

Would someone please help me!

Best regards
Moritz

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

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

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

[...]
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_SetDefinition.html#UG_SetDefinition_TheAliasStatementMultipleNamesForASet

I hope this helps!

Fred

Hi Fred,

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

Moritz