Ejemplo n.º 1
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