Download AI Intro (CS 1571) - Lecture 3: Problem Solving by Searching - Prof. Milos Hauskrecht and more Study notes Computer Science in PDF only on Docsity!
CS 1571 Intro to AI M. Hauskrecht
CS 1571 Introduction to AI
Lecture 3
Milos Hauskrecht [email protected] 5329 Sennott Square
Problem solving by searching
Course administrivia
Instructor: Milos Hauskrecht 5329 Sennott Square [email protected]
TA: Swapna Somasundaran 5422 Sennott Square [email protected]
Course web page: http://www.cs.pitt.edu/~milos/courses/cs1571/
CS 1571 Intro to AI M. Hauskrecht
Solving problems by searching
- Some problems have a straightforward solution
- Just apply the formula, or follow a standardized procedure Example: solution of the quadratic equation
- Hardly a sign of intelligence
- More interesting problems require search :
- more than one possible alternative needs to be explored before the problem is solved
- the number of alternatives to search among can be very large, even infinite.
Search example: Traveler problem
- Find a route from one city ( Arad ) to the other ( Bucharest )
CS 1571 Intro to AI M. Hauskrecht
A search problem
is defined by:
- A search space:
- A goal condition
A search problem
is defined by:
- A search space:
- What is it?
- A set of objects among which we search for the solution.
- What is the search space for the puzzle 8 problem?
- A goal condition
CS 1571 Intro to AI M. Hauskrecht
A search problem
is defined by:
- A search space:
- What is it?
- A set of objects among which we search for the solution.
- What is the search space for the puzzle 8 problem?
- A sequence of moves.
- A goal condition
- Give an example of a goal condition for the map problem.
A search problem
is defined by:
- A search space:
- What is it?
- A set of objects among which we search for the solution.
- What is the search space for the puzzle 8 problem?
- A sequence of moves.
- A goal condition
- Give an example of a goal condition for the map problem.
- A path from A to B.
- The shortest path from A to B.
CS 1571 Intro to AI M. Hauskrecht
Graph search
- Less obvious conversion: Puzzle 8. Find a sequence of moves from the initial configuration to the goal configuration. - nodes corresponds to states of the game, - links to valid moves made by the player
start target
Search problem
Search problems that can be represented or converted into a graph search problems can be defined in terms of:
- Initial state
- State (configuration) we start to search from (e.g. start city, initial game position)
- Operators :
- Transform one state to another (e.g. valid connections between cities, valid moves in Puzzle 8)
- Goal condition:
- Defines the target state (destination, winning position)
- Search space ( the set of objects we search for the solution) :
- is now defined indirectly through : the initial state + operators
CS 1571 Intro to AI M. Hauskrecht
Graph search problem
- States - game positions, or locations in the map that are represented by nodes in the graph
- Operators - connections between cities, valid moves
- Initial state – start position, start city
- Goal state – target position (positions), target city (cities)
start
target
S
T
A
B
C
D
E
F
G H
I
J
K
L
N-queens
Some problems can be converted to the graph search problems
- But some problems are harder and less intuitive
- Take e.g. N-queens problem.
- Problem:
- We look for a configuration, not a sequence of moves
- No distinguished initial state, no operators (moves)
Goal configuration
CS 1571 Intro to AI M. Hauskrecht
N-queens
Search space:
- all configurations of N queens on the board
- Can we convert it to a graph search problem?
- We need states, operators, initial state and goal state.
…
initial^ goal
States are: N-queen configurations Initial state:? Operators (moves)?
N-queens
Search space:
- all configurations of N queens on the board
- Can we convert it to a graph search problem?
- We need states, operators, initial state and goal condition.
…
initial^ goals
Initial state: an arbitrary N-queen configuration Operators (moves): change a position of one queen
CS 1571 Intro to AI M. Hauskrecht
N-queens
Is there an alternative way to formulate the N-queens problem as a search problem?
N-queens Is there an alternative way to formulate the N-queens problem as a search problem?
- Search space: configurations of 0,1,2, … N queens
- Graph search:
- States configurations of 0,1,2,…N queens
- Operators: additions of a queen to the board
- Initial state: 0 queens on the board
start
CS 1571 Intro to AI M. Hauskrecht
Two types of graph search problems
- Path search
- Find a path between states S and T
- Example: traveler problem, Puzzle 8
- Additional goal criterion: minimum length (cost) path
- Configuration search (constraint satisfaction search)
- Find a state (configuration) satisfying the goal condition
- Example: n-queens problem, design of a device with a predefined functionality
- Additional goal criterion: “soft” preferences for configurations, e.g. minimum cost design
Search problem
Search problems that can be represented or converted into a graph search problems can be defined in terms of:
- Initial state
- State (configuration) we start to search from (e.g. start city, initial game position)
- Operators :
- Transform one state to another (e.g. valid connections between cities, valid moves in Puzzle 8)
- Goal condition:
- Defines the target state (destination, winning position)
- Search space ( the set of objects we search for the solution) :
- is now defined indirectly through : the initial state + operators
CS 1571 Intro to AI M. Hauskrecht
Traveler problem.
Traveler problem formulation:
- States: different cities
- Initial state: city Arad
- Operators: moves to cities in the neighborhood
- Goal condition: city Bucharest
- Type of the problem: path search
- Possible solution cost: path length
Puzzle 8 example
Search problem formulation:
- States: tile configurations
- Initial state: initial configuration
- Operators: moves of the empty tile
- Goal: reach the winning configuration
- Type of the problem: path search
- Possible solution cost: a number of moves
Initial state Goal state
CS 1571 Intro to AI M. Hauskrecht
Comparison of two problem formulations
Operators: switch one of the queens
Operators: add a queen to the leftmost unoccupied column
1 + 4 + 42 + 43 + 44 < 45 - configurations altogether
Solution 2:
Solution 1 :
4
16
Even better solution to the N-queens
Operators: add a queen to the leftmost unoccupied column
Solution 2:
Improved solution with a smaller search space Operators: add a queen to the leftmost unoccupied column such that it does not attack already placed queens
< 45 - configurations altogether
- configurations altogether
CS 1571 Intro to AI M. Hauskrecht
Formulating a search problem
- Search (process)
- The process of exploration of the search space
- The efficiency of the search depends on:
- The search space and its size
- Method used to explore (traverse) the search space
- Condition to test the satisfaction of the search objective (what it takes to determine I found the desired goal object)
- Think twice before solving the problem by search:
- Choose the search space and the exploration policy
Search process
- Exploration of the state space through successive application of operators from the initial state
- A search tree = a kind of (search) exploration trace, with nodes corresponding to explored states
Arad
Zerind Sibiu Timisoara
Arad Oradea Arad Oradea Fagaras RimnicuVilcea
CS 1571 Intro to AI M. Hauskrecht
General search algorithm
General-search ( problem, strategy ) initialize the search tree with the initial state of problem loop if there are no candidate states to explore return failure choose a leaf node of the tree to expand next according to strategy if the node satisfies the goal condition return the solution expand the node and add all of its successors to the tree end loop
General search algorithm
General-search ( problem, strategy ) initialize the search tree with the initial state of problem loop if there are no candidate states to explore return failure choose a leaf node of the tree to expand next according to strategy if the node satisfies the goal condition return the solution expand the node and add all of its successors to the tree end loop
Arad
CS 1571 Intro to AI M. Hauskrecht
General search algorithm
General-search ( problem, strategy ) initialize the search tree with the initial state of problem loop if there are no candidate states to explore return failure choose a leaf node of the tree to expand next according to strategy if the node satisfies the goal condition return the solution expand the node and add all of its successors to the tree end loop
Arad
Zerind Sibiu Timisoara
General search algorithm
General-search ( problem, strategy ) initialize the search tree with the initial state of problem loop if there are no candidate states to explore return failure choose a leaf node of the tree to expand next according to strategy if the node satisfies the goal condition return the solution expand the node and add all of its successors to the tree end loop
Arad
Zerind Sibiu Timisoara
Arad Oradea