Module ucSearch
[frames] | no frames]

Module ucSearch

Procedures and classes for doing uniform cost search, always with dynamic programming. Becomes A* if a heuristic is specified.

Classes
  SearchNode
A node in a search tree
  PQ
Slow implementation of a priority queue that just finds the minimum element for each extraction.
Functions
 
search(initialState, goalTest, actions, successor, heuristic=<function <lambda> at 0x1755af0>, maxNodes=10000)
Returns: path from initial state to a goal state as a list of (action, state) tuples
 
smSearch(smToSearch, initialState=None, goalTest=None, heuristic=<function <lambda> at 0x1788f30>, maxNodes=10000)
Returns: a list of the form [(a0, s0), (a1, s1), (a2, s2), ...] where the a's are legal actions of c{smToSearch} and s's are states of that machine.
Variables
  somewhatVerbose = False
If True, prints a trace of the search
  verbose = False
If True, prints a verbose trace of the search
  __package__ = None
Function Details

search(initialState, goalTest, actions, successor, heuristic=<function <lambda> at 0x1755af0>, maxNodes=10000)

 
Parameters:
  • initialState - root of the search
  • goalTest - function from state to Boolean
  • actions - function from state to list of actions
  • successor - function from state and action to next state and cost
  • heuristic - function from state to estimated cost to reach a goal; defaults to a heuristic of 0, making this uniform cost search
  • maxNodes - kill the search after it expands this many nodes
Returns:
path from initial state to a goal state as a list of (action, state) tuples

smSearch(smToSearch, initialState=None, goalTest=None, heuristic=<function <lambda> at 0x1788f30>, maxNodes=10000)

 
Parameters:
  • smToSearch - instance of sm.SM defining a search domain; getNextValues is used to determine the successor of a state given an action; the output field of getNextValues is interpreted as a cost.
  • initialState - initial state for the search; if not provided, will use smToSearch.startState
  • goalTest - function that takes a state as an argument and returns True if it is a goal state, and False otherwise
  • heuristic - function from state to estimated cost to reach a goal; defaults to a heuristic of 0, making this uniform cost search
  • maxNodes - maximum number of nodes to be searched; prevents runaway searches
Returns:
a list of the form [(a0, s0), (a1, s1), (a2, s2), ...] where the a's are legal actions of c{smToSearch} and s's are states of that machine. s0 is the start state; the last state is a state that satisfies the goal test. If the goal is unreachable (within the search limit), it returns None.