33 lines
1.3 KiB
Python
33 lines
1.3 KiB
Python
from matplotlib import pyplot as plt
|
|
from matplotlib import colors
|
|
from matplotlib import patches
|
|
import numpy as np
|
|
from SchedulingAlgorithms.simanneal import rate
|
|
import random
|
|
|
|
def create_plot(problem, solution):
|
|
|
|
end = rate(solution)
|
|
|
|
with plt.xkcd():
|
|
fig,ax = plt.subplots()
|
|
col = colors.XKCD_COLORS
|
|
del col['xkcd:white']
|
|
colorlist = list(col.values())
|
|
random.shuffle(colorlist)
|
|
for m in range(0, problem.machines):
|
|
mach_ops = [ x for x in solution if problem.problem_data[x[1][0]][x[1][1]][1] == m ]
|
|
xranges = [ (x[0], problem.problem_data[x[1][0]][x[1][1]][0]) for x in mach_ops ]
|
|
ax.broken_barh(xranges, ((problem.machines - m)*10, 9),
|
|
facecolors=[colorlist[x[1][0]] for x in mach_ops])
|
|
ax.set_ylim(5, 5 + (problem.machines+1)*10)
|
|
ax.set_xlim(0, 1.25 * end)
|
|
ax.set_yticks([15 + m * 10 for m in range(0, problem.machines)])
|
|
ax.set_yticklabels([ problem.machines - 1 - m for m in range(0, problem.machines)] )
|
|
handlecolors = colorlist[0:problem.jobs]
|
|
handles = [ patches.Patch(color = handlecolors[j], label = "Job "+str(j)) for j in range(0,problem.jobs) ]
|
|
labels = ["Job "+str(j) for j in range(0,problem.jobs)]
|
|
ax.legend(handles, labels)
|
|
|
|
plt.show()
|