-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_2streets.m
55 lines (49 loc) · 1.47 KB
/
main_2streets.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
clc;
close all;
clear all;
% Anzahl Zellen bis zur Kreuzung
cellNum=100;
% Tr�delwkt
pLinger=0.30;
% Maximale geschwindigkeit
vmax=5;
% Maximale geschwindigkeit nach Stop bei Hindernis
speedStart=1;
densityH=0.30;
densityV=0.01:0.1:0.99;
timesteps=100;
sims = cell(numel(densityV, 1));
for i = 1:numel(densityV)
%% basic data
sim.timesteps = timesteps;
sim.vmax = vmax;
sim.pLinger = pLinger;
sim.densityV = densityV(i);
sim.densityH = densityH;
%% horizontale straße
[CellsH, ObstaclesH, crossingH] = init_street(cellNum, 1, densityH, vmax, timesteps);
sim.CellsH = CellsH;
sim.ObstaclesH = ObstaclesH;
sim.crossingH = crossingH;
%% vertikale straße
[CellsV, ObstaclesV, crossingV] = init_street(cellNum, 1, densityV(i), vmax, timesteps);
% Doppelbelegung der Kreuzung(en) verhindern
if( CellsV(crossingV,1,1) ~= 0)
CellsV(crossingV,1,1) = 0;
CellsV(crossingV,1,2) = 0;
end
sim.CellsV = CellsV;
sim.ObstaclesV = ObstaclesV;
sim.crossingV = crossingV;
% Anzahl der tatsaechlichen Autos
sim.numCarsV = sum(sim.CellsV(:, 1, 2) ~= 0);
sim.numCarsH = sum(sim.CellsH(:, 1, 2) ~= 0);
%% Nagelschreckenbergs Zauberalgorithmus
sim = nagelschreckenberg(sim);
sims{i} = sim;
end
% plotCars2(sims{1}.CellsH, sims{1}.CellsV, cellNum);
% plotAll(sims{1}.CellsV, cellNum);
% plotAll(sims{1}.CellsH, cellNum);
% plotAllAnimate(sims, cellNum);
plotDensity(sims.CellsH, cellNum+1);