コード例 #1
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
        """
        # TODO implement
        new_state = FluentState([], [])

        # print("result statemap", self.state_map)

        kb = PropKB()
        kb.tell(decode_state(state, self.state_map).pos_sentence())

        action.act(kb, action.args)

        # print("result - action {0}, ---- {1}".format(action.name, action.args))
        # print("result - KB Clauses: %r", kb.clauses)

        new_state.pos = kb.clauses

        return encode_state(new_state, self.state_map)
コード例 #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()
        # Add all clauses from the decoded state into the knowledge base
        kb.tell(decode_state(state, self.state_map).sentence())
        # Perform action on record the effects in the knowledge base
        action.act(kb, action.args)
        pos = []
        neg = []
        # Iterate over all clauses in knowledge base
        for clause in kb.clauses:
            # If the clause is a negation, add it to neg, else add it to pos
            if clause.op.startswith('~'):
                neg.append(clause)
            else:
                pos.append(clause)
        # Create a new fluent state based on the negative and positive literals
        new_state = FluentState(pos, neg)
        # Return the fluent state encoded as a string
        return encode_state(new_state, self.state_map)
コード例 #3
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
        """
        # TODO implement
        new_state = decode_state(state, self.state_map)
        kb = PropKB(new_state.sentence())
        for validAction in self.actions(state):
            if action.name == validAction.name and action.args == validAction.args:
                action.act(kb, action.args)
                neg = []
                pos = []
                for clause in kb.clauses:
                    if clause.op == "~":
                        neg.append(expr(clause.args[0]))
                    else:
                        pos.append(clause)
                new_state = FluentState(pos, neg)
                break
        return encode_state(new_state, self.state_map)
コード例 #4
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()
        old_state = decode_state(state, self.state_map)
        kb.tell(old_state.pos_sentence())
        action.act(kb, action.args)
        new_state_pos = list(action.effect_add)
        new_state_neg = list(action.effect_rem)
        for fluent in old_state.pos:
            if fluent not in new_state_neg and fluent not in new_state_pos:
                new_state_pos.append(fluent)

        for fluent in old_state.neg:
            if fluent not in new_state_pos and fluent not in new_state_neg:
                new_state_neg.append(fluent)

        new_state = FluentState(new_state_pos, new_state_neg)
        return encode_state(new_state, self.state_map)
    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
        """
        knowledge_base = PropKB()
        knowledge_base.tell(decode_state(state, self.state_map).sentence())
        action.act(knowledge_base, action.args)
        return encode_state(FluentState(knowledge_base.clauses, []), self.state_map)
コード例 #6
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(decode_state(state, self.state_map).sentence())
        action.act(kb, action.args)
        new_state = kb.clauses
        neg = [i for i in kb.clauses if i.op == '~']
        pos = [i for i in kb.clauses if i.op != '~']
        return encode_state(FluentState(pos, neg), self.state_map)
コード例 #7
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()
        kb.tell(decode_state(state, self.state_map).pos_sentence())
        action.act(kb, action.args)
        next_state = FluentState([], [])
        for clause in kb.clauses:
            next_state.pos.append(clause)
        return encode_state(next_state, self.state_map)
コード例 #8
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
        """
        # TODO implement
        #if action not in self.actions(state):
        #return False
        new_state = decode_state(state, self.state_map)
        kb = PropKB()
        kb.tell(new_state.sentence())
        action.act(kb, action.args)
        new_state = FluentState(kb.clauses, [])
        return encode_state(new_state, self.state_map)
コード例 #9
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()
        kb.tell(decode_state(state, self.state_map).pos_sentence())

        if not action.check_precond(kb, action.args):
            return state
        action.act(kb, action.args)
        new_state = FluentState(kb.clauses, [])

        return encode_state(new_state, self.state_map)
コード例 #10
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
        """
        # TODO implement
        kb = PropKB()
        kb.tell(decode_state(state, self.state_map).pos_sentence())

        # Act on the KB with 'action'
        action.act(kb, action.args)

        # Create a new fluent state from the KB
        new_state = FluentState(kb.clauses, [])

        return encode_state(new_state, self.state_map)
コード例 #11
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
        """
        # TODO implement
        new_state = FluentState([], [])
        kb = PropKB()
        kb.tell(decode_state(state, self.state_map).pos_sentence())
        action.check_precond(kb, action.args)
        action.act(kb, action.args)
        for clause in kb.clauses:
            if kb.ask_if_true:
                new_state.pos.append(clause)
            else:
                new_state.neg.append(clause)
        return encode_state(new_state, self.state_map)
コード例 #12
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
コード例 #13
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
        """
        new_state = FluentState([], [])
        # Create knowledge base
        kb = PropKB()
        # Add the current state to the KB
        kb.tell(decode_state(state, self.state_map).pos_sentence())
        # Change the KB according to action
        action.act(kb, action.args)
        # Add those changes to the FluentState
        for i in kb.clauses:
            new_state.pos.append(i)
        # Return the state in string formate (encode)
        return encode_state(new_state, self.state_map)
コード例 #14
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(decode_state(state, self.state_map).sentence())
        # Not sure why action.args should be given here instead
        # of using it as default.
        action.act(kb, action.args)
        # FAIL, kb does not have a method to go back to a FluentState?
        pos_list = [
            clause for clause in kb.clauses if '~' != clause.__repr__()[0]
        ]
        neg_list = [
            clause for clause in kb.clauses if '~' == clause.__repr__()[0]
        ]
        return encode_state(FluentState(pos_list, neg_list), self.state_map)
    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
        """
        # Create a knowledge base from the given state that can be used to
        # simulate an actions successor world state
        kb = PropKB()
        kb.tell(decode_state(state, self.state_map).sentence())

        # Execute the action on the knowledge base
        action.act(kb, action.args)

        # Grab the resulting positive and negative literals in the new
        # successor state. Return the resulting state as an encoded fluent
        pos_list, neg_list = partition(is_neg, kb.clauses)
        new_state = FluentState(list(pos_list), list(neg_list))
        return encode_state(new_state, self.state_map)