AgentMarketMCP / SKILL 资产档案馆

目录 / matlabtrafficflowsimulationwithcar-followingmodels

SKILL 未评级 已上架

matlabtrafficflowsimulationwithcar-followingmodels

function simulateTrafficFlow() % 单车道交通流仿真 - 使用IDM跟驰模型 % 支持不同车辆尺寸,避免碰撞,动画显示结果 clc; clear; close all; %% 仿真参数设置 dt = 0.1; % 时间步长 (s) T_total = 60; % 总仿真时间 (s) time = 0:dt:T_total; N_cars = 10; % 车辆数量 %% 道路参数 road_length = 500; % 道路长度 (m) %% 车辆初始状态 [位置, 速度, 长度, 宽度] % 随机生成车辆长度(4.0 ~ 5.5 m),宽度固定为2.0 m car_lengths = 4.0 + 1.5 * rand(N_cars, 1); car_width = 2.0; % 初始位置:等间距排列,首车在前 initial_spacing = 30; % 初始间距 (m) x0 = zeros(N_cars, 1); for i = 1:N_cars x0(i) = (i-1) * initial_spacing; end v0 = 20 + 5*randn(N_cars, 1); % 初始速度 ~ N(20, 5^2) m/s v0 = max(v0, 5); % 最小速度限制为5 m/s % 存储状态历史 X_hist = zeros(length(time), N_cars); % 位置历史 V_hist = zeros(length(time), N_cars); % 速度历史 X_hist(1, :) = x0'; V_hist(1, :) = v0'; %% IDM 模型参数(可针对不同车辆调整) % [v0, T, a, b, s0, delta] % v0: 期望速度 (m/s), T: 安全时距 (s), a: 最大加速度 (m/s²) % b: 舒适减速度 (m/s²), s0: 最小间距 (m), delta: 加速度指数 IDM_params = [ 30, 1.5, 1.5, 2.0, 2.0, 4.0; % 普通轿车 28, 1.8, 1.2, 1.8, 2.5, 4.0; % 稍慢车辆 32, 1.4, 1.8, 2.2, 1.8, 4.0; % 激进驾驶者 ]; % 为每辆车随机分配一组IDM参数 param_idx = randi(size(IDM_params, 1), N_cars, 1); v0_desired = IDM_params(param_idx, 1); T_safe = IDM_params(param_idx, 2); a_max = IDM_params(param_idx, 3); b_comfort = IDM_params(param_idx, 4); s0_min = IDM_params(param_idx, 5); delta_acc = IDM_params(param_idx, 6); %% 主仿真循环 for t_idx = 2:length(time) x = X_hist(t_idx-1, :)'; % 当前时刻位置 v = V_hist(t_idx-1, :)'; % 当前时刻速度 % 周期性边界条件(环形道路) x = mod(x, road_length); % 排序车辆位置(按行驶方向) [x_sorted, sort_idx] = sort(x); v_sorted = v(sort_idx); len_sorted = car_lengths(sort_idx); v0_sorted = v0_desired(sort_idx); T_sorted = T_safe(sort_idx); a_sorted = a_max(...

模型生成摘要(rules/v1 · 2026-11-14 07:15):function simulateTrafficFlow()
这是模型对公开材料的总结,不是官方声明,请以原链内容为准。

存档时间线

版本存档时间内容哈希内容
v12026-11-14 07:1411d16bfe 可取

版本索引永久保留;内容副本只保留最新 1 份,更早版本仅留索引与哈希(存档时间线的证据链不会因此断裂)。

下载存档内容副本

纠错与举报(发现条目失效、署名有误或涉及侵权?)
提交举报 / 纠错

侵权举报经核验成立后,我们会即时下线该条目并删除已存的内容副本。