Put docstrings at the right(?) positions.
This commit is contained in:
parent
a8c4a11b20
commit
bd370a1ed5
|
@ -2,6 +2,8 @@ from Parser import JobShopProblem as Problem
|
||||||
import random
|
import random
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def pull_fwd(solution):
|
||||||
""" Pull a task from a pseudo-random position to the position of
|
""" Pull a task from a pseudo-random position to the position of
|
||||||
a random task forward. If the task directly in front is part
|
a random task forward. If the task directly in front is part
|
||||||
of the same job, pull that instead. The first task can never
|
of the same job, pull that instead. The first task can never
|
||||||
|
@ -9,7 +11,6 @@ import random
|
||||||
|
|
||||||
Returns the modified solution and the tasks index.
|
Returns the modified solution and the tasks index.
|
||||||
"""
|
"""
|
||||||
def pull_fwd(solution):
|
|
||||||
old_idx = random.randint(1, len(solution)-1)
|
old_idx = random.randint(1, len(solution)-1)
|
||||||
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
|
||||||
|
@ -25,18 +26,18 @@ def pull_fwd(solution):
|
||||||
return (new_solution, new_idx)
|
return (new_solution, new_idx)
|
||||||
|
|
||||||
|
|
||||||
|
def accept(solution):
|
||||||
""" Accept the current generated solution and evaluate it.
|
""" Accept the current generated solution and evaluate it.
|
||||||
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.
|
||||||
"""
|
"""
|
||||||
def accept(solution):
|
|
||||||
return 3
|
return 3
|
||||||
|
|
||||||
|
|
||||||
|
def rectify(solution, idx):
|
||||||
""" Transform solution by adapting the begin times and delaying
|
""" Transform solution by adapting the begin times and delaying
|
||||||
tasks on the same machine if affected.
|
tasks on the same machine if affected.
|
||||||
"""
|
"""
|
||||||
def rectify(solution, idx):
|
|
||||||
global problem
|
global problem
|
||||||
|
|
||||||
#move previous task on the same machine back if clash
|
#move previous task on the same machine back if clash
|
||||||
|
@ -54,19 +55,19 @@ def rectify(solution, idx):
|
||||||
solution[idx][0] = solution[idx-1][0]
|
solution[idx][0] = solution[idx-1][0]
|
||||||
|
|
||||||
|
|
||||||
|
def generate(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.
|
||||||
"""
|
"""
|
||||||
def generate(solution, steps):
|
|
||||||
options = [pull_fwd, accept]
|
options = [pull_fwd, accept]
|
||||||
option = random.choice(options)
|
option = random.choice(options)
|
||||||
return option(solution)
|
return option(solution)
|
||||||
|
|
||||||
|
|
||||||
|
def mock():
|
||||||
""" Reads a mock problem and creates the corresponding enumerated
|
""" Reads a mock problem and creates the corresponding enumerated
|
||||||
solution. Should clean up the namespace afterwards.
|
solution. Should clean up the namespace afterwards.
|
||||||
"""
|
"""
|
||||||
def mock():
|
|
||||||
global problem
|
global problem
|
||||||
global solution
|
global solution
|
||||||
from Parser.js2_style import parse_file as mockload
|
from Parser.js2_style import parse_file as mockload
|
||||||
|
|
Loading…
Reference in a new issue