-
Notifications
You must be signed in to change notification settings - Fork 1
/
func.js
305 lines (278 loc) · 13.7 KB
/
func.js
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
var M = 10000,v_max = 10, t0 = 0, t1 = 45, t2 = 450, t3 = 495, t4 = 945, t5 = 990, t6 = 1395, t7 = 1440, step=15,tt=705;
function velocity_middle(M,v_max,t0,t1,t2,t3,t4,t5,t6,t7) {
var temp;
var d1 = t1 - t0;
var d2 = t3 - t2;
var d3 = t5 - t4;
var d4 = t7 - t6;
temp = M / (1440 - (d1 + d2 + d3 + d4));
//console.log(temp);
return temp;
}
var v_mid=velocity_middle(M,v_max,t0,t1,t2,t3,t4,t5,t6,t7);
var n=1440/step;
function check_velocity(v_max,v_mid ){
if (v_mid > v_max) return 1;
else return 0;
}
// x_et, y_et - массивы
function etalon_coords(M,t0,t1,t2,t3,t4,t5,t6,t7,step,n,v_mid,x_et,y_et){
var d1 = t1 - t0;
var d2 = t3 - t2;
var d3 = t5 - t4;
x_et[0] = t0; y_et[0] = 0;
for (var i = 1; i <= n; i++)
{
x_et[i] = x_et[i - 1] + step;
//если попадаем во время простоев, то остаётся константа
if (((x_et[i] > t0) && (x_et[i] < t1)) || ((x_et[i] > t2) && (x_et[i] < t3)) || ((x_et[i] > t4) && (x_et[i] < t5)) || ((x_et[i] > t6) && (x_et[i] <= t7)))
{
y_et[i] = y_et[i - 1];
}
if ((x_et[i] >= t1) && (x_et[i] <= t2)) y_et[i] = v_mid*(x_et[i] - d1);
if ((x_et[i] >= t3) && (x_et[i] <= t4)) y_et[i] = v_mid*(x_et[i] - d1 - d2);
if ((x_et[i] >= t5) && (x_et[i] <= t6)) y_et[i] = v_mid*(x_et[i] - d1 - d2 - d3);
//y_et[n] = M;
}
//console.log(x_et);
//console.log(y_et);
}
//etalon_coords(5000,40,60,130,250,560,630,890,1000,15,97,4,[],[]);
// x_model, y_model - массивы
function simulated_coords(t0,t1, t2, t3, t4, t5, t6, t7, n, step, v_mid, v_max, x_model, y_model){
x_model[0] = t0; y_model[0] = 0;
var i, last_value = v_mid*step;
var first_value = step;
var v, v_up;
for (i = 1; i <= n; i++)
{
//srand(time(0));
x_model[i] = x_model[i - 1] + step;
//если попадаем во время простоев, то остаётся константа
if (((x_model[i] > t0) && (x_model[i] < t1)) || ((x_model[i] > t2) && (x_model[i] < t3)) || ((x_model[i] > t4) && (x_model[i] < t5)) || ((x_model[i] > t6) && (x_model[i] <= t7)))
{
y_model[i] = y_model[i - 1];
}
else
{
y_model[i] = y_model[i - 1] + first_value + Math.random()*( last_value - 0);//обычное рандомное вычисление следующей производительности
if ((x_model[i] <= t2) && (x_model[i] >= t1))// если попадаем во время работы первой смены
{ //текущее значение вработки меньше эталонного
if (y_model[i]<v_mid*(x_model[i] - (t1 - t0)))//необходимо увеличение скорости в узле
{ //текущая скорость в узле
v = (y_model[i] - y_model[i - 1]) / step;
//если текущая скорость меньше максимальной то пересчитываем оптимальную скорость, либо увеличиваем до максимума
if (v<v_max)
{
v_up = (v_mid *(x_model[i] - (t1 - t0)) - y_model[i - 1]) / step;
//если оптимальная скосрость получается больше максимальной, то увеличиваем до максимума
if (v_up>v_max) v_up = v_max;
}
else v_up = v_max;
//корректировка выработки на следующем шаге
y_model[i] = y_model[i - 1] + v_up*step;
}
}
if ((x_model[i] <= t4) && (x_model[i] >= t3))//если попадаем во время работы второй смены
{ //текущее значение вработки меньше эталонного
if (y_model[i] < v_mid*(x_model[i] - ((t1 - t0) + (t3 - t2))))//необходимо увеличение скорости в узле
{ //текущая скорость в узле
v = (y_model[i] - y_model[i - 1]) / step;
//если текущая скорость меньше максимальной то пересчитываем оптимальную скорость, либо увеличиваем до максимума
if (v < v_max)
{
v_up = (v_mid * (x_model[i] - ((t1 - t0) + (t3 - t2))) - y_model[i - 1]) / step;
//если оптимальная скосрость получается больше максимальной, то увеличиваем до максимума
if (v_up > v_max) v_up = v_max;
}
else v_up = v_max;
//корректировка выработки на следующем шаге
y_model[i] = y_model[i - 1] + v_up*step;
}
}
if ((x_model[i] <= t6) && (x_model[i] >= t5))//если попадаем во время работы третьей смены
{ //текущее значение вработки меньше эталонного
if (y_model[i] < v_mid*(x_model[i] - ((t1 - t0) + (t3 - t2) + (t5 - t4))))//необходимо увеличение скорости в узле
{ //текущая скорость в узле
v = (y_model[i] - y_model[i - 1]) / step;
//если текущая скорость меньше максимальной то пересчитываем оптимальную скорость, либо увеличиваем до максимума
if (v < v_max)
{
v_up = (v_mid * (x_model[i] - ((t1 - t0) + (t3 - t2) + (t5 - t4))) - y_model[i - 1]) / step;
//если оптимальная скосрость получается больше максимальной, то увеличиваем до максимума
if (v_up > v_max) v_up = v_max;
}
else v_up = v_max;
//корректировка выработки на следующем шаге
y_model[i] = y_model[i - 1] + v_up*step;
}
}
}
}
}
function correction_production( M_act, t, M, t0, t1, t2, t3, t4, t5, t6, t7, v_max, v_mid, step, n, v_up, dM, y_pro){
//console.log(v_up, dM);
var v, v_pro;
var k = t/step;
//console.log(t);
//console.log(k);
var d1 = t1 - t0;
var d2 = t3 - t2;
var d3 = t5 - t4;
var d4 = t7 - t6;
//если попадаем в первый простой
if ((t >= t0) && (t < t1))
{
v_pro = (M - M_act) / (1440 - t - (t1 - t) - d2 - d3 - d4);
dM = 0.0 ;
if (M_act<dM)
{
dM -= M_act, v_up = 0.0 ;
}
else { dM = 0.0; v_up = 0.0 ; }
}
//если попадаем во второй простой
if ((t > t2) && (t < t3))
{
v_pro = (M - M_act) / (1440 - t - (t3 - t) - d3 - d4);
dM = v_mid*(t - (t1 - t0));
if (M_act<dM)
{
dM -= M_act, v_up = 0.0 ;
}
else { dM = 0.0 ; v_up = 0.0 ; }
}
//если попадаем в третий простой
if ((t > t4) && (t < t5))
{
v_pro = (M - M_act) / (1440 - t - (t5 - t) - d4);
dM = v_mid*(t - ((t1 - t0) + (t3 - t2)));
if (M_act<dM)
{
dM -= M_act, v_up = 0.0 ;
}
else { dM = 0.0 ; v_up = 0.0 ; }
}
//если попадаем в четвёртый простой
if ((t > t6) && (t <= t7))
{
v_pro = 0;//уже не работаем
dM = v_mid*(t - ((t1 - t0) + (t3 - t2) + (t5 - t4)));
if (M_act<dM)
{
dM -= M_act, v_up = 0.0 ;
}
else { dM = 0.0 ; v_up = 0.0 ; }
}
// если попадаем во время работы первой смены
if ((t <= t2) && (t >= t1))
{
v_pro = (M - M_act) / (1440 - t - d2 - d3 - d4);
//текущее значение вработки меньше эталонного
dM = v_mid*(t - (t1 - t0));
//текущая скорость в узле
v = M_act / (t - (t1 - t0));
if (M_act<dM)//необходимо увеличение скорости в узле
{ //если текущая скорость меньше максимальной то пересчитываем оптимальную скорость, либо увеличиваем до максимума
if (v<v_max)
{
v_up = (v_mid *(t + step - (t1 - t0)) - M_act) / step;
//если оптимальная скосрость получается больше максимальной, то увеличиваем до максимума
if (v_up>v_max) v_up = v_max;
}
else v_up = v_max;
//разница выработки на текущем шаге
dM -= M_act;
}
else
{
dM = 0.0 ; v_up = 0.0 ;
}
}
//если попадаем во время работы второй смены
if ((t <= t4) && (t >= t3))
{
v_pro = (M - M_act) / (1440 - t - d3 - d4);
//текущее значение вработки меньше эталонного
dM = v_mid*(t - ((t1 - t0) + (t3 - t2)));
//текущая скорость в узле
v = M_act / (t - ((t1 - t0) + (t3 - t2)));
if (M_act<dM)//необходимо увеличение скорости в узле
{ //если текущая скорость меньше максимальной то пересчитываем оптимальную скорость, либо увеличиваем до максимума
if (v<v_max)
{
v_up = (v_mid *(t + step - ((t1 - t0) + (t3 - t2))) - M_act) / step;
//если оптимальная скосрость получается больше максимальной, то увеличиваем до максимума
if (v_up>v_max) v_up = v_max;
}
else v_up = v_max;
//разница выработки на текущем шаге
dM -= M_act;
}
else
{
dM = 0.0 ; v_up = 0.0 ;
}
}
//если попадаем во время работы третьей смены
if ((t <= t6) && (t >= t5))
{
v_pro = (M - M_act) / (1440 - t - d4);
//текущее значение вработки меньше эталонного
dM = v_mid*(t - ((t1 - t0) + (t3 - t2) + (t5 - t4)));
//текущая скорость в узле
v = M_act / (t - ((t1 - t0) + (t3 - t2) + (t5 - t4)));
if (M_act<dM)//необходимо увеличение скорости в узле
{ //если текущая скорость меньше максимальной то пересчитываем оптимальную скорость, либо увеличиваем до максимума
if (v<v_max)
{
v_up = (v_mid *(t + step - ((t1 - t0) + (t3 - t2) + (t5 - t4))) - M_act) / step;
//если оптимальная скосрость получается больше максимальной, то увеличиваем до максимума
if (v_up>v_max) v_up = v_max;
}
else v_up = v_max;
//разница выработки на текущем шаге
dM -= M_act;
}
else
{
dM = 0.0 ; v_up = 0.0 ;
}
}
var f = false;
if (v_pro>v_max)
{
v_pro = v_max;
f = true;
}
y_pro[k] = M_act;
//console.log(y_pro[k]);
for (var i = k + 1; i <= n; i++)//цикл для вичисления координат "хвоста" эталона, начиная с текущего момента
{
t += step;
if (((t > t0) && (t <= t1)) || ((t > t2) && (t <= t3)) || ((t > t4) && (t <= t5)) || ((t > t6) && (t <= t7)))
{
y_pro[i] = y_pro[i - 1];
}
if ((t > t1) && (t <= t2)) y_pro[i] = y_pro[i - 1] + v_pro*step;
if ((t > t3) && (t <= t4)) y_pro[i] = y_pro[i - 1] + v_pro*step;
if ((t > t5) && (t <= t6)) y_pro[i] = y_pro[i - 1] + v_pro*step;
//else y_pro[i] = y_pro[i - 1] + v_pro*step;
//if (y_pro[i]>M) y_pro[i]=M;
//console.log(dM, );
}
console.log(v_up, dM);
if(f) {
var res_str3 = '{' + '\"' + 'dM' + '\":\"' + dM.toFixed(0) + '\",' + '\"' + 'v_pro' + '\":\"' + " Недостижима " + '\"' + '}';
return res_str3
}
var res_str3 = '{'+ '\"' + 'dM' + '\":\"' + dM.toFixed(0) +'\",' + '\"' + 'v_pro' + '\":\"' + v_pro.toFixed(1) +'\"' + '}';
//console.log(res_str3);
return res_str3;
//return y_pro[i];
}
//correction_production( 2000, 120, 40,60,130,250,560,630,890,1000, 10000, 4000, 15, 0.0, 0.0);
module.exports.velocity_middle = velocity_middle;
module.exports.etalon_coords = etalon_coords;
module.exports.simulated_coords = simulated_coords;
module.exports.correction_production = correction_production;