A_ Algorithm Optimalit
A_ Algorithm Optimalit
Printed using Save ChatGPT as PDF, powered by PDFCrowd HTML to PDF API. 1/15
Zerind
449=75+374
Timisoara
Arad
Fagaras
Oradea
646=280+366 415=239+176 671=291+380
(e) After expanding Fagaras
447=118+329
Rimnicu Vilcea
Craiova
Pitesti
526=366+160
417=317+100
Sibiu
553=300+253
Zerind
449=75+374
Arad
Sibiu
Arad
646=280+366
Fagaras
Oradea
Timisoara
447=118+329
Rimnicu Vilcea
671=291+380
Sibiu
Bucharest
591=338+253 450=450+0
Craiova
526=366+160
Pitesti
417=317+100
(f) After expanding Pitesti
Sibiu
Arad
646=280+366
Fagaras
Oradea
Arad
Timisoara
Zerind
449=75+374
Sibiu
553=300+253
447=118+329
Rimnicu Vilcea
671=291+380
Sibiu
Printed using Save ChatGPT as PDF, powered by PDFCrowd HTML to PDF API. 2/15
Bucharest
591=338+253 450=450+0
Craiova
526=366+160
Pitesti
Sibiu
553=300+253
Bucharest
418=418+0
Figure 3.24
Craiova
Rimnicu Vilcea
615=455+160 607=414+193
Zerind
449=75+374
Stages in an A∗ search for Bucharest. Nodes are labeled with f = g+h.The
h values are the straight-line distances to Bucharest taken from Figure 3.22.
Section 3.5.
Informed (Heuristic) Search Strategies
97
O
Z
A
380
T
N
S
400
L
R
F
I
V
P
M
D
Figure 3.25
420
C
H
B
U
G
E
Mapof Romania showing contours at f = 380, f = 400,andf = 420, with
Arad as the start state. Nodes inside a given contour have f-costs less than or equal to the
contour value.
CONTOUR
Figure 3.9; because f is nondecreasing along any path, nwould have lower f-cost than n
and would have been selected first.
From the two preceding observations, it follows that the sequence of nodes expanded
Printed using Save ChatGPT as PDF, powered by PDFCrowd HTML to PDF API. 3/15
by A∗ using GRAPH-SEARCH is in nondecreasing order of f(n). Hence, the first goal node
selected for expansion must be an optimal solution because f is the true cost for goal nodes
(which have h=0) and all later goal nodes will be at least as expensive.
The fact that f-costs are nondecreasing along any path also means that we can draw
contours in the state space, just like the contours in a topographic map. Figure 3.25 shows
an example. Inside the contour labeled 400, all nodes have f(n) less than or equal to 400,
and so on. Then, because A∗ expands the frontier node of lowest f-cost, we can see that an
A∗ search fans out from the start node, adding nodes in concentric bands of increasing f-cost.
With uniform-cost search (A∗ search using h(n)=0), the bands will be “circular”
around the start state. With more accurate heuristics, the bands will stretch toward the goal
state and become more narrowly focused around the optimal path. If C∗ is the cost of the
optimal solution path, then we can say the following:
• A∗ expands all nodes with f(n) <C∗.
• A∗mightthen expand some ofthe nodes right on the “goal contour” (where f(n)=C∗)
before selecting a goal node.
Completeness requires that there be only finitely many nodes with cost less than or equal to
C∗, a condition that is true if all step costs exceed some finite and if b is finite.
Notice that A∗ expands no nodes with f(n) >C∗—for example, Timisoara is not
expanded in Figure 3.24 even though it is a child of the root. We say that the subtree below
98
Chapter 3.
Solving Problems by Searching
PRUNING
OPTIMALLY
EFFICIENT
ABSOLUTE ERROR
RELATIVE ERROR
Timisoara is pruned; because hSLD is admissible, the algorithm can safely ignore this subtree
while still guaranteeing optimality. The concept of pruning—eliminating possibilities from
consideration without having to examine them—is important for many areas of AI.
One final observation is that among optimal algorithms of this type—algorithms that
extend search paths from the root and use the same heuristic information—A∗ is optimally
efficient for any given consistent heuristic. That is, no other optimal algorithm is guaran
teed to expand fewer nodes than A∗ (except possibly through tie-breaking among nodes with
f(n)=C∗). This is because any algorithm that does not expand all nodes with f(n) <C∗
runs the risk of missing the optimal solution.
That A∗ search is complete, optimal, and optimally efficient among all such algorithms
is rather satisfying. Unfortunately, it does not mean that A∗ is the answer to all our searching
needs. The catch is that, for most problems, the number of states within the goal contour
search space is still exponential in the length of the solution. The details of the analysis are
beyond the scope of this book, but the basic results are as follows. For problems with constant
step costs, the growth in run time as a function of the optimal solution depth d is analyzed in
terms of the the absolute error or the relative error of the heuristic. The absolute error is
defined as Δ ≡ h∗ −h,whereh∗ is the actual cost of getting from the root to the goal, and
the relative error is defined as ≡ (h∗ − h)/h∗.
The complexity results depend very strongly on the assumptions made about the state
space. The simplest model studied is a state space that has a single goal and is essentially a
tree with reversible actions. (The 8-puzzle satisfies the first and third of these assumptions.)
In this case, the time complexity of A∗ is exponential in the maximum absolute error, that is,
O(bΔ). For constant step costs, we can write this as O(b d),whered is the solution depth.
For almost all heuristics in practical use, the absolute error is at least proportional to the path
Printed using Save ChatGPT as PDF, powered by PDFCrowd HTML to PDF API. 4/15
cost h∗, so is constant or growing and the time complexity is exponential in d. We can
also see the effect of a more accurate heuristic: O(b d)=O((b)d), so the effective branching
factor (defined more formally in the next section) is b .
When the state space has many goal states—particularly near-optimal goal states—the
search process can be led astray from the optimal path and there is an extra cost proportional
to the number of goals whose cost is within a factor of the optimal cost. Finally, in the
general case of a graph, the situation is even worse. There can be exponentially many states
with f(n) <C∗ even if the absolute error is bounded by a constant. For example, consider
a version of the vacuum world where the agent can clean up any square for unit cost without
even having to visit it: in that case, squares can be cleaned in any order. With N initially dirty
squares, there are 2N states where some subset has been cleaned and all of them are on an
optimal solution path—and hence satisfy f(n) <C∗—even if the heuristic has an error of 1.
The complexity of A∗ often makes it impractical to insist on finding an optimal solution.
One can use variants of A∗ that find suboptimal solutions quickly, or one can sometimes
design heuristics that are more accurate but not strictly admissible. In any case, the use of a
good heuristic still provides enormous savings compared to the use of an uninformed search.
In Section 3.6, we look at the question of designing good heuristics.
Computation time is not, however, A∗’s main drawback. Because it keeps all generated
nodes in memory (as do all GRAPH-SEARCH algorithms), A∗ usually runs out of space long
Section 3.5.
Informed (Heuristic) Search Strategies
99
function RECURSIVE-BEST-FIRST-SEARCH(problem) returns a solution, or failure
return RBFS(problem,MAKE-NODE(problem.INITIAL-STATE),∞)
function RBFS(problem,node,f limit) returns a solution,orfailure and a new f-cost limit
if problem.GOAL-TEST(node.STATE) then return SOLUTION(node)
successors ←[]
for each action in problem.ACTIONS(node.STATE) do
add CHILD-NODE(problem,node,action) intosuccessors
if successors is empty then return failure, ∞
for each s in successors do /* update f with value from previous search, if any */
s.f ←max(s.g + s.h, node.f))
loop do
best ←the lowest f-value node in successors
if best.f > f limit then return failure, best.f
alternative ←the second-lowest f-value among successors
result,best.f ←RBFS(problem,best,min(f limit,alternative))
if result= failure then return result
Figure 3.26
The algorithm for recursive best-first search.
before it runs out of time. For this reason, A∗ is not practical for many large-scale prob
lems. There are, however, algorithms that overcome the space problem without sacrificing
optimality or completeness, at a small cost in execution time. We discuss these next. in simple
words explain this concept
The passage elaborates on the properties and behavior of the A* search algorithm, focusing on its
completeness, optimality, and efficiency under different heuristic conditions. Here's a concise
breakdown of the key points:
Printed using Save ChatGPT as PDF, powered by PDFCrowd HTML to PDF API. 5/15
Key Properties of A*
1. Optimality:
Tree-Search: A* is optimal if the heuristic h(n) is admissible (never overestimates the true
cost to reach the goal).
Graph-Search: A* is optimal if h(n) is consistent (satisfies the triangle inequality: h(n) ≤
c(n, a, n′ ) + h(n′ )).
2. Non-Decreasing f (n):
When h(n) is consistent, the f (n) = g(n) + h(n) values along any path are non-decreasing.
This follows from the consistency property.
3. Expansion of Nodes:
A* ensures that when a node is expanded, the optimal path to that node has already been
found.
The sequence of node expansions is in non-decreasing order of f (n).
4. Contours in State Space:
Nodes are expanded in concentric bands of increasing f (n) values. This is similar to
topographic contours where nodes inside a contour have f (n) ≤ contour value.
The algorithm expands all nodes with f (n) < C ∗ (optimal cost) and possibly some nodes on
the goal contour (f (n) = C ∗ ).
5. Pruning:
Subtrees with f (n) > C ∗ are pruned, ensuring efficiency without sacrificing optimality when
h(n) is admissible.
6. Optimal Efficiency:
Among algorithms that extend paths using the same heuristic information, A* is optimally
efficient—it expands the fewest nodes necessary, given a consistent heuristic.
Limitations of A*
Conclusion
Printed using Save ChatGPT as PDF, powered by PDFCrowd HTML to PDF API. 6/15
A* is a powerful algorithm that balances completeness, optimality, and efficiency when guided by a
consistent heuristic. Despite its strengths, its exponential time and space complexities pose significant
challenges for large-scale problems, leading to the need for alternative strategies or heuristic
improvements.
1. Optimality:
A* is optimal (finds the best solution) if:
The heuristic h(n) is admissible (it never overestimates the true cost to the goal) for
tree-search.
The heuristic h(n) is consistent (for any node n and its successor, the estimated cost is
less than or equal to the step cost plus the estimated cost from the successor) for
graph-search.
2. Nondecreasing f(n):
If the heuristic is consistent, the value of f(n) = g(n) + h(n) (cost so far + estimated cost to
goal) along any path does not decrease. This ensures proper ordering of nodes for expansion.
3. Node Expansion:
When A* selects a node n for expansion, it guarantees that the optimal path to n has already
been found.
Nodes with lower f(n) are always expanded first.
4. Contours of f(n):
Nodes are expanded in increasing order of f(n). This creates "contours" (bands) of nodes with
similar f(n) values.
The search focuses more narrowly on the optimal path when the heuristic is accurate.
5. Efficiency and Drawbacks:
A* is optimally efficient for any consistent heuristic—it expands the minimum number of
nodes necessary to guarantee an optimal solution.
However, A* can run out of memory quickly because it keeps all generated nodes in memory.
In large problems, this can make A* impractical.
Knowledge-Based Agents
Printed using Save ChatGPT as PDF, powered by PDFCrowd HTML to PDF API. 7/15
A knowledge-based agent is an AI agent that acts based on the knowledge it possesses about the
world. It uses a knowledge base (KB) to store facts and rules and employs reasoning mechanisms to
deduce actions.
Algorithm:
1. TELL(KB, Sentence):
Adds the given sentence (fact or rule) to the KB.
Updates the KB to reflect new knowledge.
Example:
`TELL(KB, "It is raining")`
Adds the fact "It is raining" to the KB.
2. ASK(KB, Query):
Queries the KB to check if the query is entailed by the KB.
Returns a result (true/false or specific values).
Example:
`ASK(KB, "Is it raining?")`
Returns true if the KB contains "It is raining".
Algorithm:
python
function KNOWLEDGE_BASED_AGENT(percept):
KB ← InitializeKB()
TELL(KB, percept) # Add the current percept to KB
if ASK(KB, "Is it raining?") = true:
action ← "Do nothing"
else if ASK(KB, "Is the garden dry?") = true:
action ← "Turn on the sprinkler"
else:
action ← "Do nothing"
return action
1. TELL Function:
Adds percepts like "It is raining" or "The garden is dry" to the KB.
Example:
`TELL(KB, "It is raining")` updates the KB with the current weather condition.
2. ASK Function:
Queries the KB to make decisions.
Example:
`ASK(KB, "Is it raining?")` retrieves the fact from the KB to determine the next action.
Limitations
Printed using Save ChatGPT as PDF, powered by PDFCrowd HTML to PDF API. 9/15
The Wumpus World is a classic AI problem that consists of a grid-based environment. The agent
navigates through the grid to find gold while avoiding pits and the Wumpus (a dangerous creature). The
agent senses the environment using percepts like breeze, stench, and glitter.
1. Fully or Partially Observable: Partially observable as the agent only perceives its immediate
surroundings.
2. Deterministic: Actions have deterministic outcomes.
3. Discrete: The grid-based environment is divided into distinct rooms.
4. Static: The environment does not change while the agent is deliberating.
5. Single Agent: Only one agent navigates the grid.
Propositions
Printed using Save ChatGPT as PDF, powered by PDFCrowd HTML to PDF API. 10/15
Prove that the Wumpus is in Room (1, 3)
Given KB:
1. S(1, 2).
2. ¬S(2, 2).
3. S(1, 2) ⟺ W (1, 3) ∨ W (2, 2).
4. ¬W (2, 2).
Steps:
Conclusion
Using propositional logic and the knowledge base, we proved that the Wumpus is in room (1, 3).
The models of a logical language are the formal structures that constitute the possible worlds under
consideration. Each model links the vocabulary of the logical sentences to elements of the possible
world,
so that the truth of any sentence can be determined. Thus, models for propositional logic link
proposition
symbols to predefined truth values. Models for first-order logic have objects. The domain of a model
is the
set of objects or domain elements it contains. The domain is required to be nonempty—every
possible world
must contain at least one object.
A relation is just the set of tuples of objects that are related.
• Unary Relation: Relations relates to single Object.
• Binary Relation: Relation Relates to multiple objects Certain kinds of relationships are best
considered as functions, in that a given object must be related to exactly one object.
For Example:
Richard the Lionheart, King of England from 1189 to 1199; His younger brother, the evil King John,
who
ruled from 1199 to 1215; the left legs of Richard and John; crown Unary Relation: John is a king
Binary
Relation : crown is on head of john , Richard is brother ofjohn The unary "left leg" function includes
the
Printed using Save ChatGPT as PDF, powered by PDFCrowd HTML to PDF API. 11/15
following mappings:
(Richard the Lionheart) ->Richard's left leg (King John) ->Johns left Leg explain in understanding way
The explanation deals with logical models and how they represent relationships and functions in
logical languages like propositional and first-order logic. Let’s break it down into simple terms:
1. Unary Relation:
Describes a property or characteristic of a single object.
Example:
"John is a king."
This is a unary relation because it tells us something about John alone.
2. Binary Relation:
Describes a relationship between two objects.
Example:
"The crown is on the head of John."
Here, two objects (crown and John) are connected by a relationship (is on the head of).
Key Points
Logical models provide a framework to describe and reason about such relationships in any possible
world.
The text is talking about logical models and how they describe relationships between objects in a world.
A logical model uses relations and functions to explain how objects are connected. Here's what each
term means:
Key Concepts
1. Logical Model:
It’s like a way to describe a world.
It includes:
Objects: Things like people, animals, or items (e.g., Richard, John, crown).
Relations: How these things are connected (e.g., “John is a king” or “The crown is on
John’s head”).
Functions: Special relationships where one object is related to exactly one other object
(e.g., “John’s left leg”).
Printed using Save ChatGPT as PDF, powered by PDFCrowd HTML to PDF API. 13/15
Types of Relations
1. Unary Relation:
Describes something about one object.
Example: “John is a king.”
It tells us about John only.
2. Binary Relation:
Describes a relationship between two objects.
Example: “The crown is on John’s head.”
This connects two objects: the crown and John.
3. Function:
A type of relationship where one object is connected to only one other object.
Example: The left leg function:
Richard → Richard’s left leg.
John → John’s left leg.
Each person is related to exactly one left leg.
Simple Example
This model explains how these objects are connected and helps us reason about this world.
Logical models let us organize information and figure out if statements about the world are true. For
example:
If you know “John is a king” and “The crown is on John’s head,” you can use these relationships to
understand the world.
The example describes a world where John is a king (unary relation), the crown is on John’s head
(binary relation), and each person has a unique left leg (function).
Printed using Save ChatGPT as PDF, powered by PDFCrowd HTML to PDF API. 14/15
The objects in Kinship domain are people. We have two unary predicates, Male and Female.
Kinship relations—parenthood, brotherhood, marriage, and so on—are represented by binary
predicates:
Parent, Sibling, Brother,Sister,Child, Daughter, Son, Spouse, Wife, Husband,
Grandparent,Grandchild,
Cousin, Aunt, and Uncle.
We use functions for Mother and Father, because every person has exactly one of each of these.
We can represent each function and predicate, writing down what we know in terms of the other
symbols.
2. Unary Predicates:
Male(x): x is a male.
Female(x): x is a female.
3. Binary Predicates:
Parent(x, y): x is a parent of y.
Sibling(x, y): x and y are siblings.
Brother(x, y): x is a brother of y.
Sister(x, y): x is a sister of y.
Child(x, y): x is a child of y.
Daughter(x, y): x is a daughter of y.
Son(x, y): x is a son of y.
Spouse(x, y): x is a spouse of y.
Wife(x, y): x is the wife of y.
Husband(x, y): x is the husband of y.
Grandparent(x, y): x is a grandparent of y.
Grandchild(x, y): x is a grandchild of y.
Cousin(x, y): x is a cousin of y.
Aunt(x, y): x is an aunt of y.
Uncle(x, y): x is an uncle of y.
4. Functions:
Mother(x): Returns the mother of x.
Father(x): Returns the father of x.
Example Representation:
Printed using Save ChatGPT as PDF, powered by PDFCrowd HTML to PDF API. 15/15