an investigation of dijkstra and floyd algorithms in national city

15
Arun Kumar Sangaiah et al, Int. Journal of Computer Science and Mobile Computing, Vol.3 Issue.2, February- 2014, pg. 124-138 © 2014, IJCSMC All Rights Reserved 124 Available Online at www.ijcsmc.com International Journal of Computer Science and Mobile Computing A Monthly Journal of Computer Science and Information Technology ISSN 2320–088X IJCSMC, Vol. 3, Issue. 2, February 2014, pg.124 – 138 RESEARCH ARTICLE An Investigation of Dijkstra and Floyd Algorithms in National City Traffic Advisory Procedures Arun Kumar Sangaiah 1 , Minghao Han 2 , Suzi Zhang 2 1 School of Computing Science and Engineering, VIT University, Vellore, India 2 Department of Software Engineering, University of Electronic Science and Technology, China [email protected] ABSTRACT:- This paper is focus on design and implementation of the National City traffic advisory procedures. The main aim of this paper provides the optimal decision and transport advisory procedure to the passengers. In this paper we are trying to investigate Dijkstra algorithm and Floyd algorithm implemented in Microsoft Visual Studio in order to establish the storage structure of transportation network and find the shortest path between two cities. We have formulated the optimal decision rules to analyze the time and cost parameters among various cities in china. We have used Dijkstra and Floyd algorithm in order to compare the performance and provide optimal solution to the passengers. Keywords: National City traffic advisory, Dijkstra, Floyd, Microsoft Visual Studio

Upload: lamdien

Post on 02-Jan-2017

221 views

Category:

Documents


4 download

TRANSCRIPT

Page 1: An Investigation of Dijkstra and Floyd Algorithms in National City

Arun Kumar Sangaiah et al, Int. Journal of Computer Science and Mobile Computing,

Vol.3 Issue.2, February- 2014, pg. 124-138

© 2014, IJCSMC All Rights Reserved 124

Available Online at www.ijcsmc.com

International Journal of Computer Science and Mobile Computing

A Monthly Journal of Computer Science and Information Technology

ISSN 2320–088X

IJCSMC, Vol. 3, Issue. 2, February 2014, pg.124 – 138

RESEARCH ARTICLE

An Investigation of Dijkstra and Floyd Algorithms in National City

Traffic Advisory Procedures

Arun Kumar Sangaiah1, Minghao Han2, Suzi Zhang2

1School of Computing Science and Engineering, VIT University, Vellore, India

2Department of Software Engineering, University of Electronic Science and Technology, China

[email protected]

ABSTRACT:- This paper is focus on design and implementation of the National City traffic advisory procedures. The main aim of this paper provides the optimal decision and transport advisory procedure to the passengers. In this paper we are trying to investigate Dijkstra algorithm and Floyd algorithm implemented in Microsoft Visual Studio in order to establish the storage structure of transportation network and find the shortest path between two cities. We have formulated the optimal decision rules to analyze the time and cost parameters among various cities in china. We have used Dijkstra and Floyd algorithm in order to compare the performance and provide optimal solution to the passengers. Keywords: National City traffic advisory, Dijkstra, Floyd, Microsoft Visual Studio

Page 2: An Investigation of Dijkstra and Floyd Algorithms in National City

Arun Kumar Sangaiah et al, Int. Journal of Computer Science and Mobile Computing,

Vol.3 Issue.2, February- 2014, pg. 124-138

© 2014, IJCSMC All Rights Reserved 125

1. Introduction Due to the different purposes the travel of the passengers and its transport requirements are different. For example, for business travel, the passenger wants the time of travel as short as possible. Tourists prefer the cost of travel as minimum as possible. National City traffic advisory procedures can satisfy the passengers demand and provide two to three optimal decision rules according to the transport advisory for passengers. The procedures allow users to look up city information, choose the optimal decision rule and edit city information. At first, the users choose the starting station, the terminal station, the optimal decision rules and traffic tool. The output information are the most time-efficient or the cost- efficient decision, the cost of time and money. Users can also add the city information and edit the cost and the timetable of traffic tools. 2. Literature review This section briefly discusses the Dikjstra and Floyd algorithms adopted in the existing studies. Feng (2005) discussed the taxonomy of the shortest path algorithms from the perspective of problem type, network characteristics and solution techniques and compared to the time complexities. However, the most popular sequential shortest path algorithms are evaluated for their practical efficiency with urban traffic networks. The advance of time dependent and parallel shortest path algorithms is also discussed in many studies The earlier studies [4,5] presented four shortest path algorithms namely Dijkstra’s Algorithm, Floyd-Warshall Algorithm, Bellman-Ford Algorithm, and Genetic Algorithm (GA) for intelligent traffic system. In addition, the earlier study [8] finding shortest path from one node to all other nodes can be derived quickly by using the shortest path algorithm. Further, the earlier study [8] have analyzed dynamic path of all-pairs using shortest path problem for recalculation shortest paths after changing the weight of any single edge. Thus, we can observe two different cases: increasing and decreasing of the weight. The time complexity depends on graph structure and in most cases the time complexity is better than Floyd-Warshall algorithms. In case of decreasing the weight the algorithm which requires O(n^2) time is described. Moreover the earlier study [10] discussed the shortest path between two points in a city road net based on the geographic relevance relationship among roads in the road net. Based on the literature this paper provides some instance which prove applicability and reliability of Dijkstra and Floyd algorithm for national traffic advisory procedures.

3. Proposed Methodology : Dijkstra and Floyd algorithm In this paper, Dijkstra algorithm is been used to search the shortest route from starting station to terminal station. Dijkstra's algorithm is a graph search algorithm that can solve the single-source shortest path problem for a graph with non- negative edge path cost, outputting a shortest path tree. For a given source vertex (node) in the graph, the algorithm finds the path with lowest cost or the shortest path between that vertex and every other vertex. In this paper, transport cost matrix will be initialized first. Users

Page 3: An Investigation of Dijkstra and Floyd Algorithms in National City

Arun Kumar Sangaiah et al, Int. Journal of Computer Science and Mobile Computing,

Vol.3 Issue.2, February- 2014, pg. 124-138

© 2014, IJCSMC All Rights Reserved 126

choose the starting station and terminal station, using Dijkstra's algorithm to find the least time and the least cost between the two places. Floyd algorithm The purpose of this Floyd algorithm is to find the shortest paths in a weighted graph with positive or negative edge weights. A single execution of the algorithm will find the lengths (summed weights) of the shortest paths between all pairs of vertices, though it does not return details of the paths themselves. This algorithm can also use in dynamic programming.

Edi

Figure 1: Main Menu

Figure 2: Information Menu

Start

City infomation Search the Shortest time route Search the most cost-saving route Information editing

Start

Add city Edit train cost Edit train timetable Edit plane cost Edit plane timetable

Page 4: An Investigation of Dijkstra and Floyd Algorithms in National City

Arun Kumar Sangaiah et al, Int. Journal of Computer Science and Mobile Computing,

Vol.3 Issue.2, February- 2014, pg. 124-138

© 2014, IJCSMC All Rights Reserved 127

Figure 3: Add City

Symbol Explanation vt The index number of terminal station

c_number The total number of cities cost[][] A data storage structure which can store the cost of money or

time between cities. pre[] An array to store the previous city number

final[] Mark the node which is in the shortest path found min Storage the shorest edge

dist[] The cost from starting station to terminal station Table 1: Notation in the Dijkstra’s process

start

Input the number of city “n”

i<=n,i++

Add city information

Y

End

N

Page 5: An Investigation of Dijkstra and Floyd Algorithms in National City

Arun Kumar Sangaiah et al, Int. Journal of Computer Science and Mobile Computing,

Vol.3 Issue.2, February- 2014, pg. 124-138

© 2014, IJCSMC All Rights Reserved 128

Figure 4: Process flow of Dijkstra’s Algorithm

Page 6: An Investigation of Dijkstra and Floyd Algorithms in National City

Arun Kumar Sangaiah et al, Int. Journal of Computer Science and Mobile Computing,

Vol.3 Issue.2, February- 2014, pg. 124-138

© 2014, IJCSMC All Rights Reserved 129

4. Process flow Description Tourist traffic between the cities is a typical graph structure which can be seen as a directed graph. The vertex is the city and the side is the cost of time or money. We use the adjacency matrix “G->cost[MAX][MAX]” as a data storage structure which can store the cost of money or time between cities. Editing the information of cities and traffic by different functional modules. Using the structure array to save the new cities and the information between cities. Users can look up the city information and choose the optimal decision rule in main menu. According to the specific requirements of optimal decisions we can Use Dijkstra algorithm to find the optimal value from starting station to the terminal station, (minimum time or minimum cost). Using the array “pre[MAX]” to store the previous city which can output the graph of the path. Output the path from the starting city to the destination city (including transit city) and the least time or the least cost of the travel. Process of Dijkstra algorithm is as follows:

1. Define global variables: dist[MAX] , v0,cost[MAX][MAX] and initialize

cost[MAX][ MAX].The starting node is v0. Let final [v0] =1.The remaining points are

assigned to 0:final [vt] = 0

2.Search the node of shortest distance from which final [vt] = 0.Let final [vt] = 1. 3.For each of the adjacent node u, if dist [vt] + w [vt, u] <dist [u], then let dist[u] =dist[vt] + w[vt,u] 4.If i<MAX-1.Then go back to the second step. 5.For any u, dist [u] is the distance from v0 to u.

5. Results 1. Data - City information:

Chengdu、Xi’an、Zhengzhou、Wuhan、Zhuzhou、Guiyang、Liuzhou、Guangzhou、

Nanling、Xuzhou、Beijing、Tianjing、Shanghai

Ticket price of train:

Starting city Terminal city Price (yuan) Chengdu Guiyang 96 Chengdu Xi’an 84

Xi’an Zhengzhou 51 Zhengzhou Wuhan 53

Wuhan Zhuzhou 40

Page 7: An Investigation of Dijkstra and Floyd Algorithms in National City

Arun Kumar Sangaiah et al, Int. Journal of Computer Science and Mobile Computing,

Vol.3 Issue.2, February- 2014, pg. 124-138

© 2014, IJCSMC All Rights Reserved 130

Zhuzhou Guiyang 90 Zhuzhou Guangzhou 67 Zhuzhou Liuzhou 60 Guiyang Liuzhou 60 Liuzhou Nanling 25

Zhengzhou Beijing 69 Beijing Tianjing 13 Tianjing Xuzhou 67

Zhengzhou Xuzhou 34 Xuzhou Tianjing 65

Shanghai Zhuzhou 118 Table 2: Ticket price in Train

Time cost of train

Starting city Terminal city Time cost (h) Chengdu Guiyang 9 Chengdu Xi’an 8

Xi’an Zhengzhou 5 Zhengzhou Wuhan 5

Wuhan Zhuzhou 4 Zhuzhou Guiyang 9 Zhuzhou Guangzhou 6 Zhuzhou Liuzhou 6 Guiyang Liuzhou 6 Liuzhou Nanling 2

Zhengzhou Beijing 6 Beijing Tianjing 1 Tianjing Xuzhou 6

Zhengzhou Xuzhou 3 Xuzhou Tianjing 6

Shanghai Zhuzhou 11 Table 3: Time in Train

Page 8: An Investigation of Dijkstra and Floyd Algorithms in National City

Arun Kumar Sangaiah et al, Int. Journal of Computer Science and Mobile Computing,

Vol.3 Issue.2, February- 2014, pg. 124-138

© 2014, IJCSMC All Rights Reserved 131

Ticket price of plane

Starting city Terminal city Price(yuan) Chengdu Guiyang 960 Chengdu Xi’an 840

Xi’an Zhengzhou 501 Zhengzhou Wuhan 530

Wuhan Zhuzhou 400 Zhuzhou Guiyang 900 Zhuzhou Guangzhou 670 Zhuzhou Liuzhou 670 Guiyang Liuzhou 600 Liuzhou Nanling 200

Zhengzhou Beijing 690 Beijing Tianjing 310 Tianjing Xuzhou 670

Zhengzhou Xuzhou 340 Xuzhou Tianjing 650

Shanghai Zhuzhou 1180 Table 4: Ticket price in Plane

Time cost of plane

Starting city Terminal city Time cost (h) Chengdu Guiyang 3 Chengdu Xi’an 2

Xi’an Zhengzhou 1 Zhengzhou Wuhan 2

Wuhan Zhuzhou 4 Zhuzhou Guiyang 3 Zhuzhou Guangzhou 6 Zhuzhou Liuzhou 6 Guiyang Liuzhou 6 Liuzhou Nanling 2

Zhengzhou Beijing 6 Beijing Tianjing 1 Tianjing Xuzhou 2

Zhengzhou Xuzhou 3 Xuzhou Tianjing 6

Shanghai Zhuzhou 1 Table 5: Time cost in Train

Page 9: An Investigation of Dijkstra and Floyd Algorithms in National City

Arun Kumar Sangaiah et al, Int. Journal of Computer Science and Mobile Computing,

Vol.3 Issue.2, February- 2014, pg. 124-138

© 2014, IJCSMC All Rights Reserved 132

2. Simulation result

1) Main menu.

Figure 5: Main Menu

2) City information.

Figure 6: City Information

Page 10: An Investigation of Dijkstra and Floyd Algorithms in National City

Arun Kumar Sangaiah et al, Int. Journal of Computer Science and Mobile Computing,

Vol.3 Issue.2, February- 2014, pg. 124-138

© 2014, IJCSMC All Rights Reserved 133

3) Search the shortest time route by train,from Chengdu to Shanghai.

Figure 7: Shortest Time Route Information

Output the cost of time and the graph of the path

Figure 8: Output Shortest Time & Cost Information

Page 11: An Investigation of Dijkstra and Floyd Algorithms in National City

Arun Kumar Sangaiah et al, Int. Journal of Computer Science and Mobile Computing,

Vol.3 Issue.2, February- 2014, pg. 124-138

© 2014, IJCSMC All Rights Reserved 134

4) Search the most cost-saving route by plane,from Xi’an to Beijing.

Figure 9: Shortest path to reach city

Output the cost of money and the graph of the path.

Figure 10: Minimum cost to reach city

Page 12: An Investigation of Dijkstra and Floyd Algorithms in National City

Arun Kumar Sangaiah et al, Int. Journal of Computer Science and Mobile Computing,

Vol.3 Issue.2, February- 2014, pg. 124-138

© 2014, IJCSMC All Rights Reserved 135

5) Information editing function.

Figure 11: Information Editing Function

3. Time-cost of the Dijkstra algorithm and Floyd algorithm(Unit:ns)

Search the shortest time route Time-cost of the

Dijkstra algorithm Time-cost of the Floyd algorithm

From Chengdu to Beijing 20863 ns 135271 ns FromXi’an to Shanghai 20706 ns 127890 ns From Wuhan to Chengdu 21704 ns 128436 ns From Guangzhou to Beijing 20107 ns 126914 ns From Chengdu to Xi’an 20622 ns 125989 ns From Chengdu to Zhengzhou 20328 ns 123984 ns From Xi’an to Liuzhou 20706 ns 124855 ns From Zhuzhou to Guiyang 20202 ns 129801 ns From Guangzhou to Shanghai 21010 ns 134705 ns From Nanling to Xuzhou 21137 ns 126231 ns From Beijing to Tianjing 20171 ns 126683 ns From Xi’an to Guangzhou 19099 ns 126840 ns From Tianjing to Shanghai 20622 ns 125559 ns From Guiyang to Xuzhou 21493 ns 125548 ns From Shanghai to Xuzhou 20454 ns 128226 ns From Nanling to Chengdu 21000 ns 125989 ns

Page 13: An Investigation of Dijkstra and Floyd Algorithms in National City

Arun Kumar Sangaiah et al, Int. Journal of Computer Science and Mobile Computing,

Vol.3 Issue.2, February- 2014, pg. 124-138

© 2014, IJCSMC All Rights Reserved 136

From Liuzhou to Chengdu 21609 ns 125402 ns From Zhuzhou to Beijing 19772 ns 127775 ns From Nanling to Shanghai 21746 ns 127837 ns From Beijing to Shanghai 21053 ns 125916 ns

Table 5: Time & Cost computation of Algorithms

Figure 11: Comparative Analysis of Algorithm

6. Discussion of Result

The existing research【2】have analyzed Dijkstra algorithm, PSP (partitioning shortest

path)algorithm and DBFS1(Dynamic Breadth-First Search algorithm and compared these three algorithms. Giving the analysis of DBFS1 algorithm which is the extremely

superior algorithm. The existing papers【10】use shortest path algorithm to find the

shortest path between two points in a city's road net. Using examples demonstrate the availability of models and algorithm.

In this paper,we not only use Dijkstra algorithm to implement the National City traffic

advisory procedures which can satisfy the passengers’ different demand of travel and provide some optimal decision but also compare Dijkstra algorithm with Floyd algorithm in practical case. This paper compares the two algorithms in time-cost of searching the shortest route.

0

20000

40000

60000

80000

100000

120000

140000

160000

180000

Dat

a 1

Dat

a 2

Dat

a 3

Dat

a 4

Dat

a 5

Dat

a 6

Dat

a 7

Dat

a 8

Dat

a 9

Data

10

Data

11

Data

12

Data

13

Data

14

Data

15

Data

16

Data

17

Data

18

Data

19

Data

20

Floyd algorithm

Dijkstra's algorithm

Page 14: An Investigation of Dijkstra and Floyd Algorithms in National City

Arun Kumar Sangaiah et al, Int. Journal of Computer Science and Mobile Computing,

Vol.3 Issue.2, February- 2014, pg. 124-138

© 2014, IJCSMC All Rights Reserved 137

The process is as follows:

We give twenty examples to Search the shortest time route. Measuring the time-cost of the Dijkstra algorithm and the Floyd algorithm. Time units is ‘ns’,1 s=109 ns. As can be seen from the graph, the time-cost of Dijkstra algorithm is less than Floyd algorithm. Comparing the graph and the twenty groups’ data of two algorithms, we can conclude that the time-cost of Dijkstra's algorithm in searching the shortest route is less than Floyd algorithm. Conclusion We have successfully designed and implemented the National City traffic advisory procedures which create a storage structure of transportation network and find the shortest path of the network. The National City traffic advisory procedures satisfy the passengers’ different demand of travel .Enable users to select two means of transportation, train and plane, providing the least time solution and the least cost solution for users. The search of shortest path is achieved by Dijkstra algorithm and Floyd algorithm. Comparing the time-cost of two algorithms, Dijkstra’s algorithm is more effective than Floyd algorithm. References

【1】 Feng, L. U. (2001). Shortest Path Algorithms: Taxonomy and Advance in

Research [J]. Acta Geodaetica Et Cartographic Sinica, 3, 020.

【2】 Sunan, W., Wei, S., & Wensheng, J. (1994). Comparison of the shortest path

algorithms. Systems Engineering and Electronics, 05.

【3】 Krivoshein D Y, Marchenko A M. Algorithms for dynamic all-pairs shortest

path problem[C]//Problems of Perspective Micro-and Nanoelectronic Systems Development-2012 (ÌÝÑ-2012). 2012: 263-266.

【4】 Magzhan K, Jani H M. A Review And Evaluations Of Shortest Path

Algorithms[J]. INTERNATIONAL JOURNAL OF SCIENTIFIC & TECHNOLOGY RESEARCH VOLUME 2, ISSUE 6, JUNE 2013

【5】 Ziliaskopoulos, A. K., & Mahmassani, H. S. (1993). Time-dependent,

shortest-path algorithm for real-time intelligent vehicle highway system applications (No. 1408).

【6】 ZHOU, Y. M., SUN, S. X., & TIAN, L. (2005). Practical parallel algorithm for

all-pairs shortest-path problem [J]. Computer Applications, 12.

Page 15: An Investigation of Dijkstra and Floyd Algorithms in National City

Arun Kumar Sangaiah et al, Int. Journal of Computer Science and Mobile Computing,

Vol.3 Issue.2, February- 2014, pg. 124-138

© 2014, IJCSMC All Rights Reserved 138

【7】 Zhan F B. (1997) Three fastest shortest path algorithms on real road networks:

Data structures and procedures[J]. Journal of geographic information and decision analysis, 1(1): 69-82.

【8】 Feng-sheng, X. U. (2004). Algorithm for Finding the Shortest Paths

[J].Computer Applications, 5.

【9】 Noto M, Sato H. A method for the shortest path search by extended Dijkstra

algorithm[C] Systems, Man, and Cybernetics, 2000 IEEE International Conference on. IEEE, 2000, 3: 2316-2320.

【10】 Chun Y. A. (2000) New Algorithm for Finding Shortcut in a City's Road Net

Based on GIS Technology. CHINESE JOURNAL OF COMPUTERS,2: 015.