python - Car Following Model with Optimal Velocity function - overtake occurence -
i creating project on car simulations , i've run problem. when run code, cars overtake 1 another.
i have spent few days trying figure out why happening , still have no idea. optimal velocity function should set (de)acceleration, overtake not happen, reason, still allows cars overatake each other , not decelerate fast enough.
could me, or push me in direction should looking ?
here optimal velocity function:
def optimal_velocity_function(dx, d_safe, v_max): vx_opt = v_max * (np.tanh(dx - d_safe) + np.tanh(d_safe)) return vx_opt
now using within euler's method solve ode:
def euler_method(x, v, n_cars, h, tau, d_safe, v_max): # euler method used solve ode # returns new position of car , new velocity dv = np.zeros(n_cars) j in range(n_cars - 1): dv[j] = tau ** (-1) * (optimal_velocity_function(x[j+1] - x[j], d_safe, v_max) - v[j]) dv[n_cars - 1] = tau ** (-1) * (v_max - v[n_cars - 1]) # speed of first car v_new = v + h * dv x_new = x + h * v_new return [x_new, v_new]
and here rest of model, generating starting values , iterating using functions above.
def optimal_velocity_model(n, n_cars, d_0, v_0, h, tau, d_safe, v_max): global x_limit, canvas, xx, vv car_positions = np.linspace(0, n_cars, n_cars) x = np.array(sorted(np.random.random(n_cars) + car_positions)) # generation of cars minimal distance x = x * d_0 v = np.random.random(n_cars) + v_0 # generating initial speeds around v_0 xx = np.zeros([n_cars, n]) # matrix of locations vv = np.zeros([n_cars, n]) # matrix of velocities in range(n): xx[:, i] = x vv[:, i] = v [x, v] = euler_method(x, v, n_cars, h, tau, d_safe, v_max) x_limit = xx.max() # interval in cars return
thanks lot. j.
i think getting bit lost here maths , not focusing on physics of problem. using tanhh on delta x
safe distance generating soft speed transition might not guarantee overtaking inhibited.
my train of thought like:
firstly assess relative speed of 2 vehicles approaching safety distance
define minimum deceleration given vehicle properties can stop within distance
use tanhh or other function model transition between aggressive smooth braking or viceversa.
update speed integrating acceleration.
to calculate deceleration can think of simple approach keep use of tanh :
deceleration=max_dec(relative_speed)*[1+tanh(d_safe-dx)]
hope can guide further!
Comments
Post a Comment