You are on page 1of 37

Lecture 3 – Problem-Solving

(Search) Agents

Dr. Javid Ullah

Department of Computer Science


Islamabad
17 October 2022 Model College for Boys H-9, Islamabad 1
 Problem-solving agents
 Problem types
 Problem formulation
 Example problems
 Basic search algorithms

17 October 2022 2
 Suppose an agent can execute several actions
immediately in a given state
 It doesn’t know the utility of these actions
 Then, for each action, it can execute a sequence
of actions until it reaches the goal
 The immediate action which has the best
sequence (according to the performance
measure) is then the solution
 Finding this sequence of actions is called search,
and the agent which does this is called the
problem-solver.
 NB: Its possible that some sequence might fail,
e.g., getting stuck in an infinite loop, or unable
to find the goal at all.
17 October 2022 3
 You can begin to visualize the concept of a
graph
 Searching along different paths of the graph
until you reach the solution
 The nodes can be considered congruous to the
states
 The whole graph can be the state space
 The links can be congruous to the actions……

17 October 2022 4
 On holiday in Romania; currently in Arad.
 Flight leaves tomorrow from Bucharest(capital)
 Formulate goal: Be in Bucharest
 Formulate problem:
 States: various cities
 Actions: drive between cities
 Find solution:
 Sequence of cities, e.g., Arad, Sibiu, Fagaras,
Bucharest.

17 October 2022 5
17 October 2022 6
 Static: The configuration of the graph (the city map)
is unlikely to change during search

 Observable: The agent knows the state (node)


completely, e.g., which city I am in currently

 Discrete: Discrete number of cities and routes


between them

 Deterministic: Transiting from one city (node) on


one route, can lead to only one possible city

 Single-Agent: We assume only one agent searches


at one time, but multiple agents can also be used.
17 October 2022 7
 A problem is defined by five items:
1. An Initial state, e.g., “In Arad“
2. Possible actions available, ACTIONS(s) returns the set of
actions that can be executed in s.
3. A successor function S(x) = the set of all possible
{Action–State} pairs from some state, e.g., Succ(Arad) =
{<Arad  Zerind, In Zerind>, … }

4. Goal test, can be


 explicit, e.g., x = "In Bucharest
 implicit, e.g., Checkmate(x)

5. Path cost (additive)


 e.g., sum of distances, number of actions executed, etc.
 c(x,a,y) is the step cost, assumed to be ≥ 0

 A solution is a sequence of actions leading from the initial


state to a goal state.

17 October 2022 8
 States? Actions?
 Goal test? Path cost?
17 October 2022 9
 States? dirt and robot location
 Actions? Left, Right, Pick
 Goal test? no dirt at all locations
 Path cost? 1 per action
17 October 2022 10
 States?
 Actions?
 Goal test?
 Path cost?

17 October 2022 11
 States? locations of tiles
 Actions? move blank left, right, up, down
 Goal test? = goal state (given)
 Path cost? 1 per move
[Note: optimal solution of n-Puzzle family is NP-hard]

17 October 2022 12
8 2 7 SUCC(state)  subset of states

3 4 The successor function is knowledge


about the 8-puzzle game, but it does
5 1 6 not tell us which outcome to use, nor to
which state of the board to apply it.

8 2 8 2 7 8 2 7
3 4 7 3 4 6 3 4
5 1 6 5 1 5 1 6

Search is about the


exploration of alternatives
17 October 2022 13
8-Puzzle: Successor Function
8 2 7 SUCC(state)  subset of states

3 4 The successor function is knowledge


about the 8-puzzle game, but it does
5 1 6 not tell us which outcome to use, nor to
which state of the board to apply it.

8 2 8 2 7 8 2 7
3 4 7 3 4 6 3 4
5 1 6 5 1 5 1 6

Search is about the


exploration of alternatives 14
1 2 3
Start State 4 6
7 5 8

1 2 3
4 5 6
7 8

1 2 3
Goal State 4 5 6
7 8

17 October 2022 15
16
 States?: real-valued coordinates of robot
joint angles, parts of the object to be
assembled, current assembly
 Actions?: continuous motions of robot
joints
 Goal test?: complete assembly
 Path cost?: time to execute
17 October 2022 17
Across history, puzzles and games requiring the
exploration of alternatives have been
considered a challenge for human intelligence:

 Chess originated in Persia and


India about 4000 years ago
 Checkers appear in 3600-year-old
Egyptian paintings
 Go originated in China over 3000
years ago
So, it’s not surprising that AI uses games
to design and test algorithms 18
19
8 2 1 2 3 4
3 4 7
5 1 6
5 6 7 8
9 10 11 12
....
13 14 15

20
Sam Loyd offered $1,000 of his own money to
the first person who would solve the following
problem:

1 2 3 4 1 2 3 4

5 6 7 8 ? 5 6 7 8

9 10 11 12 9 10 11 12

13 14 15 13 15 14
21
Introduced (?) in 1878 by Sam Loyd, who
dubbed himself “America’s greatest puzzle-
expert”

22
Sam Loyd offered $1,000 of his own money to
the first person who would solve the following
problem:

1 2 3 4 1 2 3 4

5 6 7 8 ? 5 6 7 8

9 10 11 12 9 10 11 12

13 14 15 13 15 14
23
 Graphs:
 nodes, arcs, directed arcs, paths
 Search graphs:
 States are nodes
 operators are directed arcs
 solution is a path from start to goal
 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 24
 A solution is a path connecting the initial node to a
goal node (any one)

25
 A solution is a path connecting the initial node to a
goal node (any one)
 The cost of a path is the sum of the arc costs along
this path
 An optimal solution is a solution path of minimum
cost
 There might be
no solution !
I

26
 8-puzzle  9! = 362,880 states
 15-puzzle  16! ~ 2.09 x 1013 states
 24-puzzle  25! ~ 1025 states

But only half of these states are


reachable from any given state
(but you may not know that in advance)

27
8-puzzle  362,880 states

0.036 sec

15-puzzle  2.09 x 1013 states

~ 55 hours

24-puzzle  1025 states


> 109 years

100 millions states/sec

28
 Basic idea:
 Offline (not dynamic), simulated exploration of
state space by generating successors of already-
explored states (a.k.a. expanding the states)
 The expansion strategy defines the different
search algorithms.

17 October 2022 29
17 October 2022 30
17 October 2022 31
17 October 2022 32
 Fringe: The collection of nodes that have been
generated but not yet expanded
 Each element of the fringe is a leaf node, with
(currently) no successors in the tree
 The search strategy defines which element to
choose from the fringe

fringe
17 October 2022
fringe 33
 A state is a representation of a physical
configuration
 A node is a data structure constituting part of a
search tree includes 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.

17 October 2022 34
 A search strategy is defined by picking the order
of node expansion
 Strategies are evaluated along the following
dimensions:
 Completeness: Does it always find a solution if one
exists?
 Time complexity: Number of nodes generated
 Space complexity: Maximum number of nodes in
memory
 Optimality: Does it always find a least-cost solution?
 Time and space complexity are measured in
terms of
 b: maximum no. of successors of any node
 d: depth of the shallowest goal node
 m: maximum length of any path in the state space.
17 October 2022 35
 Uninformed Blind search
 Breadth-first
 uniform first
 depth-first
 Iterative deepening depth-first
 Bidirectional
 Branch and Bound

 Informed Heuristic search (next class)


 Greedy search, hill climbing, Heuristics

36
17 October 2022 37

You might also like