def h_ignore_preconditions(self, node: Node):
        '''
        This heuristic estimates the minimum number of actions that must be
        carried out from the current state in order to satisfy all of the goal
        conditions by ignoring the preconditions required for an action to be
        executed.
        '''
        # TODO implement (see Russell-Norvig Ed-3 10.2.3  or Russell-Norvig Ed-2 11.2)

        kb = PropKB()
        count = 0
        kb.tell(decode_state(node.state, self.state_map).sentence())
        for l in self.goal:
            if not kb.ask_if_true(l):
                count += 1
        print(node.state)
        print(count)
        return count
Пример #2
0
    def result(self, state: str, action: Action):
        """ Return the state that results from executing the given
        action in the given state. The action must be one of
        self.actions(state).

        :param state: state entering node
        :param action: Action applied
        :return: resulting state after action
        """
        kb = PropKB()
        curr_state = decode_state(state, self.state_map)
        kb.tell(curr_state.pos_sentence())
        # If the given action cannot be done in the current state,
        # then we return the current state.
        if not action.check_precond(kb, action.args):
            return state
        # Do the action with the current knowledge base.
        action.act(kb, action.args)
        # Construct the new_state straight from the knowledge base.
        new_state = "".join(['T' if kb.ask_if_true(s) else 'F' for s in self.state_map])
        return new_state