Lecture 03. Problem Solving and Search
Search Problem
A search problem consists of a search space and a goal condition.
The search space is the set of object among which we search for the solution.
The goal condition is the characteristics of the object we are trying to find in the search space.
Searching
Searching is the process of exploration of the search space.
The efficiency of the search depends on the search space and its size, the method used to traverse the search space and the condition to test the satisfaction of the search goal. This efficiency could be optimized by using smarter tactics when choosing the search space, the exploration method, and the design of the goal test.
Graph Representation of a Search Problem
Search problems can often be represented using graphs, a typical example of such problem is path finding.
A more complex problem may assign costs to each edge of the graph, and ask to find the path with the maximum/minimum cost.
Depending on the nature of the problem, the graph search often falls under two categories:
- Path Search, that we want to find a path between vertex S and T with some constraint.
- Configuration Search, that we want to find a vertex S that satisfies a given constraint.
A graph search problem can be formulated as:
- Initial State: The state where the search starts
- Operators: The transformation from one state to another
- Goal Condition: The definition of the target state
- Search Space: The set of objects we search for the goal. This can be defined with Initial State + Operators.
- (Problem Type): Is the answer a path or a specific state?
- (Possible Solution Cost): What is the cost from the initial state to goal might be?
Search Tree
A search tree is a structure that representing the exploration trace. The tree is built dynamically during the searching process with its branches corresponding to explored paths and leaves to the fringe of exploration. A branch in the search tree corresponds a path in the search space.
Note
The search tree is not simply a transformation of the state space. Depending on the implementation of search algorithm, a node may reappear multiple times on the search tree while there is only one of itself in the search space.
Implementation of Searching
Queuing Function
The explore strategy can often be viewed as an queuing function that determine which node will be selected next.
Search Tree Node
A search tree node is a data structure that maintains information such as the state description, the cost of this state, its depth in the search tree and the cumulative path cost to this node.
Search Algorithms (Uninformed)
Search Algorithms, or Search Methods, have following properties:
- Completeness: Does the algorithm find the solution, or all existing solutions?
- Optimal: Is the solution returned optimal?
- Complexity: How many time and memory is required to perform the algorithm?
Generic Search Algorithm
def generic_search(problem, strategy):
search_tree = SearchTree(problem.initial_state)
while True:
if strategy.candidate_states == 0: return SolutionNotFoundException
next_node = strategy.get_next_expand_node()
if problem.goal == next_node:
solution = strategy.pack_solution(next_node)
return solution
else: strategy.expand_node(next_node)
Breadth First Search
BFS always expand the shallowest node.
When expanding a node, its successors are enqueued to the end of the queue in FIFO manner.
- Completeness:
True
- Optimal:
True
(for the sortest path problems)
- Complexity:
For a search tree with branching factor of b and depth of d:
- Time Complexity: O(b^d) - EXPONENTIAL
- Space Complexity: O(b^d) - EXPONENTIAL
Depth First Search
DFS always expands the deepest node, and backtracks when the current node could not be expanded.
- Completeness:
False
(possible for infinite loops)
- Can be avoided by setting a depth limit, or introduce a cycle prevention mechanism.
- Optimal:
False
(for the sortest path problems)
- Complexity:
For a search tree with branching factor of b and max-depth of d:
- Time Complexity: O(b^d) - EXPONENTIAL
- Space Complexity: O(b\times d) - LINEAR
Iterative Deepening
The idea of this algorithm is try searching using DFS with a depth limit, if the solution is not reach, then increase the depth limit by a certain amount. Repeat until the solution is reached.
- Completeness:
True
- Optimal:
True
(for the sortest path problems)
- Complexity:
For a search tree with branching factor of b and max-depth of d:
- Time Complexity: O(b^d) - EXPONENTIAL
- Space Complexity: O(b\times d) - LINEAR
Bi-directional Search
This algorithm is used in some search problems we need to find the path from the initial state to a unique goal state.
The idea is to initiate search both from initial and goal state, and use inverse operators for goal-initiated search.
The strength of this method is if a state is found both in initial and goal initiated state, the two state can be "linked" even they are on different search tree, and a path can be constructed, thus cuts down search tree by half.
This search uses a path cost function assigned for node n, called g(n). The search strategy is to expand a leaf node with minimum g(n) first.
Uniform Cost Search
Always expand the node with least cumulative path cost.
- Completeness:
True
- Optimal:
True
(for the sortest path problems)
- Complexity:
For a search tree with branching factor of b and max-depth of d, assuming the solution costs g and the minimum arc cost is \varepsilon:
- Time Complexity: O(b^{g/\varepsilon}) - EXPONENTIAL
- Space Complexity: O(b^{g/\varepsilon}) - EXPONENTIAL
Search Algorithms (Informed)
An informed search algorithm, or a heuristic search algorithm, it is built upon the evaluation-function driven search, which is a search strategy that utilizes a node evaluation function f(n) to define the desirability of a node to be expanded next. Generally, this type of search algorithms expand the node with the best evaluation function value and is implemented with a priority queue.
Heuristic search algorithm further utilizes a heuristic function h(n) to evaluate the "potential" for a node to reach the desired state, and the order of node expansion is concerned with the combination of g(n) and h(n).
Admissible Heuristics
If a heuristic function h(n) never overstimates the distance of a node to the goal, noted h*(n), then the heuristic is called admissible.
It is possible to have mulitple admissible huristics of the same problem.
Heuristic function h_2 dominates h_1 if \forall n, h_2(n) \ge h_1(n).
Two admissible heuristic function can be combined to create a new admissible heuristic: h_3(n) = \max(h_1(n), h_2(n))
Heuristic can be created using a version of problem that have fewer constraints on the actions, called a relaxed problem.
Best-first Search
This search algorithm always expand the node "seems" to be the closest to the goal first.
- When f(n) = h(n), this algorithm is the same as Greedy Search.
- Completeness:
False
(Possible for infinite loop with repeat elimination)
- Optimal:
False
(f(n) does not respect g(n))
- Complexity:
For a search tree with branching factor of b and max-depth of d, assuming the solution costs g and the minimum arc cost is \varepsilon:
- Time Complexity: O(b^m) - EXPONENTIAL (worst, avg is better)
- Space Complexity: O(b^m) - EXPONENTIAL (worst, avg is better)
- When f(n) = g(n) + h(n), this algorithm is A* algorithm, where g(n) is the path cost function from initial node to node n. (If combined with iterative deepening, this creates a special version of A* called IDA*.)
- Completeness:
True
- Optimal:
False
(for any given heuristic function)
- Complexity:
For a search tree with branching factor of b and max-depth of d, assuming the solution costs g and the minimum arc cost is \varepsilon:
- Time Complexity: Number of nodes which f(n) is less than cost of the optimal path.
- Space Complexity: Same as time complexity.
IDA*
IDA* performs a limited-cost DFS for a evaluation function limit, and progressively increase the evaluation function limit until a solution is found.
One problem of this algorithm is the determine of increment of the limit, which have two tactics:
- Peak over the previous step boundary to guarantee that new node is expanded in the next cycle
- Increase by fixed amount
- Completeness:
True
- Optimal:
True
(for the sortest path problems)
- Complexity:
For a search tree with branching factor of b and max-depth of d:
- Time Complexity: O(b^d) - EXPONENTIAL
- Space Complexity: O(b\times d) - LINEAR