Ejemplo n.º 1
0
    def graphPlan(self):
        """
        The graphplan algorithm.
        The code calls the extract function which you should complete below
        """
        #initialization
        initState = self.initialState
        level = 0
        self.noGoods = [] #make sure you update noGoods in your backward search!
        self.noGoods.append([])
        #create first layer of the graph, note it only has a proposition layer which consists of the initial state.
        propLayerInit = PropositionLayer()
        for prop in initState:
            propLayerInit.addProposition(prop)            
        pgInit = PlanGraphLevel()
        pgInit.setPropositionLayer(propLayerInit)
        self.graph.append(pgInit)
        

        """
        While the layer does not contain all of the propositions in the goal state,
        or some of these propositions are mutex in the layer we,
        and we have not reached the fixed point, continue expanding the graph
        """

        while self.goalStateNotInPropLayer(self.graph[level].getPropositionLayer().getPropositions()) or \
            self.goalStateHasMutex(self.graph[level].getPropositionLayer()):
            if self.isFixed(level):
                return None #this means we stopped the while loop above because we reached a fixed point in the graph. nothing more to do, we failed!

            self.noGoods.append([])
            level = level + 1
            pgNext = PlanGraphLevel() #create new PlanGraph object
            pgNext.expand(self.graph[level - 1]) #calls the expand function, which you are implementing in the PlanGraph class
            self.graph.append(pgNext) #appending the new level to the plan graph
            
            sizeNoGood = len(self.noGoods[level]) #remember size of nogood table

        plan = self.extract(self.graph, self.goal, level) #try to extract a plan since all of the goal propositions are in current graph level, and are not mutex
        while(plan is None): #while we didn't extract a plan successfully
            level = level + 1
            self.noGoods.append([])
            pgNext = PlanGraphLevel() #create next level of the graph by expanding
            pgNext.expand(self.graph[level - 1]) #create next level of the graph by expanding
            self.graph.append(pgNext)
            plan = self.extract(self.graph, self.goal, level) #try to extract a plan again
            if (plan is None and self.isFixed(level)): #if failed and reached fixed point
                if sizeNoGood == len(self.noGoods[level]): #if size of nogood didn't change, means there's nothing more to do. We failed.
                    return None
                sizeNoGood = len(self.noGoods[level]) #we didn't fail yet! update size of no good
        return plan
Ejemplo n.º 2
0
  def graphPlan(self):
    """
    The graphplan algorithm.
    The code calls the extract function which you should complete below
    """
    #initialization
    initState = self.initialState
    level = 0
    self.noGoods = [] #make sure you update noGoods in your backward search!
    self.noGoods.append([])
    #create first layer of the graph, note it only has a proposition layer which consists of the initial state.
    propLayerInit = PropositionLayer()
    for prop in initState:
      propLayerInit.addProposition(prop)
    pgInit = PlanGraphLevel()
    pgInit.setPropositionLayer(propLayerInit)
    self.graph.append(pgInit)

    """
    While the layer does not contain all of the propositions in the goal state,
    or some of these propositions are mutex in the layer we,
    and we have not reached the fixed point, continue expanding the graph
    """

    while self.goalStateNotInPropLayer(self.graph[level].getPropositionLayer().getPropositions()) or \
        self.goalStateHasMutex(self.graph[level].getPropositionLayer()):
      if self.isFixed(level):
        return None #this means we stopped the while loop above because we reached a fixed point in the graph. nothing more to do, we failed!

      self.noGoods.append([])
      level = level + 1
      pgNext = PlanGraphLevel() #create new PlanGraph object
      pgNext.expand(self.graph[level - 1]) #calls the expand function, which you are implementing in the PlanGraph class
      self.graph.append(pgNext) #appending the new level to the plan graph

      sizeNoGood = len(self.noGoods[level]) #remember size of nogood table

    plan = self.extract(self.graph, self.goal, level) #try to extract a plan since all of the goal propositions are in current graph level, and are not mutex
    while(plan is None): #while we didn't extract a plan successfully
      level = level + 1
      self.noGoods.append([])
      pgNext = PlanGraphLevel() #create next level of the graph by expanding
      pgNext.expand(self.graph[level - 1]) #create next level of the graph by expanding
      self.graph.append(pgNext)
      plan = self.extract(self.graph, self.goal, level) #try to extract a plan again
      if (plan is None and self.isFixed(level)): #if failed and reached fixed point
        if sizeNoGood == len(self.noGoods[level]): #if size of nogood didn't change, means there's nothing more to do. We failed.
          return None
        sizeNoGood = len(self.noGoods[level]) #we didn't fail yet! update size of no good
    return plan
Ejemplo n.º 3
0
	def graphPlan(self): 
		#El algoritmo graphplan en sí
		
		#Inicialización
		initState = self.initialState
		level = 0
		self.noGoods = []
		self.noGoods.append([])
		
		#Crea la primera capa del grafo, que no consiste más que en el estado inicial
		propLayerInit = PropositionLayer()
		for prop in initState:
			propLayerInit.addProposition(prop)
		pgInit = PlanGraphLevel()
		pgInit.setPropositionLayer(propLayerInit)
		self.graph.append(pgInit)
		
		#Mientras que la capa no contiene todos los estados del estado final buscado (o están mutex) continuamos expandiendo el grafo
		while self.goalStateNotInPropLayer(self.graph[level].getPropositionLayer().getPropositions()) or \
				self.goalStateHasMutex(self.graph[level].getPropositionLayer()):
			if self.isFixed(level):
				return None	#Si llegamos aquí paramos porque significa que hemos llegado a un fixed point en el grafo, así que no podemos hacer nada más
				
			self.noGoods.append([])
			level = level + 1 #Actualizamos el nivel
			pgNext = PlanGraphLevel() #Crea un nuevo objeto GraphPlan
			pgNext.expand(self.graph[level - 1]) #Llama a la función expandir
			self.graph.append(pgNext) #Une el nuevo nivel generado con el graphplan
		
			sizeNoGood = len(self.noGoods[level])
		
		plan = self.extract(self.graph, self.goal, level) #Intentamos hallar un plan (si todos los estados objetivos están en este nivel y no están mutex)
		while(plan is None): #Hacemos esto mientras no podemos encontrar un plan
			level = level + 1 
			self.noGoods.append([])
			pgNext = PlanGraphLevel() #Crea el próximo nivel del grafo
			pgNext.expand(self.graph[level - 1]) #Y ahora lo expande
			self.graph.append(pgNext)
			plan = self.extract(self.graph, self.goal, level) #Intentamos econtrar el plan
			if (plan is None and self.isFixed(level)): #Si fallamos y encontramos un punto un fixed point
				if sizeNoGood == len(self.noGoods[level]): #Si el tamaño de noGood no cambia significa que hemos fallado y no hay plan
					return None
				sizeNoGood = len(self.noGoods[level]) #Si no, significa que aún podemos encontrar el plan y actualizamos el tamaño de noGood
		return plan