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-77 version)
197 use json_writer,
only: json_write_aggregate
205 parameter(nmax=1024, mmax=17)
213 character*60 task, csave
215 integer n, m, iprint,
216 + nbd(nmax), iwa(3*nmax), isave(44)
217 double precision f, factr, pgtol,
218 + x(nmax), l(nmax), u(nmax), g(nmax), dsave(29),
219 + wa(2*mmax*nmax + 5*nmax + 11*mmax*mmax + 8*mmax)
223 double precision t1, t2
228 character*512 lbfgsb_json
274 16
format(/,5x,
'Solving sample problem.',
275 + /,5x,
' (f = 0.0 at the optimal solution.)',/)
282 call get_environment_variable(
'LBFGSB_JSON_OUTPUT', lbfgsb_json)
283 json_active = (len_trim(lbfgsb_json) .gt. 0)
291 call setulb(n,m,x,l,u,nbd,f,g,factr,pgtol,wa,iwa,task,iprint,
292 + csave,lsave,isave,dsave)
294 if (task(1:2) .eq.
'FG')
then
300 f=.25d0*(x(1)-1.d0)**2
302 f=f+(x(i)-x(i-1)**2)**2
309 g(1)=2.d0*(x(1)-1.d0)-1.6d1*x(1)*t1
313 g(i)=8.d0*t2-1.6d1*x(i)*t1
321 if (task(1:5) .eq.
'NEW_X')
goto 111
329 if (json_active)
then
330 call json_write_aggregate(trim(lbfgsb_json), task, f,
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...