def showsequence(s, setup): seq = msol.get_var_solution(s) visu.sequence(name=s.get_name()) vs = seq.get_value() for v in vs: nm = v.get_name() visu.interval(v, tp[id[nm]], compact(nm)) for i in range(len(vs) - 1): end = vs[i].get_end() tp1 = tp[id[vs[i].get_name()]] tp2 = tp[id[vs[i + 1].get_name()]] visu.transition(end, end + setup.get_value(tp1, tp2))
mdl.add(minimize(max([end_of(OPS[o[0]]) for o in ops]))) ############################################################################## # Model solving ############################################################################## # Solve model print("Solving model....") msol = mdl.solve(FailLimit=100000) print("Solution: ") msol.print_solution() ############################################################################## # Display result ############################################################################## # Draw solution if msol and visu.is_visu_enabled(): visu.timeline("Solution for flexible job-shop " + filename) visu.panel("Machines") for j in range(nb_mchs): visu.sequence(name='M' + str(j)) for v in MACHS[j]: itv = msol.get_var_solution(v) if itv.is_present(): job = Job[v.get_name()] visu.interval(itv, job, 'J' + str(job)) visu.show()
for j in range(nbMchs)]))) ############################################################################## # Model solving ############################################################################## # Solve model print("Solving model....") msol = mdl.solve(FailLimit=10000) print("Solution: ") msol.print_solution() ############################################################################## # Display result ############################################################################## # Draw solution if msol and visu.is_visu_enabled(): visu.timeline("Solution for open-shop " + filename) visu.panel("Jobs") for i in range(nbJobs): visu.sequence(name='J' + str(i), intervals=[(msol.get_var_solution(ITVS[i][j]), j, 'M' + str(j)) for j in range(nbMchs)]) visu.panel("Machines") for j in range(nbMchs): visu.sequence(name='M' + str(j), intervals=[(msol.get_var_solution(ITVS[i][j]), j, 'J' + str(i)) for i in range(nbJobs)]) visu.show()
mdl.add(minimize(max([end_of(ITVS[i][j]) for i in range(nbJobs) for j in range(nbMchs)]))) ############################################################################## # Model solving ############################################################################## # Solve model print("Solving model....") msol = mdl.solve(FailLimit=10000) print("Solution: ") msol.print_solution() ############################################################################## # Display result ############################################################################## # Draw solution if msol and visu.is_visu_enabled(): visu.timeline("Solution for open-shop " + filename) visu.panel("Jobs") for i in range(nbJobs): visu.sequence(name='J' + str(i), intervals=[(msol.get_var_solution(ITVS[i][j]), j, 'M' + str(j)) for j in range(nbMchs)]) visu.panel("Machines") for j in range(nbMchs): visu.sequence(name='M' + str(j), intervals=[(msol.get_var_solution(ITVS[i][j]), j, 'J' + str(i)) for i in range(nbJobs)]) visu.show()
# Add minimization objective mdl.add(minimize(max([end_of(OPS[o[0]]) for o in ops]))) ############################################################################## # Model solving ############################################################################## # Solve model print("Solving model....") msol = mdl.solve(FailLimit=100000) print("Solution: ") msol.print_solution() ############################################################################## # Display result ############################################################################## # Draw solution if msol and visu.is_visu_enabled(): visu.timeline("Solution for flexible job-shop " + filename) visu.panel("Machines") for j in range(nb_mchs): visu.sequence(name='M' + str(j)) for v in MACHS[j]: itv = msol.get_var_solution(v) if itv.is_present(): job = Job[v.get_name()] visu.interval(itv, job, 'J' + str(job)) visu.show()
############################################################################## # Model solving ############################################################################## # Solve model print("Solving model....") msol = mdl.solve() print("Solution: ") msol.print_solution() ############################################################################## # Display result ############################################################################## # Draw solution if msol and visu.is_visu_enabled(): visu.timeline("Solution for job-shop " + filename) visu.panel("Jobs") for i in range(nb_jobs): visu.sequence(name='J' + str(i), intervals=[(msol.get_var_solution(ITVS[i][j]), mch[i][j], 'M' + str(mch[i][j])) for j in range(nb_mchs)]) visu.panel("Machines") for k in range(nb_mchs): visu.sequence(name='M' + str(k), intervals=[(msol.get_var_solution(MACH[k][i]), k, 'J' + str(i)) for i in range(nb_jobs)]) visu.show()
print("Solving model....") msol = mdl.solve() print("Solution: ") msol.print_solution() ############################################################################## # Display result ############################################################################## def compact(name): # Example: H3-garden -> G3 # ^ ^ loc, task = name[1:].split('-', 1) return task[0].upper() + loc if msol and visu.is_visu_enabled(): visu.timeline('Solution SchedCalendar') visu.panel() visu.pause(joe_calendar) visu.sequence(name='Joe', intervals=[(msol.get_var_solution(t), type[t], compact(t.name)) for t in joe_tasks]) visu.panel() visu.pause(jim_calendar) visu.sequence(name='Jim', intervals=[(msol.get_var_solution(t), type[t], compact(t.name)) for t in jim_tasks]) visu.show()
# mdl.export_as_cpo() # Solve model print("Solving model....") msol = mdl.solve() print("Solution: ") msol.print_solution() ############################################################################## # Display result ############################################################################## def compact(name): # Example: H3-garden -> G3 # ^ ^ loc, task = name[1:].split('-', 1) return task[0].upper() + loc if msol and visu.is_visu_enabled(): visu.timeline('Solution SchedCalendar') visu.panel() visu.pause(joe_calendar) visu.sequence(name='Joe', intervals=[(msol.get_var_solution(t), type[t], compact(t.name)) for t in joe_tasks]) visu.panel() visu.pause(jim_calendar) visu.sequence(name='Jim', intervals=[(msol.get_var_solution(t), type[t], compact(t.name)) for t in jim_tasks]) visu.show()
print("Solution: ") msol.print_solution() ############################################################################## # Display result ############################################################################## def compact(name): # Example: H3-garden -> G3 # ^ ^ loc, task = name[1:].split('-', 1) return task[0].upper() + loc if msol and visu.is_visu_enabled(): workers_function = CpoStepFunction() for v in all_tasks: itv = msol.get_var_solution(v) workers_function.add_value(itv.get_start(), itv.get_end(), 1) visu.timeline('Solution SchedState') visu.panel(name="Schedule") for v in all_tasks: visu.interval(msol.get_var_solution(v), house[v], compact(v.get_name())) visu.panel(name="Houses state") for f in all_state_functions: visu.sequence(name=f.get_name(), segments=msol.get_var_solution(f)) visu.panel(name="Nb of workers") visu.function(segments=workers_function, style='line') visu.show()
print("Solution: ") msol.print_solution() ############################################################################## # Display result ############################################################################## def compact(name): # Example: H3-garden -> G3 # ^ ^ loc, task = name[1:].split('-', 1) return task[0].upper() + loc # Draw solution if msol and visu.is_visu_enabled(): visu.timeline('Solution SchedOptional', 0, deadline) for w in range(nbWorkers): visu.sequence(name=workerNames[w]) for t in worker_tasks[w]: wt = msol.get_var_solution(t) if wt.is_present(): if desc[t].skills[w] == max(desc[t].skills): # Green-like color when task is using the most skilled worker color = 'lightgreen' else: # Red-like color when task does not use the most skilled worker color = 'salmon' visu.interval(wt, color, compact(wt.get_name())) visu.show()
############################################################################## # Model solving ############################################################################## # Solve model print("Solving model....") msol = mdl.solve() print("Solution: ") msol.print_solution() ############################################################################## # Display result ############################################################################## # Draw solution if msol and visu.is_visu_enabled(): visu.timeline("Solution for job-shop " + filename) visu.panel("Jobs") for i in range(nb_jobs): visu.sequence(name='J' + str(i), intervals=[(msol.get_var_solution(ITVS[i][j]), mch[i][j], 'M' + str(mch[i][j])) for j in range(nb_mchs)]) visu.panel("Machines") for k in range(nb_mchs): visu.sequence(name='M' + str(k), intervals=[(msol.get_var_solution(MACH[k][i]), k, 'J' + str(i)) for i in range(nb_jobs)]) visu.show()
############################################################################## # Display result ############################################################################## def compact(name): # Example: H3-garden -> G3 # ^ ^ loc, task = name[1:].split('-', 1) return task[0].upper() + loc if msol and visu.is_visu_enabled(): workers_function = CpoStepFunction() for v in all_tasks: itv = msol.get_var_solution(v) workers_function.add_value(itv.get_start(), itv.get_end(), 1) visu.timeline('Solution SchedState') visu.panel(name="Schedule") for v in all_tasks: visu.interval(msol.get_var_solution(v), house[v], compact(v.get_name())) visu.panel(name="Houses state") for f in all_state_functions: visu.sequence(name=f.get_name(), segments=msol.get_var_solution(f)) visu.panel(name="Nb of workers") visu.function(segments=workers_function, style='line') visu.show()
msol.print_solution() ############################################################################## # Display result ############################################################################## def compact(name): # Example: H3-garden -> G3 # ^ ^ loc, task = name[1:].split('-', 1) return task[0].upper() + loc # Draw solution if msol and visu.is_visu_enabled(): visu.timeline('Solution SchedOptional', 0, deadline) for w in range(nbWorkers): visu.sequence(name=workerNames[w]) for t in worker_tasks[w]: wt = msol.get_var_solution(t) if wt.is_present(): if desc[t].skills[w] == max(desc[t].skills): # Green-like color when task is using the most skilled worker color = 'lightgreen' else: # Red-like color when task does not use the most skilled worker color = 'salmon' visu.interval(wt, color, compact(wt.get_name())) visu.show()