Está en la página 1de 58

UNIT-I

AI Foundations

i. Philosophy (428 B.C. – present)

Aristotle (384-322 B.C.) was the first to formulate a precise set of laws governing the rational part
of the mind. He developed an informal system of syllogisms for proper reasoning, which allowed
one to generate conclusions mechanically, given initial premises.

ii. Psychology (1879 – present)

The origin of scientific psychology are traced back to the wok if German physiologist Hermann von,
Helmholtz(1821-1894) and his student Wilhelm Wundt(1832 – 1920)
In 1879,Wundt opened the first laboratory of experimental psychology at the university of Leipzig.
In US, the development of computer modeling led to the creation of the field of cognitive science.
The field can be said to have started at the workshop in September 1956 at MIT.

iii.Computer engineering (1940-present)

For artificial intelligence to succeed, we need two things: intelligence and an artifact. The computer
has been the artifact of choice. AI also owes a debt to the software side of computer science, which
has supplied the operating systems, programming languages, and tools needed to write modern
programs.

iv.Control theory and Cybernetics (1948-present)

Ktesibios of Alexandria (c. 250 B.c.) built the first self-controlling machine: a water clock with a
regulator that kept the flow of water running through it at a constant, predictable pace.
Modern control theory, especially the branch known as stochastic optimal control, has as its goal
the design of systems that maximize an objective function over time.

V.Linguistics (1957-present)

Modem linguistics and AI, then, were "born" at about the same time, and grew up
together, intersecting in a hybrid field called computational linguistics or natural language
processing.

___________________________________________________________________
History of Artificial Intelligence

The gestation of artificial intelligence (1943-1955)


There were a number of early examples of work that can be characterized as AI, but it was Alan
Turing who first articulated a complete vision of AI in his 1950 article "Computing Machinery and
Intelligence." Therein, he introduced the Turing test, machine learning, genetic algorithms, and
reinforcement learning.

The birth of artificial intelligence (1956)


McCarthy convinced Minsky, Claude Shannon, and Nathaniel Rochester to help him bring together
U.S. researchers interested in automata theory, neural nets, and the study of intelligence. They
organized a two-month workshop Dartmouth in the summer of 1956.Perhaps the longest-lasting
thing to come out of the workshop was an agreement to adopt McCarthy's new name for the field:
artificial intelligence.

Early enthusiasm, great expectations (1952-1969)

The early years of AI were full of successes-in a limited way.


General Problem Solver (GPS) was a computer program created in 1957 by Herbert Simon and
Allen Newell to build a universal problem solver machine. The order in which the program
considered.

subgoals and possible actions was similar to that in which humans approached the same problems.
Thus, GPS was probably the first program to embody the "thinking humanly" approach.
At IBM, Nathaniel Rochester and his colleagues produced some of the first AI programs. Herbert
Gelernter (1959) constructed the Geometry Theorem Prover, which was able to prove theorems
that many students of mathematics would find quite tricky.

Lisp was invented by John McCarthy in 1958 while he was at the Massachusetts Institute of
Technology (MIT). In 1963, McCarthy started the AI lab at Stanford.

A dose of reality (1966-1973)

From the beginning, AI researchers were not shy about making predictions of their coming
successes. The following statement by Herbert Simon in 1957 is often quoted: “It is not my aim to
surprise or shock you-but the simplest way I can summarize is to say that there are now in the
world machines that think, that learn and that create. Moreover, their ability to do these things is
going to increase rapidly until-in a visible future-the range of problems they can handle will be
coextensive with the range to which the human mind has been applied.

Knowledge-based systems: The key to power (1969-1979)

Dendral was an influential pioneer project in artificial intelligence (AI) of the 1960s, and the
computer software expert system that it produced. Its primary aim was to help organic chemists in
identifying unknown organic molecules, by analyzing their mass spectra and using knowledge of
chemistry. It was done at Stanford University by Edward Feigenbaum, Bruce Buchanan, Joshua
Lederberg, and Carl Djerassi.

AI becomes an industry (1980-present)

In 1981, the Japanese announced the "Fifth Generation" project, a 10-year plan to build intelligent
computers running Prolog. Overall, the A1 industry boomed from a few million dollars in 1980 to
billions of dollars in 1988.

The return of neural networks (1986-present)

Psychologists including David Rumelhart and Geoff Hinton continued the study of neural-net
models of memory.

AI becomes a science (1987-present)


In recent years, approaches based on hidden Markov models (HMMs) have come to dominate the
area.
Speech technology and the related field of handwritten character recognition are already making
the transition to widespread industrial and consumer applications.
The Bayesian network formalism was invented to allow efficient representation of, and rigorous
reasoning with, uncertain knowledge.

The emergence of intelligent agents (1995-present)

One of the most important environments for intelligent agents is the Internet.

__________________________________________________________
Limits of AI Today

Today’s successful AI systems operate in well-defined domains and employ narrow, specialized
knowledge. Common sense knowledge is needed to function in complex, open-ended worlds. Such a
system also needs to understand unconstrained natural language. However these capabilities are
not yet fully present in today’s intelligent systems.

What can AI systems do


Today’s AI systems have been able to achieve limited success in some of these tasks.
• In Computer vision, the systems are capable of face recognition
• In Robotics, we have been able to make vehicles that are mostly autonomous.
• In Natural language processing, we have systems that are capable of simple machine translation.
• Today’s Expert systems can carry out medical diagnosis in a narrow domain
• Speech understanding systems are capable of recognizing several thousand words continuous
speech
• The Learning systems are capable of doing text categorization into about a 1000 topics
• In Games, AI systems can play at the Grand Master level in chess (world champion), checkers, etc.

What can AI systems NOT do yet?

• Understand natural language robustly (e.g., read and understand articles in a newspaper)
• Surf the web
• Interpret an arbitrary visual scene
• Learn a natural language
• Construct plans in dynamic real-time domains
• Exhibit true autonomy and intelligence
________________________________________________________________
Artificial Intelligence

Artificial Intelligence is the branch of computer science concerned with making computers behave
like humans.
Major AI textbooks define artificial intelligence as "the study and design of intelligent agents,"
where an intelligent agent is a system that perceives its environment and takes actions which
maximize its chances of success. John McCarthy, who coined the term in 1956, defines it as "the
science and engineering of making intelligent machines, especially intelligent computer programs."

The definitions of AI according to some text books are categorized into four approaches and are
summarized in the table below :
Systems that think like humans
“The exciting new effort to make computers think … machines with minds, in the full and literal
sense.”(Haugeland,1985)

Systems that think rationally


“The study of mental faculties through the use of computer models.” (Charniak and
McDermont,1985)

Systems that act like humans


The art of creating machines that perform functions that require intelligence when performed by
people.”(Kurzweil,1990)

Systems that act rationally


“Computational intelligence is the study of the design of intelligent agents.”(Poole et al.,1998)

The four approaches in more detail are as follows :

(a) Acting humanly : The Turing Test approach

- Test proposed by Alan Turing in 1950


-The computer is asked questions by a human interrogator.

The computer passes the test if a human interrogator, after posing some written questions, cannot
tell whether the written responses come from a person or not. Programming a computer to pass
,the computer need to possess the following capabilities :
Natural language processing to enable it to communicate successfully in English.
Knowledge representation to store what it knows or hears
Automated reasoning to use the stored information to answer questions and to draw new
conclusions.
Machine learning to adapt to new circumstances and to detect and extrapolate
Patterns.

To pass the complete Turing Test, the computer will need


Computer vision to perceive the objects, and
Robotics to manipulate objects and move about.

(b)Thinking humanly : The cognitive modeling approach

We need to get inside actual working of the human mind :


(a) through introspection – trying to capture our own thoughts as they go by;
(b) through psychological experiments
Allen Newell and Herbert Simon, who developed GPS, the “General Problem Solver” tried to trace
the reasoning steps to traces of human subjects solving the same problems.
The interdisciplinary field of cognitive science brings together computer models from AI and
experimental techniques from psychology to try to construct precise and testable theories of the
workings of the human mind.
(c) Thinking rationally : The “laws of thought approach”

The Greek philosopher Aristotle was one of the first to attempt to codify “right thinking”, that is
irrefuatable reasoning processes. His syllogism provided patterns for argument structures that
always yielded correct conclusions when given correct premises
for example,”Socrates is a man;all men are mortal; therefore Socrates is mortal.”.
These laws of thought were supposed to govern the operation of the mind; their study initiated a
field called logic.

(d) Acting rationally : The rational agent approach

An agent is something that acts. Computer agents are not mere programs ,but they are expected to
have the following attributes also :
(a) operating under autonomous control
(b) perceiving their environment
(c) persisting over a prolonged time period
(e) adapting to change
A rational agent is one that acts so as to achieve the best outcome.

INTELLIGENT AGENTS

1.2.1 Agents and environments


An agent is anything that can be viewed as perceiving its environment through sensors and acting
upon that environment through actuators. This simple idea is illustrated in Figure.

o A human agent has eyes, ears, and other organs for sensors and hands, legs, mouth, and other
body parts for actuators.
o A robotic agent might have cameras and infrared range finders for sensors and various motors
for actuators.
o A software agent receives keystrokes, file contents, and network packets as sensory inputs and
acts on the environment by displaying on the screen, writing files, and sending network packets.
Terms:

Percept
We use the term percept to refer to the agent's perceptual inputs at any given instant.

Percept Sequence
An agent's percept sequence is the complete history of everything the agent has ever perceived.

Agent function
Mathematically speaking, we say that an agent's behavior is described by the agent function that
maps any given percept sequence to an action.
F: P*->A
Agent program
Internally, The agent function for an artificial agent will be implemented by an agent program. It is
important to keep these two ideas distinct. The agent function is an abstract mathematical
description; the agent program is a concrete implementation, running on the agent architecture.

To illustrate these ideas, we will use a very simple example-the vacuum-cleaner world shown in
Figure 1.3. This particular world has just two locations: squares A and B. The vacuum agent
perceives which square it is in and whether there is dirt in the square. It can choose to move left,
move right, suck up the dirt, or do nothing. One very simple agent function is the following: if the
current square is dirty, then suck, otherwise move to the other square. A partial tabulation of this
agent function is shown in Figure 1.4.
__________________________________________________________________
AGENTS AND ENVIRONMENTS

Task environments
We must think about task environments, which are essentially the "problems" to which rational
agents are the "solutions."
Specifying the task environment
The rationality of the simple vacuum-cleaner agent, needs specification of
o the performance measure
o the environment
o the agent's actuators and sensors.
PEAS
-All these are grouped together under the heading of the task environment.
We call this the PEAS (Performance, Environment, Actuators, Sensors) description.
-In designing an agent, the first step must always be to specify the task environment as fully as
possible.
_________________________________________________________________
Nature of Environments

Properties of task environments


o Fully observable vs. partially observable
o Deterministic vs. stochastic
o Episodic vs. sequential
o Static vs. dynamic
o Discrete vs. continuous
o Single agent vs. multi-agent

Fully observable vs. partially observable.


In terms of observability, an environment can be characterized as fully observable or partially
observable.
In a fully observable environment all of the environment relevant to the action being considered is
observable. In such environments, the agent does not need to keep track of the changes in the
environment. A chess playing system is an example of a system that operates in a fully observable
environment.
In a partially observable environment, the relevant features of the environment are only partially
observable. A bridge playing program is an example of a system operating in a partially observable
environment.

Deterministic vs. stochastic.


In deterministic environments, the next state of the environment is completely described by the
current state and the agent’s action. Image analysis systems are examples of this kind of situation.
The processed image is determined completely by the current image and the processing operations.
If an element of interference or uncertainty occurs then the environment is stochastic. Note that a
deterministic yet partially observable environment will appear to be stochastic to the agent.
Examples of this are the automatic vehicles that navigate a terrain, say, the Mars rovers robot. The
new environment in which the vehicle is in is stochastic in nature.
If the environment state is wholly determined by the preceding state and the actions of multiple
agents, then the environment is said to be strategic. Example: Chess. There are two agents, the
players and the next state of the board is strategically determined by the players’ actions.

Episodic vs. sequential


In an episodic task environment, the agent's experience is divided into atomic episodes. Each
episode consists of the agent perceiving and then performing a single action. Crucially, the next
episode does not depend on the actions taken in previous episodes.
For example, an agent that has to spot defective parts on an assembly line bases each decision on
the current part, regardless of previous decisions;
In sequential environments, on the other hand, the current decision could affect all future
decisions. Chess and taxi driving are sequential.

Discrete vs. continuous.


The discrete/continuous distinction can be applied to the state of the environment, to the way time
is handled, and to the percepts and actions of the agent.
For example, a discrete-state environment such as a chess game has a finite number of distinct
states. Chess also has a discrete set of percepts and actions.
Taxi driving is a continuous state and continuous-time problem: the speed and location of the taxi
and of the other vehicles sweep through a range of continuous values and do so smoothly over time.
Taxi-driving actions are also continuous (steering angles, etc.).

Static Vs Dynamic
Static Environment: does not change from one state to the next while the agent is considering its
course of action. The only changes to the environment are those caused by the agent itself.
• A static environment does not change while the agent is thinking.
• The passage of time as an agent deliberates is irrelevant.
• The agent doesn’t need to observe the world during deliberation.

A Dynamic Environment changes over time independent of the actions of the agent -- and thus if an
agent does not respond in a timely manner, this counts as a choice to do nothing

Single agent vs. multi-agent


An agent solving a crossword puzzle by itself is clearly in a single-agent environment, whereas an
agent playing chess is in a two-agent environment.
As one might expect, the hardest case is partially observable, stochastic, sequential, dynamic,
continuous, and multi-agent.

Concept of Rationality

Rational Agent
A rational agent is one that does the right thing-conceptually speaking, every entry in the table for
the agent function is filled out correctly. Obviously, doing the right thing is better than doing the
wrong thing. The right action is the one that will cause the agent to be most successful.

Performance measures
A performance measure embodies the criterion for success of an agent's behavior. When an
agent is plunked down in an environment, it generates a sequence of actions according to the
percepts it receives. This sequence of actions causes the environment to go through a sequence of
states. If the sequence is desirable, then the agent has performed well.
Rationality
rational at any given time depends on four things:
o The performance measure that defines the criterion of success.
o The agent's prior knowledge of the environment.
o The actions that the agent can perform.
o The agent's percept sequence to date.

This leads to a definition of a rational agent:


For each possible percept sequence, a rational agent should select an action that is expected to
maximize its performance measure, given the evidence provided by the percept sequence and
whatever built-in knowledge the agent has.

Omniscience, learning, and autonomy


An omniscient agent knows the actual outcome of its actions and can act accordingly; but
omniscience is impossible in reality.
Doing actions in order to modify future percepts-sometimes called information gathering-is an
important part of rationality.
Our definition requires a rational agent not only to gather information, but also to learn as much as
possible from what it perceives.
To the extent that an agent relies on the prior knowledge of its designer rather than on its own
percepts, we say that the agent lacks autonomy. A rational agent should be autonomous-it should
learn what it can to compensate for partial or incorrect prior knowledge.
________________________________________________________________
Structure of Agents

Agent programs
The agent programs all have the same skeleton: they take the current percept as input from the
sensors and return an action to the actuators.
Notice the difference between the agent program, which takes the current percept as input, and
the agent function, which takes the entire percept history. The agent program takes just the
current percept as input because nothing more is available from the environment; if the agent's
actions depend on the entire percept sequence, the agent will have to remember the percepts.
Drawbacks:
• Table lookup of percept-action pairs defining all possible condition-action rules necessary to
interact in an environment
• Problems
– Too big to generate and to store (Chess has about 10^120 states, for example)
– No knowledge of non-perceptual parts of the current state
– Not adaptive to changes in the environment; requires entire table to be updated if changes occur
– Looping: Can't make actions conditional
• Take a long time to build the table
• No autonomy
• Even with learning, need a long time to learn the table entries

Some Agent Types

• Table-driven agents
– use a percept sequence/action table in memory to find the next action. They are
implemented by a (large) lookup table.

• Simple reflex agents


– are based on condition-action rules, implemented with an appropriate production system. They
are stateless devices which do not have memory of past world states.

• Agents with memory


– have internal state, which is used to keep track of past states of the world.

• Agents with goals


– are agents that, in addition to state information, have goal information that describes desirable
situations. Agents of this kind take future events into consideration.

• Utility-based agents
– base their decisions on classic axiomatic utility theory in order to act rationally.

Simple Reflex Agent

The simplest kind of agent is the simple reflex agent. These agents select actions on the basis of
the current percept, ignoring the rest of the percept history. For example, the vacuum agent whose
agent function is tabulated in Figure 1.10 is a simple reflex agent, because its decision is based only
on the current location and on whether that contains dirt.
o Select action on the basis of only the current percept.
E.g. the vacuum-agent
o Large reduction in possible percept/action situations.
o Implemented through condition-action rule Ex: If dirty then suck
Figure 1.11 The agent program for a simple reflex agent in the two-state vacuum environment.
This program implements the agent function tabulated in the figure 1.4.

Characteristics
o Only works if the environment is fully observable.
o Lacking history, easily get stuck in infinite loops
o One solution is to randomize actions
Model-based reflex agents
The most effective way to handle partial observability is for the agent to keep track of the part of the
world it can't see now. That is, the agent should maintain some sort of internal state that depends
on the percept history and thereby reflects at least some of the unobserved aspects of the current
state.
Updating this internal state information as time goes by requires two kinds of knowledge to be
encoded in the agent program.
First, we need some information about how the world evolves independently of the agent-for
example, that an overtaking car generally will be closer behind than it was a moment ago.
Second, we need some information about how the agent's own actions affect the world-for example,
that when the agent turns the steering wheel clockwise, the car turns to the right or that after
driving for five minutes north bound on the freeway one is usually about five miles north of where
one was five minutes ago.
This knowledge about "how the world working – whether implemented in simple Boolean
circuits or in complete scientific theories-is called a model of the world. An agent that uses such a
MODEL-BASED model is called a model-based agent.

function REFLEX-AGENT-WITH-STATE(percept) returns an action


static: rules, a set of condition-action rules
state, a description of the current world state
action, the most recent action.
state <- UPDATE-STATE(state, action, percept)
rule <-RULE-MATCH(state, rule)
action <-RULE-ACTION[rule]
return action
Fig: Model based reflex agent. It keeps track of the current state of the world using an internal
model. It then chooses an action in the same way as the reflex agent.
Goal-based agents

Knowing about the current state of the environment is not always enough to decide what to do. For
example, at a road junction, the taxi can turn left, turn right, or go straight on. The correct decision
depends on where the taxi is trying to get to. In other words, as well as a current state description,
the agent needs some sort of goal information that describes situations that are desirable-for
example, being at the passenger's destination. The agent program can combine this with
information about the results of possible actions (the same information as was used to update
internal state in the reflex agent) in order to choose actions that achieve the goal.
-Search and planning are two other sub-fields in AI to find out the action sequences to achieve its
goal

Utility Based Agents


Goals alone are not really enough to generate high-quality behavior in most environments.
For example, there are many action sequences that will get the taxi to its destination (thereby
achieving the goal) but some are quicker, safer, more reliable, or cheaper than others. Goals just
provide a crude binary distinction between "happy" and "unhappy" states, whereas a more general
performance measure should allow a comparison of different world states according to exactly
how happy they would make the agent if they could be achieved. Because "happy" does not sound
very scientific, the customary terminology is to say that if one world state is preferred to another,
then it has higher utility for the agent.
Certain goals can be reached in different ways.
– Some are better, have a higher utility.
• Utility function maps a (sequence of) state(s) onto a real number.
• Improves on goals:
– Selecting between conflicting goals (Ex: Speed and Safety)
– Select appropriately between several goals based on likelihood of success.
Learning Agents
• All agents can improve their performance through learning.
A learning agent can be divided into four conceptual components, as shown in Figure 1.15. The
most important distinction is between the learning element, which is responsible for making
improvements, and the performance element, which is responsible for selecting external actions.
The performance element is what we have previously considered to be the entire agent: it takes in
percepts and decides on actions. The learning element uses feedback from the critic on how the
agent is doing and determines how the performance element should be modified to do better in the
future.
The last component of the learning agent is the problem generator. It is responsible for suggesting
actions that will lead to new and informative experiences. But if the agent is willing to explore a
little, it might discover much better actions for the long run. The problem generator's job is to
suggest these exploratory actions. This is what scientists do when they carryout experiments.
UNIT-II
Problem Solving Agent
A Problem solving agent is a goal-based agent . It decide what to do by finding sequence of actions
that lead to desirable states. The agent can adopt a goal and aim at satisfying it.
To illustrate the agent’s behavior, let us take an example where our agent is in the city of Arad,
which is in Romania. The agent has to adopt a goal of getting to Bucharest.
Goal formulation, based on the current situation and the agent’s performance measure, is the first
step in problem solving. The agent’s task is to find out which sequence of actions will get to a goal
state.
Problem formulation is the process of deciding what actions and states to consider given a goal.
Search
Different possible sequences of actions that leads to the states of known value, and then choosing
the best sequence. The process of looking for sequences actions from the current state to reach the
goal state is called search.
The search algorithm takes a problem as input and returns a solution in the form of action
sequence. Once a solution is found, the execution phase consists of carrying out the
recommended action.

Well-defined problems and solutions


A problem can be formally defined by four components:
The initial state that the agent starts in . The initial state for our agent of example problem is
described by In(Arad)
A Successor Function returns the possible actions available to the agent. Given a state x,
SUCCESSOR-FN(x) returns a set of {action,successor} ordered pairs where each action is one of the
legal actions in state x,and each successor is a state that can be reached from x by applying the
action.
For example, from the state In(Arad),the successor function for the Romania problem would return
{ [Go(Sibiu),In(Sibiu)],[Go(Timisoara),In(Timisoara)],[Go(Zerind),In(Zerind)] }
State Space : The set of all states reachable from the initial state. The state space forms a graph in
which the nodes are states and the arcs between nodes are actions.
A path in the state space is a sequence of states connected by a sequence of actions.
The goal test determines whether the given state is a goal state.
A path cost function assigns numeric cost to each action. For the Romania problem the cost of path
might be its length in kilometers.
The step cost of taking action a to go from state x to state y is denoted by c(x,a,y). The step cost for
Romania are shown in figure 1.18. It is assumed that the step costs are non negative.
A solution to the problem is a path from the initial state to a goal state.
An optimal solution has the lowest path cost among all solutions.

EXAMPLE PROBLEMS
The problem solving approach has been applied to a vast array of task environments. Some best
known problems are summarized below. They are distinguished as toy or real-world problems
A toy problem is intended to illustrate various problem solving methods. It can be easily used by
different researchers to compare the performance of algorithms.
A real world problem is one whose solutions people actually care about.

Toy Problems
Vacuum World Example
o States: The agent is in one of two locations., each of which might or might not contain dirt.
Thus there are 2 x 22 = 8 possible world states.
o Initial state: Any state can be designated as initial state.
o Successor function : This generates the legal states that results from trying the three actions
(left, right, suck). The complete state space is shown in figure 2.3
o Goal Test : This tests whether all the squares are clean.
o Path test : Each step costs one ,so that the the path cost is the number of steps in the path.

Vacuum World State Space

8-Puzzle
An 8-puzzle consists of a 3x3 board with eight numbered tiles and a blank space. A tile adjacent to
the blank space can slide into the space. The object is to reach the goal state ,as shown in figure 2.4

The problem formulation is as follows :


o States : A state description specifies the location of each of the eight tiles and the blank in one of
the nine squares.
o Initial state : Any state can be designated as the initial state. It can be noted that any given goal
can be reached from exactly half of the possible initial states.
o Successor function : This generates the legal states that result from trying the four actions(blank
moves Left ,Right ,Up or down).
o Goal Test : This checks whether the state matches the goal configuration shown in figure
2.4.(Other goal configurations are possible)
o Path cost : Each step costs 1,so the path cost is the number of steps in the path.

The 8-puzzle belongs to the family of sliding-block puzzles, which are often used as test
problems for new search algorithms in AI. This general class is known as NP-complete.

The 8-puzzle has 9!/2 = 181,440 reachable states and is easily solved.
The 15 puzzle ( 4 x 4 board ) has around 1.3 trillion states, an the random instances can be solved
optimally in few milliseconds by the best search algorithms.
The 24-puzzle (on a 5 x 5 board) has around 1025 states ,and random instances are still quite
difficult to solve optimally with current machines and algorithms.

Partial State Space

8-queens problem

The problem is to place 8 queens on a chessboard so that no two queens are in the same row,
column or diagonal.
The picture below on the left shows a solution of the 8-queens problem. The picture on the right is
not a correct solution, because some of the queens are attacking each other.

State Space
N queens problem formulation 1
• States: Any arrangement of 0 to 8 queens on the board
• Initial state: 0 queens on the board
• Successor function: Add a queen in any square
• Goal test: 8 queens on the board, none are attacked

The initial state has 64 successors. Each of the states at the next level have 63 successors, and so on.
We can restrict the search tree somewhat by considering only those successors where no queen is
attacking each other. To do that we have to check the new queen against all existing queens on the
board. The solutions are found at a depth of 8.

State Space
N queens problem formulation 2
• States: Any arrangement of 8 queens on the board
• Initial state: All queens are at column 1
• Successor function: Change the position of any one queen
• Goal test: 8 queens on the board, none are attacked

State Space

N queens problem formulation 3


• States: Any arrangement of k queens in the first k rows such that none are attacked
• Initial state: k queens on the board
• Successor function: Add a queen to the (k+1)th row so that none are attacked.
• Goal test : 8 queens on the board, none are attacked

State Space
__________________________________________________________________

Real-World Problems

Route-Finding Problems
Route-finding problem is defined in terms of specified locations and transitions along links between
them. Route-finding algorithms are used in a variety of applications, such as routing in computer
networks, military operations planning, and air line travel planning systems.
AIRLINE TRAVEL PROBLEM
The airline travel problem is specifies as follows :
o States : Each is represented by a location(e.g.,an airport) and the current time.
o Initial state : This is specified by the problem.
o Successor function : This returns the states resulting from taking any scheduled
flight(further specified by seat class and location),leaving later than the current time plus the
within-airport transit time, from the current airport to another.
o Goal Test : Are we at the destination by some pre-specified time?
o Path cost : This depends upon the monetary cost, waiting time, flight time ,customs and
immigration procedures, seat quality, time of date, type of air plane, frequent-flyer mileage awards,
and so on.

Touring problems are closely related to route-finding problems, but with an important difference.
Consider for example,the problem,”Visit every city at least once” as shown in Romania map.
As with route-finding the actions correspond to trips between adjacent cities. The state
space,however,is quite different.
The initial state would be “In Bucharest; visited{Bucharest}”.
A typical intermediate state would be“InVaslui;visited{Bucharest,Urziceni,Vaslui}”.
The goal test would check whether the agent is in Bucharest and all 20 cities have been visited.

THE TRAVELLING SALESPERSON PROBLEM(TSP)


Is a touring problem in which each city must be visited exactly once. The aim is to find the shortest
tour. problem is known to be NP-hard. Enormous efforts have been expended to improve the
capabilities of TSP algorithms. These algorithms are also used in tasks such as planning movements
of automatic circuit-board drills and of stocking machines on shop floors.

VLSI layout
A VLSI layout problem requires positioning millions of components and connections on a chip to
minimize area ,minimize circuit delays ,minimize stray capacitances ,and maximize manufacturing
yield. The layout problem is split into two parts : cell layout and channel routing.

ROBOT navigation
ROBOT navigation is a generalization of the route-finding problem. Rather than a discrete set of
routes, a robot can move in a continuous space with an infinite set of possible actions and states.
For a circular Robot moving on a flat surface, the space is essentially two-dimensional. When the
robot has arms and legs or wheels that also must be controlled, the search space becomes multi-
dimensional. Advanced techniques are required to make the search space finite.

AUTOMATIC ASSEMBLY SEQUENCING


The example includes assembly of intricate objects such as electric motors. The aim in assembly
problems is to find the order in which to assemble the parts of some objects. If the wrong order is
choosen,there will be no way to add some part later without undoing somework already done.
Another important assembly problem is protein design,in which the goal is to find a sequence of
Amino acids that will be fold into a three-dimensional protein with the right properties to cure
some disease.
INTERNET SEARCHING
In recent years there has been increased demand for software robots that perform Internet
searching., looking for answers to questions for related information or for shopping deals. The
searching techniques consider internet as a graph of nodes(pages) connected by links.
__________________________________________________________________

Searching for Solutions

SEARCH TREE Having formulated some problems, we now need to solve them. This is done by a
search through the state space. A search tree is generated by the initial state and the successor
function that together define the state space. In general, we may have a search graph rather than a
search tree, when the same state can be reached from multiple paths.

Searching through a state space involves the following:


• A set of states
• Operators and their costs
• Start state
• A test to check for goal state

The basic search Algorithm

We need to denote the states that have been generated. We will call these as nodes. The data
structure for a node will keep track of not only the state, but also the parent state or the operator
that was applied to get this state. In addition the search algorithm maintains a list of nodes called
the fringe. The fringe keeps track of the nodes that have been generated but are yet to be explored.
The fringe represents the frontier of the search tree generated. The basic search algorithm has been
described above.
Initially, the fringe contains a single node corresponding to the start state. In this version we use
only the OPEN list or fringe. The algorithm always picks the first node from fringe for expansion. If
the node contains a goal state, the path to the goal is returned. The path corresponding to a goal
node can be found by following the parent pointers. Otherwise all the successor nodes are
generated and they are added to the fringe.
The successors of the current expanded node are put in fringe. We will soon see that the order in
which the successors are put in fringe will determine the property of the search algorithm.

Evaluating Search Strategies


1. Completeness: Is the strategy guaranteed to find a solution if one exists?

2. Optimality: Does the solution have low cost or the minimal cost?

3. What is the search cost associated with the time and memory required to find a solution?
a. Time complexity: Time taken (number of nodes expanded) (worst or average
case) to find a solution.
b. Space complexity: Space used by the algorithm measured in terms of the
maximum size of fringe

-The different search strategies that we will consider include the following:
1. Blind Search strategies or Uninformed search
a. Depth first search
b. Breadth first search
c. Iterative deepening search
d. Iterative broadening/deepening search
2. Informed Search
3. Constraint Satisfaction Search
4. Adversary Search

Search tree
Consider the explicit state space graph shown in the figure.
One may list all possible paths, eliminating cycles from the paths, and we would get the complete
search tree from a state space graph. Let us examine certain terminology associated with a search
tree. A search tree is a data structure containing a root node, from where the search starts. Every
node may have 0 or more children. If a node X is a child of node Y, node Y is said to be a parent of
node X.

Search Tree – Terminology


• Root Node: The node from which the search starts.
• Leaf Node: A node in the search tree having no children.
• Ancestor/Descendant: X is an ancestor of Y is either X is Y’s parent or X is an ancestor of the
parent of Y. If S is an ancestor of Y, Y is said to be a descendant of X.
• Branching factor: the maximum number of children of a non-leaf node in the search tree
• Path: A path in the search tree is a complete path if it begins with the start node and ends with
a goal node. Otherwise it is a partial path.

Node data structure


A node used in the search algorithm is a data structure which contains the following:
1. A state description
2. A pointer to the parent of the node
3. Depth of the node
4. The operator that generated this node
5. Cost of this path (sum of operator costs) from the start state

The nodes that the algorithm has generated are kept in a data structure called OPEN or fringe.
Initially only the start node is in OPEN. The search starts with the root node. The algorithm picks a
node from OPEN for expanding and generates all the children of the node. Expanding a node from
OPEN results in a closed node. Some search algorithms keep track of the closed nodes in a data
structure called CLOSED.

A solution to the search problem is a sequence of operators that is associated with a path from a
start node to a goal node. The cost of a solution is the sum of the arc costs on the solution path. For
large state spaces, it is not practical to represent the whole space. State space search makes explicit
a sufficient portion of an implicit state space graph to find a goal node. Each node represents a
partial solution path from the start node to the given node. In general, from this node there are
many possible paths that have this partial path as a prefix.
The search process constructs a search tree, where
• root is the initial state and
• leaf nodes are nodes
• not yet expanded (i.e., in fringe) or
• having no successors (i.e., “dead-ends”)
Search tree may be infinite because of loops even if state space is small
The search problem will return as a solution a path to a goal node. Finding a path is important in
problems like path finding, solving 15-puzzle, and such other problems. There are also problems
like the N-queens problem for which the path to the solution is not important. For such problems
the search problem needs to return the goal state only.

Breadth First Search


Note that in breadth first search the newly generated nodes are put at the back of fringe or the
OPEN list. What this implies is that the nodes will be expanded in a FIFO (First In First Out) order.
The node that enters OPEN earlier will be expanded earlier. This amounts to expanding the
shallowest nodes first.
We will now consider the search space in Figure 1, and show how breadth first search works on this
graph.
Step 1: Initially fringe contains only one node corresponding to the source state A.

Step 2: A is removed from fringe. The node is expanded, and its children B and C are generated.
They are placed at the back of fringe.
Step 3: Node B is removed from fringe and is expanded. Its children D, E are generated and put at
the back of fringe.

Step 4: Node C is removed from fringe and is expanded. Its children D,G are added to the back end
of fringe.

Step 5: Node D is removed from fringe. Its children C and F are generated and added to the back of
fringe.
Step 6: Node E is removed from fringe. It has no children.

Step 7: D is expanded, B and F are put in OPEN.

Step 8: G is selected for expansion. It is found to be a goal node. So the algorithm returns the path A
C G by following the parent pointers of the node corresponding to G. The algorithm terminates.

Properties of Breadth-First Search


We will now explore certain properties of breadth first search. Let us consider a model of the
search tree as shown in Figure 3. We assume that every non-leaf node has b children. Suppose that
d is the depth o the shallowest goal node, and m is the depth of the node found first.
• Complete.
• The algorithm is optimal (i.e., admissible) if all operators have the same cost. Otherwise, breadth
first search finds a solution with the shortest path length.
• The algorithm has exponential time and space complexity. Suppose the search tree can be
modeled as a binary tree as shown in Figure 3. Then the time and space complexity of the
algorithm is O(bd) where d is the depth of the solution and b is the branching factor (i.e.,
number of children) at each node.

Assume every state has b successors. The root of the search tree generates b nodes at the first
level,each of which generates b more nodes,for a total of b2 at the second level. Each of these
generates b more nodes,yielding b3 nodes at the third level,and so on. Now suppose,that the
solution is at depth d. In the worst case,we would expand all but the last node at level d,generating
bd+1 - b nodes at level d+1.A complete search tree of depth d where each non-leaf node has b
children, has a total of 1 + b + b2 + ... + bd = (b(d+1) - 1)/(b-1) nodes

Advantages of Breadth First Search


Finds the path of minimal length to the goal.
Disadvantages of Breadth First Search
Requires the generation and storage of a tree whose size is exponential the depth of the shallowest
goal node
_______________________________________________________________
Uniform-cost search Algorithm

Uniform Cost Search is the best algorithm for a search problem, which does not involve the use of
heuristics. It can solve any general graph for optimal cost. Uniform Cost Search as it sounds
searches in branches which are more or less the same in cost.

Uniform Cost Search again demands the use of a priority queue. Recall that Depth First Search used
a priority queue with the depth upto a particular node being the priority and the path from the root
to the node being the element stored. The priority queue used here is similar with the priority being
the cumulative cost upto the node. Unlike Depth First Search where the maximum depth had the
maximum priority, Uniform Cost Search gives the minimum cumulative cost the maximum priority
Now let us apply the algorithm on the above search tree and see what it gives us. We will go
through each iteration and look at the final output. Each element of the priority queue is written as
[path,cumulative cost].4

Ex : 2
Depth First Search

The depth first search algorithm puts newly generated nodes in the front of OPEN. This results in
expanding the deepest node first. Thus the nodes in OPEN follow a LIFO order (Last In First Out).
OPEN is thus implemented using a stack data structure.
Properties of Depth First Search
Let us now examine some properties of the DFS algorithm. The algorithm takes exponential time. If
N is the maximum depth of a node in the search space, in the worst case the algorithm will take time
O(bd). However the space taken is linear in the depth of the search tree, O(bN).
Note that the time taken by the algorithm is related to the maximum depth of the search tree. If the
search tree has infinite depth, the algorithm may not terminate. This can happen if the search space
is infinite. It can also happen if the search space contains cycles. The latter case can be handled by
checking for cycles in the algorithm. Thus Depth First Search is not complete.
________________________________________________________________
Depth Limited Search

A variation of Depth First Search circumvents the above problem by keeping a depth bound. Nodes
are only expanded if they have depth less than the bound. This algorithm is known as depth-limited
search.The depth limit solves the infinite path problem.Depth limited search will be nonoptimal if
we choose l > d. Its time complexity is O(bl) and its space complexity is O(bl). Depth-first-search can
be viewed as a special case of depth-limited search with l = infinite

___________________________________________________________________
Iterative Deepening Search
Iterative deepening search (or iterative-deepening-depth-first-search) is a general strategy often
used in combination with depth-first-search,that finds the better depth limit. It does this by
gradually increasing the limit – first 0,then 1,then 2, and so on – until a goal is found. This will occur
when the depth limit reaches d,the depth of the shallowest goal node. The algorithm is shown in
Figure 2.14.
Iterative deepening combines the benefits of depth-first and breadth-first-search
Like depth-first-search, its memory requirements are modest; O(bd) to be precise.
Like Breadth-first-search, it is complete when the branching factor is finite and optimal when the
path cost is a non decreasing function of the depth of the node.

Procedure
Successive depth-first searches are conducted – each with depth bounds increasing by 1

__________________________________________________________________
Bi-directional search
Suppose that the search problem is such that the arcs are bidirectional. That is, if there is an
operator that maps from state A to state B, there is another operator that maps from state B to state
A. Many search problems have reversible arcs. 8-puzzle, 15-puzzle, path planning etc are examples
of search problems. However there are other state space search formulations which do not have
this property. The water jug problem is a problem that does not have this property. But if the arcs
are reversible, you can see that instead of starting from the start state and searching for the goal,
one may start from a goal state and try reaching the start state. If there is a single state that satisfies
the goal property, the search problems are identical.
How do we search backwards from goal? One should be able to generate predecessor states.
Predecessors of node n are all the nodes that have n as successor. This is the motivation to consider
bidirectional search.
Algorithm: Bidirectional search involves alternate searching from the start state toward the goal
and from the goal state toward the start. The algorithm stops when the frontiers intersect.

A search algorithm has to be selected for each half. How does the algorithm know when the
frontiers of the search tree intersect? For bidirectional search to work well, there must be an
efficient way to check whether a given node belongs to the other search tree.
Bidirectional search can sometimes lead to finding a solution more quickly. The reason can be seen
from inspecting the following figure.

Time and Space Complexities


Consider a search space with branching factor b. Suppose that the goal is d steps away from the
start state. Breadth first search will expand O(bd) nodes.
If we carry out bidirectional search, the frontiers may meet when both the forward and the
backward search trees have depth = d/2. Suppose we have a good hash function to check for nodes
in the fringe. IN this case the time for bidirectional search will be O((bd/2). Also note that for at
least one of the searches the frontier has to be stored. So the space complexity is also O((bd/2).

Comparing Search Strategies

Informed Search

Uninformed search methods that systematically explore the state space and find the goal. They are
inefficient in most cases. Informed search methods use problem specific knowledge, and may be
more efficient. At the heart of such algorithms there is the concept of a heuristic function.

Best First Search


Uniform Cost Search is a special case of the best first search algorithm. The algorithm maintains a
priority queue of nodes to be explored. A cost function f(n) is applied to each node. The nodes are
put in OPEN in the order of their f values. Nodes with smaller f(n) values are expanded earlier. The
generic best first search algorithm is outlined below.
Greedy Search
In greedy search, the idea is to expand the node with the smallest estimated cost to reach the goal.
We use a heuristic function
f(n) = h(n)
h(n) estimates the distance remaining to a goal.
Greedy algorithms often perform very well. They tend to find good solutions quickly, although not
always optimal ones.

The resulting algorithm is not optimal. The algorithm is also incomplete, and it may fail to find a
solution even if one exists. This can be seen by running greedy search on the following example. A
good heuristic for the route-finding problem would be straight-line distance to the goal.

Let us run the greedy search algorithm for the graph given in Figure 2. The straight line distance
heuristic estimates for the nodes are shown in Figure 1.

Step 1: S is expanded. Its children are A and D.


Step 2: D has smaller cost and is expanded next.
__________________________________________________________________

A* Algorithm
Ex : 2

A* search: properties
The algorithm A* is admissible. This means that provided a solution exists, the first solution found
by A* is an optimal solution. A* is admissible under the following conditions:
• In the state space graph
o Every node has a finite number of successors
o Every arc in the graph has a cost greater than some ε> 0
• Heuristic function: for every node n, h(n) ≤ h*(n)

A* is also complete under the above conditions.

A* is optimally efficient for a given heuristic – of the optimal search algorithms that expand search
paths from the root node, it can be shown that no other optimal algorithm will expand fewer nodes
and find a solution.

However, the number of nodes searched still exponential in the worst case.

Unfortunately, estimates are usually not good enough for A* to avoid having to expand an
exponential number of nodes to find the optimal solution. In addition, A* must keep all nodes it is
considering in memory.

A* is still much more efficient than uninformed methods. It is always better to use a heuristic
function with higher values as long as it does not overestimate.

A heuristic is consistent if:

h(n) <= cost(n, n') + h(n')

For example, the heuristic shown below is inconsistent, because h(n) = 4, but
cost(n, n') + h(n') = 1 + 2 = 3, which is less than 4. This makes the value of f decrease from node n to
node n':

If a heuristic h is consistent, the f values along any path will be non decreasing:
f(n') = estimated distance from start to goal through n'
= actual distance from start to n + step cost from n to n' + estimated distance from n' to goal
= g(n) + cost(n, n') + h(n')
> g(n) + h(n) because cost(n, n') + h(n') > h(n) by consistency
= f(n)
Therefore f(n') > f(n), so f never decreases along a path.
__________________________________________________________________

AO * (AND-OR) ALGORITHM
 In OR graph, several arcs indicate a variety of ways in which the original problem may be
solved.
• Another kind of structure AND-OR graph (tree) is useful for representing the solution of
problems by decomposing them into smaller problems, all of which must then be solved.
• This decomposition generates arcs that we will cal l AND arc. One AND arc may point to any
number of successors, all of which must be solved.
• The proposed structure is called AND–OR graph rather than simply AND graph.

Ex1: Matrix multiplication

Consider the matrix multiplication of A1,A2 and A3.The problem can be solved as A1(A2A3) and
(A1A2)A3 which is a OR a node because problem can be solved in any way that is a it represents a
choice of nodes. A1(A2A3) can be decomposed into A1 and A2A3.To solve the A1(A2A3) both the
nods A1 and A2A3 has to solve which represents AND node.AND node are represented in the
diagram like Angle. Again (A1A2)A3 decomposed into A1A2 and A3 and it is also a AND node.
The size of A1 is size of 3x4 and its cost is 0 and A2A3 is Size of 4x1(4x10 and
10x1=4x1) ,the cost to solve A2A3 is 40 so the cost to solve
A1( A2A3)is cost of A1+A2A3= 12+40=52 where the right side problem (A1A2)A3 takes cost of
A1A2+A3=30+120=150.So the best way to solve the problem as A1(A2A3) which is minimum cost.

Reason that reducing problems to sub-goals in this way is of such great interest in Artificial
Intelligence research is that this is the way in which humans often go about solving problems.
One area in which goal trees are often used is computer security. A threat tree represents the
possible threats to a computer system, such as a computerized
banking system. If the goal is “steal Edwin’s money from the bank,” you can (guess or convince me
to divulge my PIN) and (steal or copy my card) and so on. The threat tree thus represents the
possible paths an attacker of the system might take and enables security experts to determine the
weaknesses in the system.

Example 2: Parsing Sentences


A parser is a tool that can be used to analyze the structure of a sentence in the English language (or
any other human language). Sentences can be broken down into phrases, and phrases can be
broken down into nouns, verbs, adjectives, and so on. Clearly, this is ideally suited to being
represented by goal trees.

Example 3: Games
Goal trees that are used to represent the choices made by players when playing
two-player games, such as chess, checkers, and Go. The root node of a game tree represents the
current position, and this is an or-node because I must choose one move to make. The next level
down in the game tree represents the possible choices my opponent might make, and because I
need to consider all possible responses that I might make to that move, this level consists of and-
nodes. Eventually, the leaf nodes represent final positions in the game, and a path through the tree
represents a sequence of moves from start to finish, resulting in a win, loss, or a draw.

Example 4: Theorem Proving


Goal trees can be used to represent theorems that are to be proved. The root goal is the theorem
that is to be proved. It is an or-node because there may be several ways to prove the theorem. The
next level down consists of and-nodes, which are lemmas that are to be proven. Each of these
lemmas again may have several ways to be proved so, therefore, is an or-node. The leaf-nodes of the
tree represent axioms that do not need to be proved.
______________________________________________________________
Heuristics
Heuristic means “rule of thumb”. To quote Judea Pearl, “Heuristics are criteria, methods or
principles for deciding which among several alternative courses of action promises to be the most
effective in order to achieve some goal”. In heuristic search or informed search, heuristics are used
to identify the most promising search path.

Example of Heuristic Function


A heuristic function at a node n is an estimate of the optimum cost from the current node to a goal.
It is denoted by h(n).
h(n) = estimated cost of the cheapest path from node n to a goal node
Example 1: We want a path from Kolkata to Guwahati
Heuristic for Guwahati may be straight-line distance between Kolkata and Guwahati
h(Kolkata) = euclideanDistance(Kolkata, Guwahati)
Example 2: 8-puzzle: Misplaced Tiles Heuristics is the number of tiles out of place.

The first picture shows the current state n, and the second picture the goal state.
H1(n) = 5 because the tiles 2, 8, 1, 6 and 7 are out of place.
Manhattan Distance Heuristic: Another heuristic for 8-puzzle is the Manhattan distance heuristic.
This heuristic sums the distance that the tiles are out of place. The distance of a tile is measured by
the sum of the differences in the x-positions and the y-positions.
For the above example, using the Manhattan distance heuristic,
H2(n) = 1 + 1 + 0 + 0 + 0 + 1 + 1 + 2 = 6

The effect of heuristic accuracy on performance

One way to characterize the quality of a heuristic is the effective branching factor b*. If the total
number of nodes expanded by A* for a particular problem is N, and the solution depth is ;d, then b*
is the branching factor that a uniform tree of depth d would have to have in order to ~>contain N
nodes. Thus,

N= 1+b* +(b*)2 + --- + (b*)d.


For example, if A* finds a solution at depth 5 using 52 nodes, then the effective branching factor is
1.91. Usually, the effective branching factor exhibited by a given heuristic is fairly constant over !A
well-designed heuristic would have a value of b* close to 1,

h2(n) > h1(n). We say that h2 dominates h1.


Domination translates directly into efficiency: A* using h2 will expand fewer nodes, on average,
than A* using h1. We can show this using the following simple argument. every node with h(n) <=
C* — g(n) will be expanded. But because h2 is at least as big as h1 for all nodes,
Eevery node that is expanded by A* search with h2 will also be expanded with h1 because
other nodes to be expanded as well. Hence, it is always better to use a heuristic function 1 with higher
values, as long as it does not overestimate.

Inventing heuristic functions:

The Heuristics can be invented by the relaxed problems .A problem with less restrictions on the
operators is called a relaxed problem.

If a problem definition is written down in a formal language, it is possible to construct relaxed


problems automatically.3 For example, if the 8-puzzle operators are described as
A tile can move from square A to square B if A is adjacent to B and B is blank,
we can generate three relaxed problems by removing one or more of the conditions:
(a) A tile can move from square A to square B if A is adjacent to B.
(b) A tile can move from square A to square B if B.
(c) A tile can move from square A to square B.

One problem with generating new heuristic functions is that one often fails to get one"clearly best"
heuristic. If a collection of admissible heuristics h1...hm is available for a problem, and none of them
dominates any of the others, We can have the best of all worlds, by defining
h(n) = max(h1(n),...,hm(n)).,

__________________________________________________________________________

Local Search- Hill Climbing


Hill climbing is an optimization technique for solving computationally hard problems. It is best
used in problems with “the property that the state description itself contains all the information
needed for a solution”. The algorithm is memory efficient since it does not maintain a search tree: It
looks only at the current state and immediate future states.
Hill climbing attempts to iteratively improve the current state by means of an evaluation
function. “Consider all the [possible] states laid out on the surface of a landscape. The height of any
point on the landscape corresponds to the evaluation function of the state at that point”
Hill climbing can be used to solve problems that have many solutions, some of which are better
than others. It starts with a random (potentially poor) solution, and iteratively makes small changes
to the solution, each time improving it a little. When the algorithm cannot see any improvement
anymore, it terminates. Ideally, at that point the current solution is close to optimal, but it is not
guaranteed that hill climbing will ever come close to the optimal solution.
Ex: Block World Problem
 Block world problem assumptions
 Square blocks of same size
 Blocks can be stacked one upon another.
 Flat surface (table) on which blocks can be placed.
 Robot arm that can manipulate the blocks. It can hold only one block at a time

Heuristic Function
For each block that has the correct support structure: +1 to every block in the support structure.
For each block that has a wrong support structure: −1 to every block in the support structure.
Iterative Improvement and Hill Climbing
Hill climbing get stuck for the following reasons
Local maxima
Once the top of a hill is reached the algorithm will halt since every possible step leads down.

Plateaux:
If the landscape is flat, meaning many states have the same goodness, algorithm degenerates to a
random walk.
Ridges
If the landscape contains ridges, local improvements may follow a zigzag path up the ridge, slowing
down the search.
Remedies:
– Random restart: keep restarting the search from random locations until a goal is found i.e. It
conducts a series of series of local searches from randomly generate the initial states, stopping
when a goal is found.
– Problem reformulation: reformulate the search space to eliminate these problematic features.

The success of hill climbing depends very much on a shape of state space land- scape: if there are
few local maxima and plateaux, random restart hill climbing will find a good solution very quickly.

ADVERSERIAL SEARCH: (GAMES)

Game is search problem where action of one agent effects the action of other agent. Game involves
multi-agent environment.
Types of Games

1. Zero-sum and Non-zero sum games


2. Perfect and imperfect games
3. Discrete and Continuous games
4. Single and Multi player Games
5. Cooperative and Non-cooperative games

Optimal Decisions in games


Game playing as Search
Initial State: Initial state is the initial move.
Successor Function : Defines the set of legal moves from any positions.
Terminal state: Determines when the game is over.
Utility Function/Objective function/payoff function : Which gives the numeric
values for the terminal state. In chess , the outcome is a win, loss or draw with the
values +1, -1 or 0.
Partial State space for TIC-TAC-TOE game

MIN-MAX Algorithm
The min-max algorithm is designed to determine the optimal strategy for MAX, and thus to decide
what the best first move is. The algorithm consists of five steps:
• Generate the whole game tree, all the way down to the terminal states.
• Apply the utility function to each terminal state to get its value.
• Use the utility of the terminal states to determine the utility of the nodes one level higher up in the
search tree.
• Continue backing up the values from the leaf nodes toward the root, one layer at a time.
• Eventually, the backed-up values reach the top of the tree; at that point MAX chooses the move
that leads to the highest value.

This is called the min-max decision, because it maximizes utility under the assumption that the
opponent will play perfectly to minimize it.
Two ply Two player Game tree

Procedure :
Step-1
Step-2

Step :3
3 Ply- 3 Player Game tree

If the maximum depth of the tree is m, and there are b legal moves at each point, then the time
complexity of the min-max algorithm is O(b^m). The algorithm is a depth-first search(although here
the implementation is through recursion rather than using a queue of nodes), so its space
requirements are only linear in m and b.

___________________________________________________________________
Alpha-Beta Pruning Algorithm

 Depth first search – only considers nodes along a single path at any time.
 α = highest-value choice that we can guarantee for MAX so far in the current subtree.
 β = lowest-value choice that we can guarantee for MIN so far in the current subtree.
 Update values of α and β during search and prunes remaining branches as soon as the value
is known to be worse than the current α or β value for MAX or MIN.
Example

Example-2
Step-1

Step-2
Step-3

Step-4

Step-5
Step-6

Step-7

También podría gustarte