Some small documentation, hopefully useful

This commit is contained in:
Maximilian Schlosser 2017-07-10 15:59:00 +02:00
parent 85e61f91fb
commit a7f1a86748

View file

@ -34,7 +34,8 @@ def accept(solution):
""" """
return 3 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): def rectify(solution, idx):
""" """
Transform solution by adapting the begin times and delaying Transform solution by adapting the begin times and delaying
@ -50,14 +51,16 @@ def rectify(solution, idx):
def update_begin(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 global problem
task = solution[idx] 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] ) 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] ) job = ( x for x in solution[idx-1::-1] if task[1][0] == x[1][0] )
prev_job = next( job, None) prev_job = next( job, None)
end_mach = 0 end_mach = 0
@ -78,10 +81,11 @@ def correct_indices(solution, idx):
if tasks: if tasks:
solution.remove(task) solution.remove(task)
solution.insert(idx + len(tasks), task) solution.insert(idx + len(tasks), task)
#[1,3,2] -> idx = 1, len([2])=1
def correct_machine(solution, idx): def correct_machine(solution, idx):
""" """
Push jobs on machines back if conflicts exist. Check conflicts on machines and correct if needed.
""" """
task = solution[idx] task = solution[idx]
end = problem[task[1]][0] + task[0] end = problem[task[1]][0] + task[0]
@ -104,12 +108,12 @@ def correct_precedence(solution, idx):
idx = solution.index(conflict) idx = solution.index(conflict)
solution[idx][0] = end solution[idx][0] = end
def generate(solution, steps): def generate(old_solution, steps):
""" """
Generate a new solution from an existing solution with a Generate a new solution from an existing solution with a
specified number of max steps. specified number of max steps.
""" """
solution = solution[:] solution = old_solution[:]
options = [pull_fwd, accept] options = [pull_fwd, accept]
option = random.choice(options) option = random.choice(options)
return option(solution) return option(solution)