This driver shows how to replace the default stopping test by other termination criteria. It also illustrates how to print the values of several parameters during the course of the iteration. The sample problem used here is the same as in DRIVER1 (the extended Rosenbrock function with bounds on the variables). (Fortran-90 version)
65 integer,
parameter :: n = 25, m = 5, iprint = -1
66 integer,
parameter :: dp = kind(1.0d0)
67 real(dp),
parameter :: factr = 0.0d0, pgtol = 0.0d0
69 character(len=60) :: task, csave
74 integer,
allocatable :: nbd(:), iwa(:)
75 real(dp),
allocatable :: x(:), l(:), u(:), g(:), wa(:)
80 allocate ( nbd(n), x(n), l(n), u(n), g(n) )
82 allocate ( wa(2*m*n + 5*n + 11*m*m + 8*m) )
119 16
format(/,5x,
'Solving sample problem.', &
120 /,5x,
' (f = 0.0 at the optimal solution.)',/)
129 do while( task(1:2).eq.
'FG'.or.task.eq.
'NEW_X'.or. &
134 call setulb(n,m,x,l,u,nbd,f,g,factr,pgtol,wa,iwa,task,iprint, &
135 csave,lsave,isave,dsave)
137 if (task(1:2) .eq.
'FG')
then
144 f =.25d0*(x(1) - 1.d0)**2
146 f = f + (x(i) - x(i-1)**2)**2
153 g(1) = 2.d0*(x(1) - 1.d0) - 1.6d1*x(1)*t1
156 t1 = x(i+1) - x(i)**2
157 g(i) = 8.d0*t2 - 1.6d1*x(i)*t1
163 if (task(1:5) .eq.
'NEW_X')
then
179 if (isave(34) .ge. 99) &
180 task=
'STOP: TOTAL NO. of f AND g EVALUATIONS EXCEEDS LIMIT'
185 if (dsave(13) .le. 1.d-10*(1.0d0 + abs(f))) &
186 task=
'STOP: THE PROJECTED GRADIENT IS SUFFICIENTLY SMALL'
199 write (6,
'(2(a,i5,4x),a,1p,d12.5,4x,a,1p,d12.5)')
'Iterate'
200 , isave(30),
'nfg =',isave(34),
'f =',f,
'|proj g| =',dsave(
205 if (task(1:4) .eq.
'STOP')
then
207 write (6,*)
'Final X='
208 write (6,
'((1x,1p, 6(1x,d11.4)))') (x(i),i = 1,n)
subroutine setulb(n, m, x, l, u, nbd, f, g, factr, pgtol, wa, iwa, task, iprint, csave, lsave, isave, dsave)
This subroutine partitions the working arrays wa and iwa, and then uses the limited memory BFGS metho...