AI Search
Solution A sequence of actions that leads from the initial state to a goal state
- Optimal solution A solution that has the lowest path cost among all solutions.
In a search process, data is often stored in a node, a data structure that contains the following data:
- A state
- Its parent node, through which the current node was generated
- The action that was applied to the state of the parent to get to the current node
- The path cost from the initial state to this node
Nodes contain information that makes them very useful for the purposes of search algorithms. They contain a state, which can be checked using the goal test to see if it is the final state. If it is, the node’s path cost can be compared to other nodes’ path costs, which allows choosing the optimal solution. Once the node is chosen, by virtue of storing the parent node and the action that led from the parent to the current node, it is possible to trace back every step of the way from the initial state to this node, and this sequence of actions is the solution.
To search, we use the frontier, the mechanism that “manages” the nodes.
General Approach
- Start with a frontier that contains the initial state
- Start with an empty explored set.
- Repeat:
- If the frontier is empty,
- Stop. There is no solution to the problem.
- Remove a node from the frontier. This is the node that will be considered.
- If the node contains the goal state, Return the solution. Stop.
- Expand the node, and add resulting nodes to the frontier if they aren’t already in the frontier or the explored set.
- Add the current node to the explored set.