Time-schedule network with constraints on arcs (TSNCA) means network with a list of pre-defined departure times for each arc. Compared to past research on finding the K shortest paths in TSNCA, the algorithm in this paper is suitable for networks having parallel arcs with the same direction between two nodes. A node label algorithm for finding the K shortest paths between two nodes is proposed. Temporal-arcs are put into the labels of nodes and arranged by ascending order. The number of temporal-arcs is limited to K in every label of node to improve the effectiveness of the algorithm. The complexity of this algorithm is , where is the maximum number of departure times from a node, is the number of arcs in network, and is the number of nodes in network. Experiments are carried out on major part of real urban mass transit network in Beijing, China. The result proves that the algorithm is effective and practical.
Since 1950s, many researchers have paid much attention to K shortest paths.1 The classical methods were proposed by Hoffman and Pavley,2 Yen,3 Eugene,4 and Katoh et al.5 Based on the classical methods, more efficient algorithms6–8 were introduced. And more constraints9–11 were considered when finding K shortest paths as well. Time windows12–15 and time schedule16–18 are two important constraints which were extensively studied in recent years.
Time window is a time period with the earliest and latest time, when a node is available for visiting.12,13 For example, time window of a traffic signal decides when the intersection can be passed through. Time schedule is a special type of time window, which assumes that a node16,17 or an arc18 has a list of departure times and the departure from that node can only happen at one of the departure times. The time-schedule constraint is common in the real world. For example, a node in a time-schedule network may be a transportation station, and an arc may be a section of a line. Finding the K shortest paths in a time-schedule network can help passengers or shippers to get the K shortest ways by bus, trains, or planes.
Time-schedule constraints can be divided into two different types: constraints on nodes and constraints on arcs. For time schedule on nodes, different lines out from the same node share the same schedule. For time schedule on arcs, different lines out from the same node can have different schedules. Comparing to time schedule on nodes, time schedule on arcs is more applicable.
Jin et al.18 proposed an algorithm for finding K shortest paths in time-schedule network with constraints on arcs (TSNCA) in 2013. In that algorithm, there is no more than one arc with same direction between two nodes (parallel arcs). In fact, it is common that there are parallel arcs in networks. For example, different bus line passing the same two stations can have different schedules. Similar case exists in railway network and aviation network. In this paper, we studied the algorithm for finding K shortest paths in TSNCA with parallel arcs.
The rest of this paper is organized as follows. The definitions and concepts are introduced in next section. Then, the processes of extending temporal-arcs and generating paths are proposed. The main steps, example and complexity analysis of the algorithm are then presented. The experiments of the algorithm are tested in the fifth section. Finally, the conclusion is drawn.
Definitions and concepts
Time-schedule network
With reference to Jin et al.,18 an example of TSNCA in this paper is shown in Figure 1. In this example, is the set of nodes and is the set of arcs. Denote N as the set of nodes and A as the set of arcs. Each arc in A has a non-negative travel time and a list of pre-specified departure times. For two nodes u and v (), is the i-th arc from u to v, where u is called start node and v is called end node. means the cost of arc . Arcs in set A are sorted in ascending order of , which means . Denote as the j-th departure time on arc and . The constraint on arc is described as [,,…,,…,], such as and in Figure 1.
Example of time-schedule network with constraint on arcs.
Similar to Jin et al.,18 s is the source node and d is the destination node. The K shortest paths between s and denote d as the first K paths from s to d in non-descending order of their arrival times.
Several concepts
Temporal-arc
For the network example in Figure 1, if we arrive at node s at time 2 and we want to go along , whose constraint is [3;(1,4,8,12)], we will need to wait at least two time units and depart at 4 and then arrive at node B at time 7. Or we can wait six time units at s and depart at time 8 and then arrive at node B at 11 along arc .
Denote a temporal-arc as the arc with arrival time. As shown in Figure 2, (7) and (11) are temporal-arcs of . To differentiate a temporal-arc from the ordinary arc, denote static-arc as the ordinary arc, such as .
Example of temporal-arcs.
Moreover, (7) is named as the nearest temporal-arc of for we cannot arrive at B before 7 along if we arrive at node s at time 2. With constraint of arrival time at s, for a specific static arc, the temporal-arcs with the first K arrival time are called K nearest temporal-arcs.
Set of scan eligible temporal-arc
Denote EA as the set of scan eligible temporal-arcs. EA is similar to the scan eligible node set19 and branches set II in Dijkstra algorithm20 for finding shortest path. Similar to Dijkstra algorithm, the elements in EA are in order of increasing cost from original node. Here, the cost is the arrival time of temporal-arc. For example, 7 is the arrival time of temporal-arc . Denote as a temporal-arc and is the arrival time of temporal-arc .
During process of finding, temporal-arcs are put into or taken out of EA. Here, we describe the status of a temporal-arc according to whether it is in. Denote as the status of temporal-arc. When equals 1, the temporal-arc is in set EA. When equals 2, the temporal-arc has been taken out of EA.
Label of node
Denote as the label of node v. A list of K first arrival temporal-arcs is stored in . The information of the j-th element in can be described as = (, ). can be expressed as . represents the status of the temporal-arc , which can be expressed as . K elements are sorted by arrival times of temporal-arcs in in ascending order.
Theorem 1 is proposed to support that the number of elements in label of node is less than K.
Theorem 1
For every node which can be reached from s, the maximum number of temporal-arcs in label of the node is K in TSNCA. These K temporal-arcs can support to finding K shortest path departing from s.
Proof
As shown in Figure 3, in TSNCA, d′ is a node on the K shortest path from s to d. If there are K temporal-arcs with K first arrival time at d′, we can construct K shortest paths from s to d′. If K shortest paths from s to d pass d′, the K shortest paths from s to d′ are enough for constructing the K shortest paths from s to d. Thus, K first arrival temporal-arcs are enough for finding K shortest paths.
Temporal-arcs for special node d′.
Assume K = 3, relationship between temporal-arcs and label of node is illustrated as Figure 4.
Relationship between temporal-arcs and label of node.
There are two static arcs, and , from s to B. We can extend nearest temporal-arcs for every static arc till to find three first arrival temporal-arcs which are stored in label of B.
Key processes of finding K shortest path
Process of generating new temporal-arcs and labeling node
Define the extending-arc as the current temporal-arc taken out from . From the end node of extending-arc, we can generate some new temporal-arcs. The extending-arc is the father of these new temporal-arcs.
During the process of generating new temporal-arcs, different methods are applied according to whether static arcs have been extended. Here, we define to describe whether has been extended. If is true, has been extended, we can get the nearest temporal-arc from the label of node v; else we must find the nearest temporal-arc according to the departure times of the .
The new temporal-arcs are inserted into the label of their end node and set when their arrival time is less than that of the existed temporal-arcs in label of their node. If the number of temporal-arcs in label of a node exceeds K, the last element needs to be removed from the label and the same temporal-arc of the last element needs to be removed from EA.
Assuming K = 3, an example of generating new temporal-arcs and labeling node is shown as Figure 5. In Figure 5(a), the extending-arc is , the nearest departure time is 7, which is obtained by comparing the arrival time with departure times in (3,7,12,16), and then the nearest temporal-arc is . Similarly, and are obtained corresponding to departure time 12 and 16, respectively. In Figure 5(b), when extending-arc is , arc has been extended, the nearest temporal-arc of is , which can be obtained from label of node d in Figure 5(a). The new temporal-arc is inserted into label of node d while temporal-arc is deleted from the label of node d. Two in label of d have different father.
Example of generating new temporal-arcs (a) and labeling node (b).
Process of generating paths
The information of K shortest paths is stored in set . is the j-th shortest path from s to v. The elements in are sorted in ascending of arrival time at node v. The detail of path contains the start node with arrival time, such as, and a list of travel information. The travel information contains the time when departing and arriving through the static arcs.
When a temporal-arc is taken out from , a new path can be generated as follows.
where means the index of its in label. means the index of the father of in its label.
The stop condition of finding is that the eligible temporal-arc set EA is null or equation (2) is satisfied.
When finding stopped, are the K shortest paths we need.
A label setting algorithm
Based on the concepts and processes stated in earlier sections, a label setting algorithm is proposed in this section.
Main steps of algorithm
Some temporary variables are used in the algorithm. Denote as the set of static arcs out from node u, as the set of succeed nodes from node u, M as a maximum value, as the first element in . is the arrival time at v after departing from u at through arc , and . Denote as whether the node u can be extended in next iteration. Denote as whether the static arc has been extended. t0 is the arrival time at node s. is the dummy arc.
The steps of the algorithm for finding the K shortest paths from s to d are as follows:
Step 1: Initialize.
Step 2: While set EA is not null, get first element from EA as extending temporal-arc and generate new path according to equation (1). If equation (2) is satisfied, return. If the end node of can be extended, go to step 3.
Step 3: According to “Process of generating new temporal-arcs and labeling node” subsection, if the static arc has not been extended, find nearest departure time after from departure times of the arc. The nearest departure time should satisfy . Then, get no more than K nearest arrival times by function . If the static arc has been extended, find the nearest arrival temporal-arc of static arc from label of node w and get no more than K elements arrival time of which is not earlier than . Here, the function getax K returns K elements to .
for each arc {
if {
,;
}
else {
;
}
}
Step 4: Denote c as the number of new elements in the label of w, as the set of all . c is no more than K. means getting the first arrival temporal-arc in . means inserting into and EA respectively with increasing order of arrival times, and deleting the (k+1)th element in and the same temporal-arc from EA. If is larger than the largest arrival times in , return false to , else return true. If c equals zero, there is no element being inserted into and return false to . Then go to step 2.
;
while c < K {
;
if
else
break;
}
if ,;
go to step 2.
Example
Table 1 shows the steps when we apply our algorithm to find the K shortest paths from s to d in the example network. Here, K = 3. The asterisk symbol (*) in the table means the element in the label is same as that in previous iteration. During iteration 4, the arrival time of temporal-arc (9) is 9, the nearest arrival time at C is 12, and nearest arrival time at d is 15. Both of the arrival times cannot bring updating at node C and d, so B cannot be extended in next iteration and b(B) equals false. Similarly, during iteration 5, the nearest arrival time at d is 16 after time 10 from node C, which cannot bring updating for the label of node d, so C cannot be extended in next iteration and b(C) equals false.
Denote |N| and |A| as the number of elements in set A and set N, respectively. The maximum number of departure times on an arc is denoted as r. According to “Main Steps of Algorithm” subsection, the complexity of algorithm is analyzed as follows:
In step 1, the nodes, static arcs and other sets are initialized. The complexity of step 1 is .
In step 2, searching is end or step 3 is called according to the conditions which first element of EA satisfied. The complexity of step 2 equals to the maximum number of elements in EA, which is K|N|.
In step 3, function is called no more than one time for each static arc in whole algorithm. The total times of calling function are no more than |A|. If is not called, the temporal-arc will be got by calling . Because the number of static arcs of all nodes is no more than , the number of static arcs at the end nodes of temporal-arcs in EA is no more than . So the times of calling are . In function , the satisfying time is found from the list of departure times. The number of departure times is no more than r, so the complexity of is . In function , the temporal-arc is found from K elements in label of a node. So the complexity of is . After or is called, function is called, which can be ignored because much simpler than and . Thus, the complexity brought by step 3 in the whole algorithm is .
In step 4, function and is called no more than K times for each temporal-arc in EA. The complexity of is , where is the number of static arcs of . The complexity brought by in the whole algorithm is . Because the number of static arcs of all node is no more than , can be converted to . The function inserts element into and EA, the complexity of which is and is equivalent to . The complexity brought by in the whole algorithm is . Thus, the complexity brought by step 4 in the whole algorithm is .
In conclusion, the whole algorithm is sum of , and . It can be simplified to .
We compared the algorithm in this paper with two classical algorithms in the past research. The algorithm in this paper is named as algorithm A. The algorithm proposed by Chen and Tang17 is named as algorithm B. The algorithm proposed by Jin et al.18 is named as algorithm C. The applicative network and complexity of these three algorithms are shown in Table 2.
Comparison of network and complexity.
Algorithm
Type of network
Complexity
Algorithm A
A time-schedule network with constrained on arcs and with parallel arcs
Algorithm B
A time-schedule network with constrained on node and without parallel arcs
L means the number of nodes in the path
Algorithm C
A time-schedule network with constrained on arcs, and without parallel arcs
η is the maximum in-degree of a node.
As shown in Table 2, algorithm A can handle more complex network than the other two. When , algorithm A is better than Algorithm C for same network. This inequality can be satisfied easily when K is small and r is large.
Experiments
The algorithm developed in this paper was tested on major part of urban mass transit network in Beijing, China, which are shown as Figure 6. In the test network, there are 275 stations, 16 bidirectional lines, 1 pair parallel arcs, and 130,779 departure times.
Part of urban mass transit network in Beijing.
Algorithms are programmed by JAVA language. Experiments are tested on a personal computer with an Intel Core i5, 2.50 GHz CPU and 4 GB RAM. The value of K is changed in different experiments, when finding K shortest paths for each station to other stations. The value of K, the time used and the number of paths are shown in Table 3, where = 521, = 275 and r = 586.
Result of experiments.
Value of K
Time used (s)
Number of paths
1
24
75,260
2
46
150,520
3
83
225,780
4
118
301,040
5
145
376,300
10
401
752,600
20
1146
1,505,200
30
2142
2,257,800
40
3238
3,010,400
50
4949
3,763,000
Conclusions
This paper proposed a new algorithm for finding the K shortest paths in a TSNCA with parallel arcs. It brought up the concept temporal-arc and proposed a label setting algorithm with the key steps. The complexity of this algorithm is , which is better than the past research when the K is small and r is large. Moreover, it is suitable when there are parallel arcs in network. Experiments are carried out on real urban mass transit network in Beijing, China. The result proves the algorithm is effective and practical.
Footnotes
Declaration of conflicting interests
The author(s) declared no potential conflicts of interest with respect to the research,authorship,and/or publication of this article.
Funding
The author(s) disclosed receipt of the following financial support for the research,authorship,and/or publication of this article: The work was supported by National Key Technology Research and Development Program (2014BAG01B04) from the Ministry of Science and Technology of the People’s Republic.
References
1.
Brander AW and Sinclair MC. A comparative study of k-shortest path algorithms. Performance Engineering of Computer and Telecommunications Systems. London: Springer, 1997, pp. 370–379.
2.
HoffmanWPavleyR. A method for the solution of the Nth best path problem. J Assoc Comput Mach1959; 6: 506–514.
3.
YenJY. Finding the k shortest loopless paths in a network. Manag Sci1971; 17: 712–716.
4.
EugeneL. Lawler a procedure for computing the K best solutions to discrete optimization problems and its application to the shortest path problem. Manag Sci1972; 18: 401–405.
5.
KatohNIbarakiTMineH. An efficient algorithm for k shortest simple paths. Networks1982; 12: 411–427.
6.
MartinsE. An algorithm for ranking paths that may contain cycles. Eur J Oper Res1984; 18: 123–130.
7.
GotthilfZLewensteinM. Improved algorithms for the k simple shortest paths and the replacement paths problems. Informat Process Lett2009; 109: 352–355.
8.
Sedeno-NodaA. An efficient time and space K point-to-point shortest simple paths algorithm. Appl Math Comput2012; 218: 10244–10257.
9.
ChenYLTangK. Minimum time paths in a network with mixed time constraints. Comput Oper Res1998; 25: 793–805.
10.
van der ZijppNJFiorenzo CatalanoS. Path enumeration by finding the constrained K-shortest paths. Transport Res B2005; 39: 545–563.
11.
XuWHeSSongR. Finding the K shortest paths in a schedule-based transit network. Comput Oper Res2012; 39: 1812–1826.
12.
ChenYLYangHH. Finding the first K shortest paths in a time-window network. Comput Oper Res2004; 31: 499–513.
13.
YangHHChenYL. Finding K shortest looping paths in a traffic-light network. Comput Oper Res2005; 32: 571–581.
14.
YangH-HChenY-L. Finding K shortest looping paths with waiting time in a time–window network. Appl Math Modell2006; 30: 458–465.
15.
AndroutsopoulosKNZografosKG. Solving the k-shortest path problem with time windows in a time varying network. Oper Res Lett2008; 36: 692–695.
16.
ChenYLRinksDTangK. The first k minimum cost paths in a time-schedule network. J Oper Res Soc2001; 52: 102–108.
17.
ChenYLTangK. Finding the kth shortest path in a time-schedule network. Naval Res Logist2005; 52: 93–102.
18.
JinWChenSJiangH. Finding the K shortest paths in a time-schedule network with constraints on arcs. Comput Oper Res2013; 40: 2975–2982.
19.
FuaLSunbDRilettcLR. Heuristic shortest path algorithms for transportation applications: state of the art. Comput Oper Res2006; 33: 3324–3343.
20.
DijkstraEW. A note on two problems in connection with graphs. Numer Math1959; 1: 269–271.