C.V. Raman Global University: Bidyanagar, Mahura, Janla, Bhubaneswar, Odisha-752054
C.V. Raman Global University: Bidyanagar, Mahura, Janla, Bhubaneswar, Odisha-752054
C.V. Raman Global University: Bidyanagar, Mahura, Janla, Bhubaneswar, Odisha-752054
NAME:-BISHAL SAHOO
ROLL NO-CSI20018
REGD NO-20010505
GROUP- 3C
ACKNOWLEDGEMENT
FIRSTLY, THANK YOU SIR FOR EVERYTHING.
SECONDLY, WE WOULD LIKE TO THANK OUR
ESTEEMED UNIVERSITY UNDER WHOSE ROOF
WE HAVE STUDIED AND COMPLETED OUR
TASKS, WITHOUT WHICH WE WOULD STAND
NOWHERE. MANY THANKS TO OUR
WONDERFUL LECTURER, SIR FOR GUIDING US
WITH CLEAR INSTRUCTIONS AND ALWAYS
GAVE CONSTRUCTIVE FEEDBACK. HIS
INVOLVEMENT IN THIS ASSIGNMENT TO
HELP US OUT IN ANY ISSUES WITH
REGARDING TO THE MATHMATICAL AND
TECHNIQUES TO WRITE THIS REPORT
RESULTED IN TO THIS BEAUTIFULLY
PRESENTED WORK. HOWEVER, WE WOULD
LIKE TO THANK OUR PARENTS WHO HAVE
BEEN CONSISTENTLY SUPPORTING US AND
ACTING AS A BACKBONE OF OUR SUCCESS.
THEY KEPT SUPPORTING US WITH LOTS OF
CARE, ATTENTION AND SKILLS.
TOPIC
PATH
FINDING
USING DIJKSTRA’S ALGORITHM
INTRODUCTION
Dijkstra's algorithm
A common example of a graph-based pathfinding algorithm
is Dijkstra's algorithm. This algorithm begins with a start node
and an "open set" of candidate nodes. At each step, the node
in the open set with the lowest distance from the start is
examined. The node is marked "closed", and all nodes
adjacent to it are added to the open set if they have not
already been examined. This process repeats until a path to
the destination has been found. Since the lowest distance
nodes are examined first, the first time the destination is
found, the path to it will be the shortest path.[3]
Dijkstra's algorithm fails if there is a negative edge weight. In
the hypothetical situation where Nodes A, B, and C form a
connected undirected graph with edges AB = 3, AC = 4, and
BC = −2, the optimal path from A to C costs 1, and the
optimal path from A to B costs 2. Dijkstra's Algorithm starting
from A will first examine B, as that is the closest. It will assign
a cost of 3 to it, and mark it closed, meaning that its cost will
never be reevaluated. Therefore, Dijkstra's cannot evaluate
negative edge weights. However, since for many practical
purposes there will never be a negative edgeweight,
Dijkstra's algorithm is largely suitable for the purpose of
pathfinding.
A* algorithm
A* is a variant of Dijkstra's algorithm commonly used in
games. A* assigns a weight to each open node equal to the
weight of the edge to that node plus the approximate
distance between that node and the finish. This approximate
distance is found by the heuristic, and represents a minimum
possible distance between that node and the end. This allows
it to eliminate longer paths once an initial path is found. If
there is a path of length x between the start and finish, and
the minimum distance between a node and the finish is
greater than x, that node need not be examined.[4]
A* uses this heuristic to improve on the behavior relative to
Dijkstra's algorithm. When the heuristic evaluates to zero, A*
is equivalent to Dijkstra's algorithm. As the heuristic estimate
increases and gets closer to the true distance, A* continues
to find optimal paths, but runs faster (by virtue of examining
fewer nodes). When the value of the heuristic is exactly the
true distance, A* examines the fewest nodes. (However, it is
generally impractical to write a heuristic function that always
computes the true distance, as the same comparison result
can often be reached using simpler calculations – for
example, using Manhattan distance over Euclidean
distance in two-dimensional space.) As the value of the
heuristic increases, A* examines fewer nodes but no longer
guarantees an optimal path. In many applications (such as
video games) this is acceptable and even desirable, in order
to keep the algorithm running quickly.
Sample algorithm
This is a fairly simple and easy-to-understand pathfinding
algorithm for tile-based maps. To start off, you have a map, a
start coordinate and a destination coordinate. The map will
look like X being walls, S being the O being the
this, start,
finish and _ being open spaces, the numbers along the top
and right edges are the column and row numbers:
12345678
XXXXXXXXXX
X___XX_X_X
1X_X__X___
X2XSXX___X
_X3X_X__X_
__X4X___XX
_X_X5X_X__
X_X_X6X_XX
___X_X7X__
O_X___X8XX
XXXXXXXX
First, create a list of coordinates, which we will use as a
queue. The queue will be initialized with one coordinate, the
end coordinate. Each coordinate will also have a counter
variable attached (the purpose of this will soon become
evident). Thus, the queue starts off as ((3,8,0)).
Then, go through every element in the queue, including new
elements added to the end over the course of the
algorithm, and for each element, do the following:
E ⊆ {{𝒙, 𝒚} | 𝒙, 𝒚 ∈ 𝑽 𝒂𝒏𝒅 𝒙 ≠
𝒚} a set of edges (also called links or lines), which
are unordered pairs of vertices (that is, an edge is
associated with two distinct vertices).
To avoid ambiguity, this type of object may be called
precisely an undirected simple graph.
In the edge {𝒙, 𝒚} , the vertices 𝒙 and 𝒚 are called
the endpoints of the edge. The edge is said to join 𝑥 and
𝑦 and to be incident on 𝒙 and on 𝒚. A vertex may exist in a
graph and not belong to an edge. Multiple edges, not allowed
under the definition above, are two or more edges that join
the same two vertices.
To avoid ambiguity, this type of object may be called
precisely an undirected multigraph.
A loop is an edge that joins a vertex to itself. Graphs as
defined in the two definitions above cannot have loops,
because a loop joining a vertex ‘x’ to itself is the edge (for an
undirected simple graph) or is incident on (for an undirected
multigraph) {x,x}={x} which is not in {{𝒙, 𝒚} | 𝒙, 𝒚 ∈
𝑽 𝒂𝒏𝒅 𝒙 ≠ 𝒚} . So to allow loops the definitions must be
expanded. For undirected simple graphs, the definition of E
should be modified to E ⊆ {{𝒙, 𝒚} | 𝒙, 𝒚 ∈ 𝑽} . For
undirected multigraphs, the definition of 𝜙 should be
modified to E → {{𝒙, 𝒚} | 𝒙, 𝒚 ∈ 𝑽} . To avoid ambiguity,
these types of objects may be called undirected simple graph
permitting loops and undirected multigraph permitting loops,
respectively.
V and E are usually taken to be finite, and many of the well-
known results are not true (or are rather different) for
infinite graphs because many of the arguments fail in
the infinite case. Moreover,V is often assumed to be non-
empty, but E is allowed to be the empty set. The order of a
graph is |V| its number of vertices. The size of a graph is |E|
its number of edges. The degree or valency of a vertex is the
number of edges that are incident to it, where a loop is
counted twice. The degree of a graph is the maximum of the
degrees of its vertices.
A directed graph or digraph is a graph in which edges have
orientations.
In one restricted but very common sense of the
term,[5] a directed graph is an ordered pair G=(V,E)
comprising:
54
Notice how the rightmost vertex has its path length updated
twice