tighten
This commit is contained in:
parent
6be2e20cc7
commit
6783d91c43
|
@ -13,11 +13,11 @@ def pull_fwd(solution):
|
||||||
Returns the modified solution and the tasks index.
|
Returns the modified solution and the tasks index.
|
||||||
"""
|
"""
|
||||||
old_idx = random.randint(1, len(solution)-1)
|
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]):
|
while(solution[old_idx][1][0] == solution[old_idx-1][1][0]):
|
||||||
old_idx -= 1
|
old_idx -= 1
|
||||||
#Catch case of the op to be pulled being 0
|
#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):
|
if(old_idx == 0):
|
||||||
return pull_fwd(solution)
|
return pull_fwd(solution)
|
||||||
new_idx = random.randint(0, old_idx-1)
|
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
|
Maybe skip this during the first step to generate a more
|
||||||
random solution.
|
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):
|
def rectify(solution, idx):
|
||||||
"""
|
"""
|
||||||
Transform solution by adapting the begin times and delaying
|
Transform solution by adapting the begin times and delaying
|
||||||
|
@ -52,11 +74,11 @@ def rectify(solution, idx):
|
||||||
update_begin(solution, idx)
|
update_begin(solution, idx)
|
||||||
correct_indices(solution, idx)
|
correct_indices(solution, idx)
|
||||||
for i in range(idx, len(solution)-1):
|
for i in range(idx, len(solution)-1):
|
||||||
print("i: " + str(i))
|
#print("i: " + str(i))
|
||||||
correct_machine(solution, i)
|
correct_machine(solution, i)
|
||||||
print(solution)
|
#print(solution)
|
||||||
correct_precedence(solution, i)
|
correct_precedence(solution, i)
|
||||||
print(solution)
|
#print(solution)
|
||||||
|
|
||||||
def update_begin(solution, idx):
|
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)
|
conflict = next(( x for x in possible_conf if x[0] < end or x[1][1] < task[1][1]), None)
|
||||||
if(conflict):
|
if(conflict):
|
||||||
idx = solution.index(conflict)
|
idx = solution.index(conflict)
|
||||||
print("idx->" + str(idx))
|
#print("idx->" + str(idx))
|
||||||
if(conflict[0] < end):
|
if(conflict[0] < end):
|
||||||
solution[idx] = (end,) + solution[idx][1:]
|
solution[idx] = (end,) + solution[idx][1:]
|
||||||
correct_indices(solution,idx)
|
correct_indices(solution,idx)
|
||||||
if(conflict[1][1] < task[1][1]):
|
if(conflict[1][1] < task[1][1]):
|
||||||
new_start = solution[idx][0] + solution[idx][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)
|
solution.remove(task)
|
||||||
task = (new_start,) + task[1:]
|
task = (new_start,) + task[1:]
|
||||||
solution.insert(idx, task)
|
solution.insert(idx, task)
|
||||||
|
@ -159,3 +181,9 @@ def mock():
|
||||||
solution = mockenum(problem)
|
solution = mockenum(problem)
|
||||||
del mockload
|
del mockload
|
||||||
del mockenum
|
del mockenum
|
||||||
|
|
||||||
|
def init(in_problem, in_solution):
|
||||||
|
global problem
|
||||||
|
global solution
|
||||||
|
problem = in_problem
|
||||||
|
solution = in_solution
|
||||||
|
|
Loading…
Reference in a new issue