def test_beta_prob(board_size): """ Tests beta probability for beta hill climbing Displays the results :param board_size: size of a board to test on """ # init test board board = Board(size=board_size) print( f'\nTesting steps distribution for basic hill climb with board of size {board_size}:' ) if not board.set_init_state(): print('Failed to load the board, quitting..') return # start with probability of 30% and decrease beta = 0.3 while True: print(f'[beta probability = {beta:.2f}]:') # analyze current steps distribution solver = CustomBetaHC(board, RESTARTS_BETA_STATIC, MAX_ITER_BETA_STATIC, N_PROB_STATIC, beta) # print the result _print_analysis(_engine.analyze_solver(solver)) # update beta beta = beta - 0.2 if beta > 0.1 else beta - 0.01 beta = round(beta, 2) if beta < 0.01: break
def test_performance_beta(board_size): """ Tests time performance of local hill climbing using restarts Displays the results :param board_size: size of a board to test on """ # init test board board = Board(size=board_size) print( f'\nTesting overall time performance of beta hill climbing with board of size {board_size}:' ) if not board.set_init_state(): print('Failed to load the board, quitting..') return # measure times solver = CustomBetaHC(board, 1, MAX_ITER_BETA_STATIC, N_PROB_STATIC, BETA_PROB_STATIC, stop_if_found=True) times = _engine.test_time_perfect(solver, SOLUTIONS_NUM) # print results _print_times(*times)
def test_starts_local(board_size): """ Tests time performance of separate local hill climbing (doesn't use restarts) Displays the results :param board_size: size of a board to test on """ # init test board board = Board(size=board_size) print( f'\nTesting time performance of separate starts of local hill climbing with board of size {board_size}:' ) if not board.set_init_state(): print('Failed to load the board, quitting..') return # measure times solver = HillClimbing(board, 1, MAX_ITER_LOCAL_STATIC) times = _engine.test_time_separate(solver, RESTARTS_LOCAL_STATIC) # print results _print_times(*times)
def test_itrs_beta(board_size): """ Tests different distribution between number of max iterations vs number of restarts in beta hill climbing Displays the results :param board_size: size of a board to test on """ # init test board board = Board(size=board_size) print( f'\nTesting steps distribution for basic hill climb with board of size {board_size}:' ) if not board.set_init_state(): print('Failed to load the board, quitting..') return # actual test _test_iter(initializer=_create_beta, board=board, sum_steps=1000000, min_steps=1000, growth=2)
def test_starts_beta(board_size): """ Tests time performance of separate beta hill climbing runs (doesn't use restarts) Displays the results :param board_size: size of a board to test on """ # init test board board = Board(size=board_size) print( f'\nTesting time performance of separate starts of beta hill climbing with board of size {board_size}:' ) if not board.set_init_state(): print('Failed to load the board, quitting..') return # measure times solver = CustomBetaHC(board, 1, MAX_ITER_BETA_STATIC, N_PROB_STATIC, BETA_PROB_STATIC) times = _engine.test_time_separate(solver, RESTARTS_BETA_STATIC) # print results _print_times(*times)