-
Notifications
You must be signed in to change notification settings - Fork 1
/
multipleRunsWithStochasticCapacity.m
110 lines (97 loc) · 4.09 KB
/
multipleRunsWithStochasticCapacity.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
%% Presentation
% This script launches a bottleneck simulation with a continuum of users and stochastic capacity.
% Last modified by Raphael Lamotte, on October 24, 2018.
clear all
close all
path(genpath(cd),path);
% Define the population of users
% population=generateSPabg();%
tstar=0;
N=1;
% Define some technical settings
lambda=10^(-2);
settings.maxIter=2*10^6;
settings.display='off'; %'on' 'off' 'final'
settings.additionalPlots='off';
settings.knownEq=0; % should only set to a positive value if Iryo's method apply (morning commute with identical alpha).
% Define some mode-specific parameters
departureTimes=-2:1/60:2;
ini=ones(N,length(departureTimes))/N/length(departureTimes); % initial distribution of departures
revisionProtocol.exponent=1;
revisionProtocol.fun=@(R,U,lambda)SmithRevisionProtocolExponent(R,U,lambda,revisionProtocol.exponent);
revisionProtocol.rate=lambda/length(departureTimes);
set(groot, 'defaultAxesTickLabelInterpreter','latex');
set(groot, 'defaultLegendInterpreter','latex');
set(groot, 'defaultTextInterpreter','latex');
% define multiple capacities.
% Run individual simulation with each of them
% Run one with stochastic, and plot all potential gains.
std=[0.1,0.2];
w=[4,1];
% std=[0.2];
% w=[1];
AllCumShifts=cell(length(std),length(w));
AllLyap=cell(length(std),length(w));
AllCumShiftsDet=cell(length(std),length(w),21);
AllLyapDet=cell(length(std),length(w),21);
for ind_std=1:length(std)
for ind_w=1:length(w)
population=generateSParctan(tstar,0.5,1.5,1,w(ind_w));%
Capacity=0.5*(1-std(ind_std):std(ind_std)/10:1+std(ind_std));
congestion=generateBottleneck(Capacity);
[finalState,hist]=runIterationsContinuumStochasticWhile(departureTimes,settings,congestion,population,revisionProtocol,ini);
% % figure(1)
% % subplot(length(std),length(w),ind_w+(ind_std-1)*length(w))
% % plot(1:settings.maxIter,hist.potGain,'r');
% % hold on
%
% figure(2)
% subplot(length(std),length(w),ind_w+(ind_std-1)*length(w))
% x=cumsum(hist.shifts);
% y=hist.Lyap;
% plot(x(1:end),y(1:end),'r');
% hold on
AllCumShifts{ind_std,ind_w}=cumsum(hist.shifts);
AllLyap{ind_std,ind_w}=hist.Lyap;
%
% xlabel('Average decision updates');
% ylabel('Net gain');
% xlim([0,5]);
% title(['$w=',num2str(w(ind_w)),', \Delta S=\pm',num2str(100*std(ind_std)),'\%$']);
if (ind_std==length(std) && ind_w==length(w))
% figure(3)
% plot(finalState.t',finalState.n');
% xlabel('Time');
% ylabel('Queue length');
%
% figure(4)
% plot(departureTimes,hist.R(:,:,end),'r');
% xlabel('Time');
% ylabel('departure rate');
t_stoch=finalState.t';
n_stoch=finalState.n';
R_stoch=hist.R(:,:,end);
ta_stoch=finalState.ta';
end
for i=1:10:length(Capacity)
congestion=generateBottleneck(Capacity(i));
[finalState,hist]=runIterationsContinuumStochasticWhile(departureTimes,settings,congestion,population,revisionProtocol,ini);
% % figure(1)
% % subplot(length(std),length(w),ind_w+(ind_std-1)*length(w))
% % plot(1:settings.maxIter,hist.potGain,':k');
% % hold on
% figure(2)
% x=cumsum(hist.shifts);
% y=hist.Lyap;
% subplot(length(std),length(w),ind_w+(ind_std-1)*length(w))
% plot(x(1:end),y(1:end),'k');
% hold on
AllCumShiftsDet{ind_std,ind_w,i}=cumsum(hist.shifts);
AllLyapDet{ind_std,ind_w,i}=hist.Lyap;
end
end
end
% subplot(length(std),length(w),1)
% legend({'Stochastic','Deterministic'});
% save("workspace_stochasticity")
save("workspace_stochasticity_light2",'std','w','AllCumShifts','AllLyap','AllCumShiftsDet','AllLyapDet','t_stoch','n_stoch','R_stoch','ta_stoch','departureTimes','Capacity')