Safe traffic flow generation method
By designing speed- and collision-related reward functions and TTC-related cost functions, combined with the Lagrangian method and neural network modeling, the problem of background vehicle collisions in traffic flow generation is solved, achieving a safer simulation environment and improving The effect of simulation testing.
Patent Information
- Application Number
- CN202410872050.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-01
- Publication Date
- 2024-10-29
AI Technical Summary
Existing traffic flow driving behavior models easily lead to background vehicle collisions in simulation tests and lack safety, especially in complex scenarios. Traditional methods require a large amount of data training and have poor generalization. Artificial intelligence methods fail to effectively consider safety.
Design a reward function and cost function. The reward function considers speed and collision, and the cost function measures safety from the Time-To-Collision (TTC) perspective. The maximum and minimum optimization problem is solved through the Lagrangian method and combined with the neural network to build module, reprojecting the optimal policy into the parameterized space to obtain an updated policy.
It effectively reduces the possibility of background vehicle collision in the simulation environment and improves the safety of traffic flow generation. The experimental results show that the algorithm is effective in traffic flow generation.
Smart Images

Figure CN118865670A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of autonomous driving safe driving behavior modeling, and in particular to a safe traffic flow generation method. Background Art
[0002] In recent years, autonomous driving technology has developed rapidly, but autonomous driving systems must undergo a large number of safety tests before they can be put into large-scale use. Usually, an autonomous driving system must pass 11 billion miles of testing before it can reach mass production. However, simulation testing can solve the problems of long testing cycles, high costs, and low efficiency on real roads, so it has received great attention from academia and industry. For simulation testing, the traffic flow driving behavior model is crucial to the test effect. If a large number of vehicles collide in the traffic flow background during the simulation, this situation is impossible in the real world and will greatly reduce the test effect.
[0003] Reinforcement learning (RL) discusses how an agent can maximize the rewards it can obtain in a complex and uncertain environment. By perceiving the reward (Reward) of the state (State) of the environment (Action), better actions are guided to obtain the maximum return (Return), which is called learning in interaction, and such a learning method is called reinforcement learning. Safe reinforcement learning (Safe RL) is modeled as a constrained Markov decision process (Constrained Markov Decision Process, CMDP), and the state space, action space, state transition function, reward, cost, cost threshold and discount factor are represented by the seven-tuple (S, A, p, r, c, d, γ). The goal of safe reinforcement learning is to maximize the expected reward under the constraint of not exceeding the cost threshold. Therefore, the reward and safety can be compromised by optimizing the reward objective function under safety.
[0004] There are various methods for modeling traffic flow driver models at present. Traditional methods include trajectory replay, IDM and MOBIL models; AI-based methods include behavior cloning, generative adversarial imitation learning, reinforcement learning, reward function and other methods. For traditional methods, trajectory replay requires the collection of abundant natural scene data, and background vehicles cannot interact with the main vehicle under test. IDM and MOBIL models are suitable for high-speed scenarios. For strongly interactive scenarios (e.g., intersections), this method is prone to collision and lacks safety. For AI methods, behavior cloning and generative adversarial imitation learning algorithms require a large amount of real data training. Both of them show poor generalization characteristics, and secondly, safety issues are not considered. Reinforcement learning methods can reduce collisions by designing a safety reward function. Although it can avoid some unsafe actions, it still does not solve the safety problem well. Summary of the invention
[0005] In order to solve the above problems, the present invention provides a safe traffic flow generation method to reduce the possibility of collision between background vehicles in the traffic flow of the simulated environment. First, we designed a reward function and a cost function, wherein the reward function is designed to improve the driving efficiency of the background vehicles in the traffic flow. The reward function is mainly considered from the perspective of speed and collision. The greater the speed, the greater the reward, but if a collision occurs, a penalty will be imposed; the cost function is designed to measure safety. The present invention measures safety from the perspective of TTC (Time-To-Collision). The greater the TTC, the safer it is, and the smaller the cost. Secondly, the objective function of the present invention contains safety constraints, and then the maximum and minimum optimization problem is solved by the Lagrangian method to obtain the optimal strategy. Finally, since the strategy modeled by the neural network is in a parameterized space, and the optimal strategy is in a non-parametric space, the present invention reprojects the optimal strategy into the parameterized space to obtain an updated strategy. The experimental results show that the algorithm of the present invention is an effective method for solving the safety of traffic flow generation.
[0006] The above technical objectives of the present invention are achieved through the following technical solutions: A method for generating a safe traffic flow, comprising the following steps:
[0007] S1, Traffic flow simulation environment modeling;
[0008] S2, online data collection;
[0009] S3. Safe traffic flow driving behavior modeling: First collect training data using the current strategy, and then collect batch data from the data to update the value network, cost network, and policy network.
[0010] Furthermore, online data collection includes environment status, rewards, and costs.
[0011] Further, in step S3, the safe traffic flow driving behavior modeling includes the design of reward function and cost function;
[0012] The design of the reward function is mainly based on speed and collision. The greater the speed, the greater the reward. Correspondingly, the greater the speed, the greater the penalty if a collision occurs. The following function input is speed (m / s)
[0013] Among them, speed reward: Collision Rewards: Furthermore, the cost is mainly considered from the perspective of TTC. If the TTC between the main vehicle and the front vehicle is smaller, it means that the possibility of collision between the main vehicle and the front vehicle is greater, so the cost is greater. The following formula ego represents the main vehicle, front vehicle ego Indicates the vehicle in front of the main vehicle;
[0014] Cost(ego,front ego )=50-min(50,TTC(ego,front ego )).
[0015] Furthermore, in step S3, the safe traffic flow driving behavior modeling also includes a modeling training process, the steps are as follows:
[0016] (1) Initialize the policy network π θ , Value Network V φ , price network Generalized advantage estimator (GAE) parameters β, discount rate γ, learning rate α v , α V , α π , temperature coefficient λ, initial cost constraint parameter v, cost constraint upper bound v max , confidence region threshold δ, cost threshold b;
[0017] (2) First use strategy π θ , generate(s i,t , a i,t , r i,t ,s i,t+1 , c i,t ) data, where the total number of rounds is M, each round has T data, i = 1, ..., M, t = 1, ..., T, and then the cost return is estimated by averaging the cost returns of all rounds, Secondly, GAE is used to estimate the advantage function And calculate the target value and target cost based on the value network and cost network Finally, update the cost constraint parameter v according to the formula;
[0018] (3) First, sample a batch of data of size B from the data generated in step (2) Then, the value network and the cost network are updated according to the value network loss function and the cost network loss function respectively, and finally the strategy network π is updated according to the formula θ ;
[0019] (4) Loop through step (3) times, if Then jump out of the loop;
[0020] (5) Loop through step (3) 4K times to complete one round of network update;
[0021] (6) Loop through steps (2) to (5) Num Epochs times to complete algorithm training.
[0022] Furthermore, the update formula of the cost constraint parameter v in step (2) is:
[0023] Furthermore, in step (3), the policy network π θ The update announcement is: Furthermore, the calculation formula of the value network loss function in step (3) is: Furthermore, the calculation formula of the cost network loss function in step (3) is:
[0024]
[0025] Compared with the prior art, the present invention has the following beneficial effects:
[0026] 1. The present invention designs a reward function and a cost function, wherein the reward function is used to measure driving efficiency. Its design is mainly considered from the perspective of speed and collision. The greater the speed, the greater the reward, but if a collision occurs, the corresponding penalty will also be greater. The cost function is designed to measure the safety of the current driving state. The cost function is obtained by transforming TTC. If the TTC is small, it means that the current state is unsafe, and the cost will be higher;
[0027] 2. The present invention first models the optimization objective as an optimization problem with security constraints, and then solves the maximum minimization optimization problem through the Lagrangian method to obtain the optimal update strategy. Since the optimal update strategy may be outside the parameter space, the re-projection method is used to project the optimal strategy into the parameter space to obtain the update strategy. BRIEF DESCRIPTION OF THE DRAWINGS
[0028] Figure 1 is a schematic diagram of a safe traffic flow driving behavior modeling framework in an embodiment of the present invention;
[0029] Figure 2It is a visualization diagram of the experimental data in the embodiment of the present invention. DETAILED DESCRIPTION
[0030] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0031] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0032] See also Figure 1-2 The present invention provides a technical solution: a method for generating a safe traffic flow, comprising the following steps:
[0033] S1, Traffic flow simulation environment modeling;
[0034] S2, online data collection, including environment status, rewards, and costs;
[0035] S3, safe traffic flow driving behavior modeling: first collect training data using the current strategy, and then collect batch data from the data to update the value network, cost network, and policy network;
[0036] Among them, safe traffic flow driving behavior modeling includes the design of reward function and cost function;
[0037] The design of the reward function is mainly based on speed and collision. The greater the speed, the greater the reward. Correspondingly, the greater the speed, the greater the penalty if a collision occurs. The following function input is speed (m / s);
[0038] Among them, speed reward: Collision Rewards: The design of the cost function is mainly based on the TTC perspective. If the TTC between the main vehicle and the front vehicle is smaller, it means that the possibility of collision between the main vehicle and the front vehicle is greater, so the cost is greater. The following formula ego represents the main vehicle, front vehicle ego Indicates the vehicle in front of the main vehicle;
[0039] Cost(ego,front ego )=50-min(50,TTC(ego,front ego)).
[0040] In step S3, the safe traffic flow driving behavior modeling also includes a modeling training process, the steps are as follows:
[0041] (1) Initialize the policy network π θ , Value Network V φ , price network Generalized advantage estimator (GAE) parameters β, discount rate γ, learning rate α v , α V , α π , temperature coefficient λ, initial cost constraint parameter v, cost constraint upper bound v max , confidence region threshold δ, cost threshold b;
[0042] (2) First use strategy π θ , generate(s i,t , a i,t , r i,t ,s i,t+1 , c i,t ) data, where the total number of rounds is M, each round has T data, i = 1, ..., M, t = 1, ..., T, and then the cost return is estimated by averaging the cost returns of all rounds,
[0043] Secondly, GAE is used to estimate the advantage function And calculate the target value and target cost based on the value network and cost network
[0044] Finally, the cost constraint parameter v is updated according to the formula:
[0045]
[0046] (3) First, sample a batch of data of size B from the data generated in step (2) Then according to the value network loss function: Cost network loss function: To update the value network and the cost network respectively, and finally update the policy according to the formula
[0047] Network π θ , the formula is:
[0048] (4) Loop through step (3) times, if Then jump out of the loop;
[0049] (5) Loop through step (3) 4K times to complete one round of network update;
[0050] (6) Loop through steps (2) to (5) Num Epochs times to complete algorithm training.
[0051] The algorithm principle of the present invention includes a constrained Markov decision process and an optimal constraint strategy:
[0052] Among them, the constrained Markov decision process: The Markov decision process can be expressed as a five-tuple in is the state space, is the action space, R is the reward function, P is the state transition matrix, and μ is the initial state distribution. The strategy can be expressed as Our goal is to find a fixed policy that maximizes the discounted expected return, Here τ is a sample trajectory and γ is the discount factor. The state value function is expressed as The action value function is expressed as The advantage function is defined as A π (s,a):=Q π (s,a)-V π (s), the discounted future state visit distribution is defined as A constrained Markov decision process is a Markov decision process with a set of additional constraints C that restrict the set of allowed strategies. The set C consists of a set of cost functions, and the reward of the cost can be defined as Then the set of feasible strategies is expressed as The purpose of constrained reinforcement learning is to Where Π represents the set of all strategies.
[0053] Optimal Constraint Strategy:
[0054] Typically, we update the policy by sampling from the environment, so we need to consider a set of parameterized policies (e.g., neural networks with fixed architectures) Π θ ={π θ : θ∈Θ}, from which we can evaluate and sample, and Π is called the non-parametric policy space. The method to update the parameterized policy is to solve the constrained Markov decision process and obtain and This method is difficult and has a low sample utilization rate. Therefore, this patent adopts a given strategy. By solving the optimization problem in the non-parametric policy space to find the optimal update policy π * , and then project the found policy into the parameterized policy space Π θ , by solving the closest * Strategy π θ ∈Π θ To obtain Therefore, the objective function optimized in the first step of this patent is as follows:
[0055]
[0056]
[0057]
[0058] in, Since the optimization problem satisfies strong duality, it can be solved by solving the corresponding dual problem, that is,
[0059]
[0060] in There is a duality, as follows
[0061] p * =max π∈Π min λ,v≥0 L(π,λ,v)=min λ,v≥0 max π∈Π L(π,λ,v)#(2-4)
[0062] Solving the above formula, we can get:
[0063]
[0064] Substituting formula (2-5) into formula (2-4), we can get:
[0065]
[0066] Since we allow π to be in the set of all strategies π, we get π * Not necessarily in the parameterized strategy space Π θ and we may not be able to * Therefore, in the second step, we project the optimal update policy back to the parameterized policy space by minimizing the loss function, that is, minimizing the following objective function:
[0067]
[0068] Here π θ ∈Π θ are some projection strategies, which are used to approximate the optimal update strategy. By deriving formula (2-7), we can get:
[0069]
[0070] in,
[0071]
[0072] Formula (2-7) can be obtained by This allows the policy to be trained using stochastic gradients. We start by collecting data with it, and then use that data and formula (2-6) to first estimate λ and v. We then sample a mini-batch from the data to estimate After updating the gradient according to formula (2-8), the process is repeated.
[0073] Since v needs to be adjusted continuously during training to meet the cost constraint, v can be determined based on the heuristic of the original dual gradient method. First, through strong duality, the optimal λ and v minimize the dual function formula (2-4), which is expressed here as L(π * ,λ,v). Then we can apply gradient descent to minimize vL(π * ,λ,v), we can calculate L(π * The derivative of (λ, v) with respect to v is as follows:
[0074]
[0075] Through the constraint formula (2-3), it is easy to know With π * Make it very close, so Therefore, the update formula of v is as follows:
[0076]
[0077] Experimental data analysis:
[0078] The present invention first trained the model in a simulation environment for 500 rounds and recorded the average cost and average reward during the training process. Then, the trained model was tested in the simulation environment for 1000 rounds and the cost and actions of the agent during the test were collected. Finally, the data in the experiment were visualized and analyzed. Figure 2 shown.
[0079] from Figure 2 As can be seen in a, the reward grows steadily with the training iterations, at the cost of a short increase at the beginning and then a steady decrease, which shows the effectiveness of our training method. Figure 2 b is the statistical distribution of the cost data in the test, where the red line is the cost threshold we set. After calculation, the number of costs exceeding the threshold accounts for 4.98% of the total, while the number exceeding 49 (that is, TTC is less than 1, which is a very dangerous state and the possibility of collision is very high) accounts for only 0.068%. Figure 2c is the statistical distribution of the acceleration and steering angle data collected during the test.
[0080] The present invention designs a reward function and a cost function, wherein the reward function is used to measure driving efficiency, and its design is mainly considered from the perspective of speed and collision. The greater the speed, the greater the reward, but if a collision occurs, the corresponding penalty will also be greater. The cost function is designed to measure the safety of the current driving state. The cost function is obtained by transforming TTC. If the TTC is small, it means that the current state is unsafe, and the cost will be higher.
[0081] The present invention constructs the modeling goal of driving behavior as an optimization problem with safety constraints, and the goal is to find the most efficient driving strategy in a safe strategy space. This patent first converts the constrained optimization problem into an equation through the Lagrangian method, and then converts the maximum-minimum optimization problem into a minimum-maximum optimization problem through strong duality to facilitate the solution of the optimal strategy. Since we cannot directly sample the optimal strategy, it is necessary to use gradient updates based on the current parameterized strategy to gradually approach the optimal strategy. Because the updated strategy must be in the parameterized space where the old strategy is located, this patent uses KL divergence to measure the distance between the new and old strategies. If the distance between the two is greater than the threshold, the current round of updates is stopped.
[0082] The above is only a preferred embodiment of the present invention, and the protection scope of the present invention is not limited to the above embodiments. All technical solutions under the concept of the present invention belong to the protection scope of the present invention. It should be pointed out that for ordinary technicians in this technical field, some improvements and modifications without departing from the principle of the present invention should also be regarded as the protection scope of the present invention.
Claims
1. A safe traffic flow generation method, Its characteristics are: The steps include: S1, Traffic flow simulation environment modeling; S2, online data collection; S3. Safe traffic flow driving behavior modeling: First collect training data using the current strategy, and then collect batch data from the data to update the value network, cost network, and policy network.
2. A safe traffic flow generation method according to claim 1, Its characteristics are: Online data collection includes environment status, rewards, and costs.
3. A safe traffic flow generation method according to claim 2, Its characteristics are: In step S3, safe traffic flow driving behavior modeling includes reward function and cost function design; The design of the reward function is mainly based on speed and collision. The greater the speed, the greater the reward. Correspondingly, the greater the speed, the greater the penalty if a collision occurs. The following function input is speed (m / s); Among them, speed reward: Collision Rewards:
4. A safe traffic flow generation method according to claim 3, Its characteristics are: cost It is mainly considered from the perspective of TTC. If the TTC between the main vehicle and the front vehicle is smaller, it means that the possibility of collision between the main vehicle and the front vehicle is greater, so the cost is greater. The following formula ego represents the main vehicle, front vehicle ego Indicates the vehicle in front of the main vehicle; Cost(ego,front ego )=50-min(50,TTC(ego,front ego ))。 5. A safe traffic flow generation method according to claim 4, Its characteristics are: In step S3, the safe traffic flow driving behavior modeling also includes a modeling training process, the steps are as follows: (1) Initialize the policy network π θ , Value Network V φ , price network Generalized advantage estimator (GAE) parameters β, discount rate γ, learning rate α v , α V , α π , temperature coefficient λ, initial cost constraint parameter ν, cost constraint upper bound v max , confidence region threshold δ, cost threshold b; (2) First use strategy π θ , generate(s i,t , a i,t , r i,t ,s i,t+1 , c i,t ) data, where the total number of rounds is M, each round has T data, i = 1, ..., M, t = 1, ..., T, and then the cost return is estimated by averaging the cost returns of all rounds, Secondly, GAE is used to estimate the advantage function And calculate the target value and target cost based on the value network and cost network Finally, update the cost constraint parameter v according to the formula; (3) First, sample a batch of data of size B from the data generated in step (2) Then, the value network and the cost network are updated according to the value network loss function and the cost network loss function respectively, and finally the strategy network π is updated according to the formula θ ; (4) Loop through step (3) times, if Then jump out of the loop; (5) Loop through step (3) 4K times to complete one round of network update; (6) Loop through steps (2) to (5) Num Epochs times to complete algorithm training.
6. A safe traffic flow generation method according to claim 5, Its characteristics are: The update formula of the cost constraint parameter v in step (2) is:
7. A safe traffic flow generation method according to claim 5, Its characteristics are: In step (3), the policy network π θ The update announcement is:
8. A safe traffic flow generation method according to claim 5, Its characteristics are: The calculation formula of the value network loss function in step (3) is:
9. A safe traffic flow generation method according to claim 5, Its characteristics are: The calculation formula of the cost network loss function in step (3) is:
