forked from KaranJagdale/Variable-Agent-NYU
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathheadwaycu.asv
More file actions
146 lines (133 loc) · 5.15 KB
/
headwaycu.asv
File metadata and controls
146 lines (133 loc) · 5.15 KB
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
142
143
144
145
146
function hw = headwaycu(state, nxt, atstop, dis_stp, v_bus, n_b,count)
hw = zeros(1,n_b);
for i=2:n_b
if atstop(i)==0 && atstop(i-1) == 0
k = 0;
if state(1,i) < state(1,i-1) || state(1,i) == state(1,i-1)
for j=state(1,i) + 1 : state(1,i-1)
k = k+dis_stp(j);
end
hw(i) = nxt(i) + k/v_bus - nxt(i-1);
else
for j=state(1,i-1) +1 : state(1,i)
k = k+dis_stp(j);
end
k = sum(dis_stp) - k;
hw(i) = nxt(i) + k/v_bus - nxt(i-1);
end
end
if atstop(i)==1 && atstop(i-1) == 0
k = 0;
if state(1,i) < state(1,i-1) || state(1,i) == state(1,i-1)
for j=state(1,i) : state(1,i-1)
k = k+dis_stp(j);
end
hw(i) = nxt(i) + k/v_bus - nxt(i-1);
else
for j=state(1,i-1) +1 : state(1,i) -1
k = k+dis_stp(j);
end
k = sum(dis_stp) - k;
hw(i) = nxt(i) + k/v_bus - nxt(i-1);
end
end
if atstop(i)==0 && atstop(i-1) == 1
k = 0;
if state(1,i) < state(1,i-1) || state(1,i) == state(1,i-1)
for j=state(1,i)+1 : state(1,i-1) -1
k = k+dis_stp(j);
end
hw(i) = nxt(i) + k/v_bus;
else
for j=state(1,i-1) : state(1,i)
k = k+dis_stp(j);
end
k = sum(dis_stp) - k;
hw(i) = nxt(i) + k/v_bus;
end
end
if atstop(i)==1 && atstop(i-1) == 1
k = 0;
if state(1,i) < state(1,i-1) || state(1,i) == state(1,i-1)
for j=state(1,i) : state(1,i-1) -1
k = k+dis_stp(j);
end
hw(i) = nxt(i) + k/v_bus;
else
for j=state(1,i-1) : state(1,i)-1
k = k+dis_stp(j);
end
k = sum(dis_stp) - k;
hw(i) = nxt(i) + k/v_bus;
end
end
end
%It is assumed that the passengers come at the bus stop for the first
%time in the day more or less at the same time. The busses are planned
%such that for the first bus, the passengers start coming to stop i
%when the bus leaves the stop i-1.
if count ==1
hw(1) = dis_stp(state(1))/v_bus;
else
if atstop(1)==0 && atstop(n_b) == 0
k = 0;
if state(1,1) < state(1,n_b) || state(1,1) == state(1,n_b)
for j=state(1,1)+1 : state(1,n_b)
k = k+dis_stp(j);
end
hw(1) = nxt(1) + k/v_bus - nxt(n_b);
else
for j = state(1,n_b)+1: state(1,1)
k = k + dis_stp(j);
end
k = sum(dis_stp) - k;
hw(1) = nxt(1) + k/v_bus - nxt(n_b);
end
end
if atstop(1)==1 && atstop(n_b) == 0
k = 0;
if state(1,1) < state(1,n_b) || state(1,1) == state(1,n_b)
for j=state(1,1) : state(1,n_b)
k = k+dis_stp(j);
end
hw(1) = nxt(1) + k/v_bus -nxt(n_b);
else
for j = state(1,n_b)+1: state(1,1)-1
k = k + dis_stp(j);
end
k = sum(dis_stp) - k;
hw(1) = nxt(1) + k/v_bus - nxt(n_b);
end
end
if atstop(1)==0 && atstop(n_b) == 1
k = 0;
if state(1,1) < state(1,n_b) || state(1,1) == state(1,n_b)
for j=state(1,1) +1 : state(1,n_b)-1
k = k+dis_stp(j);
end
hw(1) = nxt(1) + k/v_bus;
else
for j = state(1,n_b): state(1,1)
k = k + dis_stp(j);
end
k = sum(dis_stp) - k;
hw(1) = nxt(1) + k/v_bus;
end
end
if atstop(1)==1 && atstop(n_b) == 1
k = 0;
if state(1,1) < state(1,n_b) || state(1,1) == state(1,n_b)
for j=state(1,1) : state(1,n_b) -1
k = k+dis_stp(j);
end
hw(1) = nxt(1) + k/v_bus;
else
for j = state(1,n_b): state(1,1)-1
k = k + dis_stp(j);
end
k = sum(dis_stp) - k;
hw(1) = nxt(1) + k/v_bus;
end
end
end
end