Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def maxLevel(state, problem):
- """
- The heuristic value is the number of layers required to expand all goal propositions.
- If the goal is not reachable from the state your heuristic should return float('inf')
- A good place to start would be:
- propLayerInit = PropositionLayer() #create a new proposition layer
- for prop in state:
- propLayerInit.addProposition(prop) #update the proposition layer with the propositions of the state
- pgInit = PlanGraphLevel() #create a new plan graph level (level is the action layer and the propositions layer)
- pgInit.setPropositionLayer(propLayerInit) #update the new plan graph level with the the proposition layer
- """
- propLayerInit = PropositionLayer()
- for p in state:
- propLayerInit.addProposition(p)
- pgInit = PlanGraphLevel()
- pgInit.setPropositionLayer(propLayerInit)
- graph = [] # list of PlanGraphLevel objects
- graph.append(pgInit)
- level = 0
- # keep expanding as long as we don't hit the goal state
- while problem.goalStateNotInPropLayer(graph[level].getPropositionLayer().getPropositions()):
- if isFixed(graph, level):
- # if the graph is fixed and expansions didn't change in the last level, it means that we can't reach
- # the goal state, and we return infinity
- return float('inf')
- pg = PlanGraphLevel()
- # expanding using a easier version of the problem - without mutexes
- pg.expandWithoutMutex(graph[level])
- graph.append(pg)
- level += 1
- return level
- def levelSum(state, problem):
- """
- The heuristic value is the sum of sub-goals level they first appeared.
- If the goal is not reachable from the state your heuristic should return float('inf')
- """
- propLayerInit = PropositionLayer()
- for p in state:
- propLayerInit.addProposition(p)
- pgInit = PlanGraphLevel()
- pgInit.setPropositionLayer(propLayerInit)
- graph = [] # list of PlanGraphLevel objects
- graph.append(pgInit)
- goals = problem.goal[:]
- level = 0
- sum_ = 0
- # keep expanding as long as we still have goal states we didn't see
- while goals:
- if isFixed(graph, level):
- # if the graph is fixed and expansions didn't change in the last level, it means that we can't reach
- # the goal state, and we return infinity
- return float('inf')
- props = graph[level].getPropositionLayer().getPropositions()
- for goal in goals:
- if goal in props:
- # each goal state that we run into, we should add to the sum, and remove it from the goals we need to see
- sum_ += level
- goals.remove(goal)
- pg = PlanGraphLevel()
- # expanding using a easier version of the problem - without mutexes
- pg.expandWithoutMutex(graph[level])
- graph.append(pg)
- level += 1
- sum_ += level
- return sum_
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement