2
$\begingroup$

Am writing a small scheduling program in C# for a group of 7 staff who will be working in three shifts daily for 4 weeks. Am using the google OR-Tools Template, but i have modified it abit

This is the scope

  • We have 3 shifts(M,A,N) plus an O(off day)

  • Each shift has ONLY one staff

  • Each person must work a max of four consecutive same shifts per week(i.e NNNN) or per 7days

  • Each person must have a min of 3 off days per week or per 7 days

  • After off days the person can change the shifs (i.e from NNNN to now AAAA)

I have both shiftConstraints and weeklySumConstraints, should i use both or just one?

Here is my shiftConstraints

var shiftConstraints =
            new (int Shift, int HardMin, int SoftMin, int MinPenalty, int SoftMax, int HardMax, int MaxPenalty)[] {
                // One to three consecutive days of rest, this is a hard constraint.
                (0, 1, 1, 0, 3, 3, 0),
                //Make same employee to work same shifts 4 times consecutively. E.g night shift for 4 days then 3 days off
            };

Here is my weekSumConstraint

var weeklySumConstraints =
            new (int Shift, int HardMin, int SoftMin, int MinPenalty, int SoftMax, int HardMax, int MaxPenalty)[] {
                // Constraints on rests per week.               
               (0, 1, 2, 7, 2, 3, 4),
            };

The trick is just in one of there two variables or both, to implement the above requirements, or mybe somewhere else? let me know where am going wrong.

Am currently getting this output below but it is obviously erroneous

            M T W T F S S M T W T F S S M T W T F S S M T W T F S S
Employee 0: O O O N M M N A N O A N N O N O A O M N N N M M O M N O
Employee 1: O A O N N A N N M N M O O N A N M O N O N M N N O N O A
Employee 2: O N M N N O N O N A O A N A N O N A O A N N O N A N M O
Employee 3: N M A O A O M M O N O N N M M M N O N N O N O N N O N N
Employee 4: M O O M N N N N O N N M A O O N N O N N A A N O O N N M
Employee 5: O N N A N O N N N O N O M N N N O M O M N N A N M N O O
Employee 6: A O A N O N A N A M O N O N A A O N A O M N O A A A A O

Like you see on the first Thursday 4 employees are assigned the night shift which is wrong, it should be one employee per shift the rest should be Off... Something might be wrong with the way i set the constraints or the models, you can go through my code and see. Your help will be highly appreciated

$\endgroup$

1 Answer 1

1
$\begingroup$

Not sure why this question was abandoned but I'll give it a try:
Two vars: binary $x_{e,s,d}=1$ if employee $e$ alloted to shift $s$ on day $d$ & another binary $o_{e,d} = 1$ if off for day $d$ per week, else 0
Constraints:
$ \sum_e x_{e,s,d} = 1 \ \ \forall s, d$

$ \sum_s x_{e,s,d} + o_{e,d} \le 1 \ \ \forall e, d$

$ 3 \le \sum_{k=d}^{d+6\mod 7} o_{e,k} \le 7 \ \forall d \ \forall e$

$ \sum_{k=d}^{d+6\mod 7} x_{e,s,k}\le 4 \ \ \forall d\ \forall s \ \forall e$

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.