You are on page 1of 33

TAI2151 – Artificial

Intelligence Fundamentals
LECTURE 3 – SOLVING PROBLEMS
BY SEARCHING (UNINFORMED
SEARCHES)
PART 1
Solving Problems By Searching – Uninformed Searches
Searching
 Problems with search can be converted to graph search problems
(graph-> tree)
 Graph search problem include the following terms:
 A set of states
 Initial state
 Goal condition
 Operators (define valid moves between states
 Two types of search:
 Configuration search: solution is a state satisfying the goal condition
 Path search: solution is a path to a goal state
 Optimal solution: solution with optimal value (the best)

Solving Problems By Searching – Uninformed Searches


Searching
 Search: explore the state space (problem space)
through successive application of operators from the
initial state and goal testing (test to check whether
goal is reached)
 Search process: building a tree with nodes
representing the states, path representing the
searching from initial state to the goal

Solving Problems By Searching – Uninformed Searches


Problem-Solving Agents
Problem-Solving agent is one that “has the ability to find
sequences of actions leading to desirable states.”
[Russell & Norvig]

 Or known as goal-based agent


 Goal formulation (final state)
 E.g.: I have a meeting at 3pm in Cyberjaya campus. I am now in Melaka campus. My
goal is to reach KL before 3pm.
 Problem formulation (actions & set of states)
 Actions: move forward, backward, turn left, turn right
 State: Ayer Keroh toll, Putrajaya toll etc
 Search (solution)
 Define all the possible states to reach the goal state
 Examining the future actions when a state is chosen
 Execution (follows states in solution)

Solving Problems By Searching – Uninformed Searches


A simple problem-solving agent

Solving Problems By Searching – Uninformed Searches


Well-defined problems and solutions
 A problem can be defined by four components:
 The initial state
 Theset of possible actions available to the
agent. Most common is successor function.
Successor-Fn(x) returns a set of <action,
successor> ordered pairs.
 The goal test
 The path cost function (the path cost function
is often denoted by g.)

Solving Problems By Searching – Uninformed Searches


Example (Tic Tac Toe)

 Initial state: empty 3*3 matrix


 Set of possible actions
 Path cost:
 if X win, label 1
 If O win, label -1
 If fair, label 0
 This path cost allows the agent to count the cost and decide which is
the best move
 Successor function: action set pair that is fair~ X [1,1] O
[1,2]X[2,2]O[3,3]X[2,1]O[2,3]X[1,3]O[3,1]X[3,2
] Fair
 Goal state: X win; O win; fair

Solving Problems By Searching – Uninformed Searches


Example (Tic Tac Toe)

 Successor function: action set pair that is fair~ X [1,1] O


[1,2]X[2,2]O[3,3]X[2,1]O[2,3]X[1,3]O[3,1]
X[3,2] Fair
 Goal state: X win; O win; fair

Solving Problems By Searching – Uninformed Searches


What’s a solution?
 Solution (path) – a sequence of actions leading from the
initial state to a goal state.
Path in the graph = branch in
the search tree

Solving Problems By Searching – Uninformed Searches


Problem formulation: Arad to Bucharest

Such as: Zerind, Sibiu,


Timiosoara etc

Solving Problems By Searching – Uninformed Searches


Problem formulation: Arad to
Bucharest

Search methods can differ in how


they explore the problem space, i.e.
how they choose the node to expand
next

Solving Problems By Searching – Uninformed Searches


Example:A simplified road map of Romania

Solving Problems By Searching – Uninformed Searches


Example Problems
 Toy problems
 The 8-puzzle
 The 8-queen/n-queens
 Cryptarithmetic

 The vacuum world


 Missionaries and cannibals
 Real-world problems
 Route finding
 Touring and travelling salesperson (NP-hard)
 VLSI layout
 Robot navigation
 Assembly sequencing

Solving Problems By Searching – Uninformed Searches


The 8-puzzle problem: 3x3 board with 8 tiles & 1 blank

"move the blank up, down, left or right" than specifying actions that move
the individual tiles or the tiles in a particular location because the
branching factor of the search will be much less.”
Solving Problems By Searching – Uninformed Searches
Formulating problems:
The 8-puzzle problem

 States: a state description specifies the location of


each of the eight tiles in one of the nine squares.
 Operators: blank moves left, right, up, or down.
 Goaltest: state matches the goal configuration
shown in the right.
 Path: each step costs 1, so that the path cost is just
the length of the path.

Solving Problems By Searching – Uninformed Searches


The 8-queens problem

 The objective is to place eight queens on a chessboard such that


no queen threatens (attacks) another.
 A queen threatens (attacks) another queen in the same row,
column or in diagonal

In this example, the two queens


on the corners are the only
queens threatening each other.

Goal test: 8 queens on board, none attacked.


Path cost: zero (why???)
Solving Problems By Searching – Uninformed Searches
The 8-queens problem continued ...
Initial state: an empty 6*6 chessboard
 The states and operators
Actions/operators: addfor this toproblem
a queen could
any empty squarebe:
State space: any arrangement of 0-8 queens on the chessboard
 States: any arrangement of 0 to 8 queens on the board.
Goal: 6 queens on the chessboard without attacking each other
Solution:
 Operators: add position of queens
a queen to any square.
 This is a bad choice because there are
64x63x62x61x60x59x58x57 ≈ 1.8x1014 possible sequences to
investigate.
 A better formulation would be to choose a smarter operator that
 States: any arrangement of 0 to 8 queens on the board.
 Operators: place a queen in the left-most empty column
such that it is not attacked by any other queen.
 Now there are only 2057 possible sequences to investigate.

Solving Problems By Searching – Uninformed Searches


The vacuum world: Problem formulation

Solving Problems By Searching – Uninformed Searches


Solving Problems By Searching – Uninformed Searches
Real-World Problems
 Route finding
 routing in computer networks,
 automated travel advisory systems,
 airline travel planning systems
 Touring and travelling salesperson problems
 TSP - “ Visit every city exactly once, starting and ending in the
same city.”
 VLSI layout
 Robot navigation: know its own position, and determine the path to
move on
 Assembly sequencing (DNA sequencing)

Solving Problems By Searching – Uninformed Searches


A Toy Example: A Romanian Holiday
 The route-finding problem from Arad to Bucharest

 State space: Cities in Romania


 Initial state: Arad.
 Goal : Bucharest
 Operators: Drive between cities
 Solution: Sequence of cities
 Path cost: number of cities, distance, time, fuel

Solving Problems By Searching – Uninformed Searches


The state space

Solving Problems By Searching – Uninformed Searches


Search Algorithms: Formulating the Problems
 Basic Idea: Offline exploration of state space by
generating successors of already-explored states (also
known as expanding states).

Solving Problems By Searching – Uninformed Searches


Search Algorithms - Implementation

Solving Problems By Searching – Uninformed Searches


Tree Search Example

Solving Problems By Searching – Uninformed Searches


Tree search example (cont.)

Solving Problems By Searching – Uninformed Searches


Tree search example (cont.)

Solving Problems By Searching – Uninformed Searches


The solution

Solving Problems By Searching – Uninformed Searches


States

 A state is a (representation of a)
physical configuration.
 States do not have parents, children,
depth, or path cost!

Solving Problems By Searching – Uninformed Searches


Nodes
 A node constituting part of a search tree includes parent, children,
depth, path cost g(n)
 Node is a data structure with five components:
 the state in the state space to which the node corresponds;
 the node in search tree that generated this node (this is called the
parent node);
 the operator that was applied to generate the node;
 the number of nodes on the path from the root to this node (the
depth of the node);
 the path cost of the path from the initial state to the node.
Datatype node
components: STATE, PARENT-NODE, OPERATOR, DEPTH, PATH-COST

Solving Problems By Searching – Uninformed Searches


Nodes and States continued ...
 Node is a data structure to represent search tree for a particular problem
 State represents a configuration of the world
 Fringe or frontier
 A collection of nodes that are waiting to be expanded
 A set of nodes can be represented as a queue with following operations
 MAKE-QUEUE(element,…) creates a queue with the given elements
 EMPTY?(queue) returns true if there are no more elements in the queue.
 FIRST(queue) returns the first element of the queue.
 REMOVE-FIRST(queue) returns FIRST(queue) and removes it.
 INSERT(element, queue) inserts an element into the queue and returns the
queue.
 INSERT-ALL(elements, queue) inserts a set of elements into the queue and
returns the queue.

Front Back

Solving Problems By Searching – Uninformed Searches


Nodes vs. States

Search tree node: a data structure that is part of a search tree


Expand node function: apply operators to the state (in this e.g., move
left/right/up/down)

Solving Problems By Searching – Uninformed Searches


Uninformed Search Strategies
Uninformed (blind) strategies use only the information
available in the problem definition vs. informed search
techniques which might have additional information (e.g. a
compass).
 Search
 Breadth-first search
 Uniform-cost search
 Depth-first search
 Depth-limited search
 Iterative deepening search
 Bidirectional search
 Constraint Satisfaction Search (Not covered!)
Solving Problems By Searching – Uninformed Searches

You might also like