L-BFGS-B  3.0
Large-scale Bound-constrained Optimization
driver2.f

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-77 version)

1 c> \file driver2.f
2 
3 c
4 c L-BFGS-B is released under the “New BSD License” (aka “Modified BSD License”
5 c or “3-clause license”)
6 c Please read attached file License.txt
7 c
8 c DRIVER 2 in Fortran 77
9 c --------------------------------------------------------------
10 c CUSTOMIZED DRIVER FOR L-BFGS-B (version 3.0)
11 c --------------------------------------------------------------
12 c
13 c L-BFGS-B is a code for solving large nonlinear optimization
14 c problems with simple bounds on the variables.
15 c
16 c The code can also be used for unconstrained problems and is
17 c as efficient for these problems as the earlier limited memory
18 c code L-BFGS.
19 c
20 c This driver illustrates how to control the termination of the
21 c run and how to design customized output.
22 c
23 c References:
24 c
25 c [1] R. H. Byrd, P. Lu, J. Nocedal and C. Zhu, ``A limited
26 c memory algorithm for bound constrained optimization'',
27 c SIAM J. Scientific Computing 16 (1995), no. 5, pp. 1190--1208.
28 c
29 c [2] C. Zhu, R.H. Byrd, P. Lu, J. Nocedal, ``L-BFGS-B: FORTRAN
30 c Subroutines for Large Scale Bound Constrained Optimization''
31 c Tech. Report, NAM-11, EECS Department, Northwestern University,
32 c 1994.
33 c
34 c
35 c (Postscript files of these papers are available via anonymous
36 c ftp to eecs.nwu.edu in the directory pub/lbfgs/lbfgs_bcm.)
37 c
38 c * * *
39 c
40 c February 2011 (latest revision)
41 c Optimization Center at Northwestern University
42 c Instituto Tecnologico Autonomo de Mexico
43 c
44 c Jorge Nocedal and Jose Luis Morales
45 c Jorge Nocedal and Jose Luis Morales, Remark on "Algorithm 778:
46 c L-BFGS-B: Fortran Subroutines for Large-Scale Bound Constrained
47 c Optimization" (2011). To appear in ACM Transactions on
48 c Mathematical Software,
49 c
50 c **************
51 
52  program driver
53 
54 c This driver shows how to replace the default stopping test
55 c by other termination criteria. It also illustrates how to
56 c print the values of several parameters during the course of
57 c the iteration. The sample problem used here is the same as in
58 c DRIVER1 (the extended Rosenbrock function with bounds on the
59 c variables).
60 
61  integer nmax, mmax
62  parameter(nmax=1024, mmax=17)
63 c nmax is the dimension of the largest problem to be solved.
64 c mmax is the maximum number of limited memory corrections.
65 
66 c Declare the variables needed by the code.
67 c A description of all these variables is given at the end of
68 c driver1.
69 
70  character*60 task, csave
71  logical lsave(4)
72  integer n, m, iprint,
73  + nbd(nmax), iwa(3*nmax), isave(44)
74  double precision f, factr, pgtol,
75  + x(nmax), l(nmax), u(nmax), g(nmax), dsave(29),
76  + wa(2*mmax*nmax+5*nmax+11*mmax*mmax+8*mmax)
77 
78 c Declare a few additional variables for the sample problem.
79 
80  double precision t1, t2
81  integer i
82 
83 c We suppress the default output.
84 
85  iprint = -1
86 
87 c We suppress both code-supplied stopping tests because the
88 c user is providing his own stopping criteria.
89 
90  factr=0.0d0
91  pgtol=0.0d0
92 
93 c We specify the dimension n of the sample problem and the number
94 c m of limited memory corrections stored. (n and m should not
95 c exceed the limits nmax and mmax respectively.)
96 
97  n=25
98  m=5
99 
100 c We now specify nbd which defines the bounds on the variables:
101 c l specifies the lower bounds,
102 c u specifies the upper bounds.
103 
104 c First set bounds on the odd numbered variables.
105 
106  do 10 i=1,n,2
107  nbd(i)=2
108  l(i)=1.0d0
109  u(i)=1.0d2
110  10 continue
111 
112 c Next set bounds on the even numbered variables.
113 
114  do 12 i=2,n,2
115  nbd(i)=2
116  l(i)=-1.0d2
117  u(i)=1.0d2
118  12 continue
119 
120 c We now define the starting point.
121 
122  do 14 i=1,n
123  x(i)=3.0d0
124  14 continue
125 
126 c We now write the heading of the output.
127 
128  write (6,16)
129  16 format(/,5x, 'Solving sample problem.',
130  + /,5x, ' (f = 0.0 at the optimal solution.)',/)
131 
132 c We start the iteration by initializing task.
133 c
134  task = 'START'
135 
136 c ------- the beginning of the loop ----------
137 
138  111 continue
139 
140 c This is the call to the L-BFGS-B code.
141 
142  call setulb(n,m,x,l,u,nbd,f,g,factr,pgtol,wa,iwa,task,iprint,
143  + csave,lsave,isave,dsave)
144 
145  if (task(1:2) .eq. 'FG') then
146 c the minimization routine has returned to request the
147 c function f and gradient g values at the current x.
148 
149 c Compute function value f for the sample problem.
150 
151  f=.25d0*(x(1)-1.d0)**2
152  do 20 i=2,n
153  f=f+(x(i)-x(i-1)**2)**2
154  20 continue
155  f=4.d0*f
156 
157 c Compute gradient g for the sample problem.
158 
159  t1=x(2)-x(1)**2
160  g(1)=2.d0*(x(1)-1.d0)-1.6d1*x(1)*t1
161  do 22 i=2,n-1
162  t2=t1
163  t1=x(i+1)-x(i)**2
164  g(i)=8.d0*t2-1.6d1*x(i)*t1
165  22 continue
166  g(n)=8.d0*t1
167 
168 c go back to the minimization routine.
169  goto 111
170  endif
171 c
172  if (task(1:5) .eq. 'NEW_X') then
173 c
174 c the minimization routine has returned with a new iterate.
175 c At this point have the opportunity of stopping the iteration
176 c or observing the values of certain parameters
177 c
178 c First are two examples of stopping tests.
179 
180 c Note: task(1:4) must be assigned the value 'STOP' to terminate
181 c the iteration and ensure that the final results are
182 c printed in the default format. The rest of the character
183 c string TASK may be used to store other information.
184 
185 c 1) Terminate if the total number of f and g evaluations
186 c exceeds 99.
187 
188  if (isave(34) .ge. 99)
189  + task='STOP: TOTAL NO. of f AND g EVALUATIONS EXCEEDS LIMIT'
190 
191 c 2) Terminate if |proj g|/(1+|f|) < 1.0d-10, where
192 c "proj g" denoted the projected gradient
193 
194  if (dsave(13) .le. 1.d-10*(1.0d0 + abs(f)))
195  + task='STOP: THE PROJECTED GRADIENT IS SUFFICIENTLY SMALL'
196 
197 c We now wish to print the following information at each
198 c iteration:
199 c
200 c 1) the current iteration number, isave(30),
201 c 2) the total number of f and g evaluations, isave(34),
202 c 3) the value of the objective function f,
203 c 4) the norm of the projected gradient, dsve(13)
204 c
205 c See the comments at the end of driver1 for a description
206 c of the variables isave and dsave.
207 
208  write (6,'(2(a,i5,4x),a,1p,d12.5,4x,a,1p,d12.5)') 'Iterate'
209  + ,isave(30),'nfg =',isave(34),'f =',f,'|proj g| =',dsave(13)
210 
211 c If the run is to be terminated, we print also the information
212 c contained in task as well as the final value of x.
213 
214  if (task(1:4) .eq. 'STOP') then
215  write (6,*) task
216  write (6,*) 'Final X='
217  write (6,'((1x,1p, 6(1x,d11.4)))') (x(i),i = 1,n)
218  endif
219 
220 c go back to the minimization routine.
221  goto 111
222 
223  endif
224 
225 c ---------- the end of the loop -------------
226 
227 c If task is neither FG nor NEW_X we terminate execution.
228 
229  stop
230 
231  end
232 
233 c======================= The end of driver2 ============================
234 
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...
Definition: setulb.f:190