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)
        for fluent in old_state.pos:
            if fluent not in action.effect_rem:
                new_state.pos.append(fluent)
        for fluent in action.effect_add:
            if fluent not in new_state.pos:
                new_state.pos.append(fluent)
        for fluent in old_state.neg:
            if fluent not in action.effect_add:
                new_state.neg.append(fluent)
        for fluent in action.effect_rem:
            if fluent not in new_state.neg:
                new_state.neg.append(fluent)
        new_state_st = encode_state(new_state, self.state_map)
        return encode_state(new_state, self.state_map)
Esempio n. 2
0
 def result(self, state: str, action: Action):
     new_state = FluentState([], [])
     old_state = decode_state(state, self.state_map)
     for fluent in old_state.pos:
         if fluent not in action.effect_rem:
             new_state.pos.append(fluent)
     for fluent in action.effect_add:
         if fluent not in new_state.pos:
             new_state.pos.append(fluent)
     for fluent in old_state.neg:
         if fluent not in action.effect_add:
             new_state.neg.append(fluent)
     for fluent in action.effect_rem:
         if fluent not in new_state.neg:
             new_state.neg.append(fluent)
     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
        """
        fluent_state=decode_state(state, self.state_map)

        pos = [x for x in (fluent_state.pos + action.effect_add) if x not in action.effect_rem]
        neg = [x for x in (fluent_state.neg + action.effect_rem) if x not in action.effect_add]

        new_state = FluentState(pos, neg)
        return encode_state(new_state, self.state_map)
    def __init__(self, cargos, planes, airports, initial: FluentState, goal: list):
        """

        :param cargos: list of str
            cargos in the problem
        :param planes: list of str
            planes in the problem
        :param airports: list of str
            airports in the problem
        :param initial: FluentState object
            positive and negative literal fluents (as expr) describing initial state
        :param goal: list of expr
            literal fluents required for goal test
        """
        self.state_map = initial.pos + initial.neg
        self.initial_state_TF = encode_state(initial, self.state_map)
        Problem.__init__(self, self.initial_state_TF, goal=goal)
        self.cargos = cargos
        self.planes = planes
        self.airports = airports
        self.actions_list = self.get_actions()
Esempio n. 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
        new_state = FluentState([], [])
        kb = PropKB()
        kb.tell(decode_state(state, self.state_map).pos_sentence())

        action(kb, action.args)

        for clause in kb.clauses:
            new_state.pos.append(clause)
        for clause in action.effect_rem:
            new_state.neg.append(clause)

        return encode_state(new_state, self.state_map)
    def __init__(self, cargos, planes, airports, initial: FluentState,
                 goal: list):
        """

        :param cargos: list of str
            cargos in the problem
        :param planes: list of str
            planes in the problem
        :param airports: list of str
            airports in the problem
        :param initial: FluentState object
            positive and negative literal fluents (as expr) describing initial state
        :param goal: list of expr
            literal fluents required for goal test
        """
        self.state_map = initial.pos + initial.neg
        self.initial_state_TF = encode_state(initial, self.state_map)
        Problem.__init__(self, self.initial_state_TF, goal=goal)
        self.cargos = cargos
        self.planes = planes
        self.airports = airports
        self.actions_list = self.get_actions()
    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)

        new_state.pos.extend(f for f in old_state.pos
                             if f not in action.effect_rem)
        new_state.pos.extend(f for f in action.effect_add
                             if f not in new_state.pos)
        new_state.neg.extend(f for f in old_state.neg
                             if f not in action.effect_add)
        new_state.neg.extend(f for f in action.effect_rem
                             if f not in new_state.neg)

        return encode_state(new_state, self.state_map)
Esempio n. 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
        """
        # Lifted from example_have_cake.py
        new_state = FluentState([], [])

        # Get the current state
        old_state = decode_state(state, self.state_map)

        # Per the teaching materials, the precondition and effect of an action are each conjunctions of literals
        # (positive or negated atomic sentences). The precondition defines the states in which the action can be
        # executed, and the effect defines the result of executing the action. So, for each fluent (positive or
        # negative) in the old state, we need to look in the action's effects (both the add and remove effects) to
        # determine how the fluent will be carried over to the new state, as a positive or a negative fluent.
        for fluent in old_state.pos:
            if fluent not in action.effect_rem:
                new_state.pos.append(fluent)
        for fluent in old_state.neg:
            if fluent not in action.effect_add:
                new_state.neg.append(fluent)

        # The action may have positive and negative effects INDEPENDENTLY of the old state. If they're add effects,
        # we need to make sure these fluents are added to the new state's positive sentences. Similarly, if they're
        # remove effects, these fluents need to be added to the new state's negative sentences.
        for fluent in action.effect_add:
            if fluent not in new_state.pos:
                new_state.pos.append(fluent)
        for fluent in action.effect_rem:
            if fluent not in new_state.neg:
                new_state.neg.append(fluent)

        # Return the new state
        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
        """
        current_state = decode_state(state, self.state_map)

        new_pos = set(current_state.pos)
        new_neg = set(current_state.neg)

        for add in action.effect_add:
            new_pos.add(add)
            new_neg.discard(add)
        for rem in action.effect_rem:
            new_pos.discard(rem)
            new_neg.add(rem)

        return encode_state(FluentState(list(new_pos), list(new_neg)), 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([], [])
        old_state = decode_state(state, self.state_map)

        for fluent in old_state.pos:
            if fluent not in action.effect_rem:
                new_state.pos.append(
                    fluent
                )  # add positive fluents which are in the old state and should not be removed

        for fluent in action.effect_add:
            if fluent not in new_state.pos:
                new_state.pos.append(
                    fluent
                )  # add positive fluents which should be added and have not already been added

        for fluent in old_state.neg:
            if fluent not in action.effect_add:
                new_state.neg.append(
                    fluent
                )  # add negative fluents which are in the old state and should not be added

        for fluent in action.effect_rem:
            if fluent not in new_state.neg:
                new_state.neg.append(
                    fluent
                )  # add negative fluents which should be removed but have not already been removed from the negative state

        return encode_state(new_state, self.state_map)
    def result(self, state: str, action: Action):
        """ Returns the state that results from executing the given
        action in the given state. The action is 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)

        # If a positive fluent has not been removed by the effect of current action then
        # append that to positive fluents in the new_state.
        for fluent in old_state.pos:
            if fluent not in action.effect_rem:
                new_state.pos.append(fluent)

        # If a new positive fluent is added by the effect of current action then
        # append that to positive fluents in the new_state.
        for fluent in action.effect_add:
            if fluent not in new_state.pos:
                new_state.pos.append(fluent)

        # If a negative fluent has not been removed by the effect of current action then
        # append that to negative fluents in the new_state.
        for fluent in old_state.neg:
            if fluent not in action.effect_add:
                new_state.neg.append

        # If a negative fluent has been removed by the effect of current action then
        # append that to negative fluents in the new_state.
        for fluents in action.effect_rem:
            if fluent not in new_state.neg:
                new_state.neg.append(fluent)

        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

        # Get the current state
        curr_state = decode_state(state, self.state_map)
        new_state = FluentState([], [])

        # For each fluent in current state, we need to check the action's effects (added or removed effects),
        # in order to how the positive or negative fluent can be carried over to the new state.

        for f in curr_state.neg:
            if f not in action.effect_add:
                new_state.neg.append(f)

        for f in curr_state.pos:
            if f not in action.effect_rem:
                new_state.pos.append(f)

        #  The action may have positive and negative effects separated, e.g. we need to check if the fluents are
        #  added to the new state's positive clauses if the actions have add effects. It is also the same for negative
        #  clauses
        for f in action.effect_rem:
            if f not in new_state.neg:
                new_state.neg.append(f)

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

        return encode_state(new_state, self.state_map)
Esempio n. 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
        """
        # TODO implement
        new_state = FluentState([], [])
        #This code is used from Cake example file
        #The idea of this function is to define next state in our problem
        #which is going to "happen" after applying current action
        old_state = decode_state(state, self.state_map)

        #Going through positive fluents in previous (old) state
        for fluent in old_state.pos:
            #if that fluent is not in removal_effect from action -> add it to positve fluents for new state
            if fluent not in action.effect_rem:
                new_state.pos.append(fluent)

        #going through fluents that are added by the action
        for fluent in action.effect_add:
            #if that fluent is not already in positive fluents of new state -> add it
            if fluent not in new_state.pos:
                new_state.pos.append(fluent)
        #going through negative fluents from old state
        for fluent in old_state.neg:
            #if that negative fluent is not in adding fluents of the action -> add it to negative fluents for new state
            if fluent not in action.effect_add:
                new_state.neg.append(fluent)
        #going through fluents that are being removed by the action
        for fluent in action.effect_rem:
            #if that fluent is not already in negatives for the new state -> add it
            if fluent not in new_state.neg:
                new_state.neg.append(fluent)
        return encode_state(new_state, self.state_map)
Esempio n. 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).

        This routine simply takes the current state, pos and neg, and copies to a new version depending
        on the action's effects which can be add or rem.

        So if the action has a add effect the new state will contain that effect in its pos section
        If the action has a rem effect then the new state will contain that effect in its neg section

        More formally put (p368) - The result of executing action a in state s is defined as a state s' which is represented
        by the set of fluents formed by starting with s, removing the fluents that appear as negative literals in the
        action's effects (what we wil call the delete list or DEL(a), and addign the fluents that are positie literals
        in the action's effects (what we will call the add list or ADD(a).

        :param state: state entering node
        :param action: Action applied
        :return: resulting state after action
        """
        # TODO implement
        #print('Running result() function...')
        new_state = FluentState([], [])
        old_state = decode_state(state, self.state_map)
        for fluent in old_state.pos:
            if fluent not in action.effect_rem:
                new_state.pos.append(fluent)
        for fluent in action.effect_add:
            if fluent not in new_state.pos:
                new_state.pos.append(fluent)
        for fluent in old_state.neg:
            if fluent not in action.effect_add:
                new_state.neg.append(fluent)
        for fluent in action.effect_rem:
            if fluent not in new_state.neg:
                new_state.neg.append(fluent)

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

        old_state = decode_state(state, self.state_map)

        for pos_fluent in old_state.pos:
            if pos_fluent not in action.effect_rem:  # positive effect
                new_state.pos.append(pos_fluent)

        for pos_fluent in action.effect_add:  # negative effect
            if pos_fluent not in new_state.pos:
                new_state.pos.append(pos_fluent)

        for neg_fluent in old_state.neg:
            if neg_fluent not in action.effect_add:  # negative effect
                new_state.neg.append(neg_fluent)

        for neg_fluent in action.effect_rem:  # positive effect
            if neg_fluent not in new_state.neg:
                new_state.neg.append(neg_fluent)
        '''
        old_state = decode_state(state, self.state_map)
        pos, neg = set(old_state.pos), set(old_state.neg)
        pos = pos - set(action.effect_rem) | set(action.effect_add)
        neg = neg - set(action.effect_add) | set(action.effect_rem)
        new_state = FluentState(list(pos), list(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
        """
        # This from example_have_cake.py should work
        new_state = FluentState([], [])
        old_state = decode_state(state, self.state_map)
        """
        for fluent in old_state.pos:
            if fluent not in action.effect_rem:
                new_state.pos.append(fluent)
        for fluent in action.effect_add:
            if fluent not in new_state.pos:
                new_state.pos.append(fluent)
        for fluent in old_state.neg:
            if fluent not in action.effect_add:
                new_state.neg.append(fluent)
        for fluent in action.effect_rem:
            if fluent not in new_state.neg:
                new_state.neg.append(fluent)
        """
        # This may be a better way, how much depends on the size
        pos_fluents = set(old_state.pos)
        pos_fluents.difference_update(action.effect_rem)
        pos_fluents.update(action.effect_add)
        new_state.pos.extend(pos_fluents)
        neg_fluents = set(old_state.neg)
        neg_fluents.difference_update(action.effect_add)
        neg_fluents.update(action.effect_rem)
        new_state.neg.extend(neg_fluents)
        #"""

        return encode_state(new_state, self.state_map)
    def process_actions(self, state):
        '''
        This function is called recursively to process all action for a state, each state
        will be counted as one, and the total will indicate how many actions/states are
        processed to reach the goal, ignoring the preconditions
        :param state:
        :return: count of states to reach a goal
        '''
        count = 1
        actions = self.actions(state)
        fluent_state = decode_state(state, self.state_map)
        # assume all actions are effective regardless and add them to the state.
        for action in actions:
            for fluent in action.effect_add:
                if fluent not in fluent_state.pos:
                    fluent_state.pos.append(fluent)
                if fluent in fluent_state.neg:
                    fluent_state.neg.remove(fluent)
        new_state = encode_state(fluent_state, self.state_map)
        if not self.goal_test(new_state):
            count += self.process_actions(new_state)

        return count
Esempio n. 18
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)
        for positive in old_state.pos:
            if positive in action.effect_rem:
                new_state.neg.append(positive)
            else:
                new_state.pos.append(positive)
        for negative in old_state.neg:
            if negative in action.effect_add:
                new_state.pos.append(negative)
            else:
                new_state.neg.append(negative)
        return encode_state(new_state, self.state_map)
Esempio n. 19
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
        """

        temp_pos = decode_state(state, self.state_map).pos
        temp_neg = decode_state(state, self.state_map).neg

        # remove negative literals and add positive literals
        for add_val in action.effect_add:
            temp_pos.append(add_val)
            temp_neg.remove(add_val)

        for rem_val in action.effect_rem:
            temp_pos.remove(rem_val)
            temp_neg.append(rem_val)

        return encode_state(FluentState(temp_pos, temp_neg), 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 = decode_state(state, self.state_map)

        for eff in action.effect_add:
            if eff in new_state.neg:
                new_state.neg.remove(eff)
                new_state.pos.append(eff)

        for eff in action.effect_rem:
            if eff in new_state.pos:
                new_state.pos.remove(eff)
                new_state.neg.append(eff)

        return encode_state(new_state, self.state_map)
Esempio n. 21
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).

        Checks for fluents that are positive in the old stat and
        are not in the remove list of the actions. Later checks
        for negative fluents in the old state that not present in the
        effect_add list of the action

        Finally check for add effects of the action that are not in the
        restul, end the rem effects that

        :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)

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

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

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

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

        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([], [])
        old_state = decode_state(state, self.state_map)

        # Add not exisiting positive state and remove exsiting negative state
        for fluent in old_state.pos:
            if fluent not in new_state.pos:
                new_state.pos.append(fluent)
            if fluent in new_state.neg:
                new_state.neg.remove(fluent)
        for fluent in old_state.neg:
            if fluent in new_state.pos:
                new_state.pos.remove(fluent)
            if fluent not in new_state.neg:
                new_state.neg.append(fluent)

        for fluent in action.effect_add:
            if fluent not in new_state.pos:
                new_state.pos.append(fluent)
            if fluent in new_state.neg:
                new_state.neg.remove(fluent)
        for fluent in action.effect_rem:
            if fluent in new_state.pos:
                new_state.pos.remove(fluent)
            if fluent not in new_state.neg:
                new_state.neg.append(fluent)

        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
        # check whether the action is in the action list
        isValidAction = False
        for act in self.actions_list:
            if (action.name == act.name) and (action.args == act.args):
                isValidAction = True
                break

        if not isValidAction:
            raise ValueError("Invalid action!")

        newPos = []
        newNeg = []
        for i, char in enumerate(state):
            if char == 'T':
                newPos.append(self.state_map[i])
            else:
                newNeg.append(self.state_map[i])

        for add in action.effect_add:
            newPos.append(add)
            newNeg.remove(add)
        for rem in action.effect_rem:
            newPos.remove(rem)
            newNeg.append(rem)

        new_state = FluentState(newPos, newNeg)
        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
        """

        # Decode Bool string into its conditions
        fState = decode_state(state, self.state_map)
        # Create NewState with the same Conds. as the current
        #   - !copy(): decode_state() already creates new lists
        new_state = FluentState(fState.pos, fState.neg)

        # Loop:: iter=0: True Effects; iter=1: Not Effects
        for iter in range(2):
            # Using True Effects
            if iter == 0:
                actEft = action.effect_add  # True Effects
                stateEftAdd = new_state.pos  # Add New State Pos.
                stateEftRemove = new_state.neg  # Remove New State Neg.
            # Using Not Effects
            else:
                actEft = action.effect_rem  # Not Effects
                stateEftAdd = new_state.neg  # Add New State Neg.
                stateEftRemove = new_state.pos  # Remove New State Pos.
            # Loop by Effects of that Set
            for effect in actEft:
                stateEftAdd.append(
                    effect)  # NewState Add Effect to same Polar sign Set
                stateEftRemove.remove(
                    effect
                )  # NewState Remove Effect from opposite Polar sign Set
        # Encode into Bool String
        return encode_state(new_state, self.state_map)
Esempio n. 25
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([], [])
        current_state = decode_state(state, self.state_map)
        for pos in current_state.pos:
            if pos not in new_state.pos:
                new_state.pos.append(pos)
            if pos in new_state.neg:
                new_state.neg.remove(pos)

        for neg in current_state.neg:
            if neg in new_state.pos:
                new_state.pos.remove(neg)
            if neg not in new_state.neg:
                new_state.neg.append(neg)

        for add in action.effect_add:
            if add not in new_state.pos:
                new_state.pos.append(add)
            if add in new_state.neg:
                new_state.neg.remove(add)

        for rem in action.effect_rem:
            if rem in new_state.pos:
                new_state.pos.remove(rem)
            if rem not in new_state.neg:
                new_state.neg.append(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)
        #In the new state after action is done on old state
        #the positive fluents in old state will be added to new state as
        #it is if those fluents are not to be removed by negative effects of action.
        # Thus we do..
        for fluent in old_state.pos:
            if fluent not in action.effect_rem:
                new_state.pos.append(fluent)
        #also add "new" fluents to the new state which
        #are present in add effect of the action
        for fluent in action.effect_add:
            if fluent not in new_state.pos:
                new_state.pos.append(fluent)
        #in the new state, the negative fluents in old state
        #will be added to new state's negative fluents if those fluents
        #are not present in positive effect of action. Thus..
        for fluent in old_state.neg:
            if fluent not in action.effect_add:
                new_state.neg.append(fluent)
        #in new state, the negative fluents will be added as
        #it is from negative action fluents if these fluents
        #are not already present in negative fluents list...
        for fluent in action.effect_rem:
            if fluent not in new_state.neg:
                new_state.neg.append(fluent)
        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
        useless = decode_state(state, self.state_map)
        pos = useless.pos
        neg = useless.neg

        for pc in action.effect_add:
           pos.append(pc)
           if pc in neg:
              neg.remove(pc)
        for pc in action.effect_rem:
           neg.append(pc)
           pos.remove(pc)

        new_state = FluentState(pos, neg)
        return encode_state(new_state, self.state_map)
Esempio n. 28
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
        """
        # define the resulting state
        resulting_state = FluentState([], [])

        # the previous state
        p_state = decode_state(state, self.state_map)
        for fluent in p_state.pos:
            if fluent not in action.effect_rem:
                # each positive fluent not removed by my action, stays in the resulting state
                resulting_state.pos.append(fluent)

        for fluent in action.effect_add:
            if fluent not in resulting_state.pos:
                # each effect added by my action that is not in the resulting state yet, has to be added
                resulting_state.pos.append(fluent)

        for fluent in p_state.neg:
            if fluent not in action.effect_add:
                # every negative fluent that was not affected by my action is still applied to the resulting state
                resulting_state.neg.append(fluent)

        for fluent in action.effect_rem:
            if fluent not in resulting_state.neg:
                # every negative effect my action will have has to be added to my resulting state,
                # if is not already there
                resulting_state.neg.append(fluent)

        return encode_state(resulting_state, self.state_map)
Esempio n. 29
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([], [])
        for possible_action in (possible_action
                                for possible_action in self.actions(state)
                                if (action.name == possible_action.name
                                    and action.args == possible_action.args)):
            pos_state = decode_state(state, self.state_map).pos
            neg_state = decode_state(state, self.state_map).neg
            for new_state_pos in action.effect_add:
                pos_state.append(new_state_pos)
                neg_state.remove(new_state_pos)
            for new_state_neg in action.effect_rem:
                pos_state.remove(new_state_neg)
                neg_state.append(new_state_neg)
            new_state = FluentState(pos_state, neg_state)
        return encode_state(new_state, self.state_map)
Esempio n. 30
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
        """
        #Initialize new instance of FluentState
        new_state = FluentState([], [])

        #Read entering state
        old_state = decode_state(state, self.state_map)

        #Check if positive fluents in the entering state have been affected
        for fluent in old_state.pos:
            if fluent not in action.effect_rem:
                new_state.pos.append(fluent)

        #Add new positive fluents from the action's effects
        for fluent in action.effect_add:
            if fluent not in new_state.pos:
                new_state.pos.append(fluent)

        #Check if there are negative fluents in old state not affected by action
        for fluent in old_state.neg:
            if fluent not in action.effect_add:
                new_state.neg.append(fluent)

        #Add to negative fluents those removed by action's effects
        for fluent in action.effect_rem:
            if fluent not in new_state.neg:
                new_state.neg.append(fluent)

        return encode_state(new_state, self.state_map)
Esempio n. 31
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        def fly_actions():
        :return: resulting state after action
        """
        new_state = FluentState([], [])
        old_state = decode_state(state, self.state_map)
        for fluent in old_state.pos:
            if fluent not in action.effect_rem:
                new_state.pos.append(fluent)
        for fluent in action.effect_add:
            if fluent not in new_state.pos:
                new_state.pos.append(fluent)
        for fluent in old_state.neg:
            if fluent not in action.effect_add:
                new_state.neg.append(fluent)
        for fluent in action.effect_rem:
            if fluent not in new_state.neg:
                new_state.neg.append(fluent)
        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([], []) ## Initialize new state
        old_state = decode_state(state, self.state_map) ## Extract the old state
        for fluent in old_state.pos:
            if fluent not in action.effect_rem:
                new_state.pos.append(fluent)    ## Append +ve fluents from old state that don't require removal
        for fluent in action.effect_add:
            if fluent not in new_state.pos:
                new_state.pos.append(fluent)    ## Append +ve fluents from old state that require addition
        for fluent in old_state.neg:
            if fluent not in action.effect_add:
                new_state.neg.append(fluent)    ## Refer to comments above but with -ve fluents
        for fluent in action.effect_rem:
            if fluent not in new_state.neg:
                new_state.neg.append(fluent)    ## Refer to comments above but with -ve fluents
        return encode_state(new_state, self.state_map)  ## Encode the new state
Esempio n. 33
0
    def __init__(self, cargos, planes, airports, initial: FluentState, goal: list):
        """

        :param cargos: list of str
            cargos in the problem
        :param planes: list of str
            planes in the problem
        :param airports: list of str
            airports in the problem
        :param initial: FluentState object
            positive and negative literal fluents (as expr) describing initial state
        :param goal: list of expr
            literal fluents required for goal test
        """

        self.state_map = initial.pos + initial.neg
        self.initial_state_TF = encode_state(initial, self.state_map)
        print('Now in AirCargoProblem initiation...',self.state_map, self.initial_state_TF,goal,'preparing to call problem.__init__')
        Problem.__init__(self, self.initial_state_TF, goal=goal)
        self.cargos = cargos
        print('Back in AirCargoProblem()........cargos,planes and airports..',cargos,planes,airports)
        self.planes = planes
        self.airports = airports
        self.actions_list = self.get_actions() #CALL MY ROUTINES TO BUILD LIST OF ACTIONS
Esempio n. 34
0
    def __init__(self, cargos, planes, airports, initial: FluentState,
                 goal: list):
        """

        :param cargos: list of str
            cargos in the problem
        :param planes: list of str
            planes in the problem
        :param airports: list of str
            airports in the problem
        :param initial: FluentState object
            positive and negative literal fluents (as expr) describing initial state
        :param goal: list of expr
            literal fluents required for goal test
        """
        self.state_map = initial.pos + initial.neg  #state_map is list of [expr(..),..]
        self.initial_state_TF = encode_state(initial,
                                             self.state_map)  #TFTFFFTT
        Problem.__init__(self, self.initial_state_TF,
                         goal=goal)  #not understand
        self.cargos = cargos  #['C1', 'C2']
        self.planes = planes  #['P1', 'P2']
        self.airports = airports  #['JFK', 'SFO']
        self.actions_list = self.get_actions()
Esempio n. 35
0
 def __init__(self, initial: FluentState, goal: list):
     self.state_map = initial.pos + initial.neg
     Problem.__init__(self, encode_state(initial, self.state_map), goal=goal)
     self.actions_list = self.get_actions()