A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ......

117
A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE https://cw.fel.cvut.cz/wiki/courses/ Michal Pechoucek & Jiri Klema Department of Computer Science Czech Technical University in Prague In parts based on cs121.stanford.edu & S. Russell and P. Norvig, Artificial Intelligence: A Modern Approach. 3rd edition, Prentice Hall, 2010

Transcript of A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ......

Page 1: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCEhttps://cw.fel.cvut.cz/wiki/courses/Michal Pechoucek & Jiri KlemaDepartment of Computer Science Czech Technical University in Prague

In parts based on cs121.stanford.edu & S. Russell and P. Norvig, Artificial Intelligence: A Modern Approach. 3rd edition, Prentice Hall, 2010

Page 2: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

2

What is Artificial Intelligence?

Page 3: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

3

What is Artificial Intelligence?

Artificial Intelligence is family of technologies and scientific field that allows/studies:• automation, acceleration and scalability of• human (i) perception, (ii) reasoning and (iii)

decision making

Page 4: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

4

Why Artificial Intelligence Matters?

Page 5: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

5

Why Artificial Intelligence Matters?

Page 6: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

6

Why Artificial Intelligence Matters?

Page 7: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

7

Why Artificial Intelligence Matters?

Page 8: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

8

Types of Artificial Intelligence?

WEAK AI 𝕏 STRONG AI

Page 9: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

Types of Artificial Intelligence?

• Strong AI: – Searle's strong AI hypothesis: The appropriately programmed

computer with the right inputs and outputs would thereby have a mind in exactly the same sense human beings have minds.

– Artificial general intelligence is a hypothetical artificial intelligence that demonstrates the intelligence of a machine that could successfully perform any intellectual task that a human being can.

• Weak AI: – Turing’s hypothesis: If a machine behaves as intelligently as a human

being, then it is as intelligent as a human being = passes the Turing Test

• AI according to Smith:– The machine shall exhibit indistinguishable behaviour (according to

the weak AI definition) by means of the knowledge structures and reasoning process identical to those used by human

9

Page 10: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

10

Types of Artificial Intelligence?

WEAK AI 𝕏 STRONG AI

Page 11: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

11

Types of Artificial Intelligence?

WEAK AI 𝕏 STRONG AI

Page 12: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

11

Turing Test

12

• Test proposed by Alan Turing in 1950• The computer is asked questions by a human interrogator. It passes

the test if the interrogator cannot tell whether the responses come from a person

• Required capabilities: natural language processing, knowledge representation, automated reasoning, learning,…

• CAPTCHA: Completely Automatic Public Turing tests to tell Computers and Humans Apart

Page 13: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

13

Types of Artificial Intelligence?

WEAK AI 𝕏 STRONG AI

Page 14: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

14

Types of Artificial Intelligence?

WEAK AI 𝕏 STRONG AI

Narrow AI→Extended AI→General AI→Super AI

Page 15: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

15

Artificial Intelligence Approaches

1. Statistical AI: Machine Learning (Computational Statistics, Mathematical Optimisation)perception, understanding, prediction, classification

2. Symbolic AI: Automated Reasoning (Symbolic AI, Search based AI)problem solving, decision making, planning

3. Sub-symbolic AI: (Control theory, Computational intelligence, Softcomputing) robotics, alternative problem solving, alternative understanding

4. Collective AI: Multiagent systems (Agent Architectures, Game Theory, Mechanism Design, Combinatorial Auctions)robotics, distributed systems, market mechanisms, AI simulations

Page 16: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

16

Artificial Intelligence Approaches

1. Statistical AI: Machine Learning (Statistics, Optimisation, Neural Networks, Deep Learning)perception, understanding, prediction, classification

2. Symbolic AI: Automated Reasoning (Symbolic AI, Search based AI)problem solving, decision making, planning

3. Sub-symbolic AI: (Control theory, Computational intelligence, Softcomputing) robotics, alternative problem solving, alternative understanding

4. Collective AI: Multiagent systems (Agent Architectures, Game Theory, Mechanism Design, Combinatorial Auctions)robotics, distributed systems, market mechanisms, AI simulations

Page 17: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

17

Artificial Intelligence Approaches

1. Statistical AI: Machine Learning (Computational Statistics, Mathematical Optimisation)perception, understanding, prediction, classification

2. Symbolic AI: Automated Reasoning (Symbolic AI, Search based AI)problem solving, decision making, planning

3. Sub-symbolic AI: (Control theory, Computational intelligence, Softcomputing, Neural Networks, Deep Learning) robotics, alternative problem solving, alternative understanding

4. Collective AI: Multiagent systems (Agent Architectures, Game Theory, Mechanism Design, Combinatorial Auctions)robotics, distributed systems, market mechanisms, AI simulations

Page 18: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

18

Artificial Intelligence in OI

1. Statistical AI: Machine Learning. (Computational Statistics, Mathematical Optimisation)perception, understanding, prediction, classification

2. Symbolic AI: Automated Reasoning (Symbolic AI, Search based AI)problem solving, decision making, planning

3. Sub-symbolic AI: (Control theory, Computational intelligence, Softcomputing, Neural Networks, Deep Learning) robotics, alternative problem solving, alternative understanding

4. Collective AI: Multiagent systems (Agent Architectures, Game Theory, Mechanism Design, Combinatorial Auctions)robotics, distributed systems, market mechanisms, AI simulations

B4B33RPZ

B4B36ZUI

B4B36FUP

B4M33SSU

B4M33MAS

B4M33PUIB4M33LUP

B4M33UIR

B4M33SMU

Page 19: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

B4B36ZUI Content

1. Introduction to AI. Search-based AI, Uninformed search 2. Informed A* search 3. Advanced A*: RBFS, SMA* 4. Local search, Online search 5. Constrain Satisfaction Problem 6. Two players games 7. Monte Carlo Tree Search 8. Knowledge representation - Introduction 9. Knowledge representation in FOL  10. Rational Decisions under Uncertainty 11. Sequential Decisions under Uncertainty 12. Knowledge in Multi-agent Systems 13. AI Applications

Page 20: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

http://aima.cs.berkeley.edu

Page 21: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

21

Introduction to AI Uninformed Search

R&N: Chap. 3, Sect. 3.1–3.6

Page 22: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

22

Page 23: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

23

Example: 8-Puzzle

1

2

3 4

5 6

7

8 1 2 3

4 5 6

7 8

Initial state Goal state

State: any arrangement of 8 numbered tiles and an empty tile

Page 24: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

24

8-Puzzle: Successor Function

1

2

3 4

5 6

7

8

1

2

3 4

5

6

78

1

2

3 4

5 6

78

1

2

3 4

5 6

78

search is about the exploration of alternatives

SUCC(state) → subsetofstates The successor function is knowledgeabout the 8-puzzle game, but it does not tell us which outcome to use, nor towhich state of the board to apply it.

Page 25: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

25

(n2-1)-puzzle

1

2

3 4

5 6

7

8

12

15

11

14

10

13

9

5 6 7 8

4321 ....

Page 26: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

26

15-Puzzle Sam Loyd offered $1,000 of his own money to the

first person who would solve the following problem:

12

14

11

15

10

13

9

5 6 7 8

4321

12

15

11

14

10

13

9

5 6 7 8

4321

?

Page 27: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

27

Stating a Problem as a Search Problem

▪ State space S ▪ Successor function: x ∈ S → SUCCESSORS(x) ∈ 2S

▪ Initial state s0 ▪ Goal test: x∈S → GOAL?(x) =T or F ▪ Arc cost

S1

3 2

Page 28: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

28

State Graph

▪ Each state is represented by a distinct node

▪ An arc (or edge) connects a node s to a node s’ if s’ ∈ SUCC(s)

▪ The state graph may contain more than one connected component

Page 29: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

29

Solution to the Search Problem▪ A solution is a path connecting the initial node to

a goal node (any one)

I

G

Page 30: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

30

Solution to the Search Problem▪ A solution is a path connecting the initial node to

a goal node (any one) ▪ The cost of a path is the sum of the arc costs

along this path ▪ An optimal solution is a solution path of minimum

cost ▪ There might be

no solution ! I

G

Page 31: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

31

How big is the state space of the (n2-1)-puzzle?

▪ 8-puzzle → 9! = 362,880 states ▪ 15-puzzle → 16! ~ 2.09 x 1013 states ▪ 24-puzzle → 25! ~ 1025 states

But only half of these states are reachable from any given state(but you may not know that in advance)

Page 32: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

32

8-puzzle ! 362,880 states

15-puzzle ! 2.09 x 1013 states

24-puzzle ! 1025 states

100 millions states/sec

0.036 sec

~ 55 hours

> 109 years

8-, 15-, 24-Puzzles

Page 33: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

33

Searching the State Space

▪ Often it is not feasible (or too expensive) to build a complete representation of the state graph

▪ A problem solver must construct a solution by exploring a small portion of the graph

Page 34: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

34

Searching the State Space

Search tree

Page 35: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

35

Searching the State Space

Search tree

Page 36: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

36

Searching the State Space

Search tree

Page 37: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

37

Searching the State Space

Search tree

Page 38: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

38

Searching the State Space

Search tree

Page 39: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

39

Searching the State Space

Search tree

Page 40: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

40

Other examples

Page 41: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

41

8-Queens ProblemPlace 8 queens in a chessboard so that no two queens are in the same row, column, or diagonal.

A solution Not a solution

Page 42: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

42

Formulation #1

▪ States: all arrangements of 0, 1, 2, ..., 8 queens on the board

▪ Initial state: 0 queens on the board

▪ Successor function: each of the successors is obtained by adding one queen in an empty square

▪ Arc cost: irrelevant ▪ Goal test: 8 queens are on the

board, with no queens attacking each other

! ~ 64x63x...x57 ~ 3x1014 states

Page 43: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

43

Formulation #2

▪ States: all arrangements of k = 0, 1, 2, ..., 8 queens in the k leftmost columns with no two queens attacking each other

▪ Initial state: 0 queens on the board ▪ Successor function: each

successor is obtained by adding one queen in any square that is not attacked by any queen already in the board, in the leftmost empty column

▪ Arc cost: irrelevant ▪ Goal test: 8 queens are on the

board! 2,057 states

Page 44: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

44

n-Queens Problem▪ A solution is a goal node, not a path to this node

(typical of design problem) ▪ Number of states in state space:

8-queens → 2,057 100-queens → 1052

▪ But techniques exist to solve n-queens problems efficiently for large values of n

They exploit the fact that there are many solutions well distributed in the state space

Page 45: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

45

Path Planning

What is the state space?

Page 46: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

46

Formulation #1

Cost of one horizontal/vertical step = 1 Cost of one diagonal step = √2

Page 47: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

47

Optimal Solution

This path is the shortest in the discretized state space, but not in the original continuous space

Page 48: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

48

Formulation #2sweep-line

Page 49: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

49

Formulation #2

Page 50: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

50

States

Page 51: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

51

Successor Function

Page 52: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

52

Solution Path

A path-smoothing post-processing step is usually needed to shorten the path further

Page 53: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

53

Formulation #3

Cost of one step: length of segment

Page 54: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

54

Formulation #3

Cost of one step: length of segment

Visibility graph

Page 55: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

55

Solution Path

The shortest path in this state space is also the shortest in the original continuous space

Page 56: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

56

Simple Problem-Solving-Agent

1. s0 ← sense/read initial state 2. GOAL? ← select/read goal test 3. Succ ← read successor function 4. solution ← search(s0, GOAL?, Succ)

5. perform(solution)

Page 57: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

57

Search Nodes and States

1

2

3 4

5 6

7

8

1

2

3 4

5 6

7

8

1

2

3 4

5 6

78

13

5 6

8

1

3

4

5 6

7

82

4 7

2

1

2

3 4

5 6

7

8

If states are allowed to be revisited,the search tree may be infinite even

when the state space is finite

Page 58: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

58

Data Structure of a Node

PARENT-NODESTATE

Depth of a node N = length of path from root to N

(depth of the root = 0)

BOOKKEEPING

5Path-Cost

5DepthRightAction

Expanded yes...

CHILDREN

1

2

3 4

5 6

7

8

Page 59: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

59

Node expansion The expansion of a node N consists of:

1) Evaluating the successor function on STATE(N)

2) Generating a child of N for each state returned by the function

node generation ≠ node expansion

1

2

3 4

5 6

7

8

N

1

3

5 6

8

1

3

4

5 6

782

4 7

2

1

2

3 4

5 6

7

8

Page 60: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

▪ The Open-List is the set of all search nodes that haven’t been expanded yet

60

Open-List of Search Tree

Page 61: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

61

Search Strategy

▪ The Open-List is the set of all search nodes that haven’t been expanded yet

▪ The Open-List is implemented as a priority queue INSERT(node,Open-List) REMOVE(Open-List) ▪ The ordering of the nodes in Open-List defines

the search strategy

Page 62: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

62

Search Algorithm #1SEARCH#1 1. If GOAL?(initial-state) then return initial-state 2. INSERT(initial-node,Open-List) 3. Repeat:

a. If empty(Open-List) then return failure b. N ← REMOVE(Open-List) c. s ← STATE(N) d. For every state s’ in SUCCESSORS(s)

i. Create a new node N’ as a child of N ii. If GOAL?(s’) then return path or goal state iii.INSERT(N’,Open-List)

Expansion of N

Page 63: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

63

Performance Measures

▪ CompletenessA search algorithm is complete if it finds a solution whenever one exists[What about the case when no solution exists?]

▪ OptimalityA search algorithm is optimal if it returns a minimum-cost path whenever a solution exists

▪ ComplexityIt measures the time and amount of memory required by the algorithm

Page 64: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

64

Blind vs. Heuristic Strategies

▪ Blind (or un-informed) strategies do not exploit state descriptions to order Open-List. They only exploit the positions of the nodes in the search tree

▪ Heuristic (or informed) strategies exploit state descriptions to order Open-List (the most “promising” nodes are placed at the beginning of Open-List)

Page 65: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

65

ExampleFor a blind strategy, N1 and N2 are just two nodes (at some position in the search tree)

Goal state

N1

N2STATE

STATE1

2

3 4

5 6

7

8

1 2 3

4 5

67 8

1 2 3

4 5 6

7 8

Page 66: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

66

ExampleFor a heuristic strategy counting the number of misplaced tiles, N2 is more promising than N1

Goal state

1

2

3 4

5 6

7

8

1 2 3

4 5

67 8

1 2 3

4 5 6

7 8

N1

N2STATE

STATE

Page 67: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

67

Remark

▪ Some search problems, such as the (n2-1)-puzzle, are NP-hard

▪ One can’t expect to solve all instances of such problems in less than exponential time (in n)

▪ One may still strive to solve each instance as efficiently as possible ! This is the purpose of the search strategy

Page 68: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

68

Blind Strategies

▪ Breadth-first - Bidirectional

▪ Depth-first - Depth-limited - Iterative deepening

▪ Uniform-Cost(variant of breadth-first)

Arc cost = 1

Arc cost = c(action) ≥ ε > 0

Page 69: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

69

Breadth-First Strategy

New nodes are inserted at the end of Open-List

2 3

4 5

1

6 7

Open-List = (1)

Page 70: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

70

Breadth-First Strategy

New nodes are inserted at the end of Open-List

Open-List = (2, 3)2 3

4 5

1

6 7

Page 71: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

71

Breadth-First Strategy

New nodes are inserted at the end of Open-List

Open-List = (3, 4, 5)2 3

4 5

1

6 7

Page 72: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

72

Breadth-First Strategy

New nodes are inserted at the end of Open-List

Open-List = (4, 5, 6, 7)2 3

4 5

1

6 7

Page 73: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

73

Important Parameters

1) Maximum number of successors of any state! branching factor b of the search tree

2) Minimal length (≠ cost) of a path between the initial and a goal state! depth d of the shallowest goal node in the search tree

Page 74: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

74

Evaluation

▪ b: branching factor ▪ d: depth of shallowest goal node ▪ Breadth-first search is:

- Complete? Not complete? - Optimal? Not optimal?

Page 75: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

75

Evaluation

▪ b: branching factor ▪ d: depth of shallowest goal node ▪ Breadth-first search is:

- Complete - Optimal if step cost is 1

▪ Number of nodes generated: ???

Page 76: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

76

Evaluation

▪ b: branching factor ▪ d: depth of shallowest goal node ▪ Breadth-first search is:

- Complete - Optimal if step cost is 1

▪ Number of nodes generated:1 + b + b2 + … + bd = ???

Page 77: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

77

Evaluation

▪ b: branching factor ▪ d: depth of shallowest goal node ▪ Breadth-first search is:

- Complete - Optimal if step cost is 1

▪ Number of nodes generated: 1 + b + b2 + … + bd. = (bd+1-1)/(b-1) = O(bd)

▪ Time and space complexity is O(bd)

Page 78: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

78

Big O Notation

g(n) = O(f(n)) if there exist two positive constants a and N such that:

for all n > N: g(n) ≤ a × f(n)

Page 79: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

Time and Memory Requirements

d # Nodes Time Memory2 111 .01 msec 11 Kbytes4 11,111 1 msec 1 Mbyte6 ~106 1 sec 100 Mb8 ~108 100 sec 10 Gbytes10 ~1010 2.8 hours 1 Tbyte12 ~1012 11.6 days 100 Tbytes14 ~1014 3.2 years 10,000 Tbytes

Assumptions: b = 10; 1,000,000 nodes/sec; 100bytes/node

Page 80: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

80

RemarkIf a problem has no solution, breadth-first may run for ever (if the state space is infinite or states can be revisited arbitrary many times)

12

14

11

15

10

13

9

5 6 7 8

4321

12

15

11

14

10

13

9

5 6 7 8

4321

?

Page 81: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

81

Bidirectional Strategytwo Open-List queues: Open-List1 and Open-List2

s

Time and space complexity is O(bd/2) << O(bd) if both trees have the same branching factor b

Page 82: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

82

Depth-First Strategy

New nodes are inserted at the front of Open-List

1

2 3

4 5

Open-List = (1)

Page 83: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

83

Depth-First Strategy

New nodes are inserted at the front of Open-List

1

2 3

4 5

Open-List = (2, 3)

Page 84: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

84

Depth-First Strategy

New nodes are inserted at the front of Open-List

1

2 3

4 5

Open-List = (4, 5, 3)

Page 85: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

85

Depth-First Strategy

New nodes are inserted at the front of Open-List

1

2 3

4 5

Page 86: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

86

Depth-First Strategy

New nodes are inserted at the front of Open-List

1

2 3

4 5

Page 87: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

87

Depth-First Strategy

New nodes are inserted at the front of Open-List

1

2 3

4 5

Page 88: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

88

Depth-First Strategy

New nodes are inserted at the front of Open-List

1

2 3

4 5

Page 89: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

89

Depth-First Strategy

New nodes are inserted at the front of Open-List

1

2 3

4 5

Page 90: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

90

Depth-First Strategy

New nodes are inserted at the front of Open-List

1

2 3

4 5

Page 91: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

91

Depth-First Strategy

New nodes are inserted at the front of Open-List

1

2 3

4 5

Page 92: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

92

Depth-First Strategy

New nodes are inserted at the front of Open-List

1

2 3

4 5

Page 93: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

93

Evaluation▪ b: branching factor ▪ d: depth of shallowest goal node ▪ m: maximal depth of a leaf node ▪ Depth-first search is:

- Complete?- Optimal?

Page 94: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

Evaluation▪ b: branching factor ▪ d: depth of shallowest goal node ▪ m: maximal depth of a leaf node ▪ Depth-first search is:

- Complete only for finite search tree- Not optimal

▪ Number of nodes generated (worst case): 1 + b + b2 + … + bm = O(bm)

▪ Time complexity is O(bm) ▪ Space complexity is O(bm) [or O(m)] [Reminder: Breadth-first requires O(bd) time and space]

Page 95: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

95

Depth-Limited Search

▪ Depth-first with depth cutoff k (depth at which nodes are not expanded)

▪ Three possible outcomes: - Solution - Failure (no solution) - Cutoff (no solution within cutoff)

Page 96: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

96

Iterative Deepening Search

the best of both breadth-first and depth-first search

IDS: for k = 0,1,2, … d do: Depth-first search with depth cutoff k

Page 97: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

97

Iterative Deepening

Page 98: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

98

Iterative Deepening

Page 99: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

99

Iterative Deepening

Page 100: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

100

Performance

▪ Iterative deepening search is: - Complete - Optimal if step cost =1

▪ Time complexity is:(d+1)(1) + db + (d-1)b2 + … + (1) bd = O(bd)

▪ Space complexity is: O(bd) or O(d)

Page 101: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

101

d = 5 and b = 2BF ID1 1 x 6 = 62 2 x 5 = 104 4 x 4 = 168 8 x 3 = 2416 16 x 2 = 3232 32 x 1 = 3263 120

120/63 ~ 2

Number of Generated Nodes (Breadth-First & Iterative Deepening)

Page 102: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

102

d = 5 and b = 10BF ID1 610 50100 4001,000 3,00010,000 20,000100,000 100,000111,111 123,456

123,456/111,111 ~ 1.111

Number of Generated Nodes (Breadth-First & Iterative Deepening)

Page 103: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

103

Comparison of Strategies

▪ Breadth-first is complete and optimal, but has high space complexity

▪ Depth-first is space efficient, but is neither complete, nor optimal

▪ Iterative deepening is complete and optimal, with the same space complexity as depth-first and almost the same time complexity as breadth-first

Page 104: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

104

Revisited States

8-queens

No

assembly planning

Few

1 2 34 5

67 8

8-puzzle and robot navigation

Many

search tree is finitesearch tree is infinite

Page 105: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

105

Avoiding Revisited States

▪ Requires comparing state descriptions ▪ Breadth-first search:

• Store all states associated with generated nodes in Closed-List

• If the state of a new node is in Closed-List, then discard the node

Page 106: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

106

Avoiding Revisited States

▪ Depth-first search: Solution 1:

– Store all states associated with nodes in current path in Closed-List

– If the state of a new node is in Closed-List, then discard the node

Page 107: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

107

Avoiding Revisited States

▪ Depth-first search: Solution 1:

– Store all states associated with nodes in current path in Closed-List

– If the state of a new node is in Closed-List, then discard the node

Only avoids loops

Solution 2: – Store all generated states in Closed-List – If the state of a new node is in Closed-List, then

discard the node Same space complexity as breadth-first !

Page 108: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

108

Uniform-Cost Search▪ Each arc has some cost c ≥ ε > 0, The cost of the path to each node N is g(N) = Σ costs of arcs ▪ The goal is to generate a solution path of minimal cost ▪ The nodes in the Open-List are sorted in increasing g(N)

▪ Need to modify search algorithm

S0

1A

5B

15C

S G

A

B

C

51

15

10

5

5

G11

G10

Page 109: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

109

Search Algorithm #1SEARCH#1 1. If GOAL?(initial-state) then return initial-state 2. INSERT(initial-node,Open-List) 3. Repeat:

a. If empty(Open-List) then return failure b. N ← REMOVE(Open-List) c. s ← STATE(N) d. For every state s’ in SUCCESSORS(s)

i. Create a new node N’ as a child of N ii. If GOAL?(s’) then return path or goal state iii.INSERT(N’,Open-List)

Page 110: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

110

Search Algorithm #2SEARCH#2 1. INSERT(initial-node,Open-List) 2. Repeat:

a. If empty(Open-List) then return failure b. N ← REMOVE(Open-List) c. s ← STATE(N) d. If GOAL?(s) then return path or goal state e. For every state s’ in SUCCESSORS(s)

i. Create a node N’ as a successor of N ii.INSERT(N’,Open-List)

Page 111: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

111

Avoiding Revisited States in Uniform-Cost Search

▪ For any state S, when the first node N such that STATE(N) = S is expanded, the path to N is the best path from the initial state to S

▪ So:

• When a node is expanded, store its state into CLOSED

• When a new node N is generated:

– If STATE(N) is in CLOSED, discard N

– If there exits a node N’ in the Open-List such that STATE(N’) = STATE(N), discard the node (N or N’) with the highest-cost path

Page 112: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

112

Search Algorithm #3SEARCH#3 1. INSERT(initial-node,Open-List) 2. Repeat:

a. If empty(Open-List) then return failure b. N ← REMOVE(Open-List) c. s ← STATE(N) d. INSERT(N,Closed-List) e. If GOAL?(s) then return path or goal state f. For every state s’ in SUCCESSORS(s)

i. Create a node N’ as a successor of N ii.If N is not in Closed-List and

If N is not on Open-List with lower cost then INSERT(N’,Open-List)

Page 113: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

113

Page 114: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

114Homework

Page 115: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

17

" A tile j appears after a tile i if either j appears on the same row as i to the right of i, or on another row below the row of i.

" For every i = 1, 2, ..., 15, let ni be the number of tiles j < i that appear after tile i (permutation inversions)

" N = n2 + n3 + … + n15 + row number of empty tile

Permutation Inversions

121511

1410

1395 6 7 8

4321

12

15

11

14

6

13

9

5 10 7 8

4321n2 = 0 n3 = 0 n4 = 0 n5 = 0 n6 = 0 n7 = 1 n8 = 1 n9 = 1 n10 = 4 n11 = 0 n12 = 0 n13 = 0 n14 = 0 n15 = 0

! N = 7 + 4

Page 116: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

18

" Proposition: (N mod 2) is invariant under any legal move of the empty tile

" Proof:• Any horizontal move of the empty tile leaves N

unchanged • A vertical move of the empty tile changes N by an

even increment (± 1 ± 1 ± 1 ± 1)

1215

11

14

10

13

9

5 6 7

8

4321

s =

1215

11

14

10

13

9

5 6 7

8

4321

s’ = N(s’) = N(s) + 3 + 1

Page 117: A4B36ZUI - Introduction to ARTIFICIAL INTELLIGENCE · Introduction to AI. Search-based AI, ... Searching the State Space Search tree. 40 ... (or informed) strategies exploit state

19

" Proposition: (N mod 2) is invariant under any legal move of the empty tile

" ! For a goal state g to be reachable from a state s, a necessary condition is that N(g) and N(s) have the same parity

" It can be shown that this is also a sufficient condition

" ! The state graph consists of two connected components of equal size