Debian Codegraph @

Modules/ThirdParty/VNL/src/vxl/v3p/netlib/opt/lbfgsb.f

raw
1 c================ L-BFGS-B (version 2.1) ==========================
2
3 subroutine setulb(n, m, x, l, u, nbd, f, g, factr, pgtol, wa, iwa,
4 + task, iprint, csave, lsave, isave, dsave)
5
6 character*60 task, csave
7 logical lsave(4)
8 integer n, m, iprint,
9 + nbd(n), iwa(3*n), isave(44)
10 double precision f, factr, pgtol, x(n), l(n), u(n), g(n),
11 + wa(2*m*n+4*n+12*m*m+12*m), dsave(29)
12
13 c ************
14 c
15 c Subroutine setulb
16 c
17 c This subroutine partitions the working arrays wa and iwa, and
18 c then uses the limited memory BFGS method to solve the bound
19 c constrained optimization problem by calling mainlb.
20 c (The direct method will be used in the subspace minimization.)
21 c
22 c n is an integer variable.
23 c On entry n is the dimension of the problem.
24 c On exit n is unchanged.
25 c
26 c m is an integer variable.
27 c On entry m is the maximum number of variable metric corrections
28 c used to define the limited memory matrix.
29 c On exit m is unchanged.
30 c
31 c x is a double precision array of dimension n.
32 c On entry x is an approximation to the solution.
33 c On exit x is the current approximation.
34 c
35 c l is a double precision array of dimension n.
36 c On entry l is the lower bound on x.
37 c On exit l is unchanged.
38 c
39 c u is a double precision array of dimension n.
40 c On entry u is the upper bound on x.
41 c On exit u is unchanged.
42 c
43 c nbd is an integer array of dimension n.
44 c On entry nbd represents the type of bounds imposed on the
45 c variables, and must be specified as follows:
46 c nbd(i)=0 if x(i) is unbounded,
47 c 1 if x(i) has only a lower bound,
48 c 2 if x(i) has both lower and upper bounds, and
49 c 3 if x(i) has only an upper bound.
50 c On exit nbd is unchanged.
51 c
52 c f is a double precision variable.
53 c On first entry f is unspecified.
54 c On final exit f is the value of the function at x.
55 c
56 c g is a double precision array of dimension n.
57 c On first entry g is unspecified.
58 c On final exit g is the value of the gradient at x.
59 c
60 c factr is a double precision variable.
61 c On entry factr >= 0 is specified by the user. The iteration
62 c will stop when
63 c
64 c (f^k - f^{k+1})/max{|f^k|,|f^{k+1}|,1} <= factr*epsmch
65 c
66 c where epsmch is the machine precision, which is automatically
67 c generated by the code. Typical values for factr: 1.d+12 for
68 c low accuracy; 1.d+7 for moderate accuracy; 1.d+1 for extremely
69 c high accuracy.
70 c On exit factr is unchanged.
71 c
72 c pgtol is a double precision variable.
73 c On entry pgtol >= 0 is specified by the user. The iteration
74 c will stop when
75 c
76 c max{|proj g_i | i = 1, ..., n} <= pgtol
77 c
78 c where pg_i is the ith component of the projected gradient.
79 c On exit pgtol is unchanged.
80 c
81 c wa is a double precision working array of length
82 c (2mmax + 4)nmax + 12mmax^2 + 12mmax.
83 c
84 c iwa is an integer working array of length 3nmax.
85 c
86 c task is a working string of characters of length 60 indicating
87 c the current job when entering and quitting this subroutine.
88 c
89 c iprint is an integer variable that must be set by the user.
90 c It controls the frequency and type of output generated:
91 c iprint<0 no output is generated;
92 c iprint=0 print only one line at the last iteration;
93 c 0<iprint<99 print also f and |proj g| every iprint iterations;
94 c iprint=99 print details of every iteration except n-vectors;
95 c iprint=100 print also the changes of active set and final x;
96 c iprint>100 print details of every iteration including x and g;
97 c When iprint > 0, the file iterate.dat will be created to
98 c summarize the iteration.
99 c
100 c csave is a working string of characters of length 60.
101 c
102 c lsave is a logical working array of dimension 4.
103 c On exit with 'task' = NEW_X, the following information is
104 c available:
105 c If lsave(1) = .true. then the initial X has been replaced by
106 c its projection in the feasible set;
107 c If lsave(2) = .true. then the problem is constrained;
108 c If lsave(3) = .true. then each variable has upper and lower
109 c bounds;
110 c
111 c isave is an integer working array of dimension 44.
112 c On exit with 'task' = NEW_X, the following information is
113 c available:
114 c isave(22) = the total number of intervals explored in the
115 c search of Cauchy points;
116 c isave(26) = the total number of skipped BFGS updates before
117 c the current iteration;
118 c isave(30) = the number of current iteration;
119 c isave(31) = the total number of BFGS updates prior the current
120 c iteration;
121 c isave(33) = the number of intervals explored in the search of
122 c Cauchy point in the current iteration;
123 c isave(34) = the total number of function and gradient
124 c evaluations;
125 c isave(36) = the number of function value or gradient
126 c evaluations in the current iteration;
127 c if isave(37) = 0 then the subspace argmin is within the box;
128 c if isave(37) = 1 then the subspace argmin is beyond the box;
129 c isave(38) = the number of free variables in the current
130 c iteration;
131 c isave(39) = the number of active constraints in the current
132 c iteration;
133 c n + 1 - isave(40) = the number of variables leaving the set of
134 c active constraints in the current iteration;
135 c isave(41) = the number of variables entering the set of active
136 c constraints in the current iteration.
137 c
138 c dsave is a double precision working array of dimension 29.
139 c On exit with 'task' = NEW_X, the following information is
140 c available:
141 c dsave(1) = current 'theta' in the BFGS matrix;
142 c dsave(2) = f(x) in the previous iteration;
143 c dsave(3) = factr*epsmch;
144 c dsave(4) = 2-norm of the line search direction vector;
145 c dsave(5) = the machine precision epsmch generated by the code;
146 c dsave(7) = the accumulated time spent on searching for
147 c Cauchy points;
148 c dsave(8) = the accumulated time spent on
149 c subspace minimization;
150 c dsave(9) = the accumulated time spent on line search;
151 c dsave(11) = the slope of the line search function at
152 c the current point of line search;
153 c dsave(12) = the maximum relative step length imposed in
154 c line search;
155 c dsave(13) = the infinity norm of the projected gradient;
156 c dsave(14) = the relative step length in the line search;
157 c dsave(15) = the slope of the line search function at
158 c the starting point of the line search;
159 c dsave(16) = the square of the 2-norm of the line search
160 c direction vector.
161 c
162 c Subprograms called:
163 c
164 c L-BFGS-B Library ... mainlb.
165 c
166 c
167 c References:
168 c
169 c [1] R. H. Byrd, P. Lu, J. Nocedal and C. Zhu, ``A limited
170 c memory algorithm for bound constrained optimization'',
171 c SIAM J. Scientific Computing 16 (1995), no. 5, pp. 1190--1208.
172 c
173 c [2] C. Zhu, R.H. Byrd, P. Lu, J. Nocedal, ``L-BFGS-B: a
174 c limited memory FORTRAN code for solving bound constrained
175 c optimization problems'', Tech. Report, NAM-11, EECS Department,
176 c Northwestern University, 1994.
177 c
178 c (Postscript files of these papers are available via anonymous
179 c ftp to eecs.nwu.edu in the directory pub/lbfgs/lbfgs_bcm.)
180 c
181 c * * *
182 c
183 c NEOS, November 1994. (Latest revision June 1996.)
184 c Optimization Technology Center.
185 c Argonne National Laboratory and Northwestern University.
186 c Written by
187 c Ciyou Zhu
188 c in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal.
189 c
190 c
191 c ************
192
193 integer l1,l2,l3,lws,lr,lz,lt,ld,lsg,lwa,lyg,
194 + lsgo,lwy,lsy,lss,lyy,lwt,lwn,lsnd,lygo
195
196 if (task .eq. 'START') then
197 isave(1) = m*n
198 isave(2) = m**2
199 isave(3) = 4*m**2
200 isave(4) = 1
201 isave(5) = isave(4) + isave(1)
202 isave(6) = isave(5) + isave(1)
203 isave(7) = isave(6) + isave(2)
204 isave(8) = isave(7) + isave(2)
205 isave(9) = isave(8) + isave(2)
206 isave(10) = isave(9) + isave(2)
207 isave(11) = isave(10) + isave(3)
208 isave(12) = isave(11) + isave(3)
209 isave(13) = isave(12) + n
210 isave(14) = isave(13) + n
211 isave(15) = isave(14) + n
212 isave(16) = isave(15) + n
213 isave(17) = isave(16) + 8*m
214 isave(18) = isave(17) + m
215 isave(19) = isave(18) + m
216 isave(20) = isave(19) + m
217 endif
218 l1 = isave(1)
219 l2 = isave(2)
220 l3 = isave(3)
221 lws = isave(4)
222 lwy = isave(5)
223 lsy = isave(6)
224 lss = isave(7)
225 lyy = isave(8)
226 lwt = isave(9)
227 lwn = isave(10)
228 lsnd = isave(11)
229 lz = isave(12)
230 lr = isave(13)
231 ld = isave(14)
232 lt = isave(15)
233 lwa = isave(16)
234 lsg = isave(17)
235 lsgo = isave(18)
236 lyg = isave(19)
237 lygo = isave(20)
238
239 call mainlb(n,m,x,l,u,nbd,f,g,factr,pgtol,
240 + wa(lws),wa(lwy),wa(lsy),wa(lss),wa(lyy),wa(lwt),
241 + wa(lwn),wa(lsnd),wa(lz),wa(lr),wa(ld),wa(lt),
242 + wa(lwa),wa(lsg),wa(lsgo),wa(lyg),wa(lygo),
243 + iwa(1),iwa(n+1),iwa(2*n+1),task,iprint,
244 + csave,lsave,isave(22),dsave)
245
246 return
247
248 end
249
250 c======================= The end of setulb =============================
251
252 subroutine mainlb(n, m, x, l, u, nbd, f, g, factr, pgtol, ws, wy,
253 + sy, ss, yy, wt, wn, snd, z, r, d, t, wa, sg,
254 + sgo, yg, ygo, index, iwhere, indx2, task,
255 + iprint, csave, lsave, isave, dsave)
256
257 character*60 task, csave
258 logical lsave(4)
259 integer n, m, iprint, nbd(n), index(n),
260 + iwhere(n), indx2(n), isave(23)
261 double precision f, factr, pgtol,
262 + x(n), l(n), u(n), g(n), z(n), r(n), d(n), t(n),
263 + wa(8*m), sg(m), sgo(m), yg(m), ygo(m),
264 + ws(n, m), wy(n, m), sy(m, m), ss(m, m), yy(m, m),
265 + wt(m, m), wn(2*m, 2*m), snd(2*m, 2*m), dsave(29)
266
267 c ************
268 c
269 c Subroutine mainlb
270 c
271 c This subroutine solves bound constrained optimization problems by
272 c using the compact formula of the limited memory BFGS updates.
273 c
274 c n is an integer variable.
275 c On entry n is the number of variables.
276 c On exit n is unchanged.
277 c
278 c m is an integer variable.
279 c On entry m is the maximum number of variable metric
280 c corrections allowed in the limited memory matrix.
281 c On exit m is unchanged.
282 c
283 c x is a double precision array of dimension n.
284 c On entry x is an approximation to the solution.
285 c On exit x is the current approximation.
286 c
287 c l is a double precision array of dimension n.
288 c On entry l is the lower bound of x.
289 c On exit l is unchanged.
290 c
291 c u is a double precision array of dimension n.
292 c On entry u is the upper bound of x.
293 c On exit u is unchanged.
294 c
295 c nbd is an integer array of dimension n.
296 c On entry nbd represents the type of bounds imposed on the
297 c variables, and must be specified as follows:
298 c nbd(i)=0 if x(i) is unbounded,
299 c 1 if x(i) has only a lower bound,
300 c 2 if x(i) has both lower and upper bounds,
301 c 3 if x(i) has only an upper bound.
302 c On exit nbd is unchanged.
303 c
304 c f is a double precision variable.
305 c On first entry f is unspecified.
306 c On final exit f is the value of the function at x.
307 c
308 c g is a double precision array of dimension n.
309 c On first entry g is unspecified.
310 c On final exit g is the value of the gradient at x.
311 c
312 c factr is a double precision variable.
313 c On entry factr >= 0 is specified by the user. The iteration
314 c will stop when
315 c
316 c (f^k - f^{k+1})/max{|f^k|,|f^{k+1}|,1} <= factr*epsmch
317 c
318 c where epsmch is the machine precision, which is automatically
319 c generated by the code.
320 c On exit factr is unchanged.
321 c
322 c pgtol is a double precision variable.
323 c On entry pgtol >= 0 is specified by the user. The iteration
324 c will stop when
325 c
326 c max{|proj g_i | i = 1, ..., n} <= pgtol
327 c
328 c where pg_i is the ith component of the projected gradient.
329 c On exit pgtol is unchanged.
330 c
331 c ws, wy, sy, and wt are double precision working arrays used to
332 c store the following information defining the limited memory
333 c BFGS matrix:
334 c ws, of dimension n x m, stores S, the matrix of s-vectors;
335 c wy, of dimension n x m, stores Y, the matrix of y-vectors;
336 c sy, of dimension m x m, stores S'Y;
337 c ss, of dimension m x m, stores S'S;
338 c yy, of dimension m x m, stores Y'Y;
339 c wt, of dimension m x m, stores the Cholesky factorization
340 c of (theta*S'S+LD^(-1)L'); see eq.
341 c (2.26) in [3].
342 c
343 c wn is a double precision working array of dimension 2m x 2m
344 c used to store the LEL^T factorization of the indefinite matrix
345 c K = [-D -Y'ZZ'Y/theta L_a'-R_z' ]
346 c [L_a -R_z theta*S'AA'S ]
347 c
348 c where E = [-I 0]
349 c [ 0 I]
350 c
351 c snd is a double precision working array of dimension 2m x 2m
352 c used to store the lower triangular part of
353 c N = [Y' ZZ'Y L_a'+R_z']
354 c [L_a +R_z S'AA'S ]
355 c
356 c z(n),r(n),d(n),t(n),wa(8*m) are double precision working arrays.
357 c z is used at different times to store the Cauchy point and
358 c the Newton point.
359 c
360 c sg(m),sgo(m),yg(m),ygo(m) are double precision working arrays.
361 c
362 c index is an integer working array of dimension n.
363 c In subroutine freev, index is used to store the free and fixed
364 c variables at the Generalized Cauchy Point (GCP).
365 c
366 c iwhere is an integer working array of dimension n used to record
367 c the status of the vector x for GCP computation.
368 c iwhere(i)=0 or -3 if x(i) is free and has bounds,
369 c 1 if x(i) is fixed at l(i), and l(i) .ne. u(i)
370 c 2 if x(i) is fixed at u(i), and u(i) .ne. l(i)
371 c 3 if x(i) is always fixed, i.e., u(i)=x(i)=l(i)
372 c -1 if x(i) is always free, i.e., no bounds on it.
373 c
374 c indx2 is an integer working array of dimension n.
375 c Within subroutine cauchy, indx2 corresponds to the array iorder.
376 c In subroutine freev, a list of variables entering and leaving
377 c the free set is stored in indx2, and it is passed on to
378 c subroutine formk with this information.
379 c
380 c task is a working string of characters of length 60 indicating
381 c the current job when entering and leaving this subroutine.
382 c
383 c iprint is an INTEGER variable that must be set by the user.
384 c It controls the frequency and type of output generated:
385 c iprint<0 no output is generated;
386 c iprint=0 print only one line at the last iteration;
387 c 0<iprint<99 print also f and |proj g| every iprint iterations;
388 c iprint=99 print details of every iteration except n-vectors;
389 c iprint=100 print also the changes of active set and final x;
390 c iprint>100 print details of every iteration including x and g;
391 c When iprint > 0, the file iterate.dat will be created to
392 c summarize the iteration.
393 c
394 c csave is a working string of characters of length 60.
395 c
396 c lsave is a logical working array of dimension 4.
397 c
398 c isave is an integer working array of dimension 23.
399 c
400 c dsave is a double precision working array of dimension 29.
401 c
402 c
403 c Subprograms called
404 c
405 c L-BFGS-B Library ... cauchy, subsm, lnsrlb, formk,
406 c
407 c errclb, prn1lb, prn2lb, prn3lb, active, projgr,
408 c
409 c freev, cmprlb, matupd, formt.
410 c
411 c Minpack2 Library ... timer, dpmeps.
412 c
413 c Linpack Library ... dcopy, ddot.
414 c
415 c
416 c References:
417 c
418 c [1] R. H. Byrd, P. Lu, J. Nocedal and C. Zhu, ``A limited
419 c memory algorithm for bound constrained optimization'',
420 c SIAM J. Scientific Computing 16 (1995), no. 5, pp. 1190--1208.
421 c
422 c [2] C. Zhu, R.H. Byrd, P. Lu, J. Nocedal, ``L-BFGS-B: FORTRAN
423 c Subroutines for Large Scale Bound Constrained Optimization''
424 c Tech. Report, NAM-11, EECS Department, Northwestern University,
425 c 1994.
426 c
427 c [3] R. Byrd, J. Nocedal and R. Schnabel "Representations of
428 c Quasi-Newton Matrices and their use in Limited Memory Methods'',
429 c Mathematical Programming 63 (1994), no. 4, pp. 129-156.
430 c
431 c (Postscript files of these papers are available via anonymous
432 c ftp to eecs.nwu.edu in the directory pub/lbfgs/lbfgs_bcm.)
433 c
434 c * * *
435 c
436 c NEOS, November 1994. (Latest revision June 1996.)
437 c Optimization Technology Center.
438 c Argonne National Laboratory and Northwestern University.
439 c Written by
440 c Ciyou Zhu
441 c in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal.
442 c
443 c
444 c ************
445
446 logical prjctd,cnstnd,boxed,updatd,wrk
447 character*3 word
448 integer i,k,nintol,itfile,iback,nskip,
449 + head,col,iter,itail,iupdat,
450 + nint,nfgv,info,ifun,
451 + iword,nfree,nact,ileave,nenter
452 double precision theta,fold,ddot,dr,rr,tol,dpmeps,
453 + xstep,sbgnrm,ddum,dnorm,dtd,epsmch,
454 + cpu1,cpu2,cachyt,sbtime,lnscht,time1,time2,
455 + gd,gdold,stp,stpmx,time
456 double precision one,zero
457 parameter (one=1.0d0,zero=0.0d0)
458
459 if (task .eq. 'START') then
460
461 call timer(time1)
462
463 c Generate the current machine precision.
464
465 epsmch = dpmeps()
466
467 c Initialize counters and scalars when task='START'.
468
469 c for the limited memory BFGS matrices:
470 col = 0
471 head = 1
472 theta = one
473 iupdat = 0
474 updatd = .false.
475
476 c for operation counts:
477 iter = 0
478 nfgv = 0
479 nint = 0
480 nintol = 0
481 nskip = 0
482 nfree = n
483
484 c for stopping tolerance:
485 tol = factr*epsmch
486
487 c for measuring running time:
488 cachyt = 0
489 sbtime = 0
490 lnscht = 0
491
492 c 'word' records the status of subspace solutions.
493 word = '---'
494
495 c 'info' records the termination information.
496 info = 0
497
498 if (iprint .ge. 1) then
499 c open a summary file 'iterate.dat'
500 open (8, file = 'iterate.dat', status = 'unknown')
501 itfile = 8
502 endif
503
504 c Check the input arguments for errors.
505
506 call errclb(n,m,factr,l,u,nbd,task,info,k)
507 if (task(1:5) .eq. 'ERROR') then
508 call prn3lb(n,x,f,task,iprint,info,itfile,
509 + iter,nfgv,nintol,nskip,nact,sbgnrm,
510 + zero,nint,word,iback,stp,xstep,k,
511 + cachyt,sbtime,lnscht)
512 return
513 endif
514
515 call prn1lb(n,m,l,u,x,iprint,itfile,epsmch)
516
517 c Initialize iwhere & project x onto the feasible set.
518
519 call active(n,l,u,nbd,x,iwhere,iprint,prjctd,cnstnd,boxed)
520
521 c The end of the initialization.
522
523 else
524 c restore local variables.
525
526 prjctd = lsave(1)
527 cnstnd = lsave(2)
528 boxed = lsave(3)
529 updatd = lsave(4)
530
531 nintol = isave(1)
532 itfile = isave(3)
533 iback = isave(4)
534 nskip = isave(5)
535 head = isave(6)
536 col = isave(7)
537 itail = isave(8)
538 iter = isave(9)
539 iupdat = isave(10)
540 nint = isave(12)
541 nfgv = isave(13)
542 info = isave(14)
543 ifun = isave(15)
544 iword = isave(16)
545 nfree = isave(17)
546 nact = isave(18)
547 ileave = isave(19)
548 nenter = isave(20)
549
550 theta = dsave(1)
551 fold = dsave(2)
552 tol = dsave(3)
553 dnorm = dsave(4)
554 epsmch = dsave(5)
555 cpu1 = dsave(6)
556 cachyt = dsave(7)
557 sbtime = dsave(8)
558 lnscht = dsave(9)
559 time1 = dsave(10)
560 gd = dsave(11)
561 stpmx = dsave(12)
562 sbgnrm = dsave(13)
563 stp = dsave(14)
564 gdold = dsave(15)
565 dtd = dsave(16)
566
567 c After returning from the driver go to the point where execution
568 c is to resume.
569
570 if (task(1:5) .eq. 'FG_LN') goto 666
571 if (task(1:5) .eq. 'NEW_X') goto 777
572 if (task(1:5) .eq. 'FG_ST') goto 111
573 if (task(1:4) .eq. 'STOP') then
574 if (task(7:9) .eq. 'CPU') then
575 c restore the previous iterate.
576 call dcopy(n,t,1,x,1)
577 call dcopy(n,r,1,g,1)
578 f = fold
579 endif
580 goto 999
581 endif
582 endif
583
584 c Compute f0 and g0.
585
586 task = 'FG_START'
587 c return to the driver to calculate f and g; reenter at 111.
588 goto 1000
589 111 continue
590 nfgv = 1
591
592 c Compute the infinity norm of the (-) projected gradient.
593
594 call projgr(n,l,u,nbd,x,g,sbgnrm)
595
596 if (iprint .ge. 1) then
597 write (6,1002) iter,f,sbgnrm
598 write (itfile,1003) iter,nfgv,sbgnrm,f
599 endif
600 if (sbgnrm .le. pgtol) then
601 c terminate the algorithm.
602 task = 'CONVERGENCE: NORM OF PROJECTED GRADIENT <= PGTOL'
603 goto 999
604 endif
605
606 c ----------------- the beginning of the loop --------------------------
607
608 222 continue
609 if (iprint .ge. 99) write (6,1001) iter + 1
610 iword = -1
611 c
612 if (.not. cnstnd .and. col .gt. 0) then
613 c skip the search for GCP.
614 call dcopy(n,x,1,z,1)
615 wrk = updatd
616 nint = 0
617 goto 333
618 endif
619
620 cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
621 c
622 c Compute the Generalized Cauchy Point (GCP).
623 c
624 cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
625
626 call timer(cpu1)
627 call cauchy(n,x,l,u,nbd,g,indx2,iwhere,t,d,z,
628 + m,wy,ws,sy,wt,theta,col,head,
629 + wa(1),wa(2*m+1),wa(4*m+1),wa(6*m+1),nint,
630 + sg,yg,iprint,sbgnrm,info,epsmch)
631 if (info .ne. 0) then
632 c singular triangular system detected; refresh the lbfgs memory.
633 if(iprint .ge. 1) write (6, 1005)
634 info = 0
635 col = 0
636 head = 1
637 theta = one
638 iupdat = 0
639 updatd = .false.
640 call timer(cpu2)
641 cachyt = cachyt + cpu2 - cpu1
642 goto 222
643 endif
644 call timer(cpu2)
645 cachyt = cachyt + cpu2 - cpu1
646 nintol = nintol + nint
647
648 c Count the entering and leaving variables for iter > 0;
649 c find the index set of free and active variables at the GCP.
650
651 call freev(n,nfree,index,nenter,ileave,indx2,
652 + iwhere,wrk,updatd,cnstnd,iprint,iter)
653
654 nact = n - nfree
655
656 333 continue
657
658 c If there are no free variables or B=theta*I, then
659 c skip the subspace minimization.
660
661 if (nfree .eq. 0 .or. col .eq. 0) goto 555
662
663 cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
664 c
665 c Subspace minimization.
666 c
667 cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
668
669 call timer(cpu1)
670
671 c Form the LEL^T factorization of the indefinite
672 c matrix K = [-D -Y'ZZ'Y/theta L_a'-R_z' ]
673 c [L_a -R_z theta*S'AA'S ]
674 c where E = [-I 0]
675 c [ 0 I]
676
677 if (wrk) call formk(n,nfree,index,nenter,ileave,indx2,iupdat,
678 + updatd,wn,snd,m,ws,wy,sy,theta,col,head,info)
679 if (info .ne. 0) then
680 c nonpositive definiteness in Cholesky factorization;
681 c refresh the lbfgs memory and restart the iteration.
682 if(iprint .ge. 1) write (6, 1006)
683 info = 0
684 col = 0
685 head = 1
686 theta = one
687 iupdat = 0
688 updatd = .false.
689 call timer(cpu2)
690 sbtime = sbtime + cpu2 - cpu1
691 goto 222
692 endif
693
694 c compute r=-Z'B(xcp-xk)-Z'g (using wa(2m+1)=W'(xcp-x)
695 c from 'cauchy').
696 call cmprlb(n,m,x,g,ws,wy,sy,wt,z,r,wa,index,
697 + theta,col,head,nfree,cnstnd,info)
698 if (info .ne. 0) goto 444
699 c call the direct method.
700 call subsm(n,m,nfree,index,l,u,nbd,z,r,ws,wy,theta,
701 + col,head,iword,wa,wn,iprint,info)
702 444 continue
703 if (info .ne. 0) then
704 c singular triangular system detected;
705 c refresh the lbfgs memory and restart the iteration.
706 if(iprint .ge. 1) write (6, 1005)
707 info = 0
708 col = 0
709 head = 1
710 theta = one
711 iupdat = 0
712 updatd = .false.
713 call timer(cpu2)
714 sbtime = sbtime + cpu2 - cpu1
715 goto 222
716 endif
717
718 call timer(cpu2)
719 sbtime = sbtime + cpu2 - cpu1
720 555 continue
721
722 cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
723 c
724 c Line search and optimality tests.
725 c
726 cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
727
728 c Generate the search direction d:=z-x.
729
730 do 40 i = 1, n
731 d(i) = z(i) - x(i)
732 40 continue
733 call timer(cpu1)
734 666 continue
735 call lnsrlb(n,l,u,nbd,x,f,fold,gd,gdold,g,d,r,t,z,stp,dnorm,
736 + dtd,xstep,stpmx,iter,ifun,iback,nfgv,info,task,
737 + boxed,cnstnd,csave,isave(22),dsave(17))
738 if (info .ne. 0 .or. iback .ge. 20) then
739 c restore the previous iterate.
740 call dcopy(n,t,1,x,1)
741 call dcopy(n,r,1,g,1)
742 f = fold
743 if (col .eq. 0) then
744 c abnormal termination.
745 if (info .eq. 0) then
746 info = -9
747 c restore the actual number of f and g evaluations etc.
748 nfgv = nfgv - 1
749 ifun = ifun - 1
750 iback = iback - 1
751 endif
752 task = 'ABNORMAL_TERMINATION_IN_LNSRCH'
753 iter = iter + 1
754 goto 999
755 else
756 c refresh the lbfgs memory and restart the iteration.
757 if(iprint .ge. 1) write (6, 1008)
758 if (info .eq. 0) nfgv = nfgv - 1
759 info = 0
760 col = 0
761 head = 1
762 theta = one
763 iupdat = 0
764 updatd = .false.
765 task = 'RESTART_FROM_LNSRCH'
766 call timer(cpu2)
767 lnscht = lnscht + cpu2 - cpu1
768 goto 222
769 endif
770 else if (task(1:5) .eq. 'FG_LN') then
771 c return to the driver for calculating f and g; reenter at 666.
772 goto 1000
773 else
774 c calculate and print out the quantities related to the new X.
775 call timer(cpu2)
776 lnscht = lnscht + cpu2 - cpu1
777 iter = iter + 1
778
779 c Compute the infinity norm of the projected (-)gradient.
780
781 call projgr(n,l,u,nbd,x,g,sbgnrm)
782
783 c Print iteration information.
784
785 call prn2lb(n,x,f,g,iprint,itfile,iter,nfgv,nact,
786 + sbgnrm,nint,word,iword,iback,stp,xstep)
787 goto 1000
788 endif
789 777 continue
790
791 c Test for termination.
792
793 if (sbgnrm .le. pgtol) then
794 c terminate the algorithm.
795 task = 'CONVERGENCE: NORM OF PROJECTED GRADIENT <= PGTOL'
796 goto 999
797 endif
798
799 ddum = max(abs(fold), abs(f), one)
800 if ((fold - f) .le. tol*ddum) then
801 c terminate the algorithm.
802 task = 'CONVERGENCE: REL_REDUCTION_OF_F <= FACTR*EPSMCH'
803 if (iback .ge. 10) info = -5
804 c i.e., to issue a warning if iback>10 in the line search.
805 goto 999
806 endif
807
808 c Compute d=newx-oldx, r=newg-oldg, rr=y'y and dr=y's.
809
810 do 42 i = 1, n
811 r(i) = g(i) - r(i)
812 42 continue
813 rr = ddot(n,r,1,r,1)
814 if (stp .eq. one) then
815 dr = gd - gdold
816 ddum = -gdold
817 else
818 dr = (gd - gdold)*stp
819 call dscal(n,stp,d,1)
820 ddum = -gdold*stp
821 endif
822
823 if (dr .le. epsmch*ddum) then
824 c skip the L-BFGS update.
825 nskip = nskip + 1
826 updatd = .false.
827 if (iprint .ge. 1) write (6,1004) dr, ddum
828 goto 888
829 endif
830
831 cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
832 c
833 c Update the L-BFGS matrix.
834 c
835 cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
836
837 updatd = .true.
838 iupdat = iupdat + 1
839
840 c Update matrices WS and WY and form the middle matrix in B.
841
842 call matupd(n,m,ws,wy,sy,ss,d,r,itail,
843 + iupdat,col,head,theta,rr,dr,stp,dtd)
844
845 c Form the upper half of the pds T = theta*SS + L*D^(-1)*L';
846 c Store T in the upper triangular of the array wt;
847 c Cholesky factorize T to J*J' with
848 c J' stored in the upper triangular of wt.
849
850 call formt(m,wt,sy,ss,col,theta,info)
851
852 if (info .ne. 0) then
853 c nonpositive definiteness in Cholesky factorization;
854 c refresh the lbfgs memory and restart the iteration.
855 if(iprint .ge. 1) write (6, 1007)
856 info = 0
857 col = 0
858 head = 1
859 theta = one
860 iupdat = 0
861 updatd = .false.
862 goto 222
863 endif
864
865 c Now the inverse of the middle matrix in B is
866
867 c [ D^(1/2) O ] [ -D^(1/2) D^(-1/2)*L' ]
868 c [ -L*D^(-1/2) J ] [ 0 J' ]
869
870 888 continue
871
872 c -------------------- the end of the loop -----------------------------
873
874 goto 222
875 999 continue
876 call timer(time2)
877 time = time2 - time1
878 call prn3lb(n,x,f,task,iprint,info,itfile,
879 + iter,nfgv,nintol,nskip,nact,sbgnrm,
880 + time,nint,word,iback,stp,xstep,k,
881 + cachyt,sbtime,lnscht)
882 1000 continue
883
884 c Save local variables.
885
886 lsave(1) = prjctd
887 lsave(2) = cnstnd
888 lsave(3) = boxed
889 lsave(4) = updatd
890
891 isave(1) = nintol
892 isave(3) = itfile
893 isave(4) = iback
894 isave(5) = nskip
895 isave(6) = head
896 isave(7) = col
897 isave(8) = itail
898 isave(9) = iter
899 isave(10) = iupdat
900 isave(12) = nint
901 isave(13) = nfgv
902 isave(14) = info
903 isave(15) = ifun
904 isave(16) = iword
905 isave(17) = nfree
906 isave(18) = nact
907 isave(19) = ileave
908 isave(20) = nenter
909
910 dsave(1) = theta
911 dsave(2) = fold
912 dsave(3) = tol
913 dsave(4) = dnorm
914 dsave(5) = epsmch
915 dsave(6) = cpu1
916 dsave(7) = cachyt
917 dsave(8) = sbtime
918 dsave(9) = lnscht
919 dsave(10) = time1
920 dsave(11) = gd
921 dsave(12) = stpmx
922 dsave(13) = sbgnrm
923 dsave(14) = stp
924 dsave(15) = gdold
925 dsave(16) = dtd
926
927 1001 format (//,'ITERATION ',i5)
928 1002 format
929 + (/,'At iterate',i5,4x,'f= ',1p,d12.5,4x,'|proj g|= ',1p,d12.5)
930 1003 format (2(1x,i4),5x,'-',5x,'-',3x,'-',5x,'-',5x,'-',8x,'-',3x,
931 + 1p,2(1x,d10.3))
932 1004 format (' ys=',1p,e10.3,' -gs=',1p,e10.3,' BFGS update SKIPPED')
933 1005 format (/,
934 +' Singular triangular system detected;',/,
935 +' refresh the lbfgs memory and restart the iteration.')
936 1006 format (/,
937 +' Nonpositive definiteness in Cholesky factorization in formk;',/,
938 +' refresh the lbfgs memory and restart the iteration.')
939 1007 format (/,
940 +' Nonpositive definiteness in Cholesky factorization in formt;',/,
941 +' refresh the lbfgs memory and restart the iteration.')
942 1008 format (/,
943 +' Bad direction in the line search;',/,
944 +' refresh the lbfgs memory and restart the iteration.')
945
946 return
947
948 end
949
950 c======================= The end of mainlb =============================
951
952 subroutine active(n, l, u, nbd, x, iwhere, iprint,
953 + prjctd, cnstnd, boxed)
954
955 logical prjctd, cnstnd, boxed
956 integer n, iprint, nbd(n), iwhere(n)
957 double precision x(n), l(n), u(n)
958
959 c ************
960 c
961 c Subroutine active
962 c
963 c This subroutine initializes iwhere and projects the initial x to
964 c the feasible set if necessary.
965 c
966 c iwhere is an integer array of dimension n.
967 c On entry iwhere is unspecified.
968 c On exit iwhere(i)=-1 if x(i) has no bounds
969 c 3 if l(i)=u(i)
970 c 0 otherwise.
971 c In cauchy, iwhere is given finer gradations.
972 c
973 c
974 c * * *
975 c
976 c NEOS, November 1994. (Latest revision June 1996.)
977 c Optimization Technology Center.
978 c Argonne National Laboratory and Northwestern University.
979 c Written by
980 c Ciyou Zhu
981 c in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal.
982 c
983 c
984 c ************
985
986 integer nbdd,i
987 double precision zero
988 parameter (zero=0.0d0)
989
990 c Initialize nbdd, prjctd, cnstnd and boxed.
991
992 nbdd = 0
993 prjctd = .false.
994 cnstnd = .false.
995 boxed = .true.
996
997 c Project the initial x to the easible set if necessary.
998
999 do 10 i = 1, n
1000 if (nbd(i) .gt. 0) then
1001 if (nbd(i) .le. 2 .and. x(i) .le. l(i)) then
1002 if (x(i) .lt. l(i)) then
1003 prjctd = .true.
1004 x(i) = l(i)
1005 endif
1006 nbdd = nbdd + 1
1007 else if (nbd(i) .ge. 2 .and. x(i) .ge. u(i)) then
1008 if (x(i) .gt. u(i)) then
1009 prjctd = .true.
1010 x(i) = u(i)
1011 endif
1012 nbdd = nbdd + 1
1013 endif
1014 endif
1015 10 continue
1016
1017 c Initialize iwhere and assign values to cnstnd and boxed.
1018
1019 do 20 i = 1, n
1020 if (nbd(i) .ne. 2) boxed = .false.
1021 if (nbd(i) .eq. 0) then
1022 c this variable is always free
1023 iwhere(i) = -1
1024
1025 c otherwise set x(i)=mid(x(i), u(i), l(i)).
1026 else
1027 cnstnd = .true.
1028 if (nbd(i) .eq. 2 .and. u(i) - l(i) .le. zero) then
1029 c this variable is always fixed
1030 iwhere(i) = 3
1031 else
1032 iwhere(i) = 0
1033 endif
1034 endif
1035 20 continue
1036
1037 if (iprint .ge. 0) then
1038 if (prjctd) write (6,*)
1039 + 'The initial X is infeasible. Restart with its projection.'
1040 if (.not. cnstnd)
1041 + write (6,*) 'This problem is unconstrained.'
1042 endif
1043
1044 if (iprint .gt. 0) write (6,1001) nbdd
1045
1046 1001 format (/,'At X0 ',i9,' variables are exactly at the bounds')
1047
1048 return
1049
1050 end
1051
1052 c======================= The end of active =============================
1053
1054 subroutine bmv(m, sy, wt, col, v, p, info)
1055
1056 integer m, col, info
1057 double precision sy(m, m), wt(m, m), v(2*col), p(2*col)
1058
1059 c ************
1060 c
1061 c Subroutine bmv
1062 c
1063 c This subroutine computes the product of the 2m x 2m middle matrix
1064 c in the compact L-BFGS formula of B and a 2m vector v;
1065 c it returns the product in p.
1066 c
1067 c m is an integer variable.
1068 c On entry m is the maximum number of variable metric corrections
1069 c used to define the limited memory matrix.
1070 c On exit m is unchanged.
1071 c
1072 c sy is a double precision array of dimension m x m.
1073 c On entry sy specifies the matrix S'Y.
1074 c On exit sy is unchanged.
1075 c
1076 c wt is a double precision array of dimension m x m.
1077 c On entry wt specifies the upper triangular matrix J' which is
1078 c the Cholesky factor of (thetaS'S+LD^(-1)L').
1079 c On exit wt is unchanged.
1080 c
1081 c col is an integer variable.
1082 c On entry col specifies the number of s-vectors (or y-vectors)
1083 c stored in the compact L-BFGS formula.
1084 c On exit col is unchanged.
1085 c
1086 c v is a double precision array of dimension 2col.
1087 c On entry v specifies vector v.
1088 c On exit v is unchanged.
1089 c
1090 c p is a double precision array of dimension 2col.
1091 c On entry p is unspecified.
1092 c On exit p is the product Mv.
1093 c
1094 c info is an integer variable.
1095 c On entry info is unspecified.
1096 c On exit info = 0 for normal return,
1097 c = nonzero for abnormal return when the system
1098 c to be solved by dtrsl is singular.
1099 c
1100 c Subprograms called:
1101 c
1102 c Linpack ... dtrsl.
1103 c
1104 c
1105 c * * *
1106 c
1107 c NEOS, November 1994. (Latest revision June 1996.)
1108 c Optimization Technology Center.
1109 c Argonne National Laboratory and Northwestern University.
1110 c Written by
1111 c Ciyou Zhu
1112 c in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal.
1113 c
1114 c
1115 c ************
1116
1117 integer i,k,i2
1118 double precision sum
1119
1120 if (col .eq. 0) return
1121
1122 c PART I: solve [ D^(1/2) O ] [ p1 ] = [ v1 ]
1123 c [ -L*D^(-1/2) J ] [ p2 ] [ v2 ].
1124
1125 c solve Jp2=v2+LD^(-1)v1.
1126 p(col + 1) = v(col + 1)
1127 do 20 i = 2, col
1128 i2 = col + i
1129 sum = 0.0d0
1130 do 10 k = 1, i - 1
1131 sum = sum + sy(i,k)*v(k)/sy(k,k)
1132 10 continue
1133 p(i2) = v(i2) + sum
1134 20 continue
1135 c Solve the triangular system
1136 call dtrsl(wt,m,col,p(col+1),11,info)
1137 if (info .ne. 0) return
1138
1139 c solve D^(1/2)p1=v1.
1140 do 30 i = 1, col
1141 p(i) = v(i)/sqrt(sy(i,i))
1142 30 continue
1143
1144 c PART II: solve [ -D^(1/2) D^(-1/2)*L' ] [ p1 ] = [ p1 ]
1145 c [ 0 J' ] [ p2 ] [ p2 ].
1146
1147 c solve J^Tp2=p2.
1148 call dtrsl(wt,m,col,p(col+1),01,info)
1149 if (info .ne. 0) return
1150
1151 c compute p1=-D^(-1/2)(p1-D^(-1/2)L'p2)
1152 c =-D^(-1/2)p1+D^(-1)L'p2.
1153 do 40 i = 1, col
1154 p(i) = -p(i)/sqrt(sy(i,i))
1155 40 continue
1156 do 60 i = 1, col
1157 sum = 0.d0
1158 do 50 k = i + 1, col
1159 sum = sum + sy(k,i)*p(col+k)/sy(i,i)
1160 50 continue
1161 p(i) = p(i) + sum
1162 60 continue
1163
1164 return
1165
1166 end
1167
1168 c======================== The end of bmv ===============================
1169
1170 subroutine cauchy(n, x, l, u, nbd, g, iorder, iwhere, t, d, xcp,
1171 + m, wy, ws, sy, wt, theta, col, head, p, c, wbp,
1172 + v, nint, sg, yg, iprint, sbgnrm, info, epsmch)
1173
1174 integer n, m, head, col, nint, iprint, info,
1175 + nbd(n), iorder(n), iwhere(n)
1176 double precision theta, epsmch,
1177 + x(n), l(n), u(n), g(n), t(n), d(n), xcp(n),
1178 + sg(m), yg(m), wy(n, col), ws(n, col), sy(m, m),
1179 + wt(m, m), p(2*m), c(2*m), wbp(2*m), v(2*m)
1180
1181 c ************
1182 c
1183 c Subroutine cauchy
1184 c
1185 c For given x, l, u, g (with sbgnrm > 0), and a limited memory
1186 c BFGS matrix B defined in terms of matrices WY, WS, WT, and
1187 c scalars head, col, and theta, this subroutine computes the
1188 c generalized Cauchy point (GCP), defined as the first local
1189 c minimizer of the quadratic
1190 c
1191 c Q(x + s) = g's + 1/2 s'Bs
1192 c
1193 c along the projected gradient direction P(x-tg,l,u).
1194 c The routine returns the GCP in xcp.
1195 c
1196 c n is an integer variable.
1197 c On entry n is the dimension of the problem.
1198 c On exit n is unchanged.
1199 c
1200 c x is a double precision array of dimension n.
1201 c On entry x is the starting point for the GCP computation.
1202 c On exit x is unchanged.
1203 c
1204 c l is a double precision array of dimension n.
1205 c On entry l is the lower bound of x.
1206 c On exit l is unchanged.
1207 c
1208 c u is a double precision array of dimension n.
1209 c On entry u is the upper bound of x.
1210 c On exit u is unchanged.
1211 c
1212 c nbd is an integer array of dimension n.
1213 c On entry nbd represents the type of bounds imposed on the
1214 c variables, and must be specified as follows:
1215 c nbd(i)=0 if x(i) is unbounded,
1216 c 1 if x(i) has only a lower bound,
1217 c 2 if x(i) has both lower and upper bounds, and
1218 c 3 if x(i) has only an upper bound.
1219 c On exit nbd is unchanged.
1220 c
1221 c g is a double precision array of dimension n.
1222 c On entry g is the gradient of f(x). g must be a nonzero vector.
1223 c On exit g is unchanged.
1224 c
1225 c iorder is an integer working array of dimension n.
1226 c iorder will be used to store the breakpoints in the piecewise
1227 c linear path and free variables encountered. On exit,
1228 c iorder(1),...,iorder(nleft) are indices of breakpoints
1229 c which have not been encountered;
1230 c iorder(nleft+1),...,iorder(nbreak) are indices of
1231 c encountered breakpoints; and
1232 c iorder(nfree),...,iorder(n) are indices of variables which
1233 c have no bound constraits along the search direction.
1234 c
1235 c iwhere is an integer array of dimension n.
1236 c On entry iwhere indicates only the permanently fixed (iwhere=3)
1237 c or free (iwhere= -1) components of x.
1238 c On exit iwhere records the status of the current x variables.
1239 c iwhere(i)=-3 if x(i) is free and has bounds, but is not moved
1240 c 0 if x(i) is free and has bounds, and is moved
1241 c 1 if x(i) is fixed at l(i), and l(i) .ne. u(i)
1242 c 2 if x(i) is fixed at u(i), and u(i) .ne. l(i)
1243 c 3 if x(i) is always fixed, i.e., u(i)=x(i)=l(i)
1244 c -1 if x(i) is always free, i.e., it has no bounds.
1245 c
1246 c t is a double precision working array of dimension n.
1247 c t will be used to store the break points.
1248 c
1249 c d is a double precision array of dimension n used to store
1250 c the Cauchy direction P(x-tg)-x.
1251 c
1252 c xcp is a double precision array of dimension n used to return the
1253 c GCP on exit.
1254 c
1255 c m is an integer variable.
1256 c On entry m is the maximum number of variable metric corrections
1257 c used to define the limited memory matrix.
1258 c On exit m is unchanged.
1259 c
1260 c ws, wy, sy, and wt are double precision arrays.
1261 c On entry they store information that defines the
1262 c limited memory BFGS matrix:
1263 c ws(n,m) stores S, a set of s-vectors;
1264 c wy(n,m) stores Y, a set of y-vectors;
1265 c sy(m,m) stores S'Y;
1266 c wt(m,m) stores the
1267 c Cholesky factorization of (theta*S'S+LD^(-1)L').
1268 c On exit these arrays are unchanged.
1269 c
1270 c theta is a double precision variable.
1271 c On entry theta is the scaling factor specifying B_0 = theta I.
1272 c On exit theta is unchanged.
1273 c
1274 c col is an integer variable.
1275 c On entry col is the actual number of variable metric
1276 c corrections stored so far.
1277 c On exit col is unchanged.
1278 c
1279 c head is an integer variable.
1280 c On entry head is the location of the first s-vector (or y-vector)
1281 c in S (or Y).
1282 c On exit col is unchanged.
1283 c
1284 c p is a double precision working array of dimension 2m.
1285 c p will be used to store the vector p = W^(T)d.
1286 c
1287 c c is a double precision working array of dimension 2m.
1288 c c will be used to store the vector c = W^(T)(xcp-x).
1289 c
1290 c wbp is a double precision working array of dimension 2m.
1291 c wbp will be used to store the row of W corresponding
1292 c to a breakpoint.
1293 c
1294 c v is a double precision working array of dimension 2m.
1295 c
1296 c nint is an integer variable.
1297 c On exit nint records the number of quadratic segments explored
1298 c in searching for the GCP.
1299 c
1300 c sg and yg are double precision arrays of dimension m.
1301 c On entry sg and yg store S'g and Y'g correspondingly.
1302 c On exit they are unchanged.
1303 c
1304 c iprint is an INTEGER variable that must be set by the user.
1305 c It controls the frequency and type of output generated:
1306 c iprint<0 no output is generated;
1307 c iprint=0 print only one line at the last iteration;
1308 c 0<iprint<99 print also f and |proj g| every iprint iterations;
1309 c iprint=99 print details of every iteration except n-vectors;
1310 c iprint=100 print also the changes of active set and final x;
1311 c iprint>100 print details of every iteration including x and g;
1312 c When iprint > 0, the file iterate.dat will be created to
1313 c summarize the iteration.
1314 c
1315 c sbgnrm is a double precision variable.
1316 c On entry sbgnrm is the norm of the projected gradient at x.
1317 c On exit sbgnrm is unchanged.
1318 c
1319 c info is an integer variable.
1320 c On entry info is 0.
1321 c On exit info = 0 for normal return,
1322 c = nonzero for abnormal return when the the system
1323 c used in routine bmv is singular.
1324 c
1325 c Subprograms called:
1326 c
1327 c L-BFGS-B Library ... hpsolb, bmv.
1328 c
1329 c Linpack ... dscal dcopy, daxpy.
1330 c
1331 c
1332 c References:
1333 c
1334 c [1] R. H. Byrd, P. Lu, J. Nocedal and C. Zhu, ``A limited
1335 c memory algorithm for bound constrained optimization'',
1336 c SIAM J. Scientific Computing 16 (1995), no. 5, pp. 1190--1208.
1337 c
1338 c [2] C. Zhu, R.H. Byrd, P. Lu, J. Nocedal, ``L-BFGS-B: FORTRAN
1339 c Subroutines for Large Scale Bound Constrained Optimization''
1340 c Tech. Report, NAM-11, EECS Department, Northwestern University,
1341 c 1994.
1342 c
1343 c (Postscript files of these papers are available via anonymous
1344 c ftp to eecs.nwu.edu in the directory pub/lbfgs/lbfgs_bcm.)
1345 c
1346 c * * *
1347 c
1348 c NEOS, November 1994. (Latest revision June 1996.)
1349 c Optimization Technology Center.
1350 c Argonne National Laboratory and Northwestern University.
1351 c Written by
1352 c Ciyou Zhu
1353 c in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal.
1354 c
1355 c
1356 c ************
1357
1358 logical xlower,xupper,bnded
1359 integer i,j,col2,nfree,nbreak,pointr,
1360 + ibp,nleft,ibkmin,iter
1361 double precision f1,f2,dt,dtm,tsum,dibp,zibp,dibp2,bkmin,
1362 + tu,tl,wmc,wmp,wmw,ddot,tj,tj0,neggi,sbgnrm,
1363 + f2_org
1364 double precision one,zero
1365 parameter (one=1.0d0,zero=0.0d0)
1366
1367 c Check the status of the variables, reset iwhere(i) if necessary;
1368 c compute the Cauchy direction d and the breakpoints t; initialize
1369 c the derivative f1 and the vector p = W'd (for theta = 1).
1370
1371 if (sbgnrm .le. zero) then
1372 if (iprint .ge. 0) write (6,*) 'Subgnorm = 0. GCP = X.'
1373 call dcopy(n,x,1,xcp,1)
1374 return
1375 endif
1376 bnded = .true.
1377 nfree = n + 1
1378 nbreak = 0
1379 ibkmin = 0
1380 bkmin = zero
1381 col2 = 2*col
1382 f1 = zero
1383 if (iprint .ge. 99) write (6,3010)
1384
1385 c We set p to zero and build it up as we determine d.
1386
1387 do 20 i = 1, col2
1388 p(i) = zero
1389 20 continue
1390
1391 c In the following loop we determine for each variable its bound
1392 c status and its breakpoint, and update p accordingly.
1393 c Smallest breakpoint is identified.
1394
1395 do 50 i = 1, n
1396 neggi = -g(i)
1397 if (iwhere(i) .ne. 3 .and. iwhere(i) .ne. -1) then
1398 c if x(i) is not a constant and has bounds,
1399 c compute the difference between x(i) and its bounds.
1400 if (nbd(i) .le. 2) tl = x(i) - l(i)
1401 if (nbd(i) .ge. 2) tu = u(i) - x(i)
1402
1403 c If a variable is close enough to a bound
1404 c we treat it as at bound.
1405 xlower = nbd(i) .le. 2 .and. tl .le. zero
1406 xupper = nbd(i) .ge. 2 .and. tu .le. zero
1407
1408 c reset iwhere(i).
1409 iwhere(i) = 0
1410 if (xlower) then
1411 if (neggi .le. zero) iwhere(i) = 1
1412 else if (xupper) then
1413 if (neggi .ge. zero) iwhere(i) = 2
1414 else
1415 if (abs(neggi) .le. zero) iwhere(i) = -3
1416 endif
1417 endif
1418 pointr = head
1419 if (iwhere(i) .ne. 0 .and. iwhere(i) .ne. -1) then
1420 d(i) = zero
1421 else
1422 d(i) = neggi
1423 f1 = f1 - neggi*neggi
1424 c calculate p := p - W'e_i* (g_i).
1425 do 40 j = 1, col
1426 p(j) = p(j) + wy(i,pointr)* neggi
1427 p(col + j) = p(col + j) + ws(i,pointr)*neggi
1428 pointr = mod(pointr,m) + 1
1429 40 continue
1430 if (nbd(i) .le. 2 .and. nbd(i) .ne. 0
1431 + .and. neggi .lt. zero) then
1432 c x(i) + d(i) is bounded; compute t(i).
1433 nbreak = nbreak + 1
1434 iorder(nbreak) = i
1435 t(nbreak) = tl/(-neggi)
1436 if (nbreak .eq. 1 .or. t(nbreak) .lt. bkmin) then
1437 bkmin = t(nbreak)
1438 ibkmin = nbreak
1439 endif
1440 else if (nbd(i) .ge. 2 .and. neggi .gt. zero) then
1441 c x(i) + d(i) is bounded; compute t(i).
1442 nbreak = nbreak + 1
1443 iorder(nbreak) = i
1444 t(nbreak) = tu/neggi
1445 if (nbreak .eq. 1 .or. t(nbreak) .lt. bkmin) then
1446 bkmin = t(nbreak)
1447 ibkmin = nbreak
1448 endif
1449 else
1450 c x(i) + d(i) is not bounded.
1451 nfree = nfree - 1
1452 iorder(nfree) = i
1453 if (abs(neggi) .gt. zero) bnded = .false.
1454 endif
1455 endif
1456 50 continue
1457
1458 c The indices of the nonzero components of d are now stored
1459 c in iorder(1),...,iorder(nbreak) and iorder(nfree),...,iorder(n).
1460 c The smallest of the nbreak breakpoints is in t(ibkmin)=bkmin.
1461
1462 if (theta .ne. one) then
1463 c complete the initialization of p for theta not= one.
1464 call dscal(col,theta,p(col+1),1)
1465 endif
1466
1467 c Initialize GCP xcp = x.
1468
1469 call dcopy(n,x,1,xcp,1)
1470
1471 if (nbreak .eq. 0 .and. nfree .eq. n + 1) then
1472 c is a zero vector, return with the initial xcp as GCP.
1473 if (iprint .gt. 100) write (6,1010) (xcp(i), i = 1, n)
1474 return
1475 endif
1476
1477 c Initialize c = W'(xcp - x) = 0.
1478
1479 do 60 j = 1, col2
1480 c(j) = zero
1481 60 continue
1482
1483 c Initialize derivative f2.
1484
1485 f2 = -theta*f1
1486 f2_org = f2
1487 if (col .gt. 0) then
1488 call bmv(m,sy,wt,col,p,v,info)
1489 if (info .ne. 0) return
1490 f2 = f2 - ddot(col2,v,1,p,1)
1491 endif
1492 dtm = -f1/f2
1493 tsum = zero
1494 nint = 1
1495 if (iprint .ge. 99)
1496 + write (6,*) 'There are ',nbreak,' breakpoints '
1497
1498 c If there are no breakpoints, locate the GCP and return.
1499
1500 if (nbreak .eq. 0) goto 888
1501
1502 nleft = nbreak
1503 iter = 1
1504
1505
1506 tj = zero
1507
1508 c------------------- the beginning of the loop -------------------------
1509
1510 777 continue
1511
1512 c Find the next smallest breakpoint;
1513 c compute dt = t(nleft) - t(nleft + 1).
1514
1515 tj0 = tj
1516 if (iter .eq. 1) then
1517 c Since we already have the smallest breakpoint we need not do
1518 c heapsort yet. Often only one breakpoint is used and the
1519 c cost of heapsort is avoided.
1520 tj = bkmin
1521 ibp = iorder(ibkmin)
1522 else
1523 if (iter .eq. 2) then
1524 c Replace the already used smallest breakpoint with the
1525 c breakpoint numbered nbreak > nlast, before heapsort call.
1526 if (ibkmin .ne. nbreak) then
1527 t(ibkmin) = t(nbreak)
1528 iorder(ibkmin) = iorder(nbreak)
1529 endif
1530 c Update heap structure of breakpoints
1531 c (if iter=2, initialize heap).
1532 endif
1533 call hpsolb(nleft,t,iorder,iter-2)
1534 tj = t(nleft)
1535 ibp = iorder(nleft)
1536 endif
1537
1538 dt = tj - tj0
1539
1540 if (dt .ne. zero .and. iprint .ge. 100) then
1541 write (6,4011) nint,f1,f2
1542 write (6,5010) dt
1543 write (6,6010) dtm
1544 endif
1545
1546 c If a minimizer is within this interval, locate the GCP and return.
1547
1548 if (dtm .lt. dt) goto 888
1549
1550 c Otherwise fix one variable and
1551 c reset the corresponding component of d to zero.
1552
1553 tsum = tsum + dt
1554 nleft = nleft - 1
1555 iter = iter + 1
1556 dibp = d(ibp)
1557 d(ibp) = zero
1558 if (dibp .gt. zero) then
1559 zibp = u(ibp) - x(ibp)
1560 xcp(ibp) = u(ibp)
1561 iwhere(ibp) = 2
1562 else
1563 zibp = l(ibp) - x(ibp)
1564 xcp(ibp) = l(ibp)
1565 iwhere(ibp) = 1
1566 endif
1567 if (iprint .ge. 100) write (6,*) 'Variable ',ibp,' is fixed.'
1568 if (nleft .eq. 0 .and. nbreak .eq. n) then
1569 c all n variables are fixed,
1570 c return with xcp as GCP.
1571 dtm = dt
1572 goto 999
1573 endif
1574
1575 c Update the derivative information.
1576
1577 nint = nint + 1
1578 dibp2 = dibp**2
1579
1580 c Update f1 and f2.
1581
1582 c temporarily set f1 and f2 for col=0.
1583 f1 = f1 + dt*f2 + dibp2 - theta*dibp*zibp
1584 f2 = f2 - theta*dibp2
1585
1586 if (col .gt. 0) then
1587 c update c = c + dt*p.
1588 call daxpy(col2,dt,p,1,c,1)
1589
1590 c choose wbp,
1591 c the row of W corresponding to the breakpoint encountered.
1592 pointr = head
1593 do 70 j = 1,col
1594 wbp(j) = wy(ibp,pointr)
1595 wbp(col + j) = theta*ws(ibp,pointr)
1596 pointr = mod(pointr,m) + 1
1597 70 continue
1598
1599 c compute (wbp)Mc, (wbp)Mp, and (wbp)M(wbp)'.
1600 call bmv(m,sy,wt,col,wbp,v,info)
1601 if (info .ne. 0) return
1602 wmc = ddot(col2,c,1,v,1)
1603 wmp = ddot(col2,p,1,v,1)
1604 wmw = ddot(col2,wbp,1,v,1)
1605
1606 c update p = p - dibp*wbp.
1607 call daxpy(col2,-dibp,wbp,1,p,1)
1608
1609 c complete updating f1 and f2 while col > 0.
1610 f1 = f1 + dibp*wmc
1611 f2 = f2 + 2.0d0*dibp*wmp - dibp2*wmw
1612 endif
1613
1614 f2 = max(epsmch*f2_org,f2)
1615 if (nleft .gt. 0) then
1616 dtm = -f1/f2
1617 goto 777
1618 c to repeat the loop for unsearched intervals.
1619 else if(bnded) then
1620 f1 = zero
1621 f2 = zero
1622 dtm = zero
1623 else
1624 dtm = -f1/f2
1625 endif
1626
1627 c------------------- the end of the loop -------------------------------
1628
1629 888 continue
1630 if (iprint .ge. 99) then
1631 write (6,*)
1632 write (6,*) 'GCP found in this segment'
1633 write (6,4010) nint,f1,f2
1634 write (6,6010) dtm
1635 endif
1636 if (dtm .le. zero) dtm = zero
1637 tsum = tsum + dtm
1638
1639 c Move free variables (i.e., the ones w/o breakpoints) and
1640 c the variables whose breakpoints haven't been reached.
1641
1642 call daxpy(n,tsum,d,1,xcp,1)
1643
1644 999 continue
1645
1646 c Update c = c + dtm*p = W'(x^c - x)
1647 c which will be used in computing r = Z'(B(x^c - x) + g).
1648
1649 if (col .gt. 0) call daxpy(col2,dtm,p,1,c,1)
1650 if (iprint .gt. 100) write (6,1010) (xcp(i),i = 1,n)
1651 if (iprint .ge. 99) write (6,2010)
1652
1653 1010 format ('Cauchy X = ',/,(4x,1p,6(1x,d11.4)))
1654 2010 format (/,'---------------- exit CAUCHY----------------------',/)
1655 3010 format (/,'---------------- CAUCHY entered-------------------')
1656 4010 format ('Piece ',i3,' --f1, f2 at start point ',1p,2(1x,d11.4))
1657 4011 format (/,'Piece ',i3,' --f1, f2 at start point ',
1658 + 1p,2(1x,d11.4))
1659 5010 format ('Distance to the next break point = ',1p,d11.4)
1660 6010 format ('Distance to the stationary point = ',1p,d11.4)
1661
1662 return
1663
1664 end
1665
1666 c====================== The end of cauchy ==============================
1667
1668 subroutine cmprlb(n, m, x, g, ws, wy, sy, wt, z, r, wa, index,
1669 + theta, col, head, nfree, cnstnd, info)
1670
1671 logical cnstnd
1672 integer n, m, col, head, nfree, info, index(n)
1673 double precision theta,
1674 + x(n), g(n), z(n), r(n), wa(4*m),
1675 + ws(n, m), wy(n, m), sy(m, m), wt(m, m)
1676
1677 c ************
1678 c
1679 c Subroutine cmprlb
1680 c
1681 c This subroutine computes r=-Z'B(xcp-xk)-Z'g by using
1682 c wa(2m+1)=W'(xcp-x) from subroutine cauchy.
1683 c
1684 c Subprograms called:
1685 c
1686 c L-BFGS-B Library ... bmv.
1687 c
1688 c
1689 c * * *
1690 c
1691 c NEOS, November 1994. (Latest revision June 1996.)
1692 c Optimization Technology Center.
1693 c Argonne National Laboratory and Northwestern University.
1694 c Written by
1695 c Ciyou Zhu
1696 c in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal.
1697 c
1698 c
1699 c ************
1700
1701 integer i,j,k,pointr
1702 double precision a1,a2
1703
1704 if (.not. cnstnd .and. col .gt. 0) then
1705 do 26 i = 1, n
1706 r(i) = -g(i)
1707 26 continue
1708 else
1709 do 30 i = 1, nfree
1710 k = index(i)
1711 r(i) = -theta*(z(k) - x(k)) - g(k)
1712 30 continue
1713 call bmv(m,sy,wt,col,wa(2*m+1),wa(1),info)
1714 if (info .ne. 0) then
1715 info = -8
1716 return
1717 endif
1718 pointr = head
1719 do 34 j = 1, col
1720 a1 = wa(j)
1721 a2 = theta*wa(col + j)
1722 do 32 i = 1, nfree
1723 k = index(i)
1724 r(i) = r(i) + wy(k,pointr)*a1 + ws(k,pointr)*a2
1725 32 continue
1726 pointr = mod(pointr,m) + 1
1727 34 continue
1728 endif
1729
1730 return
1731
1732 end
1733
1734 c======================= The end of cmprlb =============================
1735
1736 subroutine errclb(n, m, factr, l, u, nbd, task, info, k)
1737
1738 character*60 task
1739 integer n, m, info, k, nbd(n)
1740 double precision factr, l(n), u(n)
1741
1742 c ************
1743 c
1744 c Subroutine errclb
1745 c
1746 c This subroutine checks the validity of the input data.
1747 c
1748 c
1749 c * * *
1750 c
1751 c NEOS, November 1994. (Latest revision June 1996.)
1752 c Optimization Technology Center.
1753 c Argonne National Laboratory and Northwestern University.
1754 c Written by
1755 c Ciyou Zhu
1756 c in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal.
1757 c
1758 c
1759 c ************
1760
1761 integer i
1762 double precision one,zero
1763 parameter (one=1.0d0,zero=0.0d0)
1764
1765 c Check the input arguments for errors.
1766
1767 if (n .le. 0) task = 'ERROR: N .LE. 0'
1768 if (m .le. 0) task = 'ERROR: M .LE. 0'
1769 if (factr .lt. zero) task = 'ERROR: FACTR .LT. 0'
1770
1771 c Check the validity of the arrays nbd(i), u(i), and l(i).
1772
1773 do 10 i = 1, n
1774 if (nbd(i) .lt. 0 .or. nbd(i) .gt. 3) then
1775 c return
1776 task = 'ERROR: INVALID NBD'
1777 info = -6
1778 k = i
1779 endif
1780 if (nbd(i) .eq. 2) then
1781 if (l(i) .gt. u(i)) then
1782 c return
1783 task = 'ERROR: NO FEASIBLE SOLUTION'
1784 info = -7
1785 k = i
1786 endif
1787 endif
1788 10 continue
1789
1790 return
1791
1792 end
1793
1794 c======================= The end of errclb =============================
1795
1796 subroutine formk(n, nsub, ind, nenter, ileave, indx2, iupdat,
1797 + updatd, wn, wn1, m, ws, wy, sy, theta, col,
1798 + head, info)
1799
1800 integer n, nsub, m, col, head, nenter, ileave, iupdat,
1801 + info, ind(n), indx2(n)
1802 double precision theta, wn(2*m, 2*m), wn1(2*m, 2*m),
1803 + ws(n, m), wy(n, m), sy(m, m)
1804 logical updatd
1805
1806 c ************
1807 c
1808 c Subroutine formk
1809 c
1810 c This subroutine forms the LEL^T factorization of the indefinite
1811 c
1812 c matrix K = [-D -Y'ZZ'Y/theta L_a'-R_z' ]
1813 c [L_a -R_z theta*S'AA'S ]
1814 c where E = [-I 0]
1815 c [ 0 I]
1816 c The matrix K can be shown to be equal to the matrix M^[-1]N
1817 c occurring in section 5.1 of [1], as well as to the matrix
1818 c Mbar^[-1] Nbar in section 5.3.
1819 c
1820 c n is an integer variable.
1821 c On entry n is the dimension of the problem.
1822 c On exit n is unchanged.
1823 c
1824 c nsub is an integer variable
1825 c On entry nsub is the number of subspace variables in free set.
1826 c On exit nsub is not changed.
1827 c
1828 c ind is an integer array of dimension nsub.
1829 c On entry ind specifies the indices of subspace variables.
1830 c On exit ind is unchanged.
1831 c
1832 c nenter is an integer variable.
1833 c On entry nenter is the number of variables entering the
1834 c free set.
1835 c On exit nenter is unchanged.
1836 c
1837 c ileave is an integer variable.
1838 c On entry indx2(ileave),...,indx2(n) are the variables leaving
1839 c the free set.
1840 c On exit ileave is unchanged.
1841 c
1842 c indx2 is an integer array of dimension n.
1843 c On entry indx2(1),...,indx2(nenter) are the variables entering
1844 c the free set, while indx2(ileave),...,indx2(n) are the
1845 c variables leaving the free set.
1846 c On exit indx2 is unchanged.
1847 c
1848 c iupdat is an integer variable.
1849 c On entry iupdat is the total number of BFGS updates made so far.
1850 c On exit iupdat is unchanged.
1851 c
1852 c updatd is a logical variable.
1853 c On entry 'updatd' is true if the L-BFGS matrix is updatd.
1854 c On exit 'updatd' is unchanged.
1855 c
1856 c wn is a double precision array of dimension 2m x 2m.
1857 c On entry wn is unspecified.
1858 c On exit the upper triangle of wn stores the LEL^T factorization
1859 c of the 2*col x 2*col indefinite matrix
1860 c [-D -Y'ZZ'Y/theta L_a'-R_z' ]
1861 c [L_a -R_z theta*S'AA'S ]
1862 c
1863 c wn1 is a double precision array of dimension 2m x 2m.
1864 c On entry wn1 stores the lower triangular part of
1865 c [Y' ZZ'Y L_a'+R_z']
1866 c [L_a+R_z S'AA'S ]
1867 c in the previous iteration.
1868 c On exit wn1 stores the corresponding updated matrices.
1869 c The purpose of wn1 is just to store these inner products
1870 c so they can be easily updated and inserted into wn.
1871 c
1872 c m is an integer variable.
1873 c On entry m is the maximum number of variable metric corrections
1874 c used to define the limited memory matrix.
1875 c On exit m is unchanged.
1876 c
1877 c ws, wy, sy, and wtyy are double precision arrays;
1878 c theta is a double precision variable;
1879 c col is an integer variable;
1880 c head is an integer variable.
1881 c On entry they store the information defining the
1882 c limited memory BFGS matrix:
1883 c ws(n,m) stores S, a set of s-vectors;
1884 c wy(n,m) stores Y, a set of y-vectors;
1885 c sy(m,m) stores S'Y;
1886 c wtyy(m,m) stores the Cholesky factorization
1887 c of (theta*S'S+LD^(-1)L')
1888 c theta is the scaling factor specifying B_0 = theta I;
1889 c col is the number of variable metric corrections stored;
1890 c head is the location of the 1st s- (or y-) vector in S (or Y).
1891 c On exit they are unchanged.
1892 c
1893 c info is an integer variable.
1894 c On entry info is unspecified.
1895 c On exit info = 0 for normal return;
1896 c = -1 when the 1st Cholesky factorization failed;
1897 c = -2 when the 2st Cholesky factorization failed.
1898 c
1899 c Subprograms called:
1900 c
1901 c Linpack ... dcopy, dpofa, dtrsl.
1902 c
1903 c
1904 c References:
1905 c [1] R. H. Byrd, P. Lu, J. Nocedal and C. Zhu, ``A limited
1906 c memory algorithm for bound constrained optimization'',
1907 c SIAM J. Scientific Computing 16 (1995), no. 5, pp. 1190--1208.
1908 c
1909 c [2] C. Zhu, R.H. Byrd, P. Lu, J. Nocedal, ``L-BFGS-B: a
1910 c limited memory FORTRAN code for solving bound constrained
1911 c optimization problems'', Tech. Report, NAM-11, EECS Department,
1912 c Northwestern University, 1994.
1913 c
1914 c (Postscript files of these papers are available via anonymous
1915 c ftp to eecs.nwu.edu in the directory pub/lbfgs/lbfgs_bcm.)
1916 c
1917 c * * *
1918 c
1919 c NEOS, November 1994. (Latest revision June 1996.)
1920 c Optimization Technology Center.
1921 c Argonne National Laboratory and Northwestern University.
1922 c Written by
1923 c Ciyou Zhu
1924 c in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal.
1925 c
1926 c
1927 c ************
1928
1929 integer m2,ipntr,jpntr,iy,is,jy,js,is1,js1,k1,i,k,
1930 + col2,pbegin,pend,dbegin,dend,upcl
1931 double precision ddot,temp1,temp2,temp3,temp4
1932 double precision one,zero
1933 parameter (one=1.0d0,zero=0.0d0)
1934
1935 c Form the lower triangular part of
1936 c WN1 = [Y' ZZ'Y L_a'+R_z']
1937 c [L_a+R_z S'AA'S ]
1938 c where L_a is the strictly lower triangular part of S'AA'Y
1939 c R_z is the upper triangular part of S'ZZ'Y.
1940
1941 if (updatd) then
1942 if (iupdat .gt. m) then
1943 c shift old part of WN1.
1944 do 10 jy = 1, m - 1
1945 js = m + jy
1946 call dcopy(m-jy,wn1(jy+1,jy+1),1,wn1(jy,jy),1)
1947 call dcopy(m-jy,wn1(js+1,js+1),1,wn1(js,js),1)
1948 call dcopy(m-1,wn1(m+2,jy+1),1,wn1(m+1,jy),1)
1949 10 continue
1950 endif
1951
1952 c put new rows in blocks (1,1), (2,1) and (2,2).
1953 pbegin = 1
1954 pend = nsub
1955 dbegin = nsub + 1
1956 dend = n
1957 iy = col
1958 is = m + col
1959 ipntr = head + col - 1
1960 if (ipntr .gt. m) ipntr = ipntr - m
1961 jpntr = head
1962 do 20 jy = 1, col
1963 js = m + jy
1964 temp1 = zero
1965 temp2 = zero
1966 temp3 = zero
1967 c compute element jy of row 'col' of Y'ZZ'Y
1968 do 15 k = pbegin, pend
1969 k1 = ind(k)
1970 temp1 = temp1 + wy(k1,ipntr)*wy(k1,jpntr)
1971 15 continue
1972 c compute elements jy of row 'col' of L_a and S'AA'S
1973 do 16 k = dbegin, dend
1974 k1 = ind(k)
1975 temp2 = temp2 + ws(k1,ipntr)*ws(k1,jpntr)
1976 temp3 = temp3 + ws(k1,ipntr)*wy(k1,jpntr)
1977 16 continue
1978 wn1(iy,jy) = temp1
1979 wn1(is,js) = temp2
1980 wn1(is,jy) = temp3
1981 jpntr = mod(jpntr,m) + 1
1982 20 continue
1983
1984 c put new column in block (2,1).
1985 jy = col
1986 jpntr = head + col - 1
1987 if (jpntr .gt. m) jpntr = jpntr - m
1988 ipntr = head
1989 do 30 i = 1, col
1990 is = m + i
1991 temp3 = zero
1992 c compute element i of column 'col' of R_z
1993 do 25 k = pbegin, pend
1994 k1 = ind(k)
1995 temp3 = temp3 + ws(k1,ipntr)*wy(k1,jpntr)
1996 25 continue
1997 ipntr = mod(ipntr,m) + 1
1998 wn1(is,jy) = temp3
1999 30 continue
2000 upcl = col - 1
2001 else
2002 upcl = col
2003 endif
2004
2005 c modify the old parts in blocks (1,1) and (2,2) due to changes
2006 c in the set of free variables.
2007 ipntr = head
2008 do 45 iy = 1, upcl
2009 is = m + iy
2010 jpntr = head
2011 do 40 jy = 1, iy
2012 js = m + jy
2013 temp1 = zero
2014 temp2 = zero
2015 temp3 = zero
2016 temp4 = zero
2017 do 35 k = 1, nenter
2018 k1 = indx2(k)
2019 temp1 = temp1 + wy(k1,ipntr)*wy(k1,jpntr)
2020 temp2 = temp2 + ws(k1,ipntr)*ws(k1,jpntr)
2021 35 continue
2022 do 36 k = ileave, n
2023 k1 = indx2(k)
2024 temp3 = temp3 + wy(k1,ipntr)*wy(k1,jpntr)
2025 temp4 = temp4 + ws(k1,ipntr)*ws(k1,jpntr)
2026 36 continue
2027 wn1(iy,jy) = wn1(iy,jy) + temp1 - temp3
2028 wn1(is,js) = wn1(is,js) - temp2 + temp4
2029 jpntr = mod(jpntr,m) + 1
2030 40 continue
2031 ipntr = mod(ipntr,m) + 1
2032 45 continue
2033
2034 c modify the old parts in block (2,1).
2035 ipntr = head
2036 do 60 is = m + 1, m + upcl
2037 jpntr = head
2038 do 55 jy = 1, upcl
2039 temp1 = zero
2040 temp3 = zero
2041 do 50 k = 1, nenter
2042 k1 = indx2(k)
2043 temp1 = temp1 + ws(k1,ipntr)*wy(k1,jpntr)
2044 50 continue
2045 do 51 k = ileave, n
2046 k1 = indx2(k)
2047 temp3 = temp3 + ws(k1,ipntr)*wy(k1,jpntr)
2048 51 continue
2049 if (is .le. jy + m) then
2050 wn1(is,jy) = wn1(is,jy) + temp1 - temp3
2051 else
2052 wn1(is,jy) = wn1(is,jy) - temp1 + temp3
2053 endif
2054 jpntr = mod(jpntr,m) + 1
2055 55 continue
2056 ipntr = mod(ipntr,m) + 1
2057 60 continue
2058
2059 c Form the upper triangle of WN = [D+Y' ZZ'Y/theta -L_a'+R_z' ]
2060 c [-L_a +R_z S'AA'S*theta]
2061
2062 m2 = 2*m
2063 do 70 iy = 1, col
2064 is = col + iy
2065 is1 = m + iy
2066 do 65 jy = 1, iy
2067 js = col + jy
2068 js1 = m + jy
2069 wn(jy,iy) = wn1(iy,jy)/theta
2070 wn(js,is) = wn1(is1,js1)*theta
2071 65 continue
2072 do 66 jy = 1, iy - 1
2073 wn(jy,is) = -wn1(is1,jy)
2074 66 continue
2075 do 67 jy = iy, col
2076 wn(jy,is) = wn1(is1,jy)
2077 67 continue
2078 wn(iy,iy) = wn(iy,iy) + sy(iy,iy)
2079 70 continue
2080
2081 c Form the upper triangle of WN= [ LL' L^-1(-L_a'+R_z')]
2082 c [(-L_a +R_z)L'^-1 S'AA'S*theta ]
2083
2084 c first Cholesky factor (1,1) block of wn to get LL'
2085 c with L' stored in the upper triangle of wn.
2086 call dpofa(wn,m2,col,info)
2087 if (info .ne. 0) then
2088 info = -1
2089 return
2090 endif
2091 c then form L^-1(-L_a'+R_z') in the (1,2) block.
2092 col2 = 2*col
2093 do 71 js = col+1 ,col2
2094 call dtrsl(wn,m2,col,wn(1,js),11,info)
2095 71 continue
2096
2097 c Form S'AA'S*theta + (L^-1(-L_a'+R_z'))'L^-1(-L_a'+R_z') in the
2098 c upper triangle of (2,2) block of wn.
2099
2100
2101 do 72 is = col+1, col2
2102 do 74 js = is, col2
2103 wn(is,js) = wn(is,js) + ddot(col,wn(1,is),1,wn(1,js),1)
2104 74 continue
2105 72 continue
2106
2107 c Cholesky factorization of (2,2) block of wn.
2108
2109 call dpofa(wn(col+1,col+1),m2,col,info)
2110 if (info .ne. 0) then
2111 info = -2
2112 return
2113 endif
2114
2115 return
2116
2117 end
2118
2119 c======================= The end of formk ==============================
2120
2121 subroutine formt(m, wt, sy, ss, col, theta, info)
2122
2123 integer m, col, info
2124 double precision theta, wt(m, m), sy(m, m), ss(m, m)
2125
2126 c ************
2127 c
2128 c Subroutine formt
2129 c
2130 c This subroutine forms the upper half of the pos. def. and symm.
2131 c T = theta*SS + L*D^(-1)*L', stores T in the upper triangle
2132 c of the array wt, and performs the Cholesky factorization of T
2133 c to produce J*J', with J' stored in the upper triangle of wt.
2134 c
2135 c Subprograms called:
2136 c
2137 c Linpack ... dpofa.
2138 c
2139 c
2140 c * * *
2141 c
2142 c NEOS, November 1994. (Latest revision June 1996.)
2143 c Optimization Technology Center.
2144 c Argonne National Laboratory and Northwestern University.
2145 c Written by
2146 c Ciyou Zhu
2147 c in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal.
2148 c
2149 c
2150 c ************
2151
2152 integer i,j,k,k1
2153 double precision ddum
2154 double precision zero
2155 parameter (zero=0.0d0)
2156
2157
2158 c Form the upper half of T = theta*SS + L*D^(-1)*L',
2159 c store T in the upper triangle of the array wt.
2160
2161 do 52 j = 1, col
2162 wt(1,j) = theta*ss(1,j)
2163 52 continue
2164 do 55 i = 2, col
2165 do 54 j = i, col
2166 k1 = min(i,j) - 1
2167 ddum = zero
2168 do 53 k = 1, k1
2169 ddum = ddum + sy(i,k)*sy(j,k)/sy(k,k)
2170 53 continue
2171 wt(i,j) = ddum + theta*ss(i,j)
2172 54 continue
2173 55 continue
2174
2175 c Cholesky factorize T to J*J' with
2176 c J' stored in the upper triangle of wt.
2177
2178 call dpofa(wt,m,col,info)
2179 if (info .ne. 0) then
2180 info = -3
2181 endif
2182
2183 return
2184
2185 end
2186
2187 c======================= The end of formt ==============================
2188
2189 subroutine freev(n, nfree, index, nenter, ileave, indx2,
2190 + iwhere, wrk, updatd, cnstnd, iprint, iter)
2191
2192 integer n, nfree, nenter, ileave, iprint, iter,
2193 + index(n), indx2(n), iwhere(n)
2194 logical wrk, updatd, cnstnd
2195
2196 c ************
2197 c
2198 c Subroutine freev
2199 c
2200 c This subroutine counts the entering and leaving variables when
2201 c iter > 0, and finds the index set of free and active variables
2202 c at the GCP.
2203 c
2204 c cnstnd is a logical variable indicating whether bounds are present
2205 c
2206 c index is an integer array of dimension n
2207 c for i=1,...,nfree, index(i) are the indices of free variables
2208 c for i=nfree+1,...,n, index(i) are the indices of bound variables
2209 c On entry after the first iteration, index gives
2210 c the free variables at the previous iteration.
2211 c On exit it gives the free variables based on the determination
2212 c in cauchy using the array iwhere.
2213 c
2214 c indx2 is an integer array of dimension n
2215 c On entry indx2 is unspecified.
2216 c On exit with iter>0, indx2 indicates which variables
2217 c have changed status since the previous iteration.
2218 c For i= 1,...,nenter, indx2(i) have changed from bound to free.
2219 c For i= ileave+1,...,n, indx2(i) have changed from free to bound.
2220 c
2221 c
2222 c * * *
2223 c
2224 c NEOS, November 1994. (Latest revision June 1996.)
2225 c Optimization Technology Center.
2226 c Argonne National Laboratory and Northwestern University.
2227 c Written by
2228 c Ciyou Zhu
2229 c in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal.
2230 c
2231 c
2232 c ************
2233
2234 integer iact,i,k
2235
2236 nenter = 0
2237 ileave = n + 1
2238 if (iter .gt. 0 .and. cnstnd) then
2239 c count the entering and leaving variables.
2240 do 20 i = 1, nfree
2241 k = index(i)
2242 if (iwhere(k) .gt. 0) then
2243 ileave = ileave - 1
2244 indx2(ileave) = k
2245 if (iprint .ge. 100) write (6,*)
2246 + 'Variable ',k,' leaves the set of free variables'
2247 endif
2248 20 continue
2249 do 22 i = 1 + nfree, n
2250 k = index(i)
2251 if (iwhere(k) .le. 0) then
2252 nenter = nenter + 1
2253 indx2(nenter) = k
2254 if (iprint .ge. 100) write (6,*)
2255 + 'Variable ',k,' enters the set of free variables'
2256 endif
2257 22 continue
2258 if (iprint .ge. 99) write (6,*)
2259 + n+1-ileave,' variables leave; ',nenter,' variables enter'
2260 endif
2261 wrk = (ileave .lt. n+1) .or. (nenter .gt. 0) .or. updatd
2262
2263 c Find the index set of free and active variables at the GCP.
2264
2265 nfree = 0
2266 iact = n + 1
2267 do 24 i = 1, n
2268 if (iwhere(i) .le. 0) then
2269 nfree = nfree + 1
2270 index(nfree) = i
2271 else
2272 iact = iact - 1
2273 index(iact) = i
2274 endif
2275 24 continue
2276 if (iprint .ge. 99) write (6,*)
2277 + nfree,' variables are free at GCP ',iter + 1
2278
2279 return
2280
2281 end
2282
2283 c======================= The end of freev ==============================
2284
2285 subroutine hpsolb(n, t, iorder, iheap)
2286 integer iheap, n, iorder(n)
2287 double precision t(n)
2288
2289 c ************
2290 c
2291 c Subroutine hpsolb
2292 c
2293 c This subroutine sorts out the least element of t, and puts the
2294 c remaining elements of t in a heap.
2295 c
2296 c n is an integer variable.
2297 c On entry n is the dimension of the arrays t and iorder.
2298 c On exit n is unchanged.
2299 c
2300 c t is a double precision array of dimension n.
2301 c On entry t stores the elements to be sorted,
2302 c On exit t(n) stores the least elements of t, and t(1) to t(n-1)
2303 c stores the remaining elements in the form of a heap.
2304 c
2305 c iorder is an integer array of dimension n.
2306 c On entry iorder(i) is the index of t(i).
2307 c On exit iorder(i) is still the index of t(i), but iorder may be
2308 c permuted in accordance with t.
2309 c
2310 c iheap is an integer variable specifying the task.
2311 c On entry iheap should be set as follows:
2312 c iheap .eq. 0 if t(1) to t(n) is not in the form of a heap,
2313 c iheap .ne. 0 if otherwise.
2314 c On exit iheap is unchanged.
2315 c
2316 c
2317 c References:
2318 c Algorithm 232 of CACM (J. W. J. Williams): HEAPSORT.
2319 c
2320 c * * *
2321 c
2322 c NEOS, November 1994. (Latest revision June 1996.)
2323 c Optimization Technology Center.
2324 c Argonne National Laboratory and Northwestern University.
2325 c Written by
2326 c Ciyou Zhu
2327 c in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal.
2328 c
2329 c ************
2330
2331 integer i,j,k,indxin,indxou
2332 double precision ddum,out
2333
2334 if (iheap .eq. 0) then
2335
2336 c Rearrange the elements t(1) to t(n) to form a heap.
2337
2338 do 20 k = 2, n
2339 ddum = t(k)
2340 indxin = iorder(k)
2341
2342 c Add ddum to the heap.
2343 i = k
2344 10 continue
2345 if (i.gt.1) then
2346 j = i/2
2347 if (ddum .lt. t(j)) then
2348 t(i) = t(j)
2349 iorder(i) = iorder(j)
2350 i = j
2351 goto 10
2352 endif
2353 endif
2354 t(i) = ddum
2355 iorder(i) = indxin
2356 20 continue
2357 endif
2358
2359 c Assign to 'out' the value of t(1), the least member of the heap,
2360 c and rearrange the remaining members to form a heap as
2361 c elements 1 to n-1 of t.
2362
2363 if (n .gt. 1) then
2364 i = 1
2365 out = t(1)
2366 indxou = iorder(1)
2367 ddum = t(n)
2368 indxin = iorder(n)
2369
2370 c Restore the heap
2371 30 continue
2372 j = i+i
2373 if (j .le. n-1) then
2374 if (t(j+1) .lt. t(j)) j = j+1
2375 if (t(j) .lt. ddum ) then
2376 t(i) = t(j)
2377 iorder(i) = iorder(j)
2378 i = j
2379 goto 30
2380 endif
2381 endif
2382 t(i) = ddum
2383 iorder(i) = indxin
2384
2385 c Put the least member in t(n).
2386
2387 t(n) = out
2388 iorder(n) = indxou
2389 endif
2390
2391 return
2392
2393 end
2394
2395 c====================== The end of hpsolb ==============================
2396
2397 subroutine lnsrlb(n, l, u, nbd, x, f, fold, gd, gdold, g, d, r, t,
2398 + z, stp, dnorm, dtd, xstep, stpmx, iter, ifun,
2399 + iback, nfgv, info, task, boxed, cnstnd, csave,
2400 + isave, dsave)
2401
2402 character*60 task, csave
2403 logical boxed, cnstnd
2404 integer n, iter, ifun, iback, nfgv, info,
2405 + nbd(n), isave(2)
2406 double precision f, fold, gd, gdold, stp, dnorm, dtd, xstep,
2407 + stpmx, x(n), l(n), u(n), g(n), d(n), r(n), t(n),
2408 + z(n), dsave(13)
2409 c **********
2410 c
2411 c Subroutine lnsrlb
2412 c
2413 c This subroutine calls subroutine dcsrch from the Minpack2 library
2414 c to perform the line search. Subroutine dscrch is safeguarded so
2415 c that all trial points lie within the feasible region.
2416 c
2417 c Subprograms called:
2418 c
2419 c Minpack2 Library ... dcsrch.
2420 c
2421 c Linpack ... dtrsl, ddot.
2422 c
2423 c
2424 c * * *
2425 c
2426 c NEOS, November 1994. (Latest revision June 1996.)
2427 c Optimization Technology Center.
2428 c Argonne National Laboratory and Northwestern University.
2429 c Written by
2430 c Ciyou Zhu
2431 c in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal.
2432 c
2433 c
2434 c **********
2435
2436 integer i
2437 double precision ddot,a1,a2
2438 double precision one,zero,big
2439 parameter (one=1.0d0,zero=0.0d0,big=1.0d+10)
2440 double precision ftol,gtol,xtol
2441 parameter (ftol=1.0d-3,gtol=0.9d0,xtol=0.1d0)
2442
2443 if (task(1:5) .eq. 'FG_LN') goto 556
2444
2445 dtd = ddot(n,d,1,d,1)
2446 dnorm = sqrt(dtd)
2447
2448 c Determine the maximum step length.
2449
2450 stpmx = big
2451 if (cnstnd) then
2452 if (iter .eq. 0) then
2453 stpmx = one
2454 else
2455 do 43 i = 1, n
2456 a1 = d(i)
2457 if (nbd(i) .ne. 0) then
2458 if (a1 .lt. zero .and. nbd(i) .le. 2) then
2459 a2 = l(i) - x(i)
2460 if (a2 .ge. zero) then
2461 stpmx = zero
2462 else if (a1*stpmx .lt. a2) then
2463 stpmx = a2/a1
2464 endif
2465 else if (a1 .gt. zero .and. nbd(i) .ge. 2) then
2466 a2 = u(i) - x(i)
2467 if (a2 .le. zero) then
2468 stpmx = zero
2469 else if (a1*stpmx .gt. a2) then
2470 stpmx = a2/a1
2471 endif
2472 endif
2473 endif
2474 43 continue
2475 endif
2476 endif
2477
2478 if (iter .eq. 0 .and. .not. boxed) then
2479 stp = min(one/dnorm, stpmx)
2480 else
2481 stp = one
2482 endif
2483
2484 call dcopy(n,x,1,t,1)
2485 call dcopy(n,g,1,r,1)
2486 fold = f
2487 ifun = 0
2488 iback = 0
2489 csave = 'START'
2490 556 continue
2491 gd = ddot(n,g,1,d,1)
2492 if (ifun .eq. 0) then
2493 gdold=gd
2494 if (gd .ge. zero) then
2495 c the directional derivative >=0.
2496 c Line search is impossible.
2497 info = -4
2498 return
2499 endif
2500 endif
2501
2502 call dcsrch(f,gd,stp,ftol,gtol,xtol,zero,stpmx,csave,isave,dsave)
2503
2504 xstep = stp*dnorm
2505 if (csave(1:4) .ne. 'CONV' .and. csave(1:4) .ne. 'WARN') then
2506 task = 'FG_LNSRCH'
2507 ifun = ifun + 1
2508 nfgv = nfgv + 1
2509 iback = ifun - 1
2510 if (stp .eq. one) then
2511 call dcopy(n,z,1,x,1)
2512 else
2513 do 41 i = 1, n
2514 x(i) = stp*d(i) + t(i)
2515 41 continue
2516 endif
2517 else
2518 task = 'NEW_X'
2519 endif
2520
2521 return
2522
2523 end
2524
2525 c======================= The end of lnsrlb =============================
2526
2527 subroutine matupd(n, m, ws, wy, sy, ss, d, r, itail,
2528 + iupdat, col, head, theta, rr, dr, stp, dtd)
2529
2530 integer n, m, itail, iupdat, col, head
2531 double precision theta, rr, dr, stp, dtd, d(n), r(n),
2532 + ws(n, m), wy(n, m), sy(m, m), ss(m, m)
2533
2534 c ************
2535 c
2536 c Subroutine matupd
2537 c
2538 c This subroutine updates matrices WS and WY, and forms the
2539 c middle matrix in B.
2540 c
2541 c Subprograms called:
2542 c
2543 c Linpack ... dcopy, ddot.
2544 c
2545 c
2546 c * * *
2547 c
2548 c NEOS, November 1994. (Latest revision June 1996.)
2549 c Optimization Technology Center.
2550 c Argonne National Laboratory and Northwestern University.
2551 c Written by
2552 c Ciyou Zhu
2553 c in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal.
2554 c
2555 c
2556 c ************
2557
2558 integer j,pointr
2559 double precision ddot
2560 double precision one
2561 parameter (one=1.0d0)
2562
2563 c Set pointers for matrices WS and WY.
2564
2565 if (iupdat .le. m) then
2566 col = iupdat
2567 itail = mod(head+iupdat-2,m) + 1
2568 else
2569 itail = mod(itail,m) + 1
2570 head = mod(head,m) + 1
2571 endif
2572
2573 c Update matrices WS and WY.
2574
2575 call dcopy(n,d,1,ws(1,itail),1)
2576 call dcopy(n,r,1,wy(1,itail),1)
2577
2578 c Set theta=yy/ys.
2579
2580 theta = rr/dr
2581
2582 c Form the middle matrix in B.
2583
2584 c update the upper triangle of SS,
2585 c and the lower triangle of SY:
2586 if (iupdat .gt. m) then
2587 c move old information
2588 do 50 j = 1, col - 1
2589 call dcopy(j,ss(2,j+1),1,ss(1,j),1)
2590 call dcopy(col-j,sy(j+1,j+1),1,sy(j,j),1)
2591 50 continue
2592 endif
2593 c add new information: the last row of SY
2594 c and the last column of SS:
2595 pointr = head
2596 do 51 j = 1, col - 1
2597 sy(col,j) = ddot(n,d,1,wy(1,pointr),1)
2598 ss(j,col) = ddot(n,ws(1,pointr),1,d,1)
2599 pointr = mod(pointr,m) + 1
2600 51 continue
2601 if (stp .eq. one) then
2602 ss(col,col) = dtd
2603 else
2604 ss(col,col) = stp*stp*dtd
2605 endif
2606 sy(col,col) = dr
2607
2608 return
2609
2610 end
2611
2612 c======================= The end of matupd =============================
2613
2614 subroutine prn1lb(n, m, l, u, x, iprint, itfile, epsmch)
2615
2616 integer n, m, iprint, itfile
2617 double precision epsmch, x(n), l(n), u(n)
2618
2619 c ************
2620 c
2621 c Subroutine prn1lb
2622 c
2623 c This subroutine prints the input data, initial point, upper and
2624 c lower bounds of each variable, machine precision, as well as
2625 c the headings of the output.
2626 c
2627 c
2628 c * * *
2629 c
2630 c NEOS, November 1994. (Latest revision June 1996.)
2631 c Optimization Technology Center.
2632 c Argonne National Laboratory and Northwestern University.
2633 c Written by
2634 c Ciyou Zhu
2635 c in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal.
2636 c
2637 c
2638 c ************
2639
2640 integer i
2641
2642 if (iprint .ge. 0) then
2643 write (6,7001) epsmch
2644 write (6,*) 'N = ',n,' M = ',m
2645 if (iprint .ge. 1) then
2646 write (itfile,2001) epsmch
2647 write (itfile,*)'N = ',n,' M = ',m
2648 write (itfile,9001)
2649 if (iprint .gt. 100) then
2650 write (6,1004) 'L =',(l(i),i = 1,n)
2651 write (6,1004) 'X0 =',(x(i),i = 1,n)
2652 write (6,1004) 'U =',(u(i),i = 1,n)
2653 endif
2654 endif
2655 endif
2656
2657 1004 format (/,a4, 1p, 6(1x,d11.4),/,(4x,1p,6(1x,d11.4)))
2658 2001 format ('RUNNING THE L-BFGS-B CODE',/,/,
2659 + 'it = iteration number',/,
2660 + 'nf = number of function evaluations',/,
2661 + 'nint = number of segments explored during the Cauchy search',/,
2662 + 'nact = number of active bounds at the generalized Cauchy point'
2663 + ,/,
2664 + 'sub = manner in which the subspace minimization terminated:'
2665 + ,/,' con = converged, bnd = a bound was reached',/,
2666 + 'itls = number of iterations performed in the line search',/,
2667 + 'stepl = step length used',/,
2668 + 'tstep = norm of the displacement (total step)',/,
2669 + 'projg = norm of the projected gradient',/,
2670 + 'f = function value',/,/,
2671 + ' * * *',/,/,
2672 + 'Machine precision =',1p,d10.3)
2673 7001 format ('RUNNING THE L-BFGS-B CODE',/,/,
2674 + ' * * *',/,/,
2675 + 'Machine precision =',1p,d10.3)
2676 9001 format (/,3x,'it',3x,'nf',2x,'nint',2x,'nact',2x,'sub',2x,'itls',
2677 + 2x,'stepl',4x,'tstep',5x,'projg',8x,'f')
2678
2679 return
2680
2681 end
2682
2683 c======================= The end of prn1lb =============================
2684
2685 subroutine prn2lb(n, x, f, g, iprint, itfile, iter, nfgv, nact,
2686 + sbgnrm, nint, word, iword, iback, stp, xstep)
2687
2688 character*3 word
2689 integer n, iprint, itfile, iter, nfgv, nact, nint,
2690 + iword, iback
2691 double precision f, sbgnrm, stp, xstep, x(n), g(n)
2692
2693 c ************
2694 c
2695 c Subroutine prn2lb
2696 c
2697 c This subroutine prints out new information after a successful
2698 c line search.
2699 c
2700 c
2701 c * * *
2702 c
2703 c NEOS, November 1994. (Latest revision June 1996.)
2704 c Optimization Technology Center.
2705 c Argonne National Laboratory and Northwestern University.
2706 c Written by
2707 c Ciyou Zhu
2708 c in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal.
2709 c
2710 c
2711 c ************
2712
2713 integer i,imod
2714
2715 c 'word' records the status of subspace solutions.
2716 if (iword .eq. 0) then
2717 c the subspace minimization converged.
2718 word = 'con'
2719 else if (iword .eq. 1) then
2720 c the subspace minimization stopped at a bound.
2721 word = 'bnd'
2722 else if (iword .eq. 5) then
2723 c the truncated Newton step has been used.
2724 word = 'TNT'
2725 else
2726 word = '---'
2727 endif
2728 if (iprint .ge. 99) then
2729 write (6,*) 'LINE SEARCH',iback,' times; norm of step = ',xstep
2730 write (6,2001) iter,f,sbgnrm
2731 if (iprint .gt. 100) then
2732 write (6,1004) 'X =',(x(i), i = 1, n)
2733 write (6,1004) 'G =',(g(i), i = 1, n)
2734 endif
2735 else if (iprint .gt. 0) then
2736 imod = mod(iter,iprint)
2737 if (imod .eq. 0) write (6,2001) iter,f,sbgnrm
2738 endif
2739 if (iprint .ge. 1) write (itfile,3001)
2740 + iter,nfgv,nint,nact,word,iback,stp,xstep,sbgnrm,f
2741
2742 1004 format (/,a4, 1p, 6(1x,d11.4),/,(4x,1p,6(1x,d11.4)))
2743 2001 format
2744 + (/,'At iterate',i5,4x,'f= ',1p,d12.5,4x,'|proj g|= ',1p,d12.5)
2745 3001 format(2(1x,i4),2(1x,i5),2x,a3,1x,i4,1p,2(2x,d7.1),1p,2(1x,d10.3))
2746
2747 return
2748
2749 end
2750
2751 c======================= The end of prn2lb =============================
2752
2753 subroutine prn3lb(n, x, f, task, iprint, info, itfile,
2754 + iter, nfgv, nintol, nskip, nact, sbgnrm,
2755 + time, nint, word, iback, stp, xstep, k,
2756 + cachyt, sbtime, lnscht)
2757
2758 character*60 task
2759 character*3 word
2760 integer n, iprint, info, itfile, iter, nfgv, nintol,
2761 + nskip, nact, nint, iback, k
2762 double precision f, sbgnrm, time, stp, xstep, cachyt, sbtime,
2763 + lnscht, x(n)
2764
2765 c ************
2766 c
2767 c Subroutine prn3lb
2768 c
2769 c This subroutine prints out information when either a built-in
2770 c convergence test is satisfied or when an error message is
2771 c generated.
2772 c
2773 c
2774 c * * *
2775 c
2776 c NEOS, November 1994. (Latest revision June 1996.)
2777 c Optimization Technology Center.
2778 c Argonne National Laboratory and Northwestern University.
2779 c Written by
2780 c Ciyou Zhu
2781 c in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal.
2782 c
2783 c
2784 c ************
2785
2786 integer i
2787
2788 if (task(1:5) .eq. 'ERROR') goto 999
2789
2790 if (iprint .ge. 0) then
2791 write (6,3003)
2792 write (6,3004)
2793 write(6,3005) n,iter,nfgv,nintol,nskip,nact,sbgnrm,f
2794 if (iprint .ge. 100) then
2795 write (6,1004) 'X =',(x(i),i = 1,n)
2796 endif
2797 if (iprint .ge. 1) write (6,*) ' F =',f
2798 endif
2799 999 continue
2800 if (iprint .ge. 0) then
2801 write (6,3009) task
2802 if (info .ne. 0) then
2803 if (info .eq. -1) write (6,9011)
2804 if (info .eq. -2) write (6,9012)
2805 if (info .eq. -3) write (6,9013)
2806 if (info .eq. -4) write (6,9014)
2807 if (info .eq. -5) write (6,9015)
2808 if (info .eq. -6) write (6,*)' Input nbd(',k,') is invalid.'
2809 if (info .eq. -7)
2810 + write (6,*)' l(',k,') > u(',k,'). No feasible solution.'
2811 if (info .eq. -8) write (6,9018)
2812 if (info .eq. -9) write (6,9019)
2813 endif
2814 if (iprint .ge. 1) write (6,3007) cachyt,sbtime,lnscht
2815 write (6,3008) time
2816 if (iprint .ge. 1) then
2817 if (info .eq. -4 .or. info .eq. -9) then
2818 write (itfile,3002)
2819 + iter,nfgv,nint,nact,word,iback,stp,xstep
2820 endif
2821 write (itfile,3009) task
2822 if (info .ne. 0) then
2823 if (info .eq. -1) write (itfile,9011)
2824 if (info .eq. -2) write (itfile,9012)
2825 if (info .eq. -3) write (itfile,9013)
2826 if (info .eq. -4) write (itfile,9014)
2827 if (info .eq. -5) write (itfile,9015)
2828 if (info .eq. -8) write (itfile,9018)
2829 if (info .eq. -9) write (itfile,9019)
2830 endif
2831 write (itfile,3008) time
2832 endif
2833 endif
2834
2835 1004 format (/,a4, 1p, 6(1x,d11.4),/,(4x,1p,6(1x,d11.4)))
2836 3002 format(2(1x,i4),2(1x,i5),2x,a3,1x,i4,1p,2(2x,d7.1),6x,'-',10x,'-')
2837 3003 format (/,
2838 + ' * * *',/,/,
2839 + 'Tit = total number of iterations',/,
2840 + 'Tnf = total number of function evaluations',/,
2841 + 'Tnint = total number of segments explored during',
2842 + ' Cauchy searches',/,
2843 + 'Skip = number of BFGS updates skipped',/,
2844 + 'Nact = number of active bounds at final generalized',
2845 + ' Cauchy point',/,
2846 + 'Projg = norm of the final projected gradient',/,
2847 + 'F = final function value',/,/,
2848 + ' * * *')
2849 3004 format (/,3x,'N',3x,'Tit',2x,'Tnf',2x,'Tnint',2x,
2850 + 'Skip',2x,'Nact',5x,'Projg',8x,'F')
2851 3005 format (i5,2(1x,i4),(1x,i6),(2x,i4),(1x,i5),1p,2(2x,d10.3))
2852 3006 format (i5,2(1x,i4),2(1x,i6),(1x,i4),(1x,i5),7x,'-',10x,'-')
2853 3007 format (/,' Cauchy time',1p,e10.3,' seconds.',/
2854 + ' Subspace minimization time',1p,e10.3,' seconds.',/
2855 + ' Line search time',1p,e10.3,' seconds.')
2856 3008 format (/,' Total User time',1p,e10.3,' seconds.',/)
2857 3009 format (/,a60)
2858 9011 format (/,
2859 +' Matrix in 1st Cholesky factorization in formk is not Pos. Def.')
2860 9012 format (/,
2861 +' Matrix in 2st Cholesky factorization in formk is not Pos. Def.')
2862 9013 format (/,
2863 +' Matrix in the Cholesky factorization in formt is not Pos. Def.')
2864 9014 format (/,
2865 +' Derivative >= 0, backtracking line search impossible.',/,
2866 +' Previous x, f and g restored.',/,
2867 +' Possible causes: 1 error in function or gradient evaluation;',/,
2868 +' 2 rounding errors dominate computation.')
2869 9015 format (/,
2870 +' Warning: more than 10 function and gradient',/,
2871 +' evaluations in the last line search. Termination',/,
2872 +' may possibly be caused by a bad search direction.')
2873 9018 format (/,' The triangular system is singular.')
2874 9019 format (/,
2875 +' Line search cannot locate an adequate point after 20 function',/
2876 +,' and gradient evaluations. Previous x, f and g restored.',/,
2877 +' Possible causes: 1 error in function or gradient evaluation;',/,
2878 +' 2 rounding error dominate computation.')
2879
2880 return
2881
2882 end
2883
2884 c======================= The end of prn3lb =============================
2885
2886 subroutine projgr(n, l, u, nbd, x, g, sbgnrm)
2887
2888 integer n, nbd(n)
2889 double precision sbgnrm, x(n), l(n), u(n), g(n)
2890
2891 c ************
2892 c
2893 c Subroutine projgr
2894 c
2895 c This subroutine computes the infinity norm of the projected
2896 c gradient.
2897 c
2898 c
2899 c * * *
2900 c
2901 c NEOS, November 1994. (Latest revision June 1996.)
2902 c Optimization Technology Center.
2903 c Argonne National Laboratory and Northwestern University.
2904 c Written by
2905 c Ciyou Zhu
2906 c in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal.
2907 c
2908 c
2909 c ************
2910
2911 integer i
2912 double precision gi
2913 double precision one,zero
2914 parameter (one=1.0d0,zero=0.0d0)
2915
2916 sbgnrm = zero
2917 do 15 i = 1, n
2918 gi = g(i)
2919 if (nbd(i) .ne. 0) then
2920 if (gi .lt. zero) then
2921 if (nbd(i) .ge. 2) gi = max((x(i)-u(i)),gi)
2922 else
2923 if (nbd(i) .le. 2) gi = min((x(i)-l(i)),gi)
2924 endif
2925 endif
2926 sbgnrm = max(sbgnrm,abs(gi))
2927 15 continue
2928
2929 return
2930
2931 end
2932
2933 c======================= The end of projgr =============================
2934
2935 subroutine subsm(n, m, nsub, ind, l, u, nbd, x, d, ws, wy, theta,
2936 + col, head, iword, wv, wn, iprint, info)
2937
2938 integer n, m, nsub, col, head, iword, iprint, info,
2939 + ind(nsub), nbd(n)
2940 double precision theta,
2941 + l(n), u(n), x(n), d(n),
2942 + ws(n, m), wy(n, m),
2943 + wv(2*m), wn(2*m, 2*m)
2944
2945 c ************
2946 c
2947 c Subroutine subsm
2948 c
2949 c Given xcp, l, u, r, an index set that specifies
2950 c the active set at xcp, and an l-BFGS matrix B
2951 c (in terms of WY, WS, SY, WT, head, col, and theta),
2952 c this subroutine computes an approximate solution
2953 c of the subspace problem
2954 c
2955 c (P) min Q(x) = r'(x-xcp) + 1/2 (x-xcp)' B (x-xcp)
2956 c
2957 c subject to l<=x<=u
2958 c x_i=xcp_i for all i in A(xcp)
2959 c
2960 c along the subspace unconstrained Newton direction
2961 c
2962 c d = -(Z'BZ)^(-1) r.
2963 c
2964 c The formula for the Newton direction, given the L-BFGS matrix
2965 c and the Sherman-Morrison formula, is
2966 c
2967 c d = (1/theta)r + (1/theta*2) Z'WK^(-1)W'Z r.
2968 c
2969 c where
2970 c K = [-D -Y'ZZ'Y/theta L_a'-R_z' ]
2971 c [L_a -R_z theta*S'AA'S ]
2972 c
2973 c Note that this procedure for computing d differs
2974 c from that described in [1]. One can show that the matrix K is
2975 c equal to the matrix M^[-1]N in that paper.
2976 c
2977 c n is an integer variable.
2978 c On entry n is the dimension of the problem.
2979 c On exit n is unchanged.
2980 c
2981 c m is an integer variable.
2982 c On entry m is the maximum number of variable metric corrections
2983 c used to define the limited memory matrix.
2984 c On exit m is unchanged.
2985 c
2986 c nsub is an integer variable.
2987 c On entry nsub is the number of free variables.
2988 c On exit nsub is unchanged.
2989 c
2990 c ind is an integer array of dimension nsub.
2991 c On entry ind specifies the coordinate indices of free variables.
2992 c On exit ind is unchanged.
2993 c
2994 c l is a double precision array of dimension n.
2995 c On entry l is the lower bound of x.
2996 c On exit l is unchanged.
2997 c
2998 c u is a double precision array of dimension n.
2999 c On entry u is the upper bound of x.
3000 c On exit u is unchanged.
3001 c
3002 c nbd is a integer array of dimension n.
3003 c On entry nbd represents the type of bounds imposed on the
3004 c variables, and must be specified as follows:
3005 c nbd(i)=0 if x(i) is unbounded,
3006 c 1 if x(i) has only a lower bound,
3007 c 2 if x(i) has both lower and upper bounds, and
3008 c 3 if x(i) has only an upper bound.
3009 c On exit nbd is unchanged.
3010 c
3011 c x is a double precision array of dimension n.
3012 c On entry x specifies the Cauchy point xcp.
3013 c On exit x(i) is the minimizer of Q over the subspace of
3014 c free variables.
3015 c
3016 c d is a double precision array of dimension n.
3017 c On entry d is the reduced gradient of Q at xcp.
3018 c On exit d is the Newton direction of Q.
3019 c
3020 c ws and wy are double precision arrays;
3021 c theta is a double precision variable;
3022 c col is an integer variable;
3023 c head is an integer variable.
3024 c On entry they store the information defining the
3025 c limited memory BFGS matrix:
3026 c ws(n,m) stores S, a set of s-vectors;
3027 c wy(n,m) stores Y, a set of y-vectors;
3028 c theta is the scaling factor specifying B_0 = theta I;
3029 c col is the number of variable metric corrections stored;
3030 c head is the location of the 1st s- (or y-) vector in S (or Y).
3031 c On exit they are unchanged.
3032 c
3033 c iword is an integer variable.
3034 c On entry iword is unspecified.
3035 c On exit iword specifies the status of the subspace solution.
3036 c iword = 0 if the solution is in the box,
3037 c 1 if some bound is encountered.
3038 c
3039 c wv is a double precision working array of dimension 2m.
3040 c
3041 c wn is a double precision array of dimension 2m x 2m.
3042 c On entry the upper triangle of wn stores the LEL^T factorization
3043 c of the indefinite matrix
3044 c
3045 c K = [-D -Y'ZZ'Y/theta L_a'-R_z' ]
3046 c [L_a -R_z theta*S'AA'S ]
3047 c where E = [-I 0]
3048 c [ 0 I]
3049 c On exit wn is unchanged.
3050 c
3051 c iprint is an INTEGER variable that must be set by the user.
3052 c It controls the frequency and type of output generated:
3053 c iprint<0 no output is generated;
3054 c iprint=0 print only one line at the last iteration;
3055 c 0<iprint<99 print also f and |proj g| every iprint iterations;
3056 c iprint=99 print details of every iteration except n-vectors;
3057 c iprint=100 print also the changes of active set and final x;
3058 c iprint>100 print details of every iteration including x and g;
3059 c When iprint > 0, the file iterate.dat will be created to
3060 c summarize the iteration.
3061 c
3062 c info is an integer variable.
3063 c On entry info is unspecified.
3064 c On exit info = 0 for normal return,
3065 c = nonzero for abnormal return
3066 c when the matrix K is ill-conditioned.
3067 c
3068 c Subprograms called:
3069 c
3070 c Linpack dtrsl.
3071 c
3072 c
3073 c References:
3074 c
3075 c [1] R. H. Byrd, P. Lu, J. Nocedal and C. Zhu, ``A limited
3076 c memory algorithm for bound constrained optimization'',
3077 c SIAM J. Scientific Computing 16 (1995), no. 5, pp. 1190--1208.
3078 c
3079 c
3080 c
3081 c * * *
3082 c
3083 c NEOS, November 1994. (Latest revision June 1996.)
3084 c Optimization Technology Center.
3085 c Argonne National Laboratory and Northwestern University.
3086 c Written by
3087 c Ciyou Zhu
3088 c in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal.
3089 c
3090 c
3091 c ************
3092
3093 integer pointr,m2,col2,ibd,jy,js,i,j,k
3094 double precision alpha,dk,temp1,temp2
3095 double precision one,zero
3096 parameter (one=1.0d0,zero=0.0d0)
3097
3098 if (nsub .le. 0) return
3099 if (iprint .ge. 99) write (6,1001)
3100
3101 c Compute wv = W'Zd.
3102
3103 pointr = head
3104 do 20 i = 1, col
3105 temp1 = zero
3106 temp2 = zero
3107 do 10 j = 1, nsub
3108 k = ind(j)
3109 temp1 = temp1 + wy(k,pointr)*d(j)
3110 temp2 = temp2 + ws(k,pointr)*d(j)
3111 10 continue
3112 wv(i) = temp1
3113 wv(col + i) = theta*temp2
3114 pointr = mod(pointr,m) + 1
3115 20 continue
3116
3117 c Compute wv:=K^(-1)wv.
3118
3119 m2 = 2*m
3120 col2 = 2*col
3121 call dtrsl(wn,m2,col2,wv,11,info)
3122 if (info .ne. 0) return
3123 do 25 i = 1, col
3124 wv(i) = -wv(i)
3125 25 continue
3126 call dtrsl(wn,m2,col2,wv,01,info)
3127 if (info .ne. 0) return
3128
3129 c Compute d = (1/theta)d + (1/theta**2)Z'W wv.
3130
3131 pointr = head
3132 do 40 jy = 1, col
3133 js = col + jy
3134 do 30 i = 1, nsub
3135 k = ind(i)
3136 d(i) = d(i) + wy(k,pointr)*wv(jy)/theta
3137 + + ws(k,pointr)*wv(js)
3138 30 continue
3139 pointr = mod(pointr,m) + 1
3140 40 continue
3141 do 50 i = 1, nsub
3142 d(i) = d(i)/theta
3143 50 continue
3144
3145 c Backtrack to the feasible region.
3146
3147 alpha = one
3148 temp1 = alpha
3149 do 60 i = 1, nsub
3150 k = ind(i)
3151 dk = d(i)
3152 if (nbd(k) .ne. 0) then
3153 if (dk .lt. zero .and. nbd(k) .le. 2) then
3154 temp2 = l(k) - x(k)
3155 if (temp2 .ge. zero) then
3156 temp1 = zero
3157 else if (dk*alpha .lt. temp2) then
3158 temp1 = temp2/dk
3159 endif
3160 else if (dk .gt. zero .and. nbd(k) .ge. 2) then
3161 temp2 = u(k) - x(k)
3162 if (temp2 .le. zero) then
3163 temp1 = zero
3164 else if (dk*alpha .gt. temp2) then
3165 temp1 = temp2/dk
3166 endif
3167 endif
3168 if (temp1 .lt. alpha) then
3169 alpha = temp1
3170 ibd = i
3171 endif
3172 endif
3173 60 continue
3174
3175 if (alpha .lt. one) then
3176 dk = d(ibd)
3177 k = ind(ibd)
3178 if (dk .gt. zero) then
3179 x(k) = u(k)
3180 d(ibd) = zero
3181 else if (dk .lt. zero) then
3182 x(k) = l(k)
3183 d(ibd) = zero
3184 endif
3185 endif
3186 do 70 i = 1, nsub
3187 k = ind(i)
3188 x(k) = x(k) + alpha*d(i)
3189 70 continue
3190
3191 if (iprint .ge. 99) then
3192 if (alpha .lt. one) then
3193 write (6,1002) alpha
3194 else
3195 write (6,*) 'SM solution inside the box'
3196 end if
3197 if (iprint .gt.100) write (6,1003) (x(i),i=1,n)
3198 endif
3199
3200 if (alpha .lt. one) then
3201 iword = 1
3202 else
3203 iword = 0
3204 endif
3205 if (iprint .ge. 99) write (6,1004)
3206
3207 1001 format (/,'----------------SUBSM entered-----------------',/)
3208 1002 format ( 'ALPHA = ',f7.5,' backtrack to the BOX')
3209 1003 format ('Subspace solution X = ',/,(4x,1p,6(1x,d11.4)))
3210 1004 format (/,'----------------exit SUBSM --------------------',/)
3211
3212 return
3213
3214 end
3215
3216 c====================== The end of subsm ===============================
3217
3218 subroutine dcsrch(f,g,stp,ftol,gtol,xtol,stpmin,stpmax,
3219 + task,isave,dsave)
3220 character*(*) task
3221 integer isave(2)
3222 double precision f,g,stp,ftol,gtol,xtol,stpmin,stpmax
3223 double precision dsave(13)
3224 c **********
3225 c
3226 c Subroutine dcsrch
3227 c
3228 c This subroutine finds a step that satisfies a sufficient
3229 c decrease condition and a curvature condition.
3230 c
3231 c Each call of the subroutine updates an interval with
3232 c endpoints stx and sty. The interval is initially chosen
3233 c so that it contains a minimizer of the modified function
3234 c
3235 c psi(stp) = f(stp) - f(0) - ftol*stp*f'(0).
3236 c
3237 c If psi(stp) <= 0 and f'(stp) >= 0 for some step, then the
3238 c interval is chosen so that it contains a minimizer of f.
3239 c
3240 c The algorithm is designed to find a step that satisfies
3241 c the sufficient decrease condition
3242 c
3243 c f(stp) <= f(0) + ftol*stp*f'(0),
3244 c
3245 c and the curvature condition
3246 c
3247 c abs(f'(stp)) <= gtol*abs(f'(0)).
3248 c
3249 c If ftol is less than gtol and if, for example, the function
3250 c is bounded below, then there is always a step which satisfies
3251 c both conditions.
3252 c
3253 c If no step can be found that satisfies both conditions, then
3254 c the algorithm stops with a warning. In this case stp only
3255 c satisfies the sufficient decrease condition.
3256 c
3257 c A typical invocation of dcsrch has the following outline:
3258 c
3259 c task = 'START'
3260 c 10 continue
3261 c call dcsrch( ... )
3262 c if (task .eq. 'FG') then
3263 c Evaluate the function and the gradient at stp
3264 c goto 10
3265 c end if
3266 c
3267 c NOTE: The user must no alter work arrays between calls.
3268 c
3269 c The subroutine statement is
3270 c
3271 c subroutine dcsrch(f,g,stp,ftol,gtol,xtol,stpmin,stpmax,
3272 c task,isave,dsave)
3273 c where
3274 c
3275 c f is a double precision variable.
3276 c On initial entry f is the value of the function at 0.
3277 c On subsequent entries f is the value of the
3278 c function at stp.
3279 c On exit f is the value of the function at stp.
3280 c
3281 c g is a double precision variable.
3282 c On initial entry g is the derivative of the function at 0.
3283 c On subsequent entries g is the derivative of the
3284 c function at stp.
3285 c On exit g is the derivative of the function at stp.
3286 c
3287 c stp is a double precision variable.
3288 c On entry stp is the current estimate of a satisfactory
3289 c step. On initial entry, a positive initial estimate
3290 c must be provided.
3291 c On exit stp is the current estimate of a satisfactory step
3292 c if task = 'FG'. If task = 'CONV' then stp satisfies
3293 c the sufficient decrease and curvature condition.
3294 c
3295 c ftol is a double precision variable.
3296 c On entry ftol specifies a nonnegative tolerance for the
3297 c sufficient decrease condition.
3298 c On exit ftol is unchanged.
3299 c
3300 c gtol is a double precision variable.
3301 c On entry gtol specifies a nonnegative tolerance for the
3302 c curvature condition.
3303 c On exit gtol is unchanged.
3304 c
3305 c xtol is a double precision variable.
3306 c On entry xtol specifies a nonnegative relative tolerance
3307 c for an acceptable step. The subroutine exits with a
3308 c warning if the relative difference between sty and stx
3309 c is less than xtol.
3310 c On exit xtol is unchanged.
3311 c
3312 c stpmin is a double precision variable.
3313 c On entry stpmin is a nonnegative lower bound for the step.
3314 c On exit stpmin is unchanged.
3315 c
3316 c stpmax is a double precision variable.
3317 c On entry stpmax is a nonnegative upper bound for the step.
3318 c On exit stpmax is unchanged.
3319 c
3320 c task is a character variable of length at least 60.
3321 c On initial entry task must be set to 'START'.
3322 c On exit task indicates the required action:
3323 c
3324 c If task(1:2) = 'FG' then evaluate the function and
3325 c derivative at stp and call dcsrch again.
3326 c
3327 c If task(1:4) = 'CONV' then the search is successful.
3328 c
3329 c If task(1:4) = 'WARN' then the subroutine is not able
3330 c to satisfy the convergence conditions. The exit value of
3331 c stp contains the best point found during the search.
3332 c
3333 c If task(1:5) = 'ERROR' then there is an error in the
3334 c input arguments.
3335 c
3336 c On exit with convergence, a warning or an error, the
3337 c variable task contains additional information.
3338 c
3339 c isave is an integer work array of dimension 2.
3340 c
3341 c dsave is a double precision work array of dimension 13.
3342 c
3343 c Subprograms called
3344 c
3345 c MINPACK-2 ... dcstep
3346 c
3347 c MINPACK-1 Project. June 1983.
3348 c Argonne National Laboratory.
3349 c Jorge J. More' and David J. Thuente.
3350 c
3351 c MINPACK-2 Project. October 1993.
3352 c Argonne National Laboratory and University of Minnesota.
3353 c Brett M. Averick, Richard G. Carter, and Jorge J. More'.
3354 c
3355 c **********
3356 double precision zero,p5,p66
3357 parameter(zero=0.0d0,p5=0.5d0,p66=0.66d0)
3358 double precision xtrapl,xtrapu
3359 parameter(xtrapl=1.1d0,xtrapu=4.0d0)
3360
3361 logical brackt
3362 integer stage
3363 double precision finit,ftest,fm,fx,fxm,fy,fym,ginit,gtest,
3364 + gm,gx,gxm,gy,gym,stx,sty,stmin,stmax,width,width1
3365
3366 c Initialization block.
3367
3368 if (task(1:5) .eq. 'START') then
3369
3370 c Check the input arguments for errors.
3371
3372 if (stp .lt. stpmin) task = 'ERROR: STP .LT. STPMIN'
3373 if (stp .gt. stpmax) task = 'ERROR: STP .GT. STPMAX'
3374 if (g .ge. zero) task = 'ERROR: INITIAL G .GE. ZERO'
3375 if (ftol .lt. zero) task = 'ERROR: FTOL .LT. ZERO'
3376 if (gtol .lt. zero) task = 'ERROR: GTOL .LT. ZERO'
3377 if (xtol .lt. zero) task = 'ERROR: XTOL .LT. ZERO'
3378 if (stpmin .lt. zero) task = 'ERROR: STPMIN .LT. ZERO'
3379 if (stpmax .lt. stpmin) task = 'ERROR: STPMAX .LT. STPMIN'
3380
3381 c Exit if there are errors on input.
3382
3383 if (task(1:5) .eq. 'ERROR') return
3384
3385 c Initialize local variables.
3386
3387 brackt = .false.
3388 stage = 1
3389 finit = f
3390 ginit = g
3391 gtest = ftol*ginit
3392 width = stpmax - stpmin
3393 width1 = width/p5
3394
3395 c The variables stx, fx, gx contain the values of the step,
3396 c function, and derivative at the best step.
3397 c The variables sty, fy, gy contain the value of the step,
3398 c function, and derivative at sty.
3399 c The variables stp, f, g contain the values of the step,
3400 c function, and derivative at stp.
3401
3402 stx = zero
3403 fx = finit
3404 gx = ginit
3405 sty = zero
3406 fy = finit
3407 gy = ginit
3408 stmin = zero
3409 stmax = stp + xtrapu*stp
3410 task = 'FG'
3411
3412 goto 1000
3413
3414 else
3415
3416 c Restore local variables.
3417
3418 if (isave(1) .eq. 1) then
3419 brackt = .true.
3420 else
3421 brackt = .false.
3422 endif
3423 stage = isave(2)
3424 ginit = dsave(1)
3425 gtest = dsave(2)
3426 gx = dsave(3)
3427 gy = dsave(4)
3428 finit = dsave(5)
3429 fx = dsave(6)
3430 fy = dsave(7)
3431 stx = dsave(8)
3432 sty = dsave(9)
3433 stmin = dsave(10)
3434 stmax = dsave(11)
3435 width = dsave(12)
3436 width1 = dsave(13)
3437
3438 endif
3439
3440 c If psi(stp) <= 0 and f'(stp) >= 0 for some step, then the
3441 c algorithm enters the second stage.
3442
3443 ftest = finit + stp*gtest
3444 if (stage .eq. 1 .and. f .le. ftest .and. g .ge. zero)
3445 + stage = 2
3446
3447 c Test for warnings.
3448
3449 if (brackt .and. (stp .le. stmin .or. stp .ge. stmax))
3450 + task = 'WARNING: ROUNDING ERRORS PREVENT PROGRESS'
3451 if (brackt .and. stmax - stmin .le. xtol*stmax)
3452 + task = 'WARNING: XTOL TEST SATISFIED'
3453 if (stp .eq. stpmax .and. f .le. ftest .and. g .le. gtest)
3454 + task = 'WARNING: STP = STPMAX'
3455 if (stp .eq. stpmin .and. (f .gt. ftest .or. g .ge. gtest))
3456 + task = 'WARNING: STP = STPMIN'
3457
3458 c Test for convergence.
3459
3460 if (f .le. ftest .and. abs(g) .le. gtol*(-ginit))
3461 + task = 'CONVERGENCE'
3462
3463 c Test for termination.
3464
3465 if (task(1:4) .eq. 'WARN' .or. task(1:4) .eq. 'CONV') goto 1000
3466
3467 c A modified function is used to predict the step during the
3468 c first stage if a lower function value has been obtained but
3469 c the decrease is not sufficient.
3470
3471 if (stage .eq. 1 .and. f .le. fx .and. f .gt. ftest) then
3472
3473 c Define the modified function and derivative values.
3474
3475 fm = f - stp*gtest
3476 fxm = fx - stx*gtest
3477 fym = fy - sty*gtest
3478 gm = g - gtest
3479 gxm = gx - gtest
3480 gym = gy - gtest
3481
3482 c Call dcstep to update stx, sty, and to compute the new step.
3483
3484 call dcstep(stx,fxm,gxm,sty,fym,gym,stp,fm,gm,
3485 + brackt,stmin,stmax)
3486
3487 c Reset the function and derivative values for f.
3488
3489 fx = fxm + stx*gtest
3490 fy = fym + sty*gtest
3491 gx = gxm + gtest
3492 gy = gym + gtest
3493
3494 else
3495
3496 c Call dcstep to update stx, sty, and to compute the new step.
3497
3498 call dcstep(stx,fx,gx,sty,fy,gy,stp,f,g,
3499 + brackt,stmin,stmax)
3500
3501 endif
3502
3503 c Decide if a bisection step is needed.
3504
3505 if (brackt) then
3506 if (abs(sty-stx) .ge. p66*width1) stp = stx + p5*(sty - stx)
3507 width1 = width
3508 width = abs(sty-stx)
3509 endif
3510
3511 c Set the minimum and maximum steps allowed for stp.
3512
3513 if (brackt) then
3514 stmin = min(stx,sty)
3515 stmax = max(stx,sty)
3516 else
3517 stmin = stp + xtrapl*(stp - stx)
3518 stmax = stp + xtrapu*(stp - stx)
3519 endif
3520
3521 c Force the step to be within the bounds stpmax and stpmin.
3522
3523 stp = max(stp,stpmin)
3524 stp = min(stp,stpmax)
3525
3526 c If further progress is not possible, let stp be the best
3527 c point obtained during the search.
3528
3529 if (brackt .and. (stp .le. stmin .or. stp .ge. stmax)
3530 + .or. (brackt .and. stmax-stmin .le. xtol*stmax)) stp = stx
3531
3532 c Obtain another function and derivative.
3533
3534 task = 'FG'
3535
3536 1000 continue
3537
3538 c Save local variables.
3539
3540 if (brackt) then
3541 isave(1) = 1
3542 else
3543 isave(1) = 0
3544 endif
3545 isave(2) = stage
3546 dsave(1) = ginit
3547 dsave(2) = gtest
3548 dsave(3) = gx
3549 dsave(4) = gy
3550 dsave(5) = finit
3551 dsave(6) = fx
3552 dsave(7) = fy
3553 dsave(8) = stx
3554 dsave(9) = sty
3555 dsave(10) = stmin
3556 dsave(11) = stmax
3557 dsave(12) = width
3558 dsave(13) = width1
3559
3560 end
3561
3562 c====================== The end of dcsrch ==============================
3563
3564 subroutine dcstep(stx,fx,dx,sty,fy,dy,stp,fp,dp,brackt,
3565 + stpmin,stpmax)
3566 logical brackt
3567 double precision stx,fx,dx,sty,fy,dy,stp,fp,dp,stpmin,stpmax
3568 c **********
3569 c
3570 c Subroutine dcstep
3571 c
3572 c This subroutine computes a safeguarded step for a search
3573 c procedure and updates an interval that contains a step that
3574 c satisfies a sufficient decrease and a curvature condition.
3575 c
3576 c The parameter stx contains the step with the least function
3577 c value. If brackt is set to .true. then a minimizer has
3578 c been bracketed in an interval with endpoints stx and sty.
3579 c The parameter stp contains the current step.
3580 c The subroutine assumes that if brackt is set to .true. then
3581 c
3582 c min(stx,sty) < stp < max(stx,sty),
3583 c
3584 c and that the derivative at stx is negative in the direction
3585 c of the step.
3586 c
3587 c The subroutine statement is
3588 c
3589 c subroutine dcstep(stx,fx,dx,sty,fy,dy,stp,fp,dp,brackt,
3590 c stpmin,stpmax)
3591 c
3592 c where
3593 c
3594 c stx is a double precision variable.
3595 c On entry stx is the best step obtained so far and is an
3596 c endpoint of the interval that contains the minimizer.
3597 c On exit stx is the updated best step.
3598 c
3599 c fx is a double precision variable.
3600 c On entry fx is the function at stx.
3601 c On exit fx is the function at stx.
3602 c
3603 c dx is a double precision variable.
3604 c On entry dx is the derivative of the function at
3605 c stx. The derivative must be negative in the direction of
3606 c the step, that is, dx and stp - stx must have opposite
3607 c signs.
3608 c On exit dx is the derivative of the function at stx.
3609 c
3610 c sty is a double precision variable.
3611 c On entry sty is the second endpoint of the interval that
3612 c contains the minimizer.
3613 c On exit sty is the updated endpoint of the interval that
3614 c contains the minimizer.
3615 c
3616 c fy is a double precision variable.
3617 c On entry fy is the function at sty.
3618 c On exit fy is the function at sty.
3619 c
3620 c dy is a double precision variable.
3621 c On entry dy is the derivative of the function at sty.
3622 c On exit dy is the derivative of the function at the exit sty.
3623 c
3624 c stp is a double precision variable.
3625 c On entry stp is the current step. If brackt is set to .true.
3626 c then on input stp must be between stx and sty.
3627 c On exit stp is a new trial step.
3628 c
3629 c fp is a double precision variable.
3630 c On entry fp is the function at stp
3631 c On exit fp is unchanged.
3632 c
3633 c dp is a double precision variable.
3634 c On entry dp is the the derivative of the function at stp.
3635 c On exit dp is unchanged.
3636 c
3637 c brackt is an logical variable.
3638 c On entry brackt specifies if a minimizer has been bracketed.
3639 c Initially brackt must be set to .false.
3640 c On exit brackt specifies if a minimizer has been bracketed.
3641 c When a minimizer is bracketed brackt is set to .true.
3642 c
3643 c stpmin is a double precision variable.
3644 c On entry stpmin is a lower bound for the step.
3645 c On exit stpmin is unchanged.
3646 c
3647 c stpmax is a double precision variable.
3648 c On entry stpmax is an upper bound for the step.
3649 c On exit stpmax is unchanged.
3650 c
3651 c MINPACK-1 Project. June 1983
3652 c Argonne National Laboratory.
3653 c Jorge J. More' and David J. Thuente.
3654 c
3655 c MINPACK-2 Project. October 1993.
3656 c Argonne National Laboratory and University of Minnesota.
3657 c Brett M. Averick and Jorge J. More'.
3658 c
3659 c **********
3660 double precision zero,p66,two,three
3661 parameter(zero=0.0d0,p66=0.66d0,two=2.0d0,three=3.0d0)
3662
3663 double precision gamma,p,q,r,s,sgnd,stpc,stpf,stpq,theta
3664
3665 sgnd = dp*(dx/abs(dx))
3666
3667 c First case: A higher function value. The minimum is bracketed.
3668 c If the cubic step is closer to stx than the quadratic step, the
3669 c cubic step is taken, otherwise the average of the cubic and
3670 c quadratic steps is taken.
3671
3672 if (fp .gt. fx) then
3673 theta = three*(fx - fp)/(stp - stx) + dx + dp
3674 s = max(abs(theta),abs(dx),abs(dp))
3675 gamma = s*sqrt((theta/s)**2 - (dx/s)*(dp/s))
3676 if (stp .lt. stx) gamma = -gamma
3677 p = (gamma - dx) + theta
3678 q = ((gamma - dx) + gamma) + dp
3679 r = p/q
3680 stpc = stx + r*(stp - stx)
3681 stpq = stx + ((dx/((fx - fp)/(stp - stx) + dx))/two)*
3682 + (stp - stx)
3683 if (abs(stpc-stx) .lt. abs(stpq-stx)) then
3684 stpf = stpc
3685 else
3686 stpf = stpc + (stpq - stpc)/two
3687 endif
3688 brackt = .true.
3689
3690 c Second case: A lower function value and derivatives of opposite
3691 c sign. The minimum is bracketed. If the cubic step is farther from
3692 c stp than the secant step, the cubic step is taken, otherwise the
3693 c secant step is taken.
3694
3695 else if (sgnd .lt. zero) then
3696 theta = three*(fx - fp)/(stp - stx) + dx + dp
3697 s = max(abs(theta),abs(dx),abs(dp))
3698 gamma = s*sqrt((theta/s)**2 - (dx/s)*(dp/s))
3699 if (stp .gt. stx) gamma = -gamma
3700 p = (gamma - dp) + theta
3701 q = ((gamma - dp) + gamma) + dx
3702 r = p/q
3703 stpc = stp + r*(stx - stp)
3704 stpq = stp + (dp/(dp - dx))*(stx - stp)
3705 if (abs(stpc-stp) .gt. abs(stpq-stp)) then
3706 stpf = stpc
3707 else
3708 stpf = stpq
3709 endif
3710 brackt = .true.
3711
3712 c Third case: A lower function value, derivatives of the same sign,
3713 c and the magnitude of the derivative decreases.
3714
3715 else if (abs(dp) .lt. abs(dx)) then
3716
3717 c The cubic step is computed only if the cubic tends to infinity
3718 c in the direction of the step or if the minimum of the cubic
3719 c is beyond stp. Otherwise the cubic step is defined to be the
3720 c secant step.
3721
3722 theta = three*(fx - fp)/(stp - stx) + dx + dp
3723 s = max(abs(theta),abs(dx),abs(dp))
3724
3725 c The case gamma = 0 only arises if the cubic does not tend
3726 c to infinity in the direction of the step.
3727
3728 gamma = s*sqrt(max(zero,(theta/s)**2-(dx/s)*(dp/s)))
3729 if (stp .gt. stx) gamma = -gamma
3730 p = (gamma - dp) + theta
3731 q = (gamma + (dx - dp)) + gamma
3732 r = p/q
3733 if (r .lt. zero .and. gamma .ne. zero) then
3734 stpc = stp + r*(stx - stp)
3735 else if (stp .gt. stx) then
3736 stpc = stpmax
3737 else
3738 stpc = stpmin
3739 endif
3740 stpq = stp + (dp/(dp - dx))*(stx - stp)
3741
3742 if (brackt) then
3743
3744 c A minimizer has been bracketed. If the cubic step is
3745 c closer to stp than the secant step, the cubic step is
3746 c taken, otherwise the secant step is taken.
3747
3748 if (abs(stpc-stp) .lt. abs(stpq-stp)) then
3749 stpf = stpc
3750 else
3751 stpf = stpq
3752 endif
3753 if (stp .gt. stx) then
3754 stpf = min(stp+p66*(sty-stp),stpf)
3755 else
3756 stpf = max(stp+p66*(sty-stp),stpf)
3757 endif
3758 else
3759
3760 c A minimizer has not been bracketed. If the cubic step is
3761 c farther from stp than the secant step, the cubic step is
3762 c taken, otherwise the secant step is taken.
3763
3764 if (abs(stpc-stp) .gt. abs(stpq-stp)) then
3765 stpf = stpc
3766 else
3767 stpf = stpq
3768 endif
3769 stpf = min(stpmax,stpf)
3770 stpf = max(stpmin,stpf)
3771 endif
3772
3773 c Fourth case: A lower function value, derivatives of the same sign,
3774 c and the magnitude of the derivative does not decrease. If the
3775 c minimum is not bracketed, the step is either stpmin or stpmax,
3776 c otherwise the cubic step is taken.
3777
3778 else
3779 if (brackt) then
3780 theta = three*(fp - fy)/(sty - stp) + dy + dp
3781 s = max(abs(theta),abs(dy),abs(dp))
3782 gamma = s*sqrt((theta/s)**2 - (dy/s)*(dp/s))
3783 if (stp .gt. sty) gamma = -gamma
3784 p = (gamma - dp) + theta
3785 q = ((gamma - dp) + gamma) + dy
3786 r = p/q
3787 stpc = stp + r*(sty - stp)
3788 stpf = stpc
3789 else if (stp .gt. stx) then
3790 stpf = stpmax
3791 else
3792 stpf = stpmin
3793 endif
3794 endif
3795
3796 c Update the interval which contains a minimizer.
3797
3798 if (fp .gt. fx) then
3799 sty = stp
3800 fy = fp
3801 dy = dp
3802 else
3803 if (sgnd .lt. zero) then
3804 sty = stx
3805 fy = fx
3806 dy = dx
3807 endif
3808 stx = stp
3809 fx = fp
3810 dx = dp
3811 endif
3812
3813 c Compute the new step.
3814
3815 stp = stpf
3816
3817 end
3818
3819 c====================== The end of dcstep ==============================
3820
3821 subroutine timer(ttime)
3822 double precision ttime
3823 c *********
3824 c
3825 c Subroutine timer
3826 c
3827 c This subroutine is used to determine user time. In a typical
3828 c application, the user time for a code segment requires calls
3829 c to subroutine timer to determine the initial and final time.
3830 c
3831 c The subroutine statement is
3832 c
3833 c subroutine timer(ttime)
3834 c
3835 c where
3836 c
3837 c ttime is an output variable which specifies the user time.
3838 c
3839 c Argonne National Laboratory and University of Minnesota.
3840 c MINPACK-2 Project.
3841 c
3842 c Modified October 1990 by Brett M. Averick.
3843 c
3844 c **********
3845 real temp
3846 real tarray(2)
3847 real etime
3848
3849 c The first element of the array tarray specifies user time
3850
3851 temp = etime(tarray)
3852
3853 ttime = dble(tarray(1))
3854
3855 return
3856
3857 end
3858
3859 c====================== The end of timer ===============================
3860
3861 double precision function dpmeps()
3862 c **********
3863 c
3864 c Subroutine dpeps
3865 c
3866 c This subroutine computes the machine precision parameter
3867 c dpmeps as the smallest floating point number such that
3868 c 1 + dpmeps differs from 1.
3869 c
3870 c This subroutine is based on the subroutine machar described in
3871 c
3872 c W. J. Cody,
3873 c MACHAR: A subroutine to dynamically determine machine parameters,
3874 c ACM Transactions on Mathematical Software, 14, 1988, pages 303-311.
3875 c
3876 c The subroutine statement is:
3877 c
3878 c subroutine dpeps(dpmeps)
3879 c
3880 c where
3881 c
3882 c dpmeps is a double precision variable.
3883 c On entry dpmeps need not be specified.
3884 c On exit dpmeps is the machine precision.
3885 c
3886 c MINPACK-2 Project. February 1991.
3887 c Argonne National Laboratory and University of Minnesota.
3888 c Brett M. Averick.
3889 c
3890 c *******
3891 integer i,ibeta,irnd,it,itemp,negep
3892 double precision a,b,beta,betain,betah,temp,tempa,temp1,
3893 + zero,one,two
3894 data zero,one,two /0.0d0,1.0d0,2.0d0/
3895
3896 c determine ibeta, beta ala malcolm.
3897
3898 a = one
3899 b = one
3900 10 continue
3901 a = a + a
3902 temp = a + one
3903 temp1 = temp - a
3904 if (temp1 - one .eq. zero) go to 10
3905 20 continue
3906 b = b + b
3907 temp = a + b
3908 itemp = int(temp - a)
3909 if (itemp .eq. 0) go to 20
3910 ibeta = itemp
3911 beta = dble(ibeta)
3912
3913 c determine it, irnd.
3914
3915 it = 0
3916 b = one
3917 30 continue
3918 it = it + 1
3919 b = b * beta
3920 temp = b + one
3921 temp1 = temp - b
3922 if (temp1 - one .eq. zero) go to 30
3923 irnd = 0
3924 betah = beta/two
3925 temp = a + betah
3926 if (temp - a .ne. zero) irnd = 1
3927 tempa = a + beta
3928 temp = tempa + betah
3929 if ((irnd .eq. 0) .and. (temp - tempa .ne. zero)) irnd = 2
3930
3931 c determine dpmeps.
3932
3933 negep = it + 3
3934 betain = one/beta
3935 a = one
3936 do 40 i = 1, negep
3937 a = a*betain
3938 40 continue
3939 50 continue
3940 temp = one + a
3941 if (temp - one .ne. zero) go to 60
3942 a = a*beta
3943 go to 50
3944 60 continue
3945 dpmeps = a
3946 if ((ibeta .eq. 2) .or. (irnd .eq. 0)) go to 70
3947 a = (a*(one + a))/two
3948 temp = one + a
3949 if (temp - one .ne. zero) dpmeps = a
3950
3951 70 return
3952
3953 end
3954
3955 c====================== The end of dpmeps ==============================
3956
3957 subroutine dtrsl(t,ldt,n,b,job,info)
3958 integer ldt,n,job,info
3959 double precision t(ldt,1),b(1)
3960 c
3961 c
3962 c dtrsl solves systems of the form
3963 c
3964 c t * x = b
3965 c or
3966 c trans(t) * x = b
3967 c
3968 c where t is a triangular matrix of order n. here trans(t)
3969 c denotes the transpose of the matrix t.
3970 c
3971 c on entry
3972 c
3973 c t double precision(ldt,n)
3974 c t contains the matrix of the system. the zero
3975 c elements of the matrix are not referenced, and
3976 c the corresponding elements of the array can be
3977 c used to store other information.
3978 c
3979 c ldt integer
3980 c ldt is the leading dimension of the array t.
3981 c
3982 c n integer
3983 c n is the order of the system.
3984 c
3985 c b double precision(n).
3986 c b contains the right hand side of the system.
3987 c
3988 c job integer
3989 c job specifies what kind of system is to be solved.
3990 c if job is
3991 c
3992 c 00 solve t*x=b, t lower triangular,
3993 c 01 solve t*x=b, t upper triangular,
3994 c 10 solve trans(t)*x=b, t lower triangular,
3995 c 11 solve trans(t)*x=b, t upper triangular.
3996 c
3997 c on return
3998 c
3999 c b b contains the solution, if info .eq. 0.
4000 c otherwise b is unaltered.
4001 c
4002 c info integer
4003 c info contains zero if the system is nonsingular.
4004 c otherwise info contains the index of
4005 c the first zero diagonal element of t.
4006 c
4007 c linpack. this version dated 08/14/78 .
4008 c g. w. stewart, university of maryland, argonne national lab.
4009 c
4010 c subroutines and functions
4011 c
4012 c blas daxpy,ddot
4013 c fortran mod
4014 c
4015 c internal variables
4016 c
4017 double precision ddot,temp
4018 integer case,j,jj
4019 c
4020 c begin block permitting ...exits to 150
4021 c
4022 c check for zero diagonal elements.
4023 c
4024 do 10 info = 1, n
4025 c ......exit
4026 if (t(info,info) .eq. 0.0d0) go to 150
4027 10 continue
4028 info = 0
4029 c
4030 c determine the task and go to it.
4031 c
4032 case = 1
4033 if (mod(job,10) .ne. 0) case = 2
4034 if (mod(job,100)/10 .ne. 0) case = case + 2
4035 go to (20,50,80,110), case
4036 c
4037 c solve t*x=b for t lower triangular
4038 c
4039 20 continue
4040 b(1) = b(1)/t(1,1)
4041 if (n .lt. 2) go to 40
4042 do 30 j = 2, n
4043 temp = -b(j-1)
4044 call daxpy(n-j+1,temp,t(j,j-1),1,b(j),1)
4045 b(j) = b(j)/t(j,j)
4046 30 continue
4047 40 continue
4048 go to 140
4049 c
4050 c solve t*x=b for t upper triangular.
4051 c
4052 50 continue
4053 b(n) = b(n)/t(n,n)
4054 if (n .lt. 2) go to 70
4055 do 60 jj = 2, n
4056 j = n - jj + 1
4057 temp = -b(j+1)
4058 call daxpy(j,temp,t(1,j+1),1,b(1),1)
4059 b(j) = b(j)/t(j,j)
4060 60 continue
4061 70 continue
4062 go to 140
4063 c
4064 c solve trans(t)*x=b for t lower triangular.
4065 c
4066 80 continue
4067 b(n) = b(n)/t(n,n)
4068 if (n .lt. 2) go to 100
4069 do 90 jj = 2, n
4070 j = n - jj + 1
4071 b(j) = b(j) - ddot(jj-1,t(j+1,j),1,b(j+1),1)
4072 b(j) = b(j)/t(j,j)
4073 90 continue
4074 100 continue
4075 go to 140
4076 c
4077 c solve trans(t)*x=b for t upper triangular.
4078 c
4079 110 continue
4080 b(1) = b(1)/t(1,1)
4081 if (n .lt. 2) go to 130
4082 do 120 j = 2, n
4083 b(j) = b(j) - ddot(j-1,t(1,j),1,b(1),1)
4084 b(j) = b(j)/t(j,j)
4085 120 continue
4086 130 continue
4087 140 continue
4088 150 continue
4089 return
4090 end
4091
4092 c====================== The end of dtrsl ===============================