Research on Improved Dijkstra Algorithm using for

Research on Improved Dijkstra Algorithm using for Safety Management in the
Road Network
FAN Jun1,GUO Zhong-yin2,Yuan Hong1
(1. Engineering Institute of Engineering Corps, PLA Univ.of Sci. & Tech.,Nanjing 210007,China;2. Key Laboratory of Road
and Traffic Engineering of the Ministry of Education, TongJi Univ.,Shanghai 200092,China 3.)
Abstract:Road safety management based on road network, including construction of the
network model, solution of effective pathway, determination of road right parameters, safety
evaluation of road state and determination of the shortest (safest) path. For individual road
users, classic Dijkstra algorithm could be used to search the shortest optional (Safety) path in
road network. However, due to the existence of connecting nodes of incomplete types in the
actual network, which connecting road is not entirely exchange on each other, the classical
Dijkstra shortest path algorithm cannot be used directly. By improved network topology
information, the incompletely connected nodes can be changed to the completely virtual
connected nodes; Or by changing algorithm data structure and data information when
maintaining the existing road network, the algorithm can be improved. The classical Dijkstra
algorithm is improved by means of these two aspects in this paper, and realizes the shortest
(safest) routing in the actual road network safety management. The algorithm is programmed
through the Dynamic Linked Database using DELPHI language, and then used to the
engineering project.
Keyword:Improved Dijkstra Algorithm;Road Network Safety Management;DLL
0 INTRODUCTIONS
In order to enhance the road traffic safety, the road supervisor frequently implements the
corresponding control measures in some unusual situations. For example, when thick fog occurs,
the highway often is closed or only uses few vehicles are allowed to pass by the police vehicle
guidance. As Chinese highway network expanded gradually, these safety operation
countermeasures not only affect the users using this facility or some road section, but also
simultaneously affect the users who plan to use this facility as well as the peripheral path user.
Therefore the implementation of safety countermeasure must simultaneously consider the
[1]
implemented road section and it’s the peripheral related road network . Road safety management
based on road network includes the road network model, solution of effective path, determination
[2][3]
. In this
of road right parameter, safety state assessment as well as shortest (safest) the way
paper, shortest (safest) routing is discussed in view of single path user.
1 CLASSICS DIJKSTRA ALGORITHM APPLICATION
Most short-path not merely points to the shortest distance in the general geography
significance, but also may expand to other measures, like safety, time, expense, capacity and so on.
Correspondingly, the shortest-path question becomes the most safety problem, the quickest way
question, the lowest expense question, the best capacity question and so on. Actually, these core
algorithms are the shortest-path algorithm.
The Dijkstra algorithm basic mentality is: Supposition each spot has a pair of marking (dj, pj),
dj is the shortest-path length from source point s to selects j (the shortest-path is zero road from the
apex to itself, which has not arched, its length is equal to zero); pj is preceding j in the same
[4][5]
.
shortest-path
The solution of the shortest-path algorithm from source s to j as follows:
(1) Initialization. Sets the source is: 1) ds= 0, ps is null; 2) All other points: di= ∞, pi=? ; 3)
Marks s, records k = s, other points set not mark.
(2) Examines all the distance direct connected from has marked k to the not mark j, and
establishment: dj = min [ dj, dk+lkj ]
In the formula, lkj is direct connection distance from k to j.
(3) Select next point. Select the smallest i from dj which has not marked: di = min [ dj, j all
1
has not marked ].Then i became one marked point in the shortest-path.
(4) Found i proceeding poinr. Found point j* direct connected point i from points which has
marked, set as proceeding point: i = j*
(5) Marked point i. If all the points have marked, then the algorithm completely exits,
otherwise, records k = i, go to (2) continue again.
Divides two kind situations, one is all nodes are the interconnection exchanges to the
connected path; as Fig. 1 shows, each way can arrived other way by this node.
Fig. 1 completely connecting node
Moreover another has the few nodes belong to incompletely connecting node in the road
network. Certainly path exchange is not completely interconnects with this node. As Fig. 2 shows.
Cannot arrive A and D from E through the intersection, similarly, A and D also are unable arrive to
E through the intersection.
E
D
A
B
C
Fig. 2 incompletely connects the node
The first situation, may directly define is adjacency matrix, and then uses the Dijkstra
algorithm solution.
The second situation, may carries on the solution from two aspects. (1) Through establishes
the virtual node and the virtual side way, incompletely will connect the node to change completely
the connecting node, and then will use the first method. (2) Establish node limited information
matrix, simultaneously considered the node limit matrix, finally obtains the reasonable
shortest-path. The solution (1) need reconstruct figure, but algorithm stand. The latter kind of
solution needs to improve to the original Dijkstra algorithm.
As Fig. 3 shows, the road networks have 7 nodes.
2
V2
3
9
V1
1
7
1
V3
3
3
4
4
V5
2
1
V4
5
V7
3
V6
Fig. 3 solution completely connecting road network demonstration
Various nodes serial number and road right the indication as Fig. 3. Road right is space length
in this example, unit as kilometer. Table 1 shows the road right between various nodes connected.
0 expressed this node itself, ∞ expressed not directly connects in two nodes.
Tab. 1 various nodes connects road right the table
V1
V2
V3
V4
V5
V1
0
9
7
3
∞
V2
9
0
1
∞
4
V3
7
1
0
3
1
V4
3
∞
3
0
1
V5
∞
4
1
1
0
V6
∞
∞
∞
5
2
V7
∞
3
∞
∞
4
Compute shortest road right from V1 to other, the results as table 2.
V6
∞
∞
∞
5
2
0
3
V7
∞
3
∞
∞
4
3
0
Tab. 2 computations sources to each shortest road right table
V7
Min
∞
0
∞
3
∞
4
8
5
8
6
8
6
8
8
The shortest-path can be obtained from source point to other, according to
shortest road right table. (For example, from V1 to others, table 3)
1
2
3
4
5
6
7
V1
0
V2
∞
9
9
8
6
V3
∞
7
6
5
V4
∞
3
V5
∞
∞
4
V6
∞
∞
8
6
6
6
P
Prev
V1
V1
V4
V4
V5
V3
V5
V2
V3
V6
V5
V7
V5
calculates the
Tab. 3 sources to each shortest-path
Destination Node
Path
Shortest Distance
V2
V1→V4→V5→V3→V2
6
V3
V1→V4→V5→V3
5
V4
V1→V4
3
V5
V1→V4→V5
4
V6
V1→V4→V5→V6
6
V7
V1→V4→V5→V7
8
Transforms the initial point, may obtain all shortest-paths between each two points.
2 ALGORITHMS IMPROVEMENTS
But if it has incompletely connects node (Fig. 3), supposition V4 cannot arrive V3 and V6
after V5, simultaneously V3 and V6 cannot arrive V4 after V5, the V5 is incompletely connecting
3
node. Then the shortest-path V1 -> V4 -> V5 -> V3 -> V2, V1 -> V4 -> V5 -> V3 and V1 -> V4
-> V5 -> V6 cannot establish in the last example. By now needed to consider other solutions or
made the improvement to the Dijkstra algorithm.
2.1 ROAD NETWORKS ANALYSIS SITUSES INFORMATION IMPROVEMENT
We still used completely connecting node algorithm. Makes the appropriate readjustment the
road network topological relations constitution. Increases the virtual node and the virtual branch
(side), the incompletely connecting node will transform for the completely connecting node.
Transformation principle: 1) does not change the topological relations between the original
node and each side connected, 2) does not change the nature (road right).
According to principle and figure nature, may obtain deduces:
Deduces one: Supposes one incompletely connects node, with it connected node is n, and its
side number also is n. If has one side e0 not to be able to connect with other sides k
( 1 ≤ k ≤ n − 2 ), simultaneously the k cannot connect e0. Then needs to increase one virtual node,
the increase virtual side number is only n-k-1.
Deduces two: If it has k sides which cannot exchange each other ( 2 ≤ k ≤ n − 1 ), Then needs
to increase the virtual nodes is k-1, the increase virtual side number is nk − k 2 − n + k .
The proof deduces one:
Supposes N = {ei
i =1, n
} is aggregate with all side which connected to the incompletely
connects node. But N 0 = {e0 , ei
i =1, k
} , if does not consider e0, then other are the completely
connects type. If only increase a virtual node, connected e0 and connected other side. The
increased virtual side number should be equal to all side in the complement aggregate of N0 .
Therefore the increase virtual points are 1, the virtual side number is n-k-1.
Fig. 3 as the example, change node V5. According to deduces one, needs to increase 1 virtual
node, and increases 2 virtual branches. After the transformation as follows shows.
V2
3
9
V1
1
7
4
4
1
V3
4
V5
V7
4
3
V5'
3
1
V4
5
2
3
V6
Fig. 4 Transformed road network
After Fig. 4 similar various nodes the transformation connects road right the table following
table. 0 expressed this node itself, ∞ expressed during two nodes not directly connects.
Tab. 4 road right with each node
V1
V2
V3
V4
V5
V5′
V1
0
9
7
3
∞
∞
V2
9
0
1
∞
4
4
V3
7
1
0
3
1
∞
V4
3
∞
3
0
∞
1
V5
∞
4
1
∞
0
∞
V5’
∞
4
∞
1
∞
0
V6
∞
∞
∞
5
2
∞
V7
∞
3
∞
∞
4
4
Compute shortest road right from V1 to other, the results as table 5.
V6
∞
∞
∞
5
2
∞
0
3
V7
∞
3
∞
∞
4
4
3
0
4
Tab. 5 computation shortest road right from origin to destination
V5′
∞
∞
4
V7
Min
∞
0
∞
3
∞
4
8
6
8
7
8
7
8
8
8
8
The shortest-path can be obtained from source point to other, according to
shortest road right table. (For example, from V1 to others, table 6)
1
2
3
4
5
6
7
8
V1
0
V2
∞
9
9
8
7
V3
∞
7
6
6
V4
∞
3
V5
∞
∞
∞
∞
7
7
V6
∞
∞
8
8
8
8
8
P
Prev
V1
V1
V4
V4
V5’
V4
V3
V2
V3
V5
V3
V6
V4
V7
V5’
calculates the
Table 6 sources to each shortest-path
Destination node
Path
Shortest distance
V2
V1→V4→V3→V2
7
V3
V1→V4→V3
6
V4
V1→V4
3
V5
V1→V4→V3→V5
7
′
′
V5
V1→V4→V5
4
V6
V1→V4→V6
8
V7
V1→V4→V5’→V7
8
Analyzes these data, V5 ' is the virtual node, it should be equates with V5, the solution is two
values after introduces the virtual node, then needed to compare with the original node, takes the
smaller. Meanwhile replace V5' with V5. Obtains final solution result as following table。
Table 7 incompletely connects a node solution result
Destination node
Path
Shortest distance
V2
V1→V4→V3→V2
7
V3
V1→V4→V3
6
V4
V1→V4
3
V5
V1→V4→V5
4
V6
V1→V4→V6
8
V7
V1→V4→V5→V7
8
Obviously, it has a bigger difference with table 3, mainly reason is the node whether
completely connect or incompletely. And value (in the road right) also had the corresponding
change.
2.2 CONSTRUCTIONS OF DATA AND INFORMATION IMPROVEMENT
If does not make the transformation to the road network topological relations, that needs
provide incompletely limit information to the algorithm procedure, and makes the corresponding
adjustment of the algorithm step.
The adjustment solution process as follows:
(1) Initialization. Sets the source point is: 1) ds= 0, ps is null; 2) All other points: di= ∞, pi=? ;
3) Marked source s, records k = s, other unmarked.
(2) Examines all the distance direct connected from has marked k to the not mark j, and
establishment: dj = min [ dj, dk+lkj ], improve this step, if k is incompletely node, also i - k - j
belongs to the limit node section, then lkj value is ∞.
(3) Select next point. Select the smallest i from dj which has not marked: di = min [ dj, j all
has not marked ].Then i became one marked point in the shortest-path.
(4) Found i proceeding poinr. Found point j* direct connected point i from points which has
marked, set as proceeding point: i = j*
(5) Marked point i. If all the points have marked, then the algorithm completely exits,
5
otherwise, records k = i, go to (2) continue again.
According to algorithm which improves, may obtain the accurate shortest-path. Still compute
Fig. 3.
The recording incompletely exchanges the node limit information,
⎡V4
⎢V
A=⎢ 4
⎢V3
⎢
⎣V6
V5 V3 ⎤
V5 V6 ⎥⎥
V5 V4 ⎥
⎥
V5 V4 ⎦
Tab. 8 road right with each node
V1
V2
V3
V4
V5
V1
0
9
7
3
∞
V2
9
0
1
∞
4
V3
7
1
0
3
1
V4
3
∞
3
0
1
V5
∞
4
1
1
0
V6
∞
∞
∞
5
2
V7
∞
3
∞
∞
4
Compute shortest road right from V1 to other, the results as table 9.
V6
∞
∞
∞
5
2
0
3
V7
∞
3
∞
∞
4
3
0
Table 9 computations sources to each shortest road right table
V1
0
V2
∞
9
9
8
7
V3
∞
7
6
6
V4
∞
3
V5
∞
∞
4
V6
∞
∞
8
8
8
8
V7
Min
P
Prev
1
∞
0
V1
V1
2
∞
3
V4
V4
3
∞
4
V5
4
8
6
V3
V4
5
8
7
V2
V3
6
8
8
V6
V4
7
8
8
V7
V5
At 4th step, , used ∞ replaces the normal road right value because the incompletely node,
thus obtains the result. The final computed result sees the next table。It is the same results.
Table 10 incompletely connects the node solution two results
Destination node
V2
V3
V4
V5
V6
V7
Path
V1→V4→V3→V2
V1→V4→V3
V1→V4
V1→V4→V5
V1→V4→V6
V1→V4→V5→V7
Shortest distance
7
6
3
4
8
8
3 ALGORITHMS PROGRAMMING REALIZATIONS
When programming the transportation control management software system, it generally
divides the work of the cooperation development not a person, even it is not a unit composes.
Therefore, the modular development or the module type development pattern often be used.
Through the Dynamic Link Library (abbreviation is DLL) or other forms may seal the commonly
used code the repetition to use other procedures, either provides to the third party user, either
serves as part in the development large software project, then all these modules organization will
translate into a complete procedure in the software project.
[6]
The DLL has more merits :
(1) Shares the code, the resources and the data. The main goal is for share the code, the DLL
code may be sharing with all Windows application procedure.
6
(2) Hides the realization detail. The DLL may be visited by the application procedure, but the
application procedure certainly does not know the detail.
(3) Develops the function of development kit like Delphi. Because DLL has nothing to do
with the language, The DLL can be created by C++, VB or any support Dynamic Link Library
language transfer.
This article used DELPHI to seal and realize the road network shortest-path algorithm with
the Dynamic Link Library, provides the foundation platform for the later development of safety
control system.
4 PROJECTS EXAMPLES
Used this algorithm procedure to the project. Because the DLL is the backstage movement,
wihtout surface. Therefore maked a calling program.
The part of the road network as following figure shows.
庵东 V1
11
V2
24
小曹娥
17
8
朗霞
V4
曹家埠
7
40
6.6
30
V6
19
V5
掌起
V7
15
6
V3
观海卫
V8
澥浦
10.5
V9 牟山
V10
肖东
22
7
前洋
5
东孙
V12
镇海 V11
39.7
21.7
V13
4.4
高桥 V14
Fig. 5 program example
The numbers in Fig. 5 nearby side are the road right value, is space length in this example.
The main interface directly loaded the road network graphical display, this graph only is just hints,
not actual meaning.
The DLL data loaded from the data file, it needs the node data file and the road section data
file before the programe run. Then the transfer algorithm procedure may obtain the result.
Some program interface as follow.
Fig 6 software input interface (node file and section file)
Fig. 6 shows the dialog which input the name and path of node file and section file. Press
“show file data” button can browse and modify the file data. Click "OK" button will enter the
main interface (Fig.7).
7
Fig. 7 Main interface with test program
In this interface, "starts node" and “termination node" locate on the right panel, including all
nodes. After selected "starts node" and” termination node", click
button in the toolbox, and
then get result as Fig 8 shows.
Fig 8 results interface
The algorithm speed is very fast in example with 24 nodes and 28 road sections. After modify
road right value, the result will be get immediately only need click “solve”. Therefore this
algorithm can satisfy apply in the road network management。
5 SUMMARY AND CONCLUSIONS
(1) Uses the classics the Dijkstra algorithm to solve the general road network shortest-path
problem.
(2) The classical Dijkstra algorithm is improved by means of these two aspects, the
incompletely connected nodes can be changed to the completely virtual connected nodes; Or by
changing algorithm data structure and data information when maintaining the existing road
network, the Dijkstra algorithm can be improved.
(3) Programed the related algorithm programe by the Dynamic Link Library with DELPHI,
convenient for later development of the safety control software system.
(4) Used the DLL in the project, the test result indicated this procedure may use to solve
shortest-path problem in the road network.
REFERENCES:
[1] Wang Wei. System analysis method on road traffic engineering[M]. Beijing: China Communication Press,2004.
[2] FAN Jun, LIU Ben min, GUO Zhong yin. Constructor Algorithm of Dumbbell Road Network for Pivotal
Infrastructure[J]. Journal of Tongji University, 2007, Vol35, No4:481
[3] Fan Jun, Zhao Yu hua, Liu Ya wen. Boundary algorithm of dumbbell road network for pivotal infrastructure[J].
Journal of Chongqing Jiaotong University, 2006, Vol25, No5:139
[4] E.W.Dijkstra.A note on two problems in connexion with graph[J].Numerische Mathematic,1959(1):269.
[5] Byers T H , Waterman M S. Determining all optimal and near-optimal solutions when solving shorte- st path
problems by Dynamic Programming [J] . Operations Rersearch ,1984 , 32 :1381.
[6] Liu Yi. Object-Oriented Programming on Delphi[M]. Beijing: China Machine Industry Press, 2003.
8