Somewhat sensible default parameters, temperature, amount of maximum anneal iterations and generator accept probability passed to anneal.
This commit is contained in:
parent
991b7f4175
commit
3a7a8ebcbd
|
@ -154,13 +154,14 @@ def correct_precedence(solution, idx):
|
||||||
task = (new_start,) + task[1:]
|
task = (new_start,) + task[1:]
|
||||||
solution.insert(idx, task)
|
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
|
Generate a new solution from an existing solution with a
|
||||||
specified number of max steps.
|
specified number of max steps.
|
||||||
"""
|
"""
|
||||||
import sys
|
import sys
|
||||||
print("Max steps: " + str(steps))
|
print("Max steps: " + str(steps))
|
||||||
|
print("Accept probability: " + str(p))
|
||||||
sys.stdout.write("Start generation... ")
|
sys.stdout.write("Start generation... ")
|
||||||
solution = old_solution[:]
|
solution = old_solution[:]
|
||||||
option = pull_fwd #do at least one pull
|
option = pull_fwd #do at least one pull
|
||||||
|
@ -168,13 +169,13 @@ def generate(old_solution, steps, percent=1):
|
||||||
solution = option(solution)
|
solution = option(solution)
|
||||||
if(option == accept):
|
if(option == accept):
|
||||||
break
|
break
|
||||||
select = random.randrange(0,1000)
|
option = pull_fwd if p < random.random() else accept
|
||||||
option = pull_fwd #if (select - percent) > 0 else accept
|
|
||||||
if ((i * 100) % steps == 0):
|
if ((i * 100) % steps == 0):
|
||||||
sys.stdout.write(str(i*100/steps) + "%... ")
|
sys.stdout.write(str(i*100/steps) + "%... ")
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
sys.stdout.write("\n")
|
sys.stdout.write("Done\n")
|
||||||
accept(solution)
|
if option != accept:
|
||||||
|
accept(solution)
|
||||||
return solution
|
return solution
|
||||||
|
|
||||||
def mock():
|
def mock():
|
||||||
|
|
|
@ -4,15 +4,15 @@ from SchedulingAlgorithms.enumerate import enumerate as enum
|
||||||
from math import e
|
from math import e
|
||||||
from random import random
|
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
|
global problem
|
||||||
gen_init(problem)
|
gen_init(problem)
|
||||||
temp = max_temp
|
temp = max_temp
|
||||||
initial = enum(problem)
|
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
|
del initial
|
||||||
for step in range(0, max_steps):
|
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)
|
new_end = rate(new)
|
||||||
curr_end = rate(current)
|
curr_end = rate(current)
|
||||||
p = 1 / ( 1 + (e ** ((curr_end - new_end)/temp)))
|
p = 1 / ( 1 + (e ** ((curr_end - new_end)/temp)))
|
||||||
|
|
Loading…
Reference in a new issue