Unit II Sub: Artificial Intelligence Prof Priya Singh
Unit II Sub: Artificial Intelligence Prof Priya Singh
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.
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).
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.
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.
2. Uniform-cost search
5. Bidirectional search
We start from
visiting S(starting node), and
mark it as visited.
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
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
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.
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:
Greedy best-first search expands the nodes that appears to be closest to the
goal.
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.
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.
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
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.
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.
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.
Offspring are created by exchanging the genes of parents among themselves until the crossover
point is reached.
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 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.
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.
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.