-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGraph5.m
141 lines (123 loc) · 4.72 KB
/
Graph5.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
%close all
clear all
%Switch the comments to switch between stopping point methods
%stoppingEq = @(x) ceil(x/exp(1));
stoppingEq = @(x) round(sqrt(x));
%stoppingEq = @(x) 0.7 * round(sqrt(x));
alpha = 0.875;
beta = 0.75;
startSecretary = 0.4:0.05:0.75;
startCritical = 0.8;
%Number of real highways you have
numSim = 151;
successes = 0;
total = 0;
rates(1:length(startSecretary), 1:length(startCritical), 1:numSim) = 10;
stops(1:length(startSecretary), 1:length(startCritical), 1:numSim) = 10;
for simNum = 1:numSim
%Change reallife to reallife_octave if running in octave
highway = reallife(['Trip' mat2str(simNum) '.csv']);
%highway = construct(0.2, 1000);
sorted = sort(highway(highway > 0));
goal = sorted(round(length(sorted) * 0.2));
for i = 1:length(startSecretary)
for j = 1:length(startCritical)
%Change SGAS5 to ML or ML to SGAS5
[rates(i, j, simNum), stops(i, j, simNum)] ...
= ML(highway, stoppingEq, alpha, beta,...
startSecretary(i), startCritical(j));
% [rates(i, j, simNum), trash, stops(i, j, simNum)] ...
% = SGAS4(highway, 9, stoppingEq, 2.5, alpha, beta);
if(rates(i, j, simNum) <= goal && rates(i, j, simNum) > 0)
successes = successes + 1;
%Graph success rate instead of gas rate
rates(i, j, simNum) = 1;
%disp(['Trip' mat2str(simNum) '.csv, ' mat2str(stops(i, j, simNum))])
elseif(rates(i, j, simNum) > 0)
rates(i, j, simNum) = 0;
end
total = total + 1;
end
end
end
%display(successes / total)
avgRate(1:length(startSecretary), 1:length(startCritical)) = 100;
avgStop(1:length(startSecretary), 1:length(startCritical)) = 100;
avgRunOutOfGas(1:length(startSecretary), 1:length(startCritical)) = 100;
for i = 1:length(startSecretary)
for j = 1:length(startCritical)
avgRate(i, j) = sum(rates(i, j, rates(i, j, : ) >= 0))...
/ length(rates(i, j,:));
avgStop(i, j) = sum(stops(i, j, stops(i, j, : ) > 0))...
/ length(stops(i, j, stops(i, j, : ) > 0));
avgRunOutOfGas(i, j) = -sum(rates(i, j, rates(i, j, : ) < 0))...
/ length(rates(i, j, : ));
end
end
axisColor = 'black';
%':bo'=ML ':rs'=SGAS5 ':gx'=PerfectPrediction
lineStyle = ':bo';
secretaryLabel = {"Start of Secretary Section";"(Faction of gas tank used)"};
subplot(2, 3, 3);
plot(startSecretary, mean(avgRate, 2), lineStyle);
%ylim([(min(mean(avgRate, 2))-0.05) (max(mean(avgRate, 2))+0.05)]);
ylim([0.15 0.5])
%xticks(alpha);
ylabel("Probability of getting cheap gas");
xlabel(secretaryLabel);
%title(sprintf("\\color{" + axisColor + "}k = %d", kValues(i)));
set(gca,'color','none')
set(gca,'XColor',axisColor,'YColor',axisColor)
hold on
subplot(2, 3, 1);
plot(startSecretary, mean(avgRunOutOfGas, 2), lineStyle);
%ylim([0 max(mean(avgRunOutOfGas, 2))+0.05]);
ylim([0 0.03])
%xticks(alpha);
ylabel("Probability of running out of gas");
xlabel(secretaryLabel);
%title(sprintf("\\color{" + axisColor + "}k = %d", kValues(i)));
set(gca,'color','none')
set(gca,'XColor',axisColor,'YColor',axisColor)
hold on
subplot(2, 3, 2);
plot(startSecretary, 1-mean(avgStop, 2), lineStyle);
%ylim([0.4 max(mean(avgStop, 2))+0.1]);
ylim([0.15 0.45])
%xticks(alpha);
ylabel("Percentage of gas left when refueling");
xlabel(secretaryLabel);
%title(sprintf("\\color{" + axisColor + "}k = %d", kValues(i)));
set(gca,'color','none')
set(gca,'XColor',axisColor,'YColor',axisColor)
hold on
subplot(2, 3, 4);
stem(startCritical, mean(avgRate, 1), 'Color', [1 0 0]);
ylim([(min(mean(avgRate, 1))-0.05) (max(mean(avgRate, 1))+0.05)]);
%xticks(alpha);
ylabel("Success Rate");
xlabel("Start of Critical");
%title(sprintf("\\color{" + axisColor + "}k = %d", kValues(i)));
set(gca,'color','none')
set(gca,'XColor',axisColor,'YColor',axisColor)
subplot(2, 3, 5);
stem(startCritical, mean(avgRunOutOfGas, 1), 'Color', [1 0 0]);
ylim([0 max(mean(avgRunOutOfGas, 2))+0.05]);
%xticks(alpha);
ylabel("% ran out of gas");
xlabel("Start of Critical");
%title(sprintf("\\color{" + axisColor + "}k = %d", kValues(i)));
set(gca,'color','none')
set(gca,'XColor',axisColor,'YColor',axisColor)
subplot(2, 3, 6);
stem(startCritical, mean(avgStop, 1), 'Color', [0 0 1]);
ylim([0.5 max(mean(avgStop, 2))+0.1]);
%xticks(alpha);
ylabel("% highway before stop");
xlabel("Start of Critical");
%title(sprintf("\\color{" + axisColor + "}k = %d", kValues(i)));
set(gca,'color','none')
set(gca,'XColor',axisColor,'YColor',axisColor)
%set(gcf, 'Position', [0, 950, 1076, 884])
%addpath('altmany-export_fig-b1a7288');
%export_fig fig.png -transparent