Modify the solver script to take in the number of shifts and the hour shifts as argument. #534
This commit is contained in:
parent
bba9060548
commit
5a69899c28
1 changed files with 27 additions and 44 deletions
|
|
@ -47,48 +47,31 @@ def main():
|
|||
for hour_index in range(0, len(hours)):
|
||||
req_hours[day_index][hour_index] = int(hours_data[hour_index])
|
||||
|
||||
# index of shift selected is 8
|
||||
shift = sys.argv[8]
|
||||
argv_index = day_index + 2
|
||||
# number of days is fixed at 7 so the number of shifts will be in index 8
|
||||
num_shifts = sys.argv[argv_index]
|
||||
|
||||
hour_shifts = []
|
||||
if shift == "24_7":
|
||||
hour_shifts = [
|
||||
['00 - 09', 0, 1, 2, 3, 4, 5, 6, 7, 8],
|
||||
['01 - 10', 1, 2, 3, 4, 5, 6, 7, 8, 9],
|
||||
['02 - 11', 2, 3, 4, 5, 6, 7, 8, 9, 10],
|
||||
['03 - 12', 3, 4, 5, 6, 7, 8, 9, 10, 11],
|
||||
['04 - 13', 4, 5, 6, 7, 8, 9, 10, 11, 12],
|
||||
['05 - 14', 5, 6, 7, 8, 9, 10, 11, 12, 13],
|
||||
['06 - 15', 6, 7, 8, 9, 10, 11, 12, 13, 14],
|
||||
['07 - 16', 7, 8, 9, 10, 11, 12, 13, 14, 15],
|
||||
['08 - 17', 8, 9, 10, 11, 12, 13, 14, 15, 16],
|
||||
['09 - 18', 9, 10, 11, 12, 13, 14, 15, 16, 17],
|
||||
['10 - 19', 10, 11, 12, 13, 14, 15, 16, 17, 18],
|
||||
['11 - 20', 11, 12, 13, 14, 15, 16, 17, 18, 19],
|
||||
['12 - 21', 12, 13, 14, 15, 16, 17, 18, 19, 20],
|
||||
['13 - 22', 13, 14, 15, 16, 17, 18, 19, 20, 21],
|
||||
['14 - 23', 14, 15, 16, 17, 18, 19, 20, 21, 22],
|
||||
['15 - 00', 15, 16, 17, 18, 19, 20, 21, 22, 23],
|
||||
['16 - 01', 16, 17, 18, 19, 20, 21, 22, 23, 0],
|
||||
['17 - 02', 17, 18, 19, 20, 21, 22, 23, 0, 1],
|
||||
['18 - 03', 18, 19, 20, 21, 22, 23, 0, 1, 2],
|
||||
['19 - 04', 19, 20, 21, 22, 23, 0, 1, 2, 3],
|
||||
['20 - 05', 20, 21, 22, 23, 0, 1, 2, 3, 4],
|
||||
['21 - 06', 21, 22, 23, 0, 1, 2, 3, 4, 5],
|
||||
['22 - 07', 22, 23, 0, 1, 2, 3, 4, 5, 6],
|
||||
['23 - 08', 23, 0, 1, 2, 3, 4, 5, 6, 7]]
|
||||
if shift == "8AM_5PM":
|
||||
hour_shifts = [
|
||||
['07 - 16', 7, 8, 9, 10, 11, 12, 13, 14, 15],
|
||||
['08 - 17', 8, 9, 10, 11, 12, 13, 14, 15, 16]]
|
||||
if shift == "7AM_10PM":
|
||||
hour_shifts = [
|
||||
['07 - 16', 7, 8, 9, 10, 11, 12, 13, 14, 15],
|
||||
['08 - 17', 8, 9, 10, 11, 12, 13, 14, 15, 16],
|
||||
['09 - 18', 9, 10, 11, 12, 13, 14, 15, 16, 17],
|
||||
['10 - 19', 10, 11, 12, 13, 14, 15, 16, 17, 18],
|
||||
['11 - 20', 11, 12, 13, 14, 15, 16, 17, 18, 19],
|
||||
['12 - 21', 12, 13, 14, 15, 16, 17, 18, 19, 20],
|
||||
['13 - 22', 13, 14, 15, 16, 17, 18, 19, 20, 21]]
|
||||
for shift_ctr in range(0, int(num_shifts)):
|
||||
# form list within the list
|
||||
hour_shift_item = []
|
||||
|
||||
# get the shifts from the arguments
|
||||
shift = sys.argv[argv_index+1]
|
||||
split_shift = shift.split(',')
|
||||
|
||||
# surround the first item in list with single quotes
|
||||
shift_index = "\'" + split_shift[0] + "\'"
|
||||
|
||||
# append the first item to the rest of the hour shift informaton
|
||||
hour_shift = shift_index + ", " + split_shift[1] + ", " + split_shift[2] + ", " + split_shift[3] + ", " + split_shift[4] + ", " + split_shift[5] + ", " + split_shift[6] + ", " + split_shift[7] + ", " + split_shift[8] + ", " + split_shift[9]
|
||||
|
||||
# append to list
|
||||
hour_shift_item.append(hour_shift)
|
||||
|
||||
# append the list to the list
|
||||
hour_shifts.append(hour_shift_item)
|
||||
argv_index+=1
|
||||
|
||||
# all possible days riders come in
|
||||
day_shifts = [
|
||||
|
|
@ -148,11 +131,11 @@ def main():
|
|||
|
||||
# solve it!
|
||||
status = solver.Solve()
|
||||
#print('Number of variables =', solver.NumVariables())
|
||||
#print('Number of constraints =', solver.NumConstraints())
|
||||
print('Number of variables =', solver.NumVariables())
|
||||
print('Number of constraints =', solver.NumConstraints())
|
||||
|
||||
if status == solver.OPTIMAL:
|
||||
#print('Optimal solution found!')
|
||||
print('Optimal solution found!')
|
||||
for day_index in range(0, len(day_shifts)):
|
||||
for hour_index in range(0, len(hour_shifts)):
|
||||
result = solv_shifts[day_index][hour_index].solution_value()
|
||||
|
|
|
|||
Loading…
Reference in a new issue