diff --git a/src/Generator/generator.py b/src/Generator/generator.py index 6920d4b..13d3441 100644 --- a/src/Generator/generator.py +++ b/src/Generator/generator.py @@ -154,13 +154,14 @@ def correct_precedence(solution, idx): task = (new_start,) + task[1:] solution.insert(idx, task) -def generate(old_solution, steps, percent=1): +def generate(old_solution, steps, p=0.01): """ Generate a new solution from an existing solution with a specified number of max steps. """ import sys print("Max steps: " + str(steps)) + print("Accept probability: " + str(p)) sys.stdout.write("Start generation... ") solution = old_solution[:] option = pull_fwd #do at least one pull @@ -168,13 +169,13 @@ def generate(old_solution, steps, percent=1): solution = option(solution) if(option == accept): break - select = random.randrange(0,1000) - option = pull_fwd #if (select - percent) > 0 else accept + option = pull_fwd if p < random.random() else accept if ((i * 100) % steps == 0): sys.stdout.write(str(i*100/steps) + "%... ") sys.stdout.flush() - sys.stdout.write("\n") - accept(solution) + sys.stdout.write("Done\n") + if option != accept: + accept(solution) return solution def mock(): diff --git a/src/SchedulingAlgorithms/simanneal.py b/src/SchedulingAlgorithms/simanneal.py index 082b64f..66d8818 100644 --- a/src/SchedulingAlgorithms/simanneal.py +++ b/src/SchedulingAlgorithms/simanneal.py @@ -4,15 +4,15 @@ from SchedulingAlgorithms.enumerate import enumerate as enum from math import e from random import random -def anneal(max_temp = 1000, max_steps = 1000): +def anneal(max_temp = 300, max_steps = 250, accept_prob=0.01): global problem gen_init(problem) temp = max_temp initial = enum(problem) - current = generate(initial, problem.machines * problem.jobs * 10) + current = generate(initial, problem.machines * problem.jobs * 10, 0) #Complete the iteration once fully. del initial for step in range(0, max_steps): - new = generate(current, problem.machines * problem.jobs) + new = generate(current, problem.machines * problem.jobs, accept_prob) new_end = rate(new) curr_end = rate(current) p = 1 / ( 1 + (e ** ((curr_end - new_end)/temp)))