0% found this document useful (0 votes)
19 views43 pages

And or Graph

The document discusses the A* algorithm, a popular search method used for pathfinding in graphs, which combines Dijkstra's algorithm and Greedy Best-First Search to find the shortest path by evaluating both actual and estimated costs. It also introduces the AND-OR graph concept and the AO* algorithm, which breaks complex problems into smaller tasks, allowing for more efficient problem-solving. Finally, it touches on Constraint Satisfaction Problems (CSPs), emphasizing their importance in modeling and solving various real-world challenges.

Uploaded by

hilegiv205
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)
19 views43 pages

And or Graph

The document discusses the A* algorithm, a popular search method used for pathfinding in graphs, which combines Dijkstra's algorithm and Greedy Best-First Search to find the shortest path by evaluating both actual and estimated costs. It also introduces the AND-OR graph concept and the AO* algorithm, which breaks complex problems into smaller tasks, allowing for more efficient problem-solving. Finally, it touches on Constraint Satisfaction Problems (CSPs), emphasizing their importance in modeling and solving various real-world challenges.

Uploaded by

hilegiv205
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/ 43

And or Graph

Madhuri Gupta
Assistant Professor
Department of Computer Science & Engineering
Recap of the last class on A * Algorithm

The A* search algorithm is a widely used and popular search algorithm


commonly employed in pathfinding and graph traversal problems.

It's designed to find the shortest path between a starting node and a goal node in
a graph or a grid, while considering both the actual cost to reach a node and an
estimate of the remaining cost to reach the goal.

A* combines the strengths of two other algorithms: Dijkstra's algorithm and


Greedy Best-First Search.
• prioritize exploring nodes that seem most
likely to lead to the goal. It achieves this
by using two key components for each
node:
The main • Cost Function (g): This represents the
actual cost of getting from the starting
idea behind node to the current node.
• Heuristic Function (h): This estimates

A* the cost of getting from the current node to


the goal. The heuristic function is
admissible if it never overestimates the
true cost.
To expand nodes in the order of their
estimated total cost, which is given by
f(n) = g(n) + h(n). At each step, the
algorithm selects the node with the
lowest f value and explores its neighbors.

The algorithm continues until the goal


A* Uses a Priority node is reached or the open list (priority
queue) is empty, indicating that there is
Queue no path to the goal.

If the heuristic is consistent (also known


as monotonic), A* is guaranteed to find
the optimal path.
A* combines Dijkstra's algorithm and Greedy Best-First
Search

Efficiency of Greedy
Completeness and Best-First Search by
optimality of Dijkstra's considering both the
algorithm actual cost and the
estimated remaining cost.
• Solving various path finding
problems.
• Finding routes on maps
• Navigating robots and
A* :A Steps to • Planning trajectories.

Powerful
Algorithm
A* is Highly Effective and Efficient

The choice of heuristic can significantly impact its A well-designed heuristic can guide the algorithm
performance. toward the goal more accurately and help reduce the
number of nodes that need to be expanded.
• the A* search algorithm is a
versatile and widely used
technique for finding optimal
paths in graphs and grids.
• It's a fundamental concept in
Summary computer science and is applied
in numerous real-world scenarios
where efficient pathfinding is
essential.
AND-OR graph concept
Best-first search is what the AO* algorithm does.

The AO* method divides any given


difficult problem into a smaller group of
problems that are then resolved using the
AND-OR graph concept.

AND OR graphs are specialized graphs that are


used in problems that can be divided into smaller
problems.
The AND side of the graph
represents a set of tasks
that must be completed to
AND OR graphs
achieve the main goal.

The OR side of the graph


represents different methods
for accomplishing the same
main goal.
AND OR graphs Example
AND OR
graphs
Example
• In the above figure,
the buying of a car may be
broken down into smaller
problems or tasks that can
be accomplished to achieve
the main goal in the above
figure, which is an example
of a simple AND-OR graph.
AND OR graphs
Example
• The other task is to either steal a
car that will help us accomplish
the main goal or use your own
money to purchase a car that will
accomplish the main goal.
AND OR
graphs Example
• The AND symbol is used to
indicate the AND part of the
graphs, which refers to the
need that all subproblems
containing the AND to be
resolved before the
preceding node or issue may
be finished.
AND-OR trees Better than the A* algorithm.

The start state and the target state are already known in
the knowledge-based search strategy known as the AO*
algorithm, and the best path is identified by heuristics.

The informed search technique considerably


reduces the algorithm’s time complexity.
ALGORITHM
a) Select an unexpanded b) Generate successors of i. otherwise for each
Repeat the followings until
Let G be a graph with only node from the most NODE. If there are none, set SUCCESSOR that is not an
INIT is labeled SOLVED or
starting node INIT. promising path from INIT h(NODE) = FUTILITY (i.e., ancestor of NODE do the
h(INIT) > FUTILITY
(call it NODE) NODE is unsolvable); following:

c) Propagate the newly


discovered information up
the graph by doing the
following: let S be set of
ii. If SUCCESSOR is a
iii. If SUCCESSPR is not a SOLVED nodes or nodes
terminal node, label it i. Remove a node from S
Add SUCCESSSOR to G. terminal node, compute its whose h values have been
SOLVED and set and call it CURRENT.
h changed and need to have
h(SUCCESSOR) = 0.
values propagated back to
their parents. Initialize S to
Node. Until S is empty
repeat the followings:

ii. Compute the cost of each iv. Mark CURRENT as v. If CURRENT has been
iii. Mark the best path out
of the arcs emerging from SOLVED if all of the nodes labeled SOLVED or its cost
of CURRENT by marking the So add all of the ancestors
CURRENT. Assign minimum connected to it through was just changed,
arc that had the minimum of CURRENT to S.
cost of its successors as its new labeled arc have been propagate its new cost back
cost in step ii
h. labeled SOLVED up through the graph.
• The evaluation function in AO* looks
like this:
f(n) = g(n) + h(n)
f(n) = Actual cost + Estimated cost
Working of here,
AO* f(n) = The actual cost of
traversal.
algorithm g(n) = the cost from the initial
node to the current node.
h(n) = estimated cost from the
current node to the goal state.
Difference between the A* Algorithm and AO*
algorithm

A* always gives the optimal


A* algorithm and AO* They are both informed
solution but AO* doesn’t
algorithm both works search and works on given
guarantee to give the optimal
on the best first search. heuristics values.
solution.

Once AO* got a


When compared to the A* opposite to the A* algorithm,
solution doesn’t explore all
algorithm, the AO* algorithm the AO* algorithm cannot go
possible paths but A*
uses less memory. into an endless loop.
explores all paths.
Example of
And or Graph
•Here in the above
example below the Node
which is given is the
heuristic value i.e h(n).
Edge length is considered
as 1.
Step 1

AO* Algorithm (Step-1)


AO* Algorithm (Step-1)

f(A⇢B) = g(B) + h(B) =


With help of f(n) =
1 + 5 ……here
g(n) + h(n) evaluation Start from node A,
g(n)=1 is taken by
function,
default for

f(A⇢C+D) = g(c) + h(c) ……here we have


path cost= 6 + g(d) + h(d) = 1 + 2 + added C & D because
4 they are in

So, by calculation
A⇢B path is chosen
AND = 8 which is the
minimum path, i.e
f(A⇢B)
Step 2

•According to the answer of


step 1, explore node BHere
the value of E & F are
calculated as follows
Step 2
f(B⇢E) = g(e) + h(e)f(B⇢E) = 1 + 7= 8

f(B⇢f) = g(f) + h(f)

f(B⇢f) = 1 + 9 = 10

So, by above calculation B⇢E path is chosen


which is minimum path, i.e f(B⇢E)
because B's heuristic value is
different from its actual value
Therefore, the heuristic for A
The heuristic is updated and
must be updated due to the
the minimum cost path is
change in B's heuristic.
selected. The minimum value
in our situation is 8.

Step 2
f(A⇢B) = g(B) + updated h(B)= So we need to calculate it
1 + 8= 9 again.
Step 3
Step 3

By comparing f(A⇢B) & f(A⇢C+D)

f(A⇢C+D) is shown to be smaller.

i.e 8 < 9Now explore f(A⇢C+D) So, the current node


is C f(C⇢G) = g(g) + h(g)f(C⇢G) = 1 + 3= 4

f(C⇢H+I) = g(h) + h(h) + g(i) + h(i)

f(C⇢H+I) = 1 + 0 + 1 + 0 ……

here we have added H & I because they are in


AND = 2
f(C⇢H+I) is selected

Paths H & I are solved

Path A⇢D needs to be calculated

Final Result f(D⇢J) = g(j) + h(j)f(D⇢J) = 1 + 0 = 1

the heuristic of node D needs to be updated to1.

f(A⇢C+D) = g(c) + h(c) + g(d) + h(d) = 1 + 2 + 1 +1=5

as we can see that path f(A⇢C+D) is get solved and this


tree has become a solved tree now.
• In simple words, the main flow of this

Conclusion of algorithm is that we have to find firstly


level 1st heuristic value and then level 2nd
and after that update the values with going
Example upward means towards the root node. In
the above tree diagram, we have updated all
the values.
EXAMPLE: 2

• STEP 1:A is the only node, it is at the end of


the current best path. It is expanded, yielding
nodes B, C, D. The arc to D is labeled as the
most promising one emerging from A, since it
costs 6compared to B and C, Which costs 9.
STEP 2:

Node B is chosen for expansion.


This process produces one new
arc, the AND arc to E and F, with
a combined cost estimate of 10.

so we update the f’ value of D to


10

.Going back one more level, we


see that this makes the AND arc
B-C better than the arc to D, so it
is labeled as the current best
path.
STEP 3:
STEP 3:

We traverse the arc from A and discover the unexpanded nodes B and C.

If we going to find a solution along this path, we will have to expand both B and C
eventually, so let’s choose to explore B first.

This generates two new arcs, the ones to G and to H. Propagating their f’ values
backward, we update f’ of B to 6(since that is the best we think we can do, which
we can achieve by going through G).

This requires updating the cost of the AND arc B-C to 12(6+4+2). After doing that,
the arc to D is again the better path from A, so we record that as the current best
path and either node E or node F will chosen for expansion at step 4.
STEP4:
EXAMPLE: 3
Solution Steps
Solution Steps
Real-Life Vehicle Routing Portfolio
Applications of Problem Optimization

AO* algorithm
• In both examples, the AO* algorithm can be
Real-Life Applic used to find the optimal solution that
ations of AO* balances multiple conflicting objectives, such
as minimizing distance and time in the
algorithm vehicle routing problem, or maximizing
returns and minimizing risks in the portfolio
optimization problem.
• The algorithm starts with an initial solution
and iteratively improves it by exploring
Summary alternative solutions and keeping the best
solution that satisfies both objectives
• A Constraint Satisfaction Problem (CSP) is
a computational problem in the field of
Upcoming Artificial Intelligence that involves finding
a solution that satisfies a set of constraints
Lecture or conditions.
Constraint
Satisfaction • It is a formal framework used to model
Problem (CSP) and solve problems where the goal is to
find values for a set of variables that meet
specified constraints.
• Components
• Variables
• Domains
• Constraints

• Objective

Brief •

Example
Solving Approaches

overview of • Backtracking
• Constraint Propagation
• Local Search
CSPs Applications
Challenges
• Constraint Satisfaction
Problems provide a formal
framework for modeling and
solving problems involving
variables, domains, and
constraints. They are used to
summary address a wide range of
real-world challenges across
different domains, where
finding a solution that adheres
to specified conditions is
critical.
•Thank You

You might also like