Lecture 02
Problem Solving
Tooba Mehtab
Outline
•
What is search?
•
Problem-solving agents
•
Example problems
(Toy problems & Real world problems)
3
Problem Solving by Search
•
An important aspect of intelligence is
goal-based
problem solving.
•
The solution of many problems can be
described by finding a
sequence of actions
that lead to a
desirable goal
.
•
Each
action
changes the state and the aim is
to find the
sequence of actions
and states that
lead from the
initial
(start) state to a
final
Agent
•
An agent:
•
Perceives and acts
•
Selects actions that maximize its utility
function
•
Has a goal
Environment:
Reflex Agents
•
Reflex agents
:
•
Choose action based on current percept (and
maybe memory)
•
Do not consider the
future consequences
of their actions
Goal Based Agents
•
Goal-based agents:
•
Plan ahead
•
Ask “what if”
•
Decisions based on
consequences of actions
•
Must have a model of
how the world evolves in response to actions
Problem Space / State Space
•
Input
-Set of states
-Successor Function [and costs - default to 1.0]
-Start state
-Goal state [test]
•
Output
Example: Simplified Pac-Man
•
Input:
•
A state space
•
A successor function
•
A start state
•
A goal test
Ex: Route Planning: Romania à
Bucharest
•
Input:
-Set of states
-Operators [and costs]
-Start state
-Goal state (test)
What is in State Space?
•
A
world state
includes every details of the
environment
State Space Sizes?
•
World states:
•
Pacman positions: 10 x 12 = 120
•
Pacman facing: up, down, left, right
•
Food Count: 30
•
How many?
•
World State:
•
120*(230)*(122)*4
•
States for Pathing:
•
120
•
States for eat-all-dots:
State Space Graphs
•
State space graph:
•
Each node is a state
•
The successor function is represented by arcs
•
Edges may be labeled with costs
Search Trees
•
A search tree:
•
Start state at the root node
•
Children correspond to successors
•
Nodes contain states, correspond to PLANS to those states
•
Edges are labeled with actions and costs
States vs. Nodes
•
Nodes in state space graphs are problem states
-Represent an abstracted state of the world
-Have successors, can be goal / non-goal, have multiple predecessors
•
Nodes in search trees are plans
-Represent a plan (sequence of actions) which results in the nodeʼs state
-Have a problem state and one parent, a path length, a depth & a cost
-The same problem state may be achieved by multiple search tree
Problem Definition
•
Initial state : starting point
•
Operator: description of an action
•
State space: all states reachable from the initial state
by any sequence action
•
Path: sequence of actions leading from one state to
another
•
Goal test: which the agent can apply to a single state
description to determine if it is a goal state
•
Path cost function: assign a cost to a path which the
There are
THREE
general categories of problems
in AI:
•
Single-agent
path-finding problems.
•
Two-player
games.
•
Constraint satisfaction problems.
•
In these problems, in each case, we have a single problem-solver
making the decisions, and the task is to find a sequence of
primitive steps that take us from the initial location to the goal
location.
•
Famous examples:
–
Rubik’s Cube (Erno Rubik, 1975).
–
Sliding-Tile puzzle.
–
Navigation - Travelling Salesman Problem.
•
In a two-player game, one must consider the moves of
an opponent, and the ultimate goal is a strategy that
will guarantee a win whenever possible.
•
Two-player perfect information have received the
most attention of the researchers till now. But,
nowadays, researchers are starting to consider more
complex games, many of them involve an element of
chance.
•
The best Chess, Checkers, and Othello players in the
world are computer programs!
•
In these problems, we also have a single-agent making all the
decisions, but here we are not concerned with the sequence
of steps required to reach the solution, but simply the
solution itself.
•
The task is to identify a state of the problem, such that all the
constraints of the problem are satisfied.
•
Famous Examples:
–
Eight Queens Problem.
–
Map Coloring.
•
Goals help organize behavior by limiting the
objectives that the agent is trying to achieve.
•
The agent’s task is to find out which sequence of
actions will get it to a goal sate.
•
Goal formulation, based on the current situation
and the agent’s performance measure, is the first
step in problem solving.
•
Problem formulation: the process of deciding what
actions and states to consider , given a goal.
•
In the example
-actions: driving from one major town to another
-states: being in a particular town
•
The process of looking for a
sequence
that leads to a
goal state is called search.
•
A search algorithm takes a
problem
as input and
returns a solution in the form of an action sequence.
•
Once a solution is found, the actions it recommends
can be carried out. This is called the execution
phase.
•
Thus, we have a simple “formulate, search, execute”
design for the agent.
•
Goal formulation is the first step in problem solving.
•
Then we need the problem formulation which is defined by
four components:
-Initial state
-Successor function (or operator)
-Goal test
-Path cost
•
A solution to a problem is a path from the initial
state to a goal state.
•
Solution quality is measured by the path cost
function and an optimal solution has the lowest
path cost among all solutions.
•
TOY PROBLEM
-Intended to illustrate or exercise various problem-solving
methods.
-Concise, exact description
-Can be used to compare performance of algorithms
•
REAL-WORLD PROBLEM
-Whose solutions people actually care about
-They tend not to have a single agreed upon description
•
Consist of a 3x3 board with 8 numbered tiles and blank
spaces.
•
Tile adjacent to the blank space can slide into the space.
•
Objective: reach a specified goal state.
An instance
The 8-Puzzle (State Space)
A portion of the
state space
Place 8-queens on a chessboard such that no queen
attacks any other.
Two main kinds of formulation
1- Complete-state formulation
Starts with all 8 queens on the board and moves them
around.
2-Incremental formulation:
-States: Any arrangement of 0 to 8 queens on the board
-Initial state: no queens on the board
-Successor function: Add a queen to any empty square
-Goal test: 8 queens are on the board, none attacked.
( possible states to
investigate.)
Some of the real world problems are,
•
Route finding problem
•
Touring problems
•
Travelling salesperson problem
•
VLSI layout problem
•
Robot navigation
•
Automatic assembly sequencing
•
Drug Design
•
Protein Design
•
Internet searching
Route finding problem
• States
– locations
• Initial state
– starting point
• Successor function (operators)
– move from one location to another
• Goal test
– arrive at a certain location
• Path cost
– may be quite complex
• money, time, travel comfort,
scenery,
Car Navigation
Routing in Computer
Routing Finding Problem
What is the state space for each of them?
Travel Salesperson Problem
• States
– locations / cities
– illegal states
• each city may be visited only once
• visited cities must be kept as state
information
• Initial state
– starting point
– no cities visited
• Successor function (operators)
– move from one location to another one
• Goal test
– all locations visited
– agent at the initial location
• Path cost
VLSI layout Problem
(very-large-scale-integration)
• States
– positions of components, wires on a chip
• Initial state
– incremental: no components placed
– complete-state: all components placed (e.g.
randomly, manually)
• Successor function (operators)
– incremental: place components, route wire
– complete-state: move component, move wire
• Goal test
– all components placed
– components connected as specified
• Path cost
– maybe complex
Robot Navigation
• States
– locations
– position of actuators
• Initial state
– start position (dependent on the task)
• Successor function (operators)
– movement, actions of actuators
• Goal test
– task-dependent
• Path cost
– maybe very complex
Automatic Assembly Sequencing
• States
– location of components
• Initial state
– no components assembled
• Successor function (operators)
– place component
• Goal test
– system fully assembled
• Path cost
Representation of Nodes
•
A node is a data structure with five components
–
State: the state in the state space that the node corresponds
–
Parent-node: the node in the search tree that generated this node
–
Action: the action that was applied to the parent to generate the node
–
Path-cost: cost of the path from initial state to the node
–
Depth: The number of steps along the path from the root.
-Node: bookkeeping data
structure to represent a
search tree
-State: corresponds to the
•
A search strategy is defined by picking the order of node
expansion
•
Strategies are evaluated along the following dimensions:
–
Completeness: Is the algorithm guaranteed to find a solution when
there is one?
–
Optimality: Does the strategy finds the optimal solution
–
Time complexity: How long does it take to find a solution?
–
Space complexity: How much memory is needed to perform the
search?
•
Time and space complexity are measured in terms of
–
b: maximum branching factor of the search tree
–
d: depth of the least-cost solution
–
m: maximum depth of the state space (may be ∞)
1.
Define in your own words the following terms: state, state space, search
tree, search node, goal, action, transition model, and branching factor.
2.
What’s the difference between a world state, a state description, and a
search node? Why is this distinction useful?
3.
Explain why problem formulation must follow goal formulation.
4.
Give a complete problem formulation for each of the following. Choose a
formulation that is precise enough to be implemented.
a) Using only four colors, you have to color a planar map in such a way that no two adjacent regions have the same color.
b) A 3-foot-tall monkey is in a room where some bananas are suspended from the 8-foot ceiling. He would like to get the bananas. The room contains two stackable, movable, climbable 3-foot-high crates.
c) You have a program that outputs the message “illegal input record” when fed a certain file of input records. You know that processing of each record is independent of the other records. You want to discover what record is illegal.
d) You have three jugs, measuring 12 gallons, 8 gallons, and 3 gallons, and a water faucet. You can fill the jugs up or empty them out from one to another or onto the ground. You need to measure out exactly one gallon.
5. The missionaries and cannibals problem is usually stated as follows. Three missionaries and three cannibals are on one side of a river, along with a boat that can hold one or two
people. Find a way to get everyone to the other side without ever leaving a group of missionaries in one place outnumbered by the cannibals in that place. This problem is famous in AI because it was the subject of the first paper that approached problem formulation from an analytical viewpoint (Amarel, 1968).
a) Formulate the problem precisely, making only those distinctions necessary to ensure a valid solution. Draw a diagram of the complete state space.
b) Implement and solve the problem optimally using an appropriate search algorithm. Is it a good idea to check for repeated states?
c) Why do you think people have a hard time solving this puzzle, given that the state space is so simple?
6. An action such as Go(Sibiu) really consists of a long sequence of finer-grained actions: turn on the car, release the brake, accelerate forward, etc. Having composite actions of this kind reduces the number of steps in a solution sequence, thereby reducing the search time. Suppose we take this to the logical extreme, by making super-composite actions out of every possible sequence of Go actions. Then every problem instance is solved by a single supercomposite action, such as Go(Sibiu)Go(Rimnicu Vilcea)Go(Pitesti)Go(Bucharest).
Explain how search would work in this formulation. Is this a practical approach for speeding up problem solving?