Presentation is loading. Please wait.

Presentation is loading. Please wait.

Tutorial 1 Uninformed Search

Similar presentations


Presentation on theme: "Tutorial 1 Uninformed Search"— Presentation transcript:

1 Tutorial 1 Uninformed Search
CS Introduction to AI Tutorial 1 Uninformed Search

2 Problem Representation
Initial state (InitState) Successor function (Succ) Goal predicate (Goal-p) 25-Dec-18 Intro. to AI – Tutorial 1 – By Saher Esmeir & Nela Gurevich

3 Problem Example - Binary Tree
The problem is to find the number 12 in a binary tree A state is represented by a number Initial State: 1 Successor Function: Succ(x) = {2*x, 2*x + 1} Goal predicate: Goal-p(x) == true iff x == 12 1 2 3 4 5 6 7 25-Dec-18 Intro. to AI – Tutorial 1 – By Saher Esmeir & Nela Gurevich

4 General Search Routine
SearchFunction (States, Problem, Combiner) { If States == {} return ‘Search Failed’ CurrState <- Get and Remove first state in States if (Problem.Goal-p(CurrState) == true) return CurrState //or any other solution form else successors <- Problem.Succ(CurrState) States <- Combiner(successors,States) SearchFunction(States, Problem, Combiner) } 25-Dec-18 Intro. to AI – Tutorial 1 – By Saher Esmeir & Nela Gurevich

5 Intro. to AI – Tutorial 1 – By Saher Esmeir & Nela Gurevich
Combiner examples Append-Combiner(states1, states2) { // First nodes in states1, then nodes in states2 Result <- states1 For s in states2 Result <- Add s to the end of Result } Prepend-Combiner(states1, states2) { // First nodes in states2, then nodes in states1 Result <- states2 For s in states1 Result <- Add s to the end of Result } 25-Dec-18 Intro. to AI – Tutorial 1 – By Saher Esmeir & Nela Gurevich

6 General Search Routine
First call to the search function: Problem <- Initialize problem with appropriate data Combiner <- Choose state combination method that will characterize the search States <- Problem.InitState Solution = SearchFunction(States, Problem, Combiner) 25-Dec-18 Intro. to AI – Tutorial 1 – By Saher Esmeir & Nela Gurevich

7 Intro. to AI – Tutorial 1 – By Saher Esmeir & Nela Gurevich
DFS States <- Problem.InitState Solution = SearchFunction(States, Problem, Append-Combiner) 1 2 3 4 5 8 9 16 17 (For this example, solution will not be found) 32 33 25-Dec-18 Intro. to AI – Tutorial 1 – By Saher Esmeir & Nela Gurevich

8 Intro. to AI – Tutorial 1 – By Saher Esmeir & Nela Gurevich
Depth Limited DFS LimDepth-Append-Combiner(states1, states2) { Result <- {} For s in states1 if s.depth <= DepthLimit Result <- Add s to the end of Result For s in states2 } DepthLimit is a property of LimDepth-Append-Combiner 25-Dec-18 Intro. to AI – Tutorial 1 – By Saher Esmeir & Nela Gurevich

9 Intro. to AI – Tutorial 1 – By Saher Esmeir & Nela Gurevich
Depth Limited DFS LimDepth-Append-Combiner.DepthLimit <- 5 States <- Problem.InitState Solution = SearchFunction(States, Problem, LimDepth-Append-Combiner) 1 2 3 4 5 6 7 8 9 10 11 12 13 16 17 18 19 20 21 22 23 X X X X X X X X 25-Dec-18 Intro. to AI – Tutorial 1 – By Saher Esmeir & Nela Gurevich

10 Iterative deepening DFS
Iterative-Deepening-DFS(Problem, MaxDepth) { for i from 1 to MaxDepth LimDepth-Append-Combiner.DepthLimit <- i States <- Problem.InitState Solution = SearchFunction(States, Problem, LimDepth-Append-Combiner) If Solution != {} return Solution } 25-Dec-18 Intro. to AI – Tutorial 1 – By Saher Esmeir & Nela Gurevich

11 Intro. to AI – Tutorial 1 – By Saher Esmeir & Nela Gurevich
BFS States <- Problem.InitState Solution = SearchFunction(States, Problem, Prepend-Combiner) 1 2 3 4 5 6 7 8 9 10 11 12 13 25-Dec-18 Intro. to AI – Tutorial 1 – By Saher Esmeir & Nela Gurevich

12 Intro. to AI – Tutorial 1 – By Saher Esmeir & Nela Gurevich
Discussion: DFS Vs. BFS DFS BFS Completeness   Optimality of Solution   Time complexity O(bd) O(bd) Space complexity O(bd) O(bd) Search in graphs?   25-Dec-18 Intro. to AI – Tutorial 1 – By Saher Esmeir & Nela Gurevich

13 Example: 9-number puzzle
The numbers 1, 2, 3, 4, 5, 6, 7, 8, and 9 must be put in the depicted square, in such a way that the sums of the numbers in each row, column, and diagonal are equal. Solution: 9 5 1 8 3 4 6 7 2 25-Dec-18 Intro. to AI – Tutorial 1 – By Saher Esmeir & Nela Gurevich

14 Example: 9-number puzzle
Problem representation Initial state: Empty board Successors: Put one of the missing numbers in an empty place Goal-p: Board is full, sums are equal, as required 5 6 1 2 25-Dec-18 Intro. to AI – Tutorial 1 – By Saher Esmeir & Nela Gurevich

15 Example: 9-number puzzle
Which search algorithm should we use? Note that the solution length is exactly 9 DFS with depth limit = 9 will find the solution and will use little memory (linear in solution depth) BFS will find the solution at depth 9, however will require a lot of memory (will eventually hold all the tree till depth 9 in memory) Iterative deepening DFS is unnecessary here, since we know the solution depth in advance. The solution will not be found at shallower depth. 25-Dec-18 Intro. to AI – Tutorial 1 – By Saher Esmeir & Nela Gurevich

16 Intro. to AI – Tutorial 1 – By Saher Esmeir & Nela Gurevich
Example: LightzOut 5x5 board Each cell can be “On” or “Off” Click on a cell inverts the states of its 4 neighbors The goal is to turn off the lights 25-Dec-18 Intro. to AI – Tutorial 1 – By Saher Esmeir & Nela Gurevich

17 Intro. to AI – Tutorial 1 – By Saher Esmeir & Nela Gurevich
Example: LightzOut Click on the central cell Goal: 25-Dec-18 Intro. to AI – Tutorial 1 – By Saher Esmeir & Nela Gurevich

18 Intro. to AI – Tutorial 1 – By Saher Esmeir & Nela Gurevich
Example: LightzOut Problem representation: Initial state: The board to solve Successors: Boards that are the result of a single click on the current board Goal-p: Empty board 25-Dec-18 Intro. to AI – Tutorial 1 – By Saher Esmeir & Nela Gurevich

19 LightzOut – solution example
. . . . . . 25-Dec-18 Intro. to AI – Tutorial 1 – By Saher Esmeir & Nela Gurevich

20 Intro. to AI – Tutorial 1 – By Saher Esmeir & Nela Gurevich
Example: LightzOut Which search algorithm should we use? Given a board, we cannot predict solution length! Note that if we are in state1, and click on the same cell twice, we return back to state1 25-Dec-18 Intro. to AI – Tutorial 1 – By Saher Esmeir & Nela Gurevich

21 Intro. to AI – Tutorial 1 – By Saher Esmeir & Nela Gurevich
Example: LightzOut DFS with no restrictions might never find a solution for the problem – can get stuck in a loop Depth limited DFS can be used if we know the problem difficulty in advance Iterative deepening DFS is a good solution, especially when we do not know how difficult the problem is BFS? The branching factor is O(N2) BFS may be suitable for very simple problems For difficult problems, the memory amounts required for BFS are immense 25-Dec-18 Intro. to AI – Tutorial 1 – By Saher Esmeir & Nela Gurevich

22 Intro. to AI – Tutorial 1 – By Saher Esmeir & Nela Gurevich
Multiple Solutions Do not stop at the first solution MultGoal-SearchFunction (States, Problem, Combiner) { Solutions <- {} If States == {} return ‘Search Failed’ CurrState <- Get and remove first state in States if (Problem.Goal-p(CurrState) == true) Solutions <- Solutions + CurrState successors <- Problem.Succ(CurrState) States <-Combiner.combine(successors,States) SearchFunction(States, Problem, Combiner) } 25-Dec-18 Intro. to AI – Tutorial 1 – By Saher Esmeir & Nela Gurevich


Download ppt "Tutorial 1 Uninformed Search"

Similar presentations


Ads by Google