670 likes | 865 Views
Princess Nora University Artificial Intelligence. Chapter (3) Solving problems by searching. Out Line :. Problem-solving agents Problem types Problem formulation Example problems Basic search algorithms. Solving problems by searching.
E N D
Princess Nora UniversityArtificial Intelligence Chapter (3) Solving problems by searching
Out Line : • Problem-solving agents • Problem types • Problem formulation • Example problems • Basic search algorithms
Solving problems by searching • In which we look at how an agent can decide what to do by systematically considering the outcomes of various sequences of actions that it might take. • Basic Search Algorithm • Many AI problems can be posed as search • If goal found=>success; else, failure
Why Search? • Not just city route search • Many AI problems can be posed as search • Planning : • Vertices : World states; Edges: Actions • Game-playing: • Vertices: Board configurations; Edges: Moves • Speech Recognition: • Vertices: Phonemes; Edges: Phone transitions
Example: • On holiday in Riyadh. • Flight leaves tomorrow from Riyadh • Formulate goal : • be after two days in Paris • Formulate problem: • States : various cities • Actions : drive between cities • Find solution : • sequence of cities, e.g., Riyadh, Jeddah, London, Paris
Problem types • Deterministic, fully observable single-state problem • Agent knows exactly which state it will be in; solution is a sequence • Non-observable sensorless problem (conformant problem) • Agent may have no idea where it is; solution is a sequence • Nondeterministic and/or partially observable contingency problem • percepts provide new information about current state • Solution is tree, branch chosen based on percepts • Must use sensors during execution • Unknown state space exploration problem
Single-state problem formulation A problem is defined by 4 items: • initial statee.g., "at Arad“ • actions or successor function S(x) = set of action–state pairs e.g., S(Arad) = {<Arad Zerind, Zerind>, … }
Single-state problem formulation 3. goal test, can be explicit, e.g., x = "at Bucharest" implicit, e.g., Checkmate(x) 4. path cost (additive) sequence of actions leading from one state to another e.g., sum of distances, number of actions executed, etc. C (x, a, y) is the step cost, assumed to be ≥ 0 State space: all states reachable from the initial state by any sequence action A solution is a sequence of actions leading from the initial state to a goal state
Selecting a state space • Real world is absurdly complex state space must be abstracted for problem solving (Abstract) state = set of real states • (Abstract) action = complex combination of real actions • e.g., "Arad Zerind" represents a complex set of possible routes, detours, rest stops, etc. • For guaranteed reliability, any real state "in Arad“ must get to some real state "in Zerind" • (Abstract) solution = • set of real paths that are solutions in the real world • Each abstract action should be "easier" than the original problem
Vacuum world state space graph • States ? dirt and robot location • actions? Left, Right, Suck • goal test ? no dirt at all locations • path cost? 1 per action
Example: The 8-puzzle • 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]
Tree search algorithms • Basic idea: • offline, simulated exploration of state space by generating successors of already-explored states (expanding states)
Implementation: states vs. nodes • 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.
Search strategies • 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 branching factor of the search tree • d: depth of the least-cost solution • m: maximum depth of the state space (may be ∞)
Uninformed search strategies • Uninformed search strategies use only the information available in the problem definition • Breadth-first search • Uniform-cost search • Depth-first search • Depth-limited search • Iterative deepening search
Breadth-first search • Expand shallowest unexpanded node • Implementation: • fringe is a FIFO queue, i.e., new successors go at end • Application1: Given the following state space (tree search), give the sequence of visited nodes when using BFS (assume that the node O is the goal state)
G F A B C E N D H I J K L M O Breadth First Search • :
G F A B C E N D H I J K L M O Breadth First Search • A, • B,C,D,E, • F,G,H,I,J, • K,L, M,N, • Goal state: O
G F A B C E N D H I J K L M O Breadth First Search • The returned solution is the sequence of operators in the path: A, B, G, L, O
Basic Search Algorithms Uninformed Search Uniform Cost Search (UCS)
Properties of breadth-first search • Complete? Yes ( if bis finite) • Time?b+b2+b3+… +bd + b(bd-1) = O(bd+1) • Space?1+b+b2+b3+… +bd + b(bd-1) = O(bd+1) O(bd+1) (keeps every node in memory) • Optimal? Yes (if cost = 1 per step) • Space is the bigger problem (more than time)
Uniform Cost Search (UCS) • Expand the cheapest node. Where the cost is the path cost g(n). • Implémentations: Enqueue nodes in order of cost g(n). QUEUING-FN:- insert in order of increasing path cost. Enqueue new node at the appropriate position in the queue so that we dequeue the cheapest node.
Uniform Cost Search (UCS) 5 2 [2] [5] 1 4 1 7 [6] [3] [9] [9] 4 5 Goal state [x] = g(n) path cost of node n [7] [8]
5 2 [2] [5] Uniform Cost Search (UCS)
Uniform Cost Search (UCS) 5 2 [2] [5] 1 7 [3] [9]
Uniform Cost Search (UCS) 5 2 [2] [5] 1 7 [3] [9] 4 5 [7] [8]
5 2 [2] [5] 1 4 1 7 [6] [3] [9] [9] 4 5 [7] [8] Uniform Cost Search (UCS)
Goal state path cost g(n)=[6] 5 2 [2] [5] 1 4 1 7 [3] [9] [9] 4 5 [7] [8] Uniform Cost Search (UCS)
5 2 [2] [5] 1 4 1 7 [6] [3] [9] [9] 4 5 [7] [8] Uniform Cost Search (UCS)
Uniform Cost Search (UCS) Complete? Yes Time? O(bd) Space? : O(bd), note that every node in the fringe keep in the queue. Optimal? Yes
Depth-first search • Expand deepest unexpanded node • Implementation: • fringe = LIFO queue, i.e., put successors at front
G F A B C E N D H I J K L M O Depth First Search (DFS) Given the following state space (tree search), give the sequence of visited nodes when using DFS (assume that the nodeO is the goal state):
A B C E D Depth First Search • A,
A B C E D F G Depth First Search • A,B,
A B C E D F G Depth First Search • A,B,F,
A B C E D F G K L Depth First Search • A,B,F, • G,
A B C E D F G K L Depth First Search • A,B,F, • G,K,
A B C E D F G K L O Depth First Search • A,B,F, • G,K, • L,
A B C E D F G K L O Depth First Search • A,B,F, • G,K, • L, O: Goal State
A B C E D F G K L O Depth First Search The returned solution is the sequence of operators in the path: A, B, G, L, O
Properties of depth-first search • Complete? No: fails in infinite-depth spaces, spaces with loops • Modify to avoid repeated states along path complete in finite spaces • Time?O(bm): terrible if m is much larger than d • but if solutions are dense, may be much faster than breadth-first • Space?O(bm), i.e., linear space! • Optimal? No
Depth-limited search = depth-first search with depth limit l, i.e., nodes at depth l have no successors
H L K J I G F M E C B A N D O Depth-Limited Search (DLS) Given the following state space (tree search), give the sequence of visited nodes when using DLS (Limit = 2): Limit = 0 Limit = 1 Limit = 2
A B C E D Depth-Limited Search (DLS) • A, Limit = 2
A B C E D F G Depth-Limited Search (DLS) • A,B, Limit = 2
A B C E D F G Limit = 2 Depth-Limited Search (DLS) • A,B,F,