Output 1.0, Beispiel s. example.py

This commit is contained in:
lukasstracke 2017-07-12 16:33:53 +02:00
parent 435291679b
commit be28f9b11f
2 changed files with 30 additions and 6 deletions

22
src/Output/output.py Normal file
View file

@ -0,0 +1,22 @@
import matplotlib.pyplot as plt
from matplotlib import colors
import numpy as np
from SchedulingAlgorithms.simanneal import rate
def create_plot(problem, solution):
end = rate(solution)
with plt.xkcd():
fig,ax = plt.subplots()
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=[list(colors.XKCD_COLORS.values())[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)] )
plt.show()

View file

@ -1,7 +1,9 @@
INSTANCES = [(5, 5)]
TASKS = [[(1, 21), (0, 53), (4, 95), (3, 55), (2, 35)],
[(0, 21), (3, 52), (4, 16), (2, 26), (1, 71)],
[(3, 39), (4, 98), (1, 42), (2, 31), (0, 12)],
[(1, 77), (0, 55), (4, 79), (2, 66), (3, 77)],
[(0, 83), (3, 34), (2, 64), (1, 19), (4, 37)]]
from Generator import generator as g
from SchedulingAlgorithms import simanneal as sim
from Output import output as o
g.mock()
problem = g.problem
sim.init(problem)
solution = sim.anneal()
o.create_plot(problem, solution)