0% found this document useful (0 votes)
64 views

Unit II Sub: Artificial Intelligence Prof Priya Singh

1) Problem solving agents adopt goals to reach goal states by searching through possible actions and states. Four general steps are goal formulation, problem formulation, search, and execution. 2) In problem formulation, the agent defines the possible states, actions, transition model between states from actions, goal test, and path cost function. Well-defined problems have a clear initial state, actions, transition model, goal test, and path cost. 3) Route finding problems involve more complex state definitions that track location, time, and historical flight details. The agent must define applicable actions, transition models, goal tests, and path costs to solve route finding problems.

Uploaded by

Abcd
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
64 views

Unit II Sub: Artificial Intelligence Prof Priya Singh

1) Problem solving agents adopt goals to reach goal states by searching through possible actions and states. Four general steps are goal formulation, problem formulation, search, and execution. 2) In problem formulation, the agent defines the possible states, actions, transition model between states from actions, goal test, and path cost function. Well-defined problems have a clear initial state, actions, transition model, goal test, and path cost. 3) Route finding problems involve more complex state definitions that track location, time, and historical flight details. The agent must define applicable actions, transition models, goal tests, and path costs to solve route finding problems.

Uploaded by

Abcd
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 25

Unit II Sub: Artificial Intelligence Prof Priya Singh

Unit II: Chapter 1: SOLVING PROBLEMS BY SEARCHING

 PROBLEM-SOLVING AGENTS:
One kind of goal-based agent called a problem-solving agent. We will consider a goal to be a
set of world states—exactly those states in which the goal is satisfied. The agent’s task is to find
out how to act, now and in the future, so that it reaches a goal state. Before it can do this, it needs
to decide (or we need to decide on its behalf) what sorts of actions and states it should consider.
For example suppose an agent is helping the students to select a institute for higher
studies. Performance measure contains many factors: institutes current rank, course fees,
available courses etc. But suppose student only want to take admission in particular city say
Delhi, now it make sense that agent adopt the goal of city Delhi and show only those result. Now
agents decision problem is simplified, it can reject any institute which is not in Delhi without any
further consideration.
Four general steps in problem solving:
1) Goal formulation
 deciding on what the goal states are
 based on current situation and agent’s performance measure
 What are the successful world states
2) Problem formulation
 How can we get to the goal, without getting bogged down in the detail of the
world?
 Walking robot not concerned about moving one inch ahead, but, in general
concerned about moving ahead.
 What actions and states to consider given the goal
 State the problem in such a way that we can make efficient progress toward a goal
state.
3) Search
 Determine the possible sequence of actions that lead to the states of known
values and then choose the best sequence.
 Search algorithms – input is a problem, output is a solution (action sequence)
4) Execute
 Given the solution, perform the actions.

Example:
Romania Suppose you are on holidays in Romania, currently in Arad. Your flight leaves
tomorrow in Bucharest. You have no geographical knowledge about Romania.
Goal formulation: Be in Bucharest
Problem formulation: states (cities), operators (drive between cities)
Solution: Can be represented as a sequence of states (cities) Example: (Arad, Sibiu, Fagaras,
Bucharest)
Our agent has now adopted the goal of driving to Bucharest and is considering where
to go from Arad. Three roads lead out of Arad, one toward Sibiu, one to Timisoara, and one
to Zerind. None of these achieves the goal, so unless the agent is familiar with the geography
of Romania, it will not know which road to follow. In other words, the agent will not know
which of its possible actions is best, because it does not yet know enough about the state
that results from taking each action. If the agent has no additional information—i.e., if the
Unit II Sub: Artificial Intelligence Prof Priya Singh

environment is unknown, then it is has no choice but to try one of the actions at random.
But suppose the agent has a map of Romania. The point of a map is to provide the
agent with information about the states it might get itself into and the actions it can take.

Environment
 Known, so the agent knows which states are reached by each action.
 observable – initial state and current state is known
eg. For the agent driving in Romania, it’s reasonable to suppose that each city
on the map has a sign indicating its presence to arriving drivers.
 discrete – more than one solution possible
 Deterministic – so each action has exactly one outcome.

 Well-defined problems and solutions


A problem can be defined formally by five components:

1) Initial state : The initial state that the agent starts in. For example, the initial state for
our agent in Romania might be described as In (Arad).

function SIMPLE-PROBLEM-SOLVING-AGENT(percept ) returns an action


persistent: seq, an action sequence, initially empty
state, some description of the current world state
goal , a goal, initially null
problem, a problem formulation
state←UPDATE-STATE(state, percept )
if seq is empty then
goal ←FORMULATE-GOAL(state)
problem ←FORMULATE-PROBLEM(state, goal )
seq ←SEARCH(problem)
if seq = failure then return a null action
action ←FIRST(seq)
seq ←REST(seq)
return action

A simple problem-solving agent. It first formulates a goal and a problem,


searches for a sequence of actions that would solve the problem, and then executes the actions
one at a time. When this is complete, it formulates another goal and starts over.

2) Action: A description of the possible actions available to the agent. Given a particular
state s, ACTIONS(s) returns the set of actions that can be executed in s. We say that each
of these actions is applicable in s. For example, from the state In(Arad), the applicable
actions are {Go(Sibiu), Go(Timisoara), Go(Zerind)}.

3) Transition Model: A description of what each action does; the formal name for this is
the transition
model, specified by a function RESULT(s, a) that returns the state that results from
Unit II Sub: Artificial Intelligence Prof Priya Singh

doing action a in state s. We also use the term successor to refer to any state reachable
from a given state by a single action.2 For example, we have
RESULT(In(Arad),Go(Zerind)) = In(Zerind) .
The state space forms a directed network or graph in which the nodes
are states and the links between nodes are actions. A path in the state space is a sequence
of states connected by a sequence of actions.
4) Goal Test: The goal test, which determines whether a given state is a goal state.
Sometimes there
is an explicit set of possible goal states, and the test simply checks whether the given
state is one of them. The agent’s goal in Romania is the singleton set {In(Bucharest )}.
5) Path cost: A path PATH COST cost function that assigns a numeric cost to each path.
The problem-solving agent chooses a cost function that reflects its own performance
measure. For the agent trying to get to Bucharest, time is of the essence, so the cost of a
path might be its length in kilometers.

Example :

Vacuum world

1. Initial state:
o Our vacuum can be in any state of the 8 states shown in the picture.
2. State description:
o Successor function generates legal states resulting from applying the three actions {Left,
Right, and Suck}.
o The states space is shown in the picture, there are 8 world states.
3. Goal test:
o Checks whether all squares are clean.
4. Path cost:
o Each step costs 1, so the path cost is the sum of steps in the path.

8-puzzle

1. Initial state:
o Our board can be in any state resulting from making it in any configuration.
2. State description:
o Successor function generates legal states resulting from applying the three actions {move
blank Up, Down, Left, or Right}.
o State description specifies the location of each of the eight titles and the blank.
3. Goal test:
o Checks whether the states matches the goal configured in the goal state shown in the
picture.
4. Path cost:
o Each step costs 1, so the path cost is the sum of steps in the path.
Unit II Sub: Artificial Intelligence Prof Priya Singh

Real-world problems

 ROUTE-FINDING PROBLEM
Route-finding algorithms are used in a variety of applications. Some, such as Web sites and in-car
systems that provide driving directions, are relatively straightforward extensions of the Romania example.
Others, such as routing video streams in computer networks, military operations planning, and airline
travel-planning systems, involve much more complex specifications. Consider the airline travel problems
that must be solved by a travel-planning Web site:

1)States: Each state obviously includes a location (e.g., an airport) and the current time.
Furthermore, because the cost of an action (a flight segment) may depend on previous
segments, their fare bases, and their status as domestic or international, the state must
record extra information about these “historical” aspects.
2)Initial state: This is specified by the user’s query.
3)Actions: Take any flight from the current location, in any seat class, leaving after the
current time, leaving enough time for within-airport transfer if needed.
4)Transition model: The state resulting from taking a flight will have the flight’s destination
as the current location and the flight’s arrival time as the current time.
5)Goal test: Are we at the final destination specified by the user?
6)Path cost: This depends on monetary cost, waiting time, flight time, customs and immigration
procedures, seat quality, time of day, type of airplane, frequent-flyer mileage
awards, and so on.

SEARCHING FOR SOLUTIONS:


Terms:

Leaf node: a node with no children in the tree.


Frontier: The set of all leaf nodes available for expansion at any given point is called the frontier.

Infrastructure for search algorithms:


 n.STATE: the state in the state space to which the node corresponds;
 n.PARENT: the node in the search tree that generated this node;
 n.ACTION: the action that was applied to the parent to generate the node;
 n.PATH-COST: the cost, traditionally denoted by g(n), of the path from the initial state to the node,
as indicated by the parent pointers.

Measuring problem-solving performance

 Completeness: Is the algorithm guaranteed to find a solution when there is one?


 Optimality: Does the strategy find the optimal solution, as defined on page 68?
Unit II Sub: Artificial Intelligence Prof Priya Singh

 Time complexity: How long does it take to find a solution?


 Space complexity: How much memory is needed to perform the search?

Uninformed Search
Uninformed search (also called blind search). That means that the strategies have no additional
Information about states beyond that provided in the problem definition.

Search strategies that we will talk about are:


1. Breadth-first search

2. Uniform-cost search

3. Depth-first search and Depth-limited search

4. Iterative deepening depth-first search

5. Bidirectional search

Breadth-first search (BFS)


Description
A simple strategy in which the root is expanded first then all the root successors are expanded
next, then their successors.
We visit the search tree level by level that all nodes are expanded at a given depth before any
nodes at the next level are expanded.
Order in which nodes are expanded.
Performance Measure:
Completeness:
it is easy to see that breadth-first search is complete that it visit all levels given that d factor is
finite, so in some d it will find a solution.
Optimality:
breadth-first search is not optimal until all actions have the same cost.
Space complexity and Time complexity:
Consider a state space where each node as a branching factor b, the root of the tree generates b
nodes, each of which generates b nodes yielding b2 each of these generates b3 and so on.
In the worst case, suppose that our solution is at depth d, and we expand all nodes but the last
node at level d, then the total number of generated nodes is: b + b2 + b3 + b4 + bd+1 – b =
O(bd+1), which is the time complexity of BFS.
As all the nodes must retain in memory while we expand our search, then the space complexity is
like the time complexity plus the root node = O(bd+1).
Conclusion:
We see that space complexity is the biggest problem for BFS than its exponential execution time.
Example:
Unit II Sub: Artificial Intelligence Prof Priya Singh

step Traversal Description

Initialize the queue.

We start from
visiting S(starting node), and
mark it as visited.

We then see an unvisited


adjacent node from S. In this
example, we have three nodes
but alphabetically we
choose A, mark it as visited
and enqueue it.
Unit II Sub: Artificial Intelligence Prof Priya Singh

Next, the unvisited adjacent


node from S is B. We mark it
as visited and enqueue it.

Next, the unvisited adjacent


node from S is C. We mark it
as visited and enqueue it.

Now, S is left with no


unvisited adjacent nodes. So,
we dequeue and find A.

From A we have D as
unvisited adjacent node. We
mark it as visited and
enqueue it.
Unit II Sub: Artificial Intelligence Prof Priya Singh

Uniform-cost search (UCS)


Description:
Uniform-cost is guided by path cost rather than path length like in BFS, the algorithms starts by
expanding the root, then expanding the node with the lowest cost from the root, the search
continues in this manner for all nodes.
Hints about UCS implementation can be found here.
You should not be surprised that Dijkstra’s algorithm, which is perhaps better-known, can be
regarded as a variant of uniform-cost search, where there is no goal state and processing
continues until the shortest path to all nodes has been determined.
Performance Measure:
Completeness:
It is obvious that UCS is complete if the cost of each step exceeds some small positive integer,
this to prevent infinite loops.
Optimality:
UCS is always optimal in the sense that the node that it always expands is the node with the least
path cost.
Time Complexity:
UCS is guided by path cost rather than path length so it is hard to determine its complexity in
terms of b and d, so if we consider C to be the cost of the optimal solution, and every action costs
at least e, then the algorithm worst case is O(bC/e).
Space Complexity:
The space complexity is O(bC/e) as the time complexity of UCS.
Conclusion:
UCS can be used instead of BFS in case that path cost is not equal and is guaranteed to be greater
than a small positive value e.
Example:

Depth-first search (DFS)


Description:
Unit II Sub: Artificial Intelligence Prof Priya Singh

DFS progresses by expanding the first child node of the search tree that appears and thus going
deeper and deeper until a goal node is found, or until it hits a node that has no children. Then the
search backtracks, returning to the most recent node it hasn’t finished exploring.
Order in which nodes are expanded
Performance Measure:
Completeness:
DFS is not complete, to convince yourself consider that our search start expanding the left sub
tree of the root for so long path (may be infinite) when different choice near the root could lead
to a solution, now suppose that the left sub tree of the root has no solution, and it is unbounded,
then the search will continue going deep infinitely, in this case we say that DFS is not complete.
Optimality:
Consider the scenario that there is more than one goal node, and our search decided to first
expand the left sub tree of the root where there is a solution at a very deep level of this left sub
tree, in the same time the right sub tree of the root has a solution near the root, here comes the
non-optimality of DFS that it is not guaranteed that the first goal to find is the optimal one, so we
conclude that DFS is not optimal.
Time Complexity:
Consider a state space that is identical to that of BFS, with branching factor b, and we start the
search from the root.
In the worst case that goal will be in the shallowest level in the search tree resulting in generating
all tree nodes which are O(bm).
Space Complexity:
Unlike BFS, our DFS has a very modest memory requirements, it needs to story only the path
from the root to the leaf node, beside the siblings of each node on the path, remember that BFS
needs to store all the explored nodes in memory.
DFS removes a node from memory once all of its descendants have been expanded.
With branching factor b and maximum depth m, DFS requires storage of only bm + 1 nodes
which are O(bm) compared to the O(bd+1) of the BFS.
Conclusion:
DFS may suffer from non-termination when the length of a path in the search tree is infinite, so
we perform DFS to a limited depth which is called Depth-limited Search.
Example:
Step Traversal Description
Unit II Sub: Artificial Intelligence Prof Priya Singh

Initialize the stack.

Mark S as visited and put it


onto the stack. Explore any
unvisited adjacent node
from S. We have three nodes
and we can pick any of them.
For this example, we shall
take the node in an
alphabetical order.

Mark A as visited and put it


onto the stack. Explore any
unvisited adjacent node from
A. Both Sand D are adjacent
to A but we are concerned for
unvisited nodes only.
Unit II Sub: Artificial Intelligence Prof Priya Singh

Visit D and mark it as visited


and put onto the stack. Here,
we have B and C nodes,
which are adjacent to D and
both are unvisited. However,
we shall again choose in an
alphabetical order.

We choose B, mark it as
visited and put onto the stack.
Here Bdoes not have any
unvisited adjacent node. So,
we pop Bfrom the stack.

We check the stack top for


return to the previous node
and check if it has any
unvisited nodes. Here, we
find D to be on the top of the
stack.
Unit II Sub: Artificial Intelligence Prof Priya Singh

Only unvisited adjacent node


is from D is C now. So we
visit C, mark it as visited and
put it onto the stack.

Depth-limited search (DLS)


Description:
The unbounded tree problem appeared in DFS can be fixed by imposing a limit on the depth that
DFS can reach, this limit we will call depth limit l, this solves the infinite path problem.
Performance Measure:
Completeness:
The limited path introduces another problem which is the case when we choose l < d, in which is
our DLS will never reach a goal, in this case we can say that DLS is not complete.
Optimality:
One can view DFS as a special case of the depth DLS, that DFS is DLS with l = infinity.
DLS is not optimal even if l > d.
Time Complexity: O(bl)
Space Complexity: O(bl)
Conclusion:
DLS can be used when the there is a prior knowledge to the problem, which is always not the
case, Typically, we will not know the depth of the shallowest goal of a problem unless we solved
this problem before.
Iterative deepening depth-first search (IDS)
Description:
It is a search strategy resulting when you combine BFS and DFS, thus combining the advantages
of each strategy, taking the completeness and optimality of BFS and the modest memory
requirements of DFS.
IDS works by looking for the best search depth d, thus starting with depth limit 0 and make a
BFS and if the search failed it increase the depth limit by 1 and try a BFS again with depth 1 and
so on – first d = 0, then 1 then 2 and so on – until a depth d is reached where a goal is found.
Performance Measure:
Completeness:
IDS is like BFS, is complete when the branching factor b is finite.
Optimality:
IDS is also like BFS optimal when the steps are of the same cost.
Time Complexity:
Unit II Sub: Artificial Intelligence Prof Priya Singh

One may find that it is wasteful to generate nodes multiple times, but actually it is not that costly
compared to BFS, that is because most of the generated nodes are always in the deepest level
reached,
Space Complexity:
IDS is like DFS in its space complexity, taking O(bd) of memory.
Conclusion:
We can conclude that IDS is a hybrid search strategy between BFS and DFS inheriting their
advantages.
IDS is faster than BFS and DFS.
It is said that “IDS is the preferred uniformed search method when there is a large search space
and the depth of the solution is not known”.
Example:
Unit II Sub: Artificial Intelligence Prof Priya Singh

Bidirectional search
Description:
As the name suggests, bidirectional search suggests to run 2 simultaneous searches, one from the
initial state and the other from the goal state, those 2 searches stop when they meet each other at
some point in the middle of the graph.
The following pictures illustrates a bidirectional search:

Performance Measure:
Completeness:
Bidirectional search is complete when we use BFS in both searches, the search that starts from
Unit II Sub: Artificial Intelligence Prof Priya Singh

the initial state and the other from the goal state.
Optimality:
Like the completeness, bidirectional search is optimal when BFS is used and paths are of a
uniform cost – all steps of the same cost.
Other search strategies can be used like DFS, but this will sacrifice the optimality and
completeness, any other combination than BFS may lead to a sacrifice in optimality or
completeness or may be both of them.
Time and Space Complexity:
May be the most attractive thing in bidirectional search is its performance, because both searches
will run the same amount of time meeting in the middle of the graph.
Conclusion:
It is not that easy to formulate a problem such that each state can be reversed, that is going from
the head to the tail is like going from the tail to the head.
It should be efficient to compute the predecessor of any state so that we can run the search from
the goal.

Example:

advantages:

1. The merit of bidirectional search is its speed. Sum of the time taken by two
searches (forward and backward) is much less than the O(bd) complexity.
2. It requires less memory.

disadvantages:

1. Implementation of bidirectional search algorithm is difficult because additional


logic must be included to decide which search tree to extend at each step.
Unit II Sub: Artificial Intelligence Prof Priya Singh

2. One should have known the goal state in advance.


3. The algorithm must be too efficient to find the intersection of the two search
trees.
4. It is not always possible to search backward through possible states.

INFORMED (HEURISTIC) SEARCH STRATEGIES:


Strategies that know whether one non-goal state is “more promising” than another are called informed
search or heuristic search strategies.

1. Greedy best-first search:


The general approach we consider is called best-first search. Best-first search is an instance of
the general TREE-SEARCH or GRAPH-SEARCH algorithm in which a node is selected for
expansion based on an evaluation function, f(n). The evaluation function is construed as a cost
estimate, so the node with the lowest evaluation is expanded first.
This specific type of search is called greedy best-first search or pure heuristic search.
Efficient selection of the current best candidate for extension is typically implemented using a
priority queue. The A* search algorithm is an example of best-first search, as is B*.
Greedy best-first search tries to expand the node that is closest to the goal, on the
grounds that this is likely to lead to a solution quickly. Thus, it evaluates nodes by using just the
heuristic function; that is, f(n) = h(n).

Greedy best-first search expands the nodes that appears to be closest to the
goal.

2. A* search: Minimizing the total estimated solution cost

The most widely known form of best-first search is called A* search (pronounced “A-star ∗ SEARCH
Unit II Sub: Artificial Intelligence Prof Priya Singh

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)

Greedy search minimizes estimated cost to goal, and thereby (hopefully) reduces search cost, but
is neither optimal nor complete. Uniform-cost search minimizes path cost so far and is optimal
and complete, but is costly. So there is another solution is A* Search Algorithm.
A* Algorithm avoid expanding paths that are already expansive.

Example:
Unit II Sub: Artificial Intelligence Prof Priya Singh

Chapter 2
BEYOND CLASSICAL SEARCH

Local Search:
Local search (optimization) In computer science, local search is a heuristic method for solving
computationally hard optimization problems. Local search can be used on problems that can be
formulated as finding a solution maximizing a criterion among a number of candidate solutions.
local search in the state space, evaluating and modifying one or more current states rather than
systematically exploring paths from an initial state. These algorithms are suitable for problems in
which all that matters is the solution state, not the path cost to reach it.
Local search algorithms operate using a single current node (rather than multiple paths)
and generally move only to neighbors of that node. Typically, the paths followed by the search
are not retained. Although local search algorithms are not systematic, they have two key
advantages: (1) they use very little memory—usually a constant amount; and (2) they can often
find reasonable solutions in large or infinite (continuous) state spaces for which systematic
algorithms are unsuitable. In addition to finding goals, local search algorithms are useful for
solving pure optimization problems, in which the aim is to find the best state according to an
objective function.

Local search are as follows:


1. Hill-climbing search
2. Simulated annealing
3. Local Beam Search
4. Genetic algoritham

1. Hill-climbing search:
The hill-climbing search algorithm (steepest-ascent version). It is simply a loop that continually
moves in the direction of increasing value—that is, uphill. It terminates when it reaches a “peak”
where no neighbor has a higher value. The algorithm does not maintain a search tree, so the data
structure for the current node need only record he state and the value of the objective
function.Hill climbing is sometimes called greedy local search because it grabs a good neighbor
state without thinking ahead about where to go next.
Unit II Sub: Artificial Intelligence Prof Priya Singh

In this algorithm, we consider all possible states from the current state and thenpick the bestone
as successor, unlike in the simple hill climbing technique.In other words, in the case of hill
climbing technique we picked any state as a successor which was closer to the goal than the
current state whereas, in Steepest-Ascent Hill Climbing algorithm, we choose the best successor
among all possible successors and then update the current state.

Unfortunately, hill climbing often gets stuck for the following reasons (Limitations):

1. Local maxima: a local maximum is a peak that is higher than each of its neighboring
states but lower than the global maximum. Hill-climbing algorithms that reach the vicinity of a
local maximum will be drawn upward toward the peak but will then be stuck with nowhere else
to go. More
concretely, every move of a single queen makes the situation worse.

2. Ridges: Ridges result in a sequence of local maxima that is very difficult for greedy
algorithms to navigate.
3. Plateaux: a plateau is a flat area of the state-space landscape. It can be a flat
localmaximum, from which no uphill exit exists, or a shoulder, from which progress is
possible. A hill-climbing search might get lost on the plateau.

2. Simulated annealing:
Annealing is a process in metallurgy where metals are slowly cooled to make them reach a state
of low energy where they are very strong. Annealing involves heating and cooling a material to
alter its physical properties due to the changes in its internal structure. As the metal cools its new
structure becomes fixed, consequently causing the metal to retain its newly obtained properties.
In simulated annealing we keep a temperature variable to simulate this heating process. We
initially set it high and then allow it to slowly 'cool' as the algorithm runs. While this temperature
Unit II Sub: Artificial Intelligence Prof Priya Singh

variable is high the algorithm will be allowed, with more frequency, to accept solutions that are
worse than our current solution. This gives the algorithm the ability to jump out of any local
optimums it finds itself in early on in execution. As the temperature is reduced so is the chance
of accepting worse solutions, therefore allowing the algorithm to gradually focus in on a area of
the search space in which hopefully, a close to optimum solution can be found.

The basic algorithm

1. First, generate a random solution


2. Calculate its cost using some cost function you've defined
3. Generate a random neighboring solution
4. Calculate the new solution's cost
5. Compare them:
o If cnew < cold: move to the new solution
o If cnew > cold: maybe move to the new solution
6. Repeat steps 3-5 above until an acceptable solution is found or you reach some maximum
number of iterations.

Disadvantages:
 The method cannot tell whether it has found an optimal solution.
 Repeatedly annealing with a schedule is very slow, especially if the cost function is
expensive to compute.

Advantages
 It is relatively easy to code, even for complex problems
 It generally gives a ``good'' solution

3. Local Beam Search:


Beam search is a heuristic search algorithm that explores a graph by expanding the most
promising node in a limited set. Beam search is an optimization of best-first search that reduces
its memory requirements. The local beam search algorithm keeps track of k states rather than just
one. It begins with k randomly generated states. At each step, all the successors of all k states are
generated. If anyone is a goal, the algorithm halts. Otherwise, it selects the k best successors
from the complete list and repeats.
Unit II Sub: Artificial Intelligence Prof Priya Singh

4. Genetic algorithms

A genetic algorithm (or GA) is a variant of stochastic beam search in which successor states
are generated by combining two parent states rather than by modifying a single state.
Like beam searches, GAs begin with a set of k randomly generated states, called the
Population. Each state, or individual, is represented as a string over a finite alphabet—most
commonly, a string of 0s and 1s.

A genetic algorithm is a search heuristic that is inspired by Charles Darwin’s theory of natural
evolution. This algorithm reflects the process of natural selection where the fittest individuals are
selected for reproduction in order to produce offspring of the next generation.
Notion of Natural Selection
The process of natural selection starts with the selection of fittest individuals from a population.
They produce offspring which inherit the characteristics of the parents and will be added to the
next generation. If parents have better fitness, their offspring will be better than parents and have
a better chance at surviving. This process keeps on iterating and at the end, a generation with the
fittest individuals will be found.

This notion can be applied for a search problem. We consider a set of solutions for a problem and
select the set of best ones out of them.

Five phases are considered in a genetic algorithm.

1. Initial population

2. Fitness function
Unit II Sub: Artificial Intelligence Prof Priya Singh

3. Selection

4. Crossover

5. Mutation

Initial Population
The process begins with a set of individuals which is called a Population. Each individual is a
solution to the problem you want to solve.
An individual is characterized by a set of parameters (variables) known as Genes. Genes
are joined into a string to form a Chromosome (solution). In a genetic algorithm, the set of genes
of an individual is represented using a string, in terms of an alphabet. Usually, binary values are
used (string of 1s and 0s). We say that we encode the genes in a chromosome.

Population, Chromosomes and Genes

Fitness Function
The fitness function determines how fit an individual is (the ability of an individual to compete
with other individuals). It gives a fitness score to each individual. The probability that an
individual will be selected for reproduction is based on its fitness score.
Selection
The idea of selection phase is to select the fittest individuals and let them pass their genes to the
next generation.

Two pairs of individuals (parents) are selected based on their fitness scores. Individuals with high
fitness have more chance to be selected for reproduction.

Crossover
Crossover is the most significant phase in a genetic algorithm. For each pair of parents to be
mated, a crossover point is chosen at random from within the genes.

For example, consider the crossover point to be 3 as shown below.


Unit II Sub: Artificial Intelligence Prof Priya Singh

Offspring are created by exchanging the genes of parents among themselves until the crossover
point is reached.

Exchanging genes among parents


The new offspring are added to the population.

Mutation
In certain new offspring formed, some of their genes can be subjected to a mutation with a low
random probability. This implies that some of the bits in the bit string can be flipped.

Mutation: Before and After

Mutation occurs to maintain diversity within the population and prevent premature convergence.

Termination
Unit II Sub: Artificial Intelligence Prof Priya Singh

The algorithm terminates if the population has converged (does not produce offspring which are
significantly different from the previous generation). Then it is said that the genetic algorithm has
provided a set of solutions to our problem.

SEARCHING WITH NONDETERMINISTIC ACTIONS:


Each action has a set of possible outcomes (resulting states) A solution is not a sequence of
actions, but a contingency plan, or a strategy: if after pushing the lift button, lift arrives, then take
the lift; else take the stairs.

1)AND –OR Search tree:

In a deterministic environment, the only branching is introduced by the agent’s own choices
in each state. We call these nodes OR nodes. In the vacuum world, for example, at an OR
node the agent chooses Left or Right or Suck.
In a nondeterministic environment, branching is also introduced by the environment’s choice of
outcome for each action. We call these nodes AND nodes.

 Branching corresponds to the agent’s choice of actions Call these OR-nodes.


 Environment’s choice of outcome for each action: AND-nodes

And-or search: solution

A solution for an AND-OR search problem is a subtree that


(1) Has a goal node at every leaf
(2) Specifies one action at each of its OR nodes
(3) Includes every outcome branch at each of its AND nodes

Online Search agents and unknown environments:


So far we have concentrated on agents that use offline search algorithms. They compute a
complete solution before setting foot in the real world and then execute the solution. In contrast,
an online search agent interleaves computation and action: first it takes an action, then it
observes the environment and computes the next action. Online search is a good idea in dynamic
or semi dynamic domains—domains where there is a penalty for sitting around and computing
too long. Online search is also helpful in nondeterministic domains because it allows the agent to
focus its computational efforts on the contingencies that actually arise rather than those that
might happen but probably won’t. Of course, there is a tradeoff: the more an agent plans ahead,
the less often it will find itself up the creek without a paddle.

Online search is a necessary idea for unknown environments, where the agent does not know
what states exist or what its actions do. In this state of ignorance, the agent faces an exploration
Unit II Sub: Artificial Intelligence Prof Priya Singh

problem and must use its actions as experiments in order to learn enough to make deliberation
worthwhile.

• ACTIONS(s), which returns a list of actions allowed in state s;


• The step-cost function c(s, a, s )—note that this cannot be used until the agent knows
that s is the outcome; and
• GOAL-TEST(s).

You might also like