This simple driver demonstrates how to call the L-BFGS-B code to solve a sample problem (the extended Rosenbrock function subject to bounds on the variables). The dimension n of this problem is variable. (Fortran-90 version)
211 integer,
parameter :: n = 25, m = 5, iprint = 1
212 integer,
parameter :: dp = kind(1.0d0)
213 real(dp),
parameter :: factr = 1.0d+7, pgtol = 1.0d-5
215 character(len=60) :: task, csave
219 real(dp) :: dsave(29)
220 integer,
allocatable :: nbd(:), iwa(:)
221 real(dp),
allocatable :: x(:), l(:), u(:), g(:), wa(:)
230 allocate ( nbd(n), x(n), l(n), u(n), g(n) )
231 allocate ( iwa(3*n) )
232 allocate ( wa(2*m*n + 11*m*m + 5*n + 8*m) )
255 16
format(/,5x,
'Solving sample problem.', &
256 /,5x,
' (f = 0.0 at the optimal solution.)',/)
264 do while(task(1:2).eq.
'FG'.or.task.eq.
'NEW_X'.or. &
269 call setulb ( n, m, x, l, u, nbd, f, g, factr, pgtol, &
270 wa, iwa, task, iprint,&
271 csave, lsave, isave, dsave )
273 if (task(1:2) .eq.
'FG')
then
275 f=.25d0*( x(1)-1.d0 )**2
277 f = f + ( x(i)-x(i-1 )**2 )**2
284 g(1) = 2.d0*(x(1) - 1.d0) - 1.6d1*x(1)*t1
287 t1 = x(i+1) - x(i)**2
288 g(i) = 8.d0*t2 - 1.6d1*x(i)*t1
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...