AI (IT) UNIT-2
AI (IT) UNIT-2
UNIT-2
Search Algorithms
Search Algorithm teaches computers to “act rationally” by achieving a certain goal with a
certain input value
Search: Searching is a step by step procedure to solve a search-problem in a given search space.
A search problem can have three main factors:
Search Space: Search space represents a set of possible solutions, which a system may
have.
Start State: It is a state from where agent begins the search.
Goal test: It is a function which observe the current state and returns whether the goal
state is achieved or not.
Search tree: A tree representation of search problem is called Search tree. The root of the search
tree is the root node which is corresponding to the initial state.
Search Trees
(a) The initial state Arad
Closed List: Contains all nodes already expanded. The closed list can be used to make
sure you don’t check the same node twice. So Closed list generally improves the speed
of algorithm.
Step 4.a. is a key step. The "algorithm" above gives no guidance about how to choose the
next state to evaluate
Random Search
A random search, while never practical as far as I know, is nevertheless interesting to
consider as a worst case search.
To program this search, modify step 4.a. so that a random state is chosen.
Given enough time, the goal state should be found, but a random search will probably
take more time (more states are checked) than any other method.
Informed Search:
Informed search algorithms use domain knowledge. In an informed search, problem
information is available which can guide the search. Informed search strategies can find a
solution more efficiently than an uninformed search strategy. Informed search is also
called a Heuristic search.
A heuristic is a way which might not always be guaranteed for best solutions but
guaranteed to find a good solution in reasonable time.
Informed search can solve much complex problem which could not be solved in another
way.
The informed search algorithm is more useful for large search space. Informed search
algorithm uses the idea of heuristics, so it is also called Heuristic search.
So Information about cost to goal taken into account
Ex: Best first search , A* search
Heuristics function: Heuristic is a function which is used in Informed Search, and it finds the
most promising path.
It takes the current state of the agent as its input and produces the estimation of how close
agent is from the goal.
The heuristic method, however, might not always give the best solution, but it guaranteed
to find a good solution in reasonable time.
Heuristic function estimates how close a state is to the goal. It is represented by h(n), and
it calculates the cost of an optimal path between the pair of states.
The value of the heuristic function is always positive, it is also called Heuristic search.
Admissibility of the heuristic function is given as:
h(n) <= h*(n)
Here h(n) is heuristic cost, and h*(n) is the estimated cost. Hence heuristic cost should
be less than or equal to the estimated cost.
Example:
Let us see how this works for route-finding problems in Romania; we use the straight
line distance heuristic, which we will call hSLD.
If the goal is Bucharest, we need to know the straight-line distances to Bucharest, which
are shown in below figure.
For example, hSLD(In(Arad))=366. Notice that the values of hSLD cannot be computed
from the problem description itself.
Moreover, it takes a certain amount of experience to know that hSLD is correlated with
actual road distances and is, therefore, a useful heuristic.
The above shows the progress of a greedy best-first search using hSLD to find a path from
Arad to Bucharest.
The first node to be expanded from Arad will be Sibiu because it is closer to Bucharest
than either Zerind or Timisoara.
The next node to be expanded will be Fagaras because it is closest. Fagaras in turn
generates Bucharest, which is the goal.
For this particular problem, greedy best-first search using hSLD finds a solution without
ever expanding a node that is not on the solution path; hence, its search cost is minimal. It is not
optimal, however: the path via Sibiu and Fagaras to Bucharest is 32 kilometers longer than the
path through Rimnicu Vilcea and Pitesti.
This shows why the algorithm is called “greedy”—at each step it tries to get as close to the goal
as it can.
Properties of greedy best-first search:
Greedy best-first tree search is also incomplete even in a finite state space, much like
depth-first search.
Consider the problem of getting from Iasi to Fagaras. The heuristic suggests that Neamt
be expanded first because it is closest to Fagaras, but it is a dead end.
The solution is to go first to Vaslui—a step that is actually farther from the goal
according to the heuristic—and then to continue to Urziceni, Bucharest, and Fagaras.
The algorithm will never find this solution, however, because expanding Neamt puts Iasi
back into the frontier,
Iasi is closer to Fagaras than Vaslui is, and so Iasi will be expanded again, leading to an
infinite loop.
The worst-case time and space complexity for the tree version is O(bm),
where b is the maximum branching factor of the search tree
m is the maximum depth of the search space.
With a good heuristic function, however, the complexity can be reduced substantially.
The amount of the reduction depends on the particular problem and on the quality of the
heuristic.
A* search
A* search is the most commonly known form of best-first search. It uses heuristic
function h(n), and cost to reach the node n from the start state g(n).
A* search algorithm finds the shortest path through the search space using the heuristic
function.
This search algorithm expands less search tree and provides optimal result faster.
In A* search algorithm, we use search heuristic as well as the cost to reach the node.
Hence we can combine both costs as following, and this sum is called as a fitness
number.
Algorithm A*:
OPEN = nodes on frontier CLOSED=expanded nodes
OPEN = {<s,nil>}
while OPEN is not empty
remove from OPEN the node <n,p> with minimum f(n)
place <n,p> on CLOSED
if n is a goal node, return success (path p)
for each edge connecting n & m with cost c
if <m,q> is on CLOSED and {p|e} is cheaper than q
then remove n from CLOSED , put <m,{p|e}> on OPEN
else if <m,q> is on OPEN AND {p|e} is cheaper than q
then replace q with {p|e}
else if m is not on OPEN put <m,{p|e}> on OPEN
return failure
Example 1:
:
Solution:
Start State: {(S, 5)}
Iteration1: {(S--> A, 4), (S-->G, 10)}
Iteration2: {(S--> A-->C, 4), (S--> A-->B, 7), (S-->G, 10)}
Iteration 3: {(S--> A-->C--->G, 6), (S--> A-->C--->D, 11), (S--> A-->B, 7), (S-->G, 10)}
Iteration 4 will give the final result, as S--->A--->C--->G it provides the optimal path with cost
6
A*: Difficulties
It becomes often difficult to use A* as the OPEN queue grows very large.
A solution is to use algorithms that work with less memory
Memory bounded heuristic search algorithms reduce the memory requirements for A* by
introducing IDA*.
IDA* is an iterative deepening algorithm.
The cut-off for nodes expanded in an iteration is decided by the f-value of the nodes.
IDA* Algorithm
Algorithm:
Set certain threshold/f-bound
If f(node) > threshold/f-bound, prune the node
Set threshold/f-bound = minimum cost of any node that is pruned
Terminates when goal is reached.