-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.m
87 lines (76 loc) · 2.27 KB
/
main.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
%% Spacing continuous Cellular automata
% By Shuqinlee @ Tongji University
%% Specifications
% Car's attribution£º 1*4 matrix
% velocity v;
% distance s;
% self-driving car / normal car: 1£ºself-driving car£¬0£ºnormal car;
% Entering time.
%% main
function [i,m] = main()
clc;
clear;
close all;
B=5; % The number of the lanes
iterations=2000; %
global plazeLen; % length of path
global plaza; % all car on this cell
global acc; % acceleation
global dacc; % decrease acceleration (negative)
global vmax; % speed limit
global dt; % time step
global sd_lane; % self_driving lanes chosen
global probc; % probability to generate a car
global prob_self_car; % proportion of self-driving car
global prob_slow; % probability of random slow
global slow_acc; % decrease acceleration of random slow
global carLen; % length of car
global stream; % average daily traffic counts
global t; % time
plazeLen = 4336;
plaza = cell(B,1);
acc = 8;
dacc = -14;
vmax = 88;
dt = 0.5;
sd_lane = [0];
prob_self_car = 1;
prob_slow=0.3;
slow_acc = 0.8;
carLen = 16;
stream = 174540;
probc = stream/(24*2*7200);
out_flow = zeros(1, iterations/100);
in_flow = zeros(1, iterations/100);
cars = zeros(1000000,1);
car_ind = 1;
for t = 1: iterations
fprintf('%d \n',t);
% Step1: switch lane
switch_lane();
% Step2: move forward
out = move_forward();
out_flow(floor((t-1)/100)+1) = out_flow(floor((t-1)/100)+1)+size(out,1);
if size(out,1) ~= 0
cars(car_ind:car_ind + size(out,1)-1) = t-out(:,4);
car_ind = car_ind + size(out,1);
end
% Step3: enter new cars
cars_num = new_cars(out);
in_flow(floor((t-1)/100)+1) = in_flow(floor((t-1)/100)+1)+cars_num;
end
fprintf('= = = = = = = = = = = = = = = = = = = \nSimulation finished!\n');
figure(1)
plot(out_flow);
title('Out-flow');
figure(2);
plot(cars(1:1000));
title('Cars time');
figure(3);
plot(in_flow);
title('In-flow');
% Note: 1:1000 should be ajusted according to the car generated within
% given iterations
[i, m] = find_equilibria(cars(1:car_ind-1));
fprintf('Equilibria point: %d\nMean: %f\n',i,m);
end