Download presentation
Presentation is loading. Please wait.
1
University College Cork (Ireland) Department of Civil and Environmental Engineering Course: Engineering Artificial Intelligence Dr. Radu Marinescu Lecture 2
2
University College Cork (Ireland) Department of Civil and Environmental Engineering Fundamental issues for most AI problems o Representation o Search o Inference o Planning o Learning R. Marinescu October-2009page 2
3
University College Cork (Ireland) Department of Civil and Environmental Engineering Representation o Facts about the world have to be represented in some way, e.g., mathematical logic o Deals with: What to represent and how to represent? How to structure knowledge? What is explicit and what must be inferred? How to encode “rules”? How to deal with incomplete, inconsistent and probabilistic knowledge? What kinds of knowledge are required to solve problems? R. Marinescu October-2009page 3
4
University College Cork (Ireland) Department of Civil and Environmental Engineering Search o Many tasks can be viewed as searching a very large problem space for a solution For example, Tic-Tac-Toe has 765 states, Chess has about 2 50 states, while Go has about 2 100 states R. Marinescu October-2009page 4
5
University College Cork (Ireland) Department of Civil and Environmental Engineering Inference o From some facts others can be inferred (related to search) For example, knowing "All elephants have trunks" and "Clyde is an elephant," can we answer the question "Does Clyde have a trunk?" What about "Peanuts has a trunk, is it an elephant?" Or "Peanuts lives in a tree and has a trunk, is it an elephant?” R. Marinescu October-2009page 5
6
University College Cork (Ireland) Department of Civil and Environmental Engineering Learning and planning o Learning Learn new facts about the world: e.g., machine learning o Planning Starting with general facts about the world, facts about the effects of basic actions, facts about a particular situation, and a statement of a goal generate a strategy for achieving that goal in terms of a sequence of primitive steps or actions R. Marinescu October-2009page 6
7
University College Cork (Ireland) Department of Civil and Environmental Engineering Fundamental issues for most AI problems o Representation o Search o Inference o Planning o Learning R. Marinescu October-2009page 7
8
University College Cork (Ireland) Department of Civil and Environmental Engineering Search o Main idea: Search allows exploring alternatives o Background o State space representation o Uninformed vs. informed o Any path vs. optimal path o Implementation and performance R. Marinescu October-2009page 8
9
University College Cork (Ireland) Department of Civil and Environmental Engineering Trees and graphs R. Marinescu October-2009page 9 C B A Tree root Terminal (leaf) Link (edge) B is parent of C C is child of B A is ancestor of C C is descendant of A
10
University College Cork (Ireland) Department of Civil and Environmental Engineering Trees and graphs R. Marinescu October-2009page 10 C B A Tree root Terminal (leaf) Link (edge) B is parent of C C is child of B A is ancestor of C C is descendant of A Directed Graph (one way streets)
11
University College Cork (Ireland) Department of Civil and Environmental Engineering Trees and graphs R. Marinescu October-2009page 11 C B A Tree root Terminal (leaf) Link (edge) B is parent of C C is child of B A is ancestor of C C is descendant of A Directed Graph (one way streets) Undirected Graph (two way streets)
12
University College Cork (Ireland) Department of Civil and Environmental Engineering Examples of graphs R. Marinescu October-2009page 12 San Fran Boston Wash DC LA Dallas Airline routes
13
University College Cork (Ireland) Department of Civil and Environmental Engineering Examples of graphs R. Marinescu October-2009page 13 San Fran Boston Wash DC LA Dallas Airline routes Planning actions (graph of possible states of the world) ABC AB C A B C A C B B A C Put C on A Put C on B Put B on C Put A on C Put C on A
14
University College Cork (Ireland) Department of Civil and Environmental Engineering Problem solving paradigm o What are the states? (All relevant aspects of the problem) Arrangement of parts (to plan an assembly) Positions of trucks (to plan package distribution) Cities (to plan a trip) Set of facts (e.g., to prove a mathematical theorem) o What are the actions (operators)? (deterministic, discrete) Assemble two parts Move a truck to a new position Fly to a new city Apply a theorem to derive a new fact o What is the goal test? (Condition for success) All parts in place All packages delivered Reached destination city Derived goal fact R. Marinescu October-2009page 14
15
University College Cork (Ireland) Department of Civil and Environmental Engineering Example: holiday in Romania o On vacation in Romania, currently in Arad o Flight home leaves tomorrow from Bucharest R. Marinescu October-2009page 15
16
University College Cork (Ireland) Department of Civil and Environmental Engineering Example: holiday in Romania o Goal Be in Bucharest o State-space States: various cities Actions: drive between cities o Solution Sequence of actions to destination R. Marinescu October-2009page 16
17
University College Cork (Ireland) Department of Civil and Environmental Engineering Solution to the holiday problem R. Marinescu October-2009page 17 Solution: go(Sibiu), go(Fagaras), go(Bucharest) Cost: 140 + 99 + 211 = 450
18
University College Cork (Ireland) Department of Civil and Environmental Engineering State-space problem formulation o A problem is defined by 4 items: Initial state: e.g., in(Arad) Actions or successor function: S(X) = set of action-state pairs e.g., S(Arad) = {,, } Goal test: e.g., in(Bucharest) Path cost (additive) e.g., sum of distances to drive o A solution is a sequence of actions leading from the initial state to a goal state R. Marinescu October-2009page 18
19
University College Cork (Ireland) Department of Civil and Environmental Engineering Vacuum cleaner state space o States: location of dirt and robot o Initial state: any o Actions: move robot left, right and suck o Goal state: no dirt at all locations o Path cost: 1 per action R. Marinescu October-2009page 19
20
University College Cork (Ireland) Department of Civil and Environmental Engineering 8-queen puzzle state space o States: arrangements of n ≤ 8 queens in the leftmost n columns, 1 per column, such that no queen attacks another o Initial state: no queens on the board o Actions: add queen to the leftmost empty column such that it is not attacked by any other queen o Goal state: 8 queens on the board, none attacked o Path cost: 1 per action R. Marinescu October-2009page 20
21
University College Cork (Ireland) Department of Civil and Environmental Engineering Sliding tile puzzle state space o States o Initial state o Actions o Goal state o Path cost R. Marinescu October-2009page 21 Try yourselves
22
University College Cork (Ireland) Department of Civil and Environmental Engineering Sliding tile puzzle state space o States: locations of tiles o Initial state: given (left) o Actions: move blank left, right, up, down o Goal state: given (right) o Path cost: 1 per action R. Marinescu October-2009page 22
23
University College Cork (Ireland) Department of Civil and Environmental Engineering Sliding tile puzzle state space R. Marinescu October-2009page 23
24
University College Cork (Ireland) Department of Civil and Environmental Engineering Search algorithms o Basic idea Exploration of state space graph by generating successors of already- explored states (a.k.a. expanding states) Every states is evaluated: is it a goal state ? R. Marinescu October-2009page 24
25
University College Cork (Ireland) Department of Civil and Environmental Engineering Terminology o State – Used to refer to the vertices in the underlying graph that is being searched, that is states in the problem domain, for example, a city, an arrangement of blocks or the arrangement of parts in a puzzle o Search node – Refers to the vertices in the search tree that is being generated by the search algorithm. Each node refers to a state of the world; many nodes may refer to the same state. Importantly, a node implicitly represents a path (from the start state of the search tree to the state associated with the node). Because search nodes are part of the search tree, they have a unique ancestor node (except for the root node) R. Marinescu October-2009page 25
26
University College Cork (Ireland) Department of Civil and Environmental Engineering Terminology: more details o A state is a (representation of) a physical configuration o A node is a data structure constituting part of a search tree contains info such as: state, parent node, action, path cost g(x), depth R. Marinescu October-2009page 26
27
University College Cork (Ireland) Department of Civil and Environmental Engineering Search strategies o A search strategy is defined by picking the order of node expansion o Search 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? o Time and space complexity are measured in terms of b: maximum branching factor of the search tree d: depth of the search tree R. Marinescu October-2009page 27
28
University College Cork (Ireland) Department of Civil and Environmental Engineering Classes of search o Any path search Uninformed search Informed search o Optimal path search Uninformed search Informed search R. Marinescu October-2009page 28
29
University College Cork (Ireland) Department of Civil and Environmental Engineering Classes of search R. Marinescu October-2009page 29 ClassNameOperation Any PathDepth-FirstSystematic exploration of whole tree UninformedBreadth-Firstuntil a goal node is found. Any PathBest-FirstUses heuristic measure of goodness Informedof a state, e.g. estimated distance to goal. OptimalUniform-CostUses path “length” measure. UninformedFinds shortest path. OptimalA*Uses path “length” measure and heuristic InformedFinds shortest path.
30
University College Cork (Ireland) Department of Civil and Environmental Engineering Simple search algorithm o A search node is a path from some state X to the start state, e.g., (X B A S) o The state of a search node is the most recent state of the path, e.g., X o Let Q be a list of search nodes, e.g., ((X B A S) (C B A S) …) o Let S be the start state 1.Initialize Q with search node (S) as only entry, set Visited = (S) 2.If Q is empty, fail. Else, pick some node N from Q 3.If state(N) is goal, return N (we’ve reached the goal) 4.(Otherwise) Remove N from Q 5.Find all descendants of state(N) not in Visited and create all the one-step extensions of N to each descendant 6.Add the extended paths to Q; add children of state(N) to Visited 7.Go to step 2. R. Marinescu October-2009page 30
31
University College Cork (Ireland) Department of Civil and Environmental Engineering Simple search algorithm o A search node is a path from some state X to the start state, e.g., (X B A S) o The state of a search node is the most recent state of the path, e.g., X o Let Q be a list of search nodes, e.g., ((X B A S) (C B A S) …) o Let S be the start state 1.Initialize Q with search node (S) as only entry, set Visited = (S) 2.If Q is empty, fail. Else, pick some node N from Q 3.If state(N) is goal, return N (we’ve reached the goal) 4.(Otherwise) Remove N from Q 5.Find all descendants of state(N) not in Visited and create all the one-step extensions of N to each descendant 6.Add the extended paths to Q; add children of state(N) to Visited 7.Go to step 2. R. Marinescu October-2009page 31 Critical decisions: Step 2: picking N from Q Step 6: adding extensions of N to Q
32
University College Cork (Ireland) Department of Civil and Environmental Engineering Implementing the search strategies o Depth-first Pick first element of Q Add path extensions to front of Q o Breadth-first Pick first element of Q Add path extensions to end of Q R. Marinescu October-2009page 32
33
University College Cork (Ireland) Department of Civil and Environmental Engineering Terminology o Visited – a state M is first visited when a path to M first gets added to Q. In general, a state is said to have been visited if it has ever shown up in a search node in Q. The intuition is that we have briefly “visited” them to place them in Q, but we have not yet examined them carefully. o Expanded – a state M is expanded when it is the state of a search node that is pulled off of Q. At that point, the descendants of M are visited and the path that led to M is extended to the eligible descendants. We sometimes refer to the search node that led to M (instead of M itself) as being expanded. However, once a node is expanded we are done with it; we will not need to expand it again. In fact, we discard it from Q R. Marinescu October-2009page 33
34
University College Cork (Ireland) Department of Civil and Environmental Engineering Depth-First R. Marinescu October-2009page 34 S A B C D G Pick first element of Q; Add path extensions to front of Q QVisited 1 2 3 4 5 Added paths in blue We show the paths in reversed order; the node’s state is the first entry
35
University College Cork (Ireland) Department of Civil and Environmental Engineering Depth-First R. Marinescu October-2009page 35 S A B C D G Pick first element of Q; Add path extensions to front of Q QVisited 1(S)S 2 3 4 5 Added paths in blue We show the paths in reversed order; the node’s state is the first entry 1
36
University College Cork (Ireland) Department of Civil and Environmental Engineering Depth-First R. Marinescu October-2009page 36 S A B C D G Pick first element of Q; Add path extensions to front of Q QVisited 1(S)S 2(A S) (B S)A, B, S 3 4 5 Added paths in blue We show the paths in reversed order; the node’s state is the first entry 1 2
37
University College Cork (Ireland) Department of Civil and Environmental Engineering Depth-First R. Marinescu October-2009page 37 S A B C D G Pick first element of Q; Add path extensions to front of Q QVisited 1(S)S 2(A S) (B S)A, B, S 3(C A S) (D A S) (B S)C, B, A, S 4 5 Added paths in blue We show the paths in reversed order; the node’s state is the first entry 1 2 3
38
University College Cork (Ireland) Department of Civil and Environmental Engineering Depth-First R. Marinescu October-2009page 38 S A B C D G Pick first element of Q; Add path extensions to front of Q QVisited 1(S)S 2(A S) (B S)A, B, S 3(C A S) (D A S) (B S)C, B, A, S 4(D A S) (B S)C, D, B, A, S 5 Added paths in blue We show the paths in reversed order; the node’s state is the first entry 1 2 3 4
39
University College Cork (Ireland) Department of Civil and Environmental Engineering Depth-First R. Marinescu October-2009page 39 S A B C D G Pick first element of Q; Add path extensions to front of Q QVisited 1(S)S 2(A S) (B S)A, B, S 3(C A S) (D A S) (B S)C, B, A, S 4(D A S) (B S)C, D, B, A, S 5(G D A S) (B S)G, C, D, B, A, S Added paths in blue We show the paths in reversed order; the node’s state is the first entry 1 2 3 4 5
40
University College Cork (Ireland) Department of Civil and Environmental Engineering Depth-First R. Marinescu October-2009page 40 S A B C D G Pick first element of Q; Add path extensions to front of Q QVisited 1(S)S 2(A S) (B S)A, B, S 3(C A S) (D A S) (B S)C, B, A, S 4(D A S) (B S)C, D, B, A, S 5(G D A S) (B S)G, C, D, B, A, S Added paths in blue We show the paths in reversed order; the node’s state is the first entry 1 2 3 4 5
41
University College Cork (Ireland) Department of Civil and Environmental Engineering Depth-First: another (easier?) way to see it R. Marinescu October-2009page 41 S A B C D G S A B 1 1 Numbers indicate order pulled off of Q (expanded) Blue fill = Visited & Expanded Gray fill = Visited
42
University College Cork (Ireland) Department of Civil and Environmental Engineering Depth-First: another (easier?) way to see it R. Marinescu October-2009page 42 S A B C D G S A B 1 1 Numbers indicate order pulled off of Q (expanded) Blue fill = Visited & Expanded Gray fill = Visited CD 2 2
43
University College Cork (Ireland) Department of Civil and Environmental Engineering Depth-First: another (easier?) way to see it R. Marinescu October-2009page 43 S A B C D G S A B 1 1 Numbers indicate order pulled off of Q (expanded) Blue fill = Visited & Expanded Gray fill = Visited CD 2 2 3 3
44
University College Cork (Ireland) Department of Civil and Environmental Engineering Depth-First: another (easier?) way to see it R. Marinescu October-2009page 44 S A B C D G S A B 1 1 Numbers indicate order pulled off of Q (expanded) Blue fill = Visited & Expanded Gray fill = Visited CD 2 2 3 3 CG 4 4 NB: C is not visited again
45
University College Cork (Ireland) Department of Civil and Environmental Engineering Depth-First: another (easier?) way to see it R. Marinescu October-2009page 45 S A B C D G S A B 1 1 Numbers indicate order pulled off of Q (expanded) Blue fill = Visited & Expanded Gray fill = Visited CD 2 2 3 3 CG 4 4 5 5
46
University College Cork (Ireland) Department of Civil and Environmental Engineering Implementing the search strategies o Depth-first Pick first element of Q Add path extensions to front of Q o Breadth-first Pick first element of Q Add path extensions to end of Q R. Marinescu October-2009page 46
47
University College Cork (Ireland) Department of Civil and Environmental Engineering Breadth-First R. Marinescu October-2009page 47 Pick first element of Q; Add path extensions to end of Q S A B C D G QVisited 1(S)S 2 3 4 5 6 Added paths in blue We show the paths in reversed order; the node’s state is the first entry
48
University College Cork (Ireland) Department of Civil and Environmental Engineering Breadth-First R. Marinescu October-2009page 48 Pick first element of Q; Add path extensions to end of Q S A B C D G QVisited 1(S)S 2(A S) (B S)A, B, S 3 4 5 6 Added paths in blue We show the paths in reversed order; the node’s state is the first entry 1
49
University College Cork (Ireland) Department of Civil and Environmental Engineering Breadth-First R. Marinescu October-2009page 49 Pick first element of Q; Add path extensions to end of Q S A B C D G QVisited 1(S)S 2(A S) (B S)A, B, S 3(B S) (C A S) (D A S)C, D, B, A, S 4 5 6 Added paths in blue We show the paths in reversed order; the node’s state is the first entry 1 2
50
University College Cork (Ireland) Department of Civil and Environmental Engineering Breadth-First R. Marinescu October-2009page 50 Pick first element of Q; Add path extensions to end of Q S A B C D G QVisited 1(S)S 2(A S) (B S)A, B, S 3(B S) (C A S) (D A S)C, D, B, A, S 4(C A S) (D A S) (G B S)*G, C, D, B, A, S 5 6 Added paths in blue We show the paths in reversed order; the node’s state is the first entry * We could have stopped here, when the first path to the goal was generated 1 2 3
51
University College Cork (Ireland) Department of Civil and Environmental Engineering Breadth-First R. Marinescu October-2009page 51 Pick first element of Q; Add path extensions to end of Q S A B C D G QVisited 1(S)S 2(A S) (B S)A, B, S 3(B S) (C A S) (D A S)C, D, B, A, S 4(C A S) (D A S) (G B S)*G, C, D, B, A, S 5(D A S) (G B S)G, C, D, B, A, S 6 Added paths in blue We show the paths in reversed order; the node’s state is the first entry * We could have stopped here, when the first path to the goal was generated 1 2 3 4
52
University College Cork (Ireland) Department of Civil and Environmental Engineering Breadth-First R. Marinescu October-2009page 52 Pick first element of Q; Add path extensions to end of Q S A B C D G QVisited 1(S)S 2(A S) (B S)A, B, S 3(B S) (C A S) (D A S)C, D, B, A, S 4(C A S) (D A S) (G B S)*G, C, D, B, A, S 5(D A S) (G B S)G, C, D, B, A, S 6 Added paths in blue We show the paths in reversed order; the node’s state is the first entry * We could have stopped here, when the first path to the goal was generated 1 2 3 4 5
53
University College Cork (Ireland) Department of Civil and Environmental Engineering Breadth-First R. Marinescu October-2009page 53 Pick first element of Q; Add path extensions to end of Q S A B C D G QVisited 1(S)S 2(A S) (B S)A, B, S 3(B S) (C A S) (D A S)C, D, B, A, S 4(C A S) (D A S) (G B S)*G, C, D, B, A, S 5(D A S) (G B S)G, C, D, B, A, S 6(G B S)G, C, D, B, A, S Added paths in blue We show the paths in reversed order; the node’s state is the first entry * We could have stopped here, when the first path to the goal was generated 1 2 3 4 5 6
54
University College Cork (Ireland) Department of Civil and Environmental Engineering Breadth-First R. Marinescu October-2009page 54 Pick first element of Q; Add path extensions to end of Q S A B C D G QVisited 1(S)S 2(A S) (B S)A, B, S 3(B S) (C A S) (D A S)C, D, B, A, S 4(C A S) (D A S) (G B S)*G, C, D, B, A, S 5(D A S) (G B S)G, C, D, B, A, S 6(G B S)G, C, D, B, A, S Added paths in blue We show the paths in reversed order; the node’s state is the first entry * We could have stopped here, when the first path to the goal was generated 1 2 3 4 5 6
55
University College Cork (Ireland) Department of Civil and Environmental Engineering Breadth-First: another (easier?) way to see it R. Marinescu October-2009page 55 S A B C D G 1 2 3 4 5 6 S A B 1 CD 2 4 5 3 DG 6 Numbers indicate order pulled off of Q (expanded) Blue fill = Visited & Expanded Gray fill = Visited NB: D is not visited again
56
University College Cork (Ireland) Department of Civil and Environmental Engineering Worst case running time o The number of states in the search space may be exponential in the some “depth” parameter, e.g. number of actions in a plan, number of moves in a game o All searches may have to visit each state at least one, in the worst case o So, all searches will have worst case running times that are at least proportional to the total number of states and therefore exponential in the “depth” parameter R. Marinescu October-2009page 56 b=2 d=0 d=1 d=2 d is depth b is branching factor b d < (b d+1 – 1) / (b - 1) < b d+1 states in tree Max Time α Max # Visited
57
University College Cork (Ireland) Department of Civil and Environmental Engineering Worst case space R. Marinescu October-2009page 57 Depth-first max Q size (b – 1)d ≈ bd visited expanded Max Q size = Max(#Visited - #Expanded) Breadth-first max Q size b d
58
University College Cork (Ireland) Department of Civil and Environmental Engineering Cost performance of any-path methods R. Marinescu October-2009page 58 SearchWorst FewestGuaranteed to MethodTimeSpaceStatesfind path? Depth-Firstb d+1 bdNoYes* Breadth-Firstb d+1 bdbd Yes Searching a tree with branching factor b and depth d (without a Visited list) * If there are no infinitely long paths in the search space Worst case time is proportional to the number of nodes added to Q Worst case space is proportional to the maximal length of Q
59
University College Cork (Ireland) Department of Civil and Environmental Engineering Space (the final frontier) o In large search problems, memory is often the limiting factor o Imagine searching a tree with branching factor 8 and depth 10. Assume a node requires just 8 bytes of storage. The, breadth- first search might require up to (2 3 ) 10 x 2 3 = 2 33 bytes = 8,000 Mbytes = 8 Gbytes o One strategy is to trade time for memory. For example, we can emulate breadth-first search by repeated application of depth- first search, each up to a preset depth limit. This is called iterative deepening search (IDS) 1.C = 1 2.Do DFS to max depth C. If path found, return it 3.Otherwise, increment C and go to 2. R. Marinescu October-2009page 59
60
University College Cork (Ireland) Department of Civil and Environmental Engineering Summary o State-space formulation Abstract representation of the problem o Search for a solution Depth-first search : exponential time, linear space Breadth-first search : exponential time, exponential space, but finds the “shallowest” goal Iterative deepening search : trades off time for space (simulates breadth-first search) o Readings Chapter 3 in R&N book R. Marinescu October-2009page 60
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.