-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtolmin.cc
3119 lines (2759 loc) · 74.1 KB
/
tolmin.cc
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
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# include <stdio.h>
# include <stdlib.h>
# include <math.h>
# include <tolmin.h>
static long iabs(long x)
{
return x>0?x:-x;
}
#ifdef __cplusplus
extern "C" {
#endif
/* Common Block Declarations */
# define integer long
# define double double
# define real float
struct {
integer itnocs, ipartc, itder, ipder, ithess, iphess, itjac, ipjac;
} totcal_;
#define totcal_1 totcal_
struct {
integer iuinp, iuout;
} units_;
#define units_1 units_
/* Table of constant values */
integer c__0 = 0;
/* --------------------------------------------------------------------- */
/* Subroutine */ int getmin_(integer *n, integer *m, integer *meq, double
*a, integer *ia, double *b, double *xl, double *xu,
double *x, double *acc, integer *iact, integer *nact,
double *par, integer *iprint, integer *info, double *w,
MinInfo &Info)
{
/* System generated locals */
integer a_dim1, a_offset;
/* Local variables */
integer iztg, ixbig, ibres, id, ig, iu, iz;
extern /* Subroutine */ int minflc_(integer *, integer *, integer *,
double *, integer *, double *, double *, double *,
double *, double *, integer *, integer *, double *,
integer *, integer *, double *, double *, double *,
double *, double *, double *, double *,
double *, double *, double *, double *,
MinInfo &);
integer ireskt, igm, igs, ixs;
/* This is the entry point to a package of subroutines that calculate */
/* the least value of a differentiable function of several variables */
/* subject to linear constraints on the values of the variables. */
/* N is the number of variables and must be set by the user. */
/* M is the number of linear constraints (excluding simple bounds) and */
/* must be set by the user. */
/* MEQ is the number of constraints that are equalities and must be set */
/* by the user. */
/* A(.,.) is a 2-dimensional array whose columns are the gradients of */
/* the M constraint functions. Its entries must be set by the user */
/* and its dimensions must be at least N by M. */
/* IA is the actual first dimension of the array A that is supplied by */
/* the user, so its value may not be less than N. */
/* B(.) is a vector of constraint right hand sides that must also be set */
/* by the user. Specifically the constraints on the variables X(I) */
/* I=1(1)N are */
/* A(1,K)*X(1)+...+A(N,K)*X(N) .EQ. B(K) K=1,...,MEQ */
/* A(1,K)*X(1)+...+A(N,K)*X(N) .LE. B(K) K=MEQ+1,...,M . */
/* Note that the data that define the equality constraints come */
/* before the data of the inequalities. */
/* XL(.) and XU(.) are vectors whose components must be set to lower and */
/* upper bounds on the variables. Choose very large negative and */
/* positive entries if a component should be unconstrained, or set */
/* XL(I)=XU(I) to freeze the I-th variable. Specifically these */
/* simple bounds are */
/* XL(I) .LE. X(I) and X(I) .LE. XU(I) I=1,...,N . */
/* X(.) is the vector of variables of the optimization calculation. Its */
/* initial elements must be set by the user to an estimate of the */
/* required solution. The subroutines can usually cope with poor */
/* estimates, and there is no need for X(.) to be feasible initially. */
/* These variables are adjusted automatically and the values that */
/* give the least feasible calculated value of the objective function */
/* are available in X(.) on the return from GETMIN. */
/* ACC is a tolerance on the first order conditions at the calculated */
/* solution of the optimization problem. These first order */
/* conditions state that, if X(.) is a solution, then there is a set */
/* of active constraints with indices IACT(K) K=1(1)NACT, say, */
/* such that X(.) is on the boundaries of these constraints, */
/* and the gradient of the objective function can be expressed */
/* in the form */
/* GRAD(F)=PAR(1)*GRAD(C(IACT(1)))+... */
/* ...+PAR(NACT)*GRAD(C(IACT(NACT))) . */
/* Here PAR(K) K=1(1)NACT are Lagrange multipliers that are */
/* nonpositive for inequality constraints, and GRAD(C(IACT(K))) */
/* is the gradient of the IACT(K)-th constraint function, so it is */
/* A(.,IACT(K)) if IACT(K) .LE. M, and it is minus or plus the J-th */
/* coordinate vector if the constraint is the lower or upper bound on */
/* X(J) respectively. The normal return from the calculation occurs */
/* when X(.) is feasible and the sum of squares of components of the */
/* vector RESKT(.) is at most ACC**2, where RESKT(.) is the */
/* N-component vector of residuals of the first order condition that */
/* is displayed above. */
/* Sometimes the package cannot satisfy this condition, because noise */
/* in the function values can prevent a change to the variables, */
/* no line search being allowed to increase the objective function. */
/* IACT(.) is a working space array of integer variables that must be */
/* provided by the user. Its length must be at least (M+2*N). Its */
/* leading entries on the return from the subroutine are the indices */
/* IACT(K) K=1(1)NACT that are mentioned in the previous paragraph: */
/* in other words they are the indices of the final active */
/* constraints. */
/* Here the indices M+1,...,M+N and M+N+1,...,M+2*N denote the lower */
/* and upper bounds respectively. */
/* NACT is set automatically to the integer variable of this ilk that */
/* has been introduced already. */
/* PAR is a one-dimensional array that will hold the Lagrange */
/* multipliers PAR(K) K=1(1)NACT on the return from GETMIN, these */
/* parameters being defined in the above paragraph on ACC. */
/* The length of PAR should be at least N. */
/* IPRINT must be set by the user to specify the frequency of printing */
/* during the execution of the optimization package. There is no */
/* printed output if IPRINT=0. Otherwise, after ensuring */
/* feasibility, information is given every IABS(IPRINT) iterations */
/* and whenever a parameter called TOL is reduced. The printing */
/* provides the values of X(.), F(.) and G(.)=GRAD(F) if IPRINT */
/* is positive, while if IPRINT is negative this information is */
/* augmented by the current values of IACT(K) K=1(1)NACT, */
/* PAR(K) K=1(1)NACT and RESKT(I) I=1(1)N. The reason for returning */
/* to the calling program is also displayed when IPRINT is nonzero. */
/* INFO is an integer variable that should be set to zero initially, */
/* unless the user wishes to impose an upper bound on the number of */
/* evaluations of the objective function and its gradient, in which */
/* case INFO should be set to the value of this bound. On the exit */
/* from GETMIN it will have one of the following integer values to */
/* indicate the reason for leaving the optimization package: */
/* INFO=1 X(.) is feasible and the condition that depends on */
/* ACC is satisfied. */
/* INFO=2 X(.) is feasible and rounding errors are preventing */
/* further progress. */
/* INFO=3 X(.) is feasible but the objective function fails to */
/* decrease although a decrease is predicted by the current gradient */
/* vector. If this return occurs and KTRES(.) has large components */
/* then the user's calculation of the gradient of the objective */
/* function may be incorrect. One should also question the coding of */
/* the gradient when the final rate of convergence is slow. */
/* INFO=4 In this case the calculation cannot begin because IA */
/* is less than N or because the lower bound on a variable is greater */
/* than the upper bound. */
/* INFO=5 This value indicates that the equality constraints */
/* are inconsistent. These constraints include any components of */
/* X(.) that are frozen by setting XL(I)=XU(I). */
/* INFO=6 In this case there is an error return because the */
/* equality constraints and the bounds on the variables are found to */
/* be inconsistent. */
/* INFO=7 This value indicates that there is no vector of */
/* variables that satisfies all of the constraints. Specifically, */
/* when this return or an INFO=6 return occurs, the current active */
/* constraints (whose indices are IACT(K) K=1(1)NACT) prevent any */
/* change in X(.) that reduces the sum of constraint violations, */
/* where only bounds are included in this sum if INFO=6. */
/* INFO=8 In this case the limit on the number of calls of */
/* subroutine FGCALC (see below) has been reached, and there would */
/* have been further calculation otherwise. */
/* W(.) is a working space array of real variables that must be provided */
/* by the user. Its length must be at least (M+11*N+N**2). On exit */
/* from the package one can find the final components of GRAD(F) and */
/* RESKT(.) in W(1),...,W(N) and W(N+1),...,W(2*N) respectively. */
/* Note 1. The variables N, M, MEQ, IA, ACC and IPRINT and the */
/* elements of the arrays A(,.,), B(.), XL(.) and XU(.) are not */
/* altered by the optimization procedure. Their values, the value of */
/* INFO and the initial components of X(.) must be set on entry */
/* to GETMIN. */
/* Note 2. Of course the package needs the objective function and its */
/* gradient. Therefore the user must provide a subroutine called */
/* FGCALC, its first two lines being */
/* SUBROUTINE FGCALC (N,X,F,G) */
/* DIMENSION X(*),G(*) . */
/* It is called automatically with N set as above and with X(.) set */
/* to a feasible vector of variables. It should calculate the value */
/* of the objective function and its gradient for this X(.) and */
/* should set them in F and G(I) I=1(1)N respectively, without */
/* disturbing N or any of the components of X(.). */
/* Note 3. A paper on the method of calculation and a report on the */
/* main features of the computer code are available from the author */
/* M.J.D.Powell (D.A.M.T.P., University of Cambridge, Silver Street, */
/* Cambridge CB3 9EW, England). */
/* Partition the workspace array. */
/* Parameter adjustments */
a_dim1 = *ia;
a_offset = 1 + a_dim1 * 1;
a -= a_offset;
--b;
--xl;
--xu;
--x;
--iact;
--par;
--w;
/* Function Body */
ig = 1;
ireskt = ig + *n;
iz = ireskt + *n;
iu = iz + *n * *n;
ixbig = iu + *n;
ibres = ixbig + *n;
id = ibres + *m + *n + *n;
iztg = id + *n;
igm = iztg + *n;
ixs = igm + *n;
igs = ixs + *n;
/* Call the optimization package. */
minflc_(n, m, meq, &a[a_offset], ia, &b[1], &xl[1], &xu[1], &x[1], acc, &
iact[1], nact, &par[1], iprint, info, &w[ig], &w[iz], &w[iu], &w[
ixbig], &w[ireskt], &w[ibres], &w[id], &w[iztg], &w[igm], &w[ixs],
&w[igs],Info);
return 0;
} /* getmin_ */
/* --------------------------------------------------------------------- */
/* Subroutine */ int initzu_(integer *n, integer *m, double *xl,
double *xu, double *x, integer *iact, integer *meql, integer *
info, double *z__, double *u, double *xbig, double *
relacc)
{
/* System generated locals */
integer i__1;
double d__1;
/* Local variables */
integer jact, i__, j;
double tempa, tempb, ztpar;
integer nn, iz;
/* Set RELACC. */
/* Parameter adjustments */
--xbig;
--u;
--z__;
--iact;
--x;
--xu;
--xl;
/* Function Body */
ztpar = (float)100.;
*relacc = (float)1.;
L10:
*relacc *= (float).5;
tempa = ztpar + *relacc * (float).5;
tempb = ztpar + *relacc;
if (ztpar < tempa && tempa < tempb) {
goto L10;
}
/* Seek bound inconsistencies and bound equality constraints. */
*meql = 0;
i__1 = *n;
for (i__ = 1; i__ <= i__1; ++i__) {
if (xl[i__] > xu[i__]) {
goto L50;
}
if (xl[i__] == xu[i__]) {
++(*meql);
}
/* L20: */
}
/* Initialize U, Z and XBIG. */
jact = 0;
nn = *n * *n;
i__1 = nn;
for (i__ = 1; i__ <= i__1; ++i__) {
/* L30: */
z__[i__] = (float)0.;
}
iz = 0;
i__1 = *n;
for (i__ = 1; i__ <= i__1; ++i__) {
if (xl[i__] == xu[i__]) {
x[i__] = xu[i__];
++jact;
u[jact] = (float)1.;
iact[jact] = i__ + *m + *n;
j = jact;
} else {
j = i__ + *meql - jact;
}
z__[iz + j] = (float)1.;
iz += *n;
/* L40: */
xbig[i__] = (d__1 = x[i__], fabs(d__1));
}
*info = 1;
L50:
return 0;
} /* initzu_ */
/* --------------------------------------------------------------------- */
/* Subroutine */ int ktvec_(integer *n, integer *m, double *a, integer *
ia, integer *iact, integer *nact, double *par, double *g,
double *reskt, double *z__, double *u, double *bres,
double *relaxf, integer *meql, double *ssqkt, double *
parw, double *resktw)
{
/* System generated locals */
integer a_dim1, a_offset, i__1, i__2;
double d__1;
/* Local variables */
double temp;
integer i__, j, k, icase, kk, jm, kl, iz;
double ssqktw;
/* Calculate the Lagrange parameters and the residual vector. */
/* Parameter adjustments */
a_dim1 = *ia;
a_offset = 1 + a_dim1 * 1;
a -= a_offset;
--iact;
--par;
--g;
--reskt;
--z__;
--u;
--bres;
--parw;
--resktw;
/* Function Body */
i__1 = *n;
for (i__ = 1; i__ <= i__1; ++i__) {
/* L10: */
reskt[i__] = g[i__];
}
if (*nact > 0) {
icase = 0;
L20:
i__1 = *nact;
for (kk = 1; kk <= i__1; ++kk) {
k = *nact + 1 - kk;
j = iact[k];
temp = (float)0.;
iz = k;
i__2 = *n;
for (i__ = 1; i__ <= i__2; ++i__) {
temp += z__[iz] * reskt[i__];
/* L30: */
iz += *n;
}
temp *= u[k];
if (icase == 0) {
par[k] = (float)0.;
}
if (k <= *meql || par[k] + temp < (float)0.) {
par[k] += temp;
} else {
temp = -par[k];
par[k] = (float)0.;
}
if (temp != (float)0.) {
if (j <= *m) {
i__2 = *n;
for (i__ = 1; i__ <= i__2; ++i__) {
/* L40: */
reskt[i__] -= temp * a[i__ + j * a_dim1];
}
} else {
jm = j - *m;
if (jm <= *n) {
reskt[jm] += temp;
} else {
reskt[jm - *n] -= temp;
}
}
}
/* L50: */
}
/* Calculate the sum of squares of the KT residual vector. */
*ssqkt = (float)0.;
if (*nact == *n) {
goto L130;
}
i__1 = *n;
for (i__ = 1; i__ <= i__1; ++i__) {
/* L60: */
/* Computing 2nd power */
d__1 = reskt[i__];
*ssqkt += d__1 * d__1;
}
/* Apply iterative refinement to the residual vector. */
if (icase == 0) {
icase = 1;
i__1 = *nact;
for (k = 1; k <= i__1; ++k) {
/* L70: */
parw[k] = par[k];
}
i__1 = *n;
for (i__ = 1; i__ <= i__1; ++i__) {
/* L80: */
resktw[i__] = reskt[i__];
}
ssqktw = *ssqkt;
goto L20;
}
/* Undo the iterative refinement if it does not reduce SSQKT. */
if (ssqktw < *ssqkt) {
i__1 = *nact;
for (k = 1; k <= i__1; ++k) {
/* L90: */
par[k] = parw[k];
}
i__1 = *n;
for (i__ = 1; i__ <= i__1; ++i__) {
/* L100: */
reskt[i__] = resktw[i__];
}
*ssqkt = ssqktw;
}
/* Calculate SSQKT when there are no active constraints. */
} else {
*ssqkt = (float)0.;
i__1 = *n;
for (i__ = 1; i__ <= i__1; ++i__) {
/* L110: */
/* Computing 2nd power */
d__1 = g[i__];
*ssqkt += d__1 * d__1;
}
}
/* Predict the reduction in F if one corrects any positive residuals */
/* of active inequality constraints. */
*relaxf = (float)0.;
if (*meql < *nact) {
kl = *meql + 1;
i__1 = *nact;
for (k = kl; k <= i__1; ++k) {
j = iact[k];
if (bres[j] > (float)0.) {
*relaxf -= par[k] * bres[j];
}
/* L120: */
}
}
L130:
return 0;
} /* ktvec_ */
/* --------------------------------------------------------------------- */
/* Subroutine */ int lsrch_(integer *n, double *x, double *g,
double *d__, double *xs, double *gs, double *relacc,
double *stepcb, double *ddotg, double *f, double *
step, integer *nfvals, integer *nfmax, double *gopt,
MinInfo &Info)
{
/* System generated locals */
integer i__1;
double d__1, d__2;
/* Local variables */
double fhgh, temp, flow, fopt;
integer i__;
double fbase, dghgh, dgmid, sbase, dglow, dgopt, ratio;
extern /* Subroutine */ int fgcalc_(integer *, double *, double *,
double *,MinInfo&);
double ddotgb;
integer isofar;
double dgknot, relint, stphgh;
integer icount;
double stpmin, stplow, stpopt, amx;
/* Initialization. */
/* Parameter adjustments */
--gopt;
--gs;
--xs;
--d__;
--g;
--x;
/* Function Body */
relint = (float).9;
icount = 0;
ratio = (float)-1.;
i__1 = *n;
for (i__ = 1; i__ <= i__1; ++i__) {
xs[i__] = x[i__];
gs[i__] = g[i__];
gopt[i__] = g[i__];
if (d__[i__] != (float)0.) {
temp = (d__1 = x[i__] / d__[i__], fabs(d__1));
if (ratio < (float)0. || temp < ratio) {
ratio = temp;
}
}
/* L10: */
}
amx = (float)1.;
*step = min(amx,*stepcb);
/* Computing MAX */
d__1 = *relacc * ratio, d__2 = *step * (float)1e-19;
stpmin = max(d__1,d__2);
*step = max(stpmin,*step);
sbase = (float)0.;
fbase = *f;
ddotgb = *ddotg;
stplow = (float)0.;
flow = *f;
dglow = *ddotg;
stphgh = (float)0.;
stpopt = (float)0.;
fopt = *f;
dgopt = fabs(*ddotg);
/* Calculate another function and gradient value. */
L20:
i__1 = *n;
for (i__ = 1; i__ <= i__1; ++i__) {
/* L30: */
x[i__] = xs[i__] + *step * d__[i__];
}
isofar = totcal_1.itnocs;
fgcalc_(n, &x[1], f, &g[1],Info);
icount += totcal_1.itnocs - isofar;
dgmid = (float)0.;
i__1 = *n;
for (i__ = 1; i__ <= i__1; ++i__) {
/* L40: */
dgmid += d__[i__] * g[i__];
}
if (*f <= fopt) {
if (*f < fopt || fabs(dgmid) < dgopt) {
stpopt = *step;
fopt = *f;
i__1 = *n;
for (i__ = 1; i__ <= i__1; ++i__) {
/* L50: */
gopt[i__] = g[i__];
}
dgopt = fabs(dgmid);
}
}
if (*nfvals + icount == *nfmax) {
goto L70;
}
/* Modify the bounds on the steplength or convergence. */
if (*f >= fbase + (*step - sbase) * (float).1 * ddotgb) {
if (stphgh > (float)0. || *f > fbase || dgmid > *ddotg * (float).5) {
stphgh = *step;
fhgh = *f;
dghgh = dgmid;
goto L60;
}
sbase = *step;
fbase = *f;
ddotgb = dgmid;
}
if (dgmid >= ddotgb * (float).7) {
goto L70;
}
stplow = *step;
flow = *f;
dglow = dgmid;
L60:
if (stphgh > (float)0. && stplow >= relint * stphgh) {
goto L70;
}
/* Calculate the next step length or end the iterations. */
if (stphgh == (float)0.) {
if (*step == *stepcb) {
goto L70;
}
temp = (float)10.;
if (dgmid > *ddotg * (float).9) {
temp = *ddotg / (*ddotg - dgmid);
}
/* Computing MIN */
d__1 = temp * *step;
*step = min(d__1,*stepcb);
goto L20;
} else if (icount == 1 || stplow > (float)0.) {
dgknot = (fhgh - flow) * (float)2. / (stphgh - stplow) - (dglow +
dghgh) * (float).5;
if (dgknot >= (float)0.) {
amx = (float).1;
/* Computing MAX */
d__1 = amx, d__2 = dglow * (float).5 / (dglow - dgknot);
ratio = max(d__1,d__2);
} else {
ratio = (dghgh * (float).5 - dgknot) / (dghgh - dgknot);
}
*step = stplow + ratio * (stphgh - stplow);
goto L20;
} else {
*step *= (float).1;
if (*step >= stpmin) {
goto L20;
}
}
/* Return from subroutine. */
L70:
if (*step != stpopt) {
*step = stpopt;
*f = fopt;
i__1 = *n;
for (i__ = 1; i__ <= i__1; ++i__) {
x[i__] = xs[i__] + *step * d__[i__];
/* L80: */
g[i__] = gopt[i__];
}
}
*nfvals += icount;
return 0;
} /* lsrch_ */
/* --------------------------------------------------------------------- */
/* Subroutine */ int minflc_(integer *n, integer *m, integer *meq, double
*a, integer *ia, double *b, double *xl, double *xu,
double *x, double *acc, integer *iact, integer *nact,
double *par, integer *iprint, integer *info, double *g,
double *z__, double *u, double *xbig, double *reskt,
double *bres, double *d__, double *ztg, double *gm,
double *xs, double *gs,
MinInfo &Info)
{
/* System generated locals */
integer a_dim1, a_offset, i__1, i__2;
double d__1, d__2;
/* Builtin functions */
//integer s_wsfe(cilist *), e_wsfe();
/* Local variables */
integer meql, msat, mtot;
double f;
integer i__, k, iterc, nfmax, iexau;
nfmax=2001;
double relacc;
integer mp;
extern /* Subroutine */ int getfes_(integer *, integer *, double *,
integer *, double *, double *, double *, double *,
integer *, integer *, double *, integer *, double *,
double *, double *, double *, double *,
double *, integer *, integer *, integer *, double *,
double *, double *, double *, double *,
double *, double *), adjtol_(integer *, integer *,
double *, integer *, double *, double *, double *,
double *, integer *, integer *, double *, double *,
double *, integer *), eqcons_(integer *, integer *, integer *,
double *, integer *, double *, double *, integer *,
integer *, integer *, double *, double *, double *,
double *, double *);
integer nfvals;
extern /* Subroutine */ int minfun_(integer *, integer *, double *,
integer *, double *, double *, double *, double *,
double *, integer *, integer *, double *, integer *,
integer *, double *, double *, double *, double *,
double *, double *, double *, integer *, integer *,
integer *, integer *, integer *, double *, double *,
double *, double *, double *, double *,
double *, double *, integer *,
MinInfo &), initzu_(integer *,
integer *, double *, double *, double *, integer *,
integer *, integer *, double *, double *, double *,
double *);
double zznorm, amx, tol;
/* Initialize ZZNORM, ITERC, NFVALS and NFMAX. */
/* Parameter adjustments */
a_dim1 = *ia;
a_offset = 1 + a_dim1 * 1;
a -= a_offset;
--b;
--xl;
--xu;
--x;
--iact;
--par;
--g;
--z__;
--u;
--xbig;
--reskt;
--bres;
--d__;
--ztg;
--gm;
--xs;
--gs;
/* Function Body */
zznorm = (float)-1.;
iterc = 0;
nfvals = 0;
nfmax = 2001;
if (*info > 0) {
nfmax = *info;
}
/* Check the bounds on N, M and MEQ. */
*info = 4;
/* Computing MAX */
i__1 = 1 - *n, i__2 = *meq * (*meq - *m);
if (max(i__1,i__2) > 0) {
goto L40;
}
/* Initialize RELACC, Z, U and TOL. */
initzu_(n, m, &xl[1], &xu[1], &x[1], &iact[1], &meql, info, &z__[1], &u[1]
, &xbig[1], &relacc);
amx = (float).01;
/* Computing MAX */
d__1 = amx, d__2 = relacc * (float)10.;
tol = max(d__1,d__2);
if (*info == 4) {
goto L40;
}
/* Add any equality constraints to the active set. */
if (*meq > 0) {
eqcons_(n, m, meq, &a[a_offset], ia, &b[1], &xu[1], &iact[1], &meql,
info, &z__[1], &u[1], &relacc, &xs[1], &gs[1]);
if (*info == 5) {
if (*iprint != 0) {
//io___62.ciunit = units_1.iuout;
//s_wsfe(&io___62);
//e_wsfe();
}
goto L40;
}
}
*nact = meql;
msat = meql;
/* Add the bounds to the list of constraints. */
mtot = *nact;
i__1 = *n;
for (i__ = 1; i__ <= i__1; ++i__) {
if (xl[i__] < xu[i__]) {
mtot += 2;
iact[mtot - 1] = *m + i__;
iact[mtot] = *m + *n + i__;
}
/* L10: */
}
/* Try to satisfy the bound constraints. */
getfes_(n, m, &a[a_offset], ia, &b[1], &xl[1], &xu[1], &x[1], &iact[1],
nact, &par[1], info, &g[1], &z__[1], &u[1], &xbig[1], &relacc, &
tol, &meql, &msat, &mtot, &bres[1], &d__[1], &ztg[1], &gm[1], &
reskt[1], &xs[1], &gs[1]);
if (msat < mtot) {
if (*iprint != 0) {
//io___66.ciunit = units_1.iuout;
//s_wsfe(&io___66);
//e_wsfe();
}
*info = 6;
goto L40;
}
/* Add the ordinary inequalities to the list of constraints. */
if (*m > *meq) {
mp = *meq + 1;
i__1 = *m;
for (k = mp; k <= i__1; ++k) {
++mtot;
/* L20: */
iact[mtot] = k;
}
}
/* Correct any constraint violations. */
L30:
getfes_(n, m, &a[a_offset], ia, &b[1], &xl[1], &xu[1], &x[1], &iact[1],
nact, &par[1], info, &g[1], &z__[1], &u[1], &xbig[1], &relacc, &
tol, &meql, &msat, &mtot, &bres[1], &d__[1], &ztg[1], &gm[1], &
reskt[1], &xs[1], &gs[1]);
if (msat < mtot) {
if (*iprint != 0) {
//io___69.ciunit = units_1.iuout;
//s_wsfe(&io___69);
//e_wsfe();
}
*info = 7;
goto L40;
} else if (meql == *n) {
if (*iprint != 0) {
//io___70.ciunit = units_1.iuout;
//s_wsfe(&io___70);
//e_wsfe();
}
goto L40;
}
/* Minimize the objective function in the case when constraints are */
/* treated as degenerate if their residuals are less than TOL. */
iexau = 0;
minfun_(n, m, &a[a_offset], ia, &b[1], &xl[1], &xu[1], &x[1], acc, &iact[
1], nact, &par[1], iprint, info, &g[1], &z__[1], &u[1], &xbig[1],
&relacc, &zznorm, &tol, &meql, &mtot, &iterc, &nfvals, &nfmax, &
reskt[1], &bres[1], &d__[1], &ztg[1], &gm[1], &xs[1], &gs[1], &f,
&iexau,Info);
if (iexau != 0) {
return 0;
}
/* Reduce TOL if necessary. */
if (tol > relacc && *nact > 0) {
if (nfvals < nfmax) {
adjtol_(n, m, &a[a_offset], ia, &b[1], &xl[1], &xu[1], &x[1], &
iact[1], nact, &xbig[1], &relacc, &tol, &meql);
goto L30;
} else {
*info = 8;
}
}
L40:
return 0;
} /* minflc_ */
/* --------------------------------------------------------------------- */
/* --------------------------------------------------------------------- */
/* Subroutine */ int minfun_(integer *n, integer *m, double *a, integer *
ia, double *b, double *xl, double *xu, double *x,
double *acc, integer *iact, integer *nact, double *par,
integer *iprint, integer *info, double *g, double *z__,
double *u, double *xbig, double *relacc, double *
zznorm, double *tol, integer *meql, integer *mtot, integer *iterc,
integer *nfvals, integer *nfmax, double *reskt, double *bres,
double *d__, double *ztg, double *gm, double *xs,
double *gs, double *f, integer *iexau,
MinInfo &Info)
{
/* System generated locals */
integer a_dim1, a_offset, i__1;
double d__1, d__2, d__3;
/* Local variables */
double diff;
extern /* Subroutine */ int mdis_(double *, double *, integer *,
integer *, integer *, integer *, integer *);
integer msat;
double step;
integer i__, k;
double ddotg;
extern /* Subroutine */ int ktvec_(integer *, integer *, double *,
integer *, integer *, integer *, double *, double *,
double *, double *, double *, double *,
double *, integer *, double *, double *, double *)
, lsrch_(integer *, double *, double *, double *,
double *, double *, double *, double *,
double *, double *, double *, integer *, integer *,
double *,MinInfo&);
integer iterk;
extern /* Subroutine */ int zbfgs_(integer *, double *, integer *,
double *, double *, double *, double *,
double *, double *);
double fprev;
integer iterp;
double ssqkt;
extern /* Subroutine */ int fgcalc_(integer *, double *, double *,
double *,MinInfo&), addcon_(integer *, integer *, double *,
integer *, integer *, integer *, double *, double *,
double *, integer *, double *, double *);
integer indxbd;
double stepcb;
integer nfvalk, isofar;
double relaxf;
extern /* Subroutine */ int conres_(integer *, integer *, double *,
integer *, double *, double *, double *, double *,
integer *, integer *, double *, double *, double *,
double *, double *, double *, double *,
double *, double *, double *, double *,
double *, integer *, integer *, integer *, integer *,
double *, double *, double *, double *);
extern integer itconv_(double *);
double sum;
/* Initialize the minimization calculation. */
/* Parameter adjustments */
a_dim1 = *ia;
a_offset = 1 + a_dim1 * 1;
a -= a_offset;
--b;
--xl;
--xu;
--x;
--iact;
--par;
--g;
--z__;
--u;
--xbig;
--reskt;
--bres;
--d__;
--ztg;
--gm;
--xs;
--gs;
/* Function Body */
msat = *mtot;
iterk = *iterc;
nfvalk = *nfvals;
if (*nfvals == 0 || *info == 1) {
isofar = totcal_1.itnocs;
fgcalc_(n, &x[1], f, &g[1],Info);
*nfvals += totcal_1.itnocs - isofar;
}
fprev = (d__1 = *f + *f + (float)1., fabs(d__1));
iterp = -1;
if (*iprint != 0) {
/* WRITE (IUOUT,1000) TOL */
/* 1000 FORMAT (/5X,'NEW VALUE OF TOL =',1PE13.5) */
iterp = *iterc;
}
/* Calculate the next search direction. */
L10:
conres_(n, m, &a[a_offset], ia, &b[1], &xl[1], &xu[1], &x[1], &iact[1],
nact, &par[1], &g[1], &z__[1], &u[1], &xbig[1], &bres[1], &d__[1],
&ztg[1], relacc, tol, &stepcb, &ddotg, meql, &msat, mtot, &
indxbd, &gm[1], &reskt[1], &xs[1], &gs[1]);
/* Calculate the Kuhn Tucker residual vector. */
ktvec_(n, m, &a[a_offset], ia, &iact[1], nact, &par[1], &g[1], &reskt[1],
&z__[1], &u[1], &bres[1], &relaxf, meql, &ssqkt, &xs[1], &gs[1]);