Professional Documents
Culture Documents
ACC2009050 - Zhou Yifeng - 106 - Project
ACC2009050 - Zhou Yifeng - 106 - Project
Author:
Supervisor:
ACC2009050
Prof Teoh Zuyao
Z HOU Yifeng
Personal Project
Contents
1 Introduction 1
2 The Algorithm 3
3.4.1 A* Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . 8
4 Conclusion 11
Acknowledgements 12
1
List of Figures
3 Graph . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
4 Weighted Graph . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
5 Graph . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
8 Dijkstra Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
9 A* Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1 Introduction
By using Dijkstra algorithm, we can easily get the optimal path to the destina-
tion.An algorithm that is used for finding the shortest distance, or path, from
starting node to target node in a weighted graph is known as Dijkstra’s Algo-
rithm.This algorithm makes a tree of the shortest path from the starting node,
the source, to all other nodes (points) in the graph.
Dijkstra algorithm is a tool used to calculate the shortest path. It has become an
indispensable thing in people’s life. It can be said that without this algorithm,
the Internet would certainly not be as efficient as it is now. It is widely used in
all aspects of life, such as the driving of unmanned vehicles, the use of game
AIDS, telephone networks and so on.
With the improvement of urbanization level, the scope of urban area is gradu-
ally expanded, and the frequency of people’s activities in the city is increasing.
Urban transportation network plays a more and more important role in mod-
ern life. How to choose the road to travel is a matter of concern.
Generally speaking, people will choose the best path suitable for themselves.
The best path between two points may need to consider more than the shortest
space distance. Sometimes people often consider the problem of travel time.
By the applycation of dijkstra algorithm in maps apps, map apps can provides
people with the best path by avoiding traffic congestion and choosing the path
as short as possible.
1
1 INTRODUCTION
It has always been a difficult problem for AI to control characters in the game to
find the way. Therefore, many practitioners engaged in the game industry have
also put forward many solutions, including Dijkstra algorithm. The location in-
formation in the game is transformed into a graph, and the Dijkstra algorithm
is applied to the intelligent path finding in the game to solve the problem that
the AI control role selects the shortest and optimal path to the target location in
the game.
2
2 THE ALGORITHM
2 The Algorithm
Figure 3: Graph
The definition is: Dijkstra algorithm is a single source shortest path algo-
rithm with weight graph. Given a starting point, Dijkstra algorithm can get
the shortest path from the starting point to all other nodes.
3
2 THE ALGORITHM
Figure 5: Graph
4
2 THE ALGORITHM
• BASE STEP:
When k = 0, before any iterations are carried out,S = ∅ , so the length of
a shortest path from a to a vertex other than a is . Hence, the basis case is
true.
• INDUCTION STEP:
Assume that the inductive hypothesis holds for the kth iteration. Let v be
the vertex added to S at the (k + 1)st iteration, so v is a vertex not in S at
the end of the kth iteration with the smallest label.
From the inductive hypothesis we see that the vertices in S before the (k +
1)st iteration are labeled with the length of a shortest path from a. Also, v
must be labeled with the length of a shortest path to it from a.
Let u be the first vertex not in S in such a path. There is a path with length
less than Lk (v) from a to u containing only vertices of S. This contradicts
the choice of v. Hence, (i) holds at the end of the (k + 1)st iteration.
Let u be a vertex not in S after k + 1 iterations. A shortest path from a to u
containing only elements of S either contains v or it does not. If it does not
contain v, then by the inductive hypothesis its length is Lk (v). If it does
contain v, then it must be made up of a path from a to v of shortest possible
length containing elements of S other than v, followed by the edge from v
to u. In this case, its length would be Lk (v) + w(v, u). This shows that (ii)
is true, because Lk+1 (u) = min { Lk (u), Lk (v) + w(v, u)}.
5
3 REAL LIFE PROBLEM
(a) The Graph of The Problem (b) The Simplified Graph of The Problem
Using the Information of graph and weighted graph, We regard the city as
the point of the graph and the path connecting cities as the edge of the graph.
Then We can use mathematical models to get a simplified form of the problem.
The steps used by Dijkstra’s algorithm to find a shortest path between building
0 and building 3 are shown in Figure 7.
6
3 REAL LIFE PROBLEM
(a) (b)
(c) (d)
(e) (f)
Figure 7: Using Dijkstra Algorithm to find the shortest path from building 0 to
building 3
At each iteration of the algorithm the vertices of the set Sk are colored. A short-
est path from a to each vertex containing only vertices in Sk is indicated for each
7
3 REAL LIFE PROBLEM
• Advantages:
3. Dijkstra algorithm only works for directed, weighted graphs and all
edges should have non-negative values.
• Disadvantages:
3.4.1 A* Algorithm
8
3 REAL LIFE PROBLEM
Therefore, we can use A* algorithm, which extends and improves Dijkstra’s al-
gorithm. The A* algorithm uses heuristics for guiding its search, thus achieving
better performance.
Figure 9: A* Algorithm
Dijkstra’s algorithm only works for weighted graphs with non-negative weights
of edges. Maybe there are negative weights but there exists no cycle of negative
weight. For example, If the road between building 0 and building 1, and build-
ing 2 is damaged, it will take two hours to repair. In order to cope with this
measure, XIAMEN UNIVERSITY MALAYSIA opened the fire passage to allow
building 0 and building 5 to pass directly, with a distance of 5km. Assuming
Professor Teo can walk 4km per hour, we can set the weight from building 0 to
building 5 as - 3 without changing the existing weight (Professor Teo can walk
8km in two hours)
9
3 REAL LIFE PROBLEM
Floyd’s algorithm can find shortest paths between all pairs of vertices.Floyd
algorithm, also known as interpolation method, is an algorithm that uses the
idea of dynamic programming to find the shortest path between multiple source
points in a given weighted graph.
10
4 CONCLUSION
4 Conclusion
The preceding study illustrates why dijkstra algorithm can be used to find the
shortest path and how dijkstra algorithm would be used to find the shortest
path.
Firstly, we introduced what is dijkstra algorithm and its application. We show
the algorithm has reached an irreplaceable position and has been applied to
many industries. Secondly, we get a defination of dijkstra algorithm and we
rigorously proof the correctness of dijkstra algorithm. After that, we use dijk-
stra algorithm to solve real life problem according to its application. Finally, we
summarize its advantages and disadvantages, and propose an improvement
scheme for the shortcomings of this algorithm.
Even though we only calculated one variable, we can still use our simplied
graph in real-world situations by changing the original variables. That is why
algorithms are significant and valuable. This project can assist us understand
the innards of the dijkstra algotirhm as well as conduct more real-world appli-
cation.
11
Acknowledgements
Zhou Yifeng
December 31, 2021