Somewhat sensible default parameters, temperature, amount of maximum anneal iterations and generator accept probability passed to anneal.

simanneal
Maximilian Schlosser 2017-07-12 04:23:36 +02:00
parent 991b7f4175
commit 3a7a8ebcbd
2 changed files with 9 additions and 8 deletions

View File

@ -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():

View File

@ -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)))