Page 1 of 1

Problem with creating a constraint for a minimum amount of consecutive days

Posted: Wed Aug 28, 2019 2:10 pm
by saraerics
Hi,

I'm trying to create a constraint over a period of 28 days for a number of agents. I have a binary variable y(i,l) i - agent l - day, indicating wether agent i works on day l or not. I want to add a constraint that ensures that the least number of days is 2. Is there anyone who could help me please?

Im trying to do it like this for now (just to give you an idea of what I'm trying to accomplish):

CONSECWORKDAYSMINFIRST(I,L) .. Y(I,"2")$(Y(I,"1") = 1) =E= 1;
CONSECWORKDAYSMIN(I,L) .. Y(I,L)$(Y(I,L-1) = 0 AND Y(I,L+1) = 0) =E= 0;

Im working with an minlp solver and I'm not allowed to use the if operator in a constraint on non-pre-set variables.

Re: Problem with creating a constraint for a minimum amount of consecutive days

Posted: Tue Sep 10, 2019 10:09 am
by Fred
Hi,

I think the following example should do the trick.

Code: Select all

binary variable
    y(i,l)     'worker i works on day l';
variable
    start(i,l) 'value of 1 indicates that worker i starts to work on day l';    
equation
    defStart(i,l)
    minconsec(i,l);

defStart(i,l)..
    start(i,l) =e= y(i,l) - y(i,l-1);
    
minconsec(i,l)$(ord(l)>1)..
    y(i,l) =g= start(i,l-1);
Not sure how you want to handle periods 1 and 28 (should they be linked? Must an agent who works on day 28 also work on 27?) but can probably adjust the the example as needed.

I hope this helps!

Fred