Dr. Mark Humphrys

School of Computing. Dublin City University.

Online coding site: Ancient Brain

 

Search:


State space Search




3.1.3 - State space representation of problem



Example: Representing Xs and Os as state-space problem.
Image courtesy of Ralph Morelli.
See Luger Fig II.5


State space representation of a problem:
  1. All the states the system can be in are represented as nodes of a graph.
  2. An action that can change the system from one state to another (e.g. a move in a game) is represented by a link from one node to another.
  3. Links may be unidirectional (e.g. Xs and Os, can't go back) or bi-directional (e.g. geographic move).

  4. Search for a solution.
  5. A solution might be:
    1. Any path from start state to goal state.
    2. The best (e.g. lowest cost) path from start state to goal state (e.g. Travelling salesman problem).
  6. It may be possible to reach the same state through many different paths (obviously true in Xs and Os).
  7. There may be loops in the graph (can go round in circle). No loops in Xs and Os.



Xs and Os


Reduce statespace

We can use symmetry reduction to reduce the search problem.
Many states are rotations or mirror-image of another state, so we don't have to search them separately.
e.g. There are basically only 3 unique first moves.

See Luger Fig 4.1

Symmetry reduction may require a lot of work by the human. But worth it if it reduces search problem (sometimes massively).
We write code to do the transform, search and transform back.



Travelling salesman problem (TSP)

Travelling salesman problem



Travelling salesman problem.
Start at A, visit all cities, return to A. Links show cost of each trip (distance, money). Find trip with minimum cost.
Solution is a path. e.g. [A,D,C,B,E,A]
Image courtesy of Ralph Morelli.
See Luger Fig 3.9

Q. What is the shortest path?



Representing Travelling salesman problem as state-space problem.
Image courtesy of Ralph Morelli.
See Luger Fig 3.10.
Start at A, 4 choices for first step, 3 choices for next, 2 choices, 1 choice.
4! (4 factorial) paths = 24 paths

Q. What assumption did we make?

Q. When do we stop the search?




How big is the TSP?

In general, how many paths are there in the TSP?




Restrict search / Problem-specific heuristics

With problems that scale badly, we need to restrict the search in some way.
Many of these restriction ideas will be problem-specific - the idea only works on this problem and not on all problems.

Reduce statespace

Branch and bound
- Keep track of best path so far. This is a bound on future candidates.
As soon as best possible extension to a partially-constructed path (the branch) exceeds bound, that partial path and all its extensions are removed.
Reduces space but still exponential (const)n number of paths.

Heuristic search

With large state spaces (e.g. 50 cities) need to use heuristic.
e.g. Nearest neighbour: "Go to the nearest unvisited city."
Finds solution quick! (Only tries one path!)

Luger changes his numbers to show example of "Nearest neighbour" heuristic failing on Travelling salesman problem:


Image courtesy of Ralph Morelli.
See Luger Fig 3.11



3.2 - Searching a statespace graph



3.2.2 - Backtracking (exhaustive search)

Backtracking - exhaustive search, try each path in order, until find goal.



Depth-first search

The "Depth-first search" version of exhaustive search.
Goes down to remote descendants looking for solution before back-tracks up to a sibling.



Depth-first search:
Start at A. Search state space systematically until find goal.
When multiple children, go down 1st child. If fails, back to parent, down 2nd child, and so on.
Image courtesy of Ralph Morelli.
See Luger Fig 3.14

Note there are multiple paths to F.
If F has already been found to be a dead-end when we went there from B, the algorithm should not go there a second time (from C).
However not a great example here since C can see goal so won't go to F anyway.




Breadth-first search

The "Breadth-first search" version of exhaustive search.
Search all children (siblings) before search all grandchildren.
  

Image courtesy of Ralph Morelli.


Depth-first search examines the nodes in the order:

  A, B, E, K, S, L, T, F, M, C, G, N, H, O, P, U, D, I, Q, J, R

Need to:

  
Breadth-first search does each level first before moving lower, examines the nodes in the order:
  A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U
Need to:


ancientbrain.com      w2mind.org      humphrysfamilytree.com

On the Internet since 1987.      New 250 G VPS server.

Note: Links on this site to user-generated content like Wikipedia are highlighted in red as possibly unreliable. My view is that such links are highly useful but flawed.