Intelligent Systems Lecture Notes

14 September 2011 • Basic State-Space Search


Outline

A State-Space Interface

interface Problem 

  abstract class State { }

  Set<State> initialStates()

  Boolean isGoalState(State s)

  Set<State> nextStates(State s)

  double moveCost(State from, State to)

A State-Space Search Interface

interface StateSpaceSearch

  interface SolutionPath 
  extends Queue<Problem.State>

  SolutionPath search(Problem problem)

  interface Comparison
    boolean isBetterThan(
      SolutionPath a, SolutionPath b)

  SolutionPath search(
    Problem problem, Comparison c)

Simple Search

Simple Search Problems

Improving Search

Graph Search

SolutionPath search(Problem problem)

  Set<Path> pendingPaths = initialPaths(problem)

  while !pendingPaths.isEmpty()
    Path path = pick(pendingPaths)
    for Problem.State neighbor : 
        problem.moveResults(path.lastState())
      Path newPath = path.addStep(neighbor)
      if problem.isGoalState(neighbor)
	return newPath
      pendingPaths.add(newPath)

  return new Path()

Observations

Graph Optimal Search

SolutionPath search(Problem problem, Comparison c)

  SolutionPath bestSolution = new Path()
  Set<Path> pendingPaths = initialPaths(problem)

  while !pendingPaths.isEmpty()
    Path path = pick(pendingPaths)
    for Problem.State neighbor : 
        problem.moveResults(path.lastState())
      Path newPath = path.addStep(neighbor)
      if    problem.isGoalState(neighbor)
         && c.isBetterThan(newPath, bestSolution)
	bestSolution = newPath
      pendingPaths.add(newPath)

  return bestSolution

Depth-First Search

SolutionPath search(Problem problem)

  Stack<Path> pendingPaths = initialPaths(problem)

  while !pendingPaths.isEmpty()
    Path path = pendingPaths.pop()
    for Problem.State neighbor : 
        problem.moveResults(path.lastState())
      Path newPath = path.addStep(neighbor)
      if problem.isGoalState(neighbor)
	return newPath
      pendingPaths.push(newPath)

  return new Path()

Breadth-First Search

Queue<Problem.State> solve(Problem p)

  paths = 
    Queue(Queue(s | s ∈ p.startStates()))

  while !paths.empty()
    path = paths.get()
    s = path.tail()
    if p.goalState(s)
      return path
    for n in p.nextStates(s)
      paths.put(path.copy().add(n))

  return Queue()

Uninformed Searches

Least-Cost-First Search

Queue<Problem.State> solve(Problem p)

  paths = 
    MinQueue(Queue(s | s ∈ p.startStates()))

  while !paths.empty()
    path = paths.get()
    s = path.tail()
    if p.goalState(s)
      return path
    for n in p.nextStates(s)
      paths.put(path.copy().add(n))

  return Queue()

Observations

Heuristics

A* Search

Comparing Searches

Summary

References

Credits


This page last modified on 2011 September 15.

Creative
    Commons License