Some small documentation, hopefully useful

simanneal
Maximilian Schlosser 2017-07-10 15:59:00 +02:00
parent 85e61f91fb
commit a7f1a86748
1 changed files with 11 additions and 7 deletions

View File

@ -34,7 +34,8 @@ def accept(solution):
"""
return 3
#TODO: Loop over successors
#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
@ -50,14 +51,16 @@ def rectify(solution, idx):
def update_begin(solution, idx):
"""
Update the start time of the given task.
Update the start time of the given task wrt machine and job.
"""
global problem
task = solution[idx]
#find the next task with condition=true, if exists
machine = ( x for x in solution[idx-1::-1] if problem[x[1]][1] == problem[task[1]][1] )
prev_mach = next(machine, None)
prev_mach = next(machine, None) #returns the task or None
job = ( x for x in solution[idx-1::-1] if task[1][0] == x[1][0] )
prev_job = next( job, None)
end_mach = 0
@ -66,7 +69,7 @@ def update_begin(solution, idx):
end_mach = problem[prev_mach[1]][0] + prev_mach[0]
if prev_job:
end_job = problem[prev_job[1]][0] + prev_job[0]
solution[idx][0] = max(end_mach, end_job, task[0])
solution[idx][0] = max(end_mach, end_job, task[0])
def correct_indices(solution, idx):
@ -78,10 +81,11 @@ def correct_indices(solution, idx):
if tasks:
solution.remove(task)
solution.insert(idx + len(tasks), task)
#[1,3,2] -> idx = 1, len([2])=1
def correct_machine(solution, idx):
"""
Push jobs on machines back if conflicts exist.
Check conflicts on machines and correct if needed.
"""
task = solution[idx]
end = problem[task[1]][0] + task[0]
@ -104,12 +108,12 @@ def correct_precedence(solution, idx):
idx = solution.index(conflict)
solution[idx][0] = end
def generate(solution, steps):
def generate(old_solution, steps):
"""
Generate a new solution from an existing solution with a
specified number of max steps.
"""
solution = solution[:]
solution = old_solution[:]
options = [pull_fwd, accept]
option = random.choice(options)
return option(solution)