Exemplo n.º 1
0
    def expend(self):
        t = time()
        old_state = self.pop_open_list()
        self.expend_node += 1
        self.H_expend += old_state.f

        if self.goal_test(old_state.unseen):
            return old_state

    # Utils.print_map(self.world)

        Utils.print_all_whacers(self.world, [[(2, 1)], [(1, 3)]])
        for new_state in itertools.product(*self.get_all_frontire(old_state)):
            if new_state != old_state.location:  # and set(new_state).__len__()==self.number_of_agent:

                sorted_new_state, sorted_indexing = Utils.sort_list(new_state)

                dead_list = self.get_dead_list(old_state, new_state,
                                               sorted_indexing)

                seen_state = old_state.unseen - self.world.get_all_seen(
                    sorted_new_state)

                new_node = Node(
                    old_state, sorted_new_state, seen_state, dead_list,
                    self.get_cost(new_state, old_state, sorted_indexing))

                self.insert_to_open_list(new_node)

        #print(time() - t)

        # for state_index in range(LOS ** (self.number_of_agent)):
        #
        #     new_state , moving_status = self.get_new_state(old_state, state_index)
        #
        #     if self.world.is_valid_node(new_state, old_state,moving_status):
        #
        #         seen_state = old_state.unseen - self.world.get_all_seen(new_state)
        #         dead_list=old_state.dead_agent[:]
        #         for i in range(self.number_of_agent):
        #             if moving_status[i]==0 and i not in dead_list:
        #                 dead_list.append(i)
        #         new_node = Node(old_state, new_state, seen_state,dead_list, self.get_cost(old_state), 0)
        #
        #         self.insert_to_open_list(new_node)
        #         #print(time()-t)
        return False
Exemplo n.º 2
0
    def print_path(self, gole_node, see_agent_walk):
        all_path = self.get_path(gole_node)
        tmp_location = []
        for cell in all_path:

            # print(f'L = {cell.location} \t h = {cell.heuristics} ')
            tmp_location.append(cell.location)
            tmp_word = np.copy(self.world.grid_map)
            for k in cell.unseen:
                tmp_word[k] = 2
            for j in cell.location:
                tmp_word[j] = 3
            if see_agent_walk:
                plt.figure(1)
                plt.pcolormesh(tmp_word, edgecolors='black', linewidth=0.01)
                plt.gca().set_aspect('equal')
                plt.gca().set_ylim(plt.gca().get_ylim()[::-1])
                plt.draw()
                plt.pause(0.001)
                plt.clf()
                sleep(0.5)
        plt.close('all')
        Utils.print_all_whacers(self.world, tmp_location)