def test_hillclimb_and_restart_getting_worse(): # see whether we restart on each number correctly def move_operator(i): # even numbers only go up to 50 if i % 2 == 0 and i < 50: yield i + 2 elif i % 2 != 0 and i < 100: # odd numbers go higher yield i + 2 def init_function_gen(): yield 3 # start off on the odd numbers then restart on evens while True: yield 2 init_gen = init_function_gen() init_function = lambda: init_gen.next() num_evaluations, best_score, best = hillclimb.hillclimb_and_restart(init_function, move_operator, objective_function, max_evaluations) # should have used all iterations assert num_evaluations == max_evaluations # should have retained score from odd numbers assert best == 101 assert best_score == 101
def test_hillclimb_and_restart_getting_worse(): ''' see whether we restart on each number correctly ''' def move_operator(i): # even numbers only go up to 50 if i % 2 == 0 and i < 50: yield i + 2 elif i % 2 != 0 and i < 100: # odd numbers go higher yield i + 2 def init_function_gen(): yield 3 # start off on the odd numbers then restart on evens while True: yield 2 init_gen = init_function_gen() init_function = lambda: init_gen.next() num_evaluations, best_score, best = hillclimb.hillclimb_and_restart( init_function, move_operator, objective_function, max_evaluations) # should have used all iterations assert num_evaluations == max_evaluations # should have retained score from odd numbers assert best == 101 assert best_score == 101
def run_hillclimb(init_function, move_operator, objective_function, max_iterations): from hillclimb import hillclimb_and_restart iterations, score, best = hillclimb_and_restart(init_function, move_operator, objective_function, max_iterations) return iterations, score, best
def run_hillclimb(init_function,move_operator,objective_function,max_iterations): from hillclimb import hillclimb_and_restart iterations,score,best=hillclimb_and_restart(init_function,move_operator,objective_function,max_iterations) return iterations,score,best