Cleaned up scheduling problem
@@ -12,6 +12,7 @@ the program finds a schedule that satisfies all priority constraints while minim
from cpmpy import *
from PIL import Image, ImageDraw, ImageFont
+def run():
# All data related to the scheduling
jobs = ['A', 'B', 'C', 'D']
lastT = 20
@@ -20,6 +21,15 @@ dur = [ [5, 2, 3 ], [4, 5, 1], [ 3, 4, 2 ], [1, 1, 1]]
nMachines = 3
taskToMach = [[1, 2, 3 ],[ 2, 1, 3],[ 2, 3, 1 ], [3, 2, 1]]
+ (model, vars) = model_scheduling(jobs, lastT, nTasks, dur, taskToMach)
+
+ if model.solve():
+ for v in vars:
+ print(v + ": " + str(vars[v].value()))
+ visualize_scheduling(vars, lastT, nMachines,jobs, nTasks, taskToMach)
+
+def model_scheduling(jobs, lastT, nTasks, dur, taskToMach):
+
# Decision variables
start = intvar(0, lastT, shape=(len(jobs), nTasks))
end = intvar(0, lastT, shape=(len(jobs), nTasks))
@@ -39,9 +49,12 @@ model = Model(
# Minimize wrt the makespan
model.minimize(makespan)
-if model.solve():
- print(start.value())
- print(end.value())
+ return (model, {"start": start, "end": end, "makespan": makespan})
+
+def visualize_scheduling(vars, lastT, nMachines,jobs, nTasks, taskToMach):
+ makespan = vars["makespan"]
+ start = vars["start"]
+ end = vars["end"]
# Draw solution
# Define start location image & unit sizes
@@ -102,3 +115,6 @@ if model.solve():
img1.text((center_x - text_w / 2, center_y - text_h / 2), msg, fill="white", font=myFont)
img.show()
+
+if __name__ == "__main__":
+ run()
\ No newline at end of file
