Automatic driving test method and device based on traffic flow generation and confrontation optimization
By using trajectory generation and adversarial optimization methods based on real traffic distribution, the problems of NPC behavior simulation distortion and low efficiency in autonomous driving simulation testing are solved, achieving high fidelity and systematic verification, and improving the efficiency and reliability of autonomous driving testing.
Patent Information
- Application Number
- CN202511909679.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-17
- Publication Date
- 2026-04-28
AI Technical Summary
Existing autonomous driving simulation testing technologies suffer from distorted NPC behavior simulations, low testing efficiency, and a lack of systematic verification, making it difficult to achieve efficient and reliable testing and verification.
Based on prior knowledge of real traffic distribution, a trajectory generation and adversarial optimization method is used to generate candidate trajectories through horizontal and vertical decomposition and query-based decoding. Combining hard constraint filtering and soft constraint sorting, an adversarial optimization approach with safety constraints is adopted to form a closed-loop simulation test.
It achieves high fidelity in NPC behavior, significantly improves the realism and diversity of test scenarios, enhances testing efficiency and the ability to cover long-tail risk scenarios, and ensures the systematicness and reproducibility of the verification process.
Smart Images

Figure CN121933279A_ABST
Abstract
Description
Technical Field
[0001] This application belongs to the field of autonomous driving testing technology, specifically relating to autonomous driving testing methods and devices based on traffic flow generation and adversarial optimization. Background Technology
[0002] As autonomous driving systems (ADS) evolve to higher levels, building an efficient and reliable testing and verification system has become a core requirement for ensuring their safety and compliance and accelerating commercialization.
[0003] To address this need, the industry initially adopted real-world road testing methods. However, these methods have inherent drawbacks, such as high cost, long testing cycles, and difficulty in reproducing dangerous scenarios, making it difficult to meet the requirements of large-scale testing.
[0004] Simulation testing technology subsequently emerged, enabling controlled scenario reproduction through virtual environments and significantly improving testing efficiency. However, existing simulation testing methods have fundamental limitations in the simulation of non-player character (NPC) behavior, mainly in the following aspects: Distorted Interaction Mechanism: Because NPC behavior is mostly controlled by simple rules or scripts, its decision-making logic deviates significantly from the complex interaction patterns of real traffic participants. Either its behavior is too conservative, making it difficult to trigger the boundary decisions of the tested vehicle; or it creates conflict through "arbitrary violations," causing traffic distribution to deviate from the realistic scenario. This design also ignores the crucial temporal causality and multi-vehicle game theory in closed-loop simulation, rendering the test results lacking practical reference value.
[0005] Testing efficiency faces bottlenecks: When the testing scope expands to multiple maps and multiple runtime design domains, existing methods face the dilemma of complex parameter coupling and a large workload for manual tuning. The lack of an automated testing loop leads to low efficiency in covering long-tail scenarios and makes it difficult to systematically discover potential risks.
[0006] Systemic Deficiencies in Verification: Current simulation testing techniques, employing open-loop playback or simple perturbation schemes, fail to form a complete test-evaluation-optimization closed loop, resulting in verification results that are neither quantifiable nor reproducible. This systemic deficiency makes it difficult for test conclusions to effectively guide the improvement of actual systems, significantly reducing their engineering application value. Summary of the Invention
[0007] This application proposes an autonomous driving test scheme based on traffic flow generation and adversarial optimization, aiming to solve the problems of distorted interaction mechanism, bottleneck in test efficiency, and lack of systematic verification in existing autonomous driving simulation test schemes.
[0008] The first aspect of this application provides an autonomous driving testing method based on traffic flow generation and adversarial optimization, including: Based on prior knowledge of real traffic distribution, a set of short-term candidate trajectories is generated for multiple non-player vehicles using horizontal and vertical decomposition and query-based decoding. The candidate trajectory set is processed sequentially as follows: illegal trajectories are filtered out by hard constraints, and soft constraints are used to sort and score the trajectories that have passed the hard constraint filtering. Based on the scoring results and multiple types of rule constraints, a set of compliance candidate trajectories is output. The multiple types of rule constraints include at least one of the following: regulations and signal control, map geometric consistency, dynamic accessibility, comfort and readability, and interaction safety. On the candidate set of compliance candidates, the non-player role strategy is refined by adjusting decision variables and adopting an adversarial optimization method with safety constraints, so as to maximize the induction of the tested master vehicle to violate regulations or fail, while ensuring that the non-player role itself behaves in accordance with regulations. The decision variables include at least one of candidate trajectory index, phase offset, slight offset of target time distance or target speed, and global cooperative rhythm. The optimized non-player role strategy is deployed to the simulation test platform to drive the advancement of the synchronous closed-loop simulation environment, and to acquire and record the generated state snapshots and event logs. Based on the recorded data, a closed-loop evaluation is performed to verify the performance of the autonomous driving system or trigger its failure scenarios.
[0009] In some embodiments of this application, the short-term candidate trajectory set is generated within a short window, and multiple candidate trajectories are generated for each non-player character vehicle.
[0010] In some embodiments of this application, the horizontal and vertical decomposition and query-based decoding methods are constructed based on imitation learning and superimposed with differentiability reachability constraints and collision constraints based on ESDF cost graphs. The differentiability reachability constraints are used to ensure trajectory dynamics reachability, and the collision constraints based on ESDF cost graphs are used to avoid trajectory collisions through distance field modeling.
[0011] In some embodiments of this application, the filtering and removal of illegal trajectories using hard constraints includes: Trajectories that violate traffic regulations, exceed dynamic limits, or pose a collision risk are directly eliminated.
[0012] In some embodiments of this application, the soft-constraint ranking and scoring of trajectories filtered by hard constraints includes: Based on a scoring function that includes robustness ρ, a unified measurement is performed on the trajectories filtered by hard constraints, and the trajectories are divided into violation trajectories, trajectories that need to be repaired, or trajectories that pass according to the robustness ρ value. The trajectory to be repaired is fine-tuned, and the fine-tuning includes at least one of amplitude reduction, local linear correction, and phase shift adjustment in the time dimension. The repaired trajectories are re-evaluated, and the repaired trajectories that pass the evaluation are integrated with the initially approved trajectories and sorted to output a set of compliance candidates.
[0013] In some embodiments of this application, the adversarial optimization of the security constraints is achieved through an objective function, which includes a main optimization term and a constraint penalty term; The main optimization term is a multi-objective weighted function used to guide the behavior of non-player characters to systematically induce violations or failures of the tested main vehicle. It is composed of the following weighted combinations of sub-terms: minimizing the safety margin between the main vehicle and surrounding non-player characters, amplifying the uncertainty caused by the short-term perception occlusion of the main vehicle's sensors due to the movement arrangement of non-player characters, and increasing the probability of competitive right-of-way situations between the main vehicle and non-player characters. The constraint penalty term is used to impose safety constraints on the optimization process of the main optimization term. The penalty term includes the non-player character's own violation cost and behavior abruptness cost, to ensure that the optimized non-player character strategy complies with traffic rules and the behavior is natural.
[0014] In some embodiments of this application, the adversarial optimization of the security constraints employs at least one of the following strategies: heuristic combinatorial search, evolutionary sampling, constraint reinforcement learning, or policy fine-tuning.
[0015] In some embodiments of this application, the closed-loop evaluation is conducted around four dimensions: safety, legality, controllability, and explainability, wherein: The safety dimensions include recording the minimum distance between the tested vehicle and its nearest neighbor, the minimum time margin, and extreme values of emergency braking or sharp turns. The legality dimension includes the number of traffic violations and the frequency of rule boundary violations committed by the tested vehicle. The controllable dimensions include the trajectory smoothness of the tested master vehicle, the number of control command jitters, and the frequency of planning strategy switching. The interpretable dimension includes state snapshots and decision context data of keyframes before and after the triggering event.
[0016] In some embodiments of this application, the method further includes: In the adversarial optimization process, all random operations are controlled by a fixed seed, and key intermediate results are recorded. These key intermediate results include the selection sequence of decision variables, the penalty value during the optimization process, and the local optimal trajectory. After the simulation is executed, an event log and a reproducibility key are generated for deterministic reproduction of the test scenario and A / B replay comparison. The event log includes the spatiotemporal nodes that triggered the event, the coordination rhythm of non-player character vehicles, and the response lag information of the tested master vehicle. The reproducibility key includes a random seed, a candidate trajectory index sequence of key non-player character vehicles, and a phase fine-tuning vector.
[0017] A second aspect of this application provides an autonomous driving test device based on traffic flow generation and adversarial optimization, comprising: The trajectory generation module is used to generate a short-term candidate trajectory set for multiple non-player vehicles based on prior knowledge of real traffic distribution, using horizontal and vertical decomposition and query-based decoding. The trajectory filtering module is used to perform the following operations sequentially on the candidate trajectory set: filtering out illegal trajectories through hard constraints, sorting and scoring the trajectories that have passed the hard constraint filtering through soft constraints, and outputting a compliance candidate set based on the scoring results and multiple types of rule constraints, wherein the multiple types of rule constraints include at least one of the following: regulations and signal control, map geometric consistency, dynamic accessibility, comfort and readability, and interaction safety. The adversarial optimization module is used to refine the non-player character strategy by adjusting decision variables and adopting an adversarial optimization method with safety constraints on the compliance candidate set, so as to maximize the induction of the tested master vehicle to violate the rules or fail, while ensuring that the non-player character's own behavior complies with the rules. The decision variables include at least one of candidate trajectory index, phase offset, slight offset of target time distance or target speed, and global cooperative rhythm. The simulation evaluation module is used to distribute the optimized non-player role strategy to the simulation test platform to drive the advancement of the synchronous closed-loop simulation environment, and to acquire and record the generated state snapshots and event logs. Based on the recorded data, a closed-loop evaluation is performed to verify the performance of the autonomous driving system or trigger its failure scenarios.
[0018] In summary, the autonomous driving testing method and apparatus based on traffic flow generation and adversarial optimization provided in the embodiments of this application, through trajectory generation technology based on prior knowledge of real traffic distribution, especially by employing horizontal and vertical decomposition and query-based decoding methods, enables NPC behavior to accurately simulate the complex decision-making logic of real traffic participants (avoiding both over-conservatism and arbitrary violations), fundamentally solving the problem of interaction mechanism distortion, achieving high fidelity of NPC behavior, and significantly improving the realism and diversity of test scenarios; through a funnel-shaped process of rule constraints and feasibility screening, combined with a dual mechanism of hard constraint filtering and soft constraint ranking, it automatically eliminates illegal trajectories and optimizes the compliance candidate set, not only significantly reducing With less human intervention, it enables rapid generation and screening of large-scale scenarios, and can more effectively cover long-tail risk scenarios, effectively solving the bottleneck of testing efficiency and significantly improving the automation level of testing efficiency. Finally, through adversarial optimization of security constraints and closed-loop simulation evaluation, it finely adjusts key decision variables, including phase offset, target time offset, and global coordination rhythm, on the compliance candidate set. Combined with synchronous closed-loop simulation and complete event record recording, and evaluation around the four dimensions of "safety, legality, controllability, and interpretability", it forms a seamless test-evaluation-optimization closed loop, which completely solves the problem of systematic lack of verification and ensures the high systematicity and complete reproducibility of the verification process. Attached Figure Description
[0019] The features and advantages of this application will be more clearly understood by referring to the accompanying drawings, which are illustrative and should not be construed as limiting the application in any way. In the drawings: Figure 1 The overall system architecture for implementing the ADS testing method of this application is shown; Figure 2 This is a schematic diagram of a computer system to which this application applies; Figure 3 This is a flowchart illustrating an autonomous driving test method based on traffic flow generation and adversarial optimization, according to some embodiments of this application; Figure 4 These are configurable parameters for scenarios in some embodiments of this application; Figure 5 This is a flowchart of traffic flow generation in this application; Figure 6 This is the funnel-shaped rule used in this application to screen candidate trajectories; Figure 7 This is a schematic diagram of an autonomous driving test device based on traffic flow generation and adversarial optimization, according to some embodiments of this application. Detailed Implementation
[0020] In the following detailed description, numerous specific details of this application are illustrated by example to provide a thorough understanding of the relevant disclosure. However, it will be apparent to those skilled in the art that this application can be practiced without these details. It should be understood that the terms “system,” “apparatus,” “unit,” and / or “module” used in this application are one way of distinguishing different parts, elements, sections, or components at different levels in a sequential arrangement. However, these terms may be replaced with other expressions if other expressions can achieve the same purpose.
[0021] It should be understood that when a device, unit, or module is referred to as being "on," "connected to," or "coupled to" another device, unit, or module, it may be directly connected to or coupled to or communicate with other devices, units, or modules, or there may be intermediate devices, units, or modules present, unless the context explicitly indicates otherwise. For example, the term "and / or" as used herein includes any one and all combinations of one or more of the relevant listed items.
[0022] The terminology used in this application is for the purpose of describing specific embodiments only and is not intended to limit the scope of this application. As shown in the specification and claims of this application, unless the context clearly indicates otherwise, words such as "a," "an," "an," and / or "the" do not specifically refer to the singular and may also include the plural. Generally speaking, the terms "comprising" and "including" only indicate that explicitly identified features, integrals, steps, operations, elements, and / or components are included, and such expressions do not constitute an exclusive list, and other features, integrals, steps, operations, elements, and / or components may also be included.
[0023] Referring to the following description and accompanying drawings, these and other features and characteristics, operating methods, functions of related structural elements, combinations of parts, and economics of manufacture of this application can be better understood, wherein the description and drawings form part of the specification. However, it is clearly understood that the drawings are for illustrative and descriptive purposes only and are not intended to limit the scope of protection of this application. It is understood that the drawings are not drawn to scale.
[0024] Various structural diagrams are used in this application to illustrate various variations of the embodiments according to this application. It should be understood that the preceding or following structures are not intended to limit this application. The scope of protection of this application is determined by the claims.
[0025] In recent years, Autonomous Driving Systems (ADS) have made rapid progress in key areas such as perception, localization, prediction, planning, and control: the application of multi-sensor fusion (cameras, millimeter-wave radar, lidar) and self-supervised / multimodal learning technologies has continuously improved the robustness of ADS in understanding the environment; high-precision maps and online mapping are used in parallel, supporting scalable deployment from L2 / L2+ to higher levels (L3 / L4); behavior prediction and interaction modeling have transitioned from traditional models to large-scale data-driven spatiotemporal sequences and graph neural networks / Transformer paradigms; and planning and control are continuously merging among constraint optimization, model predictive control, and learning methods. With the formation of an engineering closed loop of "vehicle-side intelligence + cloud collaboration + simulation verification," the industry is increasingly emphasizing a safe, compliant, interpretable, and highly comprehensive testing and verification system to support the reliable operation of the system in complex roads, dense traffic, and long-tail risk scenarios.
[0026] However, existing mainstream testing paths still have significant shortcomings. On the one hand, real-world road testing is costly, slow, and lacks controllability. Long-tail dangerous situations occur very infrequently, making it difficult to draw statistically significant safety conclusions within an acceptable timeframe. Furthermore, reproducing real-world road test scenarios and comparing them with A / B regressions is difficult, and data governance and privacy compliance costs are high. On the other hand, while conventional simulations offer advantages in controllability and reproducibility, the non-player characters (NPCs) in the environment are mostly script / rule / simple reactive models, resulting in significant deviations in behavior distribution from the real world. This makes it difficult to create "just the right" interactive tension: either they are too conservative, failing to trigger the boundaries of the ego (the tested vehicle); or they create conflict by allowing NPCs to "violate rules at will," leading to traffic distributions that deviate significantly from reality and evaluation conclusions lacking engineering significance. Existing "open-loop" playback or "simple perturbation" solutions often overlook the temporal causality and multi-vehicle game in closed-loop interactions, resulting in limitations in coverage, interpretability, and transferability. When scaled up to multiple maps and multiple ODDs, they also encounter pain points such as heavy parameter coupling, excessive manual parameter tuning, and difficulty in forming an automatic supplementary measurement closed loop, making it difficult to systematically and quantitatively verify the resilience of ADS in the face of long-tail risks.
[0027] In view of this, this application proposes an ADS testing method based on a combination of traffic flow generation and adversarial optimization: First, a traffic flow generator that closely approximates real-world distribution is used as a priori to generate short-term candidate trajectories in batches for multi-vehicle scenarios; then, strict screening is performed using rules such as regulations, dynamics, comfort, and geometric feasibility to shrink the action space of the NPC to a "compliant and feasible" subspace; based on this, multi-agent adversarial optimization with safety constraints is introduced to refine and schedule NPC strategies within the "legally feasible" candidate set, maximizing the induction of Ego violations / failures under the premise that the NPC itself hardly violates any rules. This method balances realism and induction, improving the long-tail trigger rate while maintaining engineering usability and interpretability of conclusions, thus effectively compensating for the shortcomings of existing testing systems in terms of long-tail coverage, distribution alignment, and large-scale verification. Figure 1 The overall system architecture for implementing the ADS testing method of this application is shown.
[0028] Figure 2 This is a schematic diagram of a computer system to which this application applies. Figure 2 The computer system shown includes an interconnected test database, a simulation test platform, and an adversarial optimization server. Through close collaboration and data interaction, these three components form an automated, high-throughput, and reproducible closed-loop testing system for autonomous driving systems. Specifically: The adversarial optimization server, based on a prior model trained on large-scale real traffic data, generates diverse short-term candidate trajectories that conform to real traffic distribution for non-player character (NPC) vehicles in the virtual environment. Subsequently, acting as a rigorous "rule filter," it filters and repairs these trajectories through a funnel-shaped rule set integrating traffic regulations, dynamic feasibility, and interaction safety, ultimately outputting a "rule-compliant candidate set." Building upon this, its core adversarial optimization module uses a multi-agent optimization algorithm with safety constraints to collaboratively orchestrate and fine-tune the behavior of multiple NPCs within the rule-compliant boundaries. Its goal is not to force NPCs to violate rules, but rather to intelligently and legally maximize the decision-making pressure on the tested master vehicle (Ego), thereby efficiently and purposefully exposing its potential flaws. The adversarial optimization server can be a single machine, a cluster, or a distributed server.
[0029] As a controlled virtual environment executor, the simulation testing platform completes closed-loop testing of the Autonomous Driving System (ADS) based on data interaction with the adversarial optimization server. Specifically, the platform receives environmental vehicle control commands from the adversarial optimization server and translates them into specific vehicle behavior propulsion within the virtual environment. After each propulsion, the platform feeds back a complete state snapshot of the simulated world (including the position, speed, and heading of the Ego vehicle and all NPC vehicles) to the adversarial optimization server. This real-time state data serves as the direct basis for the server to generate traffic flow, filter rules, and perform adversarial optimization for the next round, thus forming a closed loop. Simultaneously, the platform records all data during synchronous execution. These records, combined with "reproducibility keys" (such as random seeds and decision sequences) generated and stored by the adversarial optimization server, constitute a complete data chain for deterministically reproducible test scenarios, providing a foundation for A / B replay and regression testing. Through this interaction, the simulation testing platform transforms the strategies generated by the adversarial optimization server into concrete and observable test results, thereby verifying the performance of the autonomous driving system.
[0030] At the deployment level, the adversarial optimization server and simulation test platform can be deployed on a single server, server cluster, or distributed cloud environment in terms of hardware architecture; in terms of software integration, they can be embedded as functional modules into existing simulation systems (such as CARLA, LGSVL), or work together with the simulation system as independent services. Figure 2 The vehicle shown is a virtual entity in a simulation environment.
[0031] Figure 3 This is a flowchart illustrating an autonomous driving testing method based on traffic flow generation and adversarial optimization, according to some embodiments of this application. In some embodiments, the autonomous driving testing method based on traffic flow generation and adversarial optimization is... Figure 2 The method described above, which involves the execution of an anti-optimization server, includes the following steps: S310, based on prior knowledge of real traffic distribution, uses horizontal and vertical decomposition and query-based decoding to generate a short-term candidate trajectory set for multiple non-player vehicles.
[0032] This application first performs scene initialization based on the input data. Specifically, the input data includes map and topology information and the initial state of entities. Among them: Map and topology information mainly includes lane geometry topology, road speed limits, road priority, and road connection network; The initial state of the entity mainly includes the position, orientation, navigation information, speed, and acceleration of Ego and several NPC vehicles. Scene initialization includes clock configuration, which mainly involves setting the simulator to synchronous mode with a time step of 0.1s; Environmental parameter configuration mainly includes traffic light initialization, static obstacle information, weather, light intensity, etc.
[0033] The initialization step parses and organizes the input information into the simulator, unifies the map coordinate system, aligns entity states, and provides a consistent and traceable starting point for subsequent traffic flow generation, rule filtering, and adversarial scheduling. Figure 4 These are configurable parameters for scenarios in some embodiments of this application.
[0034] After completing the scene initialization, a set of candidate trajectories matching the current scene is generated using a pre-trained traffic flow generation model (whose parameters are optimized through prior learning of real traffic distribution).
[0035] Traffic flow generation aims to provide each NPC with "diverse, short-term feasible routes from real-world driving distributions." Traffic flow generation employs a base driving strategy trained on a large-scale dataset, ensuring prior realism. To balance diversity and feasibility, this application combines horizontal and vertical decomposition with query-based decoding: a horizontal reference is constructed using the road centerline, and several vertical queries represent different speed / distance / deceleration styles; after scene encoding, the decoder generates Top-K candidates for each vehicle within a short window T and provides a base score. During training, differentiability reachability and collision constraints based on ESDF cost maps are superimposed on imitation learning, and contrastive imitation learning is used to distinguish "should / should not" interaction patterns, reducing distribution offset. Offline, rule scores, such as TTC, comfort / law compliance indicators, and base scores are weighted and fused to enhance safety; online, only lightweight inference is retained to ensure real-time generation without sacrificing prior realism. The traffic flow generation part outputs a set of candidate trajectories.
[0036] Figure 5 This is a flowchart of traffic flow generation in this application.
[0037] S320, the candidate trajectory set is processed sequentially as follows: illegal trajectories are eliminated by hard constraint filtering, soft constraint sorting and scoring are performed on the trajectories that have passed the hard constraint filtering, and compliance candidate set is output based on the scoring results and multiple types of rule constraints; wherein, the multiple types of rule constraints include at least one of the following: regulations and signal control, map geometric consistency, dynamic accessibility, comfort and readability, and interaction safety.
[0038] This application employs a combination of funnel-shaped rules and feasibility screening to select compliance candidate trajectories: First, five sets of rules must be defined for candidate trajectories: regulations / traffic control (red lights, no-entry, priority), map geometric consistency (bandwidth / lane change legality, line constraint), dynamic reachability (longitudinal / lateral acceleration, jerk, curvature / minimum turning radius), comfort and readability (smoothness and abrupt amplitude limiting), and interactive safety (TTC / minimum spacing / near-end collision proxy). In implementation, the principle of "filtering hard constraints first and sorting soft constraints later" is followed: hard violations are directly eliminated, while soft violations are uniformly measured by a scoring function, and "repairable branches" are set. Priority is given to trying fine-tuning such as time shift Δt, amplitude reduction, and local linear correction. Once the repair reaches the threshold, it is retained and the repair cost is recorded. To balance versatility and portability, a lightweight STL interface is introduced to model only a small number of temporal rules (such as "stopping at a red light" and "using fog lights in foggy weather"). The robustness ρ of these rules serves as the soft constraint score: ρ ≤ 0 is considered a violation, 0 < ρ < θ enters the repair branch, and ρ ≥ θ is considered a pass, where θ is a preset repair threshold parameter. Other continuous / geometric constraints still rely on fast numerical judgment and surrogate indices (TTC, reachability, etc.) to avoid the overhead of over-formulation. The final output is a candidate set of compliance rules and a multi-dimensional score vector for each rule, which can be used for subsequent selection / adversarial optimization weighting. This combination of rule funnel and lightweight STL not only covers general traffic rules but also facilitates integrated offline evaluation and online screening.
[0039] Figure 6 This is the funnel-shaped rule used in this application to screen candidate trajectories.
[0040] S330, on the compliance candidate set, the non-player character strategy is refined by adjusting decision variables and adopting an adversarial optimization method with safety constraints, so as to maximize the induction of the tested master vehicle to violate regulations or fail, while ensuring that the non-player character's own behavior complies with regulations. The decision variables include at least one of candidate trajectory index, phase offset, slight offset of target time distance or target speed, and global cooperative rhythm.
[0041] This application employs a security-constrained adversarial optimization approach to refine non-player character strategies. Specifically: The goal of adversarial optimization is not to have NPCs illegally collide with the main vehicle, but to maximize the decision load and misjudgment probability of the Ego through multi-vehicle coordination and timing arrangement, while strictly adhering to traffic rules. The search space consists of a set of law-abiding candidates from S320, and the decision variables include: the candidate index of each vehicle, the phase offset of entering key actions (lane change, merging, crossing intersections), the slight offset of the target time distance or target speed, and the global coordination rhythm. The optimization objective function adopts a weighted combination, such as minimizing the minimum distance or minimum time margin between the Ego and its nearest neighbor in the scene, amplifying the uncertainty caused by short-term perception occlusion, increasing the probability of competitive right-of-way situations, and using a penalty term to ensure that the NPC itself has "zero violations and low abruptness". In terms of algorithm implementation, the system supports three complementary strategies: first, heuristic combinatorial search, which advances with rapid scoring on a limited candidate graph; second, evolutionary sampling, which explores hard-to-reach temporal combinations with population diversity; and third, constrained reinforcement learning / policy fine-tuning, which learns "when to choose the more stressful legitimate candidate" based on offline replay. To maintain reproducibility, all random operations are controlled by a fixed seed, and key intermediate results (selection sequences, penalty values, and local optimal trajectories) are recorded. To avoid excessive concentration of adversarial activity on a single pattern, the system introduces a "diversity conservation" term, limiting the proportion of the same type of induced pattern in a single round of evaluation and encouraging the exploration of difficulties in different mechanisms. In this way, the optimization process achieves "bounded strength enhancement": it can significantly improve triggering efficiency without sacrificing engineering acceptability and legal compliance.
[0042] S340 distributes the optimized non-player role strategy to the simulation test platform to drive the synchronous closed-loop simulation environment, and acquires and records the generated state snapshots and event logs. Based on the recorded data, it performs closed-loop evaluation to verify the performance of the autonomous driving system or trigger its failure scenarios.
[0043] Finally, the optimized server will distribute the generated NPC strategy to the simulation test platform for simulation testing.
[0044] The simulation follows the principles of "synchronized clock, fixed update order, and full recording." The system advances the simulation step size Δt in synchronous mode: sequentially executing environmental updates (signal phase and background traffic), Ego perception-decision-control loop, NPC command issuance, and dynamic advancement, sampling a complete state snapshot at each step. To reduce external noise, the map and physical parameter versions are locked during execution, and all variable conditions (weather, lighting, traffic density) are managed separately as experimental factors. Evaluation metrics revolve around four dimensions: "safety, legality, controllability, and interpretability." The safety dimension records minimum time / space margins, extreme values such as sudden braking / sharp turns; the legality dimension counts Ego violations and rule boundary touch frequencies; the controllability dimension observes Ego stability (trajectory smoothness, control jitter, number of planning switches); and the interpretability dimension retains the state and decision context of keyframes (several seconds before and after the trigger) for easy review. After the scenario execution, the system automatically generates an "event log," including whether the trigger occurred, the spatiotemporal nodes on which it was based, the NPC coordination rhythm, and the Ego response lag. When the version is iterated or the strategy is changed, A / B replays can be performed under the same reproducibility key to compare differences and confirm the effectiveness of the fix, avoiding randomness. The reproducibility key is generated by the adversarial optimization server integrating key parameters during the optimization process and is used for deterministic reproduction and A / B replay comparison of the test scenario. In some embodiments of this application, the reproducibility key includes a random seed, a candidate trajectory index sequence of key non-player character vehicles, and a phase fine-tuning vector. This reproducibility key, along with other scenario assets generated during the testing process, such as initial conditions, selection sequences, evaluation curves, and key videos, are uniformly stored in the database to form a queryable case set. The scheduling layer automatically recommends the next round of experimental plans based on road conditions or failure modes that have not been fully tested recently, completing the closed loop from "discovery—location—fix—verification." Through this execution and evaluation framework, this application transforms "real but low-frequency" challenges into reproducible engineering assets, enabling testing to move from sporadic to deterministic and from single demonstrations to continuous improvement.
[0045] To facilitate practical engineering deployment, some embodiments of this application modularly integrate the autonomous driving testing methods described in s310-s340 into existing simulation testing processes. Specifically: In terms of hardware environment, the system can be deployed on test servers or high-performance desktops with multi-core CPUs. It is recommended to use i7 / Ryzen 7 or higher models with a balanced clock speed and core count to support high-frequency status updates and parallel computing of multiple vehicles. At least 16GB of memory is recommended for caching multiple rounds of scene and trajectory candidates. NVMe SSDs are used for storage to improve the throughput of logs and playback materials. It should be noted that the core process of "traffic flow generation—rule filtering—adversarial scheduling—closed-loop execution" described in this application relies on GPU support. When only offline log replay and batch evaluation are performed, CPU and SSD read / write performance are often more critical than GPU performance. For ease of migration and expansion, the system is deployed independently by module, allowing for integrated operation or deployment of adversarial scheduling and data recording on independent nodes. All modules interact via local loopback or LAN to ensure consistent behavior in both single-machine and multi-machine scenarios. The above configuration is compatible with common simulation test workstations and can be directly integrated into existing enterprise-level test pipelines and continuous integration processes.
[0046] In terms of software architecture, the system adopts a loosely coupled layered and modular design, organizing the data flow around six stages: "data access and scenario initialization—traffic flow generation—rule constraints and feasibility screening—adversarial optimization—simulation execution and recording—results aggregation and playback." The data access module uniformly parses the map, lanes, traffic control, and participant initial states, and verifies route reachability and initial conflicts; the traffic flow generation module constructs multiple traceable routes for each NPC using short-time windows; the rule screening module eliminates non-compliant schemes based on regulations, geometry, and dynamic boundaries, retaining "compliant candidates"; the adversarial optimization module performs multi-vehicle collaboration and timing orchestration within the compliant space, forming interactions that are more challenging for Ego but still interpretable; the simulation execution module advances a synchronous loop with a fixed step size, uniformly recording states and events; the results module is responsible for generating reproducible scenario assets (reproducibility keys, random seeds, selection sequences, and keyframes). Modules are interconnected through clear data contracts, facilitating individual replacement or independent upgrades; existing simulation platforms can also integrate only some of these capabilities.
[0047] The standard operating procedure begins with scenario initialization: loading the map and traffic organization, setting the initial states and route anchors for Ego and multiple NPCs, and completing a self-check for the legality of the starting point. Then, in the "traffic flow generation" phase, the system provides multiple candidate routes for each NPC using a short-window scrolling mechanism. These candidates are derived from real-world driving distribution and common behavioral differences, aiming to cover reasonable variations that "may occur." Next, "rule constraints and feasibility screening" are executed, imposing legal, geometric, and dynamic boundaries on the candidates, eliminating obviously infeasible items such as crossing red lights, crossing lines, driving against traffic, and exceeding curvature / acceleration limits, resulting in a set of compliant candidate vehicles. In the "adversarial optimization" phase, the system does not directly generate extreme actions, but instead performs multi-vehicle collaboration and timing orchestration within the compliant space, amplifying the existing interactive pressure through phase fine-tuning and rhythm coordination, making the challenges more prominent. Finally, in the "simulation execution and recording" phase, a closed loop is advanced using a synchronized clock, recording states, events, and keyframes, and generating the random seeds and selection sequences required for reproduction. The above process forms a causal chain of "realistic starting point - compliance boundary - collaborative amplification - closed-loop verification", which can not only improve triggering efficiency, but also stabilize review and regression, and facilitate cross-version comparison and closed-loop problem repair.
[0048] One embodiment of this application integrates the methods described in s310-s340 with the simulation testing system CARLA. In the integration with CARLA, the system prioritizes "determinism, loose coupling, and replayability." First, during the session establishment phase, the client enables synchronous mode and a fixed step size: `world.get_settings()` sets `synchronous_mode=True` and `fixed_delta_seconds=Δt` (e.g., 0.1s), unifying the traffic flow module to the same synchronization rhythm to ensure that environmental updates, the perception-decision-control loop, and physical propulsion are executed in a fixed order. At the map level, `world.get_map()` obtains the HD map and its lane topology; based on the GlobalRoutePlanner provided by CARLA, a road network map is generated according to the sampling resolution, and route anchors and reachability checks are set for Ego and each NPC, ensuring that subsequent candidate generation, rule filtering, and timing orchestration are all within the accessible lane connections. Environmental variables (lighting, rain and fog intensity, road surface slippage coefficient, etc.) together with the map version constitute part of the scene configuration and are recorded in the reproduction key to ensure that the same external conditions are maintained when playing back across versions A / B.
[0049] The participant lifecycle consists of four phases: "Generation—Binding—Running—Recycling". In the generation phase, vehicle models and sensors are selected from the blueprint library. Vehicles are generated using `world.spawn_actor` near legal roadside parking spaces or the centerline of the target lane. Before generation, raycasting or collision queries ensure no physical overlap at the starting point. In the binding phase, necessary sensors and observation channels are equipped for Ego and key NPCs: optional GNSS, IMU, odometer, camera, LiDAR, collision and lane intrusion sensors, etc., are all natively provided by CARLA. Simultaneously, the system establishes an "observation summary" buffer, compressing the simulation state into the most useful local semantics for candidate generation and rule selection (relative pose of neighboring vehicles, gaps between adjacent lanes, signal remaining time, etc.), avoiding over-reliance on raw sensor point clouds / pixels. For background traffic, Traffic Manager can be used to save computational power; while NPCs participating in adversarial orchestration switch to policy takeover mode: their autopilot is disabled, and the system issues the desired longitudinal velocity and lateral offset via the trajectory tracker at each simulation step. To reduce coupling to vehicle dynamics details, the control interface uses a lightweight abstraction of "target speed - target lane / offset - phase offset"; lateral constraints are checked by lane centerline and solid / dashed line attributes, and longitudinal constraints are ensured to be "reachable and smooth" by speed limit and acceleration limiter.
[0050] The main loop strictly follows the sequence of "read—decision—execution—advancement": each tick first reads the current state of Ego / NPCs (position, heading, speed, routing progress, and the phase of the most recent signal) in batches, then calls the system's internal three-stage logic of "candidate—filter—orchestration" to select the current step for key NPCs, and issues it as a batch command. Finally, it advances the physical and signal states. To ensure that the adversarial intensity is limited by the "rule-abiding boundary," the system performs a lightweight and rapid check again before issuing the command. If it is expected to touch the red line, it dynamically reverts to the second-best candidate to avoid exchanging NPC violations for triggering. Considering that the repeatability of CARLA depends on the random source and generation order, the system writes "blueprint selection, random seed, generation order, ActorID, and TrafficManager parameters (such as global speed ratio, following distance, and lane change tendency)" into the reproducibility key. In addition, it records "candidate index sequence and phase fine-tuning vector" for key NPCs used for collaborative orchestration to ensure that the same behavior can be replayed frame by frame afterward.
[0051] Figure 7 This is a schematic diagram of an autonomous driving test device based on traffic flow generation and adversarial optimization, according to some embodiments of this application. Figure 7As shown, the autonomous driving test device 700 based on traffic flow generation and adversarial optimization includes a trajectory generation module 710, a trajectory filtering module 720, an adversarial optimization module 730, and a simulation evaluation module 740. In some embodiments of this application, the autonomous driving test function based on traffic flow generation and adversarial optimization is provided by... Figure 2 The execution of the anti-optimization server is shown, where: The trajectory generation module 710 is used to generate a short-term candidate trajectory set for multiple non-player vehicles based on prior knowledge of real traffic distribution, using horizontal and vertical decomposition and query-based decoding. The trajectory filtering module 720 is used to sequentially perform the following operations on the candidate trajectory set: filtering out illegal trajectories through hard constraints, sorting and scoring the trajectories that have passed the hard constraint filtering through soft constraints, and outputting a compliance candidate set based on the scoring results and multiple types of rule constraints, wherein the multiple types of rule constraints include at least one of the following: regulations and signal control, map geometric consistency, dynamic accessibility, comfort and readability, and interaction safety. The adversarial optimization module 730 is used to refine the non-player character strategy by adjusting decision variables and adopting an adversarial optimization method with safety constraints on the compliance candidate set, so as to maximize the induction of the tested master vehicle to violate regulations or fail, while ensuring that the non-player character's own behavior complies with regulations. The decision variables include at least one of candidate trajectory index, phase offset, slight offset of target time distance or target speed, and global cooperative rhythm. The simulation evaluation module 740 is used to distribute the optimized non-player role strategy to the simulation test platform to drive the advancement of the synchronous closed-loop simulation environment, and to acquire and record the generated state snapshots and event records, thereby performing closed-loop evaluation based on the recorded data to verify the performance of the autonomous driving system or trigger its failure scenarios.
[0052] In summary, the autonomous driving testing method and apparatus based on traffic flow generation and adversarial optimization provided in the embodiments of this application, through trajectory generation technology based on prior knowledge of real traffic distribution, especially by employing horizontal and vertical decomposition and query-based decoding methods, enables NPC behavior to accurately simulate the complex decision-making logic of real traffic participants (avoiding both over-conservatism and arbitrary violations), fundamentally solving the problem of interaction mechanism distortion, achieving high fidelity of NPC behavior, and significantly improving the realism and diversity of test scenarios; through a funnel-shaped process of rule constraints and feasibility screening, combined with a dual mechanism of hard constraint filtering and soft constraint ranking, it automatically eliminates illegal trajectories and optimizes the compliance candidate set, not only significantly reducing With less human intervention, it enables rapid generation and screening of large-scale scenarios, and can more effectively cover long-tail risk scenarios, effectively solving the bottleneck of testing efficiency and significantly improving the automation level of testing efficiency. Finally, through adversarial optimization of security constraints and closed-loop simulation evaluation, it finely adjusts key decision variables, including phase offset, target time offset, and global coordination rhythm, on the compliance candidate set. Combined with synchronous closed-loop simulation and complete event record recording, and evaluation around the four dimensions of "safety, legality, controllability, and interpretability", it forms a seamless test-evaluation-optimization closed loop, which completely solves the problem of systematic lack of verification and ensures the high systematicity and complete reproducibility of the verification process.
[0053] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working process of the devices and modules described above can be referred to the corresponding descriptions in the foregoing device embodiments, and will not be repeated here.
[0054] Although the subject matter described herein is provided in the general context of execution on a computer system in conjunction with an operating system and applications, those skilled in the art will recognize that other implementations can also be executed in conjunction with other types of program modules. Generally, program modules include routines, programs, components, data structures, and other types of structures that perform specific tasks or implement specific abstract data types. Those skilled in the art will understand that the subject matter described herein can be practiced using other computer system configurations, including handheld devices, multiprocessor systems, microprocessor-based or programmable consumer electronics, minicomputers, mainframes, etc., and can also be used in distributed computing environments where tasks are performed by remote processing devices connected via a communication network. In a distributed computing environment, program modules may reside on both local and remote memory storage devices.
[0055] Those skilled in the art will recognize that the units and method steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0056] It should be understood that the specific embodiments described above are merely illustrative or explanatory of the principles of this application and do not constitute a limitation thereof. Therefore, any modifications, equivalent substitutions, improvements, etc., made without departing from the spirit and scope of this application should be included within the protection scope of this application. Furthermore, the appended claims are intended to cover all variations and modifications falling within the scope and boundaries of the appended claims, or equivalent forms of such scope and boundaries.
Claims
1. An autonomous driving testing method based on traffic flow generation and adversarial optimization, characterized in that, include: Based on prior knowledge of real traffic distribution, a set of short-term candidate trajectories is generated for multiple non-player vehicles by using horizontal and vertical decomposition and query-based decoding. The candidate trajectory set is processed sequentially as follows: illegal trajectories are filtered out by hard constraints, and soft constraints are used to sort and score the trajectories that have passed the hard constraint filtering. Based on the scoring results and multiple types of rule constraints, a set of compliance candidate trajectories is output. The multiple types of rule constraints include at least one of the following: regulations and signal control, map geometric consistency, dynamic accessibility, comfort and readability, and interaction safety. On the candidate set of compliance candidates, the non-player role strategy is refined by adjusting decision variables and adopting an adversarial optimization method with safety constraints, so as to maximize the induction of the tested master vehicle to violate regulations or fail, while ensuring that the non-player role itself behaves in accordance with regulations. The decision variables include at least one of candidate trajectory index, phase offset, slight offset of target time distance or target speed, and global cooperative rhythm. The optimized non-player role strategy is deployed to the simulation test platform to drive the advancement of the synchronous closed-loop simulation environment, and to acquire and record the generated state snapshots and event logs. Based on the recorded data, a closed-loop evaluation is performed to verify the performance of the autonomous driving system or trigger its failure scenarios.
2. The method according to claim 1, characterized in that: The short-term candidate trajectory set is generated within a short window, and multiple candidate trajectories are generated for each non-player character vehicle.
3. The method according to claim 1, characterized in that: The horizontal and vertical decomposition and query-based decoding method is constructed based on imitation learning and superimposed with differentiability reachability constraints and collision constraints based on ESDF cost graphs. The differentiability reachability constraints are used to ensure the reachability of trajectory dynamics, and the collision constraints based on ESDF cost graphs are used to avoid trajectory collisions through distance field modeling.
4. The method according to claim 1, characterized in that, The filtering and elimination of illegal trajectories using hard constraints includes: Trajectories that violate traffic regulations, exceed dynamic limits, or pose a collision risk are directly eliminated.
5. The method according to claim 4, characterized in that, The soft-constraint ranking and scoring of trajectories filtered by hard constraints includes: Based on a scoring function that includes robustness ρ, a unified measurement is performed on the trajectories filtered by hard constraints, and the trajectories are divided into violation trajectories, trajectories that need to be repaired, or trajectories that pass according to the robustness ρ value. The trajectory to be repaired is fine-tuned, and the fine-tuning includes at least one of amplitude reduction, local linear correction, and phase shift adjustment in the time dimension. The repaired trajectories are re-evaluated, and the repaired trajectories that pass the evaluation are integrated with the initially approved trajectories and sorted to output a set of compliance candidates.
6. The method according to claim 1, characterized in that: The adversarial optimization of the security constraints is achieved through an objective function, which includes a main optimization term and a constraint penalty term. The main optimization term is a multi-objective weighted function used to guide the behavior of non-player characters to systematically induce violations or failures of the tested main vehicle. It is composed of the following weighted combinations of sub-terms: minimizing the safety margin between the main vehicle and surrounding non-player characters, amplifying the uncertainty caused by the short-term perception occlusion of the main vehicle's sensors due to the movement arrangement of non-player characters, and increasing the probability of competitive right-of-way situations between the main vehicle and non-player characters. The constraint penalty term is used to impose safety constraints on the optimization process of the main optimization term. The penalty term includes the non-player character's own violation cost and behavior abruptness cost, to ensure that the optimized non-player character strategy complies with traffic rules and the behavior is natural.
7. The method according to claim 6, characterized in that: The adversarial optimization of the security constraints employs at least one of the following strategies: heuristic combinatorial search, evolutionary sampling, constraint reinforcement learning, or policy fine-tuning.
8. The method according to claim 1, characterized in that, The closed-loop evaluation is conducted across four dimensions: safety, legality, controllability, and explainability. The safety dimensions include recording the minimum distance between the tested vehicle and its nearest neighbor, the minimum time margin, and extreme values of emergency braking or sharp turns. The legality dimension includes the number of traffic violations and the frequency of rule boundary violations committed by the tested vehicle. The controllable dimensions include the trajectory smoothness of the tested master vehicle, the number of control command jitters, and the frequency of planning strategy switching. The interpretable dimension includes state snapshots and decision context data of keyframes before and after the triggering event.
9. The method according to claim 1, characterized in that, The method further includes: In the adversarial optimization process, all random operations are controlled by a fixed seed, and key intermediate results are recorded. These key intermediate results include the selection sequence of decision variables, the penalty value during the optimization process, and the local optimal trajectory. After the simulation is executed, an event log is generated based on the state data of the simulation platform, and a reproduction key is generated by integrating the key parameters in the optimization process. This key is used for deterministic reproduction of the test scenario and A / B replay comparison. The event log includes the spatiotemporal nodes of the triggering event, the coordination rhythm of non-player character vehicles, and the response lag information of the tested master vehicle. The reproduction key includes a random seed, a candidate trajectory index sequence of key non-player character vehicles, and a phase fine-tuning vector.
10. An autonomous driving test device based on traffic flow generation and adversarial optimization, characterized in that, include: The trajectory generation module is used to generate a short-term candidate trajectory set for multiple non-player vehicles based on prior knowledge of real traffic distribution, using horizontal and vertical decomposition and query-based decoding. The trajectory filtering module is used to perform the following operations sequentially on the candidate trajectory set: filtering out illegal trajectories through hard constraints, sorting and scoring the trajectories that have passed the hard constraint filtering through soft constraints, and outputting a compliance candidate set based on the scoring results and multiple types of rule constraints, wherein the multiple types of rule constraints include at least one of the following: regulations and signal control, map geometric consistency, dynamic accessibility, comfort and readability, and interaction safety. The adversarial optimization module is used to refine the non-player character strategy by adjusting decision variables and adopting an adversarial optimization method with safety constraints on the compliance candidate set, so as to maximize the induction of the tested master vehicle to violate the rules or fail, while ensuring that the non-player character's own behavior complies with the rules. The decision variables include at least one of candidate trajectory index, phase offset, slight offset of target time distance or target speed, and global cooperative rhythm. The simulation evaluation module is used to distribute the optimized non-player role strategy to the simulation test platform to drive the advancement of the synchronous closed-loop simulation environment, and to acquire and record the generated state snapshots and event logs. Based on the recorded data, a closed-loop evaluation is performed to verify the performance of the autonomous driving system or trigger its failure scenarios.