Uninformed Search: Some Material Adopted From Notes and Slides by Marie Desjardins and Charles R. Dyer
Uninformed Search: Some Material Adopted From Notes and Slides by Marie Desjardins and Charles R. Dyer
Uninformed Search
Chapter 3
Some material adopted from notes and slides by Marie desJardins and Charles R. Dyer
Todays class
Goal-based agents Representing states and operators Example problems Generic state-space search algorithm Specific algorithms
Breadth-first search Depth-first search Uniform cost search Depth-first iterative deepening
Initial state
Actions
Goal state
The actions are largely problem-specific and determined (intelligently ;-) ) by the system designer. There usually are multiple action sets for solving the same problem. Lets look an example
8-Puzzle
Given an initial configuration of 8 numbered tiles on a 3 x 3 board, move the tiles in such a way so as to produce a desired goal configuration of the tiles.
Representing actions
The number of actions / operators depends on the representation used in describing a state.
In the 8-puzzle, we could specify 4 possible moves for each of the 8 tiles, resulting in a total of 4*8=32 operators. On the other hand, we could specify four moves for the blank square and we would only need 4 operators.
Representing states
What information is necessary to encode about the world to sufficiently describe all relevant aspects to solving the goal? That is, what knowledge needs to be represented in a state description to adequately describe the current state or situation of the world? The size of a problem is usually described in terms of the number of states that are possible. The 8-puzzle has 181,440 states. Tic-Tac-Toe has about 39 states. Rubiks Cube has about 1019 states. Checkers has about 1040 states. Chess has about 10120 states in a typical game.
Real-world problems
8-Puzzle
Given an initial configuration of 8 numbered tiles on a 3 x 3 board, move the tiles in such a way so as to produce a desired goal configuration of the tiles.
8-Puzzle
State Representation: 3 x 3 array configuration of the tiles on the board. Operators: Move Blank Square Left, Right, Up or Down.
This is a more efficient encoding of the operators than one in which each of four possible moves for each of the 8 distinct tiles is used.
Initial State: A particular configuration of the board. Goal: A particular configuration of the board.
Cryptarithmetic
Find an assignment of digits (0, ..., 9) to letters so that a given arithmetic expression is true. examples: SEND + MORE = MONEY and
FORTY Solution: + TEN + TEN ----SIXTY F=2, O=9, R=7, etc. 29786 850 850 ----31486
Cryptarithmetic
State: mapping from letters to digits Initial State: empty mapping Operators: assign a digit to a letter
Find an assignment of digits to letters so that a given arithmetic expression is true. examples: SEND + MORE = MONEY and
FORTY Solution: + TEN + TEN ----SIXTY F=2, O=9, R=7, etc. 29786 850 850 ----31486
Goal Test: whether the expression is true given the complete mapping
Note: In this problem, the solution is NOT a sequence of actions that transforms the initial state into the goal state; rather, the solution is a goal node that includes an assignment of a digit to each letter in the given problem.
Remove 5 Sticks
Given the following configuration of sticks, remove exactly 5 sticks in such a way that the remaining configuration forms exactly 3 squares. State: ? Initial State: ? Operators: ? Goal Test: ?
Initial State: ?
Operators: ?
Goal State: ?
Name
State = (x,y), where x is the number of gallons of water in the 5-gallon jug and y is # of gallons in the 2-gallon jug Initial State = (5,2) Goal State = (*,1), where * means any amount
(x,2)(x+2,0) Pour 2-gal. into 5-gal. (x,0)(x-2,2) Pour 5-gal. into 2-gal.
The number of states depends on the representation and level of abstraction chosen.
In the Remove-5-Sticks problem, if we represent the individual sticks, then there are 17-choose-5 possible ways of removing 5 sticks. On the other hand, if we represent the squares defined by 4 sticks, then there are 6 squares initially and we must remove 3 squares, so only 6-choose-3 ways of removing 3 squares.
Formalizing search II
Each arc has a fixed, positive cost associated with it corresponding to the cost of the operator. Each node has a set of successor nodes corresponding to all of the legal operators that can be applied at the source nodes state.
The process of expanding a node means to generate all of the successor nodes and add them and their associated arcs to the statespace graph
One or more nodes are designated as start nodes. A goal test predicate is applied to a state to determine if its associated node is a goal node.
1, 2
5to2part 0, 2
1, 1
0, 1
1, 0
0, 0
1, 2
0, 2
1, 1
0, 1
1, 0
0, 0
Formalizing search IV
State-space search is the process of searching through a state space for a solution by making explicit a sufficient portion of an implicit state-space graph to find a goal node.
For large state spaces, it isnt practical to represent the whole space. Initially V={S}, where S is the start node; when S is expanded, its successors are generated and those nodes are added to V and the associated arcs are added to E. This process continues until a goal node is found.
Each node implicitly or explicitly represents a partial solution path (and cost of the partial solution path) from the start node to the given node.
In general, from this node there are many possible paths (and therefore solutions) that have this partial path as a prefix.
GOAL-TEST
Test if state satisfies all goal conditions
QUEUEING-FUNCTION
Used to maintain a ranked list of nodes that are candidates for expansion
Bookkeeping
Typical node data structure includes:
State at this node Parent node Operator applied to get to this node Depth of this node (number of operator applications since initial state) Cost of the path (sum of each operator application so far)
Some issues
Search process constructs a search tree, where root is the initial state and leaf nodes are nodes
not yet expanded (i.e., they are in the list nodes) or having no successors (i.e., theyre deadends because no operators were applicable and yet they are not goals)
Search tree may be infinite because of loops even if state space is small Return a path or a node depending on problem.
E.g., in cryptarithmetic return a node; in 8-puzzle return a path
Time complexity
How long (worst or average case) does it take to find a solution? Usually measured in terms of the number of nodes expanded
Space complexity
How much space is used by the algorithm? Usually measured in terms of the maximum size of the nodes list during the search
Optimality/Admissibility
If a solution is found, is it guaranteed to be an optimal one? That is, is it the one with minimum cost?
S
3 1 8
A
3 7 15
B
20
C 5
Breadth-First
Enqueue nodes on nodes in FIFO (first-in, first-out) order. Complete Optimal (i.e., admissible) if all operators have the same cost. Otherwise, not optimal but finds solution with shortest path length. Exponential time and space complexity, O(bd), where d is the depth of the solution and b is the branching factor (i.e., number of children) at each node Will take a long time to find solutions with a large number of steps because must look at all shorter length possibilities first
A complete search tree of depth d where each non-leaf node has b children, has a total of 1 + b + b2 + ... + bd = (b(d+1) - 1)/(b-1) nodes For a complete search tree of depth 12, where every node at depths 0, ..., 11 has 10 children and every node at depth 12 has 0 children, there are 1 + 10 + 100 + 1000 + ... + 1012 = (1013 - 1)/9 = O(1012) nodes in the complete search tree. If BFS expands 1000 nodes/sec and each node uses 100 bytes of storage, then BFS will take 35 years to run in the worst case, and it will use 111 terabytes of memory!
Depth-First (DFS)
Enqueue nodes on nodes in LIFO (last-in, first-out) order. That is, nodes used as a stack data structure to order nodes. May not terminate without a depth bound, i.e., cutting off search below a fixed depth D ( depth-limited search) Not complete (with or without cycle detection, and with or without a cutoff depth) Exponential time, O(bd), but only linear space, O(bd) Can find long solutions quickly if lucky (and short solutions slowly if unlucky!) When search hits a dead-end, can only back up one level at a time even if the problem occurs because of a bad operator choice near the top of the tree. Hence, only does chronological backtracking
Uniform-Cost (UCS)
Enqueue nodes by path cost. That is, let g(n) = cost of the path from the start node to the current node n. Sort nodes by increasing value of g. Called Dijkstras Algorithm in the algorithms literature and similar to Branch and Bound Algorithm in operations research literature Complete (*) Optimal/Admissible (*) Admissibility depends on the goal test being applied when a node is removed from the nodes list, not when its parent node is expanded and the node is first generated Exponential time and space complexity, O(bd)
IDS can actually be quicker in-practice than BFS, even though it regenerates early states.
Breadth-First Search
Nodes list { S0 } S0 { A3 B1 C8 } A3 { B1 C8 D6 E10 G18 } B1 { C8 D6 E10 G18 G21 } C8 { D6 E10 G18 G21 G13 } D6 { E10 G18 G21 G13 } E10 { G18 G21 G13 } G18 { G21 G13 } Solution path found is S A G , cost 18 Number of nodes expanded (including goal node) = 7 Expanded node
Depth-First Search
Expanded node S0 A3 D6 E10 G18 Nodes list { S0 } { A3 B1 C8 } { D6 E10 G18 B1 C8 } { E10 G18 B1 C8 } { G18 B1 C8 } { B1 C8 }
Solution path found is S A G, cost 18 Number of nodes expanded (including goal node) = 5
Uniform-Cost Search
Nodes list { S0 } S0 { B1 A3 C8 } B1 { A3 C8 G21 } A3 { D6 C8 E10 G18 G21 } D6 { C8 E10 G18 G1 } C8 { E10 G13 G18 G21 } E10 { G13 G18 G21 } G13 { G18 G21 } Solution path found is S B G, cost 13 Number of nodes expanded (including goal node) = 7 Expanded node
Depth-First Search:
Expanded nodes: S A D E G Solution found: S A G (cost 18)
Uniform-Cost Search:
Expanded nodes: S A D B C E G Solution found: S B G (cost 13) This is the only uninformed search that worries about costs.
Iterative-Deepening Search:
nodes expanded: S S A B C S A D E G Solution found: S A G (cost 18)
Bi-directional search
Alternate searching from the start state toward the goal and from the goal state toward the start. Stop when the frontiers intersect. Works well only when there are unique start and goal states. Requires the ability to generate predecessor states. Can (sometimes) lead to finding a solution more quickly.
Time complexity: O(bd/2). Space complexity: O(bd/2).
Graph Search
function graph-search (problem, QUEUEING-FUNCTION) ;; problem describes the start state, operators, goal test, and operator costs ;; queueing-function is a comparator function that ranks two states ;; graph-search returns either a goal node or failure nodes = MAKE-QUEUE(MAKE-NODE(problem.INITIAL-STATE)) closed = {} loop if EMPTY(nodes) then return "failure" node = REMOVE-FRONT(nodes) if problem.GOAL-TEST(node.STATE) succeeds then return node.SOLUTION if node.STATE is not in closed then ADD(node, closed) nodes = QUEUEING-FUNCTION(nodes, EXPAND(node, problem.OPERATORS)) end ;; Note: The goal test is NOT done when nodes are generated ;; Note: closed should be implemented as a hash table for efficiency
Solution path found is S C G, cost 13 (optimal) Number of nodes expanded (including goal node) = 3 (as few as possible!) If only we knew where we were headed