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()
        old_state = decode_state(state, self.state_map)
        new_state.pos = old_state.pos
        new_state.neg = old_state.neg
        for f in action.effect_add:
            if f in old_state.neg:
                new_state.neg.remove(f)
                new_state.pos.append(f)
            elif f in old_state.pos:
                break
            else:
                new_state.pos.append(f)
        for f in action.effect_rem:
            if f in old_state.pos:
                new_state.pos.remove(f)
                new_state.neg.append(f)
            elif f in old_state.neg:
                break
            else:
                new_state.neg.append(f)
        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
        """
        # 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)
    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
        list_action = self.actions(state)
        found = False
        # check if action belongs to the list
        for act in list_action:
            if (act.name == action.name):
                found = True

        if not found:
            raise Exception
        new_state = FluentState([], [])
        curr_state = decode_state(state, self.state_map)
        # remove action that result from apply the action
        new_state.pos = [
            pos for pos in curr_state.pos if not (pos in action.effect_rem)
        ]
        new_state.pos += action.effect_add

        #print("new encode state : ",encode_state(new_state, self.state_map))
        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
        """
        # TODO implement
        new_state = FluentState([], [])
        current_state = decode_state(state, self.state_map)
        pos = []
        neg = []

        for fluent in current_state.pos:
            if fluent not in action.effect_rem:
                pos.append(fluent)

        for fluent in current_state.neg:
            if fluent not in action.effect_add:
                neg.append(fluent)

        for fluent in action.effect_add:
            if fluent not in pos:
                pos.append(fluent)

        for fluent in action.effect_rem:
            if fluent not in neg:
                neg.append(fluent)

        new_state.pos = pos
        new_state.neg = neg
        return encode_state(new_state, self.state_map)
Beispiel #5
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.name not in self.actions(state):
        #     print("available actions: ", )
        #     for atn in self.actions(state):
        #         print(atn.name, atn.args,)
        #     raise AssertionError("action {}{} is not applicable for state {} {}".format(action.name, action.args,state, self.state_map))
        new_state = FluentState([], [])
        fs = decode_state(state, self.state_map)

        new_state.pos = list((set(fs.pos) | set(action.effect_add)) -
                             set(action.effect_rem))
        new_state.neg = list((set(fs.neg) - set(action.effect_add))
                             | set(action.effect_rem))
        #state_map should not change!
        #self.state_map = new_state.pos + new_state.neg
        #print("state {} after action {}{} is state {}({})".format(state, action.name, action.args, encode_state(new_state, self.state_map), self.state_map))
        return encode_state(new_state, self.state_map)
Beispiel #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
        """
        # TODO implement
        new_state = FluentState([], [])

        # form set of current positive and negative states
        pos_state_actions = set(
            [self.state_map[i] for i, a in enumerate(state) if a == 'T'])
        neg_state_actions = set(
            [self.state_map[i] for i, a in enumerate(state) if a == 'F'])

        # update actions by removing concurrent effects and adding them to the correct groups
        new_state.pos = list(pos_state_actions - set(action.effect_rem)
                             | set(action.effect_add))
        new_state.neg = list(neg_state_actions - set(action.effect_add)
                             | set(action.effect_rem))

        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
        """

        new_state = FluentState([], [])
        old_state = decode_state(state, self.state_map)

        # Add positive state fluents
        new_state.pos = [fluent for fluent in old_state.pos \
            if fluent not in action.effect_rem]
        new_state.pos.extend([fluent for fluent in action.effect_add \
            if fluent not in new_state.pos])

        # Add negative state fluents
        new_state.neg = [fluent for fluent in old_state.neg \
            if fluent not in action.effect_add]
        new_state.neg.extend([fluent for fluent in action.effect_rem \
            if fluent not in 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
        """
        assert state != None, "state passed to Problem.result is None"
        assert action != None, "action passed to Problem.result is None"

        new_state = FluentState([], [])
        #decode the fulents of the current state
        old_fs = decode_state(state, self.state_map)

        #compute the new state's positive fluents by applying the actions
        kb = PropKB()
        #initialize a KB with positive fluents of old state.
        kb.tell(old_fs.pos_sentence())
        # apply the rem and add effects of the action onto the KB
        self.apply_action(kb, action)
        # the positive fluents of new state are in KB
        new_state.pos = kb.clauses
        logging.debug("Positive Fluents of New State: %r", new_state.pos)
        #encode_state only cares about the positive fluents in new_state
        #anything in state_map which is not in new_state.pos is assigned 'F'
        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
        """
        # TODO implement
        new_state = FluentState([], [])

        # current state
        cur_state = decode_state(state, self.state_map)

        # to execute an action, at current state
        # 1. all postive preconditions  remains in new_state.pos
        #          if they are not in the remove list as an effect of the action;
        # 2. all negative preconditions remains in new_state.neg
        #          if they are not in the add list for the effect of the action

        new_state.pos = [
            fluent for fluent in cur_state.pos
            if fluent not in action.effect_rem
        ]
        new_state.neg = [
            fluent for fluent in cur_state.neg
            if fluent not in action.effect_add
        ]

        # also, add remaining expr in action.effect_add to new_state.pos and
        #       add remaining expr in action.effect_rem to new_state.neg
        new_state.pos = new_state.pos + [
            fluent
            for fluent in action.effect_add if fluent not in new_state.pos
        ]
        new_state.neg = new_state.neg + [
            fluent
            for fluent in action.effect_rem if fluent not in new_state.neg
        ]

        return encode_state(new_state, self.state_map)
Beispiel #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
        """
        kb = PropKB()
        kb.tell(decode_state(state, self.state_map).pos_sentence())
        new_state = FluentState([], [])
        new_state.pos = [x for x in kb.clauses if x not in action.effect_rem]
        new_state.pos += action.effect_add
        new_state.neg += action.effect_rem
        return encode_state(new_state, self.state_map)
Beispiel #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
        """
        # implement
        new_state = FluentState([], [])
        old_state = decode_state(state, self.state_map)
        #if a fluent is not negated it stays positive and added effects are added to the positive fluents
        new_state.pos = list(set(old_state.pos).difference(set(action.effect_rem)).union(set(action.effect_add)))
        #if a fluent is not added it stays negated and removed effects are added to negative fluents
        new_state.neg = list(set(old_state.neg).difference(set(action.effect_add)).union(set(action.effect_rem)))
        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
        """
        new_state = FluentState([], [])
        old_fluent_state = decode_state(state, self.state_map)
        new_state.pos = old_fluent_state.pos
        new_state.neg = old_fluent_state.neg
        for to_add in action.effect_add:
            new_state.pos.append(to_add)
        for to_remove in action.effect_rem:
            new_state.pos.remove(to_remove)
        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
        """
        new_state = FluentState([], [])

        current_state = decode_state(state, self.state_map)
        
        # Add positive effect to state (sets union), remove negative effect from state's positive literals (set dieferrence)
        new_state.pos = list((set(current_state.pos) | set(action.effect_add)) - set(action.effect_rem))
        # Add negative effect to state (sets union), remove positive effect from state's negative literals (set dieferrence)
        new_state.neg = list((set(current_state.neg) | set(action.effect_rem)) - set(action.effect_add))

        return encode_state(new_state, self.state_map)
Beispiel #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
        """
        # TODO implement
        new_state = FluentState([], [])

        old_state = decode_state(state, self.state_map)

        new_state.pos = list(
            set(old_state.pos) - set(action.effect_rem)
            | set(action.effect_add))
        new_state.neg = list(
            set(old_state.neg) - set(action.effect_add)
            | set(action.effect_rem))

        return encode_state(new_state, self.state_map)
Beispiel #15
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([], [])
        current_state = decode_state(state, self.state_map)
        new_state.pos = [
            item for item in current_state.pos if item not in action.effect_rem
        ]
        new_state.neg = [
            item for item in current_state.neg if item not in action.effect_add
        ]
        for item in action.effect_add:
            if item not in new_state.pos:
                new_state.pos.append(item)
        for item in action.effect_rem:
            if item not in new_state.neg:
                new_state.neg.append(item)
        return encode_state(new_state, self.state_map)