Problem Formulation
Prerequisites
- Agents & Environments — Understanding of agents, percepts, and actions
- Agent Types — Goal-based agents and their decision-making process
🎯 Learning Objectives
- Define the five components of a well-defined problem
- Formulate real-world problems as formal search problems
- Distinguish between incremental and complete-state formulations
- Apply problem formulation to classic AI examples: 8-puzzle, Romania map, 8-queens
- Solve GATE-style problems on mapping real-world scenarios to formal representations
1. Why Problem Formulation Matters
Before an AI agent can search for a solution, it must understand what the problem is. Problem formulation is the process of deciding what actions and states to consider, given a goal. It is the bridge between the real world and the abstract world where algorithms operate.
Consider a GPS navigation system. The real world has millions of details—trees, buildings, traffic lights, pedestrians. But for route planning, the agent only cares about intersections (states) and roads (actions). This abstraction—ignoring irrelevant details—is the essence of problem formulation.
GATE problems frequently ask you to identify the initial state, goal test, or state space size for a given problem description. Being able to formally specify these components is essential for answering questions on any search algorithm.
2. The Five Components of a Well-Defined Problem
A well-defined problem is specified by exactly five components:
- Initial State: The state in which the agent starts. Denoted s0.
- Actions: The set of possible actions available to the agent in state s. Written as ACTIONS(s).
- Transition Model: A description of what each action does. RESULT(s, a) returns the state that results from doing action a in state s. Together, the initial state, actions, and transition model define the state space—the set of all states reachable from the initial state by any sequence of actions.
- Goal Test: Determines if a given state is a goal state. Can be explicit (a set of goal states) or implicit (a property to check).
- Path Cost: A function that assigns a numeric cost to each path. Typically the sum of step costs: c(s, a, s′) for going from state s to s′ via action a. The agent seeks a minimum cost path.
A solution to a problem is a sequence of actions that leads from the initial state to a goal state. An optimal solution has the lowest path cost among all solutions.
| Component | Notation | What It Answers |
|---|---|---|
| Initial State | s0 | Where do we start? |
| Actions | ACTIONS(s) | What can we do in state s? |
| Transition Model | RESULT(s, a) | Where does action a take us from s? |
| Goal Test | GOAL-TEST(s) | Is state s a goal? |
| Path Cost | g(path) = ∑ c(s, a, s′) | How expensive is this path? |
3. Worked Example 1: The 8-Puzzle
The 8-puzzle consists of a 3×3 grid with tiles numbered 1–8 and one blank space. Tiles adjacent to the blank can slide into the blank position. The goal is to reach a specific target configuration.
- States: Each state describes the location of each of the eight tiles and the blank in one of the nine squares. Total states = 9! / 2 = 181,440 reachable states (half of 9! = 362,880 because only half the permutations are reachable from any given state).
- Initial State: Any specific arrangement of tiles on the board.
- Actions: The blank can move {Left, Right, Up, Down}. Not all actions are available in every state (e.g., the blank in the top-left corner cannot move Left or Up).
- Transition Model: RESULT(s, a) returns the board configuration after moving the blank in direction a.
- Goal Test: Does the current configuration match the goal configuration? (Explicit goal.)
- Path Cost: Each move costs 1. Total path cost = number of moves.
We model the blank as the agent that moves (Left, Right, Up, Down), even though visually it’s the tiles that slide. This simplifies the action set to at most 4 actions per state.
4. Worked Example 2: Romania Road Map
This is the classic textbook example. An agent is in Arad and wants to reach Bucharest by driving through Romanian cities connected by roads.
- States: The set of all cities in Romania: {Arad, Zerind, Sibiu, Timisoara, Oradea, Fagaras, Rimnicu Vilcea, Pitesti, Bucharest, Giurgiu, Craiova, Drobeta, Mehadia, Lugoj, …}
- Initial State: In(Arad).
- Actions: Drive from one city to an adjacent city. ACTIONS(In(Arad)) = {Go(Zerind), Go(Sibiu), Go(Timisoara)}.
- Transition Model: RESULT(In(Arad), Go(Zerind)) = In(Zerind).
- Goal Test: Is current state = In(Bucharest)? (Explicit, single goal state.)
- Path Cost: Sum of road distances in kilometers. For example, Arad → Sibiu costs 140 km.
This problem illustrates that actions have different costs (unlike the 8-puzzle where every step costs 1). The optimal solution must minimize total distance, not just the number of cities visited.
5. Worked Example 3: The 8-Queens Problem
Place 8 queens on a standard 8×8 chessboard so that no two queens attack each other (no two share the same row, column, or diagonal).
5.1 Incremental Formulation
Start with an empty board, place queens one at a time:
- States: Any arrangement of 0–8 queens on the board.
- Initial State: Empty board (0 queens placed).
- Actions: Place a queen in any empty square.
- Transition Model: Returns the board with one more queen added.
- Goal Test: 8 queens on the board, none attacking each other.
- Path Cost: Irrelevant—we only care about finding a goal state, not the path to it.
This naïve formulation has 64 × 63 × … × 57 ≈ 1.8 × 1014 possible sequences. We can do much better.
5.2 Improved Incremental Formulation
Since no two queens can share a row, place one queen per row, left to right:
- States: Arrangements of k queens (0 ≤ k ≤ 8), one per row in the first k rows, with no mutual attacks.
- Actions: Add a queen to any non-attacked square in the next empty row.
- State-space size: Only 2,057 states to check!
5.3 Complete-State Formulation
Start with all 8 queens on the board (one per column) and iteratively improve:
- States: All arrangements of 8 queens, one per column.
- Initial State: All 8 queens randomly placed (one per column).
- Actions: Move a queen within its column.
- Goal Test: No two queens attack each other.
This is the approach used by local search algorithms like hill climbing and simulated annealing.
Incremental: Build the solution piece by piece from scratch. Suitable for systematic search (BFS, DFS).
Complete-State: Start with a complete (possibly incorrect) assignment and modify it. Suitable for local search (hill climbing, genetic algorithms). GATE may ask you to distinguish these!
6. Real-World to Formal Problem Mapping
Many GATE questions describe a real-world scenario and ask you to formulate it. The key is abstraction—remove irrelevant details while keeping enough structure to solve the problem.
Example A: Route Planning
| Real World | Formal Problem |
|---|---|
| Cities, intersections | States |
| Roads connecting cities | Actions |
| Driving on a road | Transition model |
| “Am I at the destination?” | Goal test |
| Distance / travel time | Path cost |
Example B: Robotic Assembly
| Real World | Formal Problem |
|---|---|
| Joint angles of robot arm, positions of parts | States |
| Rotate joint, move gripper, grasp part | Actions |
| Physics simulation of robot motion | Transition model |
| Is the product assembled correctly? | Goal test |
| Total time or energy consumed | Path cost |
Example C: Missionary-Cannibal Problem
Three missionaries and three cannibals must cross a river using a boat that holds at most two people. If cannibals ever outnumber missionaries on either bank, the missionaries get eaten.
- State: (ML, CL, B) where ML = missionaries on left bank, CL = cannibals on left bank, B = boat position (L or R). MR = 3 − ML, CR = 3 − CL.
- Initial State: (3, 3, L)—all on left bank, boat on left.
- Actions: Move 1 or 2 people (any combination of M and C) across the river, subject to constraints: ML ≥ CL (or ML = 0) and MR ≥ CR (or MR = 0).
- Goal Test: State = (0, 0, R).
- Path Cost: Number of crossings.
- State Space Size: 4 × 4 × 2 = 32 possible states, but only about 16 are legal.
7. The Role of Abstraction
A good problem formulation abstracts away irrelevant details. For the Romania road map, we ignore road conditions, weather, driving speed variations, and traffic. The resulting abstraction must satisfy two conditions:
- Validity: Any abstract solution can be expanded into a solution in the real world.
- Usefulness: Each abstract action should be “easy” to carry out (easier than the original problem).
Finding the right level of abstraction is more art than science, but critical for efficient problem solving.
8. GATE Practice Problems
Q: The 15-puzzle (4×4 grid with tiles 1–15 and one blank) has how many reachable states?
A: Total permutations = 16! = 20,922,789,888,000. Only half are reachable from any given starting state, so the answer is 16!/2 = 10,461,394,944,000 (≈ 1.05 × 1013).
Q: For the 8-puzzle, the branching factor (average number of actions per state) is approximately?
A: The blank in a corner has 2 moves, on an edge has 3 moves, in the center has 4 moves. There are 4 corners, 4 edges, and 1 center. Average = (4×2 + 4×3 + 1×4) / 9 = (8 + 12 + 4) / 9 = 24/9 ≈ 2.67.
Q: In the missionary-cannibal problem, if we start at (3, 3, L), which of the following is NOT a valid action?
• Move 1 missionary and 1 cannibal to right
• Move 2 cannibals to right
• Move 2 missionaries to right
A: Move 2 missionaries to right: Left bank becomes (1, 3, R). Since ML=1 < CL=3 and ML ≠ 0, missionaries get eaten. Invalid!
Move 1M+1C: Left=(2,2,R), valid. Move 2C: Left=(3,1,R), valid (ML=3 ≥ CL=1 and MR=0 on right).
9. Common Mistakes
- Confusing states and actions. A state is a snapshot of the world; an action is a transition between states.
- Forgetting path cost. If all step costs are 1, you can sometimes ignore it, but GATE loves weighted problems.
- Overcounting state space. In the 8-puzzle, only half of all permutations are reachable. In the 8-queens, not all 648 placements are legal.
- Mixing incremental and complete-state approaches in the same formulation.
Summary
- A problem is defined by five components: initial state, actions, transition model, goal test, path cost.
- The state space is the set of all states reachable from the initial state via valid actions.
- Incremental formulation builds a solution from scratch; complete-state formulation starts with a full assignment and modifies it.
- Good formulation requires abstraction—removing irrelevant details while preserving solvability.
- Classic examples: 8-puzzle (181,440 reachable states), Romania map (weighted graph), 8-queens (2,057 states with improved formulation).
References
- Russell, S. & Norvig, P. Artificial Intelligence: A Modern Approach, Chapter 3.1–3.2.