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

AIML UNIT 1

The document provides an overview of problem-solving in artificial intelligence, focusing on intelligent agents, their environments, and various types of search algorithms. It discusses the structure and functioning of agents, including simple reflex agents, model-based agents, goal-based agents, and utility-based agents, along with the importance of performance measures and rationality. Additionally, it categorizes environments based on observability, determinism, and other properties, emphasizing the need for agents to adapt to their surroundings for effective problem-solving.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

AIML UNIT 1

The document provides an overview of problem-solving in artificial intelligence, focusing on intelligent agents, their environments, and various types of search algorithms. It discusses the structure and functioning of agents, including simple reflex agents, model-based agents, goal-based agents, and utility-based agents, along with the importance of performance measures and rationality. Additionally, it categorizes environments based on observability, determinism, and other properties, emphasizing the need for agents to adapt to their surroundings for effective problem-solving.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 88

UNIT I

PROBLEM SOLVING

Introduction to AI - AI Applications - Problem solving


agents – search algorithms – uninformed search
strategies – Heuristic search strategies – Local search and
optimization problems – adversarial search – constraint
satisfaction problems.
ARTIFICIAL INTELLIGENCE

UNIT 1

UNIT I INTELLIGENT AGENTS

Introduction to AI – Agents and Environments – concept of rationality – nature of


environments –structure of agents. Problem solving agents – search algorithms –
uninformed search strategies.

AGENT:

 An agent is a thing that can be viewed as:

– perceiving its environment through sensors and

– acting upon that environment through actuators.

 An agent program runs in cycles of: (1)perceive, (2)think,

and (3)act.

Example:

Human agent:

– Sensors: eyes, ears, and other organs.

– Actuators: hands, legs, mouth, and other body parts.

• Robotic agent:

– Sensors: Cameras and infrared range finders.


– Actuators: Various motors.

Agent’s organization

a) Atomic Representation: Each state of the world is a black-box that has no internal structure.
E.g., finding a driving route,each state is a city.

AI algorithms: search, games, Markov decision processes, hidden Markov models, etc.

b) Factored Representation: Each state has some attribute-value properties. E.g., GPS location,
amount of gas in the tank.

AI algorithms: constraint satisfaction, and Bayesian networks.

c) Structured Representation: Relationships between the objects of a state can be explicitly


expressed. AI algorithms: first order logic, knowledge-based learning, natural language
understanding.
Percept and Percept Sequence

Percept:

Percept refer to the agent’s perceptual inputs at any given instant.

Percept Sequence:

Percept sequence is the complete history of everything the agent has ever perceived. In general, an
agent’s choice of action at any given instant can depend on the entire percept sequence observed to
date, but not on anything it hasn’t perceived. By specifying the agent’s choice of action for every
possible percept sequence, we have said more or less everything there is to say about the agent.

Agent Function and Agent Program

Agent Function:

An agent’s behavior is described by the agent function that maps any given percept sequence to an
action. We can imagine tabulating the agent function that describes any given agent; for most
agents, this would be a very large table—infinite, in fact, unless we place a bound on the length of
percept sequences we want to consider.

Agent Program:

The table is, of course, an external characterization of the agent. Internally, the agent function for an
artificial agent will be implemented by an agent program.

Note: 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 within some
physical system.

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 2.3 and an agent program that implements is given below

RATIONAL AGENT:

A rational agent is one that does the right thing—conceptually speaking, every entry in table for the
agent function is filled out correctly.

PERFORMANCE MEASURE:

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. This notion of desirability
is captured by a performance measure that evaluates any given sequence of environment states.

As a general rule, it is better to design performance measures according to what one actually wants
in the environment, rather than according to how one thinks the agent should behave.

Obviously, there is not one fixed performance measure for all tasks and agents; typically,a designer
will devise one appropriate to the circumstances.

Example:

Consider, for example, the vacuum-cleaner agent from the preceding section. We might propose to
measure performance by the amount of dirt cleaned up in a single eight-hour shift.With a rational
agent, of course, what you ask for is what you get. A rational agent can maximize this performance
measure by cleaning up the dirt, then dumping it all on the floor,then cleaning it up again, and so on.
A more suitable performance measure would reward the agent for having a clean floor. For example,
one point could be awarded for each clean square at each time step (perhaps with a penalty for
electricity consumed and noise generated).

RATIONALITY

Definition of 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.
Rational at any given time depends on four things:

• The performance measure that defines the criterion of success.

• The agent’s prior knowledge of the environment.

• The actions that the agent can perform.

• The agent’s percept sequence to date.

Example:

We claim that under these circumstances the vacuum cleaner agent is indeed rational

 The performance measure awards one point for each clean square at each time step,

over a “lifetime” of 1000 time steps.

 The “geography” of the environment is known a priori but the dirt distribution and the initial
location of the agent are not. Clean squares stay clean and sucking cleans the current
square. The Left and Right actions move the agent left and right except when this would take
the agent outside the environment, in which case the agent remains where it is.
 The only available actions are Left, Right, and Suck.
 The agent correctly perceives its location and whether that location contains dirt.

THE NATURE OF ENVIRONMENT

Task environments, which are essentially the “problems” to which rational agents are the
“solutions.”

Specifying the task environment:

We use PEAS (Performance, Environment, Actuators, Sensors) description to specify task


environment.
PROPERTIES OF ENVIRONMENT:

An environment in artificial intelligence is the surrounding of the agent. The agent takes
input from the environment through sensors and delivers the output to the environment
through actuators. There are several types of environments:

 Fully Observable vs Partially Observable


 Deterministic vs Stochastic
 Competitive vs Collaborative
 Single-agent vs Multi-agent
 Static vs Dynamic
 Discrete vs Continuous
 Episodic vs Sequential
 Known vs Unknown
Environment types

1. Fully Observable vs Partially Observable

 When an agent sensor is capable to sense or access the complete state of an agent at
each point in time, it is said to be a fully observable environment else it is partially
observable.
 Maintaining a fully observable environment is easy as there is no need to keep track
of the history of the surrounding.
 An environment is called unobservable when the agent has no sensors in all
environments.
 Examples:
o Chess – the board is fully observable, and so are the opponent’s moves.
o Driving – the environment is partially observable because what’s around the
corner is not known.

2. Deterministic vs Stochastic

 When a uniqueness in the agent’s current state completely determines the next state of
the agent, the environment is said to be deterministic.
 The stochastic environment is random in nature which is not unique and cannot be
completely determined by the agent.
 Examples:
o Chess – there would be only a few possible moves for a coin at the current
state and these moves can be determined.
o Self-Driving Cars- the actions of a self-driving car are not unique, it varies
time to time.
3. Competitive vs Collaborative

 An agent is said to be in a competitive environment when it competes against another


agent to optimize the output.
 The game of chess is competitive as the agents compete with each other to win the
game which is the output.
 An agent is said to be in a collaborative environment when multiple agents cooperate
to produce the desired output.
 When multiple self-driving cars are found on the roads, they cooperate with each
other to avoid collisions and reach their destination which is the output desired.

4. Single-agent vs Multi-agent

 An environment consisting of only one agent is said to be a single-agent environment.


 A person left alone in a maze is an example of the single-agent system.
 An environment involving more than one agent is a multi-agent environment.
 The game of football is multi-agent as it involves 11 players in each team.

5. Dynamic vs Static

 An environment that keeps constantly changing itself when the agent is up with some
action is said to be dynamic.
 A roller coaster ride is dynamic as it is set in motion and the environment keeps
changing every instant.
 An idle environment with no change in its state is called a static environment.
 An empty house is static as there’s no change in the surroundings when an agent
enters.

6. Discrete vs Continuous

 If an environment consists of a finite number of actions that can be deliberated in the


environment to obtain the output, it is said to be a discrete environment.
 The game of chess is discrete as it has only a finite number of moves. The number of
moves might vary with every game, but still, it’s finite.
 The environment in which the actions are performed cannot be numbered i.e. is not
discrete, is said to be continuous.
 Self-driving cars are an example of continuous environments as their actions are
driving, parking, etc. which cannot be numbered.

7.Episodic vs Sequential

 In an Episodic task environment, each of the agent’s actions is divided into atomic
incidents or episodes. There is no dependency between current and previous incidents.
In each incident, an agent receives input from the environment and then performs the
corresponding action.
 Example: Consider an example of Pick and Place robot, which is used to detect
defective parts from the conveyor belts. Here, every time robot(agent) will make the
decision on the current part i.e. there is no dependency between current and previous
decisions.
 In a Sequential environment, the previous decisions can affect all future decisions.
The next action of the agent depends on what action he has taken previously and what
action he is supposed to take in the future.
 Example:
o Checkers- Where the previous move can affect all the following moves.

8. Known vs Unknown

 In a known environment, the output for all probable actions is given. Obviously, in
case of unknown environment, for an agent to make a decision, it has to gain
knowledge about how the environment works.

STRUCTURE OF AGENTS

The job of AI is to design an agent program that implements the agent function—the mapping from
percepts to actions. We assume this program will run on some sort of computing device with
physical sensors and actuators—we call this the architecture.

agent = architecture + program

If the program is going to recommend actions like Walk, the architecture had better have legs. The
architecture might be just an ordinary PC, or it might be a robotic car with several on board
computers, cameras, and other sensors. In general, the architecture makes the percepts from the
sensors available to the program, runs the program, and feeds the program’s action choices to the
actuators as they are generated.

TYPES OF AGENTS:

 Simple reflex agents


 Model-based reflex agents;
 Goal-based agents; and
 Utility-based agents.

SIMPLE REFLEX AGENTS:

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 is a simple reflex agent, because its decision is based only on the
current location and on whether that location contains dirt. An agent program for this agent is
Simple reflex behaviors occur even in more complex environments. In case of automated taxi,if the
car in front brakes and its brake lights come on, then you should notice this and initiate braking. In
other words, some processing is done on the visual input to establish the condition we call “The car in
front is braking.” Then, this triggers some established connection in the agent program to the action
“initiate braking.” We call such a connection a condition–action rule,written as
if car-in-front-is-braking then initiate-braking.

Pro:

Simple reflex agents have the admirable property of being simple,

Cons:
But they turn out to be of limited intelligence. The agent will work only if the correct
decision can be made on the basis of only the current percept—that is, only if the
environment is fully observable.Even a little bit of unobservability can cause serious trouble.
For example, the braking rule given earlier assumes that the condition car-in-front-is-braking
can be determined from the current percept—a single frame of video. This works if the car in
front has a centrally mounted brake light. Unfortunately, older models have different
configurations of taillights, brake lights, and turn-signal lights, and it is not always possible to
tell from a single image whether the car is braking. A simple reflex agent driving behind such
a car would either brake continuously and unnecessarily, or, worse, never brake at all.

MODEL BASED AGENT:

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.

Example:For the braking problem, the internal state is not too extensive—
just the previous frame from the camera, allowing the agent to detect when two red lights at
the edge of the vehicle go on or off simultaneously. For other driving tasks such as changing
lanes, the agent needs to keep track of where the other cars are if it can’t see them all at once.

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 northbound on the freeway, one
is usually about five miles north of where one was five minutes ago.
This knowledge about “how the world works”—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 is called a model-based agent.
GOAL BASED AGENT:

Knowing something 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 the model to choose actions that achieve the goal.
shows the goal-based agent’s structure.

Sometimes goal-based action selection is straightforward—for example, when goal


satisfaction results immediately from a single action. Sometimes it will be more tricky—for
example, when the agent has to consider long sequences of twists and turns in order to find a
way to achieve the goal. Search and planning are the subfields of AI devoted to finding
action sequences that achieve the agent’s goals.
Although the goal-based agent appears less efficient, it is more flexible because the
knowledge that supports its decisions is represented explicitly and can be modified. If it starts
to rain, the agent can update its knowledge of how effectively its brakes will operate; this will
automatically cause all of the relevant behaviors to be altered to suit the new conditions.

UTIITY BASED AGENT:

Goals alone are not enough to generate high-quality behavior in most environments. For
example, many action sequences 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. A more general performance
measure should allow a comparison of different world states according to exactly how happy
they would make the agent. Because “happy” does not sound very scientific, economists and
computer scientists use the term utility instead.

An agent’s utility function is essentially an internalization of the performance measure. If


the internal utility function and the external performance measure are in agreement, then an
agent that chooses actions to maximize its utility will be rational according to the external
performance measure.

(refer handwritten notes for structure of agents answer)

PROBLEM SOLVING

PROBLEM SOLVING AGENTS:

 It is a kind of goal based agent.


 Problem-solving agents use atomic representations that is,states of the world are considered
as wholes, with no internal structure visible to the problem-solving algorithms.
 Goal-based agents that use more advanced factored or structured representations are
usually called planning agents.

PROBLEM SOLVING STEPS:

1.Goal Formulation:

 Intelligent agents are supposed to maximize their performance measure. Achieving this is
sometimes simplified if the agent can adopt a goal and aim at satisfying it.
 Goals help organize behaviour by limiting the objectives that the agent is trying to achieve
and hence the actions it needs to consider.
 Goal formulation, based on the current situation and the agent’s performance measure, is
the first step in problem solving.

Example:
Imagine an agent in the city of Arad, Romania, enjoying a touring holiday. Now, suppose the agent
has a non-refundable ticket to fly out of Bucharest the following day. In that case, it makes sense for
the agent to adopt the goal of getting to Bucharest. Courses of action that don’t reach Bucharest on
time can be rejected without further consideration and the agent’s decision problem is greatly
simplified.

2.Problem Formulation:

Problem formulation is the process of deciding what actions and states to consider, given a goal.

Example:

Our agent has now adopted the goal of driving to Bucharest.Let us assume that the agent will
consider actions at the level of driving from one major town to another. Each state therefore
corresponds to being in a particular town.

3.Searching

The solution to any problem is a fixed sequence of actions.The process of looking for a sequence of
actions that reaches the goal is called search. A search algorithm takes a problem as input and
returns a solution in the form of an action sequence.

5.Execution Phase

Once a solution is found, the actions it recommends can be carried out. This is called the execution
phase. After formulating a goal and a problem to solve,the agent calls a search procedure to solve it.
It then uses the solution to guide its actions,doing whatever the solution recommends as the next
thing to do—typically, the first action of the sequence—and then removing that step from the
sequence.

6.Formulate a new Goal

Once the solution has been executed, the agent will formulate a new goal.

Example : A simple Problem solving agent


OPEN LOOP SYSTEM:

While the agent is executing the solution sequence, it ignores its percepts when choosing an action
because it knows in advance what they will be. An agent that carries out its plans with its eyes
closed, so to speak, must be quite certain of what is going on. Control theorists call this an open-loop
system, because ignoring the percepts breaks the loop between agent and environment.

WELL DEFINED PROBLEMS AND SOLUTIONS

A problem can be defined formally by five components

1. The initial state that the agent starts in.


2. 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. 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 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.
 For example, we have RESULT(In(Arad),Go(Zerind)) = In(Zerind) .
Together, the initial state, actions, and transition model implicitly define the
state space of the problem—the set of all states reachable from the initial
state by any sequence of actions. The state space forms a directed network
or graph in which the nodes are states and the links between nodes are
actions. (The map of Romania shown in Figure 3.2 can be interpreted as a
state-space graph if we view each road as standing PATH for two driving
actions, one in each direction.) A path in the state space is a sequence of
states connected by a sequence of actions.

4. 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. A path 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. The cost of a path can be
described as the sum of the costs of the individual actions along the path.
The step cost of taking action a in state s to reach state sis denoted by c(s, a,
s). The step costs for Romania are shown in Figure 3.2 as route distances.
We assume that step costs are nonnegative.

The preceding elements define a problem and can be gathered into a single data structure that is
given as input to a problem-solving algorithm. A solution to a problem is an action sequence that
leads from the initial state to a goal state. Solution quality is measured by the path cost function,
and an optimal solution has the lowest path cost among all solutions.

FORMULATING PROBLEMS:

ABSTRACTION

We proposed a formulation of the problem in terms of the initial state, actions, transition model,
goal test, and path cost. This formulation seems reasonable, but it is still a model—an abstract
mathematical description—and not the real thing. Many considerations are left out of our state
descriptions if they are irrelevant to the problem.The process of removing detail from a
representation is called abstraction.

ABSTRACTION OF STATE

Example:

Compare the simple state description we have chosen, In(Arad), to an actual crosscountry trip,
where the state of the world includes so many things: the traveling companions, the current radio
program, the scenery out of the window, the proximity of law enforcement officers, the distance to
the next rest stop, the condition of the road, the weather, and so on. All these considerations are
left out of our state descriptions because they are irrelevant to the problem of finding a route to
Bucharest.

ABSTRACTION OF ACTION

In addition to abstracting the state description, we must abstract the actions themselves.

Example:A driving action has many effects. Besides changing the location of the vehicle and its
occupants, it takes up time, consumes fuel, generates pollution, and changes the agent (as they say,
travel is broadening). Our formulation takes into account only the change in location. Also, there are
many actions that we omit altogether: turning on the radio, looking out of the window, slowing
down for law enforcement officers, and so on.

Note:

 The abstraction is valid if we can expand any abstract solution into a solution in the more
detailed world.
 The abstraction is useful if carrying out each of the actions in the solution is easier than the
original problem.
 The choice of a good abstraction thus involves removing as much detail as possible while
retaining validity and ensuring that the abstract actions are easy to carry out. Were it not for
the ability to construct useful abstractions, intelligent agents would be completely swamped
by the real world.

EXAMPLE PROBLEMS

 TOY PROBLEMS
o 8 PUZZLE PROBLEM
o 8 QUEEN PROBLEM
 REAL WORLD PROBLEM
o TRAVELLING SALESMAN PROBLEM
o VLSI LAYOUT
o ROBOTIC NAVIGATION
o AUTOMATIC ASSEMBLY SEQUENCING

TOY PROBLEM REAL WORLD PROBLEM


A TOY PROBLEM toy problem is intended to A real-world problem is one whose solutions
illustrate or exercise various problem-solving people actually REAL-WORLD PROBLEM care
methods. about. Such problems tend not to have a single
It can be given a concise, exact description and agreed-upon description, but we can give the
hence is usable by different researchers to general flavor of their formulations.
compare the performance of algorithms.

TOY PROBLEM

8 PUZZLE PROBLEM

GOAL FORMULATION:

The 8-puzzle, an instance of which is shown in Figure 3.4, consists of a 3×3 board with eight
numbered tiles and a blank space. A tile adjacent to the blank space can slide into the space.
PROBLEM FORMULATION

1. States: A state description specifies the location of each of the eight tiles and the blank in
one of the nine squares.
2. Initial state: Any state can be designated as the initial state. Note that any given goal can be
reached from exactly half of the possible initial states.
3. Actions: The simplest formulation defines the actions as movements of the blank space Left,
Right, Up, or Down. Different subsets of these are possible depending on where the blank is.
4. Transition model: Given a state and action, this returns the resulting state; for example, if
we apply Left to the start state in Figure 3.4, the resulting state has the 5 and the blank
switched.
5. Goal test: This checks whether the state matches the goal configuration shown in Figure 3.4.
(Other goal configurations are possible.)
6. 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 SLIDING-BLOCK
PUZZLES test problems for new search algorithms in AI. This family is known to be NP-complete, so
one does not expect to find methods significantly better in the worst case than the search
algorithms described in this chapter and the next. The 8-puzzle has 9!/2 = 181, 440 reachable states
and is easily solved. The 15-puzzle (on a 4×4 board) has around 1.3 trillion states, and random
instances can be solved optimally in a few milliseconds by the best search algorithms. The 24-puzzle
(on a 5 × 5 board) has around 1025 states, and random instances take several hours to solve
optimally.

8 QUEENS PROBLEM

GOAL FORMULATION:
The goal of the 8-queens problem is to place eight queens on a chessboard such that no queen
attacks any other. (A queen attacks any piece in the same row, column or diagonal).

There are two main kinds of formulation.

 An incremental formulation involves operators that augment the state description, starting
with an empty state; for the 8-queens problem, this means that each action adds a queen to
the state.
 A complete-state formulation starts with all 8 queens on the board and moves them around.
In either case, the path cost is of no interest because only the final state counts.

The first incremental formulation one might try is the following:

• States: Any arrangement of 0 to 8 queens on the board is a state.

• Initial state: No queens on the board.

• Actions: Add a queen to any empty square.

• Transition model: Returns the board with a queen added to the specified square.

• Goal test: 8 queens are on the board, none attacked.

In this formulation, we have 64 · 63 ··· 57 ≈ 1.8 × 1014 possible sequences to investigate.

A better formulation would prohibit placing a queen in any square that is already attacked:

• States: All possible arrangements of n queens (0 ≤ n ≤ 8), one per column in the leftmost n
columns, with no queen attacking another.
• Actions: Add a queen to any square in the leftmost empty column such that it is not attacked by
any other queen.

This formulation reduces the 8-queens state space from 1.8 × 1014 to just 2,057, and solutions are
easy to find. On the other hand, for 100 queens the reduction is from roughly 10400 states to about
1052 states (Exercise 3.5)—a big improvement, but not enough to make the problem tractable.

REAL WORLD PROBLEM

ROUTE FINDING PROBLEM

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. 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:

• 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.

• Initial state: This is specified by the user’s query.

• 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.

• 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.

• Goal test: Are we at the final destination specified by the user?

• 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.

TOURING PROBLEM:
Touring problems are closely related to route-finding problems, but with an important
difference. Consider, for example, the problem “Visit every city in Figure 3.2 at least once,
starting and ending in Bucharest.” As with route finding, the actions correspond to trips
between adjacent cities. The state space, however, is quite different. Each state must include
not just the current location but also the set of cities the agent has visited. So the initial state
would be In(Bucharest), Visited({Bucharest}), a typical intermediate state would be
In(Vaslui), Visited({Bucharest, Urziceni, Vaslui}), and the goal test would check whether the
agent is in Bucharest and all 20 cities have been visited.

TRAVELLING SALESMAN PROBLEM:

The traveling salesperson problem (TSP) is a touring problem in which each city must be
visited exactly once. The aim is to find the shortest tour. The problem is known to be NP-
hard, but an enormous amount of effort has been expended to improve the capabilities of
TSP algorithms. In addition to planning trips for traveling salespersons, these algorithms
have been used for 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 comes after the logical design phase and is usually
split into two parts: cell layout and channel routing. In cell layout, the primitive components
of the circuit are grouped into cells, each of which performs some recognized function. Each
cell has a fixed footprint (size and shape) and requires a certain number of connections to
each of the other cells. The aim is to place the cells on the chip so that they do not overlap
and so that there is room for the connecting wires to be placed between the cells. Channel
routing finds a specific route for each wire through the gaps between the cells. These search
problems are extremely complex, but definitely worth solving. Later in this chapter, we
present some algorithms capable of solving them.

ROBOT NAVIGATION:

Robot navigation is a generalization of the route-finding problem described earlier. Rather


than following a discrete set of routes, a robot can move in a continuous space with (in
principle) 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 must also be controlled, the search space becomes many-dimensional. Advanced
techniques are required just to make the search space finite. We examine some of these
methods in Chapter 25. In addition to the complexity of the problem, real robots must also
deal with errors in their sensor readings and motor controls.

AUTOMATIC ASSEMBLY SEQUENCING:

Automatic assembly sequencing of complex objects by a robot was first demonstrated by FREDDY
(Michie, 1972). Progress since then has been slow but sure, to the point where the assembly of
intricate objects such as electric motors is economically feasible. In assembly problems, the aim is to
find an order in which to assemble the parts of some object. If the wrong order is chosen, there will
be no way to add some part later in the sequence without undoing some of the work already done.
Checking a step in the sequence for feasibility is a difficult geometrical search problem closely
related to robot navigation. Thus, the generation of legal actions is the expensive part of assembly
sequencing. Any practical algorithm must avoid exploring all but a tiny fraction of the state space.
Another important assembly problem is protein design, in which the goal is to find a sequence of
amino acids that will fold into a three-dimensional protein with the right properties to cure some
disease.

SEARCHING FOR SOLUTION

SOLUTION- A set of possible action sequence

Search Tree-The possible action sequences starting at the initial state form a search tree
with the

 initial state NODE at the root;


 the branches are actions and
 the nodes correspond to states in the state space of the problem.

Steps to form a search tree

 Start with initial state as root


 Check if it is goal state
 If no,do the process of expanding by applying legal set of actions to initial state and
generate new set of states.
 Check each newly generated states one by one.Follow up one option at a time.These
are all called leaf nodes as they don’t have children.The set of all leaf nodes that are
available for expansion is called frontier (open list).
 The process of expanding nodes on the frontier continues until either a solution s
found or no more states to expand
 Search strategy involves choosing which state to expand first.
 This can be done using TREE-SEARCH ALGORITHM.
 There can be Repeated states which is generated by loopy path. Loops can cause
certain algorithms to fail, making otherwise solvable problems unsolvable.
Fortunately, there is no need to consider loopy paths. Loopy paths are a special case of
the more general concept of redundant paths, which exist whenever there is more than one
way to get from one state to another.
Example : Arad->Sibiu->Arad Therefore Arad is repeated state.

 Algorithms that forget their history are doomed to repeat it. The way to avoid exploring
redundant paths is to remember where one has been. To do this, we EXPLORED SET
augment the TREE-SEARCH algorithm with a data structure called the explored set (also
CLOSED LIST known as the closed list), which remembers every expanded node. Newly
generated nodes that match previously generated nodes—ones in the explored set or the
frontier—can be discarded instead of being added to the frontier.
Infrastructure for Search Algorithm

Search algorithms require a data structure to keep track of the search tree that is being constructed.
For each node n of the tree, we have a structure that contains four components:

• 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.

Given the components for a parent node, it is easy to see how to compute the necessary
components for a child node. The function CHILD-NODE takes a parent node and an action and
returns the resulting child node:

The frontier needs to be stored in such a way that the search algorithm can easily choose the next
node to expand QUEUE according to its preferred strategy. The appropriate data structure for this is
a queue. The operations on a queue are as follows:

• EMPTY?(queue) returns true only if there are no more elements in the queue.

• POP(queue) removes the first element of the queue and returns it.
• INSERT(element, queue) inserts an element and returns the resulting queue

The explored set can be implemented with a hash table to allow efficient checking for repeated
states. With a good implementation, insertion and lookup can be done in roughly constant time no
matter how many states are stored. One must take care to implement the hash table with the right
notion of equality between states.

For example, in the traveling salesperson problem (page 74), the hash table needs to know that the
set of visited cities {Bucharest,Urziceni,Vaslui} is the same as {Urziceni,Vaslui,Bucharest}. Sometimes
this can be achieved most easily by insisting that the data structures for states be in some canonical
form; that is, logically equivalent states should map to the same data structure. In the case of states
described by sets, for example, a bit-vector representation or a sorted list without repetition would
be canonical, whereas an unsorted list would not.

Measuring Problem Solving performance

We can evaluate an algorithm’s performance in four ways:

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

• Optimality: Does the strategy find the optimal solution?

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

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

Size of State Space Graph

The typical measure is the size of the state space graph, |V | + |E|, where V is the set of vertices
(nodes) of the graph and E is the set of edges (links). This is appropriate when the graph is an explicit
data structure that is input to the search program.

In AI, the graph is often represented implicitly by the initial state, actions, and transition model and
is frequently infinite.

Complexity:

Complexity is expressed in terms of three quantities:

b, the branching factor or maximum number of successors of any node;

d, the depth of the shallowest goal node (i.e., the number of steps along the path from the root);
and

m, the maximum length of any path in the state space.


Time and Space Complexity:

Time is often measured in terms of the number of nodes generated during the search, and space in
terms of the maximum number of nodes stored in memory.

Search cost and Total Cost

To assess the effectiveness of a search algorithm, we can consider just the search cost— which
typically depends on the time complexity but can also include a term for memory usage—or we can
use the total cost, which combines the search cost and the path cost of the solution found. For the
problem of finding a route from Arad to Bucharest, the search cost is the amount of time taken by
the search and the solution cost is the total length of the path To assess the effectiveness of a search
algorithm, we can consider just the search cost— which typically depends on the time complexity
but can also include a term for memory—or we can use the total cost, which combines the search
cost and the path cost of the solution found. For the problem of finding a route from Arad to
Bucharest, the search cost is the amount of time taken by the search and the solution cost is the
total length of the path in kilometers. Thus, to compute the total cost, we have to add milliseconds
and kilometers. There is no “official exchange rate” between the two, but it might be reasonable in
this case to convert kilometers into milliseconds by using an estimate of the car’s average speed
(because time is what the agent cares about). This enables the agent to find an optimal tradeoff
point at which further computation to find a shorter path becomes counterproductive.

UNINFORMED SEARCH STRATEGIES

(REFER HANDWRITTEN NOTES)


Adversarial Search
Adversarial search is a search, where we examine the problem which arises when
we try to plan ahead of the world and other agents are planning against us.

o we have studied the search strategies which are only associated with a single agent
that aims to find the solution which often expressed in the form of a sequence of
actions.
o But, there might be some situations where more than one agent is searching for the
solution in the same search space, and this situation usually occurs in game playing.
o The environment with more than one agent is termed as multi-agent environment,
in which each agent is an opponent of other agent and playing against each other.
Each agent needs to consider the action of other agent and effect of that action on
their performance.
o So, Searches in which two or more players with conflicting goals are trying to
explore the same search space for the solution, are called adversarial searches,
often known as Games.
o Games are modeled as a Search problem and heuristic evaluation function, and these
are the two main factors which help to model and solve games in AI.

Types of Games in AI:


Deterministic Chance Moves

Perfect information Chess, Checkers, go, Othello Backgammon, monopoly

Imperfect information Battleships, blind, tic-tac-toe Bridge, poker, scrabble, nuclea

o Perfect information: A game with the perfect information is that in which agents can
look into the complete board. Agents have all the information about the game, and
they can see each other moves also. Examples are Chess, Checkers, Go, etc.
o Imperfect information: If in a game agents do not have all information about the
game and not aware with what's going on, such type of games are called the game
with imperfect information, such as tic-tac-toe, Battleship, blind, Bridge, etc.
o Deterministic games: Deterministic games are those games which follow a strict
pattern and set of rules for the games, and there is no randomness associated with
them. Examples are chess, Checkers, Go, tic-tac-toe, etc.
o Non-deterministic games: Non-deterministic are those games which have various
unpredictable events and has a factor of chance or luck. This factor of chance or luck
is introduced by either dice or cards. These are random, and each action response is
not fixed. Such games are also called as stochastic games.
Example: Backgammon, Monopoly, Poker, etc.

Note: In this topic, we will discuss deterministic games, fully observable


environment, zero-sum, and where each agent acts alternatively.

Zero-Sum Game
o Zero-sum games are adversarial search which involves pure competition.
o In Zero-sum game each agent's gain or loss of utility is exactly balanced by the losses
or gains of utility of another agent.
o One player of the game try to maximize one single value, while other player tries to
minimize it.
o Each move by one player in the game is called as ply.
o Chess and tic-tac-toe are examples of a Zero-sum game.

Zero-sum game: Embedded thinking


The Zero-sum game involved embedded thinking in which one agent or player is trying
to figure out:

o What to do.
o How to decide the move
o Needs to think about his opponent as well
o The opponent also thinks what to do

Each of the players is trying to find out the response of his opponent to their actions.
This requires embedded thinking or backward reasoning to solve the game problems
in AI.

Formalization of the problem:


A game can be defined as a type of search in AI which can be formalized of the
following elements:

o Initial state: It specifies how the game is set up at the start.


o Player(s): It specifies which player has moved in the state space.
o Action(s): It returns the set of legal moves in state space.
o Result(s, a): It is the transition model, which specifies the result of moves in the state
space.
o Terminal-Test(s): Terminal test is true if the game is over, else it is false at any case.
The state where the game ends is called terminal states.
o Utility(s, p): A utility function gives the final numeric value for a game that ends in
terminal states s for player p. It is also called payoff function. For Chess, the outcomes
are a win, loss, or draw and its payoff values are +1, 0, ½. And for tic-tac-toe, utility
values are +1, -1, and 0.

Game tree:
A game tree is a tree where nodes of the tree are the game states and Edges of the
tree are the moves by players. Game tree involves initial state, actions function, and
result Function.

Example: Tic-Tac-Toe game tree:

The following figure is showing part of the game-tree for tic-tac-toe game. Following
are some key points of the game:

o There are two players MAX and MIN.


o Players have an alternate turn and start with MAX.
o MAX maximizes the result of the game tree
o MIN minimizes the result.
Example Explanation:

o From the initial state, MAX has 9 possible moves as he starts first. MAX place x and
MIN place o, and both player plays alternatively until we reach a leaf node where one
player has three in a row or all squares are filled.
o Both players will compute each node, minimax, the minimax value which is the best
achievable utility against an optimal adversary.
o Suppose both the players are well aware of the tic-tac-toe and playing the best play.
Each player is doing his best to prevent another one from winning. MIN is acting
against Max in the game.
o So in the game tree, we have a layer of Max, a layer of MIN, and each layer is called
as Ply. Max place x, then MIN puts o to prevent Max from winning, and this game
continues until the terminal node.
o In this either MIN wins, MAX wins, or it's a draw. This game-tree is the whole search
space of possibilities that MIN and MAX are playing tic-tac-toe and taking turns
alternately.

Hence adversarial Search for the minimax procedure works as follows:

o It aims to find the optimal strategy for MAX to win the game.
o It follows the approach of Depth-first search.
o In the game tree, optimal leaf node could appear at any depth of the tree.
o Propagate the minimax values up to the tree until the terminal node discovered.

In a given game tree, the optimal strategy can be determined from the minimax value
of each node, which can be written as MINIMAX(n). MAX prefer to move to a state of
maximum value and MIN prefer to move to a state of minimum value then:

You might also like