AI File - 03 PDF
AI File - 03 PDF
AI File - 03 PDF
3
Initial Simplifying Assumptions (Abstraction)
• Environment is static
– no changes in environment while problem is being solved
• Environment is observable
• Environment is deterministic
4
Problem-Solving Agents
• Intelligent agents can solve problems by searching a state-space
State-space Model
– the agent’s model of the world
– usually a set of discrete states
– e.g., in driving, the states in the model could be towns/cities
Goal State(s)
– a goal is defined as a desirable state for an agent
– there may be many states which satisfy the goal test
• e.g., drive to a town with a ski-resort
– or just one state which satisfies the goal
• e.g., drive to Dinajpur
5
Representing states
• State space:
– Includes the initial state S and all other states that are reachable from S by a
sequence of actions
– A state space can be organized as a graph:
nodes: states in the space
arcs: actions/operations
• The size of a problem is usually described in terms of the number
of states (or the size of the state space) that are possible.
– Tic-Tac-Toe has about 3^9 states.
– Checkers has about 10^40 states.
– Rubik's Cube has about 10^19 states.
– Chess has about 10^120 states in a typical game.
– GO has more states than Chess
6
The State-Space Graph
• Graphs:
– nodes, arcs, directed arcs, paths
• Search graphs:
– States are nodes
– operators are directed arcs
– solution is a path from start S to goal G
• Problem formulation:
– Give an abstract description of states, operators, initial state and goal state.
• Problem solving:
– Generate a part of the search space that contains a solution
7
State-Space Problem Formulation
A problem is defined by four items:
1. Initial state
• Formulate goal:
– be in Bucharest
• Formulate problem:
– states: various cities
– actions/operators: drive between cities
• Find solution
– By searching through states to find a goal
– sequence of cities, e.g., Arad, Sibiu, Fagaras, Bucharest
10
State-Space Problem Formulation for Traveling in Romania
1. Initial state: Arad
Geometric Version: B
A D
– a complete graph of n vertices
F
– n!/2n legal tours
– S0 = A
12
Problem Formulation: The Traveling
Salesperson Problem
1. Initial state: A C
14
State-Space problem formulation
• States?
-any arrangement of n<=8 queens
-or arrangements of n<=8 queens in leftmost n
columns, 1 per column, such that no queen
attacks any other.
• States
• Initial state
• Actions
• Goal test
• Path Cost
16
Example: Robot Assembly
20
A portion of the state space of a 8-
Puzzle problem
5 4
6 1 8
7 3 2
5 4 5 4 8
6 1 8 6 1
7 3 2 7 3 2
5 1 4 5 4
6 8 6 1 8
7 3 2 7 3 2
5 1 4
6 8
7 3 2
21
Cryptarithmetic puzzles
TWO
TWO+
FOUR
E.g., setting F = 1, O = 4, R = 8, T = 7, W = 3, U = 6
gives 734+734=1468
22
Cryptarithmetic puzzles…
TWO Trick: introduce auxiliary variables
TWO+ X, Y
FOUR O + O = 10X + R
W + W + X = 10Y + U
T + T + Y = 10F + O
O R W U T F
• You have a
faucet with an
unlimited
amount of water
• Operators
– Fill 3-gallon from faucet, fill 4-gallon from faucet
– Fill 3-gallon from 4-gallon , fill 4-gallon from 3-gallon
– Empty 3-gallon into 4-gallon, empty 4-gallon into 3-gallon
– Dump 3-gallon down drain, dump 4-gallon down drain
25
Production Rules for the Water Jug Problem
1 (x,y) (4,y) Fill the 4-gallon jug
if x < 4
7 (x,y) (4,y – (4 – x)) Pour water from the 3-gallon jug into the 4-gallon jug
if x + y ≥ 4 and y > 0 until the 4-gallon jug is full
26
The Water Jug Problem (cont’d)
8 (x,y) (x – (3 – y),3) Pour water from the 4-gallon jug into the 3-gallon jug
if x + y ≥ 3 and x > 0 until the 3-gallon jug is full
9 (x,y) (x + y, 0) Pour all the water from the 3-gallon jug into the 4-gallon
if x + y ≤ 4 and y > 0 jug
10 (x,y) (0, x + y) Pour all the water from the 4-gallon jug into the 3-gallon
if x + y ≤ 3 and x > 0 jug
27
One Solution to the Water Jug
Problem
Gallons in the 4- Gallons in the 3- Rule Applied
Gallon Jug Gallon Jug
0 0 2
0 3 9
3 0 2
3 3 7
4 2 5
0 2 9
2 0
28
Missionaries and Cannibals
There are 3 missionaries, 3 cannibals,
and 1 boat that can carry up to two
people on one side of a river.
• Goal: Move all the missionaries and
cannibals across the river.
• Constraint: Missionaries can never
be outnumbered by cannibals on either
side of river, or else the missionaries
are killed. Outnumber
• State: configuration of missionaries
and cannibals and boat on each side of
river.
• Operators: Move boat containing
some set of occupants across the river
(in either direction) to the other side.
29
Missionaries and Cannibals Solution
Near side
Far side
0 Initial setup: MMMCCC B
-
1 Two cannibals cross over: MMMC
B CC
2 One comes back: MMMCC B
C
3 Two cannibals go over again: MMM
B CCC
4 One comes back: MMMC B
CC
5 Two missionaries cross: MC
B MMCC
6 A missionary & cannibal return: MMCC B
MC 30
Recape: Formalizing Search in a State Space
• A state space is a graph, (V, E) where V is a set of nodes and E is a set of arcs, where
each arc is directed from a node to another node
• node: corresponds to a state
– state description
– plus optionally other information related to the parent of the
node, operation to generate the node from that parent, and
other bookkeeping data)
• arc: corresponds to an applicable action/operation.
– the source and destination nodes are called as parent
(immediate predecessor) and child (immediate successor)
nodes with respect to each other
– ancestors( (predecessors) and descendents (successors)
– each arc has a fixed, non-negative cost associated with it,
corresponding to the cost of the action
31
Tree-based Search
• Basic idea:
– Exploration of state space by generating successors of already-
explored states (a.k.a. expanding states).
– Every state is evaluated: is it a goal state?
• In practice, the solution space can be a graph,
not a tree
– E.g., 8-puzzle
– More general approach is graph search
– Tree search can end up repeatedly visiting the same nodes
• Unless it keeps track of all nodes visited
• …but this could take vast amounts of memory
32
Tree search example
33
Tree search example
34
Tree search example
35
Tree search example
This “strategy” is
what differentiates
different search
algorithms
36
States versus Nodes
• A state is a (representation of) a physical configuration
• A node is a data structure constituting part of a search tree contains info such as: state, parent node,
action, path cost g(x), depth
• The Expand function creates new nodes, filling in the various fields and using the SuccessorFn of
the problem to create the corresponding states.
State Spaces versus Search Trees
• State Space
– Set of valid states for a problem
– Linked by operators
– e.g., 20 valid states (cities) in the Romanian travel problem
• Search Tree
– Root node = initial state
– Child nodes = states that can be visited from parent
– Note that the depth of the tree can be infinite
• E.g., via repeated states
– Partial search tree
• Portion of tree that has been expanded so far
– Fringe
• Leaves of partial search tree, candidates for expansion
39
Search Strategies
• A search strategy is defined by picking the order of node
expansion
40
Why Search can be hard
Assuming b=10, 1000 nodes/sec, 100 bytes/node
Depth of Nodes to
Solution Expand Time Memory
41
Next Topics
• Uninformed search
– Breadth-first, depth-first
– Uniform cost
– Iterative deepening
43