Professional Documents
Culture Documents
CS361
Contanct: ammohammed@msa.edu.eg
Room: D213
Formulating Problem as a Labeled Graph
In the graph
• Each node represents a possible state
• A node is designated as the initial state
• One or more nodes represent goal states, states in which the agent’s goal
is considered accomplished
• Each edge represents a state transition caused by a specific agent action
• Associated to each edge is the cost of performing that transition
Search Graph
Search space: set of states reachable from an initial state S0 via a (possibly
empty/finite/infinite) sequence of state transitions.
To achieve the problem’s goal
1. Search the space for a (ideally optimal) sequence of transitions
starting from S0 and leading to a goal state
Ø There are 9! Possible states (all permutations of tiles including the blank).
Example: 8-Puzzel Problem
q How can an artificial agent represent the states and the state space for this problem?
If the empty space is at position (r, c), OPr,c,d moves it in the direction of d
Example: 8-Puzzel Problem
Effects: A[3, 3] = 0
Better Formulation
States: each represented by a pair (A, (i, j)) where:
• A is an array of size 3×3 of numbers in [0...8]
• (i, j) is the position of the empty space (0) in the array
Example: 8-Puzzel Problem
Better Formulation
Operators: 4 operators of the form OP d where d ∈ {L, R, U, D} OPd moves
the empty space in the direction d
Example: 8-Puzzel Problem
Representation 1
States: any placement of 0–8 queens.
Operators: place a queen on the board.
Problem: Too many states
Example: 8-Queen Problem
Representation 2
States: 0–8 on board, all safe.
Operators: place one queen per column
starting from left.
Problem: few state (2057), but sometimes
dead-end
Example: 8-Queen Problem
Representation 3
States: 8 queens on board, one per column.
Operators: move a queen under attack in the same column.
Graph Search
Graph Search
For 1 ≤ i < j ≤ k + 1,
• Ni is a ancestor of Nj; Nj is a descendant of Ni
A graph is cyclic if it has a path starting and ending with the same
node. Ex: ⟨(A,D),(D,E),(E,A)⟩
From Search Graphs to Search Trees
Note:
• must remember which nodes have been visited
• a node may get duplicated several times in the tree
Searching Concepts
§ A State can be expanded by generating all states that can be reached by applying a
legal operator to the state.
§ State space can also be defined by a successor function that returns all states
produced by applying a single legal operator.
§ A search Tree is generated by generating search nodes by successively expanding
states starting from the initial state as the root.
Tree Search Algorithm
We need to represents the set of nodes that have been generated but not yet expanded-
Called Fringe ( a data Structure )
Tree Search Algorithm
Example:
Tree Search Algorithm
Example:
Example: