-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathGeneralizedIterator.cpp
More file actions
858 lines (789 loc) · 19.1 KB
/
GeneralizedIterator.cpp
File metadata and controls
858 lines (789 loc) · 19.1 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
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
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
/***************************************************************************
This file is part of the Apollo Trajectory Design Program.
The Apollo Trajectory Design Program is free software: you can redistribute it
and/or modify it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
The Apollo Trajectory Design Program is distributed in the hope that it will
be useful,but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public Licensealong with
the Apollo Trajectory Design Program. If not, see <https://www.gnu.org/licenses/>.
**************************************************************************/
#include "pch.h"
#include "GeneralizedIterator.h"
namespace GenIterator
{
int LUPDecompose(double** A, int N, double Tol, int* P)
{
int i, j, k, imax;
double maxA, * ptr, absA;
for (i = 0; i <= N; i++)
P[i] = i; //Unit permutation matrix, P[N] initialized with N
for (i = 0; i < N; i++) {
maxA = 0.0;
imax = i;
for (k = i; k < N; k++)
if ((absA = fabs(A[k][i])) > maxA) {
maxA = absA;
imax = k;
}
if (maxA < Tol)
{
return 0; //failure, matrix is degenerate
}
if (imax != i) {
//pivoting P
j = P[i];
P[i] = P[imax];
P[imax] = j;
//pivoting rows of A
ptr = A[i];
A[i] = A[imax];
A[imax] = ptr;
//counting pivots starting from N (for determinant)
P[N]++;
}
for (j = i + 1; j < N; j++) {
A[j][i] /= A[i][i];
for (k = i + 1; k < N; k++)
A[j][k] -= A[j][i] * A[i][k];
}
}
return 1; //decomposition done
}
void LUPSolve(double** A, int* P, double* b, int N, std::vector<double>& x) {
for (int i = 0; i < N; i++) {
x[i] = b[P[i]];
for (int k = 0; k < i; k++)
x[i] -= A[i][k] * x[k];
}
for (int i = N - 1; i >= 0; i--) {
for (int k = i + 1; k < N; k++)
x[i] -= A[i][k] * x[k];
x[i] = x[i] / A[i][i];
}
}
GeneralizedIteratorBlock::GeneralizedIteratorBlock()
{
for (int i = 0; i < 30; i++)
{
IndVarSwitch[i] = false;
IndVarGuess[i] = 0.0;
IndVarWeight[i] = 0.0;
IndVarStep[i] = 0.0;
DepVarSwitch[i] = false;
DepVarLowerLimit[i] = 0.0;
DepVarUpperLimit[i] = 0.0;
DepVarClass[i] = 0;
DepVarWeight[i] = 0.0;
}
}
void tmat_mul_mat(double** A, double** B, int m, int n, int p, double** C)
{
//A is NxM
//B is NxP
//C is MxP
int i, j, k;
for (i = 0; i < m; i++)
{
for (j = 0; j < p; j++)
{
C[i][j] = 0.0;
for (k = 0; k < n; k++)
{
C[i][j] += A[k][i] * B[k][j];
}
}
}
}
void diag_mul_mat(const std::vector<double>& a, double** B, int m, int n, double** C)
{
//a is M
//B is MxN
//C is MxN
int i, j;
for (i = 0; i < m; i++)
{
for (j = 0; j < n; j++)
{
C[i][j] = a[i] * B[i][j];
}
}
}
void vec_mul_vec(const std::vector<double>& a, const std::vector<double>& b, double* c)
{
for (unsigned i = 0; i < a.size(); i++)
{
c[i] = a[i] * b[i];
}
}
void vec_mul_skal(const std::vector<double>& a, double b, double* c)
{
for (unsigned i = 0; i < a.size(); i++)
{
c[i] = a[i] * b;
}
}
void mat_mul_vec(double** A, double* b, int m, int n, double* c)
{
for (int i = 0; i < m; i++)
{
c[i] = 0.0;
for (int j = 0; j < n; j++)
{
c[i] += A[i][j] * b[j];
}
}
}
void tmat_mul_vec(double** A, double* b, int m, int n, double* c)
{
for (int i = 0; i < m; i++)
{
c[i] = 0.0;
for (int j = 0; j < n; j++)
{
c[i] += A[j][i] * b[j];
}
}
}
void mat_plus_vec(double** A, double* b, int n, double** C)
{
int i, j;
for (i = 0; i < n; i++)
{
for (j = 0; j < n; j++)
{
C[i][j] = A[i][j];
if (i == j)
{
C[i][j] += b[i];
}
}
}
}
void MatrixMultiply(double** P, const std::vector<double>& W_X, const std::vector<double>& W_Y, const std::vector<double>& dy, int m, int n, double** C, double* c)
{
//W_X is M
//W_Y is N
//P is NxM
//dy, b are N
//c is M
//B is NxM
//C is MxM
double* b = new double[n];
double** B = new double* [n];
int i;
for (i = 0; i < n; i++)
{
B[i] = new double[m];
}
vec_mul_vec(W_Y, dy, b);
tmat_mul_vec(P, b, m, n, c);
diag_mul_mat(W_Y, P, n, m, B);
tmat_mul_mat(P, B, m, n, m, C);
delete[] b;
delete[] B;
}
void ComputeCoefficients(double** CARR, const std::vector<double>& W_X, double lambda, int m, int n, double** D)
{
//A is M
//C is MxM
//D is MxM
double* A = new double[m];
vec_mul_skal(W_X, lambda, A);
mat_plus_vec(CARR, A, m, D);
delete[] A;
}
bool SolveEquations(double** D, double* c, int m, std::vector<double>& dx)
{
int* PP = new int[m + 1];
if (LUPDecompose(D, m, 0.0, PP) == 0)
{
return true;
}
LUPSolve(D, PP, c, m, dx);
delete[] PP;
return false;
}
void OpenRanks(std::vector<int>& xmap, std::vector<double>& in, std::vector<double>& out, int m)
{
for (int i = 0; i < m; i++)
{
out[xmap[i]] = in[i];
}
}
void CloseRanks(std::vector<int>& ymap, std::vector<double>& in, std::vector<double>& out, int n2)
{
int j = 0;
for (int i = 0; i < n2; i++)
{
if (ymap[j] == i)
{
out[j] = in[i];
j++;
}
if (j == ymap.size())
{
break;
}
}
}
bool GeneralizedIterator(bool(*state_evaluation)(void*, std::vector<double>&, void*, std::vector<double>&, bool), GeneralizedIteratorBlock vars, void* constants, void* data, std::vector<double>& x_res, std::vector<double>& y_res)
{
double lambda, R, R_old, w_avg, ** P, ** CARR, * CVEC, ** DARR;
bool select = true, hasclass3, errind;
int n, nMax, class1num, j_optm;
unsigned N, M, i, j;
std::vector<double> Target, var_star, v_l, * Y, var_star_temp, var_star_cur, Y_star, C, dx, dy, dy_temp, W_Y, W_Y_apo, W_X, step, LowerLimit, UpperLimit, trajin, trajout, depweight, borderinterval;
std::vector<double> Y_star_best;
std::vector<int> xmap, ymap, yclass, KPULL;
trajin.assign(MGENITER, 0);
trajout.assign(NGENITER, 0);
//Establish arrays, size is the number of active independent variables
M = 0;
for (i = 0; i < MGENITER; i++)
{
if (vars.IndVarSwitch[i])
{
//Store weights
W_X.push_back(vars.IndVarWeight[i]);
//Set up initial guess
var_star_temp.push_back(vars.IndVarGuess[i]);
//Store steps
step.push_back(vars.IndVarStep[i]);
//Store index
xmap.push_back(i);
M++;
}
else
{
//Store constants
trajin[i] = vars.IndVarGuess[i];
}
}
//Establish arrays, size is the number of active dependent variables
N = 0;
for (i = 0; i < NGENITER; i++)
{
if (vars.DepVarSwitch[i])
{
LowerLimit.push_back(vars.DepVarLowerLimit[i]);
UpperLimit.push_back(vars.DepVarUpperLimit[i]);
//Calculate target as the average between min and max value
Target.push_back((vars.DepVarUpperLimit[i] + vars.DepVarLowerLimit[i]) / 2.0);
//Save class
yclass.push_back(vars.DepVarClass[i]);
//Store weights
depweight.push_back(vars.DepVarWeight[i]);
//Store index
ymap.push_back(i);
N++;
}
}
//Set up a vector
Y = new std::vector<double>[M];
var_star.assign(M, 0);
var_star_cur.assign(M, 0);
dx.assign(M, 0);
v_l.assign(M, 0);
Y_star.assign(N, 0);
Y_star_best.assign(N, 0);
C.assign(N, 0);
dy.assign(N, 0);
dy_temp.assign(N, 0);
W_Y.assign(N, 0);
W_Y_apo.assign(N, 0);
borderinterval.assign(N, 0);
KPULL.assign(N, 0);
j_optm = -1;
for (i = 0; i < M; i++)
{
Y[i].assign(N, 0);
}
P = new double* [N];
CARR = new double* [M];
DARR = new double* [M];
CVEC = new double[M];
for (i = 0; i < M; i++)
{
CVEC[i] = 0.0;
CARR[i] = new double[M];
DARR[i] = new double[M];
for (j = 0; j < M; j++)
{
CARR[i][j] = 0.0;
DARR[i][j] = 0.0;
}
}
for (i = 0; i < N; i++)
{
P[i] = new double[M];
for (j = 0; j < M; j++)
{
P[i][j] = 0.0;
}
}
//Set up iteration counters
nMax = 100;
n = 0;
//Use initial guess to get a first vector
OpenRanks(xmap, var_star_temp, trajin, M);
errind = state_evaluation(data, trajin, constants, trajout, select);
CloseRanks(ymap, trajout, Y_star, NGENITER);
if (errind)
{
return true;
}
for (i = 0; i < N; i++)
{
dy[i] = Target[i] - Y_star[i];
}
//Initial guess
lambda = pow(2, -28);
//Select y weights based on class designation
class1num = 0;
hasclass3 = false;
w_avg = 1.0;
for (i = 0; i < N; i++)
{
if (yclass[i] == 1)
{
W_Y[i] = pow(2, -40) / pow((UpperLimit[i] - LowerLimit[i]) / 2.0, 2);
class1num++;
w_avg *= W_Y[i];
C[i] = 1.0;
}
else if (yclass[i] == 3)
{
if (hasclass3)
{
//Error
}
else
{
j_optm = i;
hasclass3 = true;
}
}
}
w_avg = pow(w_avg, 1.0 / ((double)(class1num)));
for (i = 0; i < N; i++)
{
if (yclass[i] == 2)
{
W_Y[i] = depweight[i] * w_avg;
borderinterval[i] = 0.002 * abs(UpperLimit[i] - LowerLimit[i]);
}
else if (yclass[i] == 3)
{
W_Y[i] = depweight[i] * pow(10, -4) * pow(2, -40) * ((double)(class1num)) / pow(dy[i], 2);
}
}
// "In the select mode, search is made for variables which are inside the acceptable interval, but only just inside, that is, they are within
// 0.2% of full range of one of the limits. When a variable has such a value, a move procedure begins. The limit near the value of the variable is
// temporarily replaced by its opposite limit, thus shrinking the interval of acceptability to zero length. The residual vector and its length
// are then recomputed. The move counter, which has been continually reset at every iteration, now begins to count, and control passes into the
// basic iteration loop. As the iterations proceed, additional variables may have values which would start a move procedure. If this happens, the
// limits are treated the same way, and the move counter begins to count from 1 again. Finally when the move counter reaches 6, all(?) the limits
// are restored to their values, as originally input, and the(?) move counter reverts to being reset at every iteration.
bool moving = false;
//True if all class 1 and 2 variables have converged in residual check
bool convergence = false;
bool locked = false;
bool sizing = false;
int sizingcounter = 0;
//See at "moving".
int movingcounter = 0;
bool skip = true;
bool badresidual = false;
std::vector<bool> movingarr, lockedarr;
movingarr.assign(N, 0);
lockedarr.assign(N, 0);
R_old = 1000000.0;
var_star = var_star_cur = var_star_temp;
goto NewGeneralizedIterator_B;
NewGeneralizedIterator_X:
W_Y[j_optm] = depweight[j_optm] * pow(2, -32) * ((double)(class1num)) / pow(dy[j_optm], 2);
for (j = 0; j < N; j++)
{
if (yclass[j] == 1 || yclass[j] == 3)
{
KPULL[j] = 1;
}
else if (yclass[j] == 2)
{
KPULL[j] = 3;
}
}
n = 0;
skip = true;
NewGeneralizedIterator_B:
if (moving)
{
NewGeneralizedIterator_AA:
moving = false;
for (j = 0; j < N; j++)
{
if (movingarr[j])
{
Target[j] = (UpperLimit[j] + LowerLimit[j]) / 2.0;
movingarr[j] = false;
}
}
}
NewGeneralizedIterator_EE:
//Residual Computation and Checking
convergence = true;
R = 0.0;
for (j = 0; j < N; j++)
{
dy[j] = Target[j] - Y_star[j];
if (Y_star[j] >= LowerLimit[j] && Y_star[j] <= UpperLimit[j])
{
if (movingarr[j] || lockedarr[j])
{
W_Y_apo[j] = W_Y[j];
}
else
{
W_Y_apo[j] = C[j] * W_Y[j];
}
}
else
{
if (j != j_optm)
{
convergence = false;
}
W_Y_apo[j] = W_Y[j];
if (yclass[j] == 2)
{
double testval = 2.0;
}
}
R = R + W_Y_apo[j] * dy[j] * dy[j];
}
if (skip == false)
{
goto NewGeneralizedIterator_F;
}
NewGeneralizedIterator_C:
//Store information for last good nominal
var_star = var_star_temp;
Y_star_best = Y_star;
R_old = R;
if (skip)
{
goto NewGeneralizedIterator_E;
}
sizing = true;
sizingcounter++;
if (sizingcounter == 3)
{
sizing = false;
goto NewGeneralizedIterator_H;
}
else
{
lambda /= 2.0;
goto NewGeneralizedIterator_D;
}
NewGeneralizedIterator_E:
skip = false;
sizing = false;
badresidual = false;
sizingcounter = 0;
var_star_cur = var_star;
n++;
if (n > nMax)
{
if (select) return true;
return false;
}
if (select)
{
if (lambda > pow(2, -49))
{
lambda /= 64.0;
}
}
//Partial computation
for (j = 0; j < M; j++)
{
//Evalue trajectory computer
v_l = var_star;
v_l[j] += step[j];
OpenRanks(xmap, v_l, trajin, M);
errind = state_evaluation(data, trajin, constants, trajout, select);
CloseRanks(ymap, trajout, Y[j], NGENITER);
if (errind)
{
return true;
}
//Calculate matrix valuess
for (i = 0; i < N; i++)
{
P[i][j] = (Y[j][i] - Y_star[i]) / step[j];
}
}
MatrixMultiply(P, W_X, W_Y_apo, dy, M, N, CARR, CVEC);
NewGeneralizedIterator_D:
ComputeCoefficients(CARR, W_X, lambda, M, N, DARR);
if (SolveEquations(DARR, CVEC, M, dx) == false)
{
goto NewGeneralizedIterator_G;
}
if (lambda <= 1.0)
{
goto NewGeneralizedIterator_CC;
}
NewGeneralizedIterator_DD:
if (select == false)
{
convergence = true;
goto NewGeneralizedIterator_END;
}
if (moving == false)
{
return true;
}
moving = false;
for (j = 0; j < N; j++)
{
movingarr[j] = false;
}
lambda = pow(2, -28);
skip = true;
goto NewGeneralizedIterator_EE;
NewGeneralizedIterator_F:
if (badresidual)
{
goto NewGeneralizedIterator_H;
}
if (select)
{
if (convergence)
{
if (j_optm >= 0)
{
select = false;
goto NewGeneralizedIterator_X;
}
else
{
goto NewGeneralizedIterator_END;
}
}
}
if (R < R_old)
{
goto NewGeneralizedIterator_C;
}
NewGeneralizedIterator_CC:
if (sizing)
{
var_star_cur = var_star;
Y_star = Y_star_best;
sizing = false;
badresidual = true;
goto NewGeneralizedIterator_EE;
}
lambda *= 8.0;
goto NewGeneralizedIterator_D;
NewGeneralizedIterator_G:
convergence = true;
for (i = 0; i < M; i++)
{
if (abs(dx[i]) > 65536.0 * abs(step[i]))
{
goto NewGeneralizedIterator_CC;
}
if (abs(dx[i]) > step[i] / 65536.0)
{
convergence = false;
}
var_star_temp[i] = var_star_cur[i] + dx[i];
}
if (convergence)
{
goto NewGeneralizedIterator_DD;
}
OpenRanks(xmap, var_star_temp, trajin, M);
errind = state_evaluation(data, trajin, constants, trajout, select);
CloseRanks(ymap, trajout, Y_star, NGENITER);
if (errind)
{
goto NewGeneralizedIterator_CC;
}
goto NewGeneralizedIterator_EE;
NewGeneralizedIterator_H:
//Barrier Computation
if (select == false)
{
goto NewGeneralizedIterator_K;
}
if (moving)
{
movingcounter++;
if (movingcounter == 6)
{
goto NewGeneralizedIterator_AA;
}
}
skip = true;
//Select mode barrier check
for (j = 0; j < N; j++)
{
//Is Y_j an active class 2 variable?
if (yclass[j] == 2)
{
//Is Y_j inside its limits?
if (Y_star[j] >= LowerLimit[j] && Y_star[j] <= UpperLimit[j])
{
if (Y_star[j] < LowerLimit[j] + borderinterval[j])
{
if (movingarr[j] == false)
{
Target[j] = UpperLimit[j];
movingarr[j] = true;
skip = false;
}
}
else if (Y_star[j] > UpperLimit[j] - borderinterval[j])
{
if (movingarr[j] == false)
{
Target[j] = LowerLimit[j];
movingarr[j] = true;
skip = false;
}
}
}
}
}
if (skip)
{
goto NewGeneralizedIterator_E;
}
movingcounter = 0;
moving = true;
R_old = 100.0;
goto NewGeneralizedIterator_EE;
NewGeneralizedIterator_K:
//optimize mode barrier check
skip = true;
j = 0;
NewGeneralizedIterator_T:
switch (KPULL[j])
{
case 1: //Class 1 or 3 variables
goto NewGeneralizedIterator_L;
case 2:
goto NewGeneralizedIterator_Q;
case 3: //Class 2 variables
goto NewGeneralizedIterator_P;
case 4: //Lower Barrier
if (Y_star[j] <= LowerLimit[j])
{
goto NewGeneralizedIterator_L;
}
NewGeneralizedIterator_R:
KPULL[j]++;
goto NewGeneralizedIterator_L;
//2nd and 3rd iteration while the variable is inside the limit (lower)
case 5:
case 6:
if (Y_star[j] > LowerLimit[j])
{
goto NewGeneralizedIterator_R;
}
NewGeneralizedIterator_S:
KPULL[j]--;
goto NewGeneralizedIterator_L;
case 7:
goto NewGeneralizedIterator_M;
case 8: //Upper Barrier
if (Y_star[j] >= UpperLimit[j])
{
goto NewGeneralizedIterator_L;
}
goto NewGeneralizedIterator_R;
//2nd and 3rd iteration while the variable is inside the limit (upper)
case 9:
case 10:
if (Y_star[j] < UpperLimit[j])
{
goto NewGeneralizedIterator_R;
}
goto NewGeneralizedIterator_S;
case 11:
goto NewGeneralizedIterator_N;
}
NewGeneralizedIterator_M:
if (Y_star[j] <= LowerLimit[j])
{
goto NewGeneralizedIterator_S;
}
Target[j] = LowerLimit[j] + 8.0 * borderinterval[j];
KPULL[j] = 2;
C[j] = 1.0;
goto NewGeneralizedIterator_O;
NewGeneralizedIterator_N:
if (Y_star[j] >= UpperLimit[j])
{
goto NewGeneralizedIterator_S;
}
Target[j] = UpperLimit[j] - 8.0 * borderinterval[j];
KPULL[j] = 2;
C[j] = 1.0;
goto NewGeneralizedIterator_O;
NewGeneralizedIterator_P:
if (Y_star[j] <= LowerLimit[j] + borderinterval[j])
{
//Within 0.2% of lower limit
KPULL[j] = 4;
Target[j] = LowerLimit[j];
lockedarr[j] = true;
goto NewGeneralizedIterator_O;
}
else if (Y_star[j] >= UpperLimit[j] - borderinterval[j])
{
//Within 0.2% of upper limit
KPULL[j] = 8;
Target[j] = UpperLimit[j];
lockedarr[j] = true;
goto NewGeneralizedIterator_O;
}
goto NewGeneralizedIterator_L;
NewGeneralizedIterator_Q:
Target[j] = (UpperLimit[j] + LowerLimit[j]) / 2.0;
//Put into class 2
C[j] = 0.0;
KPULL[j] = 3;
lockedarr[j] = false;
NewGeneralizedIterator_O:
skip = false;
NewGeneralizedIterator_L:
if (j < N - 1)
{
j++;
goto NewGeneralizedIterator_T;
}
if (skip)
{
goto NewGeneralizedIterator_E;
}
goto NewGeneralizedIterator_EE;
NewGeneralizedIterator_END:
delete[] Y;
delete[] P;
delete[] CARR;
delete[] CVEC;
x_res = var_star;
y_res = Y_star_best;
//Return true for error, false for convergence
return (convergence == false);
}
}