diff --git a/Readme.txt b/Readme.txt new file mode 100644 index 0000000..2990537 --- /dev/null +++ b/Readme.txt @@ -0,0 +1,23 @@ +README +----- + +Für die Ausführung des Algorithmus wird Python 3 (empfohlene Version: 3.6.1) benötigt. +Die Packages, die zusätzlich gebraucht werden, können der requirements.txt entnommen werden. +(Installation kann hier einzeln oder über den Befehl: python -m pip install -r requirements.txt) + +Zur Ausführung bitte im Terminal in den Ordner src gehen und dort das Skript main.py starten. +Parameter, die hierbei möglich sind: + -h zeigt alle Optionen an + -p aktiviert die Ausgabe über den Plotter als Diagramm + -l wird benötigt falls die Eingabe eine Liste von Problemen ist (d.h. für jobshop1.txt) + -i Index des Problems in der Liste (nur relevant bei -l) + -t setzt die Starttemperatur des Simulated Annealings + -s setzt die maximalen Umformungsschritte pro Generierung einer neuen Lösung + -a setzt die Wahrscheinlichkeit, pro Umformungsschritt auch eine Lösung zu akzeptieren, obwohl + noch nicht die maximalen Umformungsschritte erreicht sind + +-t -s und -a müssen nicht alle gesetzt sein, dann wird der jeweilige Defaultwert verwendet +Defaultwerte: max_temp = 300, max_steps = 250, accept_prob = 0.01 + +Beispielaufruf: + python .\main.py -p -l -i 2 -t 50 ..\inputdata\jobshop1.txt \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 5556179..55650c7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,5 @@ mypy -Arpeggio +arpeggio matplotlib +numpy +tkinter \ No newline at end of file diff --git a/src/Generator/generator.py b/src/Generator/generator.py index d6dca45..4cc4ab3 100644 --- a/src/Generator/generator.py +++ b/src/Generator/generator.py @@ -38,8 +38,8 @@ def accept(solution): Maybe skip this during the first step to generate a more random solution. """ - #return tighten(solution) - return solution + return tighten(solution) + #return solution def tighten(solution): diff --git a/src/Output/output.py b/src/Output/output.py index 2eb31ec..a2d2168 100644 --- a/src/Output/output.py +++ b/src/Output/output.py @@ -11,7 +11,9 @@ def create_plot(problem, solution): with plt.xkcd(): fig,ax = plt.subplots() - colorlist = list(colors.XKCD_COLORS.values()) + 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 ] diff --git a/src/example.py b/src/example.py index 14ed58a..50d2f22 100644 --- a/src/example.py +++ b/src/example.py @@ -1,10 +1,10 @@ -#import Parser.js1_style as p -import Parser.js2_style as p +import Parser.js1_style as p +#import Parser.js2_style as p from SchedulingAlgorithms import simanneal as sim from Output import output as o -#problem = p.parse_file("../inputdata/jobshop1.txt")[0] -problem = p.parse_file("../inputdata/sample") +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 diff --git a/src/main.py b/src/main.py index 31c5c07..44f5448 100644 --- a/src/main.py +++ b/src/main.py @@ -13,6 +13,9 @@ Command line options: -p activate pretty output (requires tkinter) -l assume that a file contains multiple problems, default is only 1 -i index of the problem you want solved. has no effect without l + -t set parameter max_temp of simulated annealing + -s set parameter max_steps of simulated annealing + -a set parameter accept_prob of simulated annealing Invocation: python [-hlp] file @@ -24,8 +27,8 @@ def main(): js1 = False plot = False try: - opts, args = getopt.getopt(sys.argv[1:], 'hpli:') - except getoptGetoptError as err: + opts, args = getopt.getopt(sys.argv[1:], 'hpli:t:s:a:') + except getopt.GetoptError as err: print(err) sys.exit() if ('-h', '') in opts: @@ -38,6 +41,12 @@ def main(): js1 = True idx = [int(x[1]) for x in opts if x[0]=='-i'] idx = idx[0] if idx else -1 + max_temp = [int(x[1]) for x in opts if x[0]=='-t'] + max_temp = max_temp[0] if max_temp else -1 + max_steps = [int(x[1]) for x in opts if x[0]=='-s'] + max_steps = max_steps[0] if max_steps else -1 + accept_prob = [int(x[1]) for x in opts if x[0]=='-a'] + accept_prob = accept_prob[0] if accept_prob else -1 if not args: print("No file given.") sys.exit() @@ -56,7 +65,28 @@ def main(): problem = problem[idx] print(problem) sim.init(problem) - solution = sim.anneal() + if not max_temp == -1: + if not max_steps == -1: + if not accept_prob == -1: + solution = sim.anneal(max_temp, max_steps, accept_prob) + else: + solution = sim.anneal(max_temp = max_temp, max_steps = max_steps) + else: + if not accept_prob == -1: + solution = sim.anneal(max_temp = max_temp, accept_prob = accept_prob) + else: + solution = sim.anneal(max_temp = max_temp) + else: + if not max_steps == -1: + if not accept_prob == -1: + solution = sim.anneal(max_steps = max_steps, accept_prob = accept_prob) + else: + solution = sim.anneal(max_steps = max_steps) + else: + if not accept_prob == -1: + solution = sim.anneal(accept_prob = accept_prob) + else: + solution = sim.anneal() print(solution) print(sim.rate(solution)) if plot: