Unit3 Search
Unit3 Search
Chapter 3
Artificial Intelligence (UCS411)
Chapter Content
• Forward and backward
• State-space
• blind and Heuristic
• Problem-reduction
• A, A*, AO*, Minimax, Constraint propagation
• Neural, stochastic, and evolutionary search algorithms
• Sample applications
Search in terms of AI
Search is the process of considering various possible sequences
of operators applied to the initial state and finding out a
sequence which culminates in a goal state.
Input:
• Set of states
• Operators [and costs]
• Start state
• Goal state (test)
Output
Prof. Mukesh Singh (EIED) Artificial Intelligence 9 / 123
State Space Search
The search problem: How to control the search?
Given
• an initial state
• a set of operators (actions the agent can take)
• a set of goal states
• (optional) a path cost function
Find:
• a sequence of operators that leads from the initial state to a
goal state
Measuring effectiveness:
• Does the method find a solution at all?
• Is it a good solution (low path cost)
• What is the search cost?
The total cost is the sum of the search cost and the path cost
Prof. Mukesh Singh (EIED) Artificial Intelligence 10 / 123
State Space
Advantages:
1. It is very useful in AI because of it provides a set of all possible
states, operations and goals.
2. If the entire state space is for a problem then it is possible to
trace the path from the initial to the goal state and identify the
sequence of operation required for doing it.
Disadvantages:
1. It is not possible to visualize all states for a problem.
2. The resources of the computer system are very limited to handle
huge combinational state space.
Assignment
We are provided with two jugs: one having the capacity to hold 3
gallons of water and the other has the capacity to hold 4 gallons of
water. There is no other measuring equipment available and the
jugs also do not have any kind of marking on them. So, the agents
task here is to fill the 4-gallon jug with 2 gallons of water by using
only these two jugs and no other material. Initially, both our jugs
are empty.
Uninformed Informed
Search without Information Search with Information
No Knowledge Use knowledge to find steps to sol.
Time Consuming Quick Solution
More complexity(time, space) Less complexity (time, space)
Ex: DFS and BFS A*, Heuristic DFS, Best fast search
Question
You may wonder why we should use a blind search, when we could
use a search with some built in intelligence. The simple answer is
that there may not be any information we can use.
Prof. Mukesh Singh (EIED) Artificial Intelligence 22 / 123
BFS
Working of BFS
• Breadth-first search (BFS) is an algorithm that is used to graph data or searching tree
or traversing structures.
• The algorithm efficiently visits and marks all the key nodes in a graph in an accurate
breadthwise fashion.
• This algorithm selects a single node (initial or source point) in a graph and then visits
all the nodes adjacent to the selected node. Remember, BFS
Recusrsive method
• Shift N-1 disks from A to B, using C.
• Shift last disk from A to C.
• Shift N-1 disks from B to C, using A.
• It is a two-player game where one player (say Player 1) marks a letter X and the
opponent (Player 2) marks a letter 0.
• There is a 3x3 grid where the players put their letters.
• The player who is able to first mark his three letters in a complete row or column or
diagonal wins the game.
• Each state is represented by the positions occupied by the letters of the two players in
3x3 matrix along with other empty places.
• Initial State: Empty 3x3 matrix.
• Intermediate State: Any arrangement of a 3x3 matrix obtained after applying valid
rules / operators on the current state.
• Final State: Same letters in a complete row or column or diagonal.
Rules / Operators:
• The players will get turns one after the other
• The player can mark their own letter on the empty cell.
TSP?
Traveling Salesman Problem describe the salesman who is
travelling between N cities. Salesman knows the route and the cost
of cities so he has to find the possible shortest route that visits
every city exactly one and returns to the starting city.
Concept of Heuristic
• A heuristic is a technique that is used to solve a problem faster than the classic
methods.
• These techniques are used to find the approximate solution of a problem when
classical methods do not.
• It is said to be the problem-solving techniques that result in practical and quick
solutions.
• Heuristics use practical methods and shortcuts used to produce the solutions that
may or may not be optimal, but those solutions are sufficient in a given limited
timeframe.
The heuristic method might not always provide us the finest solution, but it is assured
that it helps us find a good solution in a reasonable time.
Euclidean distance
Euclidean distance is the length of the line segment joining a given pair of points in a
grid/graph. This is unique & is the shortest path between the given pair of points.
Manhattan distance
Manhattan distance is the sum of all horizontal and vertical segments joining a given pair
points in a grid/graph.
It is the distance between points if you cant travel diagonally, as you might have to
walk in a city where the streets are in a grid pattern
• Greedy best first search tries to expand the node that is closes to the goal
• on the grounds that this is likely to lead to a solution quickly
• The evaluation function is f(n)=h(n)
• Where h(n)= estimated cost from node n to the goal
• Greedy search ignores the cost of the path that has already been tranversed to reach n
• Therefore, the solution given is not necessararily optimal.
Drawback
• Greedy best first search can start down an infinite path and never return to try other
possibilities, it is uncomplete
• Because of its greediness the search makes choices that can lead to a dead end; then
one backs up in the search tree to the deepest unexpanded node
• It resembles DFS but it will backup when it hits a dead end
• The quality of the heuristics functons determins the practical usability of the greedy
search.
A* Search
• The most widely known form of best- first search
• It evaluates nodes by combining
• g(n), the cost to reach the node and
• h(n), the cost to get from the node to the goal
• f(n)=g(n)+h(n)
• Since g(n) gives the path cost from the start to node n, and h(n) gives the estimated
cost of the cheapest path from n to the goal
• f(n)=estimated cost of the cheapest solutions through n
The algorithm is identical to Uniform Cost Search except that A* uses g +h (instead of
only g)
• Both are part of informed search technique and use heuristic values to solve the
problem.
• The solution is guaranteed in both algorithm.
• A* always gives an optimal solution (shortest path with low cost)
• But It is not guaranteed to that AO* always provide an optimal solutions.
• Reason: Because AO* does not explore all the solution path once it got solution.
• Alpha-beta pruning can be applied at any depth of a tree, and sometimes it not only
prunes the tree leaves but also entire sub-tree. These parameters can be defined as:
• Alpha (α): The best (highest-value) choice we have found so far at any point
along the path of Maximizer. The initial value of alpha is -∞.
• Beta(β): The best (lowest-value) choice we have found so far at any point
along the path of Minimizer. The initial value of beta is +∞.
Stochastic Search
Is an optimization algorithm which incorporate randomness in its exploration of the search
space
Evolutionary Search
Evolutionary Search is a type of Stochastic Search Techniquies
Evolutionary Search
Genetic Algorithm is a type of Evolutionary Search.
Defining GA
• GA is a search technique used in computing to find true or approximate solutions to
optimization and search problems.
• They are categorized as global search heuristics.
• It is a particular class of evolutionary algorithm that use techniques inspired by
evolutionary biology such as inheritance, mutation, selection, and crossover (also
called recombination).
Why it is Robust ?
• If an air conditioner is designed for Europe it can not run in Saudi. The reason behind
is in the design of compressor.
• Mosquito: As the time changes, Mosquito will not have any effect on ’ALLOUT’.
• Biological system changes continuously to adapt the environment.
Concept of GA
• Genetic algorithms are implemented as a computer simulation.
• Here a population of large size where a probable solutions
exist is created.
• Traditionally, solutions are represented in binary as strings of
0s and 1s, but other encodings are also possible.
Prof. Mukesh Singh (EIED) Artificial Intelligence 100 / 123
Representation of Solutions
1)How do we represent a set of variables as a string?
Example 1
X=(x1, x2, x3, x4)
Let x1=15, x2=4, x3=21, x4=7
As a binary string, X can be written as
X=(01111, 00100, 10101, 00111)
2) Can we handle decimals or a continuous variable?
Let us say we want to represent 4.87
Multiply this by 100 which gives 487
We need 9 bits to represents 487
Because 28 represents 256 and 29 is 1111 1111 1 corresponds to
511
487 is smaller then 511 and hence 9 bits are enough to
represent 487
As our accuracy required increases; the number of bits required
will increase dramatically.
Prof. Mukesh Singh (EIED) Artificial Intelligence 101 / 123
Steps of GA
Example 1
Maximize(Y) = 800 - 62.83(2D+0.91D−0.2 )
where; 0 < D < 6.3
Important points
• A population of 2 to 4 trial design vectors (rather than just one)
is used initially in a problem with n design parameters(GA
works with a set of solutions)
• Each design vector (solution) is represented by a string of
binary variables, corresponding to the chromosomes in
genetics.
6.3 multiplied by 10 = 63
26 = 64 ; it means we can represent 0 < D < 6.3 in 6 bits
Mutation...
Mutation is a genetic operator used to maintain genetic diversity from one generation of a
population of genetic algorithm chromosomes to the next. It is analogous to biological
mutation. Mutation alters one or more gene values in a chromosome from its initial state.
Nemerical
The cost of engines plus fuel for a cargo ship (in lakhs of rupees per
year for 100 tons of cargo carried) varies with speed and is given by
0.2x2 where x is the speed of the ship in m/s. The fixed costs of hull
and crew (again in the same units) are given by 450 x . Using GA,
perform two iterations to determine the operating speed of the
ship. The original interval of uncertainty is
0.5≤x≤25.5.
One decimal accuracy is required for representing x.