A method for vehicle-machine coordination trajectory generation and city simulation based on multi-head attention mechanism
By constructing a multi-scale spatiotemporal graph model through a multi-head attention mechanism, the complexity and uncertainty of urban transportation systems are addressed, enabling accurate, compliant, and interpretable trajectory prediction and generation for city-level online services, thereby improving the robustness and controllability of the system.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- PEKING UNIV SHENZHEN GRADUATE SCHOOL
- Filing Date
- 2026-04-15
- Publication Date
- 2026-07-21
Smart Images

Figure CN122433481A_ABST
Abstract
Description
Technical Field
[0001] A human-vehicle-machine collaborative trajectory generation and urban simulation method based on multi-head attention mechanism belongs to the field of spatiotemporal big data modeling, trajectory prediction and city-level online simulation technology of smart cities and intelligent transportation. Background Technology
[0002] The high-frequency fluctuations and sudden disturbances in urban transportation systems make online prediction and collaborative scheduling, aimed at safety management, congestion mitigation, public transportation priority, incident response, and carbon efficiency improvement, fundamental capabilities. While existing "perception-prediction-control" pipelines integrate vehicle-mounted and roadside sensing, mobile terminal trajectories, floating car sampling, cross-section detection, lane-level high-precision maps, and signal timing data, they struggle to sustainably support intersection group collaboration, fine-grained guidance, and cross-regional coordination under conditions of frequent obstruction, rapid density switching, accumulated data acquisition / upload latency, and asynchronous arrival of heterogeneous sources. The structural complexities of merging and diverging, tidal flow organization, ramp integration, and dynamic phase sequence adjustments, coupled with multimodal and long-tail behavioral distributions, can easily trigger secondary congestion and safety hazards without robust prediction and uncertainty quantification.
[0003] At the methodological level, common approaches each have their shortcomings: analytical models based on mechanisms and rules have clear constraints but limited adaptability, and are prone to degradation when faced with heterogeneous participants and non-stationary interactions; sequence-based deep models (RNN / LSTM / Transformer), while able to capture temporal dependencies and local interactions, often remain at a single-layer level, failing to fully utilize lane topology and control semantics, and struggling to maintain global consistency in path-level decisions such as lane changing, turning, and merging; scene-driven methods using grid or vector elements can inject geometry and connectivity, but are often decoupled from individual temporal sequences, have high online inference overhead, and are loosely coupled with downstream control interfaces. Furthermore, multi-source temporal base alignment and probabilistic calibration are often absent, and the lack of a unified feasible domain closure for dynamics, maps, rules, and interactions leads to the amplification of off-road, line-crossing, and potential conflicts in the candidate stage, and the predicted distribution is difficult to directly use for risk and strategy assessment.
[0004] Digital twin cities and transportation infrastructure provide conditions for replicating experiments and verifying strategies that align with reality, but the connection between mainstream prediction components and twin systems remains weak: training objectives rarely simultaneously constrain the consistency of micro-trajectory accuracy and meso / macro-statistical distributions (cross-sectional flow, OD, and velocity distribution); probability temperature and thresholds lack cross-regional and cross-time-period migration calibration, leading to easy "drifting" of online alarms and policy thresholds. On the engineering side, there are common problems such as full map reconstruction, cache deficiencies, and non-incremental updates, making it difficult for inference latency and resource consumption to meet millisecond-hundred-millisecond level response and city-level horizontal scaling requirements.
[0005] Therefore, a cross-scale integrated spatiotemporal modeling and generation framework is needed: Individuals, lanes, and regions are organized into a learnable multi-scale spatiotemporal graph under a unified time base, using relation-aware spatial attention and temporal attention to uniformly encode long-range dependencies and local interactions; at the generation end, a conditional multimodal mechanism is used to overlay feasible domain closure and risk rearrangement, outputting executable and auditable candidate and optimal results; on the twin side, distribution consistency alignment and probability temperature calibration are performed to ensure stable generalization across scenarios and time periods; on the deployment side, tile parallelism, adjacency / lane caching, and event-driven subgraph incremental updates achieve low latency, maintainability, and traceability, thereby supporting "accurate, compliant, explainable, and implementable" city-level online services. Summary of the Invention
[0006] The purpose of this invention is to address the shortcomings of existing technologies and propose a human-vehicle-machine collaborative trajectory generation and urban simulation method based on a multi-head attention mechanism.
[0007] To achieve the above objectives, the present invention adopts the following technical solution:
[0008] S1. Data Acquisition and Standardization: First, spatiotemporal data of the city is collected from multiple sources (such as traffic monitoring systems, vehicle sensors, and intelligent transportation facilities), including but not limited to vehicle GPS trajectories, pedestrian path data, traffic light status, traffic flow, weather conditions, and road condition information. To ensure high-quality and consistent data, coordinate systems are unified by converting all datasets to a unified coordinate system (such as WGS84) to eliminate spatial errors caused by different devices and sensors. Outlier data is removed using statistical methods (Z-score, IQR) to ensure data authenticity. Missing data is processed using KNN (K-Nearest Neighbors) interpolation or Gaussian process-based interpolation algorithms to ensure data continuity in the spatiotemporal dimension. Data is resampled at fixed time intervals, and weighted interpolation methods (such as linear interpolation or cubic spline interpolation) are used to fill in missing time points, ensuring spatiotemporal synchronization of all data sources. Finally, a quality mask is created to mark low-quality or missing time periods, ensuring transparency and traceability in subsequent modeling processes.
[0009] S2. Multi-scale Spatiotemporal Graph Construction and Tokenization via Multi-head Attention Mechanism: In this step, a multi-scale spatiotemporal graph model is constructed based on the urban traffic network. Each traffic entity (vehicle, pedestrian, traffic facility) is treated as a node in the graph, and nodes are connected by edges representing the spatiotemporal relationships between traffic entities (such as distance, relative speed, direction, and traffic signal status). A multi-head attention mechanism is used to tokenize the nodes and edges in the graph, enhancing the model's ability to perceive changes in spatiotemporal relationships and ensuring that the interaction relationships between different traffic entities are effectively captured.
[0010] Furthermore, the multi-scale spatiotemporal graph construction and multi-head attention mechanism tokenization described in step S2 include the following specific steps:
[0011] S21 Topology Maintenance and Update: Based on real-time data, the adjacency relationships between traffic entities are dynamically updated by setting distance thresholds and interaction rules to ensure the real-time accuracy of the graph's topology. The formula for topology update is Equation 1.
[0012] Formula 1:
[0013] in, Represents a node and nodes The adjacency relationship between them The spatial distance between the two nodes. Determine whether two nodes satisfy the interaction rules (such as reachability, traffic signals, yielding).
[0014] S22 Relationship Type Embedding: Edges in the spatiotemporal graph are labeled with their types to represent different types of traffic relationships (e.g., adjacent, upstream, prohibited). The vectorized representation of edge relationships is shown in Equation 2:
[0015] Formula 2:
[0016] in, For the edge relation vectors, This is the learning weight matrix for relation types. For edge relations The embedding vector.
[0017] S23 Tokenized Output: Tokenization of node and edge features is performed using a multi-head attention mechanism to ensure efficient transmission of spatiotemporal graph information to the encoder. Tokenization for the multi-head self-attention mechanism is implemented using Equation 3.
[0018] Formula 3:
[0019] in, These are query, key, and value matrices, respectively. For the number of attention heads, This is the output mapping matrix.
[0020] S3. Unified Time Base Alignment and Signal Semantic Time Relocation. When processing asynchronous data from multiple data sources, unified time base alignment technology maps all data to a unified reference time. Linear interpolation is used to supplement missing data, ensuring that each data point can be processed under the same time reference. For the phase information of traffic signals, a one-click vectorization representation is used to convert the signal state into vector form, ensuring that the control information can be directly used in the aligned spatiotemporal diagram.
[0021] Furthermore, the unified time base alignment and signal semantic time relocation described in step S3 include the following specific steps:
[0022] S31 Trajectory and Control Signal Alignment: The vehicle trajectory is aligned with the traffic signal control signal in time to ensure that the status of all vehicles and signal information are synchronized at the reference time. The interpolation formula is shown in Equation 4.
[0023] Formula 4:
[0024] in, At the target reference time The interpolation state at that point, It is adjacent to The left side has been observed. It is adjacent to The right side has been observed. The interpolation weights are calculated as shown in Equation 5:
[0025] Formula 5:
[0026] S32 Map Synchronization with Construction Status: Time-varying maps of special areas such as construction zones and restricted areas are time-annotated and synchronized with other traffic data to ensure the spatiotemporal consistency of all dynamic information.
[0027] S4. Spatiotemporal Graph Transformer Encoding and Cross-Scale Gated Fusion: A spatiotemporal graph Transformer encoder is used for deep learning modeling. This encoder combines a temporal self-attention mechanism, a spatial relationship-aware attention mechanism, and a cross-scale fusion gating mechanism, which can effectively handle long-range temporal dependencies, complex spatial interactions, and the fusion of information at different scales.
[0028] Furthermore, the spatiotemporal graph Transformer encoding and cross-scale gating fusion described in step S4 includes the following specific steps:
[0029] S41 Temporal Attention Encoding: In the temporal dimension, a self-attention mechanism is used to extract the long-term temporal dependencies of each subject, as shown in Equation 6:
[0030] Formula 6:
[0031] in, These are the query, key, and value matrices respectively, along with the time dimension.
[0032] S42 Spatial Relationship Perception Attention: In the spatial dimension, the spatiotemporal features of adjacent nodes are aggregated through weighted aggregation, as shown in Equation 7:
[0033] Formula 7:
[0034] in, This is the spatial relation bias matrix, which adjusts the weighting of neighborhood information.
[0035] S43 Cross-Scale Gated Fusion: This method fuses macro-scale contextual information with micro-scale features using a Sigmoid gating mechanism, as shown in Equation 8.
[0036] Formula 8:
[0037] in, and The fusion weight matrix represents the fusion of information at both macroscopic and microscopic scales. The Sigmoid function is used to adjust the degree of fusion of information at different scales.
[0038] S5. Conditional multimodal trajectory generation and feasible region constraint screening: Multiple candidate trajectories are generated through a conditional variational autoencoder (CVAE) and a diffusion generation model. The generated trajectories are multimodally modeled based on environmental conditions (such as traffic density, weather, and traffic light status) and screened according to dynamic constraints, map information, and traffic rules to ensure that the trajectories are feasible in accordance with the actual traffic environment.
[0039] Furthermore, the conditional multimodal trajectory generation and feasible region constraint screening described in step S5 include the following specific steps:
[0040] S51 Conditional Generation: Multiple candidate trajectories are generated using CVAE, and the generation loss function is Equation 9:
[0041] Formula 9:
[0042] in, To generate loss; For observation samples or target sequences; It is a latent variable; It is an approximate posterior distribution; Generate the likelihood conditionally; To The expected condition.
[0043] S52 Feasible Domain Filtering: The generated trajectory is filtered based on dynamics, map, rules, and interaction behavior constraints. Constraints include the vehicle's maximum speed, heading angle range, and lane restrictions, as shown in Equation 10:
[0044] Formula 10:
[0045] in, For speed, This is the upper bound of the velocity; This refers to the heading angle or turning angle. The upper limit of the allowed angles.
[0046] S53 Risk Perception Reordering: Candidate trajectories are weighted and ranked based on confidence level, security, compliance and timeliness, and the optimal trajectory is finally selected.
[0047] S6. Digital Twin Consistency Calibration and Probability Output Calibration: To ensure consistency between the generated trajectory and the real urban situation, digital twin technology is employed. By aligning the distribution of the twin with the real observation data, the stability of the model under different regions and policy changes is ensured. Distribution alignment is achieved by minimizing the kernel mean difference (MMD) and Wasserstein distance using Equations 11 and 12.
[0048] Formula 11:
[0049] Formula 12:
[0050] in, Data distribution is divided into two domains; For each of the samples under its own distribution; For the regenerating nucleus Hilbert space; for Functions whose median norm does not exceed 1; For about Expectations The first-order Wasserstein distance; For The coupling set at the edge; It is a coupled distribution; The cost of transporting sample pairs.
[0051] S7. Staged joint optimization and cross-scale consistency enhancement: Staged scheduling and stabilization strategies are adopted to improve training controllability.
[0052] Furthermore, the staged joint optimization and cross-scale consistency enhancement described in step S7 include the following specific steps:
[0053] S71 Phased Scheduling and Annealing Learning Rate: In the early stages of training, a larger learning rate is used to promote convergence, which is then gradually reduced to a stable value. The learning rate formula is:
[0054] Formula 13:
[0055] S72 Gradient Clipping: To avoid gradient explosion, gradient clipping is used to ensure that the gradient remains within a set threshold range, as shown in Equation 14.
[0056] Formula 14:
[0057] in, For the first The original gradient vector of each parameter; Here, is the gradient norm; is the global clipping threshold. This represents the gradient after clipping.
[0058] S73 Cross-scale consistency maintenance and information fusion: Cross-scale fusion ensures contextual consistency between different scales by dynamically adjusting the transmission of information at macro and micro scales. The fusion formula is Equation 15:
[0059] Formula 15:
[0060] in, For the first The cross-scale fusion results of individual subjects; For macro or mesoscale context representation; Microscopic features; This is a weighted matrix that integrates macroscopic and microscopic scales; This is the Sigmoid function, used to adjust the fusion strength of information at different scales.
[0061] S74 Spatiotemporal Consistency Optimization: The spatiotemporal consistency loss function optimizes the temporal and spatial consistency of the generated trajectory, ensuring its spatiotemporal continuity. The temporal consistency loss function is Equation 16, and the spatial consistency loss function is Equation 17.
[0062] Formula 16:
[0063] Formula 17:
[0064] in, For a moment The predicted state vector; For a moment The true state vector; For time steps; The square Euclidean norm, For a moment The predicted spatial location vector; For a moment Real spatial position vector
[0065] S75 Evaluation and Selection: Maintains Top-1 and Best-of-K pipelines through parallel computing, automatically adjusting threshold and temperature parameters to optimize the quality of the final generated trajectory.
[0066] The S8 parallel inference architecture and online deployment mechanism utilize a tile-overlapping sliding window parallel inference approach on the system deployment side, reusing historical cached data and adjacent lane information to reduce inference latency. The system can respond in real time and connects to urban traffic management platforms through standardized interfaces, providing efficient city-level trajectory prediction and simulation services.
[0067] The present invention has the following outstanding substantive features and significant progress compared with existing technologies:
[0068] 1. Construct an engineering compliance framework of "evidence chain governance - versioned release - replayable reproducibility" to enhance the verifiability and maintainability of results. Each prediction is bound to a data family, model configuration, rule base and map version, feasible domain hit list, and rearranged decision path; it supports input hashing and solidification of key intermediate quantities to form replayable audit samples; rule and map changes adopt atomic gray-scale release and online consistency verification, with anomalies automatically rolled back to a stable snapshot; in cross-departmental collaboration and external compliance checks, it can quickly locate responsibility, reproduce experiments, and compare versions, significantly improving engineering controllability and regulatory approval rate.
[0069] 2. An online inference mechanism of "resource adaptive cascading - load shaping - steady-state control" is proposed to ensure deterministic latency of real-time services under different computing power and traffic pressures. The historical window length, number of attention heads, candidate sampling scale, and feasible domain verification accuracy are adaptively adjusted according to real-time load and latency budget. During periods of resource shortage or emergencies, fidelity-related safety constraints and risk assessments are prioritized, and low-weight targets are subject to controlled order reduction. By combining tile parallelism and cache reuse, hot and cold path splitting and fast hit are achieved, continuously meeting end-to-end latency and stability indicators, and supporting continuous online operation during peak traffic congestion at intersections, accident-prone road sections, and large-scale events.
[0070] 3. Establish a generalization enhancement system of "cross-modal / cross-scale self-distillation—domain-invariant alignment—robust regularization" to significantly reduce performance degradation caused by domain migration and weak annotation. Macro / mesoscale path intent is used as the teacher signal to perform self-distillation on the micro-decoder, and consistency constraints from vision, radar, and GNSS are introduced to suppress single-source offsets. Statistical moment alignment and kernel embedding metrics are used to achieve cross-city and cross-time period distribution alignment. Spectral norm constraints, Batch Renorm, and random weight averaging are combined to improve parameter smoothing and training convergence. Stable probabilistic availability and cross-domain robustness are maintained in long-tail scenarios such as right-of-way conflicts, frequent phase sequence adjustments, and temporary road closures. Attached Figure Description
[0071] Figure 1 Multi-scale spatiotemporal graph construction and relation-aware attention tokenization process.
[0072] Figure 2 Unified time base alignment and signal semantic time relocation process.
[0073] Figure 3 A fusion architecture of spatiotemporal graph Transformer encoding and cross-scale gating.
[0074] Figure 4 Conditional multimodal trajectory generation and feasible region constraint screening process.
[0075] Figure 5 A phased joint optimization and cross-scale consistency reinforcement training strategy.
[0076] Figure 6 This is a flowchart illustrating the overall technical process of the present invention; Detailed Implementation
[0077] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are for illustrative purposes only and are not intended to limit the invention.
[0078] Example 1, referring to Figure 1 , 2 3, 4, 5. The overall technical flow of this invention is shown in [reference needed]. Figure 6 .
[0079] Data acquisition and standardization begin with collecting spatiotemporal data from multiple sources (such as traffic monitoring systems, vehicle sensors, and intelligent transportation facilities) within the city. This data includes, but is not limited to, vehicle GPS trajectories, pedestrian path data, traffic light status, traffic flow, weather conditions, and road condition information. To ensure high data quality and consistency, coordinate systems are first standardized by converting all datasets to a unified coordinate system (such as WGS84) to eliminate spatial errors caused by different devices and sensors. Outlier data is removed using statistical methods (Z-score, IQR) to ensure data authenticity. Missing data is processed using KNN (K-Nearest Neighbors) interpolation or Gaussian process-based interpolation algorithms to ensure spatiotemporal continuity. Data is resampled at fixed time intervals, and weighted interpolation methods (such as linear interpolation or cubic spline interpolation) are used to fill in missing time points, ensuring spatiotemporal synchronization across all data sources. Finally, a quality mask is created to mark low-quality or missing time periods, ensuring transparency and traceability in subsequent modeling processes.
[0080] The multi-scale spatiotemporal graph construction and multi-head attention mechanism tokenization steps of this invention are described in [link to invention]. Figure 1 .
[0081] Multi-scale spatiotemporal graph construction and multi-head attention tokenization: Based on the urban traffic network, a multi-scale spatiotemporal graph model is constructed. Each traffic entity (vehicle, pedestrian, traffic facility) is treated as a node in the graph, and nodes are connected by edges representing the spatiotemporal relationships between traffic entities (such as distance, relative speed, direction, and traffic signal status). A multi-head attention mechanism is used to tokenize the nodes and edges in the graph, enhancing the model's ability to perceive changes in spatiotemporal relationships and ensuring that the interaction relationships between different traffic entities are effectively captured.
[0082] Furthermore, the multi-scale spatiotemporal graph construction and multi-head attention mechanism tokenization described in step S2 include the following specific steps:
[0083] 1) Topology Maintenance and Update: Based on real-time data, the adjacency relationships between traffic entities are dynamically updated by setting distance thresholds and interaction rules to ensure the real-time accuracy of the graph's topology. The formula for topology update is Equation 1.
[0084] Formula 1:
[0085] in, Represents a node and nodes The adjacency relationship between them The spatial distance between the two nodes. Determine whether two nodes satisfy the interaction rules (such as reachability, traffic signals, yielding).
[0086] 2) Relationship Type Embedding: Edges in the spatiotemporal graph are labeled with their types to represent different types of traffic relationships (e.g., adjacent, upstream, prohibited). The vectorized representation formula for edge relationships is shown in Equation 2:
[0087] Formula 2:
[0088] in, For the edge relation vectors, This is the learning weight matrix for relation types. For edge relations The embedding vector.
[0089] 3) Tokenized Output: Tokenization of node and edge features is performed using a multi-head attention mechanism to ensure efficient transmission of spatiotemporal graph information to the encoder. Tokenization for the multi-head self-attention mechanism is implemented using Equation 3:
[0090] Formula 3:
[0091] in, These are query, key, and value matrices, respectively. For the number of attention heads, This is the output mapping matrix.
[0092] The unified time base alignment and signal semantic time relocation steps of this invention are described in [link to invention]. Figure 2 .
[0093] When processing asynchronous data from multiple data sources, a unified time base alignment technique is used to map all data to a unified reference time. Linear interpolation is used to supplement missing data, ensuring that each data point can be processed under the same time reference. For the phase information of traffic signals, a one-click vectorization representation is used to convert the signal state into vector form, ensuring that the control information can be directly used in the aligned spatiotemporal diagram.
[0094] Furthermore, unified time base alignment and signal semantic time relocation include the following specific steps:
[0095] 1) Alignment of trajectory and control signals: Time-align the vehicle trajectory with the traffic signal control signals to ensure that the status of all vehicles and signal information are synchronized at the reference time. The interpolation formula is shown in Equation 4:
[0096] Formula 4:
[0097] in, At the target reference time The interpolation state at that point, It is adjacent to The left side has been observed. It is adjacent to The right side has been observed. The interpolation weights are calculated as shown in Equation 5:
[0098] Formula 5:
[0099] 2) Map synchronization with construction status: Time-varying maps of special time-varying areas such as construction areas and restricted areas are time-marked and synchronized with other traffic data to ensure the spatiotemporal consistency of all dynamic information.
[0100] The spatiotemporal graph Transformer encoding and cross-scale gating fusion steps of this invention are described in [link to invention]. Figure 3 .
[0101] Spatiotemporal graph Transformer encoding and cross-scale gating fusion are employed, using a spatiotemporal graph Transformer encoder for deep learning modeling. This encoder combines temporal self-attention, spatial relationship-aware attention, and cross-scale fusion gating mechanisms, effectively handling long-range temporal dependencies, complex spatial interactions, and the fusion of information from different scales.
[0102] Furthermore, the spatiotemporal graph Transformer encoding and cross-scale gating fusion include the following specific steps:
[0103] 1) Temporal attention encoding: In the time dimension, a self-attention mechanism is used to extract the long-term temporal dependencies of each subject, as shown in Equation 6:
[0104] Formula 6:
[0105] in, These are the query, key, and value matrices respectively, along with the time dimension.
[0106] 2) Spatial Relationship Perception Attention: In the spatial dimension, the spatiotemporal features of adjacent nodes are aggregated through weighted aggregation, as shown in Equation 7:
[0107] Formula 7:
[0108] in, This is the spatial relation bias matrix, which adjusts the weighting of neighborhood information.
[0109] 3) Cross-scale gating fusion: This involves fusing macro-scale contextual information with micro-scale features using a Sigmoid gating mechanism, as shown in Equation 8.
[0110] Formula 8:
[0111] in, and The fusion weight matrix represents the fusion of information at both macroscopic and microscopic scales. The Sigmoid function is used to adjust the degree of fusion of information at different scales.
[0112] The conditional multimodal trajectory generation and feasible region constraint screening steps of this invention are described in [link to invention]. Figure 4 .
[0113] Conditional multimodal trajectory generation and feasible region constraint screening generate multiple candidate trajectories using a conditional variational autoencoder (CVAE) and a diffusion generation model. The generated trajectories are multimodally modeled based on environmental conditions (such as traffic density, weather, and traffic light status) and screened according to dynamic constraints, map information, and traffic rules to ensure that the trajectories conform to the feasibility of the actual traffic environment.
[0114] Furthermore, the conditional multimodal trajectory generation and feasible region constraint screening include the following specific steps:
[0115] 1) Conditional Generation: Multiple candidate trajectories are generated using CVAE, and the generation loss function is given by Equation 9:
[0116] Formula 9:
[0117] in, To generate loss; For observation samples or target sequences; It is a latent variable; It is an approximate posterior distribution; Generate the likelihood conditionally; To The expected condition.
[0118] 2) Feasible Domain Filtering: The generated trajectory is filtered based on dynamics, map, rules, and interaction behavior constraints. Constraints include the vehicle's maximum speed, heading angle range, and lane restrictions, as shown in Equation 10:
[0119] Formula 10:
[0120] in, For speed, This is the upper bound of the velocity; This refers to the heading angle or turning angle. The upper limit of the allowed angles.
[0121] 3) Risk perception reordering: Candidate trajectories are weighted and ranked according to confidence level, security, compliance and timeliness, and the optimal trajectory is finally selected.
[0122] To ensure consistency between the generated trajectory and real-world urban conditions, digital twin technology is employed. By aligning the distribution of the twin with the real observation data, the stability of the model under different regions and policy changes is ensured. Distribution alignment is achieved by minimizing the kernel mean difference (MMD) and Wasserstein distance using Equations 11 and 12.
[0123] Formula 11:
[0124] Formula 12:
[0125] in, Data distribution is divided into two domains; For each of the samples under its own distribution; For the regenerating nucleus Hilbert space; for Functions whose median norm does not exceed 1; For about Expectations The first-order Wasserstein distance; For The coupling set at the edge; It is a coupled distribution; The cost of transporting sample pairs.
[0126] The phased joint optimization and cross-scale consistency enhancement steps of this invention are described in [link to invention]. Figure 5 .
[0127] Phased joint optimization and cross-scale consistency enhancement are employed, along with phased scheduling and stabilization strategies to improve training controllability.
[0128] Furthermore, the phased joint optimization and cross-scale consistency enhancement include the following specific steps:
[0129] 1) Phased scheduling and annealing learning rate: In the early stages of training, a larger learning rate is used to promote convergence, and then gradually reduced to a stable value in the later stages. The learning rate formula is:
[0130] Formula 13:
[0131] 2) Gradient clipping: To avoid gradient explosion, gradient clipping is used to ensure that the gradient remains within a set threshold range, as shown in Equation 14:
[0132] Formula 14:
[0133] in, For the first The original gradient vector of each parameter; Here, is the gradient norm; is the global clipping threshold. This represents the gradient after clipping.
[0134] 3) Maintaining cross-scale consistency and information fusion: Cross-scale fusion ensures contextual consistency between different scales by dynamically adjusting the transmission of information at macro and micro scales. The fusion formula is Equation 15:
[0135] Formula 15:
[0136] in, For the first The cross-scale fusion results of individual subjects; For macro or mesoscale context representation; Microscopic features; This is a weighted matrix that integrates macroscopic and microscopic scales; This is the Sigmoid function, used to adjust the fusion strength of information at different scales.
[0137] 4) Spatiotemporal Consistency Optimization: The spatiotemporal consistency loss function is used to optimize the temporal and spatial consistency of the generated trajectory, ensuring its spatiotemporal continuity. The temporal consistency loss function is Equation 16, and the spatial consistency loss function is Equation 17.
[0138] Formula 16:
[0139] Formula 17:
[0140] in, For a moment The predicted state vector; For a moment The true state vector; For time steps; The square Euclidean norm, For a moment The predicted spatial location vector; For a moment The true spatial location vector.
[0141] 5) Evaluation and selection: Maintain the Top-1 and Best-of-K pipelines through parallel computing, and automatically adjust threshold and temperature parameters to optimize the quality of the final generated trajectory.
[0142] Finally, on the system deployment side, tile-overlapping sliding window parallel inference is adopted, reusing historical cached data and adjacent lane information to reduce inference latency. The system can respond in real time and connect with the city traffic management platform through standardized interfaces to provide efficient city-level trajectory prediction and simulation services.
[0143] This invention constructs a three-layer spatiotemporal graph (micro-meta-macro) under a unified time base, and utilizes a spatiotemporal graph Transformer with relational bias for cross-scale encoding and gating fusion. On the generation side, a conditional multimodal head outputs candidate trajectories, which are then filtered through feasible domain projection and risk rearrangement composed of dynamics, map, rules, and interactions. On the calibration side, digital twin distribution alignment and probability temperature scaling are introduced to suppress domain drift. On the deployment side, tile parallelism and adjacency / lane buffering are combined for incremental event updates to reduce latency. This results in high-precision, compliant, and robust trajectory prediction and generation results even in complex road networks and policy switching scenarios.
[0144] It should be understood that those skilled in the art can make improvements or modifications based on the above description, and all such improvements and modifications should fall within the scope of protection of the appended claims.
Claims
1. A method for human-vehicle-machine cooperative trajectory generation and urban simulation based on a multi-head attention mechanism, characterized in that, Includes the following steps: S1. Data Acquisition and Standardization: First, spatiotemporal data of the city is collected from multiple sources (such as traffic monitoring systems, vehicle sensors, and intelligent transportation facilities), including but not limited to vehicle GPS trajectories, pedestrian path data, traffic light status, traffic flow, weather conditions, and road condition information. To ensure high-quality and consistent data, the coordinate system is unified by converting all datasets to a unified coordinate system (such as WGS84) to eliminate spatial errors caused by different devices and sensors. Outlier data is removed using statistical methods (Z-score, IQR) to ensure data authenticity. Missing data is processed using KNN (K-Nearest Neighbors) interpolation or Gaussian process-based interpolation algorithms to ensure data continuity in the spatiotemporal dimension. Data is resampled at fixed time intervals, and weighted interpolation methods (such as linear interpolation or cubic spline interpolation) are used to fill in missing time points, ensuring spatiotemporal synchronization of all data sources. Finally, a quality mask is created to mark low-quality or missing time periods, ensuring transparency and traceability in subsequent modeling processes. S2. Multi-scale Spatiotemporal Graph Construction and Tokenization via Multi-head Attention Mechanism: In this step, a multi-scale spatiotemporal graph model is constructed based on the urban traffic network. Each traffic entity (vehicle, pedestrian, traffic facility) is treated as a node in the graph, and nodes are connected by edges representing the spatiotemporal relationships between traffic entities (such as distance, relative speed, direction, and traffic signal status). A multi-head attention mechanism is used to tokenize the nodes and edges in the graph, enhancing the model's ability to perceive changes in spatiotemporal relationships and ensuring that the interaction relationships between different traffic entities are effectively captured. In the main text, Equation 1 is used for topology maintenance and updating, Equation 2 is used for vectorized representation of edge relationships, and Equation 3 implements tokenization of the multi-head self-attention mechanism. Formula 1: in, Represents a node and nodes The adjacency relationship between them The spatial distance between the two nodes. Determine whether two nodes satisfy the interaction rules (such as reachability, traffic signals, yielding). Formula 2: in, For the edge relation vectors, This is the learning weight matrix for relation types. For edge relations The embedding vector. Formula 3: in, These are query, key, and value matrices, respectively. For the number of attention heads, This is the output mapping matrix. S3. Unified Time Base Alignment and Signal Semantic Time Relocation. When processing asynchronous data from multiple data sources, unified time base alignment technology maps all data to a unified reference time. Linear interpolation is used to supplement missing data, ensuring that each data point can be processed under the same time reference. For the phase information of traffic signals, a one-click vectorization method is used to convert the signal state into vector form, ensuring that the control information can be directly used in the aligned spatiotemporal map. Equations 4 and 5 in the text are used for trajectory and control signal alignment; Formula 4: in, At the target reference time The interpolation state at that point, It is adjacent to The left side has been observed. It is adjacent to The right side has been observed. The interpolation weights are calculated as shown in Equation 5: Formula 5: S4. Spatiotemporal Graph Transformer Encoding and Cross-Scale Gated Fusion: A spatiotemporal graph Transformer encoder is used for deep learning modeling. This encoder combines a temporal self-attention mechanism, a spatial relationship-aware attention mechanism, and a cross-scale fusion gating mechanism, effectively handling long-range temporal dependencies, complex spatial interactions, and the fusion of information at different scales. In the text, Equation 6 is used to extract the long-term temporal dependencies of each subject using the self-attention mechanism; Equation 7 is used to weighted aggregate the spatiotemporal features of adjacent nodes; Equation 8 is used to fuse macro-scale contextual information and micro-scale features through a Sigmoid gating mechanism. Formula 6: in, These are the query, key, and value matrices respectively, along with the time dimension. Formula 7: in, This is the spatial relation bias matrix, which adjusts the weighting of neighborhood information. Formula 8: in, and The fusion weight matrix represents the fusion of information at both macroscopic and microscopic scales. The Sigmoid function is used to adjust the degree of fusion of information at different scales. S5. Conditional Multimodal Trajectory Generation and Feasibility Region Constraint Filtering: Multiple candidate trajectories are generated using a conditional variational autoencoder (CVAE) and a diffusion generation model. The generated trajectories are multimodally modeled based on environmental conditions (such as traffic density, weather, and traffic light status) and filtered according to dynamic constraints, map information, and traffic rules to ensure the trajectories conform to the feasibility of the actual traffic environment. In the main text, Equation 9 is used to generate the loss function, and Equation 10 is used for feasible region filtering. Formula 9: in, To generate loss; For observation samples or target sequences; It is a latent variable; It is an approximate posterior distribution; Generate the likelihood conditionally; To The expected condition. Formula 10: in, For speed, This is the upper bound of the velocity; This refers to the heading angle or turning angle. The upper limit of the allowed angles. S6. Digital Twin Consistency Calibration and Probability Output Calibration: To ensure the consistency between the generated trajectory and the real urban situation, digital twin technology is adopted. By aligning the distribution of the twin with the real observation data, the stability of the model under different regions and policy changes is ensured. Distribution alignment is achieved by minimizing the kernel mean difference (MMD) and Wasserstein distance using Equations 11 and 12. Formula 11: Formula 12: in, Data distribution is divided into two domains; For each of the samples under its own distribution; For the regenerating nucleus Hilbert space; for Functions whose median norm does not exceed 1; For about Expectations The first-order Wasserstein distance; For The coupling set at the edge; It is a coupled distribution; The cost of transporting sample pairs. S7. Staged joint optimization and cross-scale consistency enhancement: Staged scheduling and stabilization strategies are adopted to improve training controllability. In the main text, Equation 13 is used for staged scheduling and annealing learning rate, Equation 14 is used for gradient clipping, Equation 16 is the temporal consistency loss function, and Equation 17 is the spatial consistency loss function. Formula 13: Formula 14: in, For the first The original gradient vector of each parameter; Here, is the gradient norm; is the global clipping threshold. This represents the gradient after clipping. Formula 15: in, For the first The cross-scale fusion results of individual subjects; For macro or mesoscale context representation; Microscopic features; This is a weighted matrix that integrates macroscopic and microscopic scales; This is the Sigmoid function, used to adjust the fusion strength of information at different scales. Formula 16: Formula 17: in, For a moment The predicted state vector; For a moment The true state vector; For time steps; The square Euclidean norm, For a moment The predicted spatial location vector; For a moment The true spatial location vector. The S8 parallel inference architecture and online deployment mechanism utilize a tile-overlapping sliding window parallel inference approach on the system deployment side, reusing historical cached data and adjacent lane information to reduce inference latency. The system can respond in real time and connects to urban traffic management platforms through standardized interfaces, providing efficient city-level trajectory prediction and simulation services.
2. The method for human-vehicle-machine collaborative trajectory generation and urban simulation based on multi-head attention mechanism according to claim 1, characterized in that step S2 includes the following specific steps: 1) Topology Maintenance and Update: Based on real-time data, the adjacency relationships between traffic entities are dynamically updated by setting distance thresholds and interaction rules to ensure the real-time accuracy of the graph's topology. The formula for topology update is Equation 1. Formula 1: in, Represents a node and nodes The adjacency relationship between them The spatial distance between the two nodes. Determine whether two nodes satisfy the interaction rules (such as reachability, traffic signals, yielding). 2) Relationship Type Embedding: Edges in the spatiotemporal graph are labeled with their types to represent different types of traffic relationships (e.g., adjacent, upstream, prohibited). The vectorized representation formula for edge relationships is shown in Equation 2: Formula 2: in, For the edge relation vectors, This is the learning weight matrix for relation types. For edge relations The embedding vector. 3) Tokenized Output: The features of nodes and edges are tokenized using a multi-head attention mechanism to ensure that spatiotemporal graph information can be efficiently transmitted to the encoder. Tokenization of the multi-head self-attention mechanism is implemented using Equation 3: Formula 3: in, These are query, key, and value matrices, respectively. For the number of attention heads, This is the output mapping matrix.
3. The method for human-vehicle-machine cooperative trajectory generation and urban simulation based on multi-head attention mechanism according to claim 1, characterized in that, The S3 step includes the following specific steps: 1) Alignment of trajectory and control signals: Time-align the vehicle trajectory with the traffic signal control signals to ensure that the status of all vehicles and signal information are synchronized at the reference time. The interpolation formula is shown in Equation 4: Formula 4: in, At the target reference time The interpolation state at that point, It is adjacent to The left side has been observed. It is adjacent to The right side has been observed. The interpolation weights are calculated as shown in Equation 5: Formula 5: 2) Map synchronization with construction status: Time-varying maps of special time-varying areas such as construction areas and restricted areas are time-marked and synchronized with other traffic data to ensure the spatiotemporal consistency of all dynamic information.
4. The method for human-vehicle-machine cooperative trajectory generation and urban simulation based on multi-head attention mechanism according to claim 1, characterized in that, The S4 step includes the following specific steps: 1) Temporal attention encoding: In the time dimension, a self-attention mechanism is used to extract the long-term temporal dependencies of each subject, as shown in Equation 6: Formula 6: in, These are the query, key, and value matrices respectively, along with the time dimension. 2) Spatial Relationship Perception Attention: In the spatial dimension, the spatiotemporal features of adjacent nodes are aggregated through weighted aggregation, as shown in Equation 7: Formula 7: in, This is the spatial relation bias matrix, which adjusts the weighting of neighborhood information. 3) Cross-scale gating fusion: This involves fusing macro-scale contextual information with micro-scale features using a Sigmoid gating mechanism, as shown in Equation 8. Formula 8: in, and The fusion weight matrix represents the fusion of information at both macroscopic and microscopic scales. The Sigmoid function is used to adjust the degree of fusion of information at different scales.
5. The method for human-vehicle-machine cooperative trajectory generation and urban simulation based on multi-head attention mechanism according to claim 1, characterized in that, The S5 step includes the following specific steps: 1) Conditional Generation: Multiple candidate trajectories are generated using CVAE, and the generation loss function is given by Equation 9: Formula 9: in, To generate loss; For observation samples or target sequences; It is a latent variable; It is an approximate posterior distribution; Generate the likelihood conditionally; To The expected condition. 2) Feasible Domain Filtering: The generated trajectory is filtered based on dynamics, map, rules, and interaction behavior constraints. Constraints include the vehicle's maximum speed, heading angle range, and lane restrictions, as shown in Equation 10: Formula 10: in, For speed, This is the upper bound of the velocity; This refers to the heading angle or turning angle. The upper limit of the allowed angles. 3) Risk perception reordering: Candidate trajectories are weighted and ranked according to confidence, security, compliance and timeliness, and the optimal trajectory is finally selected.
6. The method for human-vehicle-machine cooperative trajectory generation and urban simulation based on multi-head attention mechanism according to claim 1, characterized in that, Step S7 has the following characteristics: 1) Phased scheduling and annealing learning rate: In the early stages of training, a larger learning rate is used to promote convergence, and then gradually reduced to a stable value in the later stages. The learning rate formula is: Formula 13: 2) Gradient clipping: To avoid gradient explosion, gradient clipping is used to ensure that the gradient remains within a set threshold range, as shown in Equation 14: Formula 14: in, For the first The original gradient vector of each parameter; Here, is the gradient norm; is the global clipping threshold. This represents the gradient after clipping. 3) Maintaining cross-scale consistency and information fusion: Cross-scale fusion ensures contextual consistency between different scales by dynamically adjusting the transmission of information at macro and micro scales. The fusion formula is Equation 15: Formula 15: in, For the first The cross-scale fusion results of individual subjects; For macro or mesoscale context representation; Microscopic features; This is a weighted matrix that integrates macroscopic and microscopic scales; This is the Sigmoid function, used to adjust the fusion strength of information at different scales. 4) Spatiotemporal Consistency Optimization: The spatiotemporal consistency loss function is used to optimize the temporal and spatial consistency of the generated trajectory, ensuring its spatiotemporal continuity. The temporal consistency loss function is Equation 16, and the spatial consistency loss function is Equation 17. Formula 16: Formula 17: in, For a moment The predicted state vector; For a moment The true state vector; For time steps; The square Euclidean norm, For a moment The predicted spatial location vector; For a moment The true spatial location vector. 5) Evaluation and selection: Maintain the Top-1 and Best-of-K pipelines through parallel computing, and automatically adjust threshold and temperature parameters to optimize the quality of the final generated trajectory.