示例#1
0
    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)
示例#2
0
    def getSuccessors(self, state):
        """   
    For a given state, this should return a list of triples, 
    (successor, action, stepCost), where 'successor' is a 
    successor to the current state, 'action' is the action
    required to get there, and 'stepCost' is the incremental 
    cost of expanding to that successor, 1 in our case.
    You might want to this function:
    For a list of propositions l and action a,
    a.allPrecondsInList(l) returns true if the preconditions of a are in l
    """
        self._expanded += 1
        "*** YOUR CODE HERE ***"

        # explain: Successors are the list of actions can be done from the current level
        #   I build the action lyer using pgNext.updateActionLayer
        #   then for each action I build a the Level that wholud have been created if only this action was selected

        Successors = []

        pg = state
        previousPropositionLayer = pg.getPropositionLayer()
        previousLayerPropositions = previousPropositionLayer.propositions

        pgNext = PlanGraphLevel()
        pgNext.updateActionLayer(previousPropositionLayer)

        for Action in pgNext.actionLayer.actions:

            if Action.isNoOp():
                continue

            pgNextAction = PlanGraphLevel()
            pgNextAction.actionLayer.addAction(Action)
            for prop in previousLayerPropositions:
                pgNextAction.propositionLayer.addProposition(prop)
            for prop in Action.getAdd():
                new_prop = Proposition(prop.getName())
                new_prop.addProducer(Action)
                pgNextAction.propositionLayer.addProposition(new_prop)
            for prop in Action.getDelete():
                pgNextAction.propositionLayer.removePropositions(prop)
            pgNextAction.updateMutexProposition()

            Successors.append((pgNextAction, Action, 1))

        return Successors