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

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

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: