Ejemplo n.º 1
0
    def fix_g(self, old_state, new_parent):
        state = self.tree.get_node(old_state.__str__())

        old_parent = self.tree.get_node(state.predecessor(
            self.tree.identifier))

        new_parent = self.tree.get_node(new_parent.__str__())

        if self.seen_comparison(new_parent, old_parent):

            self.tree.move_node(state.identifier, new_parent.identifier)

            new_g = new_parent.data.g + \
                    Utils.n_dim_distance(self.tree.get_node(state.identifier).data.pos, new_parent.data.pos)

            self.tree.get_node(state.identifier).data.f = self.tree.get_node(state.identifier).data.f - \
                                                          self.tree.get_node(state.identifier).data.g + new_g

            self.tree.get_node(state.identifier).data.g = new_g

            for index, data in enumerate(self.open_list):
                if np.all(data.pos == state.data.pos):
                    self.open_list = np.delete(self.open_list, index)
                    self.insert_to_open_list(
                        self.tree.get_node(state.identifier).data)
                    break
Ejemplo n.º 2
0
    def expend(self, state):
        move_index = np.zeros(self.number_of_agent).astype(int)
        for i in range(LOS**number_of_agent):
            for j in range(number_of_agent):
                i, index = divmod(i, LOS)
                move_index[j] = index
            neighbor = self.world.get_one_neighbor(state, move_index)

            if self.world.in_bund(neighbor) and self.world.is_obstical(
                    neighbor):
                new_g = mwrp.tree.get_node(
                    state.__str__()).data.g + Utils.n_dim_distance(
                        state, neighbor)
                if not self.tree.contains(neighbor.__str__()):
                    h = self.heuristic(state)
                    new_node = Node(neighbor, new_g, new_g + h)
                    self.tree.create_node(neighbor.__str__(),
                                          neighbor.__str__(),
                                          parent=(state.__str__()),
                                          data=new_node)
                    self.insert_to_open_list(new_node)
                else:
                    if new_g < self.tree.get_node(neighbor.__str__()).data.g:
                        self.fix_g(neighbor, state)

        self.move_from_open_to_close()