CNN-Transformer-based container truck flow prediction method and system outside wharf crossing
By using a CNN-Transformer-based prediction model, combined with data from the external truck reservation system, crossing traffic data, and GPS data, the problem of low temporal accuracy and lack of dynamic serialization of spatial features in external truck traffic prediction at container terminals has been solved. This has enabled highly fine-grained and forward-looking predictions, meeting the real-time scheduling needs of the terminal.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-26
- Publication Date
- 2026-03-27
AI Technical Summary
Existing technologies for predicting truck traffic outside container terminals suffer from low time accuracy, insufficient utilization of reservation data, and lack of dynamic serialization of spatial features, which makes it impossible to meet the actual scheduling needs of container terminals.
A CNN-Transformer-based prediction model is adopted, which combines data from the external truck reservation system, level crossing traffic data, and GPS data. Spatial features are extracted through convolutional neural networks, the Transformer architecture captures long-term dependencies in time series, and the model's understanding of time sequence is enhanced through self-attention mechanism and location encoding, thereby achieving the fusion prediction of spatiotemporal information.
It achieves high-granularity, high-foresight, and high-precision external truck flow prediction, meets the real-time production scheduling needs of the terminal, reduces prediction errors, and improves prediction reliability and resource utilization efficiency.
Smart Images

Figure CN121745397A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of intelligent container terminals, and in particular to a method and system for predicting the flow of container trucks outside the terminal level based on CNN-Transformer. Background Technology
[0002] External container trucks are container handling vehicles operating on the landside of intelligent container terminals, responsible for transporting containers at entrances and exits, and serving as a hub connecting the container terminal with the inland areas. The real-time arrival volume of external container trucks is crucial to important scheduling processes at container terminals, including yard resource allocation, integrated scheduling, and loading planning. However, their specific arrival times are significantly influenced by human factors and exhibit high uncertainty. Therefore, accurate prediction of external container truck traffic is key to improving the operational efficiency of container terminal systems and is of great research significance. Several existing technical solutions for achieving accurate prediction of external container truck traffic are as follows.
[0003] For example, Reference 1, "Prediction of Container Truck Arrival Volume at Yantian Port Based on ARMA-LSTM" (Jia Yulin, Dalian Maritime University, 2023), constructs a two-stage external container truck flow prediction system. The first stage uses a traditional Autoregressive Moving Average (ARMA) model for preliminary prediction. The second stage utilizes a Long Short-Term Memory (LSTM) neural network to predict the residual values of the first-stage model and classifies container trucks according to their operations into mixed-operation, container delivery, and container pickup categories for further prediction. However, the technical solution proposed in this reference only considers the arrival data of external container trucks and cannot reflect the impact of reservation data on the actual arrival volume. Furthermore, the precise unit of time is days, which can only serve as a long-term operational decision for the terminal and cannot meet the needs of real-time terminal resource allocation and machinery scheduling.
[0004] For example, reference 2, “Modeling Categorized Truck Arrivals at Ports: Big Data for Traffic Prediction” (Li N, Sheng H, Wang P, et al. IEEE Transactions on Intelligent Transportation Systems, 2023, 24(3): 2772-2788.), proposes an external truck traffic prediction system that combines a gated recurrent unit (GRU) and a fully convolutional neural network (FCNN) deep learning model. This system integrates new parameters affecting traffic volume, such as ship-related information, weekdays, and weather conditions, to predict external truck arrivals with daily accuracy. The proposed solution in this reference uses data beyond just external truck arrival data, incorporating potential factors affecting external truck traffic such as weather conditions and ship information. This helps the model discover causal relationships between data points. However, it still suffers from a lack of reservation system data and the prediction accuracy cannot meet actual scheduling needs.
[0005] For example, reference 3, "Actual Truck Arrival Prediction at a Container Terminal with the Truck Appointment System Based on the Long Short-term Memory and Transformer model" (Ma M, Li X, Fan H, et al. Journal of Marine Science and Engineering, 2025, 13(3): 405.), proposes an external truck traffic prediction system based on LSTM and Transformer architectures. It uses LSTM and Transformer models to capture short-term and long-term time series features, respectively, and predicts the actual truck arrival volume at the next time point based on truck reservation system data and actual arrival data. The proposed technical solution combines the advantages of LSTM in handling time dependencies with the high efficiency of Transformer's self-attention mechanism in parsing complex data contexts, and considers the crucial information from the truck reservation system. However, its prediction target is the next time point, and the prediction accuracy is 12 hours, which is difficult to meet the actual scheduling needs in terms of accuracy and foresight. As for the reservation system, it processes the reservation data into the reservation quantity of the point to be predicted, the reservation quantity of the previous two time points, and the actual arrival quantity. It only extracts the number of reserved external trucks as time series information and does not include the spatial information of external trucks.
[0006] For example, reference 4, "Research on Spatiotemporal Prediction and Real-time Assignment of External Truck Transportation Demand at Terminals" (Zhao Yanan, Dalian Maritime University, 2024), proposes an external truck transportation demand prediction system combining Graph Convolutional Network (GCN) and GRU deep learning models. It uses the start point, end point, and timestamp data of each external truck trip as time-series data, and the GPS coordinates of the start and end points as spatial data. GCN and GRU are used to capture temporal and spatial features respectively, predicting the spatiotemporal demand of external trucks within the next day, accurate to 4 hours. While this proposed solution incorporates GPS data into the external truck traffic prediction problem, introducing spatial features to some extent, the GPS data only includes the start and end points of each task, failing to reflect the real-time transportation dynamics of the external trucks. Furthermore, it does not include external truck reservation data in the model, lacking the crucial information provided by the reservation system for external truck traffic prediction.
[0007] For example, reference 5, "A Prediction Model for Truck Arrival Volume Based on Multi-Source Heterogeneous Fusion and Spatiotemporal Graph Convolutional Network" (Xue Guixiang, Chen Yuang, Liu Yu, et al. Computer Engineering and Science, 2025, 47(03): 561.), proposes a prediction model for external truck arrival volume based on a spatiotemporal graph convolutional network. This model combines multi-source heterogeneous data such as real-time truck positioning data, reservation systems, and meteorological conditions, and uses a GCN to extract spatial features from external GPS data to predict truck traffic in the next 15, 30, and 60 minutes. The proposed technical solution processes the external truck GPS data into a continuously changing graph over time, achieving dynamic capture of spatial information, and the time prediction accuracy meets real-time scheduling requirements. However, by using truck reservation information as an external feature and directly fusing it with the spatial features extracted by the GCN in the fully connected layer, it is difficult to capture time-series features. Therefore, it still fails to achieve complete extraction and utilization of both time-series and spatial features, and does not realize spatiotemporal information fusion prediction.
[0008] Chinese patent CN120297514A discloses a method, system, medium, and management method for predicting truck traffic at a crossing, applied to the field of automated container terminal technology. It dynamically adapts to the terminal operation scenario through a data modality classification model, combines a Long Short-Term Memory (LSTM) regression model and an Extreme Gradient Boosting (XGBoost) regression model for parallel prediction, and integrates the prediction results through weighted summation, thereby accurately predicting the truck traffic at the terminal crossing for each time period within a preset time period. However, this invention focuses on the classification of data modalities and the optimization of model combinations, but does not achieve the complete extraction and utilization of time series features and spatial features, and does not realize spatiotemporal information fusion prediction.
[0009] In summary, although existing technologies have integrated time-series and spatial information research methods to predict the flow of external trucks at container terminals, they still have problems such as not making full use of external truck GPS information and reservation system information. At the same time, the time accuracy and prediction step size are insufficient, which makes it impossible to meet the actual scheduling needs of container terminals and difficult to provide support for forward-looking decision-making. Summary of the Invention
[0010] The purpose of this invention is to overcome the problems of low time accuracy, insufficient utilization of reservation data, and lack of dynamic serialization of spatial features in the existing technology, and to provide a CNN-Transformer-based method and system for predicting the flow of container trucks outside the terminal level, thereby further improving the accuracy of container truck flow prediction, providing technical support for the scheduling system of intelligent terminals, optimizing the system's operating efficiency and resource utilization, and solving the need for spatiotemporal feature coordination and accurate mapping of reservation data under high-fine-grained prediction.
[0011] The objective of this invention can be achieved through the following technical solutions: A method for predicting truck traffic flow outside a terminal crossing based on CNN-Transformer, the method comprising: Data on external container trucks at the dock level is collected, preprocessed, matched, and feature-engineered to construct a spatiotemporal dataset. The spatiotemporal dataset includes time series features and spatial features. The data on external container trucks at the dock level includes data from the external container truck reservation system, dock level traffic data, and external container truck GPS data. The spatiotemporal dataset is input into a pre-trained prediction model, which outputs the predicted truck traffic flow outside the dock crossing for each hour in the next few hours. The prediction model is built based on convolutional neural networks and the Transformer architecture. When predicting the flow of container trucks outside the terminal crossing, the time series features are input into the Transformer architecture to obtain a time series feature vector, and the spatial features are input into the convolutional neural network in a dual-channel form to obtain a spatial feature vector. The time series feature vector and the spatial feature vector are concatenated dimensionally and then input into a fully connected layer to obtain the predicted value of the flow of container trucks outside the terminal crossing. The Transformer architecture captures long-term dependencies in the time series through a self-attention mechanism and adds position encoding during the capture process to enhance the model's understanding of the time sequence. The spatial features are input into the convolutional neural network in a dual-channel form to extract local and global spatial features of the location distribution of container trucks.
[0012] Furthermore, the data on container trucks outside the dock crossing includes: Data from the external truck reservation system includes: reservation initiation time, reservation arrival time, actual arrival time, and vehicle license plate number; Port crossing traffic data: The number of external trucks actually arriving at the crossing per hour; External truck GPS data: Real-time coordinate information of each external truck with second-level accuracy.
[0013] Furthermore, the preprocessing includes: Filter valid reservation data: Remove data from the external truck reservation system whose reservation initiation time is later than the reservation arrival time or the actual arrival time, and retain external truck reservation system data that conforms to logic; Filter valid GPS data: Match the reservation system with the GPS data of external trucks, retain only the GPS data of external trucks with valid reservations within the predicted time period, and exclude the GPS data of external trucks going to other ports or non-task external trucks.
[0014] Furthermore, the specific process of data matching includes: Extract the scheduled arrival time and actual arrival time of each record in the external truck reservation system data, align the hour segment of the scheduled arrival time or actual arrival time with the hour-level timestamp of the gate traffic data, establish the association mapping between the gate traffic data and the external truck reservation system data, and obtain a preliminary valid reservation dataset. Extract the list of valid license plate numbers of external vehicles and the time period to be predicted for each license plate number from the preliminary valid reservation dataset. Iterate through the GPS data of external vehicles, filter the external vehicles whose license plate numbers belong to the list of valid license plate numbers of external vehicles and whose timestamps fall within the time period to be predicted, and construct a valid GPS dataset. The preliminary valid reservation dataset and valid GPS dataset are grouped according to the license plate number, forming key-value pairs with the license plate number as the key. The GPS data key-value pairs in each group are sorted in descending order by timestamp, and the latest GPS coordinates within the predicted time period are selected. If a certain external truck has multiple GPS updates within the predicted time period, the latest coordinates are repeatedly extracted at a preset frequency. The valid reservation information of a single external truck is bound with the corresponding latest external truck GPS data to form external truck-reservation-location association data, thus completing data matching.
[0015] Furthermore, the process of constructing the time series features includes: Four prediction time intervals are preset, assuming that the reservation initiation time is a / b / c / d hours earlier than the reservation arrival time. Based on the prediction time intervals, valid external truck reservation system data within the corresponding time intervals are filtered to form time step-reservation volume correlation data. Based on the short-term, medium-term, and long-term trends of port traffic, several demand window lengths are set; using the hourly timestamp of port crossing traffic data as a benchmark, the average traffic flow is calculated by sliding the demand window lengths for each time period, and the several sliding averages for each time period together constitute the multi-scale traffic trend characteristics of that time period. The time-step-reservation volume correlation data and multi-scale traffic trend features are aligned by timestamp to construct time series features.
[0016] Furthermore, the process of constructing the spatial features includes: Using the wharf and its surrounding core transportation area as boundaries, a standardized gridded pixel map is constructed, and a mapping relationship between geographic coordinates and pixel coordinates is established. Mark the latest pixel coordinates of all valid outer cards at each prediction time step on the gridded map, with the pixel corresponding to the coordinate marked as 1 and the pixel without an outer card marked as 0, generate a binary map matrix, and store it as a .npz format file; Repeat the above construction process to generate two corresponding binary map matrices for each prediction time point.
[0017] Furthermore, the specific process of inputting time series features into the Transformer architecture to obtain time series feature vectors includes: The spatiotemporal dataset is split according to a preset prediction time step and normalized to obtain the time series input data corresponding to different prediction time steps. The prediction time step is a prediction time interval scale where the reservation initiation time is several hours earlier than the reservation arrival time. The time series input data for each prediction time step is dimensionally aligned, and its timestamp information is converted into a location encoding vector. This vector is then added element-by-element to the time series input data to obtain the location-encoded time series data. The temporal data after position encoding is input into the multi-head self-attention layer of the Transformer encoder. The multi-head self-attention layer performs a linear mapping on the input sequence to generate three matrices: Query, Key, and Value. The dot product of Query and Key is calculated and divided by a scaling factor. Attention weights are obtained through the Softmax function. The Value matrix is then weighted and summed based on the attention weights to finally output the temporal features that capture long-term dependencies. The real-time reservation volume corresponding to each prediction time step is extracted as a control vector. The dimension of the control vector is made consistent with the dimension of the temporal feature through linear transformation. The mapped control vector is then concatenated with the last time step of the temporal feature output by self-attention to obtain the temporal feature vector.
[0018] Furthermore, the specific process of inputting spatial features into the convolutional neural network in a dual-channel format to obtain spatial feature vectors includes: The spatiotemporal dataset is split according to a preset prediction time step and normalized to obtain spatial input data corresponding to different prediction time steps. The prediction time step is a prediction time interval scale where the reservation initiation time is several hours earlier than the reservation arrival time. The spatial input data corresponding to each prediction time step is input into the CNN model in a dual-channel form. The spatial input data is compressed into a fixed-dimensional vector through convolutional layers and pooling layers to capture the local clustering features and global distribution features of the outer set card position distribution. The CNN output vectors at each prediction time step are arranged in chronological order to form spatial sequence data, which is then input into the LSTM model to capture the dynamic changes of spatial features step by step, and finally output spatial feature vectors.
[0019] A CNN-Transformer-based system for predicting truck traffic flow outside a dock crossing, the system comprising: Data processing module: Collects data from external trucks at the dock level, performs preprocessing, data matching, and feature engineering to construct a spatiotemporal dataset; the spatiotemporal dataset includes time series features and spatial features; the external truck data at the dock level includes data from the external truck reservation system, dock level traffic data, and external truck GPS data; Algorithm prediction function module: Input the spatiotemporal dataset into the pre-trained prediction model and output the predicted value of the truck traffic outside the dock crossing for each hour in the next several hours; Prediction Model Pre-training Module: Constructs and pre-trains the prediction model; wherein, the prediction model is built based on a convolutional neural network and a Transformer architecture. When predicting the flow of container trucks outside the terminal crossing, the prediction model inputs time series features into the Transformer architecture to obtain a time series feature vector, inputs spatial features in a dual-channel form into the convolutional neural network to obtain a spatial feature vector, concatenates the time series feature vector and the spatial feature vector in terms of dimension, and inputs them into a fully connected layer to obtain the predicted value of the flow of container trucks outside the terminal crossing; the Transformer architecture captures long-term dependencies in the time series through a self-attention mechanism and adds position encoding during the capture process to enhance the model's understanding of the time sequence; the spatial features are input into the convolutional neural network in a dual-channel form to extract local and global spatial features of the location distribution of container trucks.
[0020] A computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the CNN-Transformer-based method for predicting truck traffic outside a dock crossing as described above.
[0021] Compared with the prior art, the beneficial effects of the present invention include: 1. This invention achieves high-granularity, high-foresight, high-precision, and comprehensive prediction of external truck traffic, taking into account spatiotemporal influencing factors and fully utilizing data features. This invention integrates spatiotemporal information, taking into account the time-series information contained in the actual arrival data of external trucks and the reservation system data, as well as the spatial information contained in the reservation system data and the GPS data of external trucks, thus achieving comprehensive consideration of spatiotemporal factors. In the prediction model of this invention, the Transformer architecture captures long-term dependencies in the time series through a self-attention mechanism and incorporates location encoding during capture, enhancing the model's understanding of the time sequence. Spatial features are input into the convolutional neural network in a dual-channel form to extract local and global spatial features of the external truck location distribution. By combining the Transformer architecture with the convolutional neural network, the prediction model of this invention significantly reduces prediction errors and enhances prediction reliability.
[0022] 2. In the data matching and feature engineering processing of this invention, in the time dimension, the effective reservation volume is screened by scale and the reservation system data is integrated. The level crossing traffic data is integrated by multi-window sliding average, which realizes the capture of traffic trends at different time scales. In the spatial dimension, the local / global structure of the real-time location distribution of external trucks is captured by GPS matrix. Combined with LSTM, the spatial features are dynamically serialized. It takes into account the temporal correlation between reservation volume and historical traffic and the spatial correlation between truck location and arrival probability, so that the prediction is more in line with the actual operation pattern of external trucks.
[0023] 3. This invention has a preset prediction step size, supports prediction at different time steps, has high time accuracy and strong adjustability, meets the time requirements of real-time production scheduling at the dock, and can also provide accurate data support for real-time decision-making such as rail gantry scheduling and adjustment of the number of open crossings, thus solving the pain point that existing technologies cannot meet short-term scheduling needs.
[0024] 4. The prediction model of this invention uses a method that combines control vectors and self-attention mechanism in the Transformer architecture to discover the inherent characteristics of the actual arrival data sequence of external trucks. It also makes full use of the one-to-one correspondence between the reservation system and different time steps, preserving the meaning of the data and making efficient use of reservation data. This solves the problem of insufficient utilization of reservation information in existing technologies. The real-time reservation volume at different time steps is used as the control vector, and through linear transformation, it is accurately mapped to the corresponding prediction time step. This not only preserves the temporal meaning of the reservation data, but also allows the model to clearly capture the direct impact of reservation information on traffic flow, making the prediction more consistent with the reservation fulfillment logic of actual terminal operations.
[0025] 5. By accurately predicting the hourly arrival volume of external trucks in the future through this invention, the terminal can plan the yard space in advance, allocate operating machinery, and make reasonable arrangements for manpower, so as to avoid idle resources or insufficient transportation capacity, reduce the waiting time of external trucks, and improve the overall operational efficiency and resource utilization efficiency of the terminal. Attached Figure Description
[0026] Figure 1 This is a flowchart of the method of the present invention; Figure 2 This is a schematic diagram of the environment for collecting level crossing traffic data, reservation data, and GPS data according to the present invention. Figure 3 This is a flowchart of the data processing of the present invention; Figure 4 This is a flowchart of the algorithm prediction process of this invention; Figure 5 This is a percentile map of prediction error in one embodiment of the present invention. Detailed Implementation
[0027] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of the present invention.
[0028] Example 1 This embodiment discloses a method for predicting truck traffic flow outside dock crossings based on CNN-Transformer. The method is as follows: Figure 1 As shown, it specifically includes: Step S1: Collect truck data outside the dock crossing, perform preprocessing, data matching, and feature engineering to construct a spatiotemporal dataset. The spatiotemporal dataset includes time series features and spatial features.
[0029] Data on container trucks outside the dock crossing includes: Data from the external truck reservation system includes: reservation initiation time, reservation arrival time, actual arrival time, and vehicle license plate number; Port crossing traffic data: The number of external trucks actually arriving at the crossing per hour; External truck GPS data: Real-time coordinate information of each external truck with second-level accuracy.
[0030] Preprocessing includes: Filter valid reservation data: Remove data from the external truck reservation system whose reservation initiation time is later than the reservation arrival time or the actual arrival time, and retain external truck reservation system data that conforms to logic; Filter valid GPS data: Match the reservation system with the GPS data of external trucks, retain only the GPS data of external trucks with valid reservations within the predicted time period, and exclude the GPS data of external trucks going to other ports or non-task external trucks.
[0031] The specific process of data matching includes: Extract the scheduled arrival time and actual arrival time of each record in the external truck reservation system data, align the hour segment of the scheduled arrival time or actual arrival time with the hour-level timestamp of the gate traffic data, establish the association mapping between the gate traffic data and the external truck reservation system data, and obtain a preliminary valid reservation dataset. Extract the list of valid license plate numbers of external vehicles and the time period to be predicted for each license plate number from the preliminary valid reservation dataset. Iterate through the GPS data of external vehicles, filter the external vehicles whose license plate numbers belong to the list of valid license plate numbers of external vehicles and whose timestamps fall within the time period to be predicted, and construct a valid GPS dataset. The preliminary valid reservation dataset and valid GPS dataset are grouped according to the license plate number, forming key-value pairs with the license plate number as the key. The GPS data key-value pairs in each group are sorted in descending order by timestamp, and the latest GPS coordinates within the predicted time period are selected. If a certain external truck has multiple GPS updates within the predicted time period, the latest coordinates are repeatedly extracted at a preset frequency. The valid reservation information of a single external truck is bound with the corresponding latest external truck GPS data to form external truck-reservation-location association data, thus completing data matching.
[0032] The process of constructing time series features includes: Four prediction time intervals are preset, assuming that the reservation initiation time is a / b / c / d hours earlier than the reservation arrival time. Based on the prediction time intervals, valid external truck reservation system data within the corresponding time intervals are filtered to form time step-reservation volume correlation data. Based on the short-term, medium-term, and long-term trends of port traffic, several demand window lengths are set; using the hourly timestamp of port crossing traffic data as a benchmark, the average traffic flow is calculated by sliding the demand window length for each time period, and several sliding averages for each time period together constitute the multi-scale traffic trend characteristics of that time period. Time series features are constructed by aligning time step-appointment volume correlation data with multi-scale traffic trend features by timestamp.
[0033] The process of constructing spatial features includes: Using the wharf and its surrounding core transportation area as boundaries, a standardized gridded pixel map is constructed, and a mapping relationship between geographic coordinates and pixel coordinates is established. Mark the latest pixel coordinates of all valid outer cards at each prediction time step on the gridded map, with the pixel corresponding to the coordinate marked as 1 and the pixel without an outer card marked as 0, generate a binary map matrix, and store it as a .npz format file; Repeat the above construction process to generate two corresponding binary map matrices for each prediction time point.
[0034] Step S2: Input the spatiotemporal dataset into the pre-trained prediction model and output the predicted truck traffic flow outside the dock crossing for each hour in the next few hours.
[0035] The prediction model is built on a convolutional neural network and a Transformer architecture. When predicting the flow of container trucks outside the terminal crossing, the model inputs time-series features into the Transformer architecture to obtain a time-series feature vector, and inputs spatial features into the convolutional neural network in a dual-channel format to obtain a spatial feature vector. The time-series feature vector and the spatial feature vector are concatenated dimensionally and then input into a fully connected layer to obtain the predicted value of the flow of container trucks outside the terminal crossing. The Transformer architecture captures long-term dependencies in the time series through a self-attention mechanism and adds position encoding during the capture process to enhance the model's understanding of the time sequence. Spatial features are input into the convolutional neural network in a dual-channel format to extract local and global spatial features of the location distribution of container trucks.
[0036] The specific process of inputting time series features into the Transformer architecture to obtain time series feature vectors includes: Split the spatiotemporal dataset according to the preset prediction time step and normalize it to obtain the time series input data corresponding to different prediction time steps. The prediction time step is the prediction time interval scale of the reservation initiation time being several hours earlier than the reservation arrival time. The temporal input data for each prediction time step is dimensionally aligned, and its timestamp information is converted into a location encoding vector. This vector is then added element-wise to the temporal input data to obtain the location-encoded temporal data. The position-encoded temporal data is input into the multi-head self-attention layer of the Transformer encoder. The multi-head self-attention layer performs a linear mapping on the input sequence, generating three matrices: Query, Key, and Value. The dot product of Query and Key is calculated and divided by a scaling factor. Attention weights are obtained through the Softmax function. The Value matrix is then weighted and summed based on the attention weights to finally output the temporal features that capture long-term dependencies. The real-time reservation volume corresponding to each prediction time step is extracted as the control vector. The dimension of the control vector is made consistent with the dimension of the temporal feature through linear transformation. The mapped control vector is then concatenated with the last time step of the temporal feature output by self-attention to obtain the temporal feature vector.
[0037] The specific process of inputting spatial features into a convolutional neural network in a dual-channel format to obtain spatial feature vectors includes: Split the spatiotemporal dataset according to the preset prediction time step and normalize it to obtain the spatial input data corresponding to different prediction time steps. The prediction time step is the prediction time interval scale of the reservation initiation time being several hours earlier than the reservation arrival time. The spatial input data corresponding to each prediction time step is input into the CNN model in a dual-channel form. The spatial input data is compressed into a fixed-dimensional vector through convolutional layers and pooling layers to capture the local clustering features and global distribution features of the outer set card position distribution. The CNN output vectors at each prediction time step are arranged in chronological order to form spatial sequence data, which is then input into the LSTM model to capture the dynamic changes of spatial features step by step, and finally output spatial feature vectors.
[0038] Specifically, the basic idea of the self-attention mechanism is: to process the input sequence A linear mapping is applied to multiple distinct representation subspaces, where attention weights are computed in parallel. The results are then concatenated and a linear transformation is used to restore the dimensionality. Let the representation subspaces be the query, key, and value matrices, respectively. , This is a scaling factor used to prevent the gradient from vanishing due to excessively large dot product results. The formula for calculating the subspace is: in, Three learnable weight matrices are randomly initialized using methods such as uniform or normal distribution. Single-head attention. The calculation formula is: in, It is a vector mapping activation function, given a matrix. Softmax performs a row-wise vector mapping on a matrix, and its calculation formula is as follows: Multi-head attention Then by repeating the above operations This is achieved through vector concatenation operations. Output implementation: The calculation for each head is as follows: in, and It is a learnable parameter matrix. Through the self-attention mechanism, the prediction model can capture the relationships between different positions in the input sequence, effectively handling long sequence dependencies.
[0039] The basic idea of control vectors is as follows: the real-time reservation volume at different time steps is used as the control vector, and a linear transformation is used to correlate and map it with each time step to be predicted in the time series. Let the time series data... ,in It refers to the batch size. It is the length of the time series. It is the feature dimension; control vector. ,in This refers to the feature dimension of the control vector. First, the control vector is processed through a linear layer. Transform into a vector with the same dimension as the time series features. : in, It is a weight matrix. The transformed control vector The last time step of the time series features Perform vector concatenation operation : The final time series feature vector is obtained. Through the control vector shown, the real-time reservation information at different time steps is effectively incorporated into the feature representation of the time series, enabling the model to clearly capture the impact of reservation information on the prediction at each time step.
[0040] The spatial features are extracted in detail using a convolutional neural network (CNN) architecture. First, the spatial dataset is read from the storage medium as a GPS matrix and input into the CNN model. The spatial features are extracted step by step through multiple convolutional layers and pooling layers to capture the local and global structure of the distribution of the truck locations. The data is then used as a time step to input into a long short-term memory network (LSTM) to serialize the spatial features, capture time series information, and finally obtain the spatial feature vector.
[0041] The convolutional neural network will read the GPS matrix from the spatial dataset. High-level spatial features are extracted progressively through multiple convolutional layers and pooling. After convolution and pooling, the feature map is represented as follows: : in, It's a convolution operation. and These are the weights and biases of the convolutional layer. (Modified activation unit) is an activation function that takes the larger of 0 and the input element; This is an average pooling operation, with the pooling window size set to... Step size is The average pooling calculation method is as follows: Global average pooling is used to compress the feature map into a fixed-size vector, and the feature vector at each time step is used as the input to an LSTM layer to capture time series information. in, It is each time step eigenvectors, Is LSTM in the first The hidden state at each time step is calculated using the following formula: Among them, the Gate of Oblivion Based on the hidden state at the previous moment and current input This determines what percentage of information should be retained for each cell's state value. It is the weight matrix of the forget gate. It is the bias vector of the forget gate. It's the sigmoid activation function. Input gate. Decide which new information to update the cell state. It is a new candidate cell state. and These are the weight matrices for the input gate and the candidate cell state, respectively. and These are the bias vectors for the input gate and the candidate cell state, respectively. It is the hyperbolic tangent activation function. This represents element-wise multiplication, ultimately occurring at the output gate. Create a hidden state As a spatial information feature vector for serialization: in, It is the weight matrix of the output gate. This is the bias vector of the output gate. Finally, the output of the temporal feature extraction submodule is a serialized spatial information feature vector.
[0042] This method fuses temporal and spatial feature vectors, utilizing both temporal and spatial information for prediction. The concatenated temporal and spatial feature vectors are then subjected to a nonlinear transformation through multiple fully connected layers to learn the mapping relationship between input and output. Finally, the output layer generates predicted external truck traffic values for various future time periods.
[0043] Furthermore, this invention employs a GPU to accelerate the training of convolutional neural networks and Transformer models, significantly reducing the time required for model training and meeting the time requirements of actual production processes. This invention comprehensively considers both temporal and spatial factors affecting the arrival volume of external container trucks. Through self-attention mechanisms, control vectors, image feature extraction, and serialization, it fully utilizes the information contained in the data to achieve highly forward-looking, fine-grained, and high-precision prediction of external container truck traffic at container terminals. This provides technical support for intelligent terminal scheduling systems, optimizing system operating efficiency and resource utilization.
[0044] Example 2 This embodiment, based on Embodiment 1 above, discloses a CNN-Transformer-based system for predicting truck traffic flow outside a dock crossing. The system includes: Data processing module: Collects data from external trucks at the dock level, performs preprocessing, data matching, and feature engineering to construct a spatiotemporal dataset; the spatiotemporal dataset includes time series features and spatial features; the external truck data at the dock level includes data from the external truck reservation system, dock level traffic data, and external truck GPS data; Algorithm prediction module: Input the spatiotemporal dataset into the pre-trained prediction model and output the predicted value of the truck traffic outside the dock crossing for each hour in the next several hours; Prediction Model Pre-training Module: Constructs and pre-trains the prediction model. The prediction model is built upon a convolutional neural network (CNN) and Transformer architecture. When predicting the flow of trucks outside the dock level, the model inputs time-series features into the Transformer architecture to obtain a time-series feature vector, and inputs spatial features in a dual-channel format into the CNN to obtain a spatial feature vector. The time-series and spatial feature vectors are concatenated dimensionally and then input into a fully connected layer to obtain the predicted flow of trucks outside the dock level. The Transformer architecture uses a self-attention mechanism to capture long-term dependencies in the time series and incorporates position encoding during the capture process to enhance the model's understanding of the time sequence. Spatial features are input into the CNN in a dual-channel format to extract local and global spatial features of the truck location distribution.
[0045] In this embodiment, data from a domestic intelligent container terminal's pre-arrangement system, level crossing traffic flow, and GPS data for two months out of the past three years were read from a storage medium. The data acquisition environment is as follows: Figure 2 As shown, external trucks operate within the road network, and their location changes over time are recorded as GPS data. These external trucks send requests to the reservation system to reach the level crossings, generating reservation system data. The level crossings record the actual number of external trucks arriving, generating traffic flow data. The level crossing traffic flow data is accurate to the hour, while the timestamps for the reservation system data and GPS data are accurate to the second.
[0046] Data processing function modules such as Figure 3 As shown, it includes two sub-modules: data cleaning and feature engineering.
[0047] The data cleaning submodule first matches the level crossing traffic dataset and the reservation system dataset according to timestamps, and then filters valid reservation data. In the reservation system, each reservation has three timestamps: reservation initiation time, reservation arrival time, and actual arrival time. Invalid reservations with initiation times later than the reservation or actual arrival time are first eliminated. Then, based on the timestamps and the external truck license plate numbers, the reservation system dataset and the external truck GPS dataset are matched to filter valid GPS data. The feature engineering submodule is divided into two parallel paths: temporal and feature-based, and spatial features. For temporal features, the valid reservation data filtered by the data cleaning submodule is further filtered and counted according to the scale of reservation initiation time being 1 / 2 / 3 / 4 hours earlier than reservation arrival time. The number of valid reservations for each time period is then calculated as the number of valid reservations for each prediction time step. For level crossing traffic data, moving averages for different window lengths (including 1 / 2 / 3 / 6 / 12 / 24 hours) are constructed to reflect the level crossing traffic trend at different time scales. In terms of spatial features, valid GPS data is further matched with the number of valid reservations to select the latest coordinates for each reserved truck within the predicted time period, with an update frequency of 30 minutes. All valid truck coordinates for the predicted time are plotted on a gridded map with dimensions of 256 pixels and stored as an .npz matrix file, with two maps corresponding to each predicted time point. Finally, the temporal and spatial features are integrated to form a spatiotemporal dataset, which is then written to a storage medium.
[0048] Algorithm prediction function module such as Figure 4 As shown, it includes two sub-modules: feature extraction and feature fusion. The feature extraction sub-module is also divided into two parallel paths: temporal features and spatial features. For temporal features, the self-attention mechanism of the Transformer architecture is used to efficiently capture the correlations in the time series data. The real-time reservation volume at different time steps is used as a control vector, which is linearly transformed and mapped to the four time steps to be predicted in the time series, precisely corresponding to each time step length to be predicted. The time series and its control vector together constitute the time series feature vector. For spatial features, the spatial dataset is first read from the storage medium as a GPS matrix. Following the standard of one time point corresponding to two maps, the data is input into a convolutional neural network model through two channels. Spatial features are extracted step by step through two convolutional layers and two pooling layers, capturing the local and global structure of the truck location distribution. The maps of the four time points to be predicted are input into a Long Short-Term Memory (LSTM) network to form a time-series spatial feature vector. The feature fusion submodule fuses and splices the temporal feature vector and spatial feature vector, and then performs a nonlinear transformation through two fully connected layers to learn the mapping relationship between the input and output. Finally, the output layer generates the predicted value of the external truck traffic for each prediction time period in the future.
[0049] Figure 5This paper demonstrates a comparison between the prediction results of the external truck traffic prediction system proposed in this invention and the average error over a 4-hour period using the Transformer architecture alone. To verify the accuracy of the prediction, the reservation system data, level crossing traffic data, and GPS data were divided into training and test sets in an 80% and 20% ratio, respectively. The training set was used to construct time series data, control features, and GPS matrices, and to train the convolutional neural network and Transformer model, while the test set was used to calculate the relative error and verify the accuracy of the prediction results.
[0050] The mean relative error (MRE) on the test set is calculated using the following formula, where Indicates the predicted value. Represents the true value. Indicates the number of samples in the test set, subscript Indicates the first One sample: Test results show that the MRE of the Transformer architecture is 15.85%, while the MRE of the proposed fusion architecture of convolutional neural network and Transformer is 12.48%, reducing the error by 21.26% and significantly improving prediction accuracy. The error percentile chart shows that samples with errors greater than 20% account for 26.48% of the total samples with the Transformer architecture, while samples with errors greater than 20% account for only 18.75% of the total samples, a reduction of 29.19% in the proportion of large error samples. This difference indicates that the spatiotemporal data fusion method proposed in this invention can control the prediction error of more than 80% of samples within 20%, significantly reducing the probability of large errors and demonstrating good robustness.
[0051] In summary, the CNN-Transformer-based external truck traffic prediction system proposed in this embodiment utilizes data from the external truck reservation system, traffic flow data at the level crossing, and GPS data. It comprehensively considers the temporal and spatial influencing factors affecting external truck traffic at container terminals, forming a complete data processing method. It achieves highly fine-grained and forward-looking predictions with a prediction step size of one hour, including four time steps, effectively meeting the actual production scheduling needs of the terminal. It employs a method that fuses control vectors and self-attention mechanisms to uncover the inherent characteristics of the actual arrival data sequence of external trucks and fully leverages the one-to-one correspondence between the reservation system and different time steps to preserve the data's meaning. It uses convolutional neural networks to extract GPS image features of external trucks and serializes them through a long short-term memory network, effectively extracting spatial information and applying it to time series prediction tasks. Therefore, this invention achieves highly fine-grained, forward-looking external truck traffic prediction that comprehensively considers spatiotemporal influencing factors and fully utilizes data features. It significantly reduces the average error and the proportion of large error samples in existing methods, providing support for terminal resource allocation and scheduling, thereby improving operational efficiency and resource utilization.
[0052] Example 3 Based on Embodiment 1, this embodiment provides an electronic device, including: one or more processors and a memory, wherein the memory stores one or more programs, the one or more programs including instructions for executing the aforementioned CNN-Transformer-based method for predicting truck traffic outside dock crossings.
[0053] At the hardware level, the electronic device includes a processor, internal bus, network interface, memory, and non-volatile memory, and may also include other hardware required for the business. The processor reads the corresponding computer program from the non-volatile memory into memory and then runs it to implement the above-mentioned CNN-Transformer-based method for predicting truck traffic outside the dock crossing. Of course, in addition to the software implementation, this invention does not exclude other implementation methods, such as logic devices or a combination of hardware and software, etc. That is to say, the execution subject of the following processing flow is not limited to individual logic units, but can also be hardware or logic devices.
[0054] Memory may include non-persistent storage in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM. Memory is an example of computer-readable media.
[0055] Computer-readable media include both permanent and non-permanent, removable and non-removable media that can store information using any method or technology. Information can be computer-readable instructions, data structures, modules of programs, or other data. Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, CD-ROM, digital versatile optical disc (DVD) or other optical storage, magnetic tape, disk storage or other magnetic storage devices, or any other non-transferable medium that can be used to store information accessible by a computing device. As defined herein, computer-readable media does not include transient computer-readable media, such as modulated data signals and carrier waves.
[0056] The above description is merely a specific embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any person skilled in the art can easily conceive of various equivalent modifications or substitutions within the technical scope disclosed in the present invention, and these modifications or substitutions should all be covered within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.
Claims
1. A method for predicting truck traffic flow outside a wharf crossing based on CNN-Transformer, characterized in that, The method includes: Data on external container trucks at the dock level is collected, preprocessed, matched, and feature-engineered to construct a spatiotemporal dataset. The spatiotemporal dataset includes time series features and spatial features. The data on external container trucks at the dock level includes data from the external container truck reservation system, dock level traffic data, and external container truck GPS data. The spatiotemporal dataset is input into a pre-trained prediction model, which outputs the predicted truck traffic flow outside the dock crossing for each hour in the next few hours. The prediction model is built based on convolutional neural networks and the Transformer architecture. When predicting the flow of container trucks outside the terminal crossing, the time series features are input into the Transformer architecture to obtain a time series feature vector, and the spatial features are input into the convolutional neural network in a dual-channel form to obtain a spatial feature vector. The time series feature vector and the spatial feature vector are concatenated dimensionally and then input into a fully connected layer to obtain the predicted value of the flow of container trucks outside the terminal crossing. The Transformer architecture captures long-term dependencies in the time series through a self-attention mechanism and adds position encoding during the capture process to enhance the model's understanding of the time sequence. The spatial features are input into the convolutional neural network in a dual-channel form to extract local and global spatial features of the location distribution of container trucks.
2. The method for predicting truck traffic flow outside a wharf crossing based on CNN-Transformer according to claim 1, characterized in that, The data on container trucks outside the wharf crossing includes: Data from the external truck reservation system includes: reservation initiation time, reservation arrival time, actual arrival time, and vehicle license plate number; Port crossing traffic data: The number of external trucks actually arriving at the crossing per hour; External truck GPS data: Real-time coordinate information of each external truck with second-level accuracy.
3. The method for predicting truck traffic flow outside a wharf crossing based on CNN-Transformer according to claim 2, characterized in that, The preprocessing includes: Filter valid reservation data: Remove data from the external truck reservation system whose reservation initiation time is later than the reservation arrival time or the actual arrival time, and retain external truck reservation system data that conforms to logic; Filter valid GPS data: Match the reservation system with the GPS data of external trucks, retain only the GPS data of external trucks with valid reservations within the predicted time period, and exclude the GPS data of external trucks going to other ports or non-task external trucks.
4. The method for predicting truck traffic flow outside a wharf crossing based on CNN-Transformer according to claim 2, characterized in that, The specific process of data matching includes: Extract the scheduled arrival time and actual arrival time of each record in the external truck reservation system data, align the hour segment of the scheduled arrival time or actual arrival time with the hour-level timestamp of the gate traffic data, establish the association mapping between the gate traffic data and the external truck reservation system data, and obtain a preliminary valid reservation dataset. Extract the list of valid license plate numbers of external vehicles and the time period to be predicted for each license plate number from the preliminary valid reservation dataset. Iterate through the GPS data of external vehicles, filter the external vehicles whose license plate numbers belong to the list of valid license plate numbers of external vehicles and whose timestamps fall within the time period to be predicted, and construct a valid GPS dataset. The preliminary valid reservation dataset and valid GPS dataset are grouped according to the license plate number, forming key-value pairs with the license plate number as the key. The GPS data key-value pairs in each group are sorted in descending order by timestamp, and the latest GPS coordinates within the predicted time period are selected. If a certain external truck has multiple GPS updates within the predicted time period, the latest coordinates are repeatedly extracted at a preset frequency. The valid reservation information of a single external truck is bound with the corresponding latest external truck GPS data to form external truck-reservation-location association data, thus completing data matching.
5. The method for predicting truck traffic flow outside a wharf crossing based on CNN-Transformer according to claim 2, characterized in that, The process of constructing the time series features includes: Four prediction time intervals are preset, assuming that the reservation initiation time is a / b / c / d hours earlier than the reservation arrival time. Based on the prediction time intervals, valid external truck reservation system data within the corresponding time intervals are filtered to form time step-reservation volume correlation data. Based on the short-term, medium-term, and long-term trends of port traffic, several demand window lengths are set; using the hourly timestamp of port crossing traffic data as a benchmark, the average traffic flow is calculated by sliding the demand window lengths for each time period, and the several sliding averages for each time period together constitute the multi-scale traffic trend characteristics of that time period. The time-step-reservation volume correlation data and multi-scale traffic trend features are aligned by timestamp to construct time series features.
6. The method for predicting truck traffic flow outside a wharf crossing based on CNN-Transformer according to claim 1, characterized in that, The process of constructing the spatial features includes: Using the wharf and its surrounding core transportation area as boundaries, a standardized gridded pixel map is constructed, and a mapping relationship between geographic coordinates and pixel coordinates is established. Mark the latest pixel coordinates of all valid outer cards at each prediction time step on the gridded map, with the pixel corresponding to the coordinate marked as 1 and the pixel without an outer card marked as 0, generate a binary map matrix, and store it as a .npz format file; Repeat the above construction process to generate two corresponding binary map matrices for each prediction time point.
7. The method for predicting truck traffic flow outside a wharf crossing based on CNN-Transformer according to claim 1, characterized in that, The specific process of inputting time series features into the Transformer architecture to obtain time series feature vectors includes: The spatiotemporal dataset is split according to a preset prediction time step and normalized to obtain the time series input data corresponding to different prediction time steps. The prediction time step is a prediction time interval scale where the reservation initiation time is several hours earlier than the reservation arrival time. The time series input data for each prediction time step is dimensionally aligned, and its timestamp information is converted into a location encoding vector. This vector is then added element-by-element to the time series input data to obtain the location-encoded time series data. The temporal data after position encoding is input into the multi-head self-attention layer of the Transformer encoder. The multi-head self-attention layer performs a linear mapping on the input sequence to generate three matrices: Query, Key, and Value. The dot product of Query and Key is calculated and divided by a scaling factor. Attention weights are obtained through the Softmax function. The Value matrix is then weighted and summed based on the attention weights to finally output the temporal features that capture long-term dependencies. The real-time reservation volume corresponding to each prediction time step is extracted as a control vector. The dimension of the control vector is made consistent with the dimension of the temporal feature through linear transformation. The mapped control vector is then concatenated with the last time step of the temporal feature output by self-attention to obtain the temporal feature vector.
8. The method for predicting truck traffic flow outside a wharf crossing based on CNN-Transformer according to claim 1, characterized in that, The specific process of inputting spatial features into the convolutional neural network in a dual-channel format to obtain spatial feature vectors includes: The spatiotemporal dataset is split according to a preset prediction time step and normalized to obtain spatial input data corresponding to different prediction time steps. The prediction time step is a prediction time interval scale where the reservation initiation time is several hours earlier than the reservation arrival time. The spatial input data corresponding to each prediction time step is input into the CNN model in a dual-channel form. The spatial input data is compressed into a fixed-dimensional vector through convolutional layers and pooling layers to capture the local clustering features and global distribution features of the outer set card position distribution. The CNN output vectors at each prediction time step are arranged in chronological order to form spatial sequence data, which is then input into the LSTM model to capture the dynamic changes of spatial features step by step, and finally output spatial feature vectors.
9. A CNN-Transformer-based system for predicting truck traffic flow outside a wharf crossing, characterized in that, The system includes: Data processing module: Collects data from external trucks at the dock level, performs preprocessing, data matching, and feature engineering to construct a spatiotemporal dataset; the spatiotemporal dataset includes time series features and spatial features; the external truck data at the dock level includes data from the external truck reservation system, dock level traffic data, and external truck GPS data; Algorithm prediction module: Input the spatiotemporal dataset into the pre-trained prediction model and output the predicted truck traffic flow outside the dock crossing for each hour in the next few hours; Prediction Model Pre-training Module: Constructs and pre-trains the prediction model; wherein, the prediction model is built based on a convolutional neural network and a Transformer architecture. When predicting the flow of container trucks outside the terminal crossing, the prediction model inputs time series features into the Transformer architecture to obtain a time series feature vector, inputs spatial features in a dual-channel form into the convolutional neural network to obtain a spatial feature vector, concatenates the time series feature vector and the spatial feature vector in terms of dimension, and inputs them into a fully connected layer to obtain the predicted value of the flow of container trucks outside the terminal crossing; the Transformer architecture captures long-term dependencies in the time series through a self-attention mechanism and adds position encoding during the capture process to enhance the model's understanding of the time sequence; the spatial features are input into the convolutional neural network in a dual-channel form to extract local and global spatial features of the location distribution of container trucks.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When executed by a processor, the computer program implements the steps of the CNN-Transformer-based method for predicting truck traffic outside a dock crossing as described in any one of claims 1-8.
Citation Information
Patent Citations
Crossing container truck flow prediction method and system, medium and crossing container truck management method
CN120297514A