Skip to main content

Welcome to a Grasp lesson

Create a free account to keep studying and create your own study path.

Lesson 89

Modeling Real-World Problems with State-Space Search

Recommended resources

Hello! Welcome to the first lesson in our module, "Artificial Intelligence: Search and Reasoning."

Throughout this course, we've built a strong foundation in programming, mathematics, and machine learning. We've seen how to make predictions from data. Now, we shift our focus to a different but equally fundamental part of AI: problem-solving. How does an intelligent agent, like a robot or a game-playing AI, make a sequence of decisions to achieve a goal? This is the domain of search.

This lesson tackles the very first step in that process. Our learning outcome is to formulate real-world problems as state-space search problems. This means learning how to take a vague goal, like "win this game" or "get from point A to point B," and translate it into a precise, formal structure that a computer algorithm can understand and solve. This is a crucial skill that underpins much of classical AI.

1. What is a Search Problem?

At its core, many AI problems can be viewed as searching for a solution within a vast space of possibilities. Imagine you're planning a trip. You're in a starting city, you have a destination, and there are many possible routes you could take. Finding the best route is a search problem.

To solve such problems, an AI agent needs a formal description of the world. This is called problem formulation. Let's watch a video that introduces this idea using a classic example: a trip across Romania.

Artificial Intelligence - 3.1 and 3.2 - Searching - Problem solving agents and Example problems

This video by Badri Adhikari introduces the core idea of problem-solving through search and lays out the five essential components needed to formally define any search problem.

Watch from the beginning until 07:18. Pay close attention to the five components introduced for defining a problem: Initial State Actions Transition Model Goal Test Path Cost Function

The Five Components of a Search Problem

As the video explained, to turn any problem into something an algorithm can solve, we must define these five components:

  1. State Space: This is the set of all possible configurations the world can be in. A state is a snapshot of the world. In the Romania example, a state is simply "being in a particular city" (e.g., In(Arad)). The collection of all states forms the state space.
  2. Initial State: The state where the agent starts. For the Romania problem, this was In(Arad).
  3. Actions: The set of possible actions available to the agent. From the state In(Arad), the actions were Go(Sibiu), Go(Timisoara), and Go(Zerind). The set of applicable actions depends on the current state.
  4. Transition Model: This defines what a new state results from performing an action in a current state. It's often called a successor function. For example, Result(In(Arad), Go(Zerind)) leads to the new state In(Zerind). Together, the initial state, actions, and transition model implicitly define the state-space graph—a map of all reachable states.
  5. Goal Test: A function that determines whether a given state is a goal state. In our example, the test is simply Is the current city Bucharest?.
  6. Path Cost: A function that assigns a numeric cost to a path. In route-finding, this could be distance, time, or fuel consumption. The goal is often to find a solution with the minimum path cost.

A solution to a search problem is not just the goal state itself, but the sequence of actions (a plan) that leads from the initial state to the goal state. An optimal solution is a solution that has the lowest path cost.

To reinforce these concepts, here is a concise article that describes the same five components.

Artificial Intelligence — Week 3. Problem Solving and ...

This article from Medium provides a clear, written summary of problem formulation and the state space representation.

Read Section 2, 'Problem Formulation and State Space Representation.' It recaps the five components we just learned and provides another clear example.


2. The Art of Abstraction

Real-world problems are incredibly complex. In our Romania example, we ignored the weather, the quality of the road, the need for fuel, and whether our agent was traveling by car or by foot. The process of removing irrelevant details and focusing only on what's necessary to solve the problem is called abstraction.

This is not just about making the problem simpler; it's about making it solvable. A good problem formulation captures all the necessary information in its state representation and cost function, while ignoring everything else.

Artificial Intelligence - 3.1 and 3.2 - Searching - Problem solving agents and Example problems

Let's return to the video to hear a brief discussion on the importance of abstraction in problem formulation.

Watch from 09:06 to 11:25. Notice how complex real-world factors like weather can be 'abstracted' away and captured within the path cost number.


3. Formulating Example Problems

The best way to master problem formulation is through practice. Let's analyze how to formalize a few classic AI problems.

Example 1: The Vacuum-Cleaner World

Imagine a simple robotic vacuum cleaner in a house with two rooms, A and B. Each room can either be dirty or clean. The vacuum can move left, move right, or suck up dirt.

Artificial Intelligence - 3.1 and 3.2 - Searching - Problem solving agents and Example problems

This video segment formulates the vacuum-cleaner world problem, showing how a simple scenario is broken down into the five components.

Watch from 11:25 to 17:36. Pay attention to how the 'state' is defined. It's not just the robot's location, but also the status of the dirt in all rooms.

Let's formally define the problem based on the video:

  • States: A state needs to capture the robot's location and the dirt status of all rooms. A state can be represented as a tuple: (robot_location, {room_A_status, room_B_status}). For example: (A, {A: Dirty, B: Clean}).
  • Initial State: Any state can be the initial state. Let's say: (A, {A: Dirty, B: Dirty}).
  • Actions: Left, Right, Suck.
  • Transition Model: Result((A, {A: Dirty, B: Dirty}), Suck) gives (A, {A: Clean, B: Dirty}). Result((A, {A: Dirty, B: Dirty}), Right) gives (B, {A: Dirty, B: Dirty}).
  • Goal Test: Are all rooms clean? E.g., is the dirt status {A: Clean, B: Clean}?
  • Path Cost: Each action costs 1.

Notice that the size of the state space grows quickly. For n rooms, there are n possible robot locations and possible dirt configurations, giving a total of states.

Example 2: The 8-Puzzle

The 8-puzzle consists of a 3x3 grid with 8 numbered tiles and one blank space. The goal is to slide the tiles to reach a target configuration.

Artificial Intelligence - 3.1 and 3.2 - Searching - Problem solving agents and Example problems

The 8-puzzle is another classic search problem. Let's see how it's formulated.

Watch from 17:24 to 21:37. Focus on how the problem is simplified by thinking of the actions as moving the blank space, rather than moving the individual tiles.

Here is the formal definition:

  • States: A specific configuration of the 8 tiles on the board. This can be represented as a 3x3 array or a flattened list.
  • Initial State: A given shuffled configuration of the board.
  • Actions: MoveBlankLeft, MoveBlankRight, MoveBlankUp, MoveBlankDown. Note that not all actions are possible in every state (e.g., you can't move the blank up if it's already in the top row).
  • Transition Model: Returns a new board configuration after sliding a tile into the blank space.
  • Goal Test: Does the current board configuration match the goal configuration?
  • Path Cost: Each move costs 1.
Test your understanding!

Let's consider a different kind of problem: Pacman.
Imagine a version of Pacman where the goal is simply to get from a starting position (x1, y1) to an ending position (x2, y2), ignoring ghosts and food.

How would you define the state for this "Pathing" problem?

Now, consider a different version: "Eat-all-dots". The goal is to eat all food pellets in the maze. How must the state representation change to handle this problem?

Show answer
  • For the "Pathing" problem: The only information needed is Pacman's location. So, a state is simply an (x, y) coordinate.

  • For the "Eat-all-dots" problem: The state must now track not only Pacman's location but also which food pellets are still remaining. A state could be represented as a tuple: ((x,y), {dot_1_eaten, dot_2_eaten, ...}), where the second element is a collection of booleans indicating the status of each food pellet. This shows that the problem's goal directly influences how you must define your state.

The resource "1.2 State Spaces and Search Problems" discusses this exact example if you'd like to read more.


4. Visualizing the Problem: State Space Graphs

We can visualize a search problem as a state-space graph. In this graph, the nodes are the states, and the directed edges between them represent the actions that transform one state into another.

State-Space Search Algorithm Flowchart
This flowchart shows the general process an algorithm follows. It starts at the initial state, checks if it's the goal, and if not, generates reachable states (successors) and continues the process, avoiding states it has already visited. This is how an algorithm explores the state-space graph.

Most search algorithms don't build this entire graph in memory at once, as it could be astronomically large. Instead, they explore it by generating a search tree. A node in a search tree represents a path from the initial state. Because there can be multiple paths to the same state, a state may appear multiple times in a search tree.

State Space Graph vs. Search Tree
This image illustrates the key difference. The state-space graph (left) is a compact representation of the problem, with each state appearing once. The search tree (right) unfolds the paths from the start node 'S', and as a result, states like 'd' and 'p' can appear multiple times. Algorithms work by building up this search tree on demand.

Conclusion

In this lesson, we laid the groundwork for solving AI problems with search. You learned how to take a real-world scenario and give it a formal structure that an algorithm can process.

Key Takeaways:

  • Problem-solving in AI can often be framed as a search for a sequence of actions.
  • To formalize a problem, you must define five components: the initial state, the available actions, a transition model, a goal test, and a path cost function.
  • Abstraction is the critical process of simplifying a problem to its essential elements.
  • The choice of state representation is crucial and depends directly on the goal of the problem.
  • A search problem can be visualized as a state-space graph, which algorithms explore by building a search tree.

Preview of the Next Lesson:

Now that we know how to formulate a search problem, how do we solve it? And how do we find the best solution efficiently? In our next lesson, we will dive into one of the most famous and powerful search algorithms: A search*. You will learn how it intelligently navigates the state space to find the optimal path.