Port storage yard container storage time prediction method and device based on self-attention mechanism

By employing a prediction method based on self-attention mechanisms, and utilizing grey relational analysis and multi-head self-attention networks, the accuracy and generalization issues of container storage time prediction in port yards were resolved, resulting in more efficient port operations.

CN121786783APending Publication Date: 2026-04-03ZHEJIANG UNIV OF TECH
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-12-24
Publication Date
2026-04-03

AI Technical Summary

Technical Problem

Existing technologies have low prediction accuracy and insufficient generalization ability in predicting container storage time in port yards, making it difficult to meet the needs of practical engineering applications.

Method used

A prediction method based on self-attention mechanism is adopted. Feature variables are selected through grey relational analysis. Multi-head self-attention network and fully connected network are combined to establish the correlation and dependency between variables. A loss function is designed to ensure the monotonic consistency of the prediction results.

Benefits of technology

It improves the accuracy and robustness of container storage time prediction, reduces container turnover rate and secondary transshipment risk in the yard, and enhances port operation efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121786783A_ABST
    Figure CN121786783A_ABST
Patent Text Reader

Abstract

The invention relates to a port storage yard container storage time prediction method and device based on a self-attention mechanism, and the method comprises the steps: calculating the correlation degree between each characteristic variable and the storage time through gray correlation degree analysis; feature variables with high correlation are screened out based on the correlation degree to serve as prediction input, a complex dependency relationship and long program column features among modeling variables of the multi-head self-attention network are introduced, nonlinear mapping and fitting are achieved in combination with a full-connection network, and therefore the accuracy of a prediction result is effectively improved; in the model training process, a loss function with measurement monotonous consistency is designed, a constraint model keeps monotonous sequence consistency of output results on the premise that prediction precision is not lost, and the container turnover and secondary transfer risks caused by prediction sequence deviation in storage yard operation are reduced. And the model prediction performance is comprehensively evaluated from two dimensions of prediction precision and monotone consistency. According to the method, prediction precision and application practicability are both considered, and reliable time information can be provided for storage optimization of the container in the storage yard.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of container storage time prediction in port yards, and more specifically, to a method and apparatus for predicting container storage time in port yards based on a self-attention mechanism. Background Technology

[0002] Predicting container storage time in port yards provides a time reference for container storage planning. Effective prediction of container storage time can significantly improve the efficiency of container storage planning and reduce secondary transshipment and handling operations. This is of great practical significance for improving the utilization rate of yard space resources and reducing operating costs and resource consumption. Therefore, researching a prediction method that can accurately predict container storage time is particularly important for space resource planning in container port yards and improving the quality of port operation services.

[0003] Currently, research on methods for predicting container storage time in port yards is relatively limited, primarily relying on statistical models and traditional machine learning methods. Statistical prediction methods analyze historical data using statistical models and predict future container storage times through linear fitting. However, these methods have limitations. First, they primarily consider single historical data points as model inputs, failing to establish the relationship between container storage time and yard handling equipment, transportation equipment, and transportation methods. Second, actual container storage time varies non-linearly, making it difficult for conventional linear models to accurately depict the evolution of storage time trends, resulting in underfitting. Due to these factors, statistical model-based prediction methods lack sufficient accuracy and fail to meet the needs of practical engineering applications. In contrast, traditional machine learning algorithms consider feature variables such as historical storage time, container status, handling equipment status, and transportation equipment status, predicting future container storage times based on multi-feature variable inputs. However, due to their relatively simple model structure and insufficient representation of complex features, they struggle to accurately characterize the correlations and dependencies between multiple variables, leading to poor model generalization performance and unsatisfactory prediction results. The method proposed in this invention is based on a self-attention network to construct the correlation and dependency between various feature variables, extract the coupling correlation information in the variable features, and realize the accurate prediction of container storage time. Summary of the Invention

[0004] To address the shortcomings of existing methods, such as low prediction accuracy and insufficient generalization ability, which make it difficult to meet the needs of practical engineering applications, this invention proposes a method and device for predicting container storage time in port yards based on a self-attention mechanism. This method is beneficial for improving container storage planning in yards, effectively reducing secondary transshipment of containers in yards, and lowering container turnover rate.

[0005] The present invention provides a method for predicting container storage time in port yards based on a self-attention mechanism, comprising the following steps: Step S1: Collect sample data of characteristic variables that affect the storage time of containers in the port yard, preprocess the data to obtain a sample dataset, and divide the sample dataset into training set, validation set and test set according to the set ratio; Step S2: Build a prediction network based on Transformer units and fully connected layers; the structure of the prediction network is as follows: starting from the input layer, three Transformer units, a fully connected network layer, and an output layer are connected in sequence; The Transformer unit includes a multi-head self-attention module and a feedforward fully connected layer. The multi-head self-attention module is used to learn the potential correlation features between related variables in historical data. The feedforward fully connected layer is used for further nonlinear mapping and feature fusion. The fully connected network layer is used to establish a multidimensional mapping relationship between fused features and storage time. The output of this layer is a one-dimensional vector containing only storage time, realizing the prediction of the storage time of containers in the yard. The output layer is used to output the predicted storage time of the container corresponding to the input features. Step S3: Input the training set into the prediction network for training to obtain the trained prediction model; and use the validation set to validate the trained model to obtain the final prediction model; design a loss function based on mean squared error and result monotonic consistency measure to constrain model training, construct ranking pairs for samples in the same batch, and output prediction results with high monotonic consistency by calculating the ranking consistency difference between the predicted ranking pairs and the input sample ranking pairs. Step S4: Input the test set into the final prediction model to complete the prediction of the yard storage time of different containers in the test set; Step S5: Evaluate the model performance in terms of prediction accuracy, consistency, and correlation, and compare it with existing methods to verify the model's prediction performance and superiority.

[0006] Preferably, step S1 includes: Step S11: Collect storage time records of several types of containers in the yard and their associated feature data. Then, based on business rules, identify and remove data points that significantly deviate from the normal distribution and variable data that are not significantly related to the target predicted value to reduce noise interference. Finally, use linear interpolation to fill in missing values ​​to preserve data integrity and feature distribution consistency to the greatest extent. Step S12: Use grey relational analysis to calculate the correlation between the target variable and other feature variables, thereby assessing the importance of the feature variables to the target variable and selecting the feature variables accordingly. Specifically, grey relational analysis includes the following steps: Step S121: Select the target variable, container storage time, as the reference variable; Step S122: Since the data dimensions and numerical ranges of various indicators may differ in actual scenarios, in order to achieve effective correlation analysis, the original data is processed to be dimensionless by mean normalization. This step eliminates the influence of dimensions between different indicators, so that each feature variable is under the same data distribution, which is conducive to the comparison of correlations.

[0007] Step S123: After completing the dimensionless transformation of the characteristic variables, first calculate the absolute difference between the reference variable sequence and the characteristic variable sequence at each observation point, and then find the global minimum and maximum differences.

[0008] Step S124: After the correlation coefficient is calculated, the grey correlation degree between the comparison sequence and the reference sequence can be obtained by aggregating the average value of the correlation coefficient of each sample point. Finally, the feature variables with a correlation degree greater than the threshold are selected as sample data for predicting the container storage time.

[0009] Step S13: Divide the sample dataset into training set, validation set and test set according to the set ratio, and set the number of sample data to be processed each time the storage time prediction is performed.

[0010] Furthermore, in step S123 ρ The value is 0.5, and the threshold mentioned in step S124 is 0.6.

[0011] Preferably, the prediction network further includes: all three Transformer units use the Softmax function to calculate attention weights and the ReLU activation function; the fully connected network layer uses the Tanh activation function; the three Transformer units are respectively denoted as Transformer unit 1, Transformer unit 2, and Transformer unit 3; specifically, Transformer unit 1 is sequentially connected to a multi-head self-attention module 1 and a feedforward fully connected layer 1; Transformer unit 2 is sequentially connected to a multi-head self-attention module 2 and a feedforward fully connected layer 2; Transformer unit 3 is sequentially connected to a multi-head self-attention module 3 and a feedforward fully connected layer 3.

[0012] Furthermore, the process of building the prediction network also includes: designing the number of attention heads, the number of output channels, the number of hidden layers, and the number of neurons in each multi-head self-attention module based on the number and dimension of the input variable features.

[0013] Preferably, step S3 includes: Step S31: Input the training set into the prediction network in batches according to the number of feature variable data to be processed each time the storage time is predicted. Use the Transformer unit in the prediction network to extract features of the feature variables to be processed and obtain the correlation and coupling strength features between each feature variable. Step S32: Input the multivariate correlation coupling strength features extracted in step S31 into the fully connected network layer in the prediction network. Through the combination of layer-by-layer weighted summation and nonlinear activation function, establish a multidimensional mapping relationship between the correlation coupling strength features and storage time, thereby realizing the regression prediction of the container storage time in the yard. Step S33: In the design of the loss function, the design not only focuses on numerical accuracy but also considers the consistency of the prediction order. Considering that the prediction order directly affects stacking and scheduling strategies in actual business operations, and that incorrect order will lead to additional costs associated with flipping boxes or operations, pairwise ranking regularization is introduced based on the traditional mean squared error (MSE). The MSE component measures the numerical closeness between the predicted and actual values.

[0014] The pairwise ordering consistency part is that, within the same batch, for any pair of samples ( i , j If the true value satisfies Then the predicted value should satisfy as much as possible. If the order is incorrect, a penalty term is used to constrain it, thereby guiding the model to learn a predicted order that conforms to actual logic. During training, the two loss components are weighted and combined into a total loss function. Through this design, the model can effectively improve the global ranking consistency of the prediction results while optimizing numerical errors, reducing order conflicts in practical applications. Finally, the prediction network is iteratively trained using stochastic gradient descent. During training, the network is considered to have converged when the loss function remains stable for M consecutive rounds, and training is stopped, resulting in a trained prediction model. Otherwise, steps S31-S32 are repeated to continue updating the parameters of the prediction network during training until the network converges, ultimately obtaining a trained prediction model. Step S34: Input the validation set from the sample dataset into the trained prediction model for validation, and obtain the final container storage time prediction model for the yard.

[0015] Further, step S5 includes: Step S51: Use RMSE, MAE, MAPE and Evaluate the accuracy of model predictions by measuring the error and correlation between the model's predictions and the actual values.

[0016] Step S52: The sequential consistency between prediction results is of great significance for subsequent yard scheduling optimization. The degree of consistency of prediction results directly affects the number of containers to be turned over in the yard. Therefore, the practicality of the prediction results is evaluated by using Consistency in Time (CST), Dynamic Time Warping (DWT) and Spearman correlation.

[0017] A second aspect of the present invention relates to a port yard container storage time prediction device based on a self-attention mechanism, comprising a memory and one or more processors, wherein the memory stores executable code, and the one or more processors execute the executable code to implement a port yard container storage time prediction method based on a self-attention mechanism according to the present invention.

[0018] A third aspect of the invention relates to a computer-readable storage medium having a program stored thereon that, when executed by a processor, implements a port yard container storage time prediction method based on a self-attention mechanism.

[0019] This invention first utilizes grey relational analysis to calculate the correlation between each feature variable and storage time, and then selects highly correlated feature variables as prediction inputs based on the correlation. Next, a multi-head self-attention network is introduced to model the complex dependencies and long program sequence features between variables, and a fully connected network is combined to achieve nonlinear mapping and fitting, thereby effectively improving the accuracy of the prediction results. During model training, a loss function measuring monotonic consistency is designed to constrain the model to maintain the monotonic order consistency of the output results without sacrificing prediction accuracy, thus effectively reducing the risk of container re-transfer and secondary handling caused by prediction order deviations in yard operations. Finally, the model's prediction performance is comprehensively evaluated from two dimensions: prediction accuracy and monotonic consistency. For accuracy, RMSE, MAE, MAPE, and R² are used; for monotonic consistency, the Consistency Index (CST), Dynamic Time Warping (DTW), and Spearman correlation coefficient are used. This invention's method balances prediction accuracy and practicality, providing reliable time information for optimizing container storage in yards, and has promising application prospects.

[0020] The innovation of this invention is: 1. The method of this invention uses grey relational analysis to achieve feature selection, ensuring the high correlation and importance of the input variables of the prediction model, and effectively improving the stability and applicability of the modeling.

[0021] 2. The method of this invention introduces a multi-head self-attention network to capture complex dependencies between variables and combines it with a nonlinear regression structure for feature fitting, which can significantly improve the accuracy and robustness of the prediction results.

[0022] 3. The method of this invention introduces consistency regularization constraints into the loss function and combines multi-dimensional evaluation indicators for performance evaluation, which not only ensures prediction accuracy, but also improves the order preservation of prediction results and practical application value, and helps to reduce the rate of container turning over in the yard and secondary transfer.

[0023] The beneficial effects of this invention are as follows: The method of this invention first achieves feature selection through grey relational analysis to ensure that the input variables have high relevance and importance, thereby improving the stability and applicability of model building. Then, a multi-head self-attention network is introduced to capture the complex dependencies between variables, and feature fitting is performed in combination with a nonlinear regression structure, which effectively improves the accuracy and robustness of the prediction results. At the same time, consistency regularization constraints are introduced into the loss function, and multi-dimensional evaluation indicators are used for performance evaluation, which not only ensures the prediction accuracy, but also enhances the order preservation of the results and the practical application value, and can further reduce the container turnover rate and secondary transshipment risk in the yard. Attached Figure Description

[0024] Appendix Figure 1 This is a flowchart of the method of the present invention; Appendix Figure 2 This is a radar chart showing the correlation analysis results of the feature variables in this embodiment of the invention. Appendix Figure 3 This is a diagram of the prediction network architecture in an embodiment of the present invention; Appendix Figure 4 This is a schematic diagram illustrating the principle of training the prediction network in an embodiment of the present invention. Appendix Figure 5 This is a graph showing the convergence result of the model training loss in an embodiment of the present invention; Appendix Figure 6 This is a scatter plot of model predictions versus actual values ​​in an embodiment of the present invention. Appendix Figure 7 This is a graph showing the comparison between the model's predicted values ​​and the actual values ​​in an embodiment of the present invention. Detailed Implementation

[0025] To facilitate understanding of this application, specific embodiments of the present invention will be described in further detail below with reference to the accompanying drawings and examples. These embodiments are primarily illustrative of the invention and are not intended to limit its scope. Rather, they are provided to provide a more thorough and comprehensive understanding of the disclosure of this application.

[0026] Example 1

[0027] This embodiment presents a method for predicting container storage time in port yards based on a self-attention mechanism, such as... Figure 1 As shown, the method includes the following steps: Step S1: Collect sample data of characteristic variables that affect the storage time of containers in the port yard, preprocess the data to obtain a sample dataset, and divide the sample dataset into training set, validation set and test set according to the set ratio; Step S11: Collect storage time records of several types of containers in the yard and their associated feature data. Then, based on business rules, identify and remove data points that significantly deviate from the normal distribution and variable data that are not significantly related to the target predicted value to reduce noise interference. Finally, use linear interpolation to fill in missing values ​​to preserve data integrity and feature distribution consistency to the greatest extent. Step S12: Use grey relational analysis to calculate the correlation between the target variable and other feature variables, thereby assessing the importance of the feature variables to the target variable and selecting the feature variables accordingly. Specifically, grey relational analysis includes the following steps: Step S121: Select the target variable, container storage time, as the reference variable. (1) The remaining relevant variables are represented as follows: (2) in n Indicates the length of the variable data. m Indicates the total number of variables; and Indicate the reference variable and the characteristic variable; k and i Both represent variable indices; Step S122: Since the data dimensions and numerical ranges of various indicators may differ in actual scenarios, in order to achieve effective correlation analysis, the original data is dimensionless by mean normalization; the processing of each feature variable sequence is as follows: (3) This step eliminates the influence of different dimensions between indicators, placing all characteristic variables under the same data distribution, which is beneficial for comparing correlations.

[0028] Step S123: After completing the dimensionless transformation of the feature variables, first calculate the absolute difference between the reference variable sequence and the feature variable sequence at each observation point, and then find the global minimum and maximum differences. The formula for calculating the correlation coefficient is as follows: (4) in, and Indicate the reference variable and the characteristic variable; ρ∈(0, ∞) represents the resolution coefficient, used to adjust the discrimination. A smaller resolution coefficient indicates stronger discrimination ability; a larger resolution coefficient results in smoother analysis results. Generally, ρ The value is 0.5; Step S124: After the correlation coefficient is calculated, the grey correlation degree between the comparison sequence and the reference sequence can be obtained by aggregating the average correlation coefficients of each sample point. The calculation formula is as follows: (5) In the formula Represents the correlation coefficient, grey relational degree The value ranges from (0,1]. The closer the value is to 1, the closer the comparison sequence and the reference sequence are in terms of their changing trends, and the stronger their correlation. Finally, the correlation analysis results are as follows: Figure 2 As shown, feature variables with a correlation degree greater than 0.6 were selected as sample data for predicting container storage time.

[0029] Step S13: Divide the sample dataset into training set, validation set and test set according to the set ratio, and set the number of sample data to be processed each time the storage time prediction is performed.

[0030] In this embodiment, since the port container storage time prediction method based on the self-attention mechanism is based on the background of storage time in a complex port container yard, in order to verify its effectiveness, nine feature variables, namely container owner number, container owner code, transportation mode, container type, whether it is domestic trade / foreign trade, operation type, and payment method / payment code, as well as actual storage time, are collected as data samples to construct a sample dataset. The sample dataset is divided into training set, validation set and test set in a ratio of 7:1:2. At the same time, the number of samples processed in a single parallel training is set to 256 to accelerate the convergence speed of the prediction network.

[0031] Step S2: Build the prediction network; The prediction network has the following structure: starting from the input layer, it is sequentially connected to three Transformer units, a fully connected network layer, and an output layer; each of the three Transformer units uses the Softmax function to calculate attention weights and the ReLU activation function; the fully connected network layer uses the Tanh activation function; the three Transformer units are denoted as Transformer unit 1, Transformer unit 2, and Transformer unit 3; specifically, Transformer unit 1 is sequentially connected to a multi-head self-attention module 1 and a feedforward fully connected layer 1; Transformer unit 2 is sequentially connected to a multi-head self-attention module 2 and a feedforward fully connected layer 2; Transformer unit 3 is sequentially connected to a multi-head self-attention module 3 and a feedforward fully connected layer 3.

[0032] The Transformer unit includes a multi-head self-attention module and a feedforward fully connected layer. The multi-head self-attention module is used to learn the potential correlation features between related variables in historical data. The feedforward fully connected layer is used for further nonlinear mapping and feature fusion. The fully connected network layer is used to establish a multidimensional mapping relationship between fused features and storage time. The output of this layer is a one-dimensional vector containing only storage time, realizing the prediction of the storage time of containers in the yard. The output layer is used to output the storage time of the container corresponding to the predicted input features.

[0033] Furthermore, the number of attention heads, the number of output channels, and the number of hidden layers and neurons in each multi-head self-attention module are designed based on the number and dimensionality of the input variable features.

[0034] In this embodiment, to fully explore the implicit relationships and complementary information among the selected feature variables, the Transformer unit described in this invention is used to extract features from the input variables, thereby adaptively learning the dependency patterns and interaction features between variables, providing a more accurate feature representation with global awareness for subsequent predictions. The specific structure is as follows: Figure 3 As shown, the network calculation process is as follows: First, layer normalization is performed to eliminate distribution differences between different feature channels and improve network stability. Then, the normalized features are input into the multi-head self-attention module for feature extraction. The calculation process can be represented as follows: (10) in, Indicates the input feature variables. This represents the feature map after computation by the attention network. LN ( ) indicates layer normalization operation; MHSA ( The ) indicates multi-head self-attention computation. The core computational steps of multi-head self-attention are as follows: First, perform linear mapping and multi-head splitting on the input features. (11) in, , and Here, Q, K, and V are the learnable weight matrices, respectively, representing the query, key, and value matrices. Secondly, attention weights are calculated using the following formula: (12) in, The key vector dimension is used for scaling to stabilize the gradient. Q, K, and V are the query, key, and value matrices, respectively. Finally, the computed multi-head attention is concatenated with a linear transformation. (13) in, h For the number of attention heads, This is the output transformation matrix. This mechanism enables the model to learn diverse dependency patterns between feature variables in different subspaces, thereby improving the modeling level of global information.

[0035] Secondly, after completing the attention modeling, the output attention feature map will be... A second layer of normalization is performed, and global information is further integrated through a multilayer perceptron to enhance feature representation capabilities. The calculation formula is as follows: (14) in, Represents the attention weight map. F This represents the feature map after aggregation by the attention network. MLP This represents a multilayer perceptron, used to introduce nonlinear mapping capabilities and further model higher-order relationships between variables; LN ( The ) indicates the layer normalization operation. By repeating the above steps three times, the multi-head self-attention module can adaptively capture the explicit and implicit dependencies between input feature variables, while the nonlinear transformation of the multilayer perceptron further mines the complementary information between features.

[0036] Finally, the feature maps will be fused. F The input feature vector Z is flattened to obtain a one-dimensional feature vector for subsequent fully connected mapping. Then, the first fully connected network layer multiplies the input feature vector by the weight matrix and adds a bias term, followed by a nonlinear transformation using a nonlinear activation function to obtain the hidden layer feature representation. h : (15) in, This represents the ReLU activation function. Represents the weight matrix. Indicates bias. F This represents the features aggregated in the previous step. Finally, the hidden layer output is linearly mapped to the fully connected output network to obtain the predicted value. : (16) Through the above mapping process, an effective conversion from high-dimensional feature representation to target predicted value is achieved.

[0037] Step S3: Input the training set into the prediction network for training to obtain the trained prediction model; and use the validation set to validate the trained model to obtain the final prediction model; design a loss function based on mean squared error and result monotonic consistency measure to constrain model training, construct ranking pairs for samples in the same batch, and output prediction results with high monotonic consistency by calculating the ranking consistency difference between the predicted ranking pairs and the input sample ranking pairs. Step S31 outputs the training set to the prediction network in batches according to the set batch size, and uses multi-head self-attention layer and feedforward fully connected layer to extract and fuse the correlation features in the input data to obtain the coupling correlation features between variables. Step S32: Output the coupled correlation features extracted in step S31 to the fully connected layer to establish a multidimensional mapping relationship between the coupled correlation features and the storage time, thereby realizing the regression prediction of the storage time of containers in the yard and finally realizing the prediction of storage time.

[0038] Step S33: In designing the loss function to constrain model training, the design of the loss function not only focuses on numerical accuracy but also considers the consistency of the prediction order. Considering that the prediction order directly affects stacking and scheduling strategies in actual business operations, and that incorrect ordering will lead to additional costs associated with flipping boxes or operations, this invention introduces a pairwise ordering consistency regularization based on the traditional mean squared error (MSE). The MSE part measures the numerical closeness between the predicted and actual values, and its formula is as follows: (6) in and This represents the true value and the model prediction result, where N represents the total number of samples. i This indicates the sample index.

[0039] The basic idea of ​​the order consistency part is that in the same batch, for any pair of samples ( i , j If the true value satisfies Then the predicted value should satisfy as much as possible. If the order is incorrect, a penalty term is used to constrain it, thereby guiding the model to learn a predicted order that conforms to actual logic. During training, the two loss components are weighted and combined into a total loss function: (7) in For the set of valid sample pairs within a batch, Indicates the actual order direction, and λ controls the weight of the sorting regularization. m For safety intervals, ( The loss function is logistic. This design allows the model to effectively improve the global ranking consistency of prediction results while optimizing numerical errors, reducing order conflicts in practical applications. Finally, the training process is as follows: Figure 4 As shown, when the loss function remains stable for M consecutive rounds, the network is considered to have converged, training is stopped, and a trained prediction model is obtained. Otherwise, steps S31-S32 are repeated to continue updating the parameters of the prediction network during training until the network converges, ultimately obtaining a trained prediction model. Based on the above training strategy, the loss changes during model training and validation are as follows: Figure 5 As shown, the model loss converges quickly, and the model training process is relatively stable.

[0040] Step S4: Input the validation set from the sample dataset into the trained prediction model for validation, and obtain the final container storage time prediction model for the yard.

[0041] Step S5: Evaluate the model performance in terms of prediction accuracy, consistency, and correlation, and compare it with existing methods to verify the model's prediction performance and superiority.

[0042] When evaluating model performance, the predictive performance is assessed from two dimensions: prediction accuracy and consistency of prediction order. RMSE, MAE, MAPE, and [other metrics] are used. The accuracy of a model's predictions is evaluated by measuring the error and correlation between the model's predictions and the actual values. The calculation formula is as follows: (8) in Indicates the first i The true value of each sample Indicates the first i The predicted value for each sample, N Indicates the total number of samples; This represents the mean of the true values.

[0043] The consistency of prediction results is crucial for subsequent yard scheduling optimization. The level of consistency directly affects the number of containers turned over in the yard. Therefore, Consistency in Time (CST), Dynamic Time Warping (DWT), and Spearman correlation are used to evaluate the practicality of the model's prediction results. The calculation formula is as follows: (9) in N Indicates the number of samples. and This indicates the difference between the reference sequence and the predicted sequence at time [time]. t The value of ; and This represents the adjacent difference between two sequences. Represents a symbolic function. Reference sequence (true value) number i One element; Predicted sequence number j one element, Let L represent a regular sequence of length L. Let P represent the set of all possible regular sequences. and Representing variables and rank, Indicates the first i The rank difference of a sample in two sequences.

[0044] Step S51: To verify the effectiveness of the method of the present invention, the method of the present invention was used to predict the storage time of containers in the port yard. The prediction results are as follows: Figure 6 and Figure 7 As shown; the model's performance is evaluated by comparing it with existing prediction methods such as SVR, BP, and LightGBM, focusing on prediction accuracy and monotonic consistency of results. For prediction accuracy, RMSE, MAE, MAPE, and... The model's prediction accuracy is evaluated; lower RMSE, MAE, and MAPE values ​​indicate smaller prediction errors and higher accuracy. This indicates that the higher the correlation between the predicted results and the actual values, the better the prediction accuracy. The comparison results are shown in Table 1. The method of this invention outperforms existing methods in all prediction accuracy evaluation indicators, effectively demonstrating the superiority of this method.

[0045] Table 1

[0046] Step S52: For the monotonic consistency evaluation of the prediction results, Spearman correlation, CST consistency, and Dynamic Time Warping (DWT) indices are used for comparative evaluation. Higher Spearman and CST values ​​indicate better model prediction performance. Lower DWT indicates closer order consistency between prediction results and the true value, resulting in higher model prediction accuracy. As shown in Table 2, the evaluation results of the method of this invention are superior to existing methods, effectively demonstrating the better practicality of the prediction results of the method of this invention.

[0047] Table 2

[0048] Example 2

[0049] This embodiment relates to a port yard container storage time prediction device based on a self-attention mechanism, including a memory and one or more processors. The memory stores executable code, and when the one or more processors execute the executable code, they are used to implement a port yard container storage time prediction method based on a self-attention mechanism according to Embodiment 1.

[0050] Example 3

[0051] This embodiment relates to a computer-readable storage medium storing a program that, when executed by a processor, implements a port yard container storage time prediction method based on a self-attention mechanism, as described in Embodiment 1.

[0052] The foregoing description provides a detailed account of embodiments of the present invention and is not intended to limit the invention in any way. Those skilled in the art can make various optimizations, improvements, and modifications based on this invention. Therefore, the scope of protection of this invention should be defined by the appended claims.

Claims

1. A method for predicting container storage time in port yards based on a self-attention mechanism, characterized in that, Includes the following steps: Step S1: Collect sample data of characteristic variables that affect the storage time of containers in the port yard, preprocess the data to obtain a sample dataset, and divide the sample dataset into training set, validation set and test set according to the set ratio; Step S2: Build a prediction network based on Transformer units and fully connected layers; the structure of the prediction network is as follows: starting from the input layer, multiple Transformer units, fully connected network layers and the output layer are connected in sequence; Step S3: Input the training set into the prediction network for training to obtain the trained prediction model; and use the validation set to validate the trained model to obtain the final prediction model; design a loss function based on mean squared error and result monotonic consistency measure to constrain model training, construct ranking pairs for samples in the same batch, and output prediction results with monotonic consistency by calculating the ranking consistency difference between the predicted ranking pairs and the input sample ranking pairs. Step S4: Input the test set into the final prediction model to complete the prediction of the yard storage time of different containers in the test set; Step S5: Evaluate the model performance in terms of prediction accuracy, consistency, and correlation, and compare it with existing methods to verify the model's prediction performance and superiority.

2. The method for predicting container storage time in port yards based on a self-attention mechanism according to claim 1, characterized in that, Step S1 includes: Step S11: Collect storage time records of several types of containers in the yard and their associated feature data. Then, based on business rules, identify and remove data points that significantly deviate from the normal distribution and variable data that are not significantly related to the target predicted value to reduce noise interference. Finally, use linear interpolation to fill in missing values ​​to preserve data integrity and feature distribution consistency to the greatest extent. Step S12: Calculate the correlation between the target variable and other feature variables using grey relational analysis to assess the importance of the feature variables for the target variable, and thus select the feature variables accordingly. Specifically, grey relational analysis includes the following steps: Step S121: Select the target variable, container storage time, as the reference variable; Step S122: Since the data dimensions and numerical ranges of various indicators may differ in actual scenarios, in order to achieve effective correlation analysis, the original data is processed to be dimensionless by mean normalization. Step S123: After completing the dimensionless transformation of the characteristic variables, first calculate the absolute difference between the reference variable sequence and the characteristic variable sequence at each observation point, and then find the global minimum and maximum differences; Step S124: After the correlation coefficient is calculated, the grey correlation degree between the comparison sequence and the reference sequence is obtained by aggregating the average value of the correlation coefficient of each sample point; finally, the feature variables with a correlation degree greater than the threshold are selected as sample data for predicting the container storage time. Step S13: Divide the sample dataset into training set, validation set and test set according to the set ratio, and set the number of sample data to be processed each time the storage time prediction is performed.

3. The method for predicting container storage time in port yards based on a self-attention mechanism according to claim 2, characterized in that, In step S123 ρ The value is 0.5, and the threshold mentioned in step S124 is 0.

6.

4. The method for predicting container storage time in port yards based on a self-attention mechanism according to claim 1, characterized in that, The Transformer unit includes a multi-head self-attention module and a feedforward fully connected layer. The multi-head self-attention module is used to learn the potential correlation features between related variables in historical data. The feedforward fully connected layer is used for further nonlinear mapping and feature fusion. The fully connected network layer is used to establish a multi-dimensional mapping relationship between fused features and storage time. The output of this layer is a one-dimensional vector containing only storage time, realizing the prediction of the storage time of containers in the yard. The output layer is used to output the storage time of the container corresponding to the predicted input features.

5. The method for predicting container storage time in port yards based on a self-attention mechanism according to claim 4, characterized in that, The prediction network further includes: the multi-layer Transformer unit consists of 3 layers, each Transformer unit uses the Softmax function to calculate attention weights and the ReLU activation function; the fully connected network layer uses the Tanh activation function; the 3 Transformer units are respectively denoted as Transformer unit 1, Transformer unit 2 and Transformer unit 3; specifically, Transformer unit 1 is sequentially connected to a multi-head self-attention module 1 and a feedforward fully connected layer 1; Transformer unit 2 is sequentially connected to a multi-head self-attention module 2 and a feedforward fully connected layer 2; Transformer unit 3 is sequentially connected to a multi-head self-attention module 3 and a feedforward fully connected layer 3.

6. The method for predicting container storage time in port yards based on a self-attention mechanism according to claim 5, characterized in that, The process of building the prediction network also includes: designing the number of attention heads, output channels, hidden layers, and neurons of each multi-head self-attention module based on the number and dimension of the input variable features.

7. The method for predicting container storage time in port yards based on a self-attention mechanism according to claim 1, characterized in that, Step S3 includes: Step S31: Input the training set into the prediction network in batches according to the number of feature variable data to be processed each time the storage time is predicted. Use the Transformer unit in the prediction network to extract features of the feature variables to be processed and obtain the correlation and coupling strength features between each feature variable. Step S32: Input the multivariate correlation coupling strength features extracted in step S31 into the fully connected network layer in the prediction network. Through the combination of layer-by-layer weighted summation and nonlinear activation function, establish a multidimensional mapping relationship between the correlation coupling strength features and storage time, thereby realizing the regression prediction of the container storage time in the yard. Step S33: Loss function; including mean squared error (MSE) and pairwise ranking regularization; where MSE is used to measure the numerical closeness between the predicted value and the true value. The pairwise sorting consistency regularization part is within the same batch, for any pair of samples ( i , j If the true value satisfies Then the predicted value should satisfy as much as possible. If the order is incorrect, a penalty term is used to constrain it, thereby guiding the model to learn a predictive order that conforms to actual logic. During training, the two loss components are weighted and combined into a total loss function. Finally, the prediction network is iteratively trained using stochastic gradient descent. During training, the network is considered to have converged when the loss function remains stable for M consecutive rounds, and training is stopped to obtain a well-trained prediction model. Otherwise, steps S31 to S32 are repeated to continue updating the parameters of the prediction network during training until the network converges, and finally, a well-trained prediction model is obtained. Step S34: Input the validation set from the sample dataset into the trained prediction model for validation, and obtain the final container storage time prediction model for the yard.

8. The method for predicting container storage time in port yards based on a self-attention mechanism according to claim 1, characterized in that, Step S5 includes: Step S51: Use RMSE, MAE, MAPE and Evaluate the accuracy of model predictions and measure the error and correlation between model predictions and actual values. Step S52: The sequential consistency between prediction results is of great significance for subsequent yard scheduling optimization. The degree of consistency of prediction results directly affects the number of containers to be turned over in the yard. Therefore, the practicality of the prediction results is evaluated by using Consistent CST, Dynamic Time Warping (DWT), and Spearman correlation.

9. A port yard container storage time prediction device based on a self-attention mechanism, characterized in that, The device includes a memory and one or more processors, wherein the memory stores executable code, and the one or more processors execute the executable code to implement a port yard container storage time prediction method based on a self-attention mechanism as described in any one of claims 1-8.

10. A computer-readable storage medium, characterized in that, It stores a program that, when executed by a processor, implements a method for predicting container storage time in a port yard based on a self-attention mechanism, as described in any one of claims 1-8.