コード例 #1
0
class PlanGraphLevel(object):
  """
  A class for representing a level in the plan graph.
  For each level i, the PlanGraphLevel consists of the actionLayer and propositionLayer at this level in this order!
  """
  independentActions = []  # updated to the independentActions of the propblem GraphPlan.py line 31 
  actions = []             # updated to the actions of the problem GraphPlan.py line 32 and planningProblem.py line 25
  props = []               # updated to the propositions of the problem GraphPlan.py line 33 and planningProblem.py line 26
  
  @staticmethod
  def setIndependentActions(independentActions):
    PlanGraphLevel.independentActions = independentActions
  
  @staticmethod  
  def setActions(actions):
    PlanGraphLevel.actions = actions
  
  @staticmethod    
  def setProps(props):
    PlanGraphLevel.props = props   
  
  def __init__(self):
    """
    Constructor
    """
    self.actionLayer = ActionLayer()    		    # see actionLayer.py
    self.propositionLayer = PropositionLayer()	# see propositionLayer.py
  
  def getPropositionLayer(self):
  # returns the proposition layer
    return self.propositionLayer
  
  def setPropositionLayer(self, propLayer):
  # sets the proposition layer
    self.propositionLayer = propLayer  
  
  def getActionLayer(self):
  # returns the action layer
    return self.actionLayer
    
  def setActionLayer(self, actionLayer):
  # sets the action layer
    self.actionLayer = actionLayer

  def updateActionLayer(self, previousPropositionLayer):
    """ 
    Updates the action layer given the previous proposition layer (see propositionLayer.py)
    You should add an action to the layer if its preconditions are in the previous propositions layer,
    and the preconditions are not pairwise mutex. 
    allAction is the list of all the action (include noOp) in the domain
    You might want to use those functions:
    previousPropositionLayer.isMutex(prop1, prop2) returns true if prop1 and prop2 are mutex at the previous propositions layer
    previousPropositionLayer.allPrecondsInLayer(action) returns true if all the preconditions of action are in the previous propositions layer
    self.actionLayer.addAction(action) adds action to the current action layer
    """ 
    allActions = PlanGraphLevel.actions
    "*** YOUR CODE HERE ***"
    for action in allActions:
      #check the preconditions
      if previousPropositionLayer.allPrecondsInLayer(action):
        actionPropositions = action.getPre()
        #check the mutex
        isNotMutex = True
        for prop1 in actionPropositions:
          for prop2 in actionPropositions:
            if not prop1 == prop2:
              if previousPropositionLayer.isMutex(prop1, prop2):
                isNotMutex = False
        if isNotMutex:
          self.actionLayer.addAction(action)


    
  def updateMutexActions(self, previousLayerMutexProposition):
    """
    Updates the mutex list in self.actionLayer,
    given the mutex proposition from the previous layer.
    currentLayerActions are the actions in the current action layer
    You might want to use this function:
    self.actionLayer.addMutexActions(action1, action2)
    adds the pair (action1, action2) to the mutex list in the current action layer
    Note that action is *not* mutex with itself
    """
    currentLayerActions = self.actionLayer.getActions()
    "*** YOUR CODE HERE ***"
    for action1 in currentLayerActions:
      for action2 in currentLayerActions:
        if (not action1 == action2) and\
            (Pair(action1,action2) not in self.actionLayer.getMutexActions()):
          if mutexActions(action1, action2, previousLayerMutexProposition):
            self.actionLayer.addMutexActions(action1, action2)
    
  def updatePropositionLayer(self):
    """
    Updates the propositions in the current proposition layer,
    given the current action layer.
    don't forget to update the producers list!
    Note that same proposition in different layers might have different producers lists,
    hence you should create two different instances.
    currentLayerActions is the list of all the actions in the current layer.
    You might want to use those functions:
    dict() creates a new dictionary that might help to keep track on the propositions that you've
           already added to the layer
    self.propositionLayer.addProposition(prop) adds the proposition prop to the current layer       
    
    """
    currentLayerActions = self.actionLayer.getActions()
    "*** YOUR CODE HERE ***"
    # create dictionary with proposition and actions
    # leading to it
    propositionDict = dict()
    for action in currentLayerActions:
      for prop in action.getAdd():
        if prop.getName() in propositionDict.keys():
          propositionDict[prop.getName()].append(action)
        else:
          actionList = list()
          actionList.append(action)
          propositionDict.update({prop.getName(): actionList})

    #create proposition object and update their actions
    for key in propositionDict.keys():
      p = Proposition(key)
      p.setProducers(propositionDict[key])
      self.propositionLayer.addProposition(p)

    
  def updateMutexProposition(self):
    """
    updates the mutex propositions in the current proposition layer
    You might want to use those functions:
    mutexPropositions(prop1, prop2, currentLayerMutexActions) returns true if prop1 and prop2 are mutex in the current layer
    self.propositionLayer.addMutexProp(prop1, prop2) adds the pair (prop1, prop2) to the mutex list of the current layer
    """
    currentLayerPropositions = self.propositionLayer.getPropositions()
    currentLayerMutexActions =  self.actionLayer.getMutexActions()
    "*** YOUR CODE HERE ***"
    for prop1 in currentLayerPropositions:
      for prop2 in currentLayerPropositions:
        if not prop1 == prop2 and \
            (Pair(prop1, prop2) not in self.propositionLayer.getMutexProps()):
          if mutexPropositions(prop1, prop2, currentLayerMutexActions):
            self.propositionLayer.addMutexProp(prop1, prop2)

    
  def expand(self, previousLayer):
    """
    Your algorithm should work as follows:
    First, given the propositions and the list of mutex propositions from the previous layer,
    set the actions in the action layer. 
    Then, set the mutex action in the action layer.
    Finally, given all the actions in the current layer,
    set the propositions and their mutex relations in the proposition layer.   
    """
    previousPropositionLayer = previousLayer.getPropositionLayer()
    previousLayerMutexProposition = previousPropositionLayer.getMutexProps()

    "*** YOUR CODE HERE ***"
    self.updateActionLayer(previousPropositionLayer)
    self.updateMutexActions(previousLayerMutexProposition)
    self.updatePropositionLayer()
    self.updateMutexProposition()



  def expandWithoutMutex(self, previousLayer):
    """
    Questions 11 and 12
    You don't have to use this function
    """
    previousLayerProposition = previousLayer.getPropositionLayer()
    "*** YOUR CODE HERE ***"
    self.updateActionLayer(previousLayerProposition)
    self.updatePropositionLayer()
コード例 #2
0
ファイル: planGraphLevel.py プロジェクト: belostoky/iAI
class PlanGraphLevel(object):
    """
    A class for representing a level in the plan graph.
    For each level i, the PlanGraphLevel consists of the actionLayer and propositionLayer at this level in this order!
    """
    independentActions = []  # updated to the independentActions of the propblem GraphPlan.py line 31
    actions = []  # updated to the actions of the problem GraphPlan.py line 32 and planningProblem.py line 25
    props = []  # updated to the propositions of the problem GraphPlan.py line 33 and planningProblem.py line 26

    @staticmethod
    def setIndependentActions(independentActions):
        PlanGraphLevel.independentActions = independentActions

    @staticmethod
    def setActions(actions):
        PlanGraphLevel.actions = actions

    @staticmethod
    def setProps(props):
        PlanGraphLevel.props = props

    def __init__(self):
        """
        Constructor
        """
        self.actionLayer = ActionLayer()  # see actionLayer.py
        self.propositionLayer = PropositionLayer()  # see propositionLayer.py

    def getPropositionLayer(self):
        # returns the proposition layer
        return self.propositionLayer

    def setPropositionLayer(self, propLayer):
        # sets the proposition layer
        self.propositionLayer = propLayer

    def getActionLayer(self):
        # returns the action layer
        return self.actionLayer

    def setActionLayer(self, actionLayer):
        # sets the action layer
        self.actionLayer = actionLayer

    def updateActionLayer(self, previousPropositionLayer):
        """
        Updates the action layer given the previous proposition layer (see propositionLayer.py)
        You should add an action to the layer if its preconditions are in the previous propositions layer,
        and the preconditions are not pairwise mutex.
        allAction is the list of all the action (include noOp) in the domain
        You might want to use those functions:
        previousPropositionLayer.isMutex(prop1, prop2) returns true if prop1 and prop2 are mutex at the previous propositions layer
        previousPropositionLayer.allPrecondsInLayer(action) returns true if all the preconditions of action are in the previous propositions layer
        self.actionLayer.addAction(action) adds action to the current action layer
        """
        allActions = PlanGraphLevel.actions

        for action in allActions:
            if previousPropositionLayer.allPrecondsInLayer(action) and\
                    not pre_contains_pairwise_mutex(action, previousPropositionLayer):
                self.actionLayer.addAction(action)

    def updateMutexActions(self, previousLayerMutexProposition):
        """
        Updates the mutex list in self.actionLayer,
        given the mutex proposition from the previous layer.
        currentLayerActions are the actions in the current action layer
        You might want to use this function:
        self.actionLayer.addMutexActions(action1, action2)
        adds the pair (action1, action2) to the mutex list in the current action layer
        Note that action is *not* mutex with itself
        """
        currentLayerActions = self.actionLayer.getActions()

        for action1 in currentLayerActions:
                for action2 in currentLayerActions:
                    if action1 != action2 and\
                            mutexActions(action1, action2, previousLayerMutexProposition):
                        self.actionLayer.addMutexActions(action1, action2)



    def updatePropositionLayer(self):
        """
        Updates the propositions in the current proposition layer,
        given the current action layer.
        don't forget to update the producers list!
        Note that same proposition in different layers might have different producers lists,
        hence you should create two different instances.
        currentLayerActions is the list of all the actions in the current layer.
        You might want to use those functions:
        dict() creates a new dictionary that might help to keep track on the propositions that you've
               already added to the layer
        self.propositionLayer.addProposition(prop) adds the proposition prop to the current layer

        """
        currentLayerActions = self.actionLayer.getActions()
        props_dict = dict()
        for action in currentLayerActions:
            for add_props in action.getAdd():
                if add_props.getName() not in props_dict:
                    props_dict[add_props.getName()] = [action]
                else:
                    props_dict[add_props.getName()] = \
                        props_dict[add_props.getName()]+[action]

        for key in props_dict:
            prop_temp = Proposition(key)
            prop_temp.setProducers(props_dict[key])    #takes care of adding procedure
            self.propositionLayer.addProposition(prop_temp)
        #notice there is no mention of mutexes. is this ok?


    def updateMutexProposition(self):
        """
        updates the mutex propositions in the current proposition layer
        You might want to use those functions:
        mutexPropositions(prop1, prop2, currentLayerMutexActions) returns true if prop1 and prop2 are mutex in the current layer
        self.propositionLayer.addMutexProp(prop1, prop2) adds the pair (prop1, prop2) to the mutex list of the current layer
        """
        currentLayerPropositions = self.propositionLayer.getPropositions()
        currentLayerMutexActions = self.actionLayer.getMutexActions()
        for prop1 in currentLayerPropositions:
            for prop2 in currentLayerPropositions:
                if mutexPropositions(prop1, prop2, currentLayerMutexActions) \
                        and prop1 != prop2:
                    self.propositionLayer.addMutexProp(prop1, prop2)



    def expand(self, previousLayer):
        """
        Your algorithm should work as follows:
        First, given the propositions and the list of mutex propositions from the previous layer,
        set the actions in the action layer.
        Then, set the mutex action in the action layer.
        Finally, given all the actions in the current layer,
        set the propositions and their mutex relations in the proposition layer.
        """
        previousPropositionLayer = previousLayer.getPropositionLayer()
        previousLayerMutexProposition = previousPropositionLayer.getMutexProps()

        self.updateActionLayer(previousPropositionLayer)
        self.updateMutexActions(previousLayerMutexProposition)

        self.updatePropositionLayer()
        self.updateMutexProposition()

    def expandWithoutMutex(self, previousLayer):
        """
        Questions 11 and 12
        You don't have to use this function
        """

        previousPropositionLayer = previousLayer.getPropositionLayer()

        self.updateActionLayer(previousPropositionLayer)

        self.updatePropositionLayer()
コード例 #3
0
ファイル: planGraphLevel.py プロジェクト: odedm/ai
class PlanGraphLevel(object):
    """
    A class for representing a level in the plan graph.
    For each level i, the PlanGraphLevel consists of the actionLayer and propositionLayer at this level in this order!
    """
    independentActions = [
    ]  # updated to the independentActions of the propblem GraphPlan.py line 31
    actions = [
    ]  # updated to the actions of the problem GraphPlan.py line 32 and planningProblem.py line 25
    props = [
    ]  # updated to the propositions of the problem GraphPlan.py line 33 and planningProblem.py line 26

    @staticmethod
    def setIndependentActions(independentActions):
        PlanGraphLevel.independentActions = independentActions

    @staticmethod
    def setActions(actions):
        PlanGraphLevel.actions = actions

    @staticmethod
    def setProps(props):
        PlanGraphLevel.props = props

    def __init__(self):
        """
        Constructor
        """
        self.actionLayer = ActionLayer()  # see actionLayer.py
        self.propositionLayer = PropositionLayer()  # see propositionLayer.py

    def getPropositionLayer(self):
        # returns the proposition layer
        return self.propositionLayer

    def setPropositionLayer(self, propLayer):
        # sets the proposition layer
        self.propositionLayer = propLayer

    def getActionLayer(self):
        # returns the action layer
        return self.actionLayer

    def setActionLayer(self, actionLayer):
        # sets the action layer
        self.actionLayer = actionLayer

    def updateActionLayer(self, previousPropositionLayer):
        """
        Updates the action layer given the previous proposition layer (see propositionLayer.py)
        You should add an action to the layer if its preconditions are in the previous propositions layer,
        and the preconditions are not pairwise mutex.
        allAction is the list of all the action (include noOp) in the domain
        You might want to use those functions:
        previousPropositionLayer.isMutex(prop1, prop2) returns true if prop1 and prop2 are mutex at the previous propositions layer
        previousPropositionLayer.allPrecondsInLayer(action) returns true if all the preconditions of action are in the previous propositions layer
        self.actionLayer.addAction(action) adds action to the current action layer
        """
        allActions = PlanGraphLevel.actions
        for action in allActions:
            if previousPropositionLayer.allPrecondsInLayer(action) \
                and True not in [previousPropositionLayer.isMutex(p1, p2) for p1, p2 in exclusiveProduct(action.getPre(), action.getPre())]:
                self.actionLayer.addAction(action)

    def updateMutexActions(self, previousLayerMutexProposition):
        """
        Updates the mutex list in self.actionLayer,
        given the mutex proposition from the previous layer.
        currentLayerActions are the actions in the current action layer
        You might want to use this function:
        self.actionLayer.addMutexActions(action1, action2)
        adds the pair (action1, action2) to the mutex list in the current action layer
        Note that action is *not* mutex with itself
        """
        currentLayerActions = self.actionLayer.getActions()
        actionPairs = exclusiveProduct(currentLayerActions,
                                       currentLayerActions)
        for a1, a2 in actionPairs:
            if mutexActions(a1, a2, previousLayerMutexProposition):
                self.actionLayer.addMutexActions(a1, a2)

    def updatePropositionLayer(self):
        """
        Updates the propositions in the current proposition layer,
        given the current action layer.
        don't forget to update the producers list!
        Note that same proposition in different layers might have different producers lists,
        hence you should create two different instances.
        currentLayerActions is the list of all the actions in the current layer.
        You might want to use those functions:
        dict() creates a new dictionary that might help to keep track on the propositions that you've
               already added to the layer
        self.propositionLayer.addProposition(prop) adds the proposition prop to the current layer
        """

        currentLayerActions = self.actionLayer.getActions()
        props = dict()

        for a in currentLayerActions:
            for prop in a.getAdd():
                name = prop.getName()
                if name not in props.keys():
                    props[name] = Proposition(name)
                props[name].addProducer(a)

        for prop in props.values():
            self.propositionLayer.addProposition(prop)

    def updateMutexProposition(self):
        """
        updates the mutex propositions in the current proposition layer
        You might want to use those functions:
        mutexPropositions(prop1, prop2, currentLayerMutexActions) returns true if prop1 and prop2 are mutex in the current layer
        self.propositionLayer.addMutexProp(prop1, prop2) adds the pair (prop1, prop2) to the mutex list of the current layer
        """
        currentLayerPropositions = self.propositionLayer.getPropositions()
        currentLayerMutexActions = self.actionLayer.getMutexActions()
        for p1, p2 in exclusiveProduct(currentLayerPropositions,
                                       currentLayerPropositions):
            if mutexPropositions(p1, p2, currentLayerMutexActions):
                self.propositionLayer.addMutexProp(p1, p2)

    def expand(self, previousLayer):
        """
        Your algorithm should work as follows:
        First, given the propositions and the list of mutex propositions from the previous layer,
        set the actions in the action layer.
        Then, set the mutex action in the action layer.
        Finally, given all the actions in the current layer,
        set the propositions and their mutex relations in the proposition layer.
        """
        previousPropositionLayer = previousLayer.getPropositionLayer()
        previousLayerMutexProposition = previousPropositionLayer.getMutexProps(
        )
        self.updateActionLayer(previousPropositionLayer)
        self.updateMutexActions(previousLayerMutexProposition)
        self.updatePropositionLayer()
        self.updateMutexProposition()

    def expandWithoutMutex(self, previousLayer):
        """
        Expand the graph without updating the mutex relations
        """
        previousPropositionLayer = previousLayer.getPropositionLayer()
        self.updateActionLayer(previousPropositionLayer)
        self.updatePropositionLayer()
コード例 #4
0
class PlanGraphLevel(object):
    """
  A class for representing a level in the plan graph.
  For each level i, the PlanGraphLevel consists of the actionLayer and propositionLayer at this level in this order!
  """
    independentActions = [
    ]  # updated to the independentActions of the propblem GraphPlan.py line 31
    actions = [
    ]  # updated to the actions of the problem GraphPlan.py line 32 and planningProblem.py line 25
    props = [
    ]  # updated to the propositions of the problem GraphPlan.py line 33 and planningProblem.py line 26

    @staticmethod
    def setIndependentActions(independentActions):
        PlanGraphLevel.independentActions = independentActions

    @staticmethod
    def setActions(actions):
        PlanGraphLevel.actions = actions

    @staticmethod
    def setProps(props):
        PlanGraphLevel.props = props

    def __init__(self):
        """
    Constructor
    """
        self.actionLayer = ActionLayer()  # see actionLayer.py
        self.propositionLayer = PropositionLayer()  # see propositionLayer.py

    def getPropositionLayer(self):
        # returns the proposition layer
        return self.propositionLayer

    def setPropositionLayer(self, propLayer):
        # sets the proposition layer
        self.propositionLayer = propLayer

    def getActionLayer(self):
        # returns the action layer
        return self.actionLayer

    def setActionLayer(self, actionLayer):
        # sets the action layer
        self.actionLayer = actionLayer

    def updateActionLayer(self, previousPropositionLayer):
        """ 
    Updates the action layer given the previous proposition layer (see propositionLayer.py)
    You should add an action to the layer if its preconditions are in the previous propositions layer,
    and the preconditions are not pairwise mutex. 
    allAction is the list of all the action (include noOp) in the domain
    You might want to use those functions:
    previousPropositionLayer.isMutex(prop1, prop2) returns true if prop1 and prop2 are mutex at the previous propositions layer
    previousPropositionLayer.allPrecondsInLayer(action) returns true if all the preconditions of action are in the previous propositions layer
    self.actionLayer.addAction(action) adds action to the current action layer
    """
        allActions = PlanGraphLevel.actions
        for action in allActions:
            if previousPropositionLayer.allPrecondsInLayer(
                    action) and action not in self.actionLayer.getActions():
                self.actionLayer.addAction(action)

    def updateMutexActions(self, previousLayerMutexProposition):
        """
    Updates the mutex list in self.actionLayer,
    given the mutex proposition from the previous layer.
    currentLayerActions are the actions in the current action layer
    You might want to use this function:
    self.actionLayer.addMutexActions(action1, action2)
    adds the pair (action1, action2) to the mutex list in the current action layer
    Note that action is *not* mutex with itself
    """
        currentLayerActions = self.actionLayer.getActions()
        for a1 in currentLayerActions:
            for a2 in currentLayerActions:
                if a1 == a2:
                    continue  # an action is not mutex with itself

                if Pair(a1, a2) not in self.actionLayer.getMutexActions(
                ) and mutexActions(a1, a2, previousLayerMutexProposition):
                    # if a1 and a2 are mutex actions, and we didn't add them before, we should do so now
                    self.actionLayer.addMutexActions(a1, a2)

    def updatePropositionLayer(self):
        """
    Updates the propositions in the current proposition layer,
    given the current action layer.
    don't forget to update the producers list!
    Note that same proposition in different layers might have different producers lists,
    hence you should create two different instances.
    currentLayerActions is the list of all the actions in the current layer.
    You might want to use those functions:
    dict() creates a new dictionary that might help to keep track on the propositions that you've
           already added to the layer
    self.propositionLayer.addProposition(prop) adds the proposition prop to the current layer       
    
    """
        currentLayerActions = self.actionLayer.getActions()
        for action in currentLayerActions:
            for p in action.getAdd():
                # add the proposition if it doesn't already exist
                if p not in self.propositionLayer.getPropositions():
                    self.propositionLayer.addProposition(p)

                # add the action as a producer if it doesn't already exist
                if action not in p.getProducers():
                    p.addProducer(action)

    def updateMutexProposition(self):
        """
    updates the mutex propositions in the current proposition layer
    You might want to use those functions:
    mutexPropositions(prop1, prop2, currentLayerMutexActions) returns true if prop1 and prop2 are mutex in the current layer
    self.propositionLayer.addMutexProp(prop1, prop2) adds the pair (prop1, prop2) to the mutex list of the current layer
    """
        currentLayerPropositions = self.propositionLayer.getPropositions()
        currentLayerMutexActions = self.actionLayer.getMutexActions()
        for p in currentLayerPropositions:
            for q in currentLayerPropositions:
                if p == q:
                    continue  # a proposition is not mutex with itself

                if Pair(p, q) not in self.propositionLayer.getMutexProps(
                ) and mutexPropositions(p, q, currentLayerMutexActions):
                    # if p and q are mutex props, and we didn't add them before, we should do so now
                    self.propositionLayer.addMutexProp(p, q)

    def expand(self, previousLayer):
        """
    Your algorithm should work as follows:
    First, given the propositions and the list of mutex propositions from the previous layer,
    set the actions in the action layer. 
    Then, set the mutex action in the action layer.
    Finally, given all the actions in the current layer,
    set the propositions and their mutex relations in the proposition layer.   
    """
        previousPropositionLayer = previousLayer.getPropositionLayer()
        previousLayerMutexProposition = previousPropositionLayer.getMutexProps(
        )

        self.updateActionLayer(previousPropositionLayer)
        self.updateMutexActions(previousLayerMutexProposition)
        self.updatePropositionLayer()
        self.updateMutexProposition()

    def expandWithoutMutex(self, previousLayer):
        """
    Questions 11 and 12
    You don't have to use this function
    """
        previousLayerProposition = previousLayer.getPropositionLayer()
        self.updateActionLayer(previousLayerProposition)
        self.updatePropositionLayer()
コード例 #5
0
ファイル: planGraphLevel.py プロジェクト: orensam/ai
class PlanGraphLevel(object):
    """
    A class for representing a level in the plan graph.
    For each level i, the PlanGraphLevel consists of the actionLayer and propositionLayer at this level in this order!
    """
    independentActions = []  # updated to the independentActions of the propblem GraphPlan.py line 31
    actions = []             # updated to the actions of the problem GraphPlan.py line 32 and planningProblem.py line 25
    props = []               # updated to the propositions of the problem GraphPlan.py line 33 and planningProblem.py line 26

    @staticmethod
    def setIndependentActions(independentActions):
        PlanGraphLevel.independentActions = independentActions

    @staticmethod
    def setActions(actions):
        PlanGraphLevel.actions = actions

    @staticmethod
    def setProps(props):
        PlanGraphLevel.props = props

    def __init__(self):
        """
        Constructor
        """
        self.actionLayer = ActionLayer()                        # see actionLayer.py
        self.propositionLayer = PropositionLayer()  # see propositionLayer.py

    def getPropositionLayer(self):
    # returns the proposition layer
        return self.propositionLayer

    def setPropositionLayer(self, propLayer):
    # sets the proposition layer
        self.propositionLayer = propLayer

    def getActionLayer(self):
    # returns the action layer
        return self.actionLayer

    def setActionLayer(self, actionLayer):
    # sets the action layer
        self.actionLayer = actionLayer

    def updateActionLayer(self, previousPropositionLayer):
        """
        Updates the action layer given the previous proposition layer (see propositionLayer.py)
        You should add an action to the layer if its preconditions are in the previous propositions layer,
        and the preconditions are not pairwise mutex.
        allAction is the list of all the action (include noOp) in the domain
        You might want to use those functions:
        previousPropositionLayer.isMutex(prop1, prop2) returns true if prop1 and prop2 are mutex at the previous propositions layer
        previousPropositionLayer.allPrecondsInLayer(action) returns true if all the preconditions of action are in the previous propositions layer
        self.actionLayer.addAction(action) adds action to the current action layer
        """
        allActions = PlanGraphLevel.actions        
        for action in allActions:
            if previousPropositionLayer.allPrecondsInLayer(action) \
                and True not in [previousPropositionLayer.isMutex(p1, p2) for p1, p2 in exclusiveProduct(action.getPre(), action.getPre())]:
                self.actionLayer.addAction(action)
            
    def updateMutexActions(self, previousLayerMutexProposition):
        """
        Updates the mutex list in self.actionLayer,
        given the mutex proposition from the previous layer.
        currentLayerActions are the actions in the current action layer
        You might want to use this function:
        self.actionLayer.addMutexActions(action1, action2)
        adds the pair (action1, action2) to the mutex list in the current action layer
        Note that action is *not* mutex with itself
        """
        currentLayerActions = self.actionLayer.getActions()        
        actionPairs = exclusiveProduct(currentLayerActions, currentLayerActions)
        for a1, a2 in actionPairs:
            if mutexActions(a1, a2, previousLayerMutexProposition):
                self.actionLayer.addMutexActions(a1, a2)
        
    def updatePropositionLayer(self):
        """
        Updates the propositions in the current proposition layer,
        given the current action layer.
        don't forget to update the producers list!
        Note that same proposition in different layers might have different producers lists,
        hence you should create two different instances.
        currentLayerActions is the list of all the actions in the current layer.
        You might want to use those functions:
        dict() creates a new dictionary that might help to keep track on the propositions that you've
               already added to the layer
        self.propositionLayer.addProposition(prop) adds the proposition prop to the current layer
        """
        
        currentLayerActions = self.actionLayer.getActions()
        props = dict()
                        
        for a in currentLayerActions:
            for prop in a.getAdd():
                name = prop.getName()
                if name not in props.keys():
                    props[name] = Proposition(name)
                props[name].addProducer(a)
        
        for prop in props.values():
            self.propositionLayer.addProposition(prop)

    def updateMutexProposition(self):
        """
        updates the mutex propositions in the current proposition layer
        You might want to use those functions:
        mutexPropositions(prop1, prop2, currentLayerMutexActions) returns true if prop1 and prop2 are mutex in the current layer
        self.propositionLayer.addMutexProp(prop1, prop2) adds the pair (prop1, prop2) to the mutex list of the current layer
        """
        currentLayerPropositions = self.propositionLayer.getPropositions()
        currentLayerMutexActions = self.actionLayer.getMutexActions()
        for p1, p2 in exclusiveProduct(currentLayerPropositions, currentLayerPropositions):
            if mutexPropositions(p1, p2, currentLayerMutexActions):
                self.propositionLayer.addMutexProp(p1, p2)

    def expand(self, previousLayer):
        """
        Your algorithm should work as follows:
        First, given the propositions and the list of mutex propositions from the previous layer,
        set the actions in the action layer.
        Then, set the mutex action in the action layer.
        Finally, given all the actions in the current layer,
        set the propositions and their mutex relations in the proposition layer.
        """
        previousPropositionLayer = previousLayer.getPropositionLayer()
        previousLayerMutexProposition = previousPropositionLayer.getMutexProps()
        self.updateActionLayer(previousPropositionLayer)
        self.updateMutexActions(previousLayerMutexProposition)
        self.updatePropositionLayer()
        self.updateMutexProposition()

    def expandWithoutMutex(self, previousLayer):
        """
        Expand the graph without updating the mutex relations
        """
        previousPropositionLayer = previousLayer.getPropositionLayer()
        self.updateActionLayer(previousPropositionLayer)
        self.updatePropositionLayer()
コード例 #6
0
class PlanGraphLevel(object):
  """
  A class for representing a level in the plan graph.
  For each level i, the PlanGraphLevel consists of the actionLayer and propositionLayer at this level in this order!
  """
  independentActions = []  # updated to the independentActions of the propblem GraphPlan.py line 31
  actions = []             # updated to the actions of the problem GraphPlan.py line 32 and planningProblem.py line 25
  props = []               # updated to the propositions of the problem GraphPlan.py line 33 and planningProblem.py line 26

  @staticmethod
  def setIndependentActions(independentActions):
    PlanGraphLevel.independentActions = independentActions

  @staticmethod
  def setActions(actions):
    PlanGraphLevel.actions = actions

  @staticmethod
  def setProps(props):
    PlanGraphLevel.props = props

  def __init__(self):
    """
    Constructor
    """
    self.actionLayer = ActionLayer()    		# see actionLayer.py
    self.propositionLayer = PropositionLayer()	# see propositionLayer.py


  def getPropositionLayer(self):
    return self.propositionLayer

  def setPropositionLayer(self, propLayer):
    self.propositionLayer = propLayer

  def getActionLayer(self):
    return self.actionLayer

  def setActionLayer(self, actionLayer):
    self.actionLayer = actionLayer

  def updateActionLayer(self, previousPropositionLayer):
    """
    Updates the action layer given the previous proposition layer (see propositionLayer.py)
    allAction is the list of all the action (include noOp in the domain)
    """
    allActions = PlanGraphLevel.actions
    for action in allActions:
      if previousPropositionLayer.allPrecondsInLayer(action):
        self.actionLayer.addAction(action)
        for p1 in action.getPre():
          for p2 in action.getPre():
            if previousPropositionLayer.isMutex(p1, p2):
              self.actionLayer.removeActions(action)

  def updateMutexActions(self, previousLayerMutexProposition):
    """
    Updates the mutex list in self.actionLayer,
    given the mutex proposition from the previous layer.
    currentLayerActions are the actions in the current action layer
    """
    currentLayerActions = self.actionLayer.getActions()
    for a1 in currentLayerActions:
      for a2 in currentLayerActions:
        if a1 == a2:
          continue
        if mutexActions(a1, a2, previousLayerMutexProposition):
          self.actionLayer.addMutexActions(a1, a2)


  def updatePropositionLayer(self):
    """
    Updates the propositions in the current proposition layer,
    given the current action layer.
    don't forget to update the producers list!
    """
    currentLayerActions = self.actionLayer.getActions()
    propsToAdd = dict()
    for action in currentLayerActions:
      for prop in action.getAdd():
        if prop.getName() not in propsToAdd:
          propsToAdd[prop.getName()] = Proposition(prop.getName())
        temp = propsToAdd[prop.getName()]
        if action not in temp.getProducers():
          temp.addProducer(action)
    for prop in propsToAdd.values():
      self.propositionLayer.addProposition(prop)

  def updateMutexProposition(self):
    """
    updates the mutex propositions in the current proposition layer
    """
    currentLayerPropositions = self.propositionLayer.getPropositions()
    currentLayerMutexActions =  self.actionLayer.getMutexActions()
    for prop1 in currentLayerPropositions:
      for prop2 in currentLayerPropositions:
        if prop1 == prop2:
          continue
        if mutexPropositions(prop1, prop2, currentLayerMutexActions):
          self.propositionLayer.addMutexProp(prop1, prop2)


  def expand(self, previousLayer):
    """
    Your algorithm should work as follows:
    First, given the propositions and the list of mutex propositions from the previous layer,
    set the actions in the action layer.
    Then, set the mutex action in the action layer.
    Finally, given all the actions in the current layer, set the propositions and their mutex relations in the proposition layer.
    """
    previousPropositionLayer = previousLayer.getPropositionLayer()
    previousLayerMutexProposition = previousPropositionLayer.getMutexProps()

    self.updateActionLayer(previousPropositionLayer)
    self.updateMutexActions(previousLayerMutexProposition)
    self.updatePropositionLayer()
    self.updateMutexProposition()


  def expandWithoutMutex(self, previousLayer):
    """
    Questions 11 and 12
    You don't have to use this function
    """
    previousLayerProposition = previousLayer.getPropositionLayer()
    "*** YOUR CODE HERE ***"
コード例 #7
0
ファイル: planGraphLevel.py プロジェクト: omerzk/AI
class PlanGraphLevel(object):
  """
  A class for representing a level in the plan graph.
  For each level i, the PlanGraphLevel consists of the actionLayer and propositionLayer at this level in this order!
  """
  independentActions = None                                               # updated to the independentActions of the propblem GraphPlan.py line 25
  actions = None                                                          # updated to the actions of the problem GraphPlan.py line 26 and planningProblem.py line 25
  props = None                                                            # updated to the propositions of the problem GraphPlan.py line 27 and planningProblem.py line 26
  
  @staticmethod
  def setIndependentActions(independentActions):
    PlanGraphLevel.independentActions = independentActions
  
  @staticmethod  
  def setActions(actions):
    PlanGraphLevel.actions = actions
  
  @staticmethod    
  def setProps(props):
    PlanGraphLevel.props = props   
  
  def __init__(self):
    """
    Constructor
    """
    self.actionLayer = ActionLayer()    		                            # see actionLayer.py
    self.propositionLayer = PropositionLayer()	                        # see propositionLayer.py
  
  def getPropositionLayer(self):                                        # returns the proposition layer

    return self.propositionLayer
  
  def setPropositionLayer(self, propLayer):                             # sets the proposition layer
    self.propositionLayer = propLayer  
  
  def getActionLayer(self):                                             # returns the action layer
    return self.actionLayer
    
  def setActionLayer(self, actionLayer):                                # sets the action layer
    self.actionLayer = actionLayer

  def updateActionLayer(self, previousPropositionLayer):
    """ 
    Updates the action layer given the previous proposition layer (see propositionLayer.py)
    You should add an action to the layer if its preconditions are in the previous propositions layer,
    and the preconditions are not pairwise mutex. 
    allAction is the set of all the action (include noOp) in the domain
    You might want to use those functions:
    previousPropositionLayer.isMutex(prop1, prop2) returns true if prop1 and prop2 are mutex at the previous propositions layer
    previousPropositionLayer.allPrecondsInLayer(action) returns true if all the preconditions of action are in the previous propositions layer
    self.actionLayer.addAction(action) adds action to the current action layer
    """ 
    allActions = PlanGraphLevel.actions
    for action in allActions:
      if previousPropositionLayer.allPrecondsInLayer(action):
        pre = action.getPre()
        add = True
        for prop1 in pre:
          for prop2 in pre:
            if prop1 != prop2 and previousPropositionLayer.isMutex(prop1, prop2):
              add = False
              break
          if not add:
            break
        if add:
          self.actionLayer.addAction(action)

              


    
  def updateMutexActions(self, previousLayerMutexProposition):
    """
    Updates the mutex set in self.actionLayer,
    given the mutex proposition from the previous layer.
    currentLayerActions are the actions in the current action layer
    You might want to use this function:
    self.actionLayer.addMutexActions(action1, action2)
    adds the pair (action1, action2) to the mutex set in the current action layer
    Note that action is *not* mutex with itself
    """
    currentLayerActions = self.actionLayer.getActions()
    for a1 in  currentLayerActions:
      for a2 in currentLayerActions:
        if(a1 == a2):
          continue
        elif haveCompetingNeeds(a1, a2, previousLayerMutexProposition):
           self.actionLayer.addMutexActions(a1, a2)
    
    
  def updatePropositionLayer(self):
    """
    Updates the propositions in the current proposition layer,
    given the current action layer.
    don't forget to update the producers list!
    Note that same proposition in different layers might have different producers lists,
    hence you should create two different instances.
    currentLayerActions is the set of all the actions in the current layer.
    You might want to use those functions:
    dict() creates a new dictionary that might help to keep track on the propositions that you've
           already added to the layer
    self.propositionLayer.addProposition(prop) adds the proposition prop to the current layer       
    
    """
    currentLayerActions = self.actionLayer.getActions()
    propostions = {}
    for action in currentLayerActions:
      for prop in action.getAdd():
        if not prop.getName() in propostions:
          newProp = Proposition(prop.getName())
          propostions[prop.getName()] = newProp

        propostions[prop.getName()].addProducer(action)

    for prop in propostions:
      self.propositionLayer.addProposition(propostions[prop])
    
  def updateMutexProposition(self):
    """
    updates the mutex propositions in the current proposition layer
    You might want to use those functions:
    mutexPropositions(prop1, prop2, currentLayerMutexActions) returns true if prop1 and prop2 are mutex in the current layer
    self.propositionLayer.addMutexProp(prop1, prop2) adds the pair (prop1, prop2) to the mutex set of the current layer
    """
    currentLayerPropositions = self.propositionLayer.getPropositions()
    currentLayerMutexActions =  self.actionLayer.getMutexActions()

    for prop1 in currentLayerPropositions:
      for prop2 in currentLayerPropositions:
        if prop1 == prop2:
          continue
        elif mutexPropositions(prop1, prop2, currentLayerMutexActions):
          self.propositionLayer.addMutexProp(prop1, prop2)


  def expand(self, previousLayer):
    """
    Your algorithm should work as follows:
    First, given the propositions and the list of mutex propositions from the previous layer,
    set the actions in the action layer. 
    Then, set the mutex action in the action layer.
    Finally, given all the actions in the current layer,
    set the propositions and their mutex relations in the proposition layer.   
    """
    previousPropositionLayer = previousLayer.getPropositionLayer()
    previousLayerMutexProposition = previousPropositionLayer.getMutexProps()
    self.updateActionLayer(previousPropositionLayer)
    self.updateMutexActions(previousLayerMutexProposition)
    self.updatePropositionLayer()
    self.updateMutexProposition()
            
  def expandWithoutMutex(self, previousLayer):
    """
    Questions 11 and 12
    You don't have to use this function
    """
    previousLayerProposition = previousLayer.getPropositionLayer()
    self.updateActionLayer(previousLayerProposition)
    self.updatePropositionLayer()
コード例 #8
0
class PlanGraphLevel(object):
  
    """
    A class for representing a level in the plan graph.
    For each level i, the PlanGraphLevel consists of the actionLayer and propositionLayer at this level in this order!
    """
    independentActions = None                                               # updated to the independentActions of the propblem GraphPlan.py line 25
    actions = None                                                          # updated to the actions of the problem GraphPlan.py line 26 and planningProblem.py line 25
    props = None                                                            # updated to the propositions of the problem GraphPlan.py line 27 and planningProblem.py line 26
  
    @staticmethod
    def setIndependentActions(independentActions):
        PlanGraphLevel.independentActions = independentActions
  
    @staticmethod  
    def setActions(actions):
        PlanGraphLevel.actions = actions
  
    @staticmethod    
    def setProps(props):
        PlanGraphLevel.props = props   
  
    def __init__(self):
    
        self.actionLayer = ActionLayer()    		                            # see actionLayer.py
        self.propositionLayer = PropositionLayer()	                        # see propositionLayer.py
  
    def getPropositionLayer(self):                                        # returns the proposition layer

        return self.propositionLayer
  
    def setPropositionLayer(self, propLayer):                             # sets the proposition layer
        self.propositionLayer = propLayer  
  
    def getActionLayer(self):                                             # returns the action layer
        return self.actionLayer
    
    def setActionLayer(self, actionLayer):                                # sets the action layer
        self.actionLayer = actionLayer

    def updateActionLayer(self, previousPropositionLayer):
        """ 
        Updates the action layer given the previous proposition layer (see propositionLayer.py)
        You should add an action to the layer if its preconditions are in the previous propositions layer,
        and the preconditions are not pairwise mutex. 
        allAction is the set of all the action (include noOp) in the domain
        You might want to use those functions:
        previousPropositionLayer.isMutex(prop1, prop2) returns true if prop1 and prop2 are mutex at the previous propositions layer
        previousPropositionLayer.allPrecondsInLayer(action) returns true if all the preconditions of action are in the previous propositions layer
        self.actionLayer.addAction(action) adds action to the current action layer
        """ 
        allActions = PlanGraphLevel.actions
        "*** YOUR CODE HERE ***"
        for a in allActions:
            if previousPropositionLayer.allPrecondsInLayer(a):
                self.actionLayer.addAction(a)
    
    def updateMutexActions(self, previousLayerMutexProposition):
        """
        Updates the mutex set in self.actionLayer,
        given the mutex proposition from the previous layer.
        currentLayerActions are the actions in the current action layer
        You might want to use this function:
        self.actionLayer.addMutexActions(action1, action2)
        adds the pair (action1, action2) to the mutex set in the current action layer
        Note that action is *not* mutex with itself
        """
        currentLayerActions = self.actionLayer.getActions()
        "*** YOUR CODE HERE ***"
        for a_i in currentLayerActions:
            for a_j in currentLayerActions:
                if a_i != a_j and mutexActions(a_i, a_j, previousLayerMutexProposition):
                    if Pair(a_i,a_j) not in self.actionLayer.mutexActions:
                        self.actionLayer.addMutexActions(a_i,a_j)
    
    def updatePropositionLayer(self):
        """
        Updates the propositions in the current proposition layer,
        given the current action layer.
        don't forget to update the producers list!
        Note that same proposition in different layers might have different producers lists,
        hence you should create two different instances.
        currentLayerActions is the set of all the actions in the current layer.
        You might want to use those functions:
        dict() creates a new dictionary that might help to keep track on the propositions that you've
           already added to the layer
        self.propositionLayer.addProposition(prop) adds the proposition prop to the current layer
        """
        currentLayerActions = self.actionLayer.getActions()
        "*** YOUR CODE HERE ***"
        for a in currentLayerActions:
          for p in a.getAdd():
            if p not in self.propositionLayer.getPropositions():
              self.propositionLayer.addProposition(p)
            p.addProducer(a)
    
    def updateMutexProposition(self):
        """
        updates the mutex propositions in the current proposition layer
        You might want to use those functions:
        mutexPropositions(prop1, prop2, currentLayerMutexActions) returns true if prop1 and prop2 are mutex in the current layer
        self.propositionLayer.addMutexProp(prop1, prop2) adds the pair (prop1, prop2) to the mutex set of the current layer
        """
    
        currentLayerPropositions = self.propositionLayer.getPropositions()
        currentLayerMutexActions =  self.actionLayer.getMutexActions()
        "*** YOUR CODE HERE ***"
        for p_i in currentLayerPropositions:
          for p_j in currentLayerPropositions:
            if p_i != p_j and mutexPropositions(p_i,p_j,currentLayerMutexActions):
              if Pair(p_i,p_j) not in self.propositionLayer.mutexPropositions:
                self.propositionLayer.mutexPropositions.append(Pair(p_i,p_j))
    
    
    def expand(self, previousLayer):
        """
        Your algorithm should work as follows:
        First, given the propositions and the list of mutex propositions from the previous layer,
        set the actions in the action layer. 
        Then, set the mutex action in the action layer.
        Finally, given all the actions in the current layer,
        set the propositions and their mutex relations in the proposition layer.
        """
        previousPropositionLayer = previousLayer.getPropositionLayer()
        previousLayerMutexProposition = previousPropositionLayer.getMutexProps()

        "*** YOUR CODE HERE ***"
        self.updateActionLayer(previousPropositionLayer) 
        self.updateMutexActions(previousLayerMutexProposition)

        self.updatePropositionLayer()
        self.updateMutexProposition()
            
    def expandWithoutMutex(self, previousLayer):
        """
        Questions 11 and 12
        You don't have to use this function
        """
        previousLayerProposition = previousLayer.getPropositionLayer()
        "*** YOUR CODE HERE ***"
    
        self.updateActionLayer(previousLayerProposition)
        self.updatePropositionLayer()
		
    def mutexActions(a1, a2, mutexProps):
        """
        This function returns true if a1 and a2 are mutex actions.
        We first check whether a1 and a2 are in PlanGraphLevel.independentActions,
        this is the list of all the independent pair of actions (according to your implementation in question 1).
        If not, we check whether a1 and a2 have competing needs
        """ 
        if Pair(a1,a2) not in PlanGraphLevel.independentActions:
            return True
        return haveCompetingNeeds(a1, a2, mutexProps)

    def haveCompetingNeeds(a1, a2, mutexProps):
        pre1 = a1.getPre()
        pre2 = a2.getPre()
        """
        Complete code for deciding whether actions a1 and a2 have competing needs,
        given the mutex proposition from previous level (list of pairs of propositions).
        Hint: for propositions p  and q, the command  "Pair(p, q) in mutexProps"
        returns true if p and q are mutex in the previous level
        """
        "*** YOUR CODE HERE ***" 
        # Get preconditions of both actions


    # Competing needs: Check if a1 and a2 have preconditions that are mutex
        for p1 in pre1:
            for p2 in pre2:
                if Pair(p1, p2) in mutexProps:
                    return True 
        return False
    
    
		
    def mutexPropositions(prop1, prop2, mutexActions):
        prod1 = prop1.getProducers()
        prod2 = prop2.getProducers()
        """
      complete code for deciding whether two propositions are mutex,
      given the mutex action from the current level (set of pairs of actions).
      Your updateMutexProposition function should call this function
      You might want to use this function:
      prop1.getProducers() returns the set of all the possible actions in the layer that have prop1 on their add list
      """
        "*** YOUR CODE HERE ***"
        for a1 in prod1:
            for a2 in prod2:
          # Check if all actions are pairwise mutex
              if Pair(a1,a2) not in mutexActions:
                return False
        return True
コード例 #9
0
class PlanGraphLevel(object):
  """
  A class for representing a level in the plan graph.
  For each level i, the PlanGraphLevel consists of the actionLayer and propositionLayer at this level in this order!
  """
  independentActions = []  # updated to the independentActions of the propblem GraphPlan.py line 31 
  actions = []             # updated to the actions of the problem GraphPlan.py line 32 and planningProblem.py line 25
  props = []               # updated to the propositions of the problem GraphPlan.py line 33 and planningProblem.py line 26
  
  @staticmethod
  def setIndependentActions(independentActions):
    PlanGraphLevel.independentActions = independentActions
  
  @staticmethod  
  def setActions(actions):
    PlanGraphLevel.actions = actions
  
  @staticmethod    
  def setProps(props):
    PlanGraphLevel.props = props   
  
  def __init__(self):
    """
    Constructor
    """
    self.actionLayer = ActionLayer()    		# see actionLayer.py
    self.propositionLayer = PropositionLayer()	# see propositionLayer.py

  
  def getPropositionLayer(self):
    return self.propositionLayer
  
  def setPropositionLayer(self, propLayer):
    self.propositionLayer = propLayer  
  
  def getActionLayer(self):
    return self.actionLayer
    
  def setActionLayer(self, actionLayer):
    self.actionLayer = actionLayer

  def updateActionLayer(self, previousPropositionLayer):
    """ 
    Updates the action layer given the previous proposition layer (see propositionLayer.py)
    allAction is the list of all the actions (include noOp in the domain)
    """ 
    allActions = PlanGraphLevel.actions
    for a in allActions:
      if previousPropositionLayer.allPrecondsInLayer(a):
        self.actionLayer.addAction(a)
   

  def updateMutexActions(self, previousLayerMutexProposition):
    """
    Updates the mutex list in self.actionLayer,
    given the mutex proposition from the previous layer.
    currentLayerActions are the actions in the current action layer
    """
    currentLayerActions = self.actionLayer.getActions()
    for a_i in currentLayerActions:
      for a_j in currentLayerActions:
        if a_i != a_j and mutexActions(a_i, a_j, previousLayerMutexProposition):
          if Pair(a_i,a_j) not in self.actionLayer.mutexActions:
            self.actionLayer.addMutexActions(a_i,a_j)
   

  def updatePropositionLayer(self):
    """
    Updates the propositions in the current proposition layer,
    given the current action layer.
    don't forget to update the producers list!
    """
    currentLayerActions = self.actionLayer.getActions()
    for a in currentLayerActions:
      for p in a.getAdd():
        if p not in self.propositionLayer.getPropositions():
          self.propositionLayer.addProposition(p)
        p.addProducer(a)



  def updateMutexProposition(self):
    """
    updates the mutex propositions in the current proposition layer
    """
    currentLayerPropositions = self.propositionLayer.getPropositions()
    currentLayerMutexActions =  self.actionLayer.getMutexActions()
    for p_i in currentLayerPropositions:
      for p_j in currentLayerPropositions:
        if p_i != p_j and mutexPropositions(p_i,p_j,currentLayerMutexActions):
          if Pair(p_i,p_j) not in self.propositionLayer.mutexPropositions:
            self.propositionLayer.mutexPropositions.append(Pair(p_i,p_j)) 
	

  def expand(self, previousLayer):
    """
    Your algorithm should work as follows:
    First, given the propositions and the list of mutex propositions from the previous layer,
    set the actions in the action layer. 
    Then, set the mutex action in the action layer.
    Finally, given all the actions in the current layer, set the propositions and their mutex relations in the proposition layer.   
    """
    previousPropositionLayer = previousLayer.getPropositionLayer()
    previousLayerMutexProposition = previousPropositionLayer.getMutexProps()

    self.updateActionLayer(previousPropositionLayer) 
    self.updateMutexActions(previousLayerMutexProposition)

    self.updatePropositionLayer()
    self.updateMutexProposition()

            
  def expandWithoutMutex(self, previousLayer):
    """
    Questions 11 and 12
    You don't have to use this function
    """
    previousLayerProposition = previousLayer.getPropositionLayer()
    self.updateActionLayer(previousLayerProposition)
    self.updatePropositionLayer()
コード例 #10
0
class PlanGraphLevel(object):
    """
    A class for representing a level in the plan graph.
    For each level i, the PlanGraphLevel consists of the actionLayer and propositionLayer at this level in this order!
    """
    independentActions = [
    ]  # updated to the independentActions of the propblem GraphPlan.py line 31
    # updated to the actions of the problem GraphPlan.py line 32 and
    # planningProblem.py line 25
    actions = []
    # updated to the propositions of the problem GraphPlan.py line 33 and
    # planningProblem.py line 26
    props = []

    @staticmethod
    def setIndependentActions(independentActions):
        PlanGraphLevel.independentActions = independentActions

    @staticmethod
    def setActions(actions):
        PlanGraphLevel.actions = actions

    @staticmethod
    def setProps(props):
        PlanGraphLevel.props = props

    def __init__(self):
        """
        Constructor
        """
        self.actionLayer = ActionLayer()  # see actionLayer.py
        self.propositionLayer = PropositionLayer()  # see propositionLayer.py

    def getPropositionLayer(self):
        # returns the proposition layer
        return self.propositionLayer

    def setPropositionLayer(self, propLayer):
        # sets the proposition layer
        self.propositionLayer = propLayer

    def getActionLayer(self):
        # returns the action layer
        return self.actionLayer

    def setActionLayer(self, actionLayer):
        # sets the action layer
        self.actionLayer = actionLayer

    def updateActionLayer(self, previousPropositionLayer):
        """
        Updates the action layer given the previous proposition layer (see propositionLayer.py)
        You should add an action to the layer if its preconditions are in the previous propositions layer,
        and the preconditions are not pairwise mutex.
        allAction is the list of all the action (include noOp) in the domain
        You might want to use those functions:
        previousPropositionLayer.isMutex(prop1, prop2) returns true if prop1 and prop2 are mutex at the previous propositions layer
        previousPropositionLayer.allPrecondsInLayer(action) returns true if all the preconditions of action are in the previous propositions layer
        self.actionLayer.addAction(action) adds action to the current action layer
        """
        allActions = PlanGraphLevel.actions

        def isAllPrecondsInLayer(action):
            return previousPropositionLayer.allPrecondsInLayer(action)

        def isPropositionMutex(action):
            # create all the combinations of the actions preconditions
            all_combinations = [(cond1, cond2) for cond1 in action.getPre()
                                for cond2 in action.getPre()]
            # check if exists at least one mutex
            are_any_mutex = any(
                lmap(
                    lambda conds: previousPropositionLayer.isMutex(
                        conds[0], conds[1]),
                    lfilter(isDifferent, all_combinations)))
            # retun if rthere are no mutex
            return not are_any_mutex

        addActionToLayer = self.actionLayer.addAction

        lmap(
            addActionToLayer,
            lfilter(isPropositionMutex,
                    lfilter(isAllPrecondsInLayer, allActions)))

    def updateMutexActions(self, previousLayerMutexProposition):
        """
        Updates the mutex list in self.actionLayer,
        given the mutex proposition from the previous layer.
        currentLayerActions are the actions in the current action layer
        You might want to use this function:
        self.actionLayer.addMutexActions(action1, action2)
        adds the pair (action1, action2) to the mutex list in the current action layer
        Note that action is *not* mutex with itself
        """
        currentLayerActions = self.actionLayer.getActions()
        # create all the combinations of the actions
        all_combinations = [(action1, action2)
                            for action1 in currentLayerActions
                            for action2 in currentLayerActions]

        def isMutexActions(actions):
            a1, a2 = actions
            return mutexActions(a1, a2, previousLayerMutexProposition)

        def isNotIn(actions):
            a1, a2 = actions
            return Pair(a1, a2) not in self.actionLayer.mutexActions

        def addMutexActions(actions):
            a1, a2 = actions
            self.actionLayer.addMutexActions(a1, a2)

        lmap(
            addMutexActions,
            lfilter(
                isNotIn,
                lfilter(isMutexActions, lfilter(isDifferent,
                                                all_combinations))))

    def updatePropositionLayer(self):
        """
        Updates the propositions in the current proposition layer,
        given the current action layer.
        don't forget to update the producers list!
        Note that same proposition in different layers might have different producers lists,
        hence you should create two different instances.
        currentLayerActions is the list of all the actions in the current layer.
        You might want to use those functions:
        dict() creates a new dictionary that might help to keep track on the propositions that you've
               already added to the layer
        self.propositionLayer.addProposition(prop) adds the proposition prop to the current layer

        """
        currentLayerActions = self.actionLayer.getActions()

        def isNotIn(prop):
            return prop not in self.propositionLayer.getPropositions()

        addProposition = self.propositionLayer.addProposition

        for action in currentLayerActions:
            for prop in action.getAdd():
                if isNotIn(prop):
                    addProposition(prop)
                prop.addProducer(action)

    def updateMutexProposition(self):
        """
        updates the mutex propositions in the current proposition layer
        You might want to use those functions:
        mutexPropositions(prop1, prop2, currentLayerMutexActions) returns true if prop1 and prop2 are mutex in the current layer
        self.propositionLayer.addMutexProp(prop1, prop2) adds the pair (prop1, prop2) to the mutex list of the current layer
        """
        currentLayerPropositions = self.propositionLayer.getPropositions()
        currentLayerMutexActions = self.actionLayer.getMutexActions()

        # create all the combinations of the propositions
        all_combinations = [(prop1, prop2)
                            for prop1 in currentLayerPropositions
                            for prop2 in currentLayerPropositions]

        def isMutexPropositions(propositions):
            p1, p2 = propositions
            return mutexPropositions(p1, p2, currentLayerMutexActions)

        def isNotIn(propositions):
            p1, p2 = propositions
            return Pair(p1, p2) not in self.propositionLayer.mutexPropositions

        def addMutexPropositions(propositions):
            p1, p2 = propositions
            return self.propositionLayer.mutexPropositions.append(Pair(p1, p2))

        lmap(
            addMutexPropositions,
            lfilter(
                isNotIn,
                lfilter(isMutexPropositions,
                        lfilter(isDifferent, all_combinations))))

    def expand(self, previousLayer):
        """
        Your algorithm should work as follows:
        First, given the propositions and the list of mutex propositions from the previous layer,
        set the actions in the action layer.
        Then, set the mutex action in the action layer.
        Finally, given all the actions in the current layer,
        set the propositions and their mutex relations in the proposition layer.
        """
        previousPropositionLayer = previousLayer.getPropositionLayer()
        previousLayerMutexProposition = previousPropositionLayer.getMutexProps(
        )

        self.updateActionLayer(previousPropositionLayer)
        self.updateMutexActions(previousLayerMutexProposition)

        self.updatePropositionLayer()
        self.updateMutexProposition()

    def expandWithoutMutex(self, previousLayer):
        """
        Questions 11 and 12
        You don't have to use this function
        """
        previousLayerProposition = previousLayer.getPropositionLayer()
        self.updateActionLayer(previousLayerProposition)
        self.updatePropositionLayer()
コード例 #11
0
class PlanGraphLevel(object):
    """
    A class for representing a level in the plan graph.
    For each level i, the PlanGraphLevel consists of the actionLayer and propositionLayer at this level in this order!
    """
    independentActions = []  # updated to the independentActions of the propblem GraphPlan.py line 31
    actions = []  # updated to the actions of the problem GraphPlan.py line 32 and planningProblem.py line 25
    props = []  # updated to the propositions of the problem GraphPlan.py line 33 and planningProblem.py line 26

    @staticmethod
    def setIndependentActions(independentActions):
        PlanGraphLevel.independentActions = independentActions

    @staticmethod
    def setActions(actions):
        PlanGraphLevel.actions = actions

    @staticmethod
    def setProps(props):
        PlanGraphLevel.props = props

    def __init__(self):
        """
        Constructor
        """
        self.actionLayer = ActionLayer()  # see actionLayer.py
        self.propositionLayer = PropositionLayer()  # see propositionLayer.py

    def getPropositionLayer(self):
        # returns the proposition layer
        return self.propositionLayer

    def setPropositionLayer(self, propLayer):
        # sets the proposition layer
        self.propositionLayer = propLayer

    def getActionLayer(self):
        # returns the action layer
        return self.actionLayer

    def setActionLayer(self, actionLayer):
        # sets the action layer
        self.actionLayer = actionLayer

    def updateActionLayer(self, previousPropositionLayer):
        """
        Updates the action layer given the previous proposition layer (see propositionLayer.py)
        You should add an action to the layer if its preconditions are in the previous propositions layer,
        and the preconditions are not pairwise mutex.
        allAction is the list of all the action (include noOp) in the domain
        You might want to use those functions:
        previousPropositionLayer.isMutex(prop1, prop2) returns true if prop1 and prop2 are mutex at the previous propositions layer
        previousPropositionLayer.allPrecondsInLayer(action) returns true if all the preconditions of action are in the previous propositions layer
        self.actionLayer.addAction(action) adds action to the current action layer
        """
        # Check all possible actions
        for action in PlanGraphLevel.actions:
            if previousPropositionLayer.allPrecondsInLayer(action):  # only if all pre. exist, then try to add it
                mutexes = previousPropositionLayer.getMutexProps()
                has_mutexes = False
                # check for all pairs of mutexes, also if we have one pre. only, it will work
                for p1, p2 in product(action.getPre(), action.getPre()):
                    if Pair(p1, p2) in mutexes:
                        has_mutexes = True
                        break  # mutex found, we don't want to continue our checking
                if not has_mutexes:
                    self.actionLayer.addAction(action)

    def updateMutexActions(self, previousLayerMutexProposition):
        """
        Updates the mutex list in self.actionLayer,
        given the mutex proposition from the previous layer.
        currentLayerActions are the actions in the current action layer
        You might want to use this function:
        self.actionLayer.addMutexActions(action1, action2)
        adds the pair (action1, action2) to the mutex list in the current action layer
        Note that action is *not* mutex with itself
        """
        current_layer_actions = self.actionLayer.getActions()
        for a1, a2 in product(current_layer_actions, current_layer_actions):
            if a1 != a2 and mutexActions(a1, a2, previousLayerMutexProposition):
                self.actionLayer.addMutexActions(a1, a2)

    def updatePropositionLayer(self):
        """
        Updates the propositions in the current proposition layer,
        given the current action layer.
        don't forget to update the producers list!
        Note that same proposition in different layers might have different producers lists,
        hence you should create two different instances.
        currentLayerActions is the list of all the actions in the current layer.
        You might want to use those functions:
        dict() creates a new dictionary that might help to keep track on the propositions that you've
               already added to the layer
        self.propositionLayer.addProposition(prop) adds the proposition prop to the current layer

        """
        added_props = {}  # this dictionary will see what propositions were added
        # for all actions do the test
        for action in self.actionLayer.getActions():
            for prop in action.getAdd():
                if prop.getName() not in added_props:  # we don't wan't to add proposition twice
                    added_props[prop.getName()] = prop
                    self.getPropositionLayer().addProposition(prop)
                else:
                    # in case action not in producers, not see that issue but was asked to add that line in description
                    if action not in prop.getProducers():
                        prop.addProducer(action)

    def updateMutexProposition(self):
        """
        updates the mutex propositions in the current proposition layer
        You might want to use those functions:
        mutexPropositions(prop1, prop2, currentLayerMutexActions) returns true if prop1 and prop2 are mutex in the current layer
        self.propositionLayer.addMutexProp(prop1, prop2) adds the pair (prop1, prop2) to the mutex list of the current layer
        """
        currentLayerPropositions = self.propositionLayer.getPropositions()
        currentLayerMutexActions = self.actionLayer.getMutexActions()

        for p1, p2 in product(currentLayerPropositions, currentLayerPropositions):
            if p1 != p2 and mutexPropositions(p1, p2, currentLayerMutexActions):
                self.getPropositionLayer().addMutexProp(p1, p2)

    def expand(self, previousLayer):
        """
        Your algorithm should work as follows:
        First, given the propositions and the list of mutex propositions from the previous layer,
        set the actions in the action layer.
        Then, set the mutex action in the action layer.
        Finally, given all the actions in the current layer,
        set the propositions and their mutex relations in the proposition layer.
        """
        previousPropositionLayer = previousLayer.getPropositionLayer()
        previousLayerMutexProposition = previousPropositionLayer.getMutexProps()

        self.updateActionLayer(previousPropositionLayer)
        self.updateMutexActions(previousLayerMutexProposition)
        self.updatePropositionLayer()
        self.updateMutexProposition()

    def expandWithoutMutex(self, previousLayer):
        """
        Questions 11 and 12
        You don't have to use this function
        """
        previousLayerProposition = previousLayer.getPropositionLayer()
        self.updateActionLayer(previousLayerProposition)
        self.updatePropositionLayer()
コード例 #12
0
ファイル: planGraphLevel.py プロジェクト: dovh/openu
class PlanGraphLevel(object):
    """
  A class for representing a level in the plan graph.
  For each level i, the PlanGraphLevel consists of the actionLayer and propositionLayer at this level in this order!
  """
    independentActions = [
    ]  # updated to the independentActions of the propblem GraphPlan.py line 31
    actions = [
    ]  # updated to the actions of the problem GraphPlan.py line 32 and planningProblem.py line 25
    props = [
    ]  # updated to the propositions of the problem GraphPlan.py line 33 and planningProblem.py line 26

    @staticmethod
    def setIndependentActions(independentActions):
        PlanGraphLevel.independentActions = independentActions

    @staticmethod
    def setActions(actions):
        PlanGraphLevel.actions = actions

    @staticmethod
    def setProps(props):
        PlanGraphLevel.props = props

    def __init__(self):
        """
    Constructor
    """
        self.actionLayer = ActionLayer()  # see actionLayer.py
        self.propositionLayer = PropositionLayer()  # see propositionLayer.py

    def getPropositionLayer(self):
        # returns the proposition layer
        return self.propositionLayer

    def setPropositionLayer(self, propLayer):
        # sets the proposition layer
        self.propositionLayer = propLayer

    def getActionLayer(self):
        # returns the action layer
        return self.actionLayer

    def setActionLayer(self, actionLayer):
        # sets the action layer
        self.actionLayer = actionLayer

    def updateActionLayer(self, previousPropositionLayer):
        """ 
    Updates the action layer given the previous proposition layer (see propositionLayer.py)
    You should add an action to the layer if its preconditions are in the previous propositions layer,
    and the preconditions are not pairwise mutex. 
    allAction is the list of all the action (include noOp) in the domain
    You might want to use those functions:
    previousPropositionLayer.isMutex(prop1, prop2) returns true if prop1 and prop2 are mutex at the previous propositions layer
    previousPropositionLayer.allPrecondsInLayer(action) returns true if all the preconditions of action are in the previous propositions layer
    self.actionLayer.addAction(action) adds action to the current action layer
    """
        allActions = PlanGraphLevel.actions
        "*** YOUR CODE HERE ***"

        for action in allActions:
            if previousPropositionLayer.allPrecondsInLayer(action):
                self.actionLayer.addAction(action)

    def updateMutexActions(self, previousLayerMutexProposition):
        """
    Updates the mutex list in self.actionLayer,
    given the mutex proposition from the previous layer.
    currentLayerActions are the actions in the current action layer
    You might want to use this function:
    self.actionLayer.addMutexActions(action1, action2)
    adds the pair (action1, action2) to the mutex list in the current action layer
    Note that action is *not* mutex with itself
    """
        currentLayerActions = self.actionLayer.getActions()
        "*** YOUR CODE HERE ***"

        index = 0
        for action1 in currentLayerActions:
            index += 1
            for action2 in currentLayerActions[index:]:

                is_mutex = False
                for pre1 in action1.getPre():
                    for pre2 in action2.getPre():
                        if Pair(pre1, pre2) in previousLayerMutexProposition:
                            is_mutex = True
                            break

                if Pair(action1, action2) not in self.independentActions:
                    is_mutex = True

                if is_mutex:
                    self.actionLayer.addMutexActions(action1, action2)

    def updatePropositionLayer(self):
        """
    Updates the propositions in the current proposition layer,
    given the current action layer.
    don't forget to update the producers list!
    Note that same proposition in different layers might have different producers lists,
    hence you should create two different instances.
    currentLayerActions is the list of all the actions in the current layer.
    You might want to use those functions:
    dict() creates a new dictionary that might help to keep track on the propositions that you've
           already added to the layer
    self.propositionLayer.addProposition(prop) adds the proposition prop to the current layer       
    
    """
        currentLayerActions = self.actionLayer.getActions()
        "*** YOUR CODE HERE ***"

        Propositions = dict()

        for action in currentLayerActions:
            for prop in action.getAdd():

                name = prop.getName()
                if Propositions.has_key(name):
                    new_prop = Propositions[name]
                else:
                    new_prop = Proposition(name)
                    Propositions[name] = new_prop
                    self.propositionLayer.addProposition(new_prop)

                new_prop.addProducer(action)

    def updateMutexProposition(self):
        """
    updates the mutex propositions in the current proposition layer
    You might want to use those functions:
    mutexPropositions(prop1, prop2, currentLayerMutexActions) returns true if prop1 and prop2 are mutex in the current layer
    self.propositionLayer.addMutexProp(prop1, prop2) adds the pair (prop1, prop2) to the mutex list of the current layer
    """
        currentLayerPropositions = self.propositionLayer.getPropositions()
        currentLayerMutexActions = self.actionLayer.getMutexActions()
        "*** YOUR CODE HERE ***"

        index = 0
        for prop1 in currentLayerPropositions:
            index += 1
            for prop2 in currentLayerPropositions[index:]:
                if mutexPropositions(prop1, prop2, currentLayerMutexActions):
                    self.propositionLayer.addMutexProp(prop1, prop2)

    def expand(self, previousLayer):
        """
    Your algorithm should work as follows:
    First, given the propositions and the list of mutex propositions from the previous layer,
    set the actions in the action layer. 
    Then, set the mutex action in the action layer.
    Finally, given all the actions in the current layer,
    set the propositions and their mutex relations in the proposition layer.   
    """
        previousPropositionLayer = previousLayer.getPropositionLayer()
        previousLayerMutexProposition = previousPropositionLayer.getMutexProps(
        )

        "*** YOUR CODE HERE ***"

        self.updateActionLayer(previousPropositionLayer)
        self.updateMutexActions(previousLayerMutexProposition)
        self.updatePropositionLayer()
        self.updateMutexProposition()

        #print('expand')
        #print('actions              ' + str([action.getName() for action in self.actionLayer.actions]))
        #print('propositions         ' + str([prop.getName() for prop in self.propositionLayer.propositions]))
        #print('actions mutexes      ' + str([pair.a.getName()+","+pair.b.getName() for pair in self.actionLayer.mutexActions]))
        #print('propositions mutexes ' +  str([pair.a.getName()+","+pair.b.getName() for pair in self.propositionLayer.mutexPropositions]))

    def expandWithoutMutex(self, previousLayer):
        """
    Questions 11 and 12
    You don't have to use this function
    """
        previousLayerProposition = previousLayer.getPropositionLayer()
        "*** YOUR CODE HERE ***"

        self.updateActionLayer(previousLayerProposition)
        self.updatePropositionLayer()
コード例 #13
0
ファイル: planGraphLevel.py プロジェクト: YaboLee/GraphPlan
class PlanGraphLevel(object):
    """
  A class for representing a level in the plan graph.
  For each level i, the PlanGraphLevel consists of the actionLayer and propositionLayer at this level in this order!
  """
    independentActions = [
    ]  # updated to the independentActions of the propblem GraphPlan.py line 31
    actions = [
    ]  # updated to the actions of the problem GraphPlan.py line 32 and planningProblem.py line 25
    props = [
    ]  # updated to the propositions of the problem GraphPlan.py line 33 and planningProblem.py line 26

    @staticmethod
    def setIndependentActions(independentActions):
        PlanGraphLevel.independentActions = independentActions

    @staticmethod
    def setActions(actions):
        PlanGraphLevel.actions = actions

    @staticmethod
    def setProps(props):
        PlanGraphLevel.props = props

    def __init__(self):
        """
    Constructor
    """
        self.actionLayer = ActionLayer()  # see actionLayer.py
        self.propositionLayer = PropositionLayer()  # see propositionLayer.py

    def getPropositionLayer(self):
        return self.propositionLayer

    def setPropositionLayer(self, propLayer):
        self.propositionLayer = propLayer

    def getActionLayer(self):
        return self.actionLayer

    def setActionLayer(self, actionLayer):
        self.actionLayer = actionLayer

    def updateActionLayer(self, previousPropositionLayer):
        """ 
    Updates the action layer given the previous proposition layer (see propositionLayer.py)
    allAction is the list of all the actions (include noOp in the domain)
    """
        allActions = PlanGraphLevel.actions
        for a in allActions:
            if previousPropositionLayer.allPrecondsInLayer(a):
                self.actionLayer.addAction(a)

    def updateMutexActions(self, previousLayerMutexProposition):
        """
    Updates the mutex list in self.actionLayer,
    given the mutex proposition from the previous layer.
    currentLayerActions are the actions in the current action layer
    """
        currentLayerActions = self.actionLayer.getActions()
        for a_i in currentLayerActions:
            for a_j in currentLayerActions:
                if a_i != a_j and mutexActions(a_i, a_j,
                                               previousLayerMutexProposition):
                    if Pair(a_i, a_j) not in self.actionLayer.mutexActions:
                        self.actionLayer.addMutexActions(a_i, a_j)

    def updatePropositionLayer(self):
        """
    Updates the propositions in the current proposition layer,
    given the current action layer.
    don't forget to update the producers list!
    """
        currentLayerActions = self.actionLayer.getActions()
        for a in currentLayerActions:
            for p in a.getAdd():
                if p not in self.propositionLayer.getPropositions():
                    self.propositionLayer.addProposition(p)
                p.addProducer(a)

    def updateMutexProposition(self):
        """
    updates the mutex propositions in the current proposition layer
    """
        currentLayerPropositions = self.propositionLayer.getPropositions()
        currentLayerMutexActions = self.actionLayer.getMutexActions()
        for p_i in currentLayerPropositions:
            for p_j in currentLayerPropositions:
                if p_i != p_j and mutexPropositions(p_i, p_j,
                                                    currentLayerMutexActions):
                    if Pair(p_i, p_j
                            ) not in self.propositionLayer.mutexPropositions:
                        self.propositionLayer.mutexPropositions.append(
                            Pair(p_i, p_j))

    def expand(self, previousLayer):
        """
    Your algorithm should work as follows:
    First, given the propositions and the list of mutex propositions from the previous layer,
    set the actions in the action layer. 
    Then, set the mutex action in the action layer.
    Finally, given all the actions in the current layer, set the propositions and their mutex relations in the proposition layer.   
    """
        previousPropositionLayer = previousLayer.getPropositionLayer()
        previousLayerMutexProposition = previousPropositionLayer.getMutexProps(
        )

        self.updateActionLayer(previousPropositionLayer)
        self.updateMutexActions(previousLayerMutexProposition)

        self.updatePropositionLayer()
        self.updateMutexProposition()

    def expandWithoutMutex(self, previousLayer):
        """
    Questions 11 and 12
    You don't have to use this function
    """
        previousLayerProposition = previousLayer.getPropositionLayer()
        self.updateActionLayer(previousLayerProposition)
        self.updatePropositionLayer()
コード例 #14
0
class PlanGraphLevel(object):
    """
  A class for representing a level in the plan graph.
  For each level i, the PlanGraphLevel consists of the actionLayer and propositionLayer at this level in this order!
  """
    independentActions = [
    ]  # updated to the independentActions of the propblem GraphPlan.py line 31
    actions = [
    ]  # updated to the actions of the problem GraphPlan.py line 32 and planningProblem.py line 25
    props = [
    ]  # updated to the propositions of the problem GraphPlan.py line 33 and planningProblem.py line 26

    @staticmethod
    def setIndependentActions(independentActions):
        PlanGraphLevel.independentActions = independentActions

    @staticmethod
    def setActions(actions):
        PlanGraphLevel.actions = actions

    @staticmethod
    def setProps(props):
        PlanGraphLevel.props = props

    def __init__(self):
        """
    Constructor
    """
        self.actionLayer = ActionLayer()  # see actionLayer.py
        self.propositionLayer = PropositionLayer()  # see propositionLayer.py

    def getPropositionLayer(self):
        # returns the proposition layer
        return self.propositionLayer

    def setPropositionLayer(self, propLayer):
        # sets the proposition layer
        self.propositionLayer = propLayer

    def getActionLayer(self):
        # returns the action layer
        return self.actionLayer

    def setActionLayer(self, actionLayer):
        # sets the action layer
        self.actionLayer = actionLayer

    def updateActionLayer(self, previousPropositionLayer):
        """ 
    Updates the action layer given the previous proposition layer (see propositionLayer.py)
    You should add an action to the layer if its preconditions are in the previous propositions layer,
    and the preconditions are not pairwise mutex. 
    allAction is the list of all the action (include noOp) in the domain
    You might want to use those functions:
    previousPropositionLayer.isMutex(prop1, prop2) returns true if prop1 and prop2 are mutex at the previous propositions layer
    previousPropositionLayer.allPrecondsInLayer(action) returns true if all the preconditions of action are in the previous propositions layer
    self.actionLayer.addAction(action) adds action to the current action layer
    """
        allActions = PlanGraphLevel.actions
        # For each action that is not in this actionLayer and was in the previous one. We will add it to this layer too (as noOp)
        for action in allActions:
            if action not in self.actionLayer.getActions(
            ) and previousPropositionLayer.allPrecondsInLayer(action):
                self.actionLayer.addAction(action)

    def updateMutexActions(self, previousLayerMutexProposition):
        """
    Updates the mutex list in self.actionLayer,
    given the mutex proposition from the previous layer.
    currentLayerActions are the actions in the current action layer
    You might want to use this function:
    self.actionLayer.addMutexActions(action1, action2)
    adds the pair (action1, action2) to the mutex list in the current action layer
    Note that action is *not* mutex with itself
    """
        currentLayerActions = self.actionLayer.getActions()
        for ai in currentLayerActions:
            for aj in currentLayerActions:
                # For each action 1,2 in current action layer, if they are mutex, and they are not in mutex actions, we will ad them too.
                if ai != aj and \
                  Pair(ai, aj) not in self.actionLayer.getMutexActions() and \
                  mutexActions(ai, aj, previousLayerMutexProposition):
                    self.actionLayer.addMutexActions(ai, aj)

    def updatePropositionLayer(self):
        """
    Updates the propositions in the current proposition layer,
    given the current action layer.
    don't forget to update the producers list!
    Note that same proposition in different layers might have different producers lists,
    hence you should create two different instances.
    currentLayerActions is the list of all the actions in the current layer.
    You might want to use those functions:
    dict() creates a new dictionary that might help to keep track on the propositions that you've
           already added to the layer
    self.propositionLayer.addProposition(prop) adds the proposition prop to the current layer       
    
    """
        currentLayerActions = self.actionLayer.getActions()
        for action in currentLayerActions:
            for prop in action.getAdd():
                if prop not in self.propositionLayer.getPropositions():
                    self.propositionLayer.addProposition(prop)
                # updating action's producers
                if action not in prop.getProducers():
                    prop.addProducer(action)

    def updateMutexProposition(self):
        """
    updates the mutex propositions in the current proposition layer
    You might want to use those functions:
    mutexPropositions(prop1, prop2, currentLayerMutexActions) returns true if prop1 and prop2 are mutex in the current layer
    self.propositionLayer.addMutexProp(prop1, prop2) adds the pair (prop1, prop2) to the mutex list of the current layer
    """
        currentLayerPropositions = self.propositionLayer.getPropositions()
        currentLayerMutexActions = self.actionLayer.getMutexActions()
        for p1 in currentLayerPropositions:
            for p2 in currentLayerPropositions:
                if p1 != p2 and \
                        Pair(p1, p2) not in self.propositionLayer.getMutexProps() and \
                        mutexPropositions(p1, p2, currentLayerMutexActions):
                    self.propositionLayer.addMutexProp(p1, p2)

    def expand(self, previousLayer):
        """
    Your algorithm should work as follows:
    First, given the propositions and the list of mutex propositions from the previous layer,
    set the actions in the action layer. 
    Then, set the mutex action in the action layer.
    Finally, given all the actions in the current layer,
    set the propositions and their mutex relations in the proposition layer.   
    """
        previousPropositionLayer = previousLayer.getPropositionLayer()
        previousLayerMutexProposition = previousPropositionLayer.getMutexProps(
        )
        # doing the algorithm of adding a layer,
        self.updateActionLayer(previousPropositionLayer)
        self.updateMutexActions(previousLayerMutexProposition)
        self.updatePropositionLayer()
        self.updateMutexProposition()

    def expandWithoutMutex(self, previousLayer):
        """
    Questions 11 and 12
    You don't have to use this function
    """
        previousLayerProposition = previousLayer.getPropositionLayer()
        # self.updateActionLayer(previousLayerProposition)
        # self.updatePropositionLayer()
        "*** YOUR CODE HERE ***"