Employee Scheduling example using the CP-SAT solver in Java gives INFEASIBLE status

499 views
Skip to first unread message

Chatree Srichart

unread,
Apr 11, 2019, 9:14:37 AM4/11/19
to or-tools-discuss
Hello Everyone,

I wrote a class (attached file) to solve the Employee Scheduling in Java as in this Python example:


However, the solver gives INFEASIBLE status.

What I need to do to make it OPTIMAL are:
  1. change the upper bound of 
    model.addLinearSum(d_shifts, 0, 1);
    from 1 to 2
  2. delete this line
    model.addLinearSum(n_shifts_worked, min_shifts_per_nurse, max_shifts_per_nurse);

However, the solved values are not the same as in the Python example.

Note: I uses the or-tools library which was compiled from the master yesterday.

Any help would be appreciated.

Thanks.

EmployeeSchedulingSat.java

Chatree Srichart

unread,
Apr 12, 2019, 1:05:18 AM4/12/19
to or-tools-discuss
For more information

What I did in the Java class (attached file in the original post) to replace the original Python example:

are:

From Python
model.Add(min_shifts_per_nurse <= num_shifts_worked)
model
.Add(num_shifts_worked <= max_shifts_per_nurse)


To Java
int min_shifts_per_nurse = num_shifts * num_days; // num_nurses
int max_shifts_per_nurse = min_shifts_per_nurse + 1;IntVar[] n_shifts_worked = new IntVar[num_shifts * num_days];
           
for (int s : all_shifts) {
               
for (int d : all_days) {
                   
int index = s * num_days + d;
                    n_shifts_worked
[index] = shifts[n][d][s];
               
}
           
}
model
.addLinearSum(n_shifts_worked, min_shifts_per_nurse, max_shifts_per_nurse);

and

From Python
model.Maximize(
        sum
(shift_requests[n][d][s] * shifts[(n, d, s)] for n in all_nurses
           
for d in all_days for s in all_shifts))


To Java
IntVar[] intVars = new IntVar[num_shifts * num_days * num_nurses];
       
int[] ints = new int[num_shifts * num_days * num_nurses];
       
for (int s : all_shifts) {
           
for (int d : all_days) {
               
for (int n : all_nurses) {
                   
int index = (s * num_days + d) * num_nurses + n;
                    intVars
[index] = shifts[n][d][s];
                    ints
[index] = shift_requests[n][d][s];
               
}
           
}
       
}
        model
.maximizeScalProd(intVars, ints);

Are they correct?

Note: I still don't know why my EmployeeSchedulingSat.java class (attached file) does not produce the same solution as in the original Python example https://developers.google.com/optimization/scheduling/employee_scheduling .


เมื่อ วันพฤหัสบดีที่ 11 เมษายน ค.ศ. 2019 20 นาฬิกา 14 นาที 37 วินาที UTC+7, Chatree Srichart เขียนว่า:
Reply all
Reply to author
Forward
0 new messages