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)
193 use json_writer,
only: json_write_aggregate
212 integer,
parameter :: n = 25, m = 5, iprint = 1
213 integer,
parameter :: dp = kind(1.0d0)
214 real(dp),
parameter :: factr = 1.0d+7, pgtol = 1.0d-5
216 character(len=60) :: task, csave
220 real(dp) :: dsave(29)
221 integer,
allocatable :: nbd(:), iwa(:)
222 real(dp),
allocatable :: x(:), l(:), u(:), g(:), wa(:)
231 character(len=512) :: lbfgsb_json
232 logical :: json_active
236 allocate ( nbd(n), x(n), l(n), u(n), g(n) )
237 allocate ( iwa(3*n) )
238 allocate ( wa(2*m*n + 11*m*m + 5*n + 8*m) )
261 16
format(/,5x,
'Solving sample problem.', &
262 /,5x,
' (f = 0.0 at the optimal solution.)',/)
269 call get_environment_variable(
'LBFGSB_JSON_OUTPUT', lbfgsb_json)
270 json_active = (len_trim(lbfgsb_json) > 0)
274 do while(task(1:2).eq.
'FG'.or.task.eq.
'NEW_X'.or. &
279 call setulb ( n, m, x, l, u, nbd, f, g, factr, pgtol, &
280 wa, iwa, task, iprint,&
281 csave, lsave, isave, dsave )
283 if (task(1:2) .eq.
'FG')
then
285 f=.25d0*( x(1)-1.d0 )**2
287 f = f + ( x(i)-x(i-1 )**2 )**2
294 g(1) = 2.d0*(x(1) - 1.d0) - 1.6d1*x(1)*t1
297 t1 = x(i+1) - x(i)**2
298 g(i) = 8.d0*t2 - 1.6d1*x(i)*t1
308 call json_write_aggregate(trim(lbfgsb_json), task, f, dsave(13)
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...