-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdater.py
173 lines (147 loc) · 7.28 KB
/
updater.py
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
import numpy as np
from utils import Unit
D = 10000
DD = 1000
def generate_V(X, best_X, grp_size, max_cft_pkt):
V = Unit(grp_size, max_cft_pkt)
V.mal = best_X.mal - X.mal
for i in range(grp_size):
for j in range(int(round(X.mal[i][1]))):
V.craft[i][j] = best_X.craft[i][j] - X.craft[i][j]
return V
def update_X(X, V, grp_size, max_cft_pkt, last_end_time, groupList,
max_time_extend, proto_max_lmt):
last_end_time = float(last_end_time)
max_mal_itv = (float(groupList[-1].time) -
last_end_time) * (max_time_extend + 1)
mal_itv_lmt = max_mal_itv / D
# mal_itv_lmt = 0
for i in range(grp_size):
targt_time = X.mal[i][0] + V.mal[i][0]
if i == 0:
if targt_time < last_end_time + mal_itv_lmt:
X.mal[i][0] = last_end_time + mal_itv_lmt
elif grp_size > 1:
if targt_time > X.mal[i + 1][0] - mal_itv_lmt:
X.mal[i][0] = X.mal[i + 1][0] - mal_itv_lmt
else:
X.mal[i][0] = targt_time
else:
X.mal[i][0] = targt_time
elif i == grp_size - 1:
if targt_time < X.mal[i - 1][0] + mal_itv_lmt:
X.mal[i][0] = X.mal[i - 1][0] + mal_itv_lmt
elif targt_time > (last_end_time + max_mal_itv) - mal_itv_lmt:
X.mal[i][0] = (last_end_time + max_mal_itv) - mal_itv_lmt
else:
X.mal[i][0] = targt_time
else:
if targt_time < X.mal[i - 1][0] + mal_itv_lmt:
X.mal[i][0] = X.mal[i - 1][0] + mal_itv_lmt
elif targt_time > X.mal[i + 1][0] - mal_itv_lmt:
X.mal[i][0] = X.mal[i + 1][0] - mal_itv_lmt
else:
X.mal[i][0] = targt_time
for i in range(grp_size):
if V.mal[i][1] < 0:
X.mal[i][1] += V.mal[i][1]
if X.mal[i][1] < 0:
X.mal[i][1] = 0.
else:
if X.mal[i][1] + V.mal[i][1] > max_cft_pkt:
ics_cft_num = max_cft_pkt - round(X.mal[i][1])
targt_cft_num = max_cft_pkt
else:
ics_cft_num = round(X.mal[i][1] + V.mal[i][1]) - round(
X.mal[i][1])
targt_cft_num = X.mal[i][1] + V.mal[i][1]
for j in range(int(ics_cft_num)):
if round(X.mal[i][1]) == 0:
if i == 0:
itv = X.mal[i][0] - last_end_time
else:
itv = X.mal[i][0] - X.mal[i - 1][0]
else:
itv = X.craft[i][int(round(X.mal[i][1])) - 1][0]
X.craft[i][int(round(X.mal[i][1])) +
j][0] = (itv / ics_cft_num) * (j + 1)
X.mal[i][1] = targt_cft_num
for i in range(grp_size):
targt_itv = X.craft[i][0][0] + V.craft[i][0][0]
if i == 0:
cft_itv_lmt = (X.mal[i][0] - last_end_time) / DD
if round(X.mal[i][1]) == 1:
if X.mal[i][0] - targt_itv < last_end_time + cft_itv_lmt:
X.craft[i][0][0] = X.mal[i][0] - (last_end_time +
cft_itv_lmt)
elif targt_itv < cft_itv_lmt:
X.craft[i][0][0] = cft_itv_lmt
elif round(X.mal[i][1]) > 1:
for j in range(int(round(X.mal[i][1]))):
if j == 0:
if X.mal[i][
0] - targt_itv < last_end_time + cft_itv_lmt:
X.craft[i][j][0] = X.mal[i][0] - (last_end_time +
cft_itv_lmt)
elif targt_itv < X.craft[i][j + 1][0] + cft_itv_lmt:
X.craft[i][j][0] = X.craft[i][j +
1][0] + cft_itv_lmt
elif j == round(X.mal[i][1]) - 1:
if targt_itv > X.craft[i][j - 1][0] - cft_itv_lmt:
X.craft[i][j][0] = X.craft[i][j -
1][0] - cft_itv_lmt
elif targt_itv < cft_itv_lmt:
X.craft[i][j][0] = cft_itv_lmt
else:
if targt_itv > X.craft[i][j - 1][0] - cft_itv_lmt:
X.craft[i][j][0] = X.craft[i][j -
1][0] - cft_itv_lmt
elif targt_itv < X.craft[i][j + 1][0] + cft_itv_lmt:
X.craft[i][j][0] = X.craft[i][j +
1][0] + cft_itv_lmt
else:
cft_itv_lmt = (X.mal[i][0] - X.mal[i - 1][0]) / DD
if round(X.mal[i][1]) == 1:
if X.mal[i][0] - targt_itv < X.mal[i - 1][0] + cft_itv_lmt:
X.craft[i][0][0] = X.mal[i][0] - (X.mal[i - 1][0] +
cft_itv_lmt)
elif targt_itv < cft_itv_lmt:
X.craft[i][0][0] = cft_itv_lmt
elif round(X.mal[i][1]) > 1:
for j in range(int(round(X.mal[i][1]))):
if j == 0:
if X.mal[i][0] - targt_itv < X.mal[i -
1][0] + cft_itv_lmt:
X.craft[i][j][0] = X.mal[i][0] - (X.mal[i - 1][0] +
cft_itv_lmt)
elif targt_itv < X.craft[i][j + 1][0] + cft_itv_lmt:
X.craft[i][j][0] = X.craft[i][j +
1][0] + cft_itv_lmt
elif j == round(X.mal[i][1]) - 1:
if targt_itv > X.craft[i][j - 1][0] - cft_itv_lmt:
X.craft[i][j][0] = X.craft[i][j -
1][0] - cft_itv_lmt
elif targt_itv < cft_itv_lmt:
X.craft[i][j][0] = cft_itv_lmt
else:
if targt_itv > X.craft[i][j - 1][0] - cft_itv_lmt:
X.craft[i][j][0] = X.craft[i][j -
1][0] - cft_itv_lmt
elif targt_itv < X.craft[i][j + 1][0] + cft_itv_lmt:
X.craft[i][j][0] = X.craft[i][j +
1][0] + cft_itv_lmt
proto_min_lmt = 1.
data_max_lmt = [np.nan, 1500., 1480., 1460.]
data_min_lmt = 0.
for i in range(grp_size):
for j in range(int(round(X.mal[i][1]))):
if X.craft[i][j][1] < proto_min_lmt:
X.craft[i][j][1] = proto_min_lmt
elif X.craft[i][j][1] > proto_max_lmt[i]:
X.craft[i][j][1] = proto_max_lmt[i]
X.craft[i][j][2] += V.craft[i][j][2]
if X.craft[i][j][2] < data_min_lmt:
X.craft[i][j][2] = data_min_lmt
elif X.craft[i][j][2] > data_max_lmt[int(round(X.craft[i][j][1]))]:
X.craft[i][j][2] = data_max_lmt[int(round(X.craft[i][j][1]))]
return X