search problem formulation and uninformed searcha23gao/cs486686_s19/slides/lec...1/30 search problem...

30
1/30 Search Problem Formulation and Uninformed Search Alice Gao Lecture 3 Readings: R & N 3.2, 3.3, 3.4.1, 3.4.3. Based on work by K. Leyton-Brown, K. Larson, and P. van Beek

Upload: others

Post on 30-Jul-2020

5 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Search Problem Formulation and Uninformed Searcha23gao/cs486686_s19/slides/lec...1/30 Search Problem Formulation and Uninformed Search Alice Gao Lecture 3 Readings: R & N 3.2, 3.3,

1/30

SearchProblem Formulation and Uninformed

Search

Alice GaoLecture 3

Readings: R & N 3.2, 3.3, 3.4.1, 3.4.3.

Based on work by K. Leyton-Brown, K. Larson, and P. van Beek

Page 2: Search Problem Formulation and Uninformed Searcha23gao/cs486686_s19/slides/lec...1/30 Search Problem Formulation and Uninformed Search Alice Gao Lecture 3 Readings: R & N 3.2, 3.3,

2/30

Outline

Learning Goals

Applications of Search

Definition of a Search Problem

Problem Formulation

A Review of Uninformed Search

Revisiting the Learning Goals

Page 3: Search Problem Formulation and Uninformed Searcha23gao/cs486686_s19/slides/lec...1/30 Search Problem Formulation and Uninformed Search Alice Gao Lecture 3 Readings: R & N 3.2, 3.3,

3/30

Learning goals

By the end of the lecture, you should be able to▶ Formulate a real world problem as a search problem.▶ Given a search problem, draw a portion of the search graph.▶ Trace the execution of and implement uninformed search

algorithms including Breadth-First Search and Depth-FirstSearch.

▶ Given a scenario, explain why it is or it is not appropriate touse an uninformed algorithm.

Page 4: Search Problem Formulation and Uninformed Searcha23gao/cs486686_s19/slides/lec...1/30 Search Problem Formulation and Uninformed Search Alice Gao Lecture 3 Readings: R & N 3.2, 3.3,

4/30

Example: Sliding puzzles

Initial State

5 3

8 7 6

2 4 1

Goal State

1 2 3

4 5 6

7 8

Page 5: Search Problem Formulation and Uninformed Searcha23gao/cs486686_s19/slides/lec...1/30 Search Problem Formulation and Uninformed Search Alice Gao Lecture 3 Readings: R & N 3.2, 3.3,

5/30

Example: Hua Rong Pass Puzzle

Page 6: Search Problem Formulation and Uninformed Searcha23gao/cs486686_s19/slides/lec...1/30 Search Problem Formulation and Uninformed Search Alice Gao Lecture 3 Readings: R & N 3.2, 3.3,

6/30

Example: Rubik’s cube

Page 7: Search Problem Formulation and Uninformed Searcha23gao/cs486686_s19/slides/lec...1/30 Search Problem Formulation and Uninformed Search Alice Gao Lecture 3 Readings: R & N 3.2, 3.3,

7/30

Example: River Crossing Puzzle

A parent and two children are trying to cross a river using a boat.▶ The capacity of the boat is 100kg.▶ The parent weighs 100kg.▶ Each child weighs 50kg.

How can they get across the river?

Page 8: Search Problem Formulation and Uninformed Searcha23gao/cs486686_s19/slides/lec...1/30 Search Problem Formulation and Uninformed Search Alice Gao Lecture 3 Readings: R & N 3.2, 3.3,

8/30

Example: N-Queens Problem

The n-queens problem: Place n queens on an n × n board so thatno pair of queens attacks each other.

Page 9: Search Problem Formulation and Uninformed Searcha23gao/cs486686_s19/slides/lec...1/30 Search Problem Formulation and Uninformed Search Alice Gao Lecture 3 Readings: R & N 3.2, 3.3,

9/30

Example: Propositional Satisfiability

Given a formula in propositional logic, determine if there is a wayto assign truth values to the Boolean variables to make theformula true.

((((a ∧ b) ∨ c) ∧ d) ∨ (¬e))

Applications:▶ FCC spectrum auction▶ Circuit design▶ Planning in AI

Page 10: Search Problem Formulation and Uninformed Searcha23gao/cs486686_s19/slides/lec...1/30 Search Problem Formulation and Uninformed Search Alice Gao Lecture 3 Readings: R & N 3.2, 3.3,

10/30

Example: Traveling Salesperson Problem

What is the shortest path that starts at city A, visits each city onlyonce, and returns to A?

Applications of TSP: https://bit.ly/2i9JdIV

Page 11: Search Problem Formulation and Uninformed Searcha23gao/cs486686_s19/slides/lec...1/30 Search Problem Formulation and Uninformed Search Alice Gao Lecture 3 Readings: R & N 3.2, 3.3,

11/30

Why search?

We would like to find a solution when we are▶ Not given an algorithm to solve a problem▶ Given a specification of what a solution looks like▶ (Given costs associated with certain actions)

Idea: search for a solution (with the minimum cost)

Page 12: Search Problem Formulation and Uninformed Searcha23gao/cs486686_s19/slides/lec...1/30 Search Problem Formulation and Uninformed Search Alice Gao Lecture 3 Readings: R & N 3.2, 3.3,

12/30

A Search Problem

Definition (Search Problem)A search problem is defined by

▶ A set of states▶ A start state▶ A goal state or goal test

▶ a boolean function which tells us whether a given state is agoal state

▶ A successor function▶ a mapping/action which takes us from one state to other states

▶ A cost associated with each action

Page 13: Search Problem Formulation and Uninformed Searcha23gao/cs486686_s19/slides/lec...1/30 Search Problem Formulation and Uninformed Search Alice Gao Lecture 3 Readings: R & N 3.2, 3.3,

13/30

Learning Goals

Applications of Search

Definition of a Search Problem

Problem Formulation

A Review of Uninformed Search

Revisiting the Learning Goals

Page 14: Search Problem Formulation and Uninformed Searcha23gao/cs486686_s19/slides/lec...1/30 Search Problem Formulation and Uninformed Search Alice Gao Lecture 3 Readings: R & N 3.2, 3.3,

14/30

Example: 8-Puzzle

Initial State

5 3

8 7 6

2 4 1

Goal State

1 2 3

4 5 6

7 8

Page 15: Search Problem Formulation and Uninformed Searcha23gao/cs486686_s19/slides/lec...1/30 Search Problem Formulation and Uninformed Search Alice Gao Lecture 3 Readings: R & N 3.2, 3.3,

15/30

Formulating 8-Puzzle as a Search Problem

Page 16: Search Problem Formulation and Uninformed Searcha23gao/cs486686_s19/slides/lec...1/30 Search Problem Formulation and Uninformed Search Alice Gao Lecture 3 Readings: R & N 3.2, 3.3,

16/30

CQ: The successor function

CQ: Which of the following is a successor of 530, 876, 241?(A) 350, 876, 241(B) 536, 870, 241(C) 537, 806, 241(D) 538, 076, 241

Page 17: Search Problem Formulation and Uninformed Searcha23gao/cs486686_s19/slides/lec...1/30 Search Problem Formulation and Uninformed Search Alice Gao Lecture 3 Readings: R & N 3.2, 3.3,

17/30

The Search Graph

Page 18: Search Problem Formulation and Uninformed Searcha23gao/cs486686_s19/slides/lec...1/30 Search Problem Formulation and Uninformed Search Alice Gao Lecture 3 Readings: R & N 3.2, 3.3,

18/30

Terminologies

▶ Search graph contains all the states and all the edges for thesuccessor function.

▶ Search tree is constructed as we execute the algorithm.

▶ Frontier contains all the leaf nodes available for expansion.

▶ Expanding a node removes it from from the frontier.

▶ Generating a node adds the node to the frontier.

Page 19: Search Problem Formulation and Uninformed Searcha23gao/cs486686_s19/slides/lec...1/30 Search Problem Formulation and Uninformed Search Alice Gao Lecture 3 Readings: R & N 3.2, 3.3,

19/30

The Search Tree

frontier

explored nodes

unexplored nodes

startnode

Page 20: Search Problem Formulation and Uninformed Searcha23gao/cs486686_s19/slides/lec...1/30 Search Problem Formulation and Uninformed Search Alice Gao Lecture 3 Readings: R & N 3.2, 3.3,

20/30

CQ: What do we have to store in memory?

CQ: Assume that we have hard-coded all the information of8-puzzle into our program. When we execute a search algorithm onthe 8-puzzle, what do we have to store in memory?(A) The frontier only(B) The search graph and the frontier(C) The search tree and the frontier(D) The search graph, the search tree, and the frontier

Page 21: Search Problem Formulation and Uninformed Searcha23gao/cs486686_s19/slides/lec...1/30 Search Problem Formulation and Uninformed Search Alice Gao Lecture 3 Readings: R & N 3.2, 3.3,

21/30

Graph Search Algorithm

Algorithm 1 Search1: let the frontier to be an empty list2: add initial state to the frontier3: while the frontier is not empty do4: remove curr_state from the frontier5: if curr_state is a goal state then6: return curr_state7: end if8: get all the successors of curr_state9: add all the successors to the frontier

10: end while11: return no solution

Page 22: Search Problem Formulation and Uninformed Searcha23gao/cs486686_s19/slides/lec...1/30 Search Problem Formulation and Uninformed Search Alice Gao Lecture 3 Readings: R & N 3.2, 3.3,

22/30

Uninformed Search Algorithms

The search algorithms differ by the order in which we removenodes from the frontier.

▶ Breadth-first search treats the frontier as a queue (FIFO).▶ Depth-first search treats the frontier as a stack (LIFO).

Page 23: Search Problem Formulation and Uninformed Searcha23gao/cs486686_s19/slides/lec...1/30 Search Problem Formulation and Uninformed Search Alice Gao Lecture 3 Readings: R & N 3.2, 3.3,

23/30

The Execution of BFS

Page 24: Search Problem Formulation and Uninformed Searcha23gao/cs486686_s19/slides/lec...1/30 Search Problem Formulation and Uninformed Search Alice Gao Lecture 3 Readings: R & N 3.2, 3.3,

24/30

The Execution of DFS

Page 25: Search Problem Formulation and Uninformed Searcha23gao/cs486686_s19/slides/lec...1/30 Search Problem Formulation and Uninformed Search Alice Gao Lecture 3 Readings: R & N 3.2, 3.3,

25/30

Comparing BFS and DFS

Consider the scenarios below. Which of BFS and DFS would youchoose? Why?

1. Memory is limited.2. All solutions are deep in the tree.3. The search graph contains cycles.4. The branching factor is large.5. We must find the shallowest goal node.6. Some solutions are very shallow.

Page 26: Search Problem Formulation and Uninformed Searcha23gao/cs486686_s19/slides/lec...1/30 Search Problem Formulation and Uninformed Search Alice Gao Lecture 3 Readings: R & N 3.2, 3.3,

26/30

CQ: BFS v.s. DFS

CQ: Suppose that we have very limited memory to solve a problem.Which of BFS and DFS would you choose?(A) I prefer BFS over DFS.(B) I prefer DFS over BFS.(C) Both are good choices.(D) Neither is a good choice.

Page 27: Search Problem Formulation and Uninformed Searcha23gao/cs486686_s19/slides/lec...1/30 Search Problem Formulation and Uninformed Search Alice Gao Lecture 3 Readings: R & N 3.2, 3.3,

27/30

CQ: BFS v.s. DFS

CQ: Suppose that the search graph for a problem contains cycles.Which of BFS and DFS would you choose?(A) I prefer BFS over DFS.(B) I prefer DFS over BFS.(C) Both are good choices.(D) Neither is a good choice.

Page 28: Search Problem Formulation and Uninformed Searcha23gao/cs486686_s19/slides/lec...1/30 Search Problem Formulation and Uninformed Search Alice Gao Lecture 3 Readings: R & N 3.2, 3.3,

28/30

Dealing with Cycles in the Search Graph

▶ Prune explored states by storing them in a hash table.▶ How would the properties of DFS change if we prune explored

states?

Page 29: Search Problem Formulation and Uninformed Searcha23gao/cs486686_s19/slides/lec...1/30 Search Problem Formulation and Uninformed Search Alice Gao Lecture 3 Readings: R & N 3.2, 3.3,

29/30

Dealing with Cycles in the Search Graph

Algorithm 2 Search1: let the frontier to be an empty list2: add initial state to the frontier3: while the frontier is not empty do4: remove curr_state from the frontier5: if curr_state is a goal state then6: return curr_state7: end if8: get all the successors of curr_state9: add all the successors to the frontier

10: end while11: return no solution

Page 30: Search Problem Formulation and Uninformed Searcha23gao/cs486686_s19/slides/lec...1/30 Search Problem Formulation and Uninformed Search Alice Gao Lecture 3 Readings: R & N 3.2, 3.3,

30/30

Revisiting the learning goals

By the end of the lecture, you should be able to▶ Formulate a real world problem as a search problem.▶ Given a search problem, draw a portion of the search graph.▶ Trace the execution of and implement uninformed search

algorithms including Breadth-First Search and Depth-FirstSearch.

▶ Given a scenario, explain why it is or it is not appropriate touse an uninformed algorithm.