SEARCH ALGORITHMS David Kauchak CS30 – Spring 2015.

Slides:



Advertisements
Similar presentations
Cooperating Intelligent Systems
Advertisements

Uninformed Search CS 63 Chapter 3
Uninformed Search.
Jecho and Donatus Depth First and Breadth First Search.
Artificial Intelligence By Mr. Ejaz CIIT Sahiwal.
Algorithmic Software Verification II. Modeling using FSA.
Prolog Search. Implementing Search in Prolog How to represent the problem Uninformed Search –depth first –breadth first –iterative deepening search Informed.
Graphs CSC 220 Data Structure. Introduction One of the Most versatile data structures like trees. Terminology –Nodes in trees are vertices in graphs.
Problem Solving Agents A problem solving agent is one which decides what actions and states to consider in completing a goal Examples: Finding the shortest.
CPSC 322, Lecture 5Slide 1 Uninformed Search Computer Science cpsc322, Lecture 5 (Textbook Chpt 3.4) January, 14, 2009.
Binary Trees CS 110: Data Structures and Algorithms First Semester,
Feng Zhiyong Tianjin University Fall  datatype PROBLEM ◦ components: INITIAL-STATE, OPERATORS, GOAL- TEST, PATH-COST-FUNCTION  Measuring problem-solving.
SEARCH APPLICATIONS David Kauchak CS30 – Spring 2015.
Artificial Intelligence Problem solving by searching CSC 361
State-Space Searches. State spaces A state space consists of –A (possibly infinite) set of states The start state represents the initial problem Each.
Artificial Intelligence
Toy Problem: Missionaries and Cannibals
Problem solving by Searching Problem Formulation.
Intelligent agents Intelligent agents are supposed to act in such a way that the environment goes through a sequence of states that maximizes the performance.
1 Solving Problems by Searching. 2 Terminology State State Space Initial State Goal Test Action Step Cost Path Cost State Change Function State-Space.
Artificial Intelligence Problem solving by searching CSC 361 Prof. Mohamed Batouche Computer Science Department CCIS – King Saud University Riyadh, Saudi.
Intelligent agents Intelligent agents are supposed to act in such a way that the environment goes through a sequence of states that maximizes the performance.
Thoughts on AI Will computers ever be intelligent? Really intelligent? Tasks that previously were thought to require intelligence: adding and subtracting.
Blind Search-Part 2 Ref: Chapter 2. Search Trees The search for a solution can be described by a tree - each node represents one state. The path from.
Artificial Intelligence Problem solving by searching CSC 361
Artificial Intelligence Problem solving by searching CSC 361 Prof. Mohamed Batouche Computer Science Department CCIS – King Saud University Riyadh, Saudi.
State-Space Searches. 2 State spaces A state space consists of –A (possibly infinite) set of states The start state represents the initial problem Each.
For Friday Finish chapter 3 Homework: –Chapter 3, exercise 6 –May be done in groups. –Clarification on part d: an “action” must be running the program.
Solving Problems by Searching
State-Space Searches.
lib. umn. edu/torre107/si/pics/superficialintelligence2

CMSC 471 Spring 2014 Class #3 Tue 2/4/14 Problem Solving as Search Professor Marie desJardins,
Problem solving.
Uninformed Search Chapter 3. Building Goal-Based Agents We have a goal to reach –Driving from point A to point B –Put 8 queens on a chess board such that.
Uninformed Search Chapter 3 Some material adopted from notes by Charles R. Dyer, University of Wisconsin-Madison.
SEARCH David Kauchak CS30 – Spring Admin Assignment 7 due tomorrow Assignment 8 out soon Talk today 4:15 in Rose Hills Theatre.
State-Space Searches. 2 State spaces A state space consists of A (possibly infinite) set of states The start state represents the initial problem Each.
CS.462 Artificial Intelligence SOMCHAI THANGSATHITYANGKUL Lecture 02 : Search.
“Planning is bringing the future into the present so that you can do something about it now.” – Alan Lakein Thought for the Day.
For Friday Finish reading chapter 4 Homework: –Lisp handout 4.
CS344: Introduction to Artificial Intelligence (associated lab: CS386)
Problem solving by search Department of Computer Science & Engineering Indian Institute of Technology Kharagpur.
For Friday Read chapter 4, sections 1 and 2 Homework –Chapter 3, exercise 7 –May be done in groups.
Graphs David Johnson. Describing the Environment How do you tell a person/robot how to get somewhere? –Tell me how to get to the student services building…
Goal-based Problem Solving Goal formation Based upon the current situation and performance measures. Result is moving into a desirable state (goal state).
1 Solving Problems by Searching. 2 Terminology State State Space Goal Action Cost State Change Function Problem-Solving Agent State-Space Search.
CS621 : Artificial Intelligence Pushpak Bhattacharyya CSE Dept., IIT Bombay Lecture 2 - Search.
CS621: Artificial Intelligence Pushpak Bhattacharyya CSE Dept., IIT Bombay Lecture 13– Search 17 th August, 2010.
Uninformed Search.
SEARCH David Kauchak CS30 – Spring Admin Assignment 6 graded Assignment 7  1 extra day: Due 3/26 at 6pm  If you turn it in by the original due.
ARTIFICIAL INTELLIGENCE
Problem solving by Searching
Uninformed Search Chapter 3.
David Kauchak CS30 – Spring 2016
Some problems Cse-402 K3r20,k3r23.
CMSC 471 Fall 2011 Class #3 Thu 9/8/11 Problem Solving as Search
Artificial Intelligence Problem solving by searching CSC 361
Some problems Cse-402 K3r20,k3r23.
Problem Solving by Searching Search Methods :
(1) Breadth-First Search  S Queue S
Artificial Intelligence
State-Space Searches.
State-Space Searches.
Uninformed Search Chapter 3.
David Kauchak CS51A – Spring 2019
David Kauchak CS51A – Spring 2019
State-Space Searches.
Problem Solving by Searching Search Methods :
Presentation transcript:

SEARCH ALGORITHMS David Kauchak CS30 – Spring 2015

What order will BFS and DFS visit the states assuming states are added to to_visit left to right? add the start state to to_visit Repeat  take a state off the to_visit list  if it’s the goal state we’re done!  if it’s not the goal state Add all of the successive states to the to_visit list Depth first search (DFS): to_visit is a stack Breadth first search (BFS): to_visit is a queue

What order will BFS and DFS visit the states? Depth first search (DFS): to_visit is a stack Breadth first search (BFS): to_visit is a queue DFS: Why not 1, 2, 5? 1, 4, 3, 8, 7, 6, 9, 2, 5

What order will BFS and DFS visit the states? Depth first search (DFS): to_visit is a stack Breadth first search (BFS): to_visit is a queue DFS: , 4, 3, 8, 7, 6, 9, 2, 5 STACK 1

What order will BFS and DFS visit the states? Depth first search (DFS): to_visit is a stack Breadth first search (BFS): to_visit is a queue DFS: , 4, 3, 8, 7, 6, 9, 2, 5 STACK 2 3 4

What order will BFS and DFS visit the states? Depth first search (DFS): to_visit is a stack Breadth first search (BFS): to_visit is a queue DFS: , 4, 3, 8, 7, 6, 9, 2, 5 STACK 2 3

What order will BFS and DFS visit the states? Depth first search (DFS): to_visit is a stack Breadth first search (BFS): to_visit is a queue DFS: , 4, 3, 8, 7, 6, 9, 5 BFS: 1, 2, 3, 4, 5

Search variants implemented add the start state to to_visit Repeat  take a state off the to_visit list  if it’s the goal state we’re done!  if it’s not the goal state Add all of the successive states to the to_visit list

What order would this variant visit the states? , 2, 5

What order would this variant visit the states? , 2, 5, 3, 6, 9, 7, 8 What search algorithm is this?

What order would this variant visit the states? , 2, 5, 3, 6, 9, 7, 8 DFS! Where’s the stack?

One last DFS variant How is this different?

One last DFS variant Returns ALL solutions found, not just one

Missionaries and Cannibals Three missionaries and three cannibals wish to cross the river. They have a small boat that will carry up to two people. Everyone can navigate the boat. If at any time the Cannibals outnumber the Missionaries on either bank of the river, they will eat the Missionaries. Find the smallest number of crossings that will allow everyone to cross the river safely. What is the “state” of this problem (it should capture all possible valid configurations)?

Missionaries and Cannibals Three missionaries and three cannibals wish to cross the river. They have a small boat that will carry up to two people. Everyone can navigate the boat. If at any time the Cannibals outnumber the Missionaries on either bank of the river, they will eat the Missionaries. Find the smallest number of crossings that will allow everyone to cross the river safely.

Missionaries and Cannibals Three missionaries and three cannibals wish to cross the river. They have a small boat that will carry up to two people. Everyone can navigate the boat. If at any time the Cannibals outnumber the Missionaries on either bank of the river, they will eat the Missionaries. Find the smallest number of crossings that will allow everyone to cross the river safely. MMMCCC B MMCC B MC MC B MMCC …

Searching for a solution MMMCCC B ~~ What states can we get to from here?

Searching for a solution MMMCCC B ~~ MMCC ~~ B MC MMMC ~~ B CC Next states? MMMCC ~~ B C

Code!

Talk about copy.deepcopy

Missionaries and Cannibals Solution Near side Far side 0 Initial setup: MMMCCC B - 1 Two cannibals cross over: MMMC B CC 2 One comes back: MMMCC B C 3 Two cannibals go over again: MMM B CCC 4 One comes back: MMMC B CC 5 Two missionaries cross: MC B MMCC 6 A missionary & cannibal return: MMCC B MC 7 Two missionaries cross again: CC B MMMC 8 A cannibal returns: CCC B MMM 9 Two cannibals cross: C B MMMCC 10 One returns: CC B MMMC 11 And brings over the third: - B MMMCCC How is this solution different than the n-queens problem?

Missionaries and Cannibals Solution Near side Far side 0 Initial setup: MMMCCC B - 1 Two cannibals cross over: MMMC B CC 2 One comes back: MMMCC B C 3 Two cannibals go over again: MMM B CCC 4 One comes back: MMMC B CC 5 Two missionaries cross: MC B MMCC 6 A missionary & cannibal return: MMCC B MC 7 Two missionaries cross again: CC B MMMC 8 A cannibal returns: CCC B MMM 9 Two cannibals cross: C B MMMCC 10 One returns: CC B MMMC 11 And brings over the third: - B MMMCCC Solution is not a state, but a sequence of actions (or a sequence of states)

One other problem MMMCCC B~~MMMCC B~~ C What would happen if we ran DFS here? MMMCCC B ~~ MMCC ~~ B MC MMMC ~~ B CC MMMCC ~~ B C MMMCCC B~~

One other problem MMMCCC B~~MMMCC B~~ C MMMCCC B ~~ MMCC ~~ B MC MMMC ~~ B CC MMMCC ~~ B C MMMCCC B~~ If we always go left first, will continue forever!

One other problem MMMCCC B~~MMMCC B~~ C MMMCCC B ~~ MMCC ~~ B MC MMMC ~~ B CC MMMCC ~~ B C MMMCCC B~~ Does BFS have this problem?No!

DFS vs. BFS Why do we use DFS then, and not BFS?

DFS vs. BFS … Consider a search problem where each state has two states you can reach Assume the goal state involves 20 actions, i.e. moving between ~20 states How big can the queue get for BFS?

DFS vs. BFS … Consider a search problem where each state has two states you can reach Assume the goal state involves 20 actions, i.e. moving between ~20 states At any point, need to remember roughly a “row”

DFS vs. BFS … Consider a search problem where each state has two states you can reach Assume the goal state involves 20 actions, i.e. moving between ~20 states How big does this get?

DFS vs. BFS … Consider a search problem where each state has two states you can reach Assume the goal state involves 20 actions, i.e. moving between ~20 states Doubles every level we have to go deeper. For 20 actions that is 2 20 = ~1 million states!

DFS vs. BFS … Consider a search problem where each state has two states you can reach Assume the goal state involves 20 actions, i.e. moving between ~20 states How many states would DFS keep on the stack?

DFS vs. BFS … Consider a search problem where each state has two states you can reach Assume the goal state involves 20 actions, i.e. moving between ~20 states Only one path through the tree, roughly 20 states

One other problem MMMCCC B~~MMMCC B~~ C MMMCCC B ~~ MMCC ~~ B MC MMMC ~~ B CC MMMCC ~~ B C MMMCCC B~~ If we always go left first, will continue forever! Solution?

DFS avoiding repeats