예제 #1
0
def generate_maze(algorithm, height, width, path, displayMaze):
    if algorithm == "backtracking":
        backtracking = Backtracking(height, width, path, displayMaze)
        backtracking.createMaze()
    elif algorithm == "aldous_broder":
        aldous_broder = Aldous_Broder(height, width, path, displayMaze)
        aldous_broder.createMaze()
    elif algorithm == "hunt_and_kill":
        hunt_and_kill = Hunt_and_Kill(height, width, path, displayMaze)
        hunt_and_kill.createMaze()
    elif algorithm == "prims":
        prims = Prims(height, width, path, displayMaze)
        prims.createMaze()
def main():
    # grab word length
    i = int(sys.argv[1][0])
    # start timer
    start = time.time()
    # Get relevant words
    frontLetters, endLetters, words = extractLetters(i)
    wordCount = len(words)
    #DFS = DepthFirstSearch(words, wordCount)
    #solution = DFS.run()
    BT = Backtracking(frontLetters, endLetters, words, wordCount)
    solution = BT.search()
    end = time.time()
    print("Time: ", end-start)
예제 #3
0
 def setUp(self):
     self.easy = "003020600900305001001806400008102900700000008006708200" + \
                 "002609500800203009005010300"
     self.normal = "400000805030000000000700000020000060000080400000010000" + \
                   "000603070500200000104000000"
     self.hard = "000006000059000008200008000045000000003000000006003054" + \
                 "000325006000000000000000000"
     self.back = Backtracking()
예제 #4
0
class TestBacktracking(unittest.TestCase):

    def setUp(self):
        self.easy = "003020600900305001001806400008102900700000008006708200" + \
                    "002609500800203009005010300"
        self.normal = "400000805030000000000700000020000060000080400000010000" + \
                      "000603070500200000104000000"
        self.hard = "000006000059000008200008000045000000003000000006003054" + \
                    "000325006000000000000000000"
        self.back = Backtracking()

    def test_verify_solution_for_easy_grid(self):
        expected_result_easy = '48392165796734582125187649354813297672956413' \
                               '8136798245372689514814253769695417382'
        dict_result = self.back.solve(self.easy)
        result = self.back.dict_to_string(dict_result)
        self.assertEqual(expected_result_easy, result)

    def test_verify_solution_for_normal_grid(self):
        expected_result_normal = '41736982563215894795872431682543716979158643' \
                                 '2346912758289643571573291684164875293'
        dict_result = self.back.solve(self.normal)
        result = self.back.dict_to_string(dict_result)
        self.assertEqual(expected_result_normal, result)

    def test_verify_solution_for_hard_grid(self):
        expected_result_hard = "73815624965943217821479863584567931292354186717" \
                               "6283954481325796562917483397864521"
        dict_result = self.back.solve(self.hard)
        result = self.back.dict_to_string(dict_result)
        self.assertEqual(expected_result_hard, result)
예제 #5
0
# Created by Ningxiang He, 01/30/2019

from map_color import map_color
from backtracking import Backtracking
import timeit

new_csp = map_color()  # create a csp map_color
search = Backtracking(True, True, True)
# define a class Backtracking.
# First parameter represents enable or disable Inference. True means enable. False means disable.
# Second parameter represents enable or disable MRV.
# Third parameter represents enable or disable LCV.

start_time = timeit.default_timer() # start the timer
solution = search.Backtracking_search(new_csp) # call Backtracking search function. Input csp
stop_time = timeit.default_timer() # stop the timer

print ("Run time is:\n", stop_time-start_time) # output run time
print ("The solution is:\n", solution) # print assignment
new_csp.show_result(solution) # print territory and color
예제 #6
0
 def __test_backtracking(self, data):
     sudoku = Sudoku(data.puzzle)
     Backtracking(sudoku).solve()
     self.assertTrue(self.__are_arrays_equal(data.solution, sudoku.cells))
예제 #7
0
파일: futoshiki.py 프로젝트: eug/futoshiki
    if not config.value_selection:
        print('Algoritmo de seleção de valor não especificado')
        sys.exit(1)

    if not config.look_ahead:
        print('Algoritmo de inferencia não especificado')
        sys.exit(1)

    instances = read_file(config.input_file)

    if config.instance_id > 0:
        instances = [instances[config.instance_id - 1]]

    for variables, domains, constraints, assignment, D, r, n in instances:
        try:
            bt = Backtracking(variables, domains, constraints, 1000000)
            bt.set_is_complete(total_assignment)
            bt.set_variable_selection(config.variable_selection)
            bt.set_value_selection(config.value_selection)
            bt.set_look_ahead(config.look_ahead)

            # initial_nassigns = len(assignment)
            start = time()
            output = bt.solve(assignment)
            t = time() - start
            # final_nassigns = len(output)

            nassigns = bt.csp.nassigns
            # print(initial_nassigns, final_nassigns,final_nassigns - initial_nassigns != nassigns)
        except KeyboardInterrupt:
            t = 0
예제 #8
0
# Created by Ningxiang He, 01/30/2019

from Circuit_board import Circuit_board
from backtracking import Backtracking
import timeit

cur_csp = Circuit_board()  # create a csp circuit board
search = Backtracking(False, True, False)
# define a class Backtracking.
# First parameter represents enable or disable Inference. True means enable. False means disable.
# Second parameter represents enable or disable MRV.
# Third parameter represents enable or disable LCV.

start_time = timeit.default_timer()  # start the timer
solution = search.Backtracking_search(
    cur_csp)  # call Backtracking search function. Input csp
stop_time = timeit.default_timer()  # stop the timer

print("Run time is:\n", stop_time - start_time)  # print run time
print("The assignment is:\n", solution)  # print assignment
cur_csp.show_result(solution)  # print the board
예제 #9
0
 def backtrack_time(self, index, iter):
     BacktrackingAlgorithm = Backtracking(index, self.SymmetricalMatrix)
     start = timer()
     BacktrackingAlgorithm.tsp(0, 1, 0)
     end = timer()
     self.BacktrackingTime[iter] = end - start
예제 #10
0
def test_backtracking():
    backtracking = Backtracking(201, 201, "maze.png", False)
    assert backtracking.createMaze() == 0