Date post: | 22-Dec-2015 |
Category: |
Documents |
View: | 217 times |
Download: | 0 times |
2
Objectives
Learn how to formulate a search problem.
Learn the different algorithms used to solve problems by searching.
Learn how to assess the performance of a search algorithm.
3
Introduction To solve a particular problem, we need to do define the
elements of the problem and its solution:
1. Define the problem precisely.
2. Isolate and represent the task knowledge that is necessary to solve the problem.
3. Choose and apply the best problem-solving technique(s) to the particular problem.
PROBLEM SOLVING BY SEARCHING (1)
4
Introduction
Search is a necessity to determine solutions to an enormous range of problems.
Search is a method that can be used by computers to examine a huge problem space to find a goal,
e.g searching for a contact lens on a football field.
Challenge: how to find the goal as quickly as possible or without using too many resources.
PROBLEM SOLVING BY SEARCHING (1)
5
Introduction
start
end
PROBLEM SOLVING BY SEARCHING (1)PROBLEM SOLVING BY SEARCHING (1)
A problem can be considered to consist of a goal and a set of actions That can be taken to lead to the goal.
6
PROBLEM SOLVING BY SEARCHING(1)PROBLEM SOLVING BY SEARCHING(1)
Example Problems
Toy problems
Vacuum world
The 8-Puzzle
The N-Queen...
Real world Problems
Touring problems
Route Finding
VLSI Layout
Robot navigation
Internet searching
7
PROBLEM SOLVING BY SEARCHING(1)PROBLEM SOLVING BY SEARCHING(1)
The 8-puzzle belongs to the family of Sliding-block puzzles.
The 8-puzzle has 9!/2=181,440 reacheable states.
The 8-puzzle has around 1.3 trillion states………..
Rubik’s cube: Rubik 1974.
Example Problems
8
PROBLEM SOLVING BY SEARCHING(1)PROBLEM SOLVING BY SEARCHING(1)
Problem solving as search
Search can be performed without any additional information about how to reach a solution: BLIND SEARCH.
Search can be performed using heuristics: INFORMED SEARCH.
To successfully operate, blind search should satisfy some properties:
It must be complete: it must generate every possible solution otherwise it might miss a suitable solution.
It must be non redundant: it should not generate the same solution twice.
Search can be data driven (starting from an initial state) or goal driven (starting fom goal).
9
PROBLEM SOLVING BY SEARCHING(1)PROBLEM SOLVING BY SEARCHING(1)
Problem solving as search
Key questions to be addressed:
1. What goal do we need to achieve?
2. How to know when a goal is reached?
3. What knoweldge we need?
4. What actions do we need to do?
Goal formulation: is the first step in problem solving. It takes into account current situation and some performance measure.
A goal can be described as: To know if a goal is achieved
1. a task to be accomplished. Need to define a goal test
2. a situation to be reached.
3. a set of properties to be acquired.
10
PROBLEM SOLVING BY SEARCHING(1)PROBLEM SOLVING BY SEARCHING(1)
Problem formulation
Search= Process of deciding what actions and states to consider given a goal.
Solution: sequence of actions that help achieving the goal.
Search: process of looking for a solution. Takes input (problem) and returns solution.
Execution: to carry out the actions recommended by the solution.
11
PROBLEM SOLVING BY SEARCHING(1)PROBLEM SOLVING BY SEARCHING(1)
Problem definition: a problem can be formally defined by1. Initial state: starting state2. Successor function: Given a particular state x,
fsuccessor(x)={<action,new-state>} where action is one of the legal actions in state x and new-state is the state that can be reached from x by applying action.
Allows together with the initial state to define the STATE SPACE that is the set of all states reachable from the initial state.
Problem formulation
12
PROBLEM SOLVING BY SEARCHING(1)PROBLEM SOLVING BY SEARCHING(1)
Problem formulation
A path in the state space is a sequence of states connected by a sequence of actions.
3. Goal test : determines whether a given state is a goal state.
4. Path cost funtion: assigns a cost to each path. Should recflect the performance measure.
13
PROBLEM SOLVING BY SEARCHING(1)PROBLEM SOLVING BY SEARCHING(1)
Arad
Zerind Sibiu Timisoara
Oradea Fagaras Rimnicu VilceaArad
Sibiu Bucharest
Solution definition: A potential solution is a path from the initial state to a goal state. Solution quality is measured by the path cost function and an optimal solution has the lowest path cost among all solutions.
14
PROBLEM SOLVING BY SEARCHING(1)PROBLEM SOLVING BY SEARCHING(1)
Touring problem: Given a set of n cities, the touring problem consists in visiting cities at least once starting and ending in the same city.
States: specified by the current city and the set of cities already visited.
Initial state: Any state can be designed as the initial state.
Successor function: generates the next city to visit according to the current state.
Goal test: Ending city reached and all cities have been visited.
Path cost: sum of all step costs.
Problem formulation
15
PROBLEM SOLVING BY SEARCHING(1)PROBLEM SOLVING BY SEARCHING(1)
Searching for solutions
To solve the problem, we need to define a search strategy that allows to explore efficiently the state space.
How to represent the state space? Tree Graph
Each state is represented by a node.
Expansion operation: A node is expanded if the successor function for the corresponding state generates new states.
16
PROBLEM SOLVING BY SEARCHING(1)PROBLEM SOLVING BY SEARCHING(1)
Informal description of Tree-Search
Function Tree-Search(problem,strategy) returns a solution or a failure
Initialize the search tree using the initial state of problem
Loop do
If there are no candidates for expansion then return failure
Choose a leaf node for expansion according to strategy
If the node contains a goal state then return the corresponding solution
Else expand the node and add the resulting node to the search tree
17
PROBLEM SOLVING BY SEARCHING(1)PROBLEM SOLVING BY SEARCHING(1)
Node definition:Data structure with 5
components: State: representation of a
physical configuration. Parent node: The node in the
search tree that generated this node.
Action: action applied to the parent node to generate this node.
Path cost: cost of the path from the initial state to the node.
Depth: The number of steps along the path from the initial state.
2 1 3
4 7
5 8 6
Node
Parent Node
Action: rightDepth= 3Path-cost=3
State
Towards a formal description
18
PROBLEM SOLVING BY SEARCHING(1)PROBLEM SOLVING BY SEARCHING(1)
How to deal with non expanded nodes?
Fringe : set of nodes generated but not yet expanded. Each node is a leaf node.
What is the suitable representation of fringe?
Set of nodes: Simplest way but could be computationally expensive.
Queue: best implementation of the fringe
oTowards a formal description
19
PROBLEM SOLVING BY SEARCHING(1)PROBLEM SOLVING BY SEARCHING(1)
What are the operations to be performed on the queue?
Make-Node(state,parent,action,depth,cost) : creates a node with the given parameters.
Empty?(queue) : returns TRUE only if there are no more nodes in the queue.
First(queue) : returns the first node of the queue. Remove-First(queue) : returns First(queue) and removes
it from the queue. Insert(element, queue) : inserts a node into the queue
and returns the resulting queue. Insert-All(elements, queue) : inserts a set of nodes into
the queue and returns the resulting queue.
Towards a formal description
20
PROBLEM SOLVING BY SEARCHING(1)PROBLEM SOLVING BY SEARCHING(1)
Function Tree-Search(problem,fringe) returns a solution or a failure
fringe ← Insert (Make-Node(Initial-state[problem],NULL,NULL,d,c),fringe)
Loop do If Empty?(fringe) then return failure node ← Remove-First(fringe) If Goal-Test[ problem] applied to State[node]
succeeds then return Solution(node) fringe ← Insert-all( Expand (node,problem),fringe)
Formal description of Tree-Search algorithm
21
PROBLEM SOLVING BY SEARCHINGPROBLEM SOLVING BY SEARCHING
Function Expand (node,problem) returns a set of nodes
successors ← empty set For each <action,result> in
fsuccessor(state(node)) doPath-cost ← path-cost[node] + step-
cost(State[node],action,result)Depth ← Depth[node]+1S ← Make-node (result, node, action, Path-cost,
Depth)Add s to successorsreturn successors
Formal description of Expand algorithm
22
PROBLEM SOLVING BY SEARCHING(1)PROBLEM SOLVING BY SEARCHING(1)
Completeness: is it guaranteed to find a solution when there is one.
Optimality: Does the strategy find the optimal solution.
Time complexity: how long does it take to find a solution? It can be measured by the number of generated nodes.
Space complexity: how much memory is needed to perform the search? It can be measured in terms of the maximum number of nodes stored in memory.
Performance Evaluation:
23
PROBLEM SOLVING BY SEARCHING(1)PROBLEM SOLVING BY SEARCHING(1)
Time and space complexity are measured in terms of:
b : The branching factor: maximum number of successors of any node.
d : The depth of the shallowest goal node.
m : The maximum length of any path in the state space.
Performance Evaluation
24
PROBLEM SOLVING BY SEARCHINGPROBLEM SOLVING BY SEARCHING
Uninformed search Informed search
►Breadth-first ►Greedy best first
► Uniform cost ►A*
► Depth first ►Local search
► Depth limited ►……..► Iterative deepening depth first….
Basic Search Algorithms
25
PROBLEM SOLVING BY SEARCHINGPROBLEM SOLVING BY SEARCHING
Strategies that order nodes without using any domain specific information (only problem definition is provided).
Generate successors and simply differentiate between a goal state and a non goal state.
Blind search strategies differ by the order of node expansion.
Uninformed search (blind search)
26
PROBLEM SOLVING BY SEARCHINGPROBLEM SOLVING BY SEARCHING
Main idea: Nodes at depth i are expanded before nodes at depth (i+1).
Implementation: use of a First-In-First-Out queue (FIFO). Nodes visited first are expanded first.
Shallow nodes are expanded before deeper nodes.
Breadth first search (BFS)
27
PROBLEM SOLVING BY SEARCHINGPROBLEM SOLVING BY SEARCHING
Completeness: yes if the branching factor b is finite.
Optimality: shallowest goal is not necessarily the optimal one. It is optimal if all actions have the same cost.
Time complexity: At the worst case, BFS expands every node (except goal node) thus taking time as follows:
1 +b + b2 + b3 +….+ bd + (bd+1 – b)=O(bd+1)
Memory complexity: BFS keeps every node in memory. Space is a big problem.
Breadth first search Evaluation
28
PROBLEM SOLVING BY SEARCHINGPROBLEM SOLVING BY SEARCHING
In case of equal step costs, Breadth First search finds the optimal solution.
For any step-cost function, Uniform Cost search expands the node n with the lowest path cost.
UCS takes into account the total cost.
UCS is guided by path costs rather than depths. Nodes are ordered according to their path cost.
Uniform cost search (UCS)
32
PROBLEM SOLVING BY SEARCHINGPROBLEM SOLVING BY SEARCHING
DFS expands the deepest node in the current fringe of the search tree.
As nodes are expanded, they are dropped from the fringe so then the search « backs up » to the next shallowest node that still has unexplored successors.
DFS strategy is implemented using a Last-In_First-Out (LIFO) queue or stack.
Another alternative is to implement DFS with a recursive function that calls itself on each of its children in turn.
Depth first search (DFS)
34
PROBLEM SOLVING BY SEARCHINGPROBLEM SOLVING BY SEARCHING
Completeness: Incomplete in case of unbounded depth containing no solution.
Optimality: does not provide always optimal solutions.
Time complexity: At the worst case, DFS generates about O(bm) nodes in tha search tree.
Memory complexity: DFS requires less memory than BFS. It needs to store only a single path from the root to a leaf node along with the remaining unexpanded sibling nodes for each node in the path. The required storage is (bm+1) where b is the branching factor and m maximium depth.
Depth first search Evaluation
35
PROBLEM SOLVING BY SEARCHINGPROBLEM SOLVING BY SEARCHING
It is simply DFS with a depth bound. Searching is not permitted beyond the depth
bound.
Works well if we know what the depth of the solution is.
Termination is guaranteed.
If the solution is beneath the depth bound, the search cannot find the goal (hence this search algorithm is incomplete).
Otherwise use Iterative deepening search (IDS).
Depth-Limited Search (DLS)
36
PROBLEM SOLVING BY SEARCHINGPROBLEM SOLVING BY SEARCHING
Iterative Deepening Depth-First Search (IDS)
37
PROBLEM SOLVING BY SEARCHINGPROBLEM SOLVING BY SEARCHING
Key idea: Iterative deepening search (IDS) applies DLS repeatedly with increasing depth. It terminates when a solution is found or no solutions exists.
IDS combines the benefits of BFS and DFS: Like DFS the memory requirements are very modest (O(bd)). Like BFS, it is complete when the branching factor is finite.
The total number of generated nodes is :
N(IDS)=(d)b + (d-1) b2 + …+(1)bd
In general, iterative deepening is the preferred uninformed search method when there is a large search space and the depth of the solution is not known.
Iterative Deepening Depth-First Search (IDS)
38
PROBLEM SOLVING BY SEARCHINGPROBLEM SOLVING BY SEARCHING
Problem: Possibility of wasting time by expanding states that have already been encountered and expanded before.
Occurs when actions are reversible.
A solvable problem can become unsolvable if the algorithm does not detect them systematically.
For detection purposes, a comparison operation is needed.
For DFS, looping paths can be discarded immediately.
Need to keep more nodes in memory: tradeoff between time and space.
Keep a list to store every expanded node.
Avoiding repeated states
39
PROBLEM SOLVING BY SEARCHINGPROBLEM SOLVING BY SEARCHING
Function Graph-Search(problem,fringe) returns a solution or a failure
closed ← empty;fringe ← Insert (Make-Node(Initial-
state[problem],NULL,NULL,d,c),fringe)
Loop do If Empty?(fringe) then return failure node ← Remove-First(fringe) If Goal-Test[ problem] applied to State[node] succeeds then
return Solution(node) If state [node] is not in closed then add State [node] to closed fringe ← Insert-all( Expand (node,problem),fringe)
Solution: Graph Search instead of tree search
40
PROBLEM SOLVING BY SEARCHINGPROBLEM SOLVING BY SEARCHING
When the world is not fully observable, the agent must reason about sets of states that might get to rather than single states.
Search is performed in the belief state space instead of state space.
Initial state is a belief state.
Searching with partial information
41
PROBLEM SOLVING BY SEARCHINGPROBLEM SOLVING BY SEARCHING
Vaccum world example:
initial belief state = set of possible states
Searching with partial information
42
PROBLEM SOLVING BY SEARCHINGPROBLEM SOLVING BY SEARCHING
GO Right action on the belief state leads to:
Go Left action on the belief state leads to:
Suck action on the belief state leads to:
Searching with partial information
43
PROBLEM SOLVING BY SEARCHINGPROBLEM SOLVING BY SEARCHING
Search: process of constructing sequences of actions that achieve a goal given a problem.
The studied methods assume that the environment is observable, deterministic, static and completely known.
Goal formulation is the first step in solving problems by searching. It facilitates problem formulation.
Formulating a problem requires specifying four components: Initial states, successor function, goal test and path cost function. Environment is represented as a state space.
A solution is a path from the initial state to a goal state.
Search algorithms are judged on the basis of completeness, optimality, time complexity and space complexity.
Several search strategies: BFS, DFS, DLS, IDS,…
Summary