-
Notifications
You must be signed in to change notification settings - Fork 0
/
ve11d.f
executable file
·1878 lines (1876 loc) · 54 KB
/
ve11d.f
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
* COPYRIGHT (c) 1989 AEA Technology.
*######DATE 29 Sept 1992
*######ALIAS VE11A
C######29/9/92. Modified to avoid branches into IF constructs.
SUBROUTINE VE11AD (N,M,MEQ,A,IA,B,XL,XU,X,ACC,IACT,NACT,PAR,
1 IPRINT,INFO,W,FGCALC)
IMPLICIT DOUBLE PRECISION (A-H,O-Z)
DIMENSION A(IA,*),B(*),XL(*),XU(*),X(*),IACT(*),PAR(*),W(*)
EXTERNAL VE11TD,FGCALC
C
C purpose.
C This is the entry point to a package of subroutines that
C calculate the least value of a differentiable function of
C several variables subject to linear constraints on the
C values of the variables.
C
C argument list.
C N is the number of variables and must be set by the user.
C M is the number of linear constraints (excluding simple
C bounds) and must be set by the user.
C MEQ is the number of constraints that are equalities and
C must be set by the user.
C A(.,.) is a 2-dimensional array whose columns are the gradients
C of the M constraint functions. Its entries must be set
C by the user and its dimensions must be at least N by M.
C IA is the actual first dimension of the array A that is
C supplied by the user, so its value may not be less than N.
C B(.) is a vector of constraint right hand sides that must
C also be set by the user. Specifically the constraints
C on the variables X(I) I=1(1)N are
C A(1,K)*X(1)+...+A(N,K)*X(N) .EQ. B(K) K=1,...,MEQ
C A(1,K)*X(1)+...+A(N,K)*X(N) .LE. B(K) K=MEQ+1,...,M .
C Note that the data that define the equality constraints
C come before the data of the inequalities.
C XL(.) are vectors whose components must be set to lower and
C XU(.) upper bounds on the variables. Choose very large
C negative and positive entries if a component should be
C unconstrained, or set XL(I)=XU(I) to freeze the I-th
C variable. Specifically these simple bounds are
C XL(I) .LE. X(I) and X(I) .LE. XU(I) I=1,...,N .
C X(.) is the vector of variables of the optimization calculation
C Its initial elements must be set by the user to an
C estimate of the required solution. The subroutines can
C usually cope with poor estimates, and there is no need
C for X(.) to be feasible initially. These variables are
C adjusted automatically and the values that give the least
C feasible calculated value of the objective functions are
C available in X(.) on the return from VE11AD.
C ACC is a tolerance on the first order conditions at the
C calculated solution of the optimization problem. These
C first order conditions state that, if X(.) is a solution,
C then there is a set of active constraints with indices
C IACT(K) K=1(1)NACT, say, such that X(.) is on the
C boundaries of these constraints, and the gradient of the
C objective function can be expressed in the form
C GRAD(F)=PAR(1)*GRAD(C(IACT(1)))+...
C ...+PAR(NACT)*GRAD(C(IACT(NACT))) .
C Here PAR(K) K=1(1)NACT are Lagrange multipliers that are
C nonpositive for inequality constraints, and
C GRAD(C(IACT(K))) is the gradient of the IACT(K)-th
C constraint function, so it is A(.,IACT(K)) if IACT(K)
C .LE. M, and it is minus or plus the J-th coordinate vector
C if the constraint is the lower or upper bound on X(J)
C respectively. The normal return from th calculation
C occurs when X(.) is feasible and the sum of squares of
C components of the vector RESKT(.) is at most ACC**2,
C where RESKT(.) is the N-component vector of residuals of
C the first order condition that is displayed above.
C Sometimes the package cannot satisfy this condition,
C because noise in the function values can prevent a change
C to the variables, no line search being allowed to increas
C the objective function.
C IACT(.) is a working space array of integer variables that must
C be provided by the user. Its length must be at least
C (M+2*N). Its leading entries on the return from the
C subroutine are the indices IACT(k) K=1(1)NACT that are
C mentioned in the previous paragraph: in other words they
C are the indices of the final active constraints.
C Here the indices M+1,...,M+N and M+N+1,...,M+2*N denote
C the lower and upper bounds respectively.
C NACT is set automatically to the integer variable of this ilk
C that has been introduced already.
C PAR is a one-dimensional array that will hold the Lagrange
C multipliers PAR(K) K=1(1)NACT on the return from VE11AD,
C these parameters being defined in the above paragraph
C on ACC. The length of PAR should be at least N.
C IPRINT must be set by the user to specify the frequency of
C printing during the execution of the optimization package.
C There is no printed output if IPRINT=0. Otherwise, after
C ensuring feasibility, information is given every
C IABS(IPRINT) iterations and whenever a parameter called
C TOL is reduced. The printing provides the values of X(.),
C F(.) and G(.)=GRAD(F) if IPRINT is positive, while if
C IPRINT is negative this information is augmented by the
C current values of IACT(K) K=1(1)NACT, PAR(K) K=1(1)NACT
C and RESKT(I) I=1(1)N. The reason for returning to the
C calling program is also displayed when IPRINT is nonzero.
C INFO is an integer variable that should be set to zero
C initially, unless the user wishes to impose an upper
C bound on the number of evaluations of the objective
C function and its gradient, in which case INFO should be
C set to the value of this bound. On the exit from VE11AD
C it will have one of the following integer values to
C indicate the reason for leaving the optimization package:
C INFO=1 X(.) is feasible and the condition that depends
C on ACC is satisfied.
C INFO=2 X(.) is feasible and rounding errors are
C preventing further progress.
C INFO=3 X(.) is feasible but the objective function fails
C to decrease although a decrease is predicted by
C the current gradient vector. If this return
C occurs and KTRES(.) has large components then the
C user's calculation of the gradient of the
C objective function may be incorrect. One should
C also question the coding of the gradient when
C the final rate of convergence is slow.
C INFO=4 In this case the calculation cannot begin because
C IA is less than N or because the lower bound on a
C variable is greater than the upper bound.
C INFO=5 This value indicates that the equality
C constraints are inconsistent. These constraints
C include any components of X(.) that are frozen by
C setting XL(I)=XU(I).
C INFO=6 In this case there is an error return because the
C equality constraints and the bounds on the
C variables are found to be inconsistent.
C INFO=7 This value indicates that there is no vector of
C variables that satisfies all of the constraints.
C Specifically, when this return or an INFO=6
C return occurs, the current active constraints
C (whose indices are IACT(K) K=1(1)NACT) prevent
C any change in X(.) that reduces the sum of
C constraint violations, where only bounds are
C included in this sum if INFO=6.
C INFO=8 In this case the limit on the number of calls of
C subroutine FGCALC (see below) has been reached,
C and there would have been further calculation
C otherwise.
C W(.) is a working space array of real variables that must be
C provided by the user. Its length must be at least
C (M+11*N+N**2). On exit from the package one can find the
C final components of GRAD(F) and RESKT(.) in W(1),...,W(N)
C and W(N+1),...,W(2*N) respectively.
C FGCALC is a user supplied subroutine to calculate the objective
C function and its gradient.Its first two lines being
C SUBROUTINE FGCALC (N,X,F,G)
C DIMENSION X(*),G(*) .
C It is called automatically with N set as above and with
C X(.) set to a feasible vector of variables. It should
C calculate the value of the objective function and its
C gradient for this X(.) and should set them in F and G(I)
C I=1(1)N respectively, without disturbing N or any
C of the components of X(.).
C
C Note 1. The variables N, M, MEQ, IA, ACC and IPRINT and the
C elements of the arrays A(,.,), B(.), XL(.) and XU(.) are
C not altered by the optimization procedure. Their values,
C the value of INFO and the initial components of X(.)
C must be set on entry to VE11AD.
C Note 2. A paper on the method of calculation and a report on the
C main features of the computer code are available from
C the author M.J.D.Powell (D.A.M.T.P., University of
C Cambridge, Silver Street, Cambridge CB3 9EW, England).
C
C Partition the workspace array.
C
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
C
C Call the optimization package.
C
CALL VE11BD (N,M,MEQ,A,IA,B,XL,XU,X,ACC,IACT,NACT,PAR,IPRINT,
1 INFO,W(IG),W(IZ),W(IU),W(IXBIG),W(IRESKT),W(IBRES),W(ID),
2 W(IZTG),W(IGM),W(IXS),W(IGS),FGCALC)
RETURN
END
SUBROUTINE VE11CD (N,M,XL,XU,X,IACT,MEQL,INFO,Z,U,XBIG,RELACC)
IMPLICIT DOUBLE PRECISION (A-H,O-Z)
DIMENSION XL(*),XU(*),X(*),IACT(*),Z(*),U(*),XBIG(*)
DATA ZERO/0.0D0/,ONE/1.0D0/
C
C Set RELACC.
C
ZTPAR=100.0
RELACC=ONE
10 RELACC=0.5*RELACC
TEMPA=ZTPAR+0.5*RELACC
TEMPB=ZTPAR+RELACC
IF (ZTPAR .LT. TEMPA .AND. TEMPA .LT. TEMPB) GOTO 10
C
C Seek bound inconsistencies and bound equality constraints.
C
MEQL=0
DO 20 I=1,N
IF (XL(I) .GT. XU(I)) GOTO 50
IF (XL(I) .EQ. XU(I)) MEQL=MEQL+1
20 CONTINUE
C
C Initialize U, Z and XBIG.
C
JACT=0
NN=N*N
DO 30 I=1,NN
Z(I)=ZERO
30 CONTINUE
IZ=0
DO 40 I=1,N
IF (XL(I) .EQ. XU(I)) THEN
X(I)=XU(I)
JACT=JACT+1
U(JACT)=ONE
IACT(JACT)=I+M+N
J=JACT
ELSE
J=I+MEQL-JACT
END IF
Z(IZ+J)=ONE
IZ=IZ+N
XBIG(I)=DABS(X(I))
40 CONTINUE
INFO=1
50 RETURN
END
SUBROUTINE VE11HD (N,M,A,IA,IACT,NACT,Z,U,RELACC,INDXBD,ZTC,
1 CGRAD)
IMPLICIT DOUBLE PRECISION (A-H,O-Z)
DIMENSION A(IA,*),IACT(*),Z(*),U(*),ZTC(*),CGRAD(*)
DATA ZERO/0.0D0/,ONE/1.0D0/
NP=NACT+1
ICON=IACT(INDXBD)
IACT(INDXBD)=IACT(NP)
IACT(NP)=ICON
C
C Form ZTC when the new constraint is a bound.
C
IF (ICON .GT. M) THEN
INEWBD=ICON-M
IF (INEWBD .LE. N) THEN
TEMP=-ONE
ELSE
INEWBD=INEWBD-N
TEMP=ONE
END IF
IZNBD=INEWBD*N-N
DO 10 J=1,N
ZTC(J)=TEMP*Z(IZNBD+J)
10 CONTINUE
C
C Else form ZTC for an ordinary constraint.
C
ELSE
DO 20 I=1,N
CGRAD(I)=A(I,ICON)
20 CONTINUE
DO 35 J=1,N
ZTC(J)=ZERO
IZ=J
DO 30 I=1,N
ZTC(J)=ZTC(J)+Z(IZ)*CGRAD(I)
IZ=IZ+N
30 CONTINUE
35 CONTINUE
END IF
C
C Find any Givens rotations to apply to the last columns of Z.
C
J=N
40 JP=J
J=J-1
IF (J .GT. NACT) THEN
IF (ZTC(JP) .EQ. ZERO) GOTO 40
IF (DABS(ZTC(JP)) .LE. RELACC*DABS(ZTC(J))) THEN
TEMP=DABS(ZTC(J))
ELSE IF (DABS(ZTC(J)) .LE. RELACC*DABS(ZTC(JP))) THEN
TEMP=DABS(ZTC(JP))
ELSE
TEMP=DABS(ZTC(JP))*DSQRT(ONE+(ZTC(J)/ZTC(JP))**2)
END IF
WCOS=ZTC(J)/TEMP
WSIN=ZTC(JP)/TEMP
ZTC(J)=TEMP
C
C Apply the rotation when the new constraint is a bound.
C
IZ=J
IF (ICON .GT. M) THEN
DO 50 I=1,N
TEMP=WCOS*Z(IZ+1)-WSIN*Z(IZ)
Z(IZ)=WCOS*Z(IZ)+WSIN*Z(IZ+1)
Z(IZ+1)=TEMP
IZ=IZ+N
50 CONTINUE
Z(IZNBD+JP)=ZERO
C
C Else apply the rotation for an ordinary constraint.
C
ELSE
WPIV=ZERO
DO 60 I=1,N
TEMPA=WCOS*Z(IZ+1)
TEMPB=WSIN*Z(IZ)
TEMP=DABS(CGRAD(I))*(DABS(TEMPA)+DABS(TEMPB))
IF (TEMP .GT. WPIV) THEN
WPIV=TEMP
IPIV=I
END IF
Z(IZ)=WCOS*Z(IZ)+WSIN*Z(IZ+1)
Z(IZ+1)=TEMPA-TEMPB
IZ=IZ+N
60 CONTINUE
C
C Ensure orthogonality of Z(.,JP) to CGRAD.
C
SUM=ZERO
IZ=JP
DO 70 I=1,N
SUM=SUM+Z(IZ)*CGRAD(I)
IZ=IZ+N
70 CONTINUE
IF (SUM .NE. ZERO) THEN
IZ=IPIV*N-N+JP
Z(IZ)=Z(IZ)-SUM/CGRAD(IPIV)
END IF
END IF
GO TO 40
END IF
C
C Test for linear independence in the proposed new active set.
C
IF (ZTC(NP) .EQ. ZERO) GOTO 90
IF (ICON .LE. M) THEN
SUM=ZERO
SUMABS=ZERO
IZ=NP
DO 80 I=1,N
TEMP=Z(IZ)*CGRAD(I)
SUM=SUM+TEMP
SUMABS=SUMABS+DABS(TEMP)
IZ=IZ+N
80 CONTINUE
IF (DABS(SUM) .LE. RELACC*SUMABS) GOTO 90
END IF
C
C Set the new diagonal element of U and return.
C
U(NP)=ONE/ZTC(NP)
NACT=NP
90 RETURN
END
SUBROUTINE VE11GD (N,M,A,IA,B,XL,XU,X,IACT,NACT,XBIG,RELACC,TOL,
1 MEQL)
IMPLICIT DOUBLE PRECISION (A-H,O-Z)
DIMENSION A(IA,*),B(*),XL(*),XU(*),X(*),IACT(*),XBIG(*)
DATA ZERO/0.0D0/,ONE/1.0D0/
C
C Set VIOL to the greatest relative constraint residual of the first
C NACT constraints.
C
VIOL=ZERO
IF (NACT .GT. MEQL) THEN
KL=MEQL+1
DO 20 K=KL,NACT
J=IACT(K)
IF (J .LE. M) THEN
RES=B(J)
RESABS=DABS(B(J))
DO 10 I=1,N
RES=RES-A(I,J)*X(I)
RESABS=RESABS+DABS(A(I,J)*XBIG(I))
10 CONTINUE
ELSE
JM=J-M
IF (JM .LE. N) THEN
RES=X(JM)-XL(JM)
RESABS=XBIG(JM)+DABS(XL(JM))
ELSE
JM=JM-N
RES=XU(JM)-X(JM)
RESABS=XBIG(JM)+DABS(XU(JM))
END IF
END IF
IF (RES .GT. ZERO) VIOL=DMAX1(VIOL,RES/RESABS)
20 CONTINUE
END IF
C
C Adjust TOL.
C
TOL=0.1*DMIN1(TOL,VIOL)
IF (TOL .LE. RELACC+RELACC) THEN
TOL=RELACC
DO 30 I=1,N
XBIG(I)=DABS(X(I))
30 CONTINUE
END IF
RETURN
END
SUBROUTINE VE11JD (N,M,A,IA,B,XL,XU,X,IACT,NACT,PAR,G,Z,U,XBIG,
1 BRES,D,ZTG,RELACC,TOL,STEPCB,SUMRES,MEQL,MSAT,MTOT,INDXBD,
2 GM,GMNEW,PARNEW,CGRAD)
IMPLICIT DOUBLE PRECISION (A-H,O-Z)
DIMENSION A(IA,*),B(*),XL(*),XU(*),X(*),IACT(*),PAR(*),G(*),
1 Z(*),U(*),XBIG(*),BRES(*),D(*),ZTG(*),GM(*),GMNEW(*),PARNEW(*),
2 CGRAD(*)
DATA ZERO/0.0D0/,ONE/1.0D0/
IDIFF=MTOT-MSAT
C
C Calculate and partition the residuals of the inactive constraints,
C and set the gradient vector when seeking feasibility.
C
IF (IDIFF .GT. 0) THEN
DO 10 I=1,N
G(I)=ZERO
10 CONTINUE
SUMRES=ZERO
END IF
MSATK=MSAT
MDEG=NACT
MSAT=NACT
KL=MEQL+1
DO 50 K=KL,MTOT
J=IACT(K)
C
C Calculate the residual of the current constraint.
C
IF (J .LE. M) THEN
RES=B(J)
RESABS=DABS(B(J))
DO 20 I=1,N
RES=RES-X(I)*A(I,J)
RESABS=RESABS+DABS(XBIG(I)*A(I,J))
20 CONTINUE
ELSE
JM=J-M
IF (JM .LE. N) THEN
RES=X(JM)-XL(JM)
RESABS=DABS(XBIG(JM))+DABS(XL(JM))
ELSE
JM=JM-N
RES=XU(JM)-X(JM)
RESABS=DABS(XBIG(JM))+DABS(XU(JM))
END IF
END IF
BRES(J)=RES
C
C Set TEMP to the relative residual.
C
TEMP=ZERO
IF (RESABS .NE. ZERO) TEMP=RES/RESABS
IF (K .GT. MSATK .AND. TEMP .LT. ZERO) THEN
IF (TEMP+RELACC .GE. ZERO) THEN
IF (J .LE. M) THEN
SUM=DABS(B(J))
DO 30 I=1,N
SUM=SUM+DABS(X(I)*A(I,J))
30 CONTINUE
ELSE
JM=J-M
IF (JM .LE. N) THEN
SUM=DABS(X(JM))+DABS(XL(JM))
ELSE
SUM=DABS(X(JM-N))+DABS(XU(JM-N))
END IF
END IF
IF (DABS(RES) .LE. SUM*RELACC) TEMP=ZERO
END IF
END IF
C
C Place the residual in the appropriate position.
C
IF (K .LE. NACT) GOTO 50
IF (K .LE. MSATK .OR. TEMP .GE. ZERO) THEN
MSAT=MSAT+1
IF (MSAT .LT. K) THEN
IACT(K)=IACT(MSAT)
END IF
IF (TEMP .GT. TOL) THEN
IACT(MSAT)=J
ELSE
MDEG=MDEG+1
IACT(MSAT)=IACT(MDEG)
IACT(MDEG)=J
END IF
C
C Update the gradient and SUMRES if the constraint is violated when
C seeking feasibility.
C
ELSE
IF (J .LE. M) THEN
DO 40 I=1,N
G(I)=G(I)+A(I,J)
40 CONTINUE
ELSE
J=J-M
IF (J .LE. N) THEN
G(J)=G(J)-ONE
ELSE
G(J-N)=G(J-N)+ONE
END IF
END IF
SUMRES=SUMRES+DABS(RES)
END IF
50 CONTINUE
C
C Seek the next search direction unless VE11JD was called from VE11ED
C and feasibility has been achieved.
C
STEPCB=ZERO
IF (IDIFF .GT. 0 .AND. MSAT .EQ. MTOT) GOTO 60
CALL VE11OD (N,M,A,IA,IACT,NACT,PAR,G,Z,U,D,ZTG,RELACC,DDOTG,MEQL,
1 MDEG,GM,GMNEW,PARNEW,CGRAD)
C
C Calculate the (bound on the) step-length due to the constraints.
C
IF (DDOTG .LT. ZERO) THEN
CALL VE11PD (N,M,A,IA,IACT,BRES,D,STEPCB,DDOTG,MDEG,MSAT,
1 MTOT,INDXBD)
END IF
IF (IDIFF .EQ. 0) SUMRES=DDOTG
60 RETURN
END
SUBROUTINE VE11ND (N,M,A,IA,IACT,NACT,Z,U,RELACC,IDROP)
IMPLICIT DOUBLE PRECISION (A-H,O-Z)
DIMENSION A(IA,*),IACT(*),Z(*),U(*)
DATA ZERO/0.0D0/,ONE/1.0D0/
NM=NACT-1
IF (IDROP .EQ. NACT) GOTO 60
ISAVE=IACT(IDROP)
C
C Cycle through the constraint exchanges that are needed.
C
DO 50 J=IDROP,NM
JP=J+1
ICON=IACT(JP)
IACT(J)=ICON
C
C Calculate the (J,JP) element of R.
C
IF (ICON .LE. M) THEN
RJJP=ZERO
IZ=J
DO 10 I=1,N
RJJP=RJJP+Z(IZ)*A(I,ICON)
IZ=IZ+N
10 CONTINUE
ELSE
IBD=ICON-M
IF (IBD .LE. N) THEN
IZBD=IBD*N-N
RJJP=-Z(IZBD+J)
ELSE
IBD=IBD-N
IZBD=IBD*N-N
RJJP=Z(IZBD+J)
END IF
END IF
C
C Calculate the parameters of the next rotation.
C
UJP=U(JP)
TEMP=RJJP*UJP
DENOM=DABS(TEMP)
IF (DENOM*RELACC .LT. ONE) DENOM=DSQRT(ONE+DENOM*DENOM)
WCOS=TEMP/DENOM
WSIN=ONE/DENOM
C
C Rotate Z when a bound constraint is promoted.
C
IZ=J
IF (ICON .GT. M) THEN
DO 20 I=1,N
TEMP=WCOS*Z(IZ+1)-WSIN*Z(IZ)
Z(IZ)=WCOS*Z(IZ)+WSIN*Z(IZ+1)
Z(IZ+1)=TEMP
IZ=IZ+N
20 CONTINUE
Z(IZBD+JP)=ZERO
C
C Rotate Z when an ordinary constraint is promoted.
C
ELSE
WPIV=ZERO
DO 30 I=1,N
TEMPA=WCOS*Z(IZ+1)
TEMPB=WSIN*Z(IZ)
TEMP=DABS(A(I,ICON))*(DABS(TEMPA)+DABS(TEMPB))
IF (TEMP .GT. WPIV) THEN
WPIV=TEMP
IPIV=I
END IF
Z(IZ)=WCOS*Z(IZ)+WSIN*Z(IZ+1)
Z(IZ+1)=TEMPA-TEMPB
IZ=IZ+N
30 CONTINUE
C
C Ensure orthogonality to promoted constraint.
C
SUM=ZERO
IZ=JP
DO 40 I=1,N
SUM=SUM+Z(IZ)*A(I,ICON)
IZ=IZ+N
40 CONTINUE
IF (SUM .NE. ZERO) THEN
IZ=IPIV*N-N+JP
Z(IZ)=Z(IZ)-SUM/A(IPIV,ICON)
END IF
END IF
C
C Set the new diagonal elements of U.
C
U(JP)=-DENOM*U(J)
U(J)=UJP/DENOM
50 CONTINUE
C
C Return.
C
IACT(NACT)=ISAVE
60 NACT=NM
RETURN
END
SUBROUTINE VE11DD (N,M,MEQ,A,IA,B,XU,IACT,MEQL,INFO,Z,U,RELACC,
1 AM,CGRAD)
IMPLICIT DOUBLE PRECISION (A-H,O-Z)
DIMENSION A(IA,*),B(*),XU(*),IACT(*),Z(*),U(*),AM(*),CGRAD(*)
DATA ZERO/0.0D0/,ONE/1.0D0/
C
C Try to add the next equality constraint to the active set.
C
DO 50 KEQ=1,MEQ
IF (MEQL .LT. N) THEN
NP=MEQL+1
IACT(NP)=KEQ
CALL VE11HD (N,M,A,IA,IACT,MEQL,Z,U,RELACC,NP,AM,CGRAD)
IF (MEQL .EQ. NP) GOTO 50
END IF
C
C If linear dependence occurs then find the multipliers of the
C dependence relation and apply them to the right hand sides.
C
SUM=B(KEQ)
SUMABS=DABS(B(KEQ))
IF (MEQL .GT. 0) THEN
DO 10 I=1,N
AM(I)=A(I,KEQ)
10 CONTINUE
K=MEQL
20 VMULT=ZERO
IZ=K
DO 30 I=1,N
VMULT=VMULT+Z(IZ)*AM(I)
IZ=IZ+N
30 CONTINUE
VMULT=VMULT*U(K)
J=IACT(K)
IF (J .LE. M) THEN
DO 40 I=1,N
AM(I)=AM(I)-VMULT*A(I,J)
40 CONTINUE
RHS=B(J)
ELSE
JM=J-M-N
AM(JM)=AM(JM)-VMULT
RHS=XU(JM)
END IF
SUM=SUM-RHS*VMULT
SUMABS=SUMABS+DABS(RHS*VMULT)
K=K-1
IF (K .GE. 1) GOTO 20
END IF
C
C Error return if the constraints are inconsistent.
C
IF (DABS(SUM) .GT. RELACC*SUMABS) THEN
INFO=5
GOTO 60
END IF
50 CONTINUE
60 RETURN
END
SUBROUTINE VE11OD (N,M,A,IA,IACT,NACT,PAR,G,Z,U,D,ZTG,RELACC,
1 DDOTG,MEQL,MDEG,GM,GMNEW,PARNEW,CGRAD)
IMPLICIT DOUBLE PRECISION (A-H,O-Z)
DIMENSION A(IA,*),IACT(*),PAR(*),G(*),Z(*),U(*),D(*),ZTG(*),
1 GM(*),GMNEW(*),PARNEW(*),CGRAD(*)
DATA ZERO/0.0D0/,ONE/1.0D0/
C
C Initialize GM and cycle backwards through the active set.
C
10 DO 20 I=1,N
GM(I)=G(I)
20 CONTINUE
K=NACT
30 IF (K .GT. 0) THEN
C
C Set TEMP to the next multiplier, but reduce the active set if
C TEMP has an unacceptable sign.
C
TEMP=ZERO
IZ=K
DO 40 I=1,N
TEMP=TEMP+Z(IZ)*GM(I)
IZ=IZ+N
40 CONTINUE
TEMP=TEMP*U(K)
IF (K .GT. MEQL .AND. TEMP .GT. ZERO) THEN
CALL VE11ND (N,M,A,IA,IACT,NACT,Z,U,RELACC,K)
GOTO 10
END IF
C
C Update GM using the multiplier that has just been calculated.
C
J=IACT(K)
IF (J .LE. M) THEN
DO 50 I=1,N
GM(I)=GM(I)-TEMP*A(I,J)
50 CONTINUE
ELSE
JM=J-M
IF (JM .LE. N) THEN
GM(JM)=GM(JM)+TEMP
ELSE
GM(JM-N)=GM(JM-N)-TEMP
END IF
END IF
PAR(K)=TEMP
K=K-1
GOTO 30
END IF
C
C Calculate the search direction and DDOTG.
C
DDOTG=ZERO
IF (NACT .LT. N) THEN
CALL VE11QD (N,M,A,IA,IACT,NACT,PAR,Z,U,D,ZTG,GM,RELACC,
1 DDOTGM,MEQL,MDEG,GMNEW,PARNEW,CGRAD)
IF (DDOTGM .LT. ZERO) THEN
DO 60 I=1,N
DDOTG=DDOTG+D(I)*G(I)
60 CONTINUE
END IF
END IF
RETURN
END
SUBROUTINE VE11ED (N,M,A,IA,B,XL,XU,X,IACT,NACT,PAR,INFO,G,Z,
1 U,XBIG,RELACC,TOL,MEQL,MSAT,MTOT,BRES,D,ZTG,GM,GMNEW,PARNEW,
2 CGRAD)
IMPLICIT DOUBLE PRECISION (A-H,O-Z)
DIMENSION A(IA,*),B(*),XL(*),XU(*),X(*),IACT(*),PAR(*),G(*),Z(*),
1 U(*),XBIG(*),BRES(*),D(*),ZTG(*),GM(*),GMNEW(*),PARNEW(*),
2 CGRAD(*)
DATA ZERO/0.0D0/,ONE/1.0D0/
C
C Make the correction to X for the active constraints.
C
INFO=0
10 CALL VE11ID (N,M,A,IA,B,XL,XU,X,IACT,NACT,INFO,Z,U,XBIG,RELACC,
1 TOL,MEQL)
IF (INFO .GT. 0) MSAT=NACT
IF (MSAT .EQ. MTOT) GOTO 60
C
C Try to correct the infeasibility.
C
20 MSATK=MSAT
SUMRSK=ZERO
30 CALL VE11JD (N,M,A,IA,B,XL,XU,X,IACT,NACT,PAR,G,Z,U,XBIG,BRES,
1 D,ZTG,RELACC,TOL,STEPCB,SUMRES,MEQL,MSAT,MTOT,INDXBD,GM,GMNEW,
2 PARNEW,CGRAD)
C
C Include the new constraint in the active set.
C
IF (STEPCB .GT. ZERO) THEN
DO 40 I=1,N
X(I)=X(I)+STEPCB*D(I)
XBIG(I)=DMAX1(XBIG(I),DABS(X(I)))
40 CONTINUE
CALL VE11HD (N,M,A,IA,IACT,NACT,Z,U,RELACC,INDXBD,GMNEW,CGRAD)
END IF
C
C Test whether to continue the search for feasibility.
C
IF (MSAT .LT. MTOT) THEN
IF (STEPCB .EQ. ZERO) GOTO 50
IF (MSATK .LT. MSAT) GOTO 20
IF (SUMRSK .EQ. ZERO .OR. SUMRES .LT. SUMRSK) THEN
SUMRSK=SUMRES
ITEST=0
END IF
ITEST=ITEST+1
IF (ITEST .LE. 2) GOTO 30
C
C Reduce TOL if it may be too large to allow feasibility.
C
50 IF (TOL .GT. RELACC) THEN
CALL VE11GD (N,M,A,IA,B,XL,XU,X,IACT,NACT,XBIG,RELACC,
1 TOL,MEQL)
GOTO 10
END IF
END IF
60 RETURN
END
SUBROUTINE VE11KD (N,M,A,IA,IACT,NACT,PAR,G,RESKT,Z,U,BRES,RELAXF,
1 MEQL,SSQKT,PARW,RESKTW)
IMPLICIT DOUBLE PRECISION (A-H,O-Z)
DIMENSION A(IA,*),IACT(*),PAR(*),G(*),RESKT(*),Z(*),U(*),
1 BRES(*),PARW(*),RESKTW(*)
DATA ZERO/0.0D0/,ONE/1.0D0/
C
C Calculate the Lagrange parameters and the residual vector.
C
DO 10 I=1,N
RESKT(I)=G(I)
10 CONTINUE
IF (NACT .GT. 0) THEN
ICASE=0
20 DO 50 KK=1,NACT
K=NACT+1-KK
J=IACT(K)
TEMP=ZERO
IZ=K
DO 30 I=1,N
TEMP=TEMP+Z(IZ)*RESKT(I)
IZ=IZ+N
30 CONTINUE
TEMP=TEMP*U(K)
IF (ICASE .EQ. 0) PAR(K)=ZERO
IF (K .LE. MEQL .OR. PAR(K)+TEMP .LT. ZERO) THEN
PAR(K)=PAR(K)+TEMP
ELSE
TEMP=-PAR(K)
PAR(K)=ZERO
END IF
IF (TEMP .NE. ZERO) THEN
IF (J .LE. M) THEN
DO 40 I=1,N
RESKT(I)=RESKT(I)-TEMP*A(I,J)
40 CONTINUE
ELSE
JM=J-M
IF (JM .LE. N) THEN
RESKT(JM)=RESKT(JM)+TEMP
ELSE
RESKT(JM-N)=RESKT(JM-N)-TEMP
END IF
END IF
END IF
50 CONTINUE
C
C Calculate the sum of squares of the KT residual vector.
C
SSQKT=ZERO
IF (NACT .EQ. N) GOTO 130
DO 60 I=1,N
SSQKT=SSQKT+RESKT(I)**2
60 CONTINUE
C
C Apply iterative refinement to the residual vector.
C
IF (ICASE .EQ. 0) THEN
ICASE=1
DO 70 K=1,NACT
PARW(K)=PAR(K)
70 CONTINUE
DO 80 I=1,N
RESKTW(I)=RESKT(I)
80 CONTINUE
SSQKTW=SSQKT
GOTO 20
END IF
C
C Undo the iterative refinement if it does not reduce SSQKT.
C
IF (SSQKTW .LT. SSQKT) THEN
DO 90 K=1,NACT
PAR(K)=PARW(K)
90 CONTINUE
DO 100 I=1,N
RESKT(I)=RESKTW(I)
100 CONTINUE
SSQKT=SSQKTW
END IF
C
C Calculate SSQKT when there are no active constraints.
C
ELSE
SSQKT=ZERO
DO 110 I=1,N
SSQKT=SSQKT+G(I)**2
110 CONTINUE
END IF
C
C Predict the reduction in F if one corrects any positive residuals
C of active inequality constraints.
C
RELAXF=ZERO
IF (MEQL. LT. NACT) THEN
KL=MEQL+1
DO 120 K=KL,NACT
J=IACT(K)
IF (BRES(J) .GT. ZERO) THEN
RELAXF=RELAXF-PAR(K)*BRES(J)
END IF
120 CONTINUE
END IF
130 RETURN
END
SUBROUTINE VE11LD (N,X,G,D,XS,GS,RELACC,STEPCB,DDOTG,F,STEP,
1 NFVALS,NFMAX,GOPT,FGCALC)
IMPLICIT DOUBLE PRECISION (A-H,O-Z)
DIMENSION X(*),G(*),D(*),XS(*),GS(*),GOPT(*)
EXTERNAL FGCALC
DATA ZERO/0.0D0/,ONE/1.0D0/
C
C Initialization.
C
RELINT=0.9
ICOUNT=0
RATIO=-ONE
DO 10 I=1,N
XS(I)=X(I)
GS(I)=G(I)
GOPT(I)=G(I)
IF (D(I) .NE. ZERO) THEN
TEMP=DABS(X(I)/D(I))
IF (RATIO .LT. ZERO .OR. TEMP .LT. RATIO) RATIO=TEMP
END IF
10 CONTINUE
STEP=DMIN1(ONE,STEPCB)
STPMIN=DMAX1(RELACC*RATIO,1.0E-12*STEP)
STEP=DMAX1(STPMIN,STEP)
SBASE=ZERO
FBASE=F
DDOTGB=DDOTG
STPLOW=ZERO
FLOW=F
DGLOW=DDOTG
STPHGH=ZERO
STPOPT=ZERO
FOPT=F
DGOPT=DABS(DDOTG)
C
C Calculate another function and gradient value.
C
20 DO 30 I=1,N
X(I)=XS(I)+STEP*D(I)
30 CONTINUE
CALL FGCALC (N,X,F,G)
ICOUNT=ICOUNT+1
DGMID=ZERO
DO 40 I=1,N
DGMID=DGMID+D(I)*G(I)
40 CONTINUE
IF (F .LE. FOPT) THEN
IF (F .LT. FOPT .OR. DABS(DGMID) .LT. DGOPT) THEN
STPOPT=STEP
FOPT=F
DO 50 I=1,N
GOPT(I)=G(I)
50 CONTINUE
DGOPT=DABS(DGMID)
END IF
END IF
IF (NFVALS+ICOUNT .EQ. NFMAX) GOTO 70
C
C Modify the bounds on the steplength or convergence.
C
IF (F .GE. FBASE+0.1*(STEP-SBASE)*DDOTGB) THEN
IF (STPHGH .GT. ZERO .OR. F .GT. FBASE .OR. DGMID .GT.
1 0.5*DDOTG) THEN
STPHGH=STEP
FHGH=F
DGHGH=DGMID
GOTO 60
END IF
SBASE=STEP
FBASE=F
DDOTGB=DGMID
END IF
IF (DGMID .GE. 0.7*DDOTGB) GOTO 70
STPLOW=STEP
FLOW=F
DGLOW=DGMID
60 IF (STPHGH .GT. ZERO .AND. STPLOW .GE. RELINT*STPHGH) GOTO 70
C
C Calculate the next step length or end the iterations.
C
IF (STPHGH .EQ. ZERO) THEN
IF (STEP .EQ. STEPCB) GOTO 70
TEMP=10.0
IF (DGMID .GT. 0.9*DDOTG) TEMP=DDOTG/(DDOTG-DGMID)
STEP=DMIN1(TEMP*STEP,STEPCB)
GOTO 20