This time-controlled driver shows that it is possible to terminate a run by elapsed CPU time, and yet be able to print all desired information. This driver also illustrates the use of two stopping criteria that may be used in conjunction with a limit on execution time. The sample problem used here is the same as in driver1 and driver2 (the extended Rosenbrock function with bounds on the variables). (Fortran-90 version)
70 integer,
parameter :: n = 1000, m = 10, iprint = -1
71 integer,
parameter :: dp = kind(1.0d0)
72 real(dp),
parameter :: factr = 0.0d0, pgtol = 0.0d0, &
75 character(len=60) :: task, csave
80 integer,
allocatable :: nbd(:), iwa(:)
81 real(dp),
allocatable :: x(:), l(:), u(:), g(:), wa(:)
83 real(dp) :: t1, t2, time1, time2
86 allocate ( nbd(n), x(n), l(n), u(n), g(n) )
88 allocate ( wa(2*m*n + 5*n + 11*m*m + 8*m) )
127 16
format(/,5x,
'Solving sample problem.',&
128 /,5x,
' (f = 0.0 at the optimal solution.)',/)
140 do while( task(1:2).eq.
'FG'.or.task.eq.
'NEW_X'.or. &
145 call setulb(n,m,x,l,u,nbd,f,g,factr,pgtol,wa,iwa, &
146 task,iprint, csave,lsave,isave,dsave)
148 if (task(1:2) .eq.
'FG')
then
155 if (time2-time1 .gt. tlimit)
then
156 task=
'STOP: CPU EXCEEDING THE TIME LIMIT.'
175 j = 3*n+2*m*n+11*m**2
176 write (6,*)
'Latest iterate X ='
177 write (6,
'((1x,1p, 6(1x,d11.4)))') (wa(i),i = j+1,j+n)
183 write (6,
'(a,1p,d12.5,4x,a,1p,d12.5)') &
184 'At latest iterate f =',dsave(2),
'|proj g| =',dsave(13)
190 f=.25d0*(x(1)-1.d0)**2
192 f=f+(x(i)-x(i-1)**2)**2
199 g(1) = 2.d0*(x(1)-1.d0)-1.6d1*x(1)*t1
203 g(i)=8.d0*t2-1.6d1*x(i)*t1
211 if (task(1:5) .eq.
'NEW_X')
then
220 if (isave(34) .ge. 900) &
221 task=
'STOP: TOTAL NO. of f AND g EVALUATIONS EXCEEDS LIMIT'
225 if (dsave(13) .le. 1.d-10*(1.0d0 + abs(f))) &
226 task=
'STOP: THE PROJECTED GRADIENT IS SUFFICIENTLY SMALL'
237 write (6,
'(2(a,i5,4x),a,1p,d12.5,4x,a,1p,d12.5)')
'Iterate'
238 ,isave(30),
'nfg =',isave(34),
'f =',f,
'|proj g| =',dsave(13)
243 if (task(1:4) .eq.
'STOP')
then
245 write (6,*)
'Final X='
246 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...
subroutine timer(ttime)
This routine computes cpu time in double precision.