NagelSchreckenbergモデルシミュレーションのソースコード

1.問題の説明:

 NagelSchreckenbergモデルシミュレーションのソースコード

2.プログラムの一部:

 

clc;
晴れ;
すべて閉じる;

%Parameters
vmax = 6;
p = 0.6;
road_length = 40;
Simulation_steps = 400;
render_on = 0;
pause_on = 0;
delay_on = 0;
delay_length = 0.05; %10 FPS

road = zeros(1、road_length); %職業状態が含まれています
road_next = road;
速度= zeros(1、road_length); %速度状態が含まれています
velocities_next = velocities;

%Sampling
num_samples = 200;
サンプル= zeros(2、num_samples); %密度と流量が含まれています
density_step = 1 / num_samples;

history = zeros(simulation_steps、road_length);
speed_history = zeros(simulation_steps、road_length);

for g = 1:num_samples
    
    %Generate traffic
    road = zeros(1、road_length); %職業状態が含まれています
    road_next = road;
    密度= g / num_samples;
    
    %     rand <density         road(i)= 1の場合 
    
、i = 1:road_lengthのトラフィック生成します     エンドエンド



    render_on
    imshow(road);の場合
    drawow
    end
    
    %
i = 1:simulation_stepsのシミュレーション実行します
    history(i、:) = road;
    speed_history(i、:)=速度;
           %--------------------速度の更新------------------------%
    for j = 1:road_length
       if road(j)== 1
           距離= 0;
           %先にvmaxを探す
           bf = 0;
           k = 1の場合:vmax
               距離= k;
              
               if j + k <= road_length%インデックスは「検討中のセル」です-ここに着陸しても安全ですか?
                   インデックス= j + k;
               そうしないと
                   インデックス= j + k-road_length;                road(index)== 1                    bf = 1の場合 、ラッピング
               終了を処理します。                終了            ifbf                == 1、ブレーク、終了            終了if velocities(j)<vmax%Acceleration                velocities(j)= velocities(j)+ 1;            end            if(velocities(j)> distance-1)&& bf == 1%衝突回避                velocities(j)= distance-1;            rand <p && velocities(j)> 0%の場合に            終了ランダムブレーキ                速度(j)= velocities(j)-1;            エンド        エンド     エンド
               



               


            



           



           



           
           


    
    %--------------------動き---------------------------- ---%
    for j = 1:road_length
        if road(j)== 1
            if j + velocities(j)<= road_length
                index = j + velocities(j);
            else
                index = j + velocities(j)-road_length; %ラッピング
            終了を処理します
            %
            road_next(index)== 1の場合の衝突検出
                disp( '衝突検出')
            end
            road_next(index)= 1;
            velocities_next(index)= velocities(j);
        end
    end
    
    velocities = velocities_next;
    
    road = road_next;
    road_next = zeros(1、road_length);
    
    render_on
    imshow(road);の場合
    関数drawnowの
    端
    
    pause_onの場合
        休止
    端
    
    delay_onの場合
        休止(delay_length)
    エンド
    
エンド

3.シミュレーションの結論:

B-0036

おすすめ

転載: blog.csdn.net/ccsss22/article/details/114746103