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
#include "lbfgsb.h"
int prn1lb(integer *n, integer *m, double *l,
double *u, double *x, integer *iprint, fileType itfile,
double *epsmch)
{
/*
************
Subroutine prn1lb
This subroutine prints the input data, initial point, upper and
lower bounds of each variable, machine precision, as well as
the headings of the output.
* * *
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.
************
*/
/* System generated locals */
integer i__1;
/* Local variables */
static integer i__;
/* Parameter adjustments */
--x;
--u;
--l;
/* Function Body */
if (*iprint >= 0) {
printf(" * * *\n");
printf(" RUNNING THE L-BFGS-B CODE\n");
printf(" * * *\n");
printf("Machine precision = %.2e\n", *epsmch );
printf(" N = %10ld\n M = %10ld\n", *n, *m );
if (*iprint >= 1) {
if (*iprint > 100) {
printf("L =");
i__1 = *n;
for (i__ = 1; i__ <= i__1; ++i__) {
printf("%.2e ", l[i__] );
}
printf("\n");
printf("X0 =");
i__1 = *n;
for (i__ = 1; i__ <= i__1; ++i__) {
printf("%.2e ", x[i__] );
}
printf("\n");
printf("U =");
i__1 = *n;
for (i__ = 1; i__ <= i__1; ++i__) {
printf("%.2e ", u[i__] );
}
printf("\n");
}
}
}
return 0;
} /* prn1lb */
/* Subroutine */ int prn2lb(integer *n, double *x, double *f,
double *g, integer *iprint, fileType itfile, integer *iter,
integer *nfgv, integer *nact, double *sbgnrm, integer *nseg, integer
*word, integer *iword, integer *iback, double *stp, double *
xstep, ftnlen word_len)
{
/*
************
Subroutine prn2lb
This subroutine prints out new information after a successful
line search.
* * *
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.
************
*/
/* 'word' records the status of subspace solutions. */
/* System generated locals */
integer i__1;
/* Local variables */
static integer i__, imod;
/* Parameter adjustments */
--g;
--x;
/* Function Body */
if (*iword == 0) {
*word = WORD_CON;
/* the subspace minimization converged. */
/* s_copy(word, "con", (ftnlen)3, (ftnlen)3); */
} else if (*iword == 1) {
*word = WORD_BND;
/* the subspace minimization stopped at a bound. */
/* s_copy(word, "bnd", (ftnlen)3, (ftnlen)3); */
} else if (*iword == 5) {
*word = WORD_TNT;
/* the truncated Newton step has been used. */
/* s_copy(word, "TNT", (ftnlen)3, (ftnlen)3); */
} else {
*word = WORD_DEFAULT;
/* s_copy(word, "---", (ftnlen)3, (ftnlen)3); */
}
if (*iprint >= 99) {
printf("LINE SEARCH %ld times; norm of step = %.2e\n", *iback, *xstep );
printf("At iterate %5ld, f(x)= %5.2e, ||proj grad||_infty = %.2e\n",*iter,*f,*sbgnrm );
if (*iprint > 100) {
printf("X =");
i__1 = *n;
for (i__ = 1; i__ <= i__1; ++i__) {
printf("%.2e ", x[i__] );
}
printf("\n");
printf("G =");
i__1 = *n;
for (i__ = 1; i__ <= i__1; ++i__) {
printf("%.2e ", g[i__] );
}
printf("\n");
}
} else if (*iprint > 0) {
imod = *iter % *iprint;
if (imod == 0) {
printf("At iterate %5ld, f(x)= %5.2e, ||proj grad||_infty = %.2e\n",*iter,*f,*sbgnrm );
}
}
return 0;
} /* prn2lb */
int prn3lb(integer *n, double *x, double *f, integer *
task, integer *iprint, integer *info, fileType itfile, integer *iter,
integer *nfgv, integer *nintol, integer *nskip, integer *nact,
double *sbgnrm, double *time, integer *nseg, integer *word,
integer *iback, double *stp, double *xstep, integer *k,
double *cachyt, double *sbtime, double *lnscht, ftnlen
task_len, ftnlen word_len)
{
/*
************
Subroutine prn3lb
This subroutine prints out information when either a built-in
convergence test is satisfied or when an error message is
generated.
* * *
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.
************
*/
/* System generated locals */
integer i__1;
/* Local variables */
static integer i__;
/* Parameter adjustments */
--x;
/* Function Body */
/* if (s_cmp(task, "ERROR", (ftnlen)5, (ftnlen)5) == 0) { */
if ( IS_ERROR(*task) ) {
goto L999;
}
if (*iprint >= 0) {
printf(" * * * \n");
printf("Tit = total number of iterations\n");
printf("Tnf = total number of function evaluations\n");
printf("Tnint = total number of segments explored during Cauchy searches\n");
printf("Skip = number of BFGS updates skipped\n");
printf("Nact = number of active bounds at final generalized Cauchy point\n");
printf("Projg = norm of the final projected gradient\n");
printf("F = final function value\n");
printf(" * * * \n");
printf(" N Tit Tnf Tnint Skip Nact Projg F\n");
printf("%5ld %5ld %5ld %5ld %5ld %5ld\t%6.2e %9.5e\n",
*n, *iter, *nfgv, *nintol, *nskip, *nact, *sbgnrm, *f );
if (*iprint >= 100) {
printf("X = ");
i__1 = *n;
for (i__ = 1; i__ <= i__1; ++i__) {
printf(" %.2e", x[i__] );
}
printf("\n");
}
if (*iprint >= 1) {
printf("F(x) = %.9e\n", *f );
}
}
L999:
if (*iprint >= 0) {
printf("%ld\n",*task);
if (*info != 0) {
if (*info == -1) {
printf(" Matrix in 1st Cholesky factorization in formk is not Pos. Def.\n");
}
if (*info == -2) {
printf(" Matrix in 2nd Cholesky factorization in formk is not Pos. Def.\n");
}
if (*info == -3) {
printf(" Matrix in the Cholesky factorization in formt is not Pos. Def.\n");
}
if (*info == -4) {
printf(" Derivative >= 0, backtracking line search impossible.\n");
printf(" Previous x, f and g restored.\n");
printf(" Possible causes: 1 error in function or gradient evaluation;\n");
printf(" 2 rounding errors dominate computation.\n");
}
if (*info == -5) {
printf(" Warning: more than 10 function and gradient\n");
printf(" evaluations in the last line search. Termination\n");
printf(" may possibly be caused by a bad search direction.\n");
}
if (*info == -6) {
printf(" Input nbd(%ld) is invalid\n", *k );
}
if (*info == -7) {
printf(" l(%ld) > u(%ld). No feasible solution.\n", *k, *k );
}
if (*info == -8) {
printf(" The triangular system is singular.\n");
}
if (*info == -9) {
printf(" Line search cannot locate an adequate point after 20 function\n");
printf(" and gradient evaluations. Previous x, f and g restored.\n");
printf(" Possible causes: 1 error in function or gradient evaluation;\n");
printf(" 2 rounding error dominate computation.\n");
}
}
if (*iprint >= 1) {
printf("Cauchy time %.3e seconds.\n", *cachyt );
printf("Subspace minimization time %.3e seconds.\n", *sbtime );
printf("Line search time %.3e seconds.\n", *lnscht );
}
printf(" Total User time %.3e seconds.\n", *time );
}
return 0;
} /* prn3lb */
int errclb(integer *n, integer *m, double *factr,
double *l, double *u, integer *nbd, integer *task, integer *info,
integer *k, ftnlen task_len)
{
/*
************
Subroutine errclb
This subroutine checks the validity of the input data.
* * *
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 input arguments for errors. */
/* System generated locals */
integer i__1;
/* Local variables */
static integer i__;
/* Parameter adjustments */
--nbd;
--u;
--l;
/* Function Body */
if (*n <= 0) *task = ERROR_N0;
if (*m <= 0) *task = ERROR_M0;
if (*factr < 0.) *task = ERROR_FACTR;
/* Check the validity of the arrays nbd(i), u(i), and l(i). */
i__1 = *n;
for (i__ = 1; i__ <= i__1; ++i__) {
if (nbd[i__] < 0 || nbd[i__] > 3) {
/* return */
*task = ERROR_NBD;
*info = -6;
*k = i__;
}
if (nbd[i__] == 2) {
if (l[i__] > u[i__]) {
/* return */
*task = ERROR_FEAS;
*info = -7;
*k = i__;
}
}
/* L10: */
}
return 0;
} /* errclb */