When the world is known and the right action is not obvious, an agent can search for a sequence of actions that leads to a goal.

Goal Formulation and Problem Formulation

A problem-solving agent is a goal-based agent that follows four phases. Goal formulation: decide what states are acceptable, limiting what the agent tries to achieve: for a tourist in Arad, the goal is to reach Bucharest. Problem formulation: decide which actions and states to consider. Search: look for a sequence of actions that reaches the goal, called a solution. Execution: carry out the actions of the solution, usually with the percepts ignored (open-loop) in a known, deterministic, observable environment.

Components of a Problem

A well-defined problem has five components. The initial state (In(Arad)). The actions available in each state (Go(Sibiu), Go(Zerind)). The transition model giving the result of an action (RESULT(In(Arad), Go(Zerind)) = In(Zerind)). The goal test checking if a state is a goal (In(Bucharest)). The path cost function giving each path a numerical cost, usually the sum of step costs such as distances; a solution with the lowest cost is optimal. The initial state, actions and transition model together define the state space, a graph whose nodes are states and edges are actions.

Definition: Problem-solving agent. A goal-based agent that formulates a goal and a problem, searches for a sequence of actions that reaches the goal, and then executes that sequence.

Examples of Problems

Toy problems: the vacuum world (8 states with two squares), the 8-puzzle (states = tile positions, 9!/2 = 181,440 reachable states, actions slide the blank, goal is the ordered arrangement), 8-queens and route finding. Real-world problems: airline travel planning, robot navigation, VLSI layout, assembly sequencing and protein design.

Abstraction

The real world is far too detailed, so a problem is abstracted by removing details that do not matter: a route plan ignores the scenery, the radio and the weather on the way. A good abstraction is valid (every abstract solution can be expanded into a real one) and useful (easier to solve than the original). Choosing the right abstraction is itself an art.

Search algorithms are compared by completeness (will it find a solution when one exists?), optimality (does it find the least-cost one?), time complexity and space complexity, measured by the branching factor b (maximum successors), the depth d of the shallowest goal and the maximum path length m. Unit II studies the algorithms in detail.

Table 1.7: Formulating the 8-puzzle

Component Meaning 8-puzzle
Initial state Starting configuration Any arrangement of tiles
Actions Moves Slide blank Up, Down, Left, Right
Transition model Result of a move New tile arrangement
Goal test Is it the goal? Tiles in order
Path cost Cost of solution 1 per move

Example 1.7: Formulating a route problem

Problem: A tourist in A wants to reach D. Roads: A-B (4), A-C (2), C-B (1), B-D (5), C-D (8). Formulate the problem and find the optimal path.

Solution:

  1. Initial state A; actions: move along a road; goal test: at D; step cost: road length.
  2. Candidate paths: A-B-D = 9; A-C-D = 10; A-C-B-D = 2 + 1 + 5 = 8.
  3. The least cost is 8.

Result: Optimal solution A → C → B → D with path cost 8.

import heapq
roads = {"A": {"B": 4, "C": 2}, "B": {"A": 4, "C": 1, "D": 5},
         "C": {"A": 2, "B": 1, "D": 8}, "D": {"B": 5, "C": 8}}
pq, seen = [(0, "A", ["A"])], set()
while pq:
    cost, s, path = heapq.heappop(pq)
    if s == "D":
        print("solution", path, "cost", cost)
        break
    if s in seen:
        continue
    seen.add(s)
    for n, w in roads[s].items():
        heapq.heappush(pq, (cost + w, n, path + [n]))

Output

solution ['A', 'C', 'B', 'D'] cost 8

Common mistakes

  • Searching before the goal and the problem have been formulated.
  • Using an abstraction that removes details needed for a valid solution.
  • Forgetting the goal test or the path cost in the problem definition.
  • Assuming open-loop execution works in a stochastic or unknown environment.

Key takeaways

  • Four phases: goal formulation, problem formulation, search, execution.
  • A problem has initial state, actions, transition model, goal test and path cost.
  • Solution = sequence of actions; optimal solution = least path cost.
  • Search is judged by completeness, optimality, time and space.

Practice questions

  1. List the components of a well-defined problem.
  2. What is a solution to a problem?
  3. Why is abstraction needed?

Answers to the practice questions

  1. Initial state, actions, transition model, goal test and path cost.
  2. A sequence of actions that leads from the initial state to a goal state.
  3. The real world has too much detail; abstraction removes irrelevant detail so the problem can be solved.

Sources

  • Official BCA syllabus Artificial Intelligence, course code 26BCA404DS04, Unit I