Esempio n. 1
0
    def a_star_heuristic_2(self, puzzle: Puzzle8):
        tree_quene = PriorityQueue()
        queue_pro = PriorityQueue()

        tree = MyNode(puzzle)
        tree_quene.put(
            (puzzle.get_priority() + Utility.get_hurestic2(puzzle), tree))
        queue_pro.put(
            (puzzle.get_priority() + Utility.get_hurestic2(puzzle), puzzle))

        while not queue_pro.empty():

            puzzle_help = queue_pro.get()[1]
            node_parent = tree_quene.get()[1]
            print(puzzle_help)
            if Utility.is_goal(puzzle_help):
                return puzzle_help, tree

            possible_states = puzzle_help.expand()

            for item in possible_states:
                queue_pro.put(
                    (item.get_priority() + Utility.get_hurestic2(item), item))
                node_help = MyNode(item, parent=node_parent)
                tree_quene.put(
                    (item.get_priority() + Utility.get_hurestic2(item),
                     node_help))
Esempio n. 2
0
    def ucs(self, puzzle: Puzzle8):
        tree_quene = PriorityQueue()
        queue_pro = PriorityQueue()

        tree = MyNode(puzzle)
        tree_quene.put((puzzle.get_priority(), tree))
        queue_pro.put((puzzle.get_priority(), puzzle))

        while not queue_pro.empty():
            puzzle_help = queue_pro.get()[1]
            node_parent = tree_quene.get()[1]
            print(puzzle_help)
            if Utility.is_goal(puzzle_help):
                return puzzle_help, tree

            possible_states = puzzle_help.expand()

            for p in possible_states:
                queue_pro.put((puzzle.get_priority(), p))
                node_help = MyNode(p, parent=node_parent)
                tree_quene.put((puzzle.get_priority(), node_help))
Esempio n. 3
0
File: Main.py Progetto: smajy/AI
    def start(self):
        self.update_after_drag()

        puzzle = Puzzle8(self.start_puzzle_date)
        print(self.current_algorithm)

        # Terminate threads that may run
        self.algorithm_thread.terminate()
        self.image_thread.terminate()

        self.algorithm_thread.set_algorithm_type(self.current_algorithm)
        self.algorithm_thread.set_puzzle(puzzle)
        self.algorithm_thread.start()
Esempio n. 4
0
File: Main.py Progetto: smajy/AI
    def __init__(self, ):
        super().__init__()
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)

        item_list = ["BFS", "DFS", "UCS", "A*", "IDS", "IDA*"]
        self.ui.comboBox.addItems(item_list)

        self.current_algorithm = self.ui.comboBox.currentText()
        # self.start_puzzle_date = self.get_random_list()
        self.start_puzzle_date = [1, 2, 3, 4, 5, 6, 7, 0, 8]

        # put labels together for better control
        self.labels = []
        self.labels.append(self.ui.label1)
        self.labels.append(self.ui.label2)
        self.labels.append(self.ui.label3)
        self.labels.append(self.ui.label4)
        self.labels.append(self.ui.label5)
        self.labels.append(self.ui.label6)
        self.labels.append(self.ui.label7)
        self.labels.append(self.ui.label8)
        self.labels.append(self.ui.label9)

        self.set_labels_text(self.start_puzzle_date)

        # event handling
        self.ui.loadImageBtn.clicked.connect(self.getfile)
        self.ui.randomBrn.clicked.connect(self.start_randomly)
        self.ui.startBtn.clicked.connect(self.start)
        self.ui.endBtn.clicked.connect(self.end)

        # self.ui.comboBox.currentIndexChanged.connect(self.combobox_changed)

        # if you don't put [str] it return the index of combobox selected item
        self.ui.comboBox.activated[str].connect(self.combobox_changed)

        # initialize threads
        # algorithm threads
        self.algorithm_thread = AlgorithmThread(Puzzle8(
            self.start_puzzle_date))
        self.algorithm_thread.signal.connect(self.on_received)
        # Image thread:
        self.image_thread = ImageThread(self.current_algorithm)
        self.image_thread.signal.connect(self.on_tree_recived)