accept, tighten, generate rewrite (now has magic number describing percentage)
This commit is contained in:
parent
6783d91c43
commit
32c99ff075
|
@ -38,7 +38,7 @@ def accept(solution):
|
||||||
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.
|
||||||
"""
|
"""
|
||||||
tighten(solution)
|
return tighten(solution)
|
||||||
|
|
||||||
|
|
||||||
def tighten(solution):
|
def tighten(solution):
|
||||||
|
@ -79,6 +79,7 @@ def rectify(solution, idx):
|
||||||
#print(solution)
|
#print(solution)
|
||||||
correct_precedence(solution, i)
|
correct_precedence(solution, i)
|
||||||
#print(solution)
|
#print(solution)
|
||||||
|
return solution
|
||||||
|
|
||||||
def update_begin(solution, idx):
|
def update_begin(solution, idx):
|
||||||
"""
|
"""
|
||||||
|
@ -159,13 +160,16 @@ def generate(old_solution, steps):
|
||||||
specified number of max steps.
|
specified number of max steps.
|
||||||
"""
|
"""
|
||||||
solution = old_solution[:]
|
solution = old_solution[:]
|
||||||
options = [pull_fwd, accept]
|
accept_percent = 1
|
||||||
|
option = pull_fwd #do at least one pull
|
||||||
while(steps > 0):
|
while(steps > 0):
|
||||||
option = random.choice(options)
|
|
||||||
solution = option(solution)
|
solution = option(solution)
|
||||||
if(option == accept):
|
if(option == accept):
|
||||||
break
|
break
|
||||||
steps -= 1
|
steps -= 1
|
||||||
|
select = random.randrange(0,100)
|
||||||
|
option = pull_fwd if (select - accept_percent) > 0 else accept
|
||||||
|
accept(solution)
|
||||||
return solution
|
return solution
|
||||||
|
|
||||||
def mock():
|
def mock():
|
||||||
|
@ -174,16 +178,14 @@ def mock():
|
||||||
solution. Should clean up the namespace afterwards.
|
solution. Should clean up the namespace afterwards.
|
||||||
"""
|
"""
|
||||||
global problem
|
global problem
|
||||||
global solution
|
|
||||||
from Parser.js2_style import parse_file as mockload
|
from Parser.js2_style import parse_file as mockload
|
||||||
from SchedulingAlgorithms.enumerate import enumerate as mockenum
|
from SchedulingAlgorithms.enumerate import enumerate as mockenum
|
||||||
problem = mockload('../inputdata/sample')
|
problem = mockload('../inputdata/sample')
|
||||||
solution = mockenum(problem)
|
solution = mockenum(problem)
|
||||||
del mockload
|
del mockload
|
||||||
del mockenum
|
del mockenum
|
||||||
|
return solution
|
||||||
|
|
||||||
def init(in_problem, in_solution):
|
def init(in_problem):
|
||||||
global problem
|
global problem
|
||||||
global solution
|
|
||||||
problem = in_problem
|
problem = in_problem
|
||||||
solution = in_solution
|
|
||||||
|
|
Loading…
Reference in a new issue