This commit is contained in:
Maximilian Schlosser 2017-07-11 12:07:03 +02:00
parent 6be2e20cc7
commit 6783d91c43

View file

@ -13,11 +13,11 @@ def pull_fwd(solution):
Returns the modified solution and the tasks index.
"""
old_idx = random.randint(1, len(solution)-1)
print("old_idx" + str(old_idx))
#print("old_idx" + str(old_idx))
while(solution[old_idx][1][0] == solution[old_idx-1][1][0]):
old_idx -= 1
#Catch case of the op to be pulled being 0
print("old_idx" + str(old_idx))
#print("old_idx: " + str(old_idx))
if(old_idx == 0):
return pull_fwd(solution)
new_idx = random.randint(0, old_idx-1)
@ -38,10 +38,32 @@ def accept(solution):
Maybe skip this during the first step to generate a more
random solution.
"""
return 3
tighten(solution)
def tighten(solution):
"""
Try to remove any holes in the schedule.
"""
global problem
bound = len(solution)
for i in range(0,bound):
jobs = ( task for task in solution[i-1:bound:-1] if task[1][0] == solution[i][1][0] )
machs = ( task for task in solution[i-1:bound:-1] if problem[task[1]][1] == problem[solution[i][1]][1] )
job = next(jobs,None)
mach = next(machs,None)
times = []
if job:
times += [job[0] + problem[job[1]][0]]
if mach:
times += [mach[0] + problem[job[1]][0]]
if times:
solution[i] = (max(times), solution[i][1])
solution.sort()
return solution
#TODO: Loop over successors. The correct_methods might need to be
#changed so the changes are correctly passed on
def rectify(solution, idx):
"""
Transform solution by adapting the begin times and delaying
@ -52,11 +74,11 @@ def rectify(solution, idx):
update_begin(solution, idx)
correct_indices(solution, idx)
for i in range(idx, len(solution)-1):
print("i: " + str(i))
#print("i: " + str(i))
correct_machine(solution, i)
print(solution)
#print(solution)
correct_precedence(solution, i)
print(solution)
#print(solution)
def update_begin(solution, idx):
"""
@ -120,13 +142,13 @@ def correct_precedence(solution, idx):
conflict = next(( x for x in possible_conf if x[0] < end or x[1][1] < task[1][1]), None)
if(conflict):
idx = solution.index(conflict)
print("idx->" + str(idx))
#print("idx->" + str(idx))
if(conflict[0] < end):
solution[idx] = (end,) + solution[idx][1:]
correct_indices(solution,idx)
if(conflict[1][1] < task[1][1]):
new_start = solution[idx][0] + solution[idx][1][1]
print("new_start: " + str(new_start))
#print("new_start: " + str(new_start))
solution.remove(task)
task = (new_start,) + task[1:]
solution.insert(idx, task)
@ -159,3 +181,9 @@ def mock():
solution = mockenum(problem)
del mockload
del mockenum
def init(in_problem, in_solution):
global problem
global solution
problem = in_problem
solution = in_solution