What would happen if nothing is constrained?
The results from the previous chapter show that the same shift is not always achieved when HeadNurse is used as Preceptor and Trainee as Preceptee.
_____________________________________
| | | |
| Weight | Errors | Cost |
|___________|___________|_____________|
| | | |
| 60 | 0 | 0 |
| 45 | 0 | 0 |
| 30 | 1 | 30 |
| 20 | 0 | 0 |
| 15 | 2 | 30 |
| 10 | 3 | 30 |
|___________|___________|_____________|
| | |
| Total | 90 |
|_______________________|_____________|
*********UB=90(0) 80.804(cpu sec)
o 90(0)
Finished solving process. 82 (sec)
Getting Successful Result.
Start Post Processing..Calling solver
post main
*******Partner Ship Error******** 1stWeek HN_0 TR_29
*******Partner Ship Error******** 1stWeek HN_1 TR_30
*******Partner Ship Error******** 1stWeek HN_2 TR_31
Patner Day Detected 2018-06-05 HN_3 TR_32
Patner Day Detected 2018-06-06 HN_3 TR_32
Patner Day Detected 2018-06-04 HN_4 TR_33
Patner Day Detected 2018-06-05 HN_4 TR_33
Patner Day Detected 2018-06-06 HN_4 TR_33
Patner Day Detected 2018-06-07 HN_4 TR_33
*******Partner Ship Error******** 1stWeek HN_5 TR_34
post main
*******Partner Ship Error******** 2ndWeek HN_0 TR_29
Patner Day Detected 2018-06-16 HN_1 TR_30
*******Partner Ship Error******** 2ndWeek HN_2 TR_31
Patner Day Detected 2018-06-13 HN_3 TR_32
Patner Day Detected 2018-06-14 HN_3 TR_32
*******Partner Ship Error******** 2ndWeek HN_4 TR_33
*******Partner Ship Error******** 2ndWeek HN_5 TR_34
post main
*******Partner Ship Error******** 3rdWeek HN_0 TR_29
*******Partner Ship Error******** 3rdWeek HN_1 TR_30
Patner Day Detected 2018-06-23 HN_2 TR_31
Patner Day Detected 2018-06-24 HN_2 TR_31
*******Partner Ship Error******** 3rdWeek HN_3 TR_32
Patner Day Detected 2018-06-19 HN_4 TR_33
Patner Day Detected 2018-06-21 HN_5 TR_34
post main
*******Partner Ship Error******** 4thWeek HN_0 TR_29
Patner Day Detected 2018-06-28 HN_1 TR_30
Patner Day Detected 2018-06-29 HN_1 TR_30
*******Partner Ship Error******** 4thWeek HN_2 TR_31
Patner Day Detected 2018-06-29 HN_3 TR_32
Patner Day Detected 2018-06-30 HN_3 TR_32
Patner Day Detected 2018-07-01 HN_3 TR_32
Patner Day Detected 2018-06-27 HN_4 TR_33
Patner Day Detected 2018-06-29 HN_4 TR_33
*******Partner Ship Error******** 4thWeek HN_5 TR_34
Finished Post Processing. 1 (sec)
The following Python code outputs the above.
def confirm_patner_ship(week,week_name):
print('post main')
for p in Partnership_Property:
if len(p) !=2:
continue
vlist=[]
b=False
for day in week:
v0=shift_solution[p[0]][day]
v1=shift_solution[p[1]][day]
if ( (v0=='Day' and v1=='Day') or (v0=='Early' and v1=='Early') or (v0=='Late' and v1=='Late') or (v0=='Night' and v1=='Night')):
print('Patner Day Detected ',daydef[day],staffdef[p[0]],staffdef[p[1]])
b=True
if b==False:
print('*******Partner Ship Error********',week_name,staffdef[p[0]],staffdef[p[1]])
def post_main():
confirm_partner_ship()
Define PartnerShip
Entire Python Code
def partner_ship_constraint_sub(week,week_name):
for p in Partnership_Property:
if len(p) !=2:
continue
vlist=[]
for day in week:
v0A=sc3.GetShiftVar(p[0],day,'Day')
v0B=sc3.GetShiftVar(p[0],day,'Early')
v0C=sc3.GetShiftVar(p[0],day,'Late')
v0D=sc3.GetShiftVar(p[0],day,'Night')
v1A=sc3.GetShiftVar(p[1],day,'Day')
v1B=sc3.GetShiftVar(p[1],day,'Early')
v1C=sc3.GetShiftVar(p[1],day,'Late')
v1D=sc3.GetShiftVar(p[1],day,'Night')
#Collect the day when a Head Nurse and Trainee works together.
vlist.append( (v0A&v1A) | (v0B&v1B) | (v0C&v1C) | (v0D&v1D))
s='Partner '+staffdef[p[0]]+' '+staffdef[p[1]] +' '+week_name
print(s)
sc3.AddSoft(sc3.Or(vlist),s,4)#Take OR
def partner_ship_constraint():
partner_ship_constraint_sub(a_1stWeek,'1stWeek')
partner_ship_constraint_sub(b_2ndWeek,'2ndWeek')
partner_ship_constraint_sub(c_3rdWeek,'3rdWeek')
partner_ship_constraint_sub(d_4thWeek,'4thWeek')
def confirm_partner_ship():
confirm_patner_ship(a_1stWeek,'1stWeek')
confirm_patner_ship(b_2ndWeek,'2ndWeek')
confirm_patner_ship(c_3rdWeek,'3rdWeek')
confirm_patner_ship(d_4thWeek,'4thWeek')
def confirm_patner_ship(week,week_name):
print('post main')
for p in Partnership_Property:
if len(p) !=2:
continue
vlist=[]
b=False
for day in week:
v0=shift_solution[p[0]][day]
v1=shift_solution[p[1]][day]
if ( (v0=='Day' and v1=='Day') or (v0=='Early' and v1=='Early') or (v0=='Late' and v1=='Late') or (v0=='Night' and v1=='Night')):
print('Patner Day Detected ',daydef[day],staffdef[p[0]],staffdef[p[1]])
b=True
if b==False:
print('*******Partner Ship Error********',week_name,staffdef[p[0]],staffdef[p[1]])
def post_main():
confirm_partner_ship()
partner_ship_constraint()
Results are as follows. No partner-ship error is observed.
Preparing to compile.
Calling solver
Compiling constraints..
Generating python property file finished.
Partner HN_0 TR_29 1stWeek
Partner HN_1 TR_30 1stWeek
Partner HN_2 TR_31 1stWeek
Partner HN_3 TR_32 1stWeek
Partner HN_4 TR_33 1stWeek
Partner HN_5 TR_34 1stWeek
Partner HN_0 TR_29 2ndWeek
Partner HN_1 TR_30 2ndWeek
Partner HN_2 TR_31 2ndWeek
Partner HN_3 TR_32 2ndWeek
Partner HN_4 TR_33 2ndWeek
Partner HN_5 TR_34 2ndWeek
Partner HN_0 TR_29 3rdWeek
Partner HN_1 TR_30 3rdWeek
Partner HN_2 TR_31 3rdWeek
Partner HN_3 TR_32 3rdWeek
Partner HN_4 TR_33 3rdWeek
Partner HN_5 TR_34 3rdWeek
Partner HN_0 TR_29 4thWeek
Partner HN_1 TR_30 4thWeek
Partner HN_2 TR_31 4thWeek
Partner HN_3 TR_32 4thWeek
Partner HN_4 TR_33 4thWeek
Partner HN_5 TR_34 4thWeek
Algorithm 1 Solving Process Started..
o 13765 3.545000(sec)
o 13535 3.560000(sec)
o 12995 3.597000(sec)
o 12870 3.613000(sec)
o 12740 3.626000(sec)
o 12655 3.653000(sec)
o 12595 3.666000(sec)
o 12580 3.682000(sec)
o 12550 3.702000(sec)
o 12470 3.735000(sec)
o 12395 3.749000(sec)
o 12370 3.763000(sec)
o 12135 3.777000(sec)
o 12040 3.803000(sec)
o 11980 3.817000(sec)
o 11975 3.830000(sec)
o 11885 3.854000(sec)
o 11645 3.869000(sec)
o 11520 3.883000(sec)
o 11410 3.899000(sec)
o 11330 3.915000(sec)
o 11150 6.846000(sec)
o 11125 6.876000(sec)
o 11040 6.892000(sec)
o 10990 6.909000(sec)
o 10790 6.936000(sec)
o 10735 6.954000(sec)
o 10650 6.970000(sec)
o 10450 6.989000(sec)
o 10400 7.013000(sec)
o 10325 7.027000(sec)
o 10250 7.042000(sec)
o 10180 7.058000(sec)
o 10170 7.075000(sec)
o 10080 7.089000(sec)
o 9965 7.102000(sec)
o 9920 7.129000(sec)
o 9830 10.159000(sec)
o 9805 10.225000(sec)
o 9775 10.241000(sec)
o 9680 10.265000(sec)
o 9505 10.282000(sec)
o 9290 10.314000(sec)
o 9170 10.338000(sec)
o 8950 10.385000(sec)
o 8830 10.407000(sec)
o 8715 10.427000(sec)
o 8595 10.442000(sec)
o 8565 10.457000(sec)
o 8495 10.483000(sec)
o 8475 10.523000(sec)
o 8395 10.551000(sec)
o 8225 10.637000(sec)
o 8220 10.715000(sec)
o 8040 10.740000(sec)
o 8025 10.763000(sec)
o 7980 10.778000(sec)
o 7890 10.795000(sec)
o 7835 10.815000(sec)
o 7760 10.864000(sec)
o 7545 10.898000(sec)
o 7370 10.938000(sec)
o 7315 10.982000(sec)
o 7245 11.011000(sec)
o 7235 11.033000(sec)
o 7195 11.061000(sec)
o 7055 11.078000(sec)
o 7020 11.125000(sec)
o 6960 11.147000(sec)
o 6950 11.162000(sec)
o 6915 11.190000(sec)
o 6880 11.207000(sec)
o 6825 11.240000(sec)
o 6720 11.255000(sec)
o 6660 11.273000(sec)
o 6550 11.299000(sec)
o 6520 11.314000(sec)
o 6480 11.329000(sec)
o 6395 11.344000(sec)
o 6365 11.364000(sec)
o 6335 11.381000(sec)
o 6310 11.405000(sec)
o 6155 11.434000(sec)
o 6125 11.454000(sec)
o 6025 11.485000(sec)
o 6000 11.506000(sec)
o 5990 11.527000(sec)
o 5760 11.577000(sec)
o 5695 11.596000(sec)
o 5650 11.612000(sec)
o 5590 11.627000(sec)
o 5540 11.689000(sec)
o 5360 11.704000(sec)
o 5110 11.736000(sec)
o 5065 11.764000(sec)
o 5030 11.809000(sec)
o 4915 12.162000(sec)
o 4840 12.181000(sec)
o 4815 12.215000(sec)
o 4770 12.234000(sec)
o 4795 16.558000(sec)
o 4740 16.664000(sec)
o 4730 16.714000(sec)
o 4700 16.787000(sec)
o 4650 16.833000(sec)
o 4505 16.879000(sec)
o 4470 16.897000(sec)
o 4420 16.931000(sec)
o 4385 16.960000(sec)
o 4325 16.978000(sec)
o 4235 17.152000(sec)
o 4215 17.189000(sec)
o 4210 17.207000(sec)
o 4170 17.225000(sec)
o 4130 17.286000(sec)
o 4095 17.306000(sec)
o 3975 17.410000(sec)
o 3915 17.535000(sec)
o 3890 17.553000(sec)
o 3870 17.572000(sec)
o 3845 17.604000(sec)
o 3700 17.630000(sec)
o 3665 17.662000(sec)
o 3450 17.789000(sec)
o 3430 17.945000(sec)
o 3225 18.034000(sec)
o 3220 18.071000(sec)
o 3170 18.092000(sec)
o 3020 18.155000(sec)
o 2930 18.210000(sec)
o 2865 18.230000(sec)
o 2850 18.322000(sec)
o 2845 21.545000(sec)
o 2830 21.662000(sec)
o 2800 21.706000(sec)
o 2580 21.727000(sec)
o 2565 21.770000(sec)
o 2475 21.872000(sec)
o 2135 21.980000(sec)
o 2120 21.996000(sec)
o 2030 22.025000(sec)
o 1865 22.041000(sec)
o 1720 22.072000(sec)
o 1700 22.175000(sec)
o 1635 22.223000(sec)
o 1620 22.257000(sec)
o 1515 22.392000(sec)
o 1485 22.430000(sec)
o 1455 22.590000(sec)
o 1440 22.612000(sec)
o 1425 22.779000(sec)
o 1410 22.796000(sec)
o 1395 22.835000(sec)
o 1365 23.147000(sec)
o 1275 23.294000(sec)
o 1175 23.313000(sec)
o 1130 23.456000(sec)
o 1085 23.590000(sec)
o 1055 24.169000(sec)
o 1040 24.200000(sec)
o 1010 24.231000(sec)
o 980 24.248000(sec)
o 945 24.274000(sec)
o 920 24.777000(sec)
o 915 24.803000(sec)
o 900 24.885000(sec)
o 870 24.941000(sec)
o 855 24.997000(sec)
o 840 25.193000(sec)
o 785 25.303000(sec)
o 770 25.329000(sec)
o 755 25.382000(sec)
o 740 25.397000(sec)
o 725 25.452000(sec)
o 710 25.467000(sec)
o 695 25.527000(sec)
o 680 25.552000(sec)
o 675 25.600000(sec)
o 660 25.615000(sec)
o 635 25.840000(sec)
o 630 25.983000(sec)
o 615 26.018000(sec)
o 595 26.688000(sec)
o 540 27.354000(sec)
o 525 27.916000(sec)
o 510 28.613000(sec)
o 495 28.711000(sec)
o 480 29.926000(sec)
o 465 29.990000(sec)
o 455 32.446000(sec)
o 440 32.623000(sec)
o 425 32.774000(sec)
o 410 32.868000(sec)
o 400 33.851000(sec)
o 365 34.904000(sec)
o 350 35.418000(sec)
o 330 50.710000(sec)
o 320 50.747000(sec)
o 310 50.806000(sec)
o 300 50.824000(sec)
o 290 50.980000(sec)
o 280 51.019000(sec)
o 270 51.816000(sec)
o 260 52.104000(sec)
o 250 52.640000(sec)
o 240 52.849000(sec)
o 230 53.113000(sec)
o 220 53.131000(sec)
o 210 53.772000(sec)
o 200 53.965000(sec)
o 190 54.196000(sec)
o 180 55.059000(sec)
o 175 55.192000(sec)
o 165 55.359000(sec)
o 155 56.045000(sec)
o 145 62.457000(sec)
_____________________________________
| | | |
| Weight | Errors | Cost |
|___________|___________|_____________|
| | | |
| 60 | 0 | 0 |
| 45 | 0 | 0 |
| 30 | 2 | 60 |
| 20 | 0 | 0 |
| 15 | 3 | 45 |
| 10 | 4 | 40 |
|___________|___________|_____________|
| | |
| Total | 145 |
|_______________________|_____________|
*********UB=145(0) 83.304(cpu sec)
o 145(0)
Generating python property file finished.
Finished solving process. 85 (sec)
Getting Successful Result.
Start Post Processing..Calling solver
post main
Patner Day Detected 2018-06-08 HN_0 TR_29
Patner Day Detected 2018-06-04 HN_1 TR_30
Patner Day Detected 2018-06-06 HN_1 TR_30
Patner Day Detected 2018-06-07 HN_1 TR_30
Patner Day Detected 2018-06-04 HN_2 TR_31
Patner Day Detected 2018-06-08 HN_2 TR_31
Patner Day Detected 2018-06-09 HN_2 TR_31
Patner Day Detected 2018-06-10 HN_2 TR_31
Patner Day Detected 2018-06-04 HN_3 TR_32
Patner Day Detected 2018-06-06 HN_3 TR_32
Patner Day Detected 2018-06-06 HN_4 TR_33
Patner Day Detected 2018-06-05 HN_5 TR_34
Patner Day Detected 2018-06-06 HN_5 TR_34
post main
Patner Day Detected 2018-06-12 HN_0 TR_29
Patner Day Detected 2018-06-12 HN_1 TR_30
Patner Day Detected 2018-06-13 HN_1 TR_30
Patner Day Detected 2018-06-14 HN_2 TR_31
Patner Day Detected 2018-06-11 HN_3 TR_32
Patner Day Detected 2018-06-12 HN_3 TR_32
Patner Day Detected 2018-06-13 HN_4 TR_33
Patner Day Detected 2018-06-14 HN_5 TR_34
post main
Patner Day Detected 2018-06-21 HN_0 TR_29
Patner Day Detected 2018-06-22 HN_0 TR_29
Patner Day Detected 2018-06-18 HN_1 TR_30
Patner Day Detected 2018-06-19 HN_1 TR_30
Patner Day Detected 2018-06-23 HN_1 TR_30
Patner Day Detected 2018-06-21 HN_2 TR_31
Patner Day Detected 2018-06-22 HN_2 TR_31
Patner Day Detected 2018-06-21 HN_3 TR_32
Patner Day Detected 2018-06-22 HN_3 TR_32
Patner Day Detected 2018-06-18 HN_4 TR_33
Patner Day Detected 2018-06-19 HN_4 TR_33
Patner Day Detected 2018-06-21 HN_5 TR_34
post main
Patner Day Detected 2018-06-28 HN_0 TR_29
Patner Day Detected 2018-06-30 HN_1 TR_30
Patner Day Detected 2018-07-01 HN_1 TR_30
Patner Day Detected 2018-06-25 HN_2 TR_31
Patner Day Detected 2018-06-26 HN_2 TR_31
Patner Day Detected 2018-06-30 HN_3 TR_32
Patner Day Detected 2018-06-27 HN_4 TR_33
Patner Day Detected 2018-06-27 HN_5 TR_34
Patner Day Detected 2018-06-30 HN_5 TR_34
Finished Post Processing. 1 (sec)
Load the Project File
File → Open Project File from GitHub