Search Problem Summary
π§ Search Problem Summaryβ
A search problem in AI is defined by five key components:
- Initial State
- Where the agent begins (e.g. position A in a maze).
- Actions
- The set of choices the agent can take in each state.
- Defined as
ACTIONS(s)
β returns all possible actions from states
.
- Transition Model
- Describes the result of an action.
- Defined as
RESULT(s, a)
β gives the next state after applying actiona
in states
.
- Goal Test
- Checks if the current state satisfies the goal condition.
- Path Cost Function
- Assigns a numerical cost to each path β used to find the optimal solution.
π§ Key Conceptsβ
- State: A configuration of the agent and its environment.
- State Space: All possible states reachable from the initial state.
- Solution: A sequence of actions that gets the agent from the initial to a goal state.
- Optimal Solution: The path with the lowest total cost.
π¦ Node Data Structureβ
Each node in the search process stores:
- The current state
- A parent (how you got here)
- The action taken from the parent
- The path cost so far
π Basic Search Algorithm (Uninformed Search)β
Algorithm:
sql
CopyEdit
1. Initialize frontier with the initial state.
2. Loop:
a. If frontier is empty β no solution.
b. Remove a node from the frontier.
c. If itβs the goal state β return the solution.
d. Else, expand node and add children to frontier.
π¨ Problem: Repeated Statesβ
Without handling duplicates, the agent can revisit the same state and get stuck (infinite loops, wasted time).
β Revised Search Approach (with Explored Set)β
Adds an explored set to avoid revisiting:
Improved Algorithm:
sql
CopyEdit
1. Frontier β initial state
2. Explored β empty set
3. Loop:
a. If frontier is empty β failure.
b. Remove a node.
c. If node is goal β return path.
d. Add node to explored.
e. Expand node.
f. For each child:
- If not in explored or frontier β add to frontier.
π§± Data Structuresβ
- Stack (LIFO): Used in Depth-First Search (DFS)
- Queue (FIFO): Used in Breadth-First Search (BFS)
- More will come soon in advanced strategies.
π TL;DR Review List:β
- Understand what defines a search problem.
- Know the five elements: initial state, actions, transition model, goal test, path cost.
- Use explored sets to avoid redundancy.
- Search is about expanding states, tracking paths, and finding optimal solutions.