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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
#include "lbfgsb.h"
static integer c__1 = 1;
/* Table of constant values */
static integer c__11 = 11;
/* Subroutine */ int active(integer *n, double *l, double *u,
integer *nbd, double *x, integer *iwhere, integer *iprint,
logical *prjctd, logical *cnstnd, logical *boxed)
{
/* System generated locals */
integer i__1;
/* Local variables */
static integer i__, nbdd;
/* ************ */
/* Subroutine active */
/* This subroutine initializes iwhere and projects the initial x to */
/* the feasible set if necessary. */
/* iwhere is an integer array of dimension n. */
/* On entry iwhere is unspecified. */
/* On exit iwhere(i)=-1 if x(i) has no bounds */
/* 3 if l(i)=u(i) */
/* 0 otherwise. */
/* In cauchy, iwhere is given finer gradations. */
/* * * * */
/* NEOS, November 1994. (Latest revision June 1996.) */
/* Optimization Technology Center. */
/* Argonne National Laboratory and Northwestern University. */
/* Written by */
/* Ciyou Zhu */
/* in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal. */
/* ************ */
/* Initialize nbdd, prjctd, cnstnd and boxed. */
/* Parameter adjustments */
--iwhere;
--x;
--nbd;
--u;
--l;
/* Function Body */
nbdd = 0;
*prjctd = FALSE_;
*cnstnd = FALSE_;
*boxed = TRUE_;
/* Project the initial x to the easible set if necessary. */
i__1 = *n;
for (i__ = 1; i__ <= i__1; ++i__) {
if (nbd[i__] > 0) {
if (nbd[i__] <= 2 && x[i__] <= l[i__]) {
if (x[i__] < l[i__]) {
*prjctd = TRUE_;
x[i__] = l[i__];
}
++nbdd;
} else if (nbd[i__] >= 2 && x[i__] >= u[i__]) {
if (x[i__] > u[i__]) {
*prjctd = TRUE_;
x[i__] = u[i__];
}
++nbdd;
}
}
/* L10: */
}
/* Initialize iwhere and assign values to cnstnd and boxed. */
i__1 = *n;
for (i__ = 1; i__ <= i__1; ++i__) {
if (nbd[i__] != 2) {
*boxed = FALSE_;
}
if (nbd[i__] == 0) {
/* this variable is always free */
iwhere[i__] = -1;
/* otherwise set x(i)=mid(x(i), u(i), l(i)). */
} else {
*cnstnd = TRUE_;
if (nbd[i__] == 2 && u[i__] - l[i__] <= 0.) {
/* this variable is always fixed */
iwhere[i__] = 3;
} else {
iwhere[i__] = 0;
}
}
/* L20: */
}
if (*iprint >= 0) {
if (*prjctd) {
printf("The initial X is infeasible. Restart with its projection\n");
}
if (! (*cnstnd)) {
printf("This problem is unconstrained\n");
}
}
if (*iprint > 0) {
printf("At X0, %ld variables are exactly at the bounds\n",nbdd);
}
return 0;
} /* active */
/* ======================= The end of active ============================= */
/* Subroutine */ int bmv(integer *m, double *sy, double *wt, integer
*col, double *v, double *p, integer *info)
{
/* System generated locals */
integer sy_dim1, sy_offset, wt_dim1, wt_offset, i__1, i__2;
/* Builtin functions */
double sqrt(double);
/* Local variables */
static integer i__, k, i2;
static double sum;
/* ************ */
/* Subroutine bmv */
/* This subroutine computes the product of the 2m x 2m middle matrix */
/* in the compact L-BFGS formula of B and a 2m vector v; */
/* it returns the product in p. */
/* m is an integer variable. */
/* On entry m is the maximum number of variable metric corrections */
/* used to define the limited memory matrix. */
/* On exit m is unchanged. */
/* sy is a double precision array of dimension m x m. */
/* On entry sy specifies the matrix S'Y. */
/* On exit sy is unchanged. */
/* wt is a double precision array of dimension m x m. */
/* On entry wt specifies the upper triangular matrix J' which is */
/* the Cholesky factor of (thetaS'S+LD^(-1)L'). */
/* On exit wt is unchanged. */
/* col is an integer variable. */
/* On entry col specifies the number of s-vectors (or y-vectors) */
/* stored in the compact L-BFGS formula. */
/* On exit col is unchanged. */
/* v is a double precision array of dimension 2col. */
/* On entry v specifies vector v. */
/* On exit v is unchanged. */
/* p is a double precision array of dimension 2col. */
/* On entry p is unspecified. */
/* On exit p is the product Mv. */
/* info is an integer variable. */
/* On entry info is unspecified. */
/* On exit info = 0 for normal return, */
/* = nonzero for abnormal return when the system */
/* to be solved by dtrsl is singular. */
/* Subprograms called: */
/* Linpack ... dtrsl. */
/* * * * */
/* NEOS, November 1994. (Latest revision June 1996.) */
/* Optimization Technology Center. */
/* Argonne National Laboratory and Northwestern University. */
/* Written by */
/* Ciyou Zhu */
/* in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal. */
/* ************ */
/* Parameter adjustments */
wt_dim1 = *m;
wt_offset = 1 + wt_dim1;
wt -= wt_offset;
sy_dim1 = *m;
sy_offset = 1 + sy_dim1;
sy -= sy_offset;
--p;
--v;
/* Function Body */
if (*col == 0) {
return 0;
}
/* PART I: solve [ D^(1/2) O ] [ p1 ] = [ v1 ] */
/* [ -L*D^(-1/2) J ] [ p2 ] [ v2 ]. */
/* solve Jp2=v2+LD^(-1)v1. */
p[*col + 1] = v[*col + 1];
i__1 = *col;
for (i__ = 2; i__ <= i__1; ++i__) {
i2 = *col + i__;
sum = 0.;
i__2 = i__ - 1;
for (k = 1; k <= i__2; ++k) {
sum += sy[i__ + k * sy_dim1] * v[k] / sy[k + k * sy_dim1];
/* L10: */
}
p[i2] = v[i2] + sum;
/* L20: */
}
/* Solve the triangular system */
dtrsl(&wt[wt_offset], m, col, &p[*col + 1], &c__11, info);
if (*info != 0) {
return 0;
}
/* solve D^(1/2)p1=v1. */
i__1 = *col;
for (i__ = 1; i__ <= i__1; ++i__) {
p[i__] = v[i__] / sqrt(sy[i__ + i__ * sy_dim1]);
/* L30: */
}
/* PART II: solve [ -D^(1/2) D^(-1/2)*L' ] [ p1 ] = [ p1 ] */
/* [ 0 J' ] [ p2 ] [ p2 ]. */
/* solve J^Tp2=p2. */
dtrsl(&wt[wt_offset], m, col, &p[*col + 1], &c__1, info);
if (*info != 0) {
return 0;
}
/* compute p1=-D^(-1/2)(p1-D^(-1/2)L'p2) */
/* =-D^(-1/2)p1+D^(-1)L'p2. */
i__1 = *col;
for (i__ = 1; i__ <= i__1; ++i__) {
p[i__] = -p[i__] / sqrt(sy[i__ + i__ * sy_dim1]);
/* L40: */
}
i__1 = *col;
for (i__ = 1; i__ <= i__1; ++i__) {
sum = 0.;
i__2 = *col;
for (k = i__ + 1; k <= i__2; ++k) {
sum += sy[k + i__ * sy_dim1] * p[*col + k] / sy[i__ + i__ *
sy_dim1];
/* L50: */
}
p[i__] += sum;
/* L60: */
}
return 0;
} /* bmv */
/* ======================== The end of bmv =============================== */
/* Subroutine */ int cauchy(integer *n, double *x, double *l,
double *u, integer *nbd, double *g, integer *iorder, integer *
iwhere, double *t, double *d__, double *xcp, integer *m,
double *wy, double *ws, double *sy, double *wt,
double *theta, integer *col, integer *head, double *p,
double *c__, double *wbp, double *v, integer *nseg,
integer *iprint, double *sbgnrm, integer *info, double *
epsmch)
{
/* System generated locals */
integer wy_dim1, wy_offset, ws_dim1, ws_offset, sy_dim1, sy_offset,
wt_dim1, wt_offset, i__1, i__2;
double d__1;
/* Local variables */
static integer i__, j;
static double f1, f2, dt, tj, tl, tu, tj0;
static integer ibp;
static double dtm;
extern /* Subroutine */ int bmv(integer *, double *, double *,
integer *, double *, double *, integer *);
static double wmc, wmp, wmw;
static integer col2;
static double dibp;
static integer iter;
static double zibp, tsum, dibp2;
static logical bnded;
static double neggi;
static integer nfree;
static double bkmin;
static integer nleft;
static double f2_org__;
static integer nbreak, ibkmin;
extern /* Subroutine */ int hpsolb(integer *, double *, integer *,
integer *);
static integer pointr;
static logical xlower, xupper;
/* ************ */
/* Subroutine cauchy */
/* For given x, l, u, g (with sbgnrm > 0), and a limited memory */
/* BFGS matrix B defined in terms of matrices WY, WS, WT, and */
/* scalars head, col, and theta, this subroutine computes the */
/* generalized Cauchy point (GCP), defined as the first local */
/* minimizer of the quadratic */
/* Q(x + s) = g's + 1/2 s'Bs */
/* along the projected gradient direction P(x-tg,l,u). */
/* The routine returns the GCP in xcp. */
/* n is an integer variable. */
/* On entry n is the dimension of the problem. */
/* On exit n is unchanged. */
/* x is a double precision array of dimension n. */
/* On entry x is the starting point for the GCP computation. */
/* On exit x is unchanged. */
/* l is a double precision array of dimension n. */
/* On entry l is the lower bound of x. */
/* On exit l is unchanged. */
/* u is a double precision array of dimension n. */
/* On entry u is the upper bound of x. */
/* On exit u is unchanged. */
/* nbd is an integer array of dimension n. */
/* On entry nbd represents the type of bounds imposed on the */
/* variables, and must be specified as follows: */
/* nbd(i)=0 if x(i) is unbounded, */
/* 1 if x(i) has only a lower bound, */
/* 2 if x(i) has both lower and upper bounds, and */
/* 3 if x(i) has only an upper bound. */
/* On exit nbd is unchanged. */
/* g is a double precision array of dimension n. */
/* On entry g is the gradient of f(x). g must be a nonzero vector. */
/* On exit g is unchanged. */
/* iorder is an integer working array of dimension n. */
/* iorder will be used to store the breakpoints in the piecewise */
/* linear path and free variables encountered. On exit, */
/* iorder(1),...,iorder(nleft) are indices of breakpoints */
/* which have not been encountered; */
/* iorder(nleft+1),...,iorder(nbreak) are indices of */
/* encountered breakpoints; and */
/* iorder(nfree),...,iorder(n) are indices of variables which */
/* have no bound constraits along the search direction. */
/* iwhere is an integer array of dimension n. */
/* On entry iwhere indicates only the permanently fixed (iwhere=3) */
/* or free (iwhere= -1) components of x. */
/* On exit iwhere records the status of the current x variables. */
/* iwhere(i)=-3 if x(i) is free and has bounds, but is not moved */
/* 0 if x(i) is free and has bounds, and is moved */
/* 1 if x(i) is fixed at l(i), and l(i) .ne. u(i) */
/* 2 if x(i) is fixed at u(i), and u(i) .ne. l(i) */
/* 3 if x(i) is always fixed, i.e., u(i)=x(i)=l(i) */
/* -1 if x(i) is always free, i.e., it has no bounds. */
/* t is a double precision working array of dimension n. */
/* t will be used to store the break points. */
/* d is a double precision array of dimension n used to store */
/* the Cauchy direction P(x-tg)-x. */
/* xcp is a double precision array of dimension n used to return the */
/* GCP on exit. */
/* m is an integer variable. */
/* On entry m is the maximum number of variable metric corrections */
/* used to define the limited memory matrix. */
/* On exit m is unchanged. */
/* ws, wy, sy, and wt are double precision arrays. */
/* On entry they store information that defines the */
/* limited memory BFGS matrix: */
/* ws(n,m) stores S, a set of s-vectors; */
/* wy(n,m) stores Y, a set of y-vectors; */
/* sy(m,m) stores S'Y; */
/* wt(m,m) stores the */
/* Cholesky factorization of (theta*S'S+LD^(-1)L'). */
/* On exit these arrays are unchanged. */
/* theta is a double precision variable. */
/* On entry theta is the scaling factor specifying B_0 = theta I. */
/* On exit theta is unchanged. */
/* col is an integer variable. */
/* On entry col is the actual number of variable metric */
/* corrections stored so far. */
/* On exit col is unchanged. */
/* head is an integer variable. */
/* On entry head is the location of the first s-vector (or y-vector) */
/* in S (or Y). */
/* On exit col is unchanged. */
/* p is a double precision working array of dimension 2m. */
/* p will be used to store the vector p = W^(T)d. */
/* c is a double precision working array of dimension 2m. */
/* c will be used to store the vector c = W^(T)(xcp-x). */
/* wbp is a double precision working array of dimension 2m. */
/* wbp will be used to store the row of W corresponding */
/* to a breakpoint. */
/* v is a double precision working array of dimension 2m. */
/* nseg is an integer variable. */
/* On exit nseg records the number of quadratic segments explored */
/* in searching for the GCP. */
/* sg and yg are double precision arrays of dimension m. */
/* On entry sg and yg store S'g and Y'g correspondingly. */
/* On exit they are unchanged. */
/* iprint is an INTEGER variable that must be set by the user. */
/* It controls the frequency and type of output generated: */
/* iprint<0 no output is generated; */
/* iprint=0 print only one line at the last iteration; */
/* 0<iprint<99 print also f and |proj g| every iprint iterations; */
/* iprint=99 print details of every iteration except n-vectors; */
/* iprint=100 print also the changes of active set and final x; */
/* iprint>100 print details of every iteration including x and g; */
/* When iprint > 0, the file iterate.dat will be created to */
/* summarize the iteration. */
/* sbgnrm is a double precision variable. */
/* On entry sbgnrm is the norm of the projected gradient at x. */
/* On exit sbgnrm is unchanged. */
/* info is an integer variable. */
/* On entry info is 0. */
/* On exit info = 0 for normal return, */
/* = nonzero for abnormal return when the the system */
/* used in routine bmv is singular. */
/* Subprograms called: */
/* L-BFGS-B Library ... hpsolb, bmv. */
/* Linpack ... dscal dcopy, daxpy. */
/* References: */
/* [1] R. H. Byrd, P. Lu, J. Nocedal and C. Zhu, ``A limited */
/* memory algorithm for bound constrained optimization'', */
/* SIAM J. Scientific Computing 16 (1995), no. 5, pp. 1190--1208. */
/* [2] C. Zhu, R.H. Byrd, P. Lu, J. Nocedal, ``L-BFGS-B: FORTRAN */
/* Subroutines for Large Scale Bound Constrained Optimization'' */
/* Tech. Report, NAM-11, EECS Department, Northwestern University, */
/* 1994. */
/* (Postscript files of these papers are available via anonymous */
/* ftp to eecs.nwu.edu in the directory pub/lbfgs/lbfgs_bcm.) */
/* * * * */
/* NEOS, November 1994. (Latest revision June 1996.) */
/* Optimization Technology Center. */
/* Argonne National Laboratory and Northwestern University. */
/* Written by */
/* Ciyou Zhu */
/* in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal. */
/* ************ */
/* Check the status of the variables, reset iwhere(i) if necessary; */
/* compute the Cauchy direction d and the breakpoints t; initialize */
/* the derivative f1 and the vector p = W'd (for theta = 1). */
/* Parameter adjustments */
--xcp;
--d__;
--t;
--iwhere;
--iorder;
--g;
--nbd;
--u;
--l;
--x;
--v;
--wbp;
--c__;
--p;
wt_dim1 = *m;
wt_offset = 1 + wt_dim1;
wt -= wt_offset;
sy_dim1 = *m;
sy_offset = 1 + sy_dim1;
sy -= sy_offset;
ws_dim1 = *n;
ws_offset = 1 + ws_dim1;
ws -= ws_offset;
wy_dim1 = *n;
wy_offset = 1 + wy_dim1;
wy -= wy_offset;
/* Function Body */
if (*sbgnrm <= 0.) {
if (*iprint >= 0) {
printf("Subnorm = 0. GCP = X.\n");
}
dcopy(n, &x[1], &c__1, &xcp[1], &c__1);
return 0;
}
bnded = TRUE_;
nfree = *n + 1;
nbreak = 0;
ibkmin = 0;
bkmin = 0.;
col2 = *col << 1;
f1 = 0.;
if (*iprint >= 99) {
printf("CAUCHY entered\n");
}
/* We set p to zero and build it up as we determine d. */
i__1 = col2;
for (i__ = 1; i__ <= i__1; ++i__) {
p[i__] = 0.;
/* L20: */
}
/* In the following loop we determine for each variable its bound */
/* status and its breakpoint, and update p accordingly. */
/* Smallest breakpoint is identified. */
i__1 = *n;
for (i__ = 1; i__ <= i__1; ++i__) {
neggi = -g[i__];
if (iwhere[i__] != 3 && iwhere[i__] != -1) {
/* if x(i) is not a constant and has bounds, */
/* compute the difference between x(i) and its bounds. */
if (nbd[i__] <= 2) {
tl = x[i__] - l[i__];
}
if (nbd[i__] >= 2) {
tu = u[i__] - x[i__];
}
/* If a variable is close enough to a bound */
/* we treat it as at bound. */
xlower = nbd[i__] <= 2 && tl <= 0.;
xupper = nbd[i__] >= 2 && tu <= 0.;
/* reset iwhere(i). */
iwhere[i__] = 0;
if (xlower) {
if (neggi <= 0.) {
iwhere[i__] = 1;
}
} else if (xupper) {
if (neggi >= 0.) {
iwhere[i__] = 2;
}
} else {
if (fabs(neggi) <= 0.) {
iwhere[i__] = -3;
}
}
}
pointr = *head;
if (iwhere[i__] != 0 && iwhere[i__] != -1) {
d__[i__] = 0.;
} else {
d__[i__] = neggi;
f1 -= neggi * neggi;
/* calculate p := p - W'e_i* (g_i). */
i__2 = *col;
for (j = 1; j <= i__2; ++j) {
p[j] += wy[i__ + pointr * wy_dim1] * neggi;
p[*col + j] += ws[i__ + pointr * ws_dim1] * neggi;
pointr = pointr % *m + 1;
/* L40: */
}
if (nbd[i__] <= 2 && nbd[i__] != 0 && neggi < 0.) {
/* x(i) + d(i) is bounded; compute t(i). */
++nbreak;
iorder[nbreak] = i__;
t[nbreak] = tl / (-neggi);
if (nbreak == 1 || t[nbreak] < bkmin) {
bkmin = t[nbreak];
ibkmin = nbreak;
}
} else if (nbd[i__] >= 2 && neggi > 0.) {
/* x(i) + d(i) is bounded; compute t(i). */
++nbreak;
iorder[nbreak] = i__;
t[nbreak] = tu / neggi;
if (nbreak == 1 || t[nbreak] < bkmin) {
bkmin = t[nbreak];
ibkmin = nbreak;
}
} else {
/* x(i) + d(i) is not bounded. */
--nfree;
iorder[nfree] = i__;
if (fabs(neggi) > 0.) {
bnded = FALSE_;
}
}
}
/* L50: */
}
/* The indices of the nonzero components of d are now stored */
/* in iorder(1),...,iorder(nbreak) and iorder(nfree),...,iorder(n). */
/* The smallest of the nbreak breakpoints is in t(ibkmin)=bkmin. */
if (*theta != 1.) {
/* complete the initialization of p for theta not= one. */
dscal(col, theta, &p[*col + 1], &c__1);
}
/* Initialize GCP xcp = x. */
dcopy(n, &x[1], &c__1, &xcp[1], &c__1);
if (nbreak == 0 && nfree == *n + 1) {
/* is a zero vector, return with the initial xcp as GCP. */
if (*iprint > 100) {
printf("Cauchy X = ");
i__1 = *n;
for (i__ = 1; i__ <= i__1; ++i__) {
printf("%5.2e ", xcp[i__] );
}
printf("\n");
}
return 0;
}
/* Initialize c = W'(xcp - x) = 0. */
i__1 = col2;
for (j = 1; j <= i__1; ++j) {
c__[j] = 0.;
/* L60: */
}
/* Initialize derivative f2. */
f2 = -(*theta) * f1;
f2_org__ = f2;
if (*col > 0) {
bmv(m, &sy[sy_offset], &wt[wt_offset], col, &p[1], &v[1], info);
if (*info != 0) {
return 0;
}
f2 -= ddot(&col2, &v[1], &c__1, &p[1], &c__1);
}
dtm = -f1 / f2;
tsum = 0.;
*nseg = 1;
if (*iprint >= 99) {
printf("There are %ld breakpoints\n", nbreak );
}
/* If there are no breakpoints, locate the GCP and return. */
if (nbreak == 0) {
goto L888;
}
nleft = nbreak;
iter = 1;
tj = 0.;
/* ------------------- the beginning of the loop ------------------------- */
L777:
/* Find the next smallest breakpoint; */
/* compute dt = t(nleft) - t(nleft + 1). */
tj0 = tj;
if (iter == 1) {
/* Since we already have the smallest breakpoint we need not do */
/* heapsort yet. Often only one breakpoint is used and the */
/* cost of heapsort is avoided. */
tj = bkmin;
ibp = iorder[ibkmin];
} else {
if (iter == 2) {
/* Replace the already used smallest breakpoint with the */
/* breakpoint numbered nbreak > nlast, before heapsort call. */
if (ibkmin != nbreak) {
t[ibkmin] = t[nbreak];
iorder[ibkmin] = iorder[nbreak];
}
/* Update heap structure of breakpoints */
/* (if iter=2, initialize heap). */
}
i__1 = iter - 2;
hpsolb(&nleft, &t[1], &iorder[1], &i__1);
tj = t[nleft];
ibp = iorder[nleft];
}
dt = tj - tj0;
if (dt != 0. && *iprint >= 100) {
printf("Piece %ld --f1, f2 at start point %.2e %.2e\n", *nseg, f1, f2 );
printf("Distance to the next break point = %.2e\n", dt );
printf("Distance to the stationary point = %.2e\n", dtm );
}
/* If a minimizer is within this interval, locate the GCP and return. */
if (dtm < dt) {
goto L888;
}
/* Otherwise fix one variable and */
/* reset the corresponding component of d to zero. */
tsum += dt;
--nleft;
++iter;
dibp = d__[ibp];
d__[ibp] = 0.;
if (dibp > 0.) {
zibp = u[ibp] - x[ibp];
xcp[ibp] = u[ibp];
iwhere[ibp] = 2;
} else {
zibp = l[ibp] - x[ibp];
xcp[ibp] = l[ibp];
iwhere[ibp] = 1;
}
if (*iprint >= 100) {
printf("Variable %ld is fixed\n", ibp );
}
if (nleft == 0 && nbreak == *n) {
/* all n variables are fixed, */
/* return with xcp as GCP. */
dtm = dt;
goto L999;
}
/* Update the derivative information. */
++(*nseg);
/* Computing 2nd power */
d__1 = dibp;
dibp2 = d__1 * d__1;
/* Update f1 and f2. */
/* temporarily set f1 and f2 for col=0. */
f1 = f1 + dt * f2 + dibp2 - *theta * dibp * zibp;
f2 -= *theta * dibp2;
if (*col > 0) {
/* update c = c + dt*p. */
daxpy(&col2, &dt, &p[1], &c__1, &c__[1], &c__1);
/* choose wbp, */
/* the row of W corresponding to the breakpoint encountered. */
pointr = *head;
i__1 = *col;
for (j = 1; j <= i__1; ++j) {
wbp[j] = wy[ibp + pointr * wy_dim1];
wbp[*col + j] = *theta * ws[ibp + pointr * ws_dim1];
pointr = pointr % *m + 1;
/* L70: */
}
/* compute (wbp)Mc, (wbp)Mp, and (wbp)M(wbp)'. */
bmv(m, &sy[sy_offset], &wt[wt_offset], col, &wbp[1], &v[1], info);
if (*info != 0) {
return 0;
}
wmc = ddot(&col2, &c__[1], &c__1, &v[1], &c__1);
wmp = ddot(&col2, &p[1], &c__1, &v[1], &c__1);
wmw = ddot(&col2, &wbp[1], &c__1, &v[1], &c__1);
/* update p = p - dibp*wbp. */
d__1 = -dibp;
daxpy(&col2, &d__1, &wbp[1], &c__1, &p[1], &c__1);
/* complete updating f1 and f2 while col > 0. */
f1 += dibp * wmc;
f2 = f2 + dibp * 2. * wmp - dibp2 * wmw;
}
/* Computing MAX */
d__1 = *epsmch * f2_org__;
f2 = fmax(d__1,f2);
if (nleft > 0) {
dtm = -f1 / f2;
goto L777;
/* to repeat the loop for unsearched intervals. */
} else if (bnded) {
f1 = 0.;
f2 = 0.;
dtm = 0.;
} else {
dtm = -f1 / f2;
}
/* ------------------- the end of the loop ------------------------------- */
L888:
if (*iprint >= 99) {
printf("\nGCP found in this segment. Piece %ld --f1, f2 at start point %.2e %.2e\n", *nseg, f1, f2 );
printf("Distance to the stationary point = %.2e\n", dtm );
}
if (dtm <= 0.) {
dtm = 0.;
}
tsum += dtm;
/* Move free variables (i.e., the ones w/o breakpoints) and */
/* the variables whose breakpoints haven't been reached. */
daxpy(n, &tsum, &d__[1], &c__1, &xcp[1], &c__1);
L999:
/* Update c = c + dtm*p = W'(x^c - x) */
/* which will be used in computing r = Z'(B(x^c - x) + g). */
if (*col > 0) {
daxpy(&col2, &dtm, &p[1], &c__1, &c__[1], &c__1);
}
if (*iprint > 100) {
printf("Cauchy X = ");
i__1 = *n;
for (i__ = 1; i__ <= i__1; ++i__) {
printf("%5.2e ", xcp[i__] );
}
}
if (*iprint >= 99) {
printf("-------------- exit CAUCHY -----------\n");
}
return 0;
} /* cauchy */
/* ====================== The end of cauchy ============================== */
/* Subroutine */ int cmprlb(integer *n, integer *m, double *x,
double *g, double *ws, double *wy, double *sy,
double *wt, double *z__, double *r__, double *wa,
integer *index, double *theta, integer *col, integer *head,
integer *nfree, logical *cnstnd, integer *info)
{
/* System generated locals */
integer ws_dim1, ws_offset, wy_dim1, wy_offset, sy_dim1, sy_offset,
wt_dim1, wt_offset, i__1, i__2;
/* Local variables */
static integer i__, j, k;
static double a1, a2;
extern /* Subroutine */ int bmv(integer *, double *, double *,
integer *, double *, double *, integer *);
static integer pointr;
/* ************ */
/* Subroutine cmprlb */
/* This subroutine computes r=-Z'B(xcp-xk)-Z'g by using */
/* wa(2m+1)=W'(xcp-x) from subroutine cauchy. */
/* Subprograms called: */
/* L-BFGS-B Library ... bmv. */
/* * * * */
/* NEOS, November 1994. (Latest revision June 1996.) */
/* Optimization Technology Center. */
/* Argonne National Laboratory and Northwestern University. */
/* Written by */
/* Ciyou Zhu */
/* in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal. */
/* ************ */
/* Parameter adjustments */
--index;
--r__;
--z__;
--g;
--x;
--wa;
wt_dim1 = *m;
wt_offset = 1 + wt_dim1;
wt -= wt_offset;
sy_dim1 = *m;
sy_offset = 1 + sy_dim1;
sy -= sy_offset;
wy_dim1 = *n;
wy_offset = 1 + wy_dim1;
wy -= wy_offset;
ws_dim1 = *n;
ws_offset = 1 + ws_dim1;
ws -= ws_offset;
/* Function Body */
if (! (*cnstnd) && *col > 0) {
i__1 = *n;
for (i__ = 1; i__ <= i__1; ++i__) {
r__[i__] = -g[i__];
/* L26: */
}
} else {
i__1 = *nfree;
for (i__ = 1; i__ <= i__1; ++i__) {
k = index[i__];
r__[i__] = -(*theta) * (z__[k] - x[k]) - g[k];
/* L30: */
}
bmv(m, &sy[sy_offset], &wt[wt_offset], col, &wa[(*m << 1) + 1], &wa[
1], info);
if (*info != 0) {
*info = -8;
return 0;
}
pointr = *head;
i__1 = *col;
for (j = 1; j <= i__1; ++j) {
a1 = wa[j];
a2 = *theta * wa[*col + j];
i__2 = *nfree;
for (i__ = 1; i__ <= i__2; ++i__) {
k = index[i__];
r__[i__] = r__[i__] + wy[k + pointr * wy_dim1] * a1 + ws[k +
pointr * ws_dim1] * a2;
/* L32: */
}
pointr = pointr % *m + 1;
/* L34: */
}
}
return 0;
} /* cmprlb */
/* ======================= The end of cmprlb ============================= */
/* Subroutine */ int formk(integer *n, integer *nsub, integer *ind, integer *
nenter, integer *ileave, integer *indx2, integer *iupdat, logical *
updatd, double *wn, double *wn1, integer *m, double *ws,
double *wy, double *sy, double *theta, integer *col,
integer *head, integer *info)
{
/* System generated locals */
integer wn_dim1, wn_offset, wn1_dim1, wn1_offset, ws_dim1, ws_offset,
wy_dim1, wy_offset, sy_dim1, sy_offset, i__1, i__2, i__3;
/* Local variables */
static integer i__, k, k1, m2, is, js, iy, jy, is1, js1, col2, dend, pend;
static integer upcl;
static double temp1, temp2, temp3, temp4;
static integer ipntr, jpntr, dbegin, pbegin;
/* ************ */
/* Subroutine formk */
/* This subroutine forms the LEL^T factorization of the indefinite */
/* matrix K = [-D -Y'ZZ'Y/theta L_a'-R_z' ] */
/* [L_a -R_z theta*S'AA'S ] */
/* where E = [-I 0] */
/* [ 0 I] */
/* The matrix K can be shown to be equal to the matrix M^[-1]N */
/* occurring in section 5.1 of [1], as well as to the matrix */
/* Mbar^[-1] Nbar in section 5.3. */
/* n is an integer variable. */
/* On entry n is the dimension of the problem. */
/* On exit n is unchanged. */
/* nsub is an integer variable */
/* On entry nsub is the number of subspace variables in free set. */
/* On exit nsub is not changed. */
/* ind is an integer array of dimension nsub. */
/* On entry ind specifies the indices of subspace variables. */
/* On exit ind is unchanged. */
/* nenter is an integer variable. */
/* On entry nenter is the number of variables entering the */
/* free set. */
/* On exit nenter is unchanged. */
/* ileave is an integer variable. */
/* On entry indx2(ileave),...,indx2(n) are the variables leaving */
/* the free set. */
/* On exit ileave is unchanged. */
/* indx2 is an integer array of dimension n. */
/* On entry indx2(1),...,indx2(nenter) are the variables entering */
/* the free set, while indx2(ileave),...,indx2(n) are the */
/* variables leaving the free set. */
/* On exit indx2 is unchanged. */
/* iupdat is an integer variable. */
/* On entry iupdat is the total number of BFGS updates made so far. */
/* On exit iupdat is unchanged. */
/* updatd is a logical variable. */
/* On entry 'updatd' is true if the L-BFGS matrix is updatd. */
/* On exit 'updatd' is unchanged. */
/* wn is a double precision array of dimension 2m x 2m. */
/* On entry wn is unspecified. */
/* On exit the upper triangle of wn stores the LEL^T factorization */
/* of the 2*col x 2*col indefinite matrix */
/* [-D -Y'ZZ'Y/theta L_a'-R_z' ] */
/* [L_a -R_z theta*S'AA'S ] */
/* wn1 is a double precision array of dimension 2m x 2m. */
/* On entry wn1 stores the lower triangular part of */
/* [Y' ZZ'Y L_a'+R_z'] */
/* [L_a+R_z S'AA'S ] */
/* in the previous iteration. */
/* On exit wn1 stores the corresponding updated matrices. */
/* The purpose of wn1 is just to store these inner products */
/* so they can be easily updated and inserted into wn. */
/* m is an integer variable. */
/* On entry m is the maximum number of variable metric corrections */
/* used to define the limited memory matrix. */
/* On exit m is unchanged. */
/* ws, wy, sy, and wtyy are double precision arrays; */
/* theta is a double precision variable; */
/* col is an integer variable; */
/* head is an integer variable. */
/* On entry they store the information defining the */
/* limited memory BFGS matrix: */
/* ws(n,m) stores S, a set of s-vectors; */
/* wy(n,m) stores Y, a set of y-vectors; */
/* sy(m,m) stores S'Y; */
/* wtyy(m,m) stores the Cholesky factorization */
/* of (theta*S'S+LD^(-1)L') */
/* theta is the scaling factor specifying B_0 = theta I; */
/* col is the number of variable metric corrections stored; */
/* head is the location of the 1st s- (or y-) vector in S (or Y). */
/* On exit they are unchanged. */
/* info is an integer variable. */
/* On entry info is unspecified. */
/* On exit info = 0 for normal return; */
/* = -1 when the 1st Cholesky factorization failed; */
/* = -2 when the 2st Cholesky factorization failed. */
/* Subprograms called: */
/* Linpack ... dcopy, dpofa, dtrsl. */
/* References: */
/* [1] R. H. Byrd, P. Lu, J. Nocedal and C. Zhu, ``A limited */
/* memory algorithm for bound constrained optimization'', */
/* SIAM J. Scientific Computing 16 (1995), no. 5, pp. 1190--1208. */
/* [2] C. Zhu, R.H. Byrd, P. Lu, J. Nocedal, ``L-BFGS-B: a */
/* limited memory FORTRAN code for solving bound constrained */
/* optimization problems'', Tech. Report, NAM-11, EECS Department, */
/* Northwestern University, 1994. */
/* (Postscript files of these papers are available via anonymous */
/* ftp to eecs.nwu.edu in the directory pub/lbfgs/lbfgs_bcm.) */
/* * * * */
/* NEOS, November 1994. (Latest revision June 1996.) */
/* Optimization Technology Center. */
/* Argonne National Laboratory and Northwestern University. */
/* Written by */
/* Ciyou Zhu */
/* in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal. */
/* ************ */
/* Form the lower triangular part of */
/* WN1 = [Y' ZZ'Y L_a'+R_z'] */
/* [L_a+R_z S'AA'S ] */
/* where L_a is the strictly lower triangular part of S'AA'Y */
/* R_z is the upper triangular part of S'ZZ'Y. */
/* Parameter adjustments */
--indx2;
--ind;
sy_dim1 = *m;
sy_offset = 1 + sy_dim1;
sy -= sy_offset;
wy_dim1 = *n;
wy_offset = 1 + wy_dim1;
wy -= wy_offset;
ws_dim1 = *n;
ws_offset = 1 + ws_dim1;
ws -= ws_offset;
wn1_dim1 = 2 * *m;
wn1_offset = 1 + wn1_dim1;
wn1 -= wn1_offset;
wn_dim1 = 2 * *m;
wn_offset = 1 + wn_dim1;
wn -= wn_offset;
/* Function Body */
if (*updatd) {
if (*iupdat > *m) {
/* shift old part of WN1. */
i__1 = *m - 1;
for (jy = 1; jy <= i__1; ++jy) {
js = *m + jy;
i__2 = *m - jy;
dcopy(&i__2, &wn1[jy + 1 + (jy + 1) * wn1_dim1], &c__1, &wn1[
jy + jy * wn1_dim1], &c__1);
i__2 = *m - jy;
dcopy(&i__2, &wn1[js + 1 + (js + 1) * wn1_dim1], &c__1, &wn1[
js + js * wn1_dim1], &c__1);
i__2 = *m - 1;
dcopy(&i__2, &wn1[*m + 2 + (jy + 1) * wn1_dim1], &c__1, &wn1[
*m + 1 + jy * wn1_dim1], &c__1);
/* L10: */
}
}
/* put new rows in blocks (1,1), (2,1) and (2,2). */
pbegin = 1;
pend = *nsub;
dbegin = *nsub + 1;
dend = *n;
iy = *col;
is = *m + *col;
ipntr = *head + *col - 1;
if (ipntr > *m) {
ipntr -= *m;
}
jpntr = *head;
i__1 = *col;
for (jy = 1; jy <= i__1; ++jy) {
js = *m + jy;
temp1 = 0.;
temp2 = 0.;
temp3 = 0.;
/* compute element jy of row 'col' of Y'ZZ'Y */
i__2 = pend;
for (k = pbegin; k <= i__2; ++k) {
k1 = ind[k];
temp1 += wy[k1 + ipntr * wy_dim1] * wy[k1 + jpntr * wy_dim1];
/* L15: */
}
/* compute elements jy of row 'col' of L_a and S'AA'S */
i__2 = dend;
for (k = dbegin; k <= i__2; ++k) {
k1 = ind[k];
temp2 += ws[k1 + ipntr * ws_dim1] * ws[k1 + jpntr * ws_dim1];
temp3 += ws[k1 + ipntr * ws_dim1] * wy[k1 + jpntr * wy_dim1];
/* L16: */
}
wn1[iy + jy * wn1_dim1] = temp1;
wn1[is + js * wn1_dim1] = temp2;
wn1[is + jy * wn1_dim1] = temp3;
jpntr = jpntr % *m + 1;
/* L20: */
}
/* put new column in block (2,1). */
jy = *col;
jpntr = *head + *col - 1;
if (jpntr > *m) {
jpntr -= *m;
}
ipntr = *head;
i__1 = *col;
for (i__ = 1; i__ <= i__1; ++i__) {
is = *m + i__;
temp3 = 0.;
/* compute element i of column 'col' of R_z */
i__2 = pend;
for (k = pbegin; k <= i__2; ++k) {
k1 = ind[k];
temp3 += ws[k1 + ipntr * ws_dim1] * wy[k1 + jpntr * wy_dim1];
/* L25: */
}
ipntr = ipntr % *m + 1;
wn1[is + jy * wn1_dim1] = temp3;
/* L30: */
}
upcl = *col - 1;
} else {
upcl = *col;
}
/* modify the old parts in blocks (1,1) and (2,2) due to changes */
/* in the set of free variables. */
ipntr = *head;
i__1 = upcl;
for (iy = 1; iy <= i__1; ++iy) {
is = *m + iy;
jpntr = *head;
i__2 = iy;
for (jy = 1; jy <= i__2; ++jy) {
js = *m + jy;
temp1 = 0.;
temp2 = 0.;
temp3 = 0.;
temp4 = 0.;
i__3 = *nenter;
for (k = 1; k <= i__3; ++k) {
k1 = indx2[k];
temp1 += wy[k1 + ipntr * wy_dim1] * wy[k1 + jpntr * wy_dim1];
temp2 += ws[k1 + ipntr * ws_dim1] * ws[k1 + jpntr * ws_dim1];
/* L35: */
}
i__3 = *n;
for (k = *ileave; k <= i__3; ++k) {
k1 = indx2[k];
temp3 += wy[k1 + ipntr * wy_dim1] * wy[k1 + jpntr * wy_dim1];
temp4 += ws[k1 + ipntr * ws_dim1] * ws[k1 + jpntr * ws_dim1];
/* L36: */
}
wn1[iy + jy * wn1_dim1] = wn1[iy + jy * wn1_dim1] + temp1 - temp3;
wn1[is + js * wn1_dim1] = wn1[is + js * wn1_dim1] - temp2 + temp4;
jpntr = jpntr % *m + 1;
/* L40: */
}
ipntr = ipntr % *m + 1;
/* L45: */
}
/* modify the old parts in block (2,1). */
ipntr = *head;
i__1 = *m + upcl;
for (is = *m + 1; is <= i__1; ++is) {
jpntr = *head;
i__2 = upcl;
for (jy = 1; jy <= i__2; ++jy) {
temp1 = 0.;
temp3 = 0.;
i__3 = *nenter;
for (k = 1; k <= i__3; ++k) {
k1 = indx2[k];
temp1 += ws[k1 + ipntr * ws_dim1] * wy[k1 + jpntr * wy_dim1];
/* L50: */
}
i__3 = *n;
for (k = *ileave; k <= i__3; ++k) {
k1 = indx2[k];
temp3 += ws[k1 + ipntr * ws_dim1] * wy[k1 + jpntr * wy_dim1];
/* L51: */
}
if (is <= jy + *m) {
wn1[is + jy * wn1_dim1] = wn1[is + jy * wn1_dim1] + temp1 -
temp3;
} else {
wn1[is + jy * wn1_dim1] = wn1[is + jy * wn1_dim1] - temp1 +
temp3;
}
jpntr = jpntr % *m + 1;
/* L55: */
}
ipntr = ipntr % *m + 1;
/* L60: */
}
/* Form the upper triangle of WN = [D+Y' ZZ'Y/theta -L_a'+R_z' ] */
/* [-L_a +R_z S'AA'S*theta] */
m2 = *m << 1;
i__1 = *col;
for (iy = 1; iy <= i__1; ++iy) {
is = *col + iy;
is1 = *m + iy;
i__2 = iy;
for (jy = 1; jy <= i__2; ++jy) {
js = *col + jy;
js1 = *m + jy;
wn[jy + iy * wn_dim1] = wn1[iy + jy * wn1_dim1] / *theta;
wn[js + is * wn_dim1] = wn1[is1 + js1 * wn1_dim1] * *theta;
/* L65: */
}
i__2 = iy - 1;
for (jy = 1; jy <= i__2; ++jy) {
wn[jy + is * wn_dim1] = -wn1[is1 + jy * wn1_dim1];
/* L66: */
}
i__2 = *col;
for (jy = iy; jy <= i__2; ++jy) {
wn[jy + is * wn_dim1] = wn1[is1 + jy * wn1_dim1];
/* L67: */
}
wn[iy + iy * wn_dim1] += sy[iy + iy * sy_dim1];
/* L70: */
}
/* Form the upper triangle of WN= [ LL' L^-1(-L_a'+R_z')] */
/* [(-L_a +R_z)L'^-1 S'AA'S*theta ] */
/* first Cholesky factor (1,1) block of wn to get LL' */
/* with L' stored in the upper triangle of wn. */
dpofa(&wn[wn_offset], &m2, col, info);
if (*info != 0) {
*info = -1;
return 0;
}
/* then form L^-1(-L_a'+R_z') in the (1,2) block. */
col2 = *col << 1;
i__1 = col2;
for (js = *col + 1; js <= i__1; ++js) {
dtrsl(&wn[wn_offset], &m2, col, &wn[js * wn_dim1 + 1], &c__11, info);
/* L71: */
}
/* Form S'AA'S*theta + (L^-1(-L_a'+R_z'))'L^-1(-L_a'+R_z') in the */
/* upper triangle of (2,2) block of wn. */
i__1 = col2;
for (is = *col + 1; is <= i__1; ++is) {
i__2 = col2;
for (js = is; js <= i__2; ++js) {
wn[is + js * wn_dim1] += ddot(col, &wn[is * wn_dim1 + 1], &c__1,
&wn[js * wn_dim1 + 1], &c__1);
/* L74: */
}
/* L72: */
}
/* Cholesky factorization of (2,2) block of wn. */
dpofa(&wn[*col + 1 + (*col + 1) * wn_dim1], &m2, col, info);
if (*info != 0) {
*info = -2;
return 0;
}
return 0;
} /* formk */
/* ======================= The end of formk ============================== */
/* Subroutine */ int formt(integer *m, double *wt, double *sy,
double *ss, integer *col, double *theta, integer *info)
{
/* System generated locals */
integer wt_dim1, wt_offset, sy_dim1, sy_offset, ss_dim1, ss_offset, i__1,
i__2, i__3;
/* Local variables */
static integer i__, j, k, k1;
static double ddum;
/* ************ */
/* Subroutine formt */
/* This subroutine forms the upper half of the pos. def. and symm. */
/* T = theta*SS + L*D^(-1)*L', stores T in the upper triangle */
/* of the array wt, and performs the Cholesky factorization of T */
/* to produce J*J', with J' stored in the upper triangle of wt. */
/* Subprograms called: */
/* Linpack ... dpofa. */
/* * * * */
/* NEOS, November 1994. (Latest revision June 1996.) */
/* Optimization Technology Center. */
/* Argonne National Laboratory and Northwestern University. */
/* Written by */
/* Ciyou Zhu */
/* in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal. */
/* ************ */
/* Form the upper half of T = theta*SS + L*D^(-1)*L', */
/* store T in the upper triangle of the array wt. */
/* Parameter adjustments */
ss_dim1 = *m;
ss_offset = 1 + ss_dim1;
ss -= ss_offset;
sy_dim1 = *m;
sy_offset = 1 + sy_dim1;
sy -= sy_offset;
wt_dim1 = *m;
wt_offset = 1 + wt_dim1;
wt -= wt_offset;
/* Function Body */
i__1 = *col;
for (j = 1; j <= i__1; ++j) {
wt[j * wt_dim1 + 1] = *theta * ss[j * ss_dim1 + 1];
/* L52: */
}
i__1 = *col;
for (i__ = 2; i__ <= i__1; ++i__) {
i__2 = *col;
for (j = i__; j <= i__2; ++j) {
k1 = fmin(i__,j) - 1;
ddum = 0.;
i__3 = k1;
for (k = 1; k <= i__3; ++k) {
ddum += sy[i__ + k * sy_dim1] * sy[j + k * sy_dim1] / sy[k +
k * sy_dim1];
/* L53: */
}
wt[i__ + j * wt_dim1] = ddum + *theta * ss[i__ + j * ss_dim1];
/* L54: */
}
/* L55: */
}
/* Cholesky factorize T to J*J' with */
/* J' stored in the upper triangle of wt. */
dpofa(&wt[wt_offset], m, col, info);
if (*info != 0) {
*info = -3;
}
return 0;
} /* formt */
/* ======================= The end of formt ============================== */
/* Subroutine */ int freev(integer *n, integer *nfree, integer *index,
integer *nenter, integer *ileave, integer *indx2, integer *iwhere,
logical *wrk, logical *updatd, logical *cnstnd, integer *iprint,
integer *iter)
{
/* System generated locals */
integer i__1;
/* Local variables */
static integer i__, k, iact;
/* ************ */
/* Subroutine freev */
/* This subroutine counts the entering and leaving variables when */
/* iter > 0, and finds the index set of free and active variables */
/* at the GCP. */
/* cnstnd is a logical variable indicating whether bounds are present */
/* index is an integer array of dimension n */
/* for i=1,...,nfree, index(i) are the indices of free variables */
/* for i=nfree+1,...,n, index(i) are the indices of bound variables */
/* On entry after the first iteration, index gives */
/* the free variables at the previous iteration. */
/* On exit it gives the free variables based on the determination */
/* in cauchy using the array iwhere. */
/* indx2 is an integer array of dimension n */
/* On entry indx2 is unspecified. */
/* On exit with iter>0, indx2 indicates which variables */
/* have changed status since the previous iteration. */
/* For i= 1,...,nenter, indx2(i) have changed from bound to free. */
/* For i= ileave+1,...,n, indx2(i) have changed from free to bound. */
/* * * * */
/* NEOS, November 1994. (Latest revision June 1996.) */
/* Optimization Technology Center. */
/* Argonne National Laboratory and Northwestern University. */
/* Written by */
/* Ciyou Zhu */
/* in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal. */
/* ************ */
/* Parameter adjustments */
--iwhere;
--indx2;
--index;
/* Function Body */
*nenter = 0;
*ileave = *n + 1;
if (*iter > 0 && *cnstnd) {
/* count the entering and leaving variables. */
i__1 = *nfree;
for (i__ = 1; i__ <= i__1; ++i__) {
k = index[i__];
/* write(6,*) ' k = index(i) ', k */
/* write(6,*) ' index = ', i */
if (iwhere[k] > 0) {
--(*ileave);
indx2[*ileave] = k;
if (*iprint >= 100) {
printf("Variable %ld leaves the set of free variables\n", k );
}
}
/* L20: */
}
i__1 = *n;
for (i__ = *nfree + 1; i__ <= i__1; ++i__) {
k = index[i__];
if (iwhere[k] <= 0) {
++(*nenter);
indx2[*nenter] = k;
if (*iprint >= 100) {
printf("Variable %ld leaves the set of free variables\n", k );
}
}
/* L22: */
}
if (*iprint >= 99) {
i__1 = *n + 1 - *ileave;
printf("%ld variables leave; %ld variables enter\n", i__1, *nenter );
}
}
*wrk = *ileave < *n + 1 || *nenter > 0 || *updatd;
/* Find the index set of free and active variables at the GCP. */
*nfree = 0;
iact = *n + 1;
i__1 = *n;
for (i__ = 1; i__ <= i__1; ++i__) {
if (iwhere[i__] <= 0) {
++(*nfree);
index[*nfree] = i__;
} else {
--iact;
index[iact] = i__;
}
/* L24: */
}
if (*iprint >= 99) {
i__1 = *iter + 1;
printf("%ld variables are free at GCP iter %ld\n", *nfree, i__1 );
}
return 0;
} /* freev */
/* ======================= The end of freev ============================== */
/* Subroutine */ int hpsolb(integer *n, double *t, integer *iorder,
integer *iheap)
{
/* System generated locals */
integer i__1;
/* Local variables */
static integer i__, j, k;
static double out, ddum;
static integer indxin, indxou;
/* ************ */
/* Subroutine hpsolb */
/* This subroutine sorts out the least element of t, and puts the */
/* remaining elements of t in a heap. */
/* n is an integer variable. */
/* On entry n is the dimension of the arrays t and iorder. */
/* On exit n is unchanged. */
/* t is a double precision array of dimension n. */
/* On entry t stores the elements to be sorted, */
/* On exit t(n) stores the least elements of t, and t(1) to t(n-1) */
/* stores the remaining elements in the form of a heap. */
/* iorder is an integer array of dimension n. */
/* On entry iorder(i) is the index of t(i). */
/* On exit iorder(i) is still the index of t(i), but iorder may be */
/* permuted in accordance with t. */
/* iheap is an integer variable specifying the task. */
/* On entry iheap should be set as follows: */
/* iheap .eq. 0 if t(1) to t(n) is not in the form of a heap, */
/* iheap .ne. 0 if otherwise. */
/* On exit iheap is unchanged. */
/* References: */
/* Algorithm 232 of CACM (J. W. J. Williams): HEAPSORT. */
/* * * * */
/* NEOS, November 1994. (Latest revision June 1996.) */
/* Optimization Technology Center. */
/* Argonne National Laboratory and Northwestern University. */
/* Written by */
/* Ciyou Zhu */
/* in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal. */
/* ************ */
/* Parameter adjustments */
--iorder;
--t;
/* Function Body */
if (*iheap == 0) {
/* Rearrange the elements t(1) to t(n) to form a heap. */
i__1 = *n;
for (k = 2; k <= i__1; ++k) {
ddum = t[k];
indxin = iorder[k];
/* Add ddum to the heap. */
i__ = k;
L10:
if (i__ > 1) {
j = i__ / 2;
if (ddum < t[j]) {
t[i__] = t[j];
iorder[i__] = iorder[j];
i__ = j;
goto L10;
}
}
t[i__] = ddum;
iorder[i__] = indxin;
/* L20: */
}
}
/* Assign to 'out' the value of t(1), the least member of the heap, */
/* and rearrange the remaining members to form a heap as */
/* elements 1 to n-1 of t. */
if (*n > 1) {
i__ = 1;
out = t[1];
indxou = iorder[1];
ddum = t[*n];
indxin = iorder[*n];
/* Restore the heap */
L30:
j = i__ + i__;
if (j <= *n - 1) {
if (t[j + 1] < t[j]) {
++j;
}
if (t[j] < ddum) {
t[i__] = t[j];
iorder[i__] = iorder[j];
i__ = j;
goto L30;
}
}
t[i__] = ddum;
iorder[i__] = indxin;
/* Put the least member in t(n). */
t[*n] = out;
iorder[*n] = indxou;
}
return 0;
} /* hpsolb */
/* ====================== The end of hpsolb ============================== */
/* Subroutine */ int matupd(integer *n, integer *m, double *ws,
double *wy, double *sy, double *ss, double *d__,
double *r__, integer *itail, integer *iupdat, integer *col,
integer *head, double *theta, double *rr, double *dr,
double *stp, double *dtd)
{
/* System generated locals */
integer ws_dim1, ws_offset, wy_dim1, wy_offset, sy_dim1, sy_offset,
ss_dim1, ss_offset, i__1, i__2;
/* Local variables */
static integer j;
static integer pointr;
/* ************ */
/* Subroutine matupd */
/* This subroutine updates matrices WS and WY, and forms the */
/* middle matrix in B. */
/* Subprograms called: */
/* Linpack ... dcopy, ddot. */
/* * * * */
/* NEOS, November 1994. (Latest revision June 1996.) */
/* Optimization Technology Center. */
/* Argonne National Laboratory and Northwestern University. */
/* Written by */
/* Ciyou Zhu */
/* in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal. */
/* ************ */
/* Set pointers for matrices WS and WY. */
/* Parameter adjustments */
--r__;
--d__;
ss_dim1 = *m;
ss_offset = 1 + ss_dim1;
ss -= ss_offset;
sy_dim1 = *m;
sy_offset = 1 + sy_dim1;
sy -= sy_offset;
wy_dim1 = *n;
wy_offset = 1 + wy_dim1;
wy -= wy_offset;
ws_dim1 = *n;
ws_offset = 1 + ws_dim1;
ws -= ws_offset;
/* Function Body */
if (*iupdat <= *m) {
*col = *iupdat;
*itail = (*head + *iupdat - 2) % *m + 1;
} else {
*itail = *itail % *m + 1;
*head = *head % *m + 1;
}
/* Update matrices WS and WY. */
dcopy(n, &d__[1], &c__1, &ws[*itail * ws_dim1 + 1], &c__1);
dcopy(n, &r__[1], &c__1, &wy[*itail * wy_dim1 + 1], &c__1);
/* Set theta=yy/ys. */
*theta = *rr / *dr;
/* Form the middle matrix in B. */
/* update the upper triangle of SS, */
/* and the lower triangle of SY: */
if (*iupdat > *m) {
/* move old information */
i__1 = *col - 1;
for (j = 1; j <= i__1; ++j) {
dcopy(&j, &ss[(j + 1) * ss_dim1 + 2], &c__1, &ss[j * ss_dim1 + 1]
, &c__1);
i__2 = *col - j;
dcopy(&i__2, &sy[j + 1 + (j + 1) * sy_dim1], &c__1, &sy[j + j *
sy_dim1], &c__1);
/* L50: */
}
}
/* add new information: the last row of SY */
/* and the last column of SS: */
pointr = *head;
i__1 = *col - 1;
for (j = 1; j <= i__1; ++j) {
sy[*col + j * sy_dim1] = ddot(n, &d__[1], &c__1, &wy[pointr *
wy_dim1 + 1], &c__1);
ss[j + *col * ss_dim1] = ddot(n, &ws[pointr * ws_dim1 + 1], &c__1, &
d__[1], &c__1);
pointr = pointr % *m + 1;
/* L51: */
}
if (*stp == 1.) {
ss[*col + *col * ss_dim1] = *dtd;
} else {
ss[*col + *col * ss_dim1] = *stp * *stp * *dtd;
}
sy[*col + *col * sy_dim1] = *dr;
return 0;
} /* matupd */
/* ======================= The end of matupd ============================= */
/* Subroutine */ int projgr(integer *n, double *l, double *u,
integer *nbd, double *x, double *g, double *sbgnrm)
{
/* System generated locals */
integer i__1;
double d__1, d__2;
/* Local variables */
static integer i__;
static double gi;
/* ************ */
/* Subroutine projgr */
/* This subroutine computes the infinity norm of the projected */
/* gradient. */
/* * * * */
/* NEOS, November 1994. (Latest revision June 1996.) */
/* Optimization Technology Center. */
/* Argonne National Laboratory and Northwestern University. */
/* Written by */
/* Ciyou Zhu */
/* in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal. */
/* ************ */
/* Parameter adjustments */
--g;
--x;
--nbd;
--u;
--l;
/* Function Body */
*sbgnrm = 0.;
i__1 = *n;
for (i__ = 1; i__ <= i__1; ++i__) {
gi = g[i__];
if (nbd[i__] != 0) {
if (gi < 0.) {
if (nbd[i__] >= 2) {
/* Computing MAX */
d__1 = x[i__] - u[i__];
gi = fmax(d__1,gi);
}
} else {
if (nbd[i__] <= 2) {
/* Computing MIN */
d__1 = x[i__] - l[i__];
gi = fmin(d__1,gi);
}
}
}
/* Computing MAX */
d__1 = *sbgnrm, d__2 = fabs(gi);
*sbgnrm = fmax(d__1,d__2);
/* L15: */
}
return 0;
} /* projgr */
/* ======================= The end of projgr ============================= */
/* Subroutine */ int subsm(integer *n, integer *m, integer *nsub, integer *
ind, double *l, double *u, integer *nbd, double *x,
double *d__, double *xp, double *ws, double *wy,
double *theta, double *xx, double *gg, integer *col,
integer *head, integer *iword, double *wv, double *wn,
integer *iprint, integer *info)
{
/* System generated locals */
integer ws_dim1, ws_offset, wy_dim1, wy_offset, wn_dim1, wn_offset, i__1,
i__2;
double d__1, d__2;
/* Local variables */
static integer i__, j, k, m2;
static double dk;
static integer js, jy;
static double xk;
static integer ibd, col2;
static double dd_p__, temp1, temp2, alpha;
static integer pointr;
/* ********************************************************************** */
/* This routine contains the major changes in the updated version. */
/* The changes are described in the accompanying paper */
/* Jose Luis Morales, Jorge Nocedal */
/* "Remark On Algorithm 788: L-BFGS-B: Fortran Subroutines for Large-Scale */
/* Bound Constrained Optimization". Decemmber 27, 2010. */
/* J.L. Morales Departamento de Matematicas, */
/* Instituto Tecnologico Autonomo de Mexico */
/* Mexico D.F. */
/* J, Nocedal Department of Electrical Engineering and */
/* Computer Science. */
/* Northwestern University. Evanston, IL. USA */
/* January 17, 2011 */
/* ********************************************************************** */
/* Subroutine subsm */
/* Given xcp, l, u, r, an index set that specifies */
/* the active set at xcp, and an l-BFGS matrix B */
/* (in terms of WY, WS, SY, WT, head, col, and theta), */
/* this subroutine computes an approximate solution */
/* of the subspace problem */
/* (P) min Q(x) = r'(x-xcp) + 1/2 (x-xcp)' B (x-xcp) */
/* subject to l<=x<=u */
/* x_i=xcp_i for all i in A(xcp) */
/* along the subspace unconstrained Newton direction */
/* d = -(Z'BZ)^(-1) r. */
/* The formula for the Newton direction, given the L-BFGS matrix */
/* and the Sherman-Morrison formula, is */
/* d = (1/theta)r + (1/theta*2) Z'WK^(-1)W'Z r. */
/* where */
/* K = [-D -Y'ZZ'Y/theta L_a'-R_z' ] */
/* [L_a -R_z theta*S'AA'S ] */
/* Note that this procedure for computing d differs */
/* from that described in [1]. One can show that the matrix K is */
/* equal to the matrix M^[-1]N in that paper. */
/* n is an integer variable. */
/* On entry n is the dimension of the problem. */
/* On exit n is unchanged. */
/* m is an integer variable. */
/* On entry m is the maximum number of variable metric corrections */
/* used to define the limited memory matrix. */
/* On exit m is unchanged. */
/* nsub is an integer variable. */
/* On entry nsub is the number of free variables. */
/* On exit nsub is unchanged. */
/* ind is an integer array of dimension nsub. */
/* On entry ind specifies the coordinate indices of free variables. */
/* On exit ind is unchanged. */
/* l is a double precision array of dimension n. */
/* On entry l is the lower bound of x. */
/* On exit l is unchanged. */
/* u is a double precision array of dimension n. */
/* On entry u is the upper bound of x. */
/* On exit u is unchanged. */
/* nbd is a integer array of dimension n. */
/* On entry nbd represents the type of bounds imposed on the */
/* variables, and must be specified as follows: */
/* nbd(i)=0 if x(i) is unbounded, */
/* 1 if x(i) has only a lower bound, */
/* 2 if x(i) has both lower and upper bounds, and */
/* 3 if x(i) has only an upper bound. */
/* On exit nbd is unchanged. */
/* x is a double precision array of dimension n. */
/* On entry x specifies the Cauchy point xcp. */
/* On exit x(i) is the minimizer of Q over the subspace of */
/* free variables. */
/* d is a double precision array of dimension n. */
/* On entry d is the reduced gradient of Q at xcp. */
/* On exit d is the Newton direction of Q. */
/* xp is a double precision array of dimension n. */
/* used to safeguard the projected Newton direction */
/* xx is a double precision array of dimension n */
/* On entry it holds the current iterate */
/* On output it is unchanged */
/* gg is a double precision array of dimension n */
/* On entry it holds the gradient at the current iterate */
/* On output it is unchanged */
/* ws and wy are double precision arrays; */
/* theta is a double precision variable; */
/* col is an integer variable; */
/* head is an integer variable. */
/* On entry they store the information defining the */
/* limited memory BFGS matrix: */
/* ws(n,m) stores S, a set of s-vectors; */
/* wy(n,m) stores Y, a set of y-vectors; */
/* theta is the scaling factor specifying B_0 = theta I; */
/* col is the number of variable metric corrections stored; */
/* head is the location of the 1st s- (or y-) vector in S (or Y). */
/* On exit they are unchanged. */
/* iword is an integer variable. */
/* On entry iword is unspecified. */
/* On exit iword specifies the status of the subspace solution. */
/* iword = 0 if the solution is in the box, */
/* 1 if some bound is encountered. */
/* wv is a double precision working array of dimension 2m. */
/* wn is a double precision array of dimension 2m x 2m. */
/* On entry the upper triangle of wn stores the LEL^T factorization */
/* of the indefinite matrix */
/* K = [-D -Y'ZZ'Y/theta L_a'-R_z' ] */
/* [L_a -R_z theta*S'AA'S ] */
/* where E = [-I 0] */
/* [ 0 I] */
/* On exit wn is unchanged. */
/* iprint is an INTEGER variable that must be set by the user. */
/* It controls the frequency and type of output generated: */
/* iprint<0 no output is generated; */
/* iprint=0 print only one line at the last iteration; */
/* 0<iprint<99 print also f and |proj g| every iprint iterations; */
/* iprint=99 print details of every iteration except n-vectors; */
/* iprint=100 print also the changes of active set and final x; */
/* iprint>100 print details of every iteration including x and g; */
/* When iprint > 0, the file iterate.dat will be created to */
/* summarize the iteration. */
/* info is an integer variable. */
/* On entry info is unspecified. */
/* On exit info = 0 for normal return, */
/* = nonzero for abnormal return */
/* when the matrix K is ill-conditioned. */
/* Subprograms called: */
/* Linpack dtrsl. */
/* References: */
/* [1] R. H. Byrd, P. Lu, J. Nocedal and C. Zhu, ``A limited */
/* memory algorithm for bound constrained optimization'', */
/* SIAM J. Scientific Computing 16 (1995), no. 5, pp. 1190--1208. */
/* * * * */
/* NEOS, November 1994. (Latest revision June 1996.) */
/* Optimization Technology Center. */
/* Argonne National Laboratory and Northwestern University. */
/* Written by */
/* Ciyou Zhu */
/* in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal. */
/* ************ */
/* Parameter adjustments */
--gg;
--xx;
--xp;
--d__;
--x;
--nbd;
--u;
--l;
wn_dim1 = 2 * *m;
wn_offset = 1 + wn_dim1;
wn -= wn_offset;
--wv;
wy_dim1 = *n;
wy_offset = 1 + wy_dim1;
wy -= wy_offset;
ws_dim1 = *n;
ws_offset = 1 + ws_dim1;
ws -= ws_offset;
--ind;
/* Function Body */
if (*nsub <= 0) {
return 0;
}
if (*iprint >= 99) {
printf("---------------SUBSM entered---------\n");
}
/* Compute wv = W'Zd. */
pointr = *head;
i__1 = *col;
for (i__ = 1; i__ <= i__1; ++i__) {
temp1 = 0.;
temp2 = 0.;
i__2 = *nsub;
for (j = 1; j <= i__2; ++j) {
k = ind[j];
temp1 += wy[k + pointr * wy_dim1] * d__[j];
temp2 += ws[k + pointr * ws_dim1] * d__[j];
/* L10: */
}
wv[i__] = temp1;
wv[*col + i__] = *theta * temp2;
pointr = pointr % *m + 1;
/* L20: */
}
/* Compute wv:=K^(-1)wv. */
m2 = *m << 1;
col2 = *col << 1;
dtrsl(&wn[wn_offset], &m2, &col2, &wv[1], &c__11, info);
if (*info != 0) {
return 0;
}
i__1 = *col;
for (i__ = 1; i__ <= i__1; ++i__) {
wv[i__] = -wv[i__];
/* L25: */
}
dtrsl(&wn[wn_offset], &m2, &col2, &wv[1], &c__1, info);
if (*info != 0) {
return 0;
}
/* Compute d = (1/theta)d + (1/theta**2)Z'W wv. */
pointr = *head;
i__1 = *col;
for (jy = 1; jy <= i__1; ++jy) {
js = *col + jy;
i__2 = *nsub;
for (i__ = 1; i__ <= i__2; ++i__) {
k = ind[i__];
d__[i__] = d__[i__] + wy[k + pointr * wy_dim1] * wv[jy] / *theta
+ ws[k + pointr * ws_dim1] * wv[js];
/* L30: */
}
pointr = pointr % *m + 1;
/* L40: */
}
d__1 = 1. / *theta;
dscal(nsub, &d__1, &d__[1], &c__1);
/* ----------------------------------------------------------------- */
/* Let us try the projection, d is the Newton direction */
*iword = 0;
dcopy(n, &x[1], &c__1, &xp[1], &c__1);
i__1 = *nsub;
for (i__ = 1; i__ <= i__1; ++i__) {
k = ind[i__];
dk = d__[i__];
xk = x[k];
if (nbd[k] != 0) {
if (nbd[k] == 1) {
/* lower bounds only */
/* Computing MAX */
d__1 = l[k], d__2 = xk + dk;
x[k] = fmax(d__1,d__2);
if (x[k] == l[k]) {
*iword = 1;
}
} else {
if (nbd[k] == 2) {
/* upper and lower bounds */
/* Computing MAX */
d__1 = l[k], d__2 = xk + dk;
xk = fmax(d__1,d__2);
/* Computing MIN */
d__1 = u[k];
x[k] = fmin(d__1,xk);
if (x[k] == l[k] || x[k] == u[k]) {
*iword = 1;
}
} else {
if (nbd[k] == 3) {
/* upper bounds only */
/* Computing MIN */
d__1 = u[k], d__2 = xk + dk;
x[k] = fmin(d__1,d__2);
if (x[k] == u[k]) {
*iword = 1;
}
}
}
}
} else {
/* free variables */
x[k] = xk + dk;
}
/* L50: */
}
if (*iword == 0) {
goto L911;
}
/* check sign of the directional derivative */
dd_p__ = 0.;
i__1 = *n;
for (i__ = 1; i__ <= i__1; ++i__) {
dd_p__ += (x[i__] - xx[i__]) * gg[i__];
/* L55: */
}
if (dd_p__ > 0.) {
dcopy(n, &xp[1], &c__1, &x[1], &c__1);
if (*iprint >= 99) {
printf("Positive dir derivative in projection \n");
printf("Using the backtracking step\n");
}
} else {
goto L911;
}
/* ----------------------------------------------------------------- */
alpha = 1.;
temp1 = alpha;
ibd = 0;
i__1 = *nsub;
for (i__ = 1; i__ <= i__1; ++i__) {
k = ind[i__];
dk = d__[i__];
if (nbd[k] != 0) {
if (dk < 0. && nbd[k] <= 2) {
temp2 = l[k] - x[k];
if (temp2 >= 0.) {
temp1 = 0.;
} else if (dk * alpha < temp2) {
temp1 = temp2 / dk;
}
} else if (dk > 0. && nbd[k] >= 2) {
temp2 = u[k] - x[k];
if (temp2 <= 0.) {
temp1 = 0.;
} else if (dk * alpha > temp2) {
temp1 = temp2 / dk;
}
}
if (temp1 < alpha) {
alpha = temp1;
ibd = i__;
}
}
/* L60: */
}
if (alpha < 1.) {
dk = d__[ibd];
k = ind[ibd];
if (dk > 0.) {
x[k] = u[k];
d__[ibd] = 0.;
} else if (dk < 0.) {
x[k] = l[k];
d__[ibd] = 0.;
}
}
i__1 = *nsub;
for (i__ = 1; i__ <= i__1; ++i__) {
k = ind[i__];
x[k] += alpha * d__[i__];
/* L70: */
}
/* ccccc */
L911:
if (*iprint >= 99) {
printf("----------------- exit SUBSM --------------\n");
}
return 0;
} /* subsm */