Research on Phase Combination and Signal Timing Based on Improved K-Medoids Algorithm for Intersection Signal Control

Aiming at the problem of intersection signal control, a method of traffic phase combination and signal timing optimization based on the improved K-medoids algorithm is proposed. Firstly, the improvement of the traditional K-medoids algorithm embodies in two aspects, namely, the selection of the initial medoids and the parameter k, which will be applied to the cluster analysis of historical saturation data. The algorithm determines the initial medoids based on a set of probabilities calculated from the distance and determines the number of clusters k based on an exponential function, weight adjustment, and elbow ideas. Secondly, a phase combination model is established based on the saturation and green split data, and the signal timing is optimized through a bilevel programming model. Finally, the algorithm is evaluated over a certain intersection in Hangzhou, and results show that this algorithm can reduce the average vehicle delay and queue length and improve the traffic capacity of the intersection in the peak hour.


Introduction
With the rapid development of urban construction and socioeconomy, traffic congestion, one of China's urban diseases, not only brings tremendous pressure to urban traffic management but also seriously affects the harmonious development of cities. Many modern transportation facilities and applications can benefit from better performance of signal timing schemes [1][2][3][4]. For example, space-time road resources can be allocated more reasonably, the accuracy of traffic speed prediction can be improved [2], and the optimized signal cycle time and green split scheme can help make better-coordinated control [4]. In [5,6], the authors studied the application of mobile crowdsourcing (MCS) in smart cities. In [7,8], the authors integrate geographic and temporal influences into points of interest (POI) recommendations to help people find points of interest.
In recent years, several algorithms have been presented in the literature for traffic signal phase combination and timing optimization. In [9], the authors studied the dynamic prediction traffic signal control framework for a single intersection and optimized the signal timing according to the predicted arrival flow. In [10], a queuing and dissipation model of the intersection traffic flow was presented, which provided a theoretical basis for optimizing the intersection phase and timing. In [11], the authors considered an adaptive traffic signal control method based on fuzzy logic. This method optimized the phase duration and phase sequence. The results showed that the average queue length, the maximum queue length, and the parking rate were significantly shortened, but only lower queue lengths were considered. In [12], fog calculation was used to process traffic data, and a phase combination method based on a genetic algorithm was presented. The authors in [13] studied dynamic programming algorithms to optimize signal timing and phase, thereby, reducing average vehicle latency. In [14], the Artificial Bee Colony algorithm was adopted to optimize the signal cycle time and the green split, reducing the average vehicle delay and the average queue length, but the algorithm needed to obtain the vehicle speed online and calculate it. In [15], the authors considered a dynamic phase control method based on traffic flow, but it needed real-time detection and calculation of road conditions, resulting in poor practical application effect. In [16], the clustering algorithm was applied to process vehicle motion information, which was the basis for subsequent optimization, but only optimized the signal timing, excluding phase combination. In [17], a traffic signal segmentation algorithm based on the two-dimensional clustering was presented. It matched the best timing scheme for the current traffic conditions through the clustering analysis. However, the intersection traffic flow model cannot distinguish between a left turn and straight vehicles.
In [18], the authors studied the interval data-based K-means clustering method, and the clustering results can accurately describe the trend of traffic state evolution at an urban intersection. In [19], the K-means clustering algorithm was used to group traffic flows and divide the traffic condition level and provides a theoretical basis for matching the most suitable traffic signal control scheme in different situations. In [20], the author studies a dynamic traffic control method that predicts congestion by the clustering thought. In [21], a traffic signal control method based on the K-means clustering algorithm was presented, and the number of clusters was defined as two. The authors in [22] studied the improved affinity propagation (AP) clustering algorithm, which provided efficient and accurate traffic state information for traffic signal control. The average waiting time was effectively reduced. In [23], the authors studied the K-means clustering method to optimize the best switching time of time-of-day (TOD) control scheme, but the number of clusters needed to be specified in advance, which largely affected the effectiveness of the method. Similarly, the authors in [24] used the Kohonen cluster and K-means cluster to optimize TOD breakpoints and proved that K-means had a better performance. However, it was still necessary to specify the number of clusters and the initial cluster centers in advance, which was easy to fall into local optimum.
The existing researches mainly have the following shortcomings: (1) the intersection traffic flow model is established without considering all of the flow directions (2) the practical value of online data acquisition and frequent signal switching solutions is not high (3) the number of clusters depends heavily on prior or empirical knowledge To solve the problems above, this paper proposes a traffic phase combination and signal timing optimization method based on the improved K-medoids algorithm. Firstly, the improved K-medoids algorithm is used to cluster the historical saturation data, which can select the number of schemes k more quickly and accurately. Then, the phase combination model is established since K-medoids correspond to k pairs of saturation and green split data, which can combine the flow direction with similar traffic demand to improve the utilization of green time. Finally, the bilevel programming model is used to optimize the signal cycle time and green split of each phase, so that the timing scheme can be further optimized based on the phase combination. After clustering, each medoid composing a scheme library corresponds to a traffic scheme. In experiments, we choose an appropriate traffic scheme according to the Euclidean distance between the actual traffic saturation and medoids.
The paper is organized as follows: Section 2 introduces the traditional K-medoids clustering algorithm and its improvement. Section 3 designs the phase combination and signal timing optimization algorithm. Section 4 provides experimental results and comparisons with the traditional K-medoids algorithm. Section 5 provides conclusions and describes directions for future research.

Improved K-Medoids Algorithm
In this section, we first introduce the traditional k-medoids algorithm, then, to find better initial medoids and the appropriate parameter k, an improvement is introduced. Finally, we apply the improved k-medoids algorithm to the traffic saturation dataset into k clusters, and each cluster corresponds to one set of traffic scheme.

Traditional K-Medoids Algorithm.
Clustering is an unsupervised learning algorithm that partitions the origin data into several clusters, where the data in the same cluster are similar to each other but different from the data in other clusters. K-medoids algorithm is a partition-based clustering algorithm. Compared with K-means clustering, it is less sensitive to outliers. Among many k-medoids algorithms, partitioning around medoids (PAM) is one of the most classical and powerful [25].
K-medoids algorithm first randomly selects k representative data points as the initial medoids, each medoid corresponds to one cluster. Secondly, Euclidean distance is applied to calculate the distance between all data and the chosen medoid, each data point will be assigned to the most similar medoid. Thirdly, such a new medoid in each cluster is found to minimize the criterion function within the cluster. The algorithm will stop until all of the medoids are equal to the previous ones, otherwise, assign each data to the nearest medoid and generate k new clusters. The Euclidean distance d ðx i ,y i Þ is used to measure the similarity between all of the data points and the medoids, which can be calculated as follows: where x i and y i are both n-dimensional data objects.
The criterion function in within-cluster can be calculated as: where B i is the cluster after clustering, b j is the data point in the cluster B i , and c i is the medoid of the cluster B i .

Wireless Communications and Mobile Computing
The criterion function is described as follows: where k is the number of clusters.
2.2. The Improvement of K-Medoids Algorithm. For the K-medoids clustering algorithm, the number of clusters and the initialization have a great influence on the clustering process and results. In [26], a density peak clustering algorithm is proposed. This algorithm can select medoids and confirm the correct number of clusters. In [27], the author studied the K-medoids clustering algorithm based on a subset of candidate medoids and gradually increasing the number of clusters, thereby, improving the clustering performance of the algorithm. In order to reduce the negative impact when the initial medoids have a low dispersion degree, this paper proposes an initial point probability selection method based on the Euclidean distance. In addition, in order to reduce the artificial dependence for selecting initial medoids and avoid the excessive gap between each cluster, this paper proposes an optimization for selecting an optimal parameter k based on exponential function, weight adjustment, and elbow idea.

Improved Method for Selecting Initial Medoids.
After selecting a point in sample data as the first medoid c 1 randomly, the Euclidean distance d ðb h ,c i Þ is applied to calculate the distance between each point b h and the nearest medoid c i , and the probability p h that point b h will be selected as the next cluster medoid can be calculated as: where B is the dataset, and the probability set P can be obtained as follows: where n is the number of samples in the dataset. The roulette wheel method is used to select the cluster medoid c i ði ≥ 2Þ (see Figure 1): Step 1. We generate a random number r between ½0, 1Þ, if r belongs to the interval ½p 1 + p 2 +⋯+p i−1 , p 1 + p 2 +⋯+p i−1 + p i Þ in P, point b i will be the second cluster medoid c 2 .
Step 2. We recalculate the probabilities that each point in the dataset will be selected as the next medoid.
Step 3. We select the next medoid according to the probability set P and the roulette wheel method.
The steps mentioned above will be repeated until k centers are selected. The purpose is to make the initial medoids more discrete, which are closer to the real cluster centers.
The number of iterations can be reduced, but settle the problem of trapping in a local optimum.

Improved Method for Selecting the Number of Clusters.
The traditional criterion function in each cluster is the sum of all data within the cluster, which will make a big difference among clusters, and the classification will also be uneven. To settle the problem, this paper uses the exponential function e x to optimize the criterion function calculation method. The criterion function in within-cluster can be calculated as: In order to avoid exponential explosion, the weight coefficient t is employed, and the criterion function S can be calculated as follows: With the optimization, the criterion function S can be calculated for different k. Following the increasement of parameter k, S will decrease. According to the elbow idea, S drops dramatically at the beginning, then, S reaches an elbow, finally, the curve of S turns to a plateau. The value k corresponding to the elbow is regarded as the optimal number of clusters.

Clustering with Saturation Data.
Traffic saturation data is a collection of saturation at intersections, a single piece of data can be described as: where n is the number of intersections.
The improved K-medoids algorithm described in Section 2.2 is then applied to the traffic saturation data, which divides the data into k clusters, and the initial cluster medoids are selected according to the distance probability p h . The phase and timing optimization can be performed according to the cluster medoids, and each cluster corresponds to one set of 3 Wireless Communications and Mobile Computing traffic scheme, which means there will be k sets of initial traffic schemes.

Phase Combination and Signal Timing
In order to improve the adaptability of the traffic schemes for maching different traffic conditions, we establish the phase combination model and optimize the signal timing using the bilevel programming model. Two traffic flows are conflicting if there is a collision point of the vehicle travel path in these two directions. For example, the traffic flow in the east-west direction and the south-north direction are conflict, while the traffic flow in the east-west direction and the west-east direction are compatible. The conflict matrix can be constructed as follows: where φ ij indicates whether the flow direction and j is conflict. If not, the value is 0, otherwise, 1.
The distance matrix is used to represent the difference between traffic flows, which can be constructed based on the saturation of flow directions, green signal split data, and the conflict matrix: where the element d ij in the matrix can be calculated as follows: where y i is the traffic flow ratio of the flow direction i, which reflecting the traffic demand not affected by the signal control scheme. x i is the saturation of the flow direction i, and λ i is the initial green split of the flow direction i.
Since the distance between the flow direction i and j is the same as the distance between the flow direction j and i, the distance matrix is symmetric, that is, d ij = d ji . To ensure the balance of traffic flows in each phase, we optimize the phase combination according to the distance matrix between flow directions to make the combination more rational. For a typical crossroad, four-phase schemes are usually used, each phase consists of two flow directions, and the same flow direction traffic must be released only once in one cycle. Considering the symmetry of the distance matrix and all-zero values on the main diagonal, only the lower triangle needs to be processed. Algorithm 1 shows the optimization of the phase combination. If the distance between two flows is equal to or greater than 1, these two flows are physically conflicting. Hence, we select all the flow pairs with their distances less than 1 to form the D first vector. If one scheme in the D first contains all flow direction and each direction c i only appears once, it will be saved as D each to D all . Then, we calculate the sum of the distances in D each and insert it into the S all as S each , and the index z of the minimum S min in S all is selected. Finally, we choose the optimal scheme D final according to z in D all .
For example, there are two schemes here (see Figure 2): Scheme A takes east left movement and east through movement as one phase, west left movement and west through movement as another phase. Scheme B takes east left movement and west left movement as one phase, east through movement and west through movement as another phase, the distances of above four combinations are 0.2, 0.1, 0.3, and 0.4, respectively. The scheme A is chosen because the sum of the first two values is smaller than that of the last two values.

Input:
The distance matrix D Output: The final phase combination scheme D f inal Begin 1. for i = 1 to n, do 2, For j = 1 to ði − 1Þ, do 3.
If d ij < 1 Then 4.  Wireless Communications and Mobile Computing

Traffic Signal Timing Bi-Level Programming
Model. The bilevel programming model is a system optimization model with a two-tier hierarchical structure. The upper and lower levels have their own objective functions and constraints [28,29]. The objective functions and constraints of the upper-level problem are not only related to the upper decision variables but also depending on the optimal solution of the lower level problem, while the optimal solution of the lower level problem is affected by the upper decision variables.
We establish a traffic signal timing optimization algorithm based on the bilevel programming model. The framework of the traffic signal timing optimization algorithm is shown in Figure 3.

Establishment of the Bilevel Programming
Model. The signal cycle time is the key control parameter that determines the quality of traffic signal control in traffic signal timing, and the saturation can reflect the rationality of the signal cycle time to some extent. We establish the upper-level programming model with saturation as the decision target, which can be calculated as: where x À is the average saturation of each phase, andx is the target average saturation.
Under the condition of fixed signal cycle time constraints, the mean square error (MSE) of the saturation is used to evaluate the rationality of green split distribution. With the MSE, the lower-level programming model can be established as: where N is the number of signal phases. The saturation of each phase can be calculated as: where f i is the arrival traffic flow for phase i, q i is the average of each flow direction saturated flow in phase i, and λ i is the initial green split of phase i.

Solution of the Bilevel Programming
Model. The singlestep action set with signal cycle time changes is designed to obtain the optimal signal cycle time of the upper-level programming model, the action set can be expressed as follows: where a 1 , in seconds, is the adjustment step size for cycle time.
The three elements in action1 represent three operations, including addition, subtraction and invariance, respectively. For example, if the initial signal cycle time is T, the action1 is ½a 1 ,−a 1 , 0, and the signal cycle time after each adjustment according to action1 will be ½T + a 1 , T − a 1 , T.
Algorithm 3 shows the process for green split optimization. Considered the premise of the green split optimization algorithm that the signal cycle time is fixed, the sum of all elements in the action matrix is zero. According to the initial scheme of green split, the initial timing scheme is obtained by multiplying the signal cycle time. Each action of Equation (16) is executed, respectively, and then σ value of the corresponding action can be saved into σ all according to Equation  (13) and (14). Then we select the minimum σ min in σ all , if its corresponding action is not ½0, 0, 0, 0, the action will be taken, and the green timing scheme after execution is updated as the initial scheme g 0 for the next iteration. The algorithm will loop until the action corresponding to σ min is ½0, 0, 0, 0, and the green time of each signal phase at this time is converted into green split, and the optimal green split scheme λ f is output.
We complete the green split optimization in the lowerlevel programming model, which will be fed back to the upper level. While in the upper level, the signal cycle time is optimized heuristically and iteratively under the restriction Optimize the signal cycle time Optimize the green split of each signal phase e scheme is optimal or the cycle has reached the upper limit?
Take the current timing scheme as the initial scheme Output the current timing scheme Input the initial timing scheme Yes No Figure 3: The framework of the traffic signal timing optimization algorithm.

Input:
The initial signal cycle time T 0 , the average arrival traffic flow for each phase f = ½ f 1 , f 2 ,⋯,f n , the average of each flow direction saturated flow in each phase q = ½q 1 , q 2 ,⋯,q n , the initial green split of each phase λ = ½λ 1 , λ 2 ,⋯,λ n and the action set action1 Output: The optimal signal cycle time T f Begin 1. w 0 ⟵ The index of 0 in action1 ; 2. w ⟵ A number! = w 0 ; 3. While w! = w 0 , do 4.
For each a i in action1, do 5.
For each TN i in TNow, do 9.
w ⟵ The index of J min in J all ; 13.
End If

End While End
Algorithm 2: Signal cycle time optimization. 6 Wireless Communications and Mobile Computing of the green split, until the scheme is optimal or the cycle reaches the upper limit. According to the traffic laws and regulations in our country, the right turn movement can pass the intersection at any time without being controlled by the signal light; thus, only the left turn and the straight vehicles are considered in the simulation. Figure 5 shows the simulation structure of the intersection.

Simulation Experiment and Result Analysis
The traffic flow data were provided by the traffic control department of Xiaoshan District, Hangzhou, from 7 : 00 a.m. to 9 : 00 a.m. on November 20th, 2018. The original data was the traffic flow data of the signal cycle time and the timing scheme of the corresponding time, which was processed into saturation data set for clustering, and then, timing
For each a i in action2, do 7.
End     Table 1, which has been converted into the hourly traffic flow to the inlet, and the through flow of each flow direction is also recorded. In this table, "E, " "S," "W," and "N" refer to eastbound, southbound, westbound, and northbound, respectively. "L" and "S" mean left turn and straight vehicles. For example, "LE" represents the traffic flow of the left turn in the eastbound movement.
The signal timing scheme generated by the improved K-medoids clustering algorithm is compared with the scheme generated by the traditional one to ensure the fairness of the experiment. In order to avoid the exponential explosion and make the criterion function E and S be in the same order of magnitude, the weight coefficient t is set as 11000. Additionally, we set the target average saturation δ x to 70 according to the actual intersection traffic demand. In order to avoid missing the optimal timing scheme due to overlarge step size, the signal cycle time adjustment step a 1 and the green time adjustment step a 2 are both set as 1.
In addition, the proposed algorithm is compared to the fixed phase scheme and the traffic flow and vector angle based on the optimization scheme [17].

Analysis of Results.
The criterion functions of different k using traditional and improved K-medoids algorithm are shown, expressed by E and S, respectively. As k increases, the criterion functions decrease, and the rate of decline also stabilizes. In both cases, the optimal k is 3, while using the  Time  LE  SE  LS  SS  LW  SW  LN  SN   7 : 00  128  242  168  476  92  186  266  368  7 : 30  202  364  150  980  96  198  320  798  8 : 00  124  240  184  758  88  164  238  662  8 : 30  138  275  143  752  98  150  282  760  9 : 00  118  220  186  576  102  148  224  448  Saturation flow  1529  1641  1347  2360  1286  1606  1722 Figure 6 shows the curves of both algorithms, which is more intuitive. Table 2 shows the different performances of the traditional and improved K-medoids algorithm. As for the number of clusters, in different iterations, the traditional K-medoids may reach the elbow when k is in range of 3 and 6, which is ambiguous to identify, while the improved K-medoids can   always reach the elbow when k = 3. In addition, the improved K-medoids runs faster than the traditional version, and that may because we optimize the selection of initial optimizing, which reduces the number of interactions.
Average vehicle delay and average queue length are used to evaluate the performance of the proposed algorithm. Figures 7 and 8 show the curves of optimized phase and timing schemes under different conditions compared to fixed schemes that optimize only timing and vector angle-based schemes. The outperformance of our proposed method can be seen in all time periods. Table 3 shows the averaged values of the above two evaluation indexes, we can see that the proposed method outperforms the fixed phase method with improvements of 2.462 s (7.07%), and 1.542 m (11.38%) on the vehicle delay and the queue length, and also shows improvements of 3.924 s (10.81%) and 1.656 m (12.16%) compared to the traffic flow and vector angle-based optimization scheme. Table 4 shows the delay comparison of three optimization schemes in SS, SW, and LE. We can see that the method proposed by us has a great improvement on the average vehicle delays in each flow direction compared to the traffic flow and vector angle-based optimization scheme. In our proposed method, the average vehicle delays of SW and LE is different from that of the fixed phase method, this is because the phase of SW and LE has changed. Compared with the fixed phase method, the average vehicle delays of LE in our method are reduced, but the average vehicle delays of SW are increased. The main reason is that our method improves the overall traffic capacity of the intersection rather than the single flow direction.

Conclusions
In this paper, we optimize the traditional K-medoids clustering algorithm in terms of the clustering number and initial medoids selection. In order to match the changes of traffic flow in different time periods adaptively, the phase combination optimization model is established to optimize the phase, and the bilevel programming model aims to optimize the signal timing, which can maximize the utilization of green time. The proposed algorithm is optimized for each flow direction. Whereas the flow saturation may be different when the overall situation is similar, we will study the difference of different flow saturation to achieve the optimal control effect of the intersection.

Conflicts of Interest
The authors declare that there is no conflict of interest regarding the publication of this paper.