From 304dc401f741a5c29cec7692beed9b5a2031082f Mon Sep 17 00:00:00 2001 From: Maximilian Schlosser Date: Tue, 11 Jul 2017 13:18:14 +0200 Subject: [PATCH 1/3] Added matplotlib as requirement --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index 4612f56..5556179 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ mypy Arpeggio +matplotlib From be28f9b11fdbffef6c4f94741840c6fcc7513655 Mon Sep 17 00:00:00 2001 From: lukasstracke Date: Wed, 12 Jul 2017 16:33:53 +0200 Subject: [PATCH 2/3] Output 1.0, Beispiel s. example.py --- src/Output/output.py | 22 ++++++++++++++++++++++ src/example.py | 14 ++++++++------ 2 files changed, 30 insertions(+), 6 deletions(-) create mode 100644 src/Output/output.py diff --git a/src/Output/output.py b/src/Output/output.py new file mode 100644 index 0000000..615f6d1 --- /dev/null +++ b/src/Output/output.py @@ -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() \ No newline at end of file diff --git a/src/example.py b/src/example.py index a56e489..be8b4dd 100644 --- a/src/example.py +++ b/src/example.py @@ -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) \ No newline at end of file From d88e5d9e9155f48749a395c784900a6072169ae7 Mon Sep 17 00:00:00 2001 From: lukasstracke Date: Wed, 12 Jul 2017 17:50:36 +0200 Subject: [PATCH 3/3] Legendary Output, v1.1 --- src/Generator/generator.py | 3 ++- src/Output/output.py | 10 +++++++++- src/example.py | 7 ++++--- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/Generator/generator.py b/src/Generator/generator.py index 13d3441..d6dca45 100644 --- a/src/Generator/generator.py +++ b/src/Generator/generator.py @@ -38,7 +38,8 @@ def accept(solution): Maybe skip this during the first step to generate a more random solution. """ - return tighten(solution) + #return tighten(solution) + return solution def tighten(solution): diff --git a/src/Output/output.py b/src/Output/output.py index 615f6d1..6f06aed 100644 --- a/src/Output/output.py +++ b/src/Output/output.py @@ -1,7 +1,9 @@ import matplotlib.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): @@ -9,14 +11,20 @@ def create_plot(problem, solution): with plt.xkcd(): fig,ax = plt.subplots() + colorlist = list(colors.XKCD_COLORS.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=[list(colors.XKCD_COLORS.values())[x[1][0]] for x in mach_ops]) + 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() \ No newline at end of file diff --git a/src/example.py b/src/example.py index be8b4dd..14ed58a 100644 --- a/src/example.py +++ b/src/example.py @@ -1,9 +1,10 @@ -from Generator import generator as g +#import Parser.js1_style as p +import Parser.js2_style as p from SchedulingAlgorithms import simanneal as sim from Output import output as o -g.mock() -problem = g.problem +#problem = p.parse_file("../inputdata/jobshop1.txt")[0] +problem = p.parse_file("../inputdata/sample") sim.init(problem) solution = sim.anneal() o.create_plot(problem, solution) \ No newline at end of file