finale Version: Readme für Dr. Gaggl, Reqs ergänzt (kp ob notwendig), weiss als Farbe im Plot ausschliessen, main um simanneal-params ergaenzt

master
lukasstracke 2017-07-13 00:03:27 +02:00
parent d6f3eb9dd3
commit 03c5fb612d
6 changed files with 68 additions and 11 deletions

23
Readme.txt Normal file
View File

@ -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

View File

@ -1,3 +1,5 @@
mypy
Arpeggio
arpeggio
matplotlib
numpy
tkinter

View File

@ -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):

View File

@ -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 ]

View File

@ -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)

View File

@ -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: