Abstract:[Purposes] This paper aims to solve the traffic conflict of connected and autonomous vehicle (CAV) on the mainline in the ramp merge area. [Methods] An autonomous lane-changing method for CAV based on the double-deep Q network (DDQN) algorithm was proposed. First, a traffic state matrix incorporating CAV, adjacent vehicles, and on-ramp vehicles was established. Virtual vehicles were introduced to address missing dimensions in the state space, resulting in a unified matrix dimension. Second, to mitigate the negative impact of CAV lane changes on upstream traffic in the target lane, upstream vehicle speed and emergency braking characteristics were incorporated into the DDQN reward function. This enables joint optimization of individual vehicle performance and overall traffic conditions, improving lane-changing safety. Finally, the proposed method was validated by simulation experiments for a single-mainline two-lane freeway ramp merge scenario. [Findings] Compared with the lane-changing model 2013 (LC2013), the proposed method reduces the number of emergency braking events by 49.8% while ensuring CAV traffic efficiency. Compared with a baseline DDQN algorithm that does not consider the influence of following vehicles, the number of emergency braking is reduced by 15.8%. Sensitivity analysis further shows that, without reducing CAV driving speed, increasing the safety weight reduces emergency braking by 16.4% for CAVs and 46.6% for following vehicles. [Conclusions] The proposed method can effectively improve the traffic safety level of the ramp merge area while ensuring traffic efficiency.