diff --git a/src/Generator/generator.py b/src/Generator/generator.py new file mode 100644 index 0000000..bb7ac34 --- /dev/null +++ b/src/Generator/generator.py @@ -0,0 +1,77 @@ +from Parser import JobShopProblem as Problem +import random + + +""" Pull a task from a pseudo-random position to the position of + a random task forward. If the task directly in front is part + of the same job, pull that instead. The first task can never + be pulled forward. Will not rectify solutions. + + Returns the modified solution and the tasks index. +""" +def pull_fwd(solution): + old_idx = random.randint(1, len(solution)-1) + while(solution[old_idx][1][0] == solution[old_idx-1][1][0]): + old_idx -= 1 + new_idx = random.randint(0, old_idx-1) + for task in solution[new:old_idx]: + if(task[1][0] == solution[old_idx][1][0]): + break + else: + new_solution = solution[:] + task = solution[old_idx] + new_solution.remove(task) + new_solution.insert(new_idx, task) + return (new_solution, new_idx) + + +""" Accept the current generated solution and evaluate it. + Maybe skip this during the first step to generate a more + random solution. +""" +def accept(solution): + return 3 + + +""" Transform solution by adapting the begin times and delaying + tasks on the same machine if affected. +""" +def rectify(solution, idx): + global problem + + #move previous task on the same machine back if clash +""" task = solution[idx][1] + prev_task = solution[idx-1][1] + while(problem[task[0]][task[1]][1] == problem[prev_task[0]][prev_task[1]][1]): + solution[idx-1][0] += problem[task[0]][task[1]][0] + solution[idx], solution[idx-1] = solution[idx-1], solution[idx] + idx -= 1 + task = solution[idx][1] + prev_task = solution[idx-1][1] + del prev_task +""" + #make parallel + solution[idx][0] = solution[idx-1][0] + + +"""Generate a new solution from an existing solution with a + specified number of max steps. +""" +def generate(solution, steps): + options = [pull_fwd, accept] + option = random.choice(options) + return option(solution) + + +""" Reads a mock problem and creates the corresponding enumerated + solution. Should clean up the namespace afterwards. +""" +def mock(): + global problem + global solution + from Parser.js2_style import parse_file as mockload + from SchedulingAlgorithms.enumerate import enumerate as mockenum + problem = mockload('../inputdata/sample') + solution = mockenum(problem) + del mockload + del mockenum