empl0_beg += empl0 empl0_fin = S.Task('empl0_fin',completion_time_cost=2) empl0_fin += empl0 #S += 2 <= empl0_beg, empl0_fin < empl0_beg + 6 # employee 1 begins at any time and finishes # at most four hours later empl1_beg = S.Task('empl1_beg',completion_time_cost=2) empl1_beg += empl1 empl1_fin = S.Task('empl1_fin',completion_time_cost=2) empl1_fin += empl1 #S += empl1_fin < empl1_beg + 6 # interchangeable tasks that need to be finished as # by the two employees as early as possible T = S.Tasks(name='T',num=6,is_group=True) T += empl0 | empl1 # bound tasks of employees by shift begin and finish S += empl0_beg < T*empl0, T*empl0 < empl0_fin S += empl1_beg < T*empl1, T*empl1 < empl1_fin if solvers.mip.solve(S,msg=0,kind='CBC'): opts, _ = getopt.getopt(sys.argv[1:], 't:', ['test']) if ('--test','') in opts: assert(empl0_fin.start_value == 4) assert(empl1_fin.start_value == 4) print('test passed') else: plotters.matplotlib.plot(S)
#! /usr/bin/env python import sys sys.path.append('../src') import getopt opts, _ = getopt.getopt(sys.argv[1:], 't:', ['test']) from pyschedule import Scenario, solvers, plotters horizon = 10 S = Scenario('Scenario', horizon=horizon) tasks = S.Tasks('T', num=int(horizon / 2), is_group=True, completion_time_cost=2, state=1) breaks = S.Tasks('B', num=int(horizon / 2), is_group=True, completion_time_cost=1, state=-1) R = S.Resource('R') tasks += R breaks += R # ensure that state is always between 0 and 1 for t in range(horizon): S += R['state'][:t] <= 1 S += R['state'][:t] >= 0 if solvers.mip.solve(S, msg=0): if ('--test', '') in opts:
# test artefact for the case that pyschedule is # read from folder from pyschedule import Scenario, solvers, plotters, alt import getopt import sys sys.path.append('../src') opts, _ = getopt.getopt(sys.argv[1:], 't:', ['test']) horizon = 18 S = Scenario('parallel_courses', horizon=horizon) # size 2 means teacher can do two things in parallel Teacher = S.Resource('T', size=2, periods=[0, 1, 2, 3, 4, 5, 7, 8, 9]) Courses_English = S.Tasks('CE', num=7, delay_cost=1, plot_color='red', english=1) Courses_Math = S.Tasks('CM', num=7, delay_cost=1, plot_color='green', math=1) Courses_English += Teacher Courses_Math += Teacher S += Teacher['english'][0:horizon:1].max + \ Teacher['math'][0:horizon:1].max <= 1 if solvers.mip.solve(S, time_limit=600, msg=0): if ('--test', '') in opts: assert(len(set(T.start_value for T in Courses_English) & set(T.start_value for T in Courses_Math)) == 0) print('test passed') else:
empl0_beg += empl0 empl0_fin = S.Task('empl0_fin', delay_cost=2) empl0_fin += empl0 #S += 2 <= empl0_beg, empl0_fin < empl0_beg + 6 # employee 1 begins at any time and finishes # at most four hours later empl1_beg = S.Task('empl1_beg', delay_cost=2) empl1_beg += empl1 empl1_fin = S.Task('empl1_fin', delay_cost=2) empl1_fin += empl1 #S += empl1_fin < empl1_beg + 6 # interchangeable tasks that need to be finished as # by the two employees as early as possible T = S.Tasks(name='T', num=6, delay_cost=1, is_group=True) T += empl0 | empl1 # bound tasks of employees by shift begin and finish S += empl0_beg < T * empl0, T * empl0 < empl0_fin S += empl1_beg < T * empl1, T * empl1 < empl1_fin if solvers.mip.solve(S, msg=0, kind='CBC'): opts, _ = getopt.getopt(sys.argv[1:], 't:', ['test']) if ('--test', '') in opts: assert (empl0_fin.start_value == 4) assert (empl1_fin.start_value == 4) print('test passed') else: plotters.matplotlib.plot(S) else:
# test artefact for the case that pyschedule is # read from folder import sys sys.path.append('../src') import getopt opts, _ = getopt.getopt(sys.argv[1:], 't:', ['test']) from pyschedule import Scenario, solvers, plotters, alt horizon = 20 S = Scenario('parallel_courses',horizon=horizon) #size 2 means teacher can do two things in parallel Teacher = S.Resource('T',size=2) Courses_English = S.Tasks('CE',num=10,completion_time_cost=1,plot_color='red',english=1) Courses_Math = S.Tasks('CM',num=10,completion_time_cost=1,plot_color='green',math=1) Courses_English += Teacher Courses_Math += Teacher S += Teacher['english'][0:horizon:1].max + Teacher['math'][0:horizon:1].max <= 1 if solvers.mip.solve(S,time_limit=600,msg=0): if ('--test','') in opts: assert(len(set( T.start_value for T in Courses_English ) & set( T.start_value for T in Courses_Math )) == 0) print('test passed') else: plotters.matplotlib.plot(S,show_task_labels=True) else: print('no solution found')
empl0_beg += empl0 empl0_fin = S.Task('empl0_fin', completion_time_cost=2) empl0_fin += empl0 S += 2 <= empl0_beg, empl0_fin < empl0_beg + 6 # employee 1 begins at any time and finishes # at most four hours later empl1_beg = S.Task('empl1_beg', completion_time_cost=2) empl1_beg += empl1 empl1_fin = S.Task('empl1_fin', completion_time_cost=2) empl1_fin += empl1 S += empl1_fin < empl1_beg + 6 # interchangeable tasks that need to be finished as # by the two employees as early as possible T = S.Tasks(group='T', n_tasks=6) T += empl0 | empl1 # bound tasks of employees by shift begin and finish S += empl0_beg << T, T << empl0_fin S += empl1_beg << T, T << empl1_fin # alternatively, define each task separately # and not as a interchangeable group ''' T = dict() for i in range(6): T[i] = S.Task('T%i'%i,completion_time_cost=1) T[i] += R1 | R2 S += T[i] << T1_e, T1_s << T[i] S += T2_s << T[i], T[i] << T2_e