CalculiX  2.13
A Free Software Three-Dimensional Structural Finite Element Program
lbfgsb.f File Reference

Go to the source code of this file.

Functions/Subroutines

subroutine setulb (n, m, x, l, u, nbd, f, g, factr, pgtol, wa, iwa, task, iprint, csave, lsave, isave, dsave)
 
subroutine mainlb (n, m, x, l, u, nbd, f, g, factr, pgtol, ws, wy, sy, ss, wt, wn, snd, z, r, d, t, xp, wa, index, iwhere, indx2, task, iprint, csave, lsave, isave, dsave)
 
subroutine active (n, l, u, nbd, x, iwhere, iprint, prjctd, cnstnd, boxed)
 
subroutine bmv (m, sy, wt, col, v, p, info)
 
subroutine cauchy (n, x, l, u, nbd, g, iorder, iwhere, t, d, xcp, m, wy, ws, sy, wt, theta, col, head, p, c, wbp, v, nseg, iprint, sbgnrm, info, epsmch)
 
subroutine cmprlb (n, m, x, g, ws, wy, sy, wt, z, r, wa, index, theta, col, head, nfree, cnstnd, info)
 
subroutine errclb (n, m, factr, l, u, nbd, task, info, k)
 
subroutine formk (n, nsub, ind, nenter, ileave, indx2, iupdat, updatd, wn, wn1, m, ws, wy, sy, theta, col, head, info)
 
subroutine formt (m, wt, sy, ss, col, theta, info)
 
subroutine freev (n, nfree, index, nenter, ileave, indx2, iwhere, wrk, updatd, cnstnd, iprint, iter)
 
subroutine hpsolb (n, t, iorder, iheap)
 
subroutine lnsrlb (n, l, u, nbd, x, f, fold, gd, gdold, g, d, r, t, z, stp, dnorm, dtd, xstep, stpmx, iter, ifun, iback, nfgv, info, task, boxed, cnstnd, csave, isave, dsave)
 
subroutine matupd (n, m, ws, wy, sy, ss, d, r, itail, iupdat, col, head, theta, rr, dr, stp, dtd)
 
subroutine prn1lb (n, m, l, u, x, iprint, itfile, epsmch)
 
subroutine prn2lb (n, x, f, g, iprint, itfile, iter, nfgv, nact, sbgnrm, nseg, word, iword, iback, stp, xstep)
 
subroutine prn3lb (n, x, f, task, iprint, info, itfile, iter, nfgv, nintol, nskip, nact, sbgnrm, time, nseg, word, iback, stp, xstep, k, cachyt, sbtime, lnscht)
 
subroutine projgr (n, l, u, nbd, x, g, sbgnrm)
 
subroutine subsm (n, m, nsub, ind, l, u, nbd, x, d, xp, ws, wy, theta, xx, gg, col, head, iword, wv, wn, iprint, info)
 
subroutine dcsrch (f, g, stp, ftol, gtol, xtol, stpmin, stpmax, task, isave, dsave)
 
subroutine dcstep (stx, fx, dx, sty, fy, dy, stp, fp, dp, brackt, stpmin, stpmax)
 

Function/Subroutine Documentation

◆ active()

subroutine active ( integer  n,
double precision, dimension(n)  l,
double precision, dimension(n)  u,
integer, dimension(n)  nbd,
double precision, dimension(n)  x,
integer, dimension(n)  iwhere,
integer  iprint,
logical  prjctd,
logical  cnstnd,
logical  boxed 
)
1006 
1007  logical prjctd, cnstnd, boxed
1008  integer n, iprint, nbd(n), iwhere(n)
1009  double precision x(n), l(n), u(n)
1010 
1011 c ************
1012 c
1013 c Subroutine active
1014 c
1015 c This subroutine initializes iwhere and projects the initial x to
1016 c the feasible set if necessary.
1017 c
1018 c iwhere is an integer array of dimension n.
1019 c On entry iwhere is unspecified.
1020 c On exit iwhere(i)=-1 if x(i) has no bounds
1021 c 3 if l(i)=u(i)
1022 c 0 otherwise.
1023 c In cauchy, iwhere is given finer gradations.
1024 c
1025 c
1026 c * * *
1027 c
1028 c NEOS, November 1994. (Latest revision June 1996.)
1029 c Optimization Technology Center.
1030 c Argonne National Laboratory and Northwestern University.
1031 c Written by
1032 c Ciyou Zhu
1033 c in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal.
1034 c
1035 c
1036 c ************
1037 
1038  integer nbdd,i
1039  double precision zero
1040  parameter(zero=0.0d0)
1041 
1042 c Initialize nbdd, prjctd, cnstnd and boxed.
1043 
1044  nbdd = 0
1045  prjctd = .false.
1046  cnstnd = .false.
1047  boxed = .true.
1048 
1049 c Project the initial x to the easible set if necessary.
1050 
1051  do 10 i = 1, n
1052  if (nbd(i) .gt. 0) then
1053  if (nbd(i) .le. 2 .and. x(i) .le. l(i)) then
1054  if (x(i) .lt. l(i)) then
1055  prjctd = .true.
1056  x(i) = l(i)
1057  endif
1058  nbdd = nbdd + 1
1059  else if (nbd(i) .ge. 2 .and. x(i) .ge. u(i)) then
1060  if (x(i) .gt. u(i)) then
1061  prjctd = .true.
1062  x(i) = u(i)
1063  endif
1064  nbdd = nbdd + 1
1065  endif
1066  endif
1067  10 continue
1068 
1069 c Initialize iwhere and assign values to cnstnd and boxed.
1070 
1071  do 20 i = 1, n
1072  if (nbd(i) .ne. 2) boxed = .false.
1073  if (nbd(i) .eq. 0) then
1074 c this variable is always free
1075  iwhere(i) = -1
1076 
1077 c otherwise set x(i)=mid(x(i), u(i), l(i)).
1078  else
1079  cnstnd = .true.
1080  if (nbd(i) .eq. 2 .and. u(i) - l(i) .le. zero) then
1081 c this variable is always fixed
1082  iwhere(i) = 3
1083  else
1084  iwhere(i) = 0
1085  endif
1086  endif
1087  20 continue
1088 
1089  if (iprint .ge. 0) then
1090  if (prjctd) write (6,*)
1091  + 'The initial X is infeasible. Restart with its projection.'
1092  if (.not. cnstnd)
1093  + write (6,*) 'This problem is unconstrained.'
1094  endif
1095 
1096  if (iprint .gt. 0) write (6,1001) nbdd
1097 
1098  1001 format (/,'At X0 ',i9,' variables are exactly at the bounds')
1099 
1100  return
1101 

◆ bmv()

subroutine bmv ( integer  m,
double precision, dimension(m, m)  sy,
double precision, dimension(m, m)  wt,
integer  col,
double precision, dimension(2*col)  v,
double precision, dimension(2*col)  p,
integer  info 
)
1107 
1108  integer m, col, info
1109  double precision sy(m, m), wt(m, m), v(2*col), p(2*col)
1110 
1111 c ************
1112 c
1113 c Subroutine bmv
1114 c
1115 c This subroutine computes the product of the 2m x 2m middle matrix
1116 c in the compact L-BFGS formula of B and a 2m vector v;
1117 c it returns the product in p.
1118 c
1119 c m is an integer variable.
1120 c On entry m is the maximum number of variable metric corrections
1121 c used to define the limited memory matrix.
1122 c On exit m is unchanged.
1123 c
1124 c sy is a double precision array of dimension m x m.
1125 c On entry sy specifies the matrix S'Y.
1126 c On exit sy is unchanged.
1127 c
1128 c wt is a double precision array of dimension m x m.
1129 c On entry wt specifies the upper triangular matrix J' which is
1130 c the Cholesky factor of (thetaS'S+LD^(-1)L').
1131 c On exit wt is unchanged.
1132 c
1133 c col is an integer variable.
1134 c On entry col specifies the number of s-vectors (or y-vectors)
1135 c stored in the compact L-BFGS formula.
1136 c On exit col is unchanged.
1137 c
1138 c v is a double precision array of dimension 2col.
1139 c On entry v specifies vector v.
1140 c On exit v is unchanged.
1141 c
1142 c p is a double precision array of dimension 2col.
1143 c On entry p is unspecified.
1144 c On exit p is the product Mv.
1145 c
1146 c info is an integer variable.
1147 c On entry info is unspecified.
1148 c On exit info = 0 for normal return,
1149 c = nonzero for abnormal return when the system
1150 c to be solved by dtrsl is singular.
1151 c
1152 c Subprograms called:
1153 c
1154 c Linpack ... dtrsl.
1155 c
1156 c
1157 c * * *
1158 c
1159 c NEOS, November 1994. (Latest revision June 1996.)
1160 c Optimization Technology Center.
1161 c Argonne National Laboratory and Northwestern University.
1162 c Written by
1163 c Ciyou Zhu
1164 c in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal.
1165 c
1166 c
1167 c ************
1168 
1169  integer i,k,i2
1170  double precision sum
1171 
1172  if (col .eq. 0) return
1173 
1174 c PART I: solve [ D^(1/2) O ] [ p1 ] = [ v1 ]
1175 c [ -L*D^(-1/2) J ] [ p2 ] [ v2 ].
1176 
1177 c solve Jp2=v2+LD^(-1)v1.
1178  p(col + 1) = v(col + 1)
1179  do 20 i = 2, col
1180  i2 = col + i
1181  sum = 0.0d0
1182  do 10 k = 1, i - 1
1183  sum = sum + sy(i,k)*v(k)/sy(k,k)
1184  10 continue
1185  p(i2) = v(i2) + sum
1186  20 continue
1187 c Solve the triangular system
1188  call dtrsl(wt,m,col,p(col+1),11,info)
1189  if (info .ne. 0) return
1190 
1191 c solve D^(1/2)p1=v1.
1192  do 30 i = 1, col
1193  p(i) = v(i)/sqrt(sy(i,i))
1194  30 continue
1195 
1196 c PART II: solve [ -D^(1/2) D^(-1/2)*L' ] [ p1 ] = [ p1 ]
1197 c [ 0 J' ] [ p2 ] [ p2 ].
1198 
1199 c solve J^Tp2=p2.
1200  call dtrsl(wt,m,col,p(col+1),01,info)
1201  if (info .ne. 0) return
1202 
1203 c compute p1=-D^(-1/2)(p1-D^(-1/2)L'p2)
1204 c =-D^(-1/2)p1+D^(-1)L'p2.
1205  do 40 i = 1, col
1206  p(i) = -p(i)/sqrt(sy(i,i))
1207  40 continue
1208  do 60 i = 1, col
1209  sum = 0.d0
1210  do 50 k = i + 1, col
1211  sum = sum + sy(k,i)*p(col+k)/sy(i,i)
1212  50 continue
1213  p(i) = p(i) + sum
1214  60 continue
1215 
1216  return
1217 
subroutine dtrsl(t, ldt, n, b, job, info)
Definition: linpack.f:82

◆ cauchy()

subroutine cauchy ( integer  n,
double precision, dimension(n)  x,
double precision, dimension(n)  l,
double precision, dimension(n)  u,
integer, dimension(n)  nbd,
double precision, dimension(n)  g,
integer, dimension(n)  iorder,
integer, dimension(n)  iwhere,
double precision, dimension(n)  t,
double precision, dimension(n)  d,
double precision, dimension(n)  xcp,
integer  m,
double precision, dimension(n, col)  wy,
double precision, dimension(n, col)  ws,
double precision, dimension(m, m)  sy,
double precision, dimension(m, m)  wt,
double precision  theta,
integer  col,
integer  head,
double precision, dimension(2*m)  p,
double precision, dimension(2*m)  c,
double precision, dimension(2*m)  wbp,
double precision, dimension(2*m)  v,
integer  nseg,
integer  iprint,
double precision  sbgnrm,
integer  info,
double precision  epsmch 
)
1225  implicit none
1226  integer n, m, head, col, nseg, iprint, info,
1227  + nbd(n), iorder(n), iwhere(n)
1228  double precision theta, epsmch,
1229  + x(n), l(n), u(n), g(n), t(n), d(n), xcp(n),
1230  + wy(n, col), ws(n, col), sy(m, m),
1231  + wt(m, m), p(2*m), c(2*m), wbp(2*m), v(2*m)
1232 
1233 c ************
1234 c
1235 c Subroutine cauchy
1236 c
1237 c For given x, l, u, g (with sbgnrm > 0), and a limited memory
1238 c BFGS matrix B defined in terms of matrices WY, WS, WT, and
1239 c scalars head, col, and theta, this subroutine computes the
1240 c generalized Cauchy point (GCP), defined as the first local
1241 c minimizer of the quadratic
1242 c
1243 c Q(x + s) = g's + 1/2 s'Bs
1244 c
1245 c along the projected gradient direction P(x-tg,l,u).
1246 c The routine returns the GCP in xcp.
1247 c
1248 c n is an integer variable.
1249 c On entry n is the dimension of the problem.
1250 c On exit n is unchanged.
1251 c
1252 c x is a double precision array of dimension n.
1253 c On entry x is the starting point for the GCP computation.
1254 c On exit x is unchanged.
1255 c
1256 c l is a double precision array of dimension n.
1257 c On entry l is the lower bound of x.
1258 c On exit l is unchanged.
1259 c
1260 c u is a double precision array of dimension n.
1261 c On entry u is the upper bound of x.
1262 c On exit u is unchanged.
1263 c
1264 c nbd is an integer array of dimension n.
1265 c On entry nbd represents the type of bounds imposed on the
1266 c variables, and must be specified as follows:
1267 c nbd(i)=0 if x(i) is unbounded,
1268 c 1 if x(i) has only a lower bound,
1269 c 2 if x(i) has both lower and upper bounds, and
1270 c 3 if x(i) has only an upper bound.
1271 c On exit nbd is unchanged.
1272 c
1273 c g is a double precision array of dimension n.
1274 c On entry g is the gradient of f(x). g must be a nonzero vector.
1275 c On exit g is unchanged.
1276 c
1277 c iorder is an integer working array of dimension n.
1278 c iorder will be used to store the breakpoints in the piecewise
1279 c linear path and free variables encountered. On exit,
1280 c iorder(1),...,iorder(nleft) are indices of breakpoints
1281 c which have not been encountered;
1282 c iorder(nleft+1),...,iorder(nbreak) are indices of
1283 c encountered breakpoints; and
1284 c iorder(nfree),...,iorder(n) are indices of variables which
1285 c have no bound constraits along the search direction.
1286 c
1287 c iwhere is an integer array of dimension n.
1288 c On entry iwhere indicates only the permanently fixed (iwhere=3)
1289 c or free (iwhere= -1) components of x.
1290 c On exit iwhere records the status of the current x variables.
1291 c iwhere(i)=-3 if x(i) is free and has bounds, but is not moved
1292 c 0 if x(i) is free and has bounds, and is moved
1293 c 1 if x(i) is fixed at l(i), and l(i) .ne. u(i)
1294 c 2 if x(i) is fixed at u(i), and u(i) .ne. l(i)
1295 c 3 if x(i) is always fixed, i.e., u(i)=x(i)=l(i)
1296 c -1 if x(i) is always free, i.e., it has no bounds.
1297 c
1298 c t is a double precision working array of dimension n.
1299 c t will be used to store the break points.
1300 c
1301 c d is a double precision array of dimension n used to store
1302 c the Cauchy direction P(x-tg)-x.
1303 c
1304 c xcp is a double precision array of dimension n used to return the
1305 c GCP on exit.
1306 c
1307 c m is an integer variable.
1308 c On entry m is the maximum number of variable metric corrections
1309 c used to define the limited memory matrix.
1310 c On exit m is unchanged.
1311 c
1312 c ws, wy, sy, and wt are double precision arrays.
1313 c On entry they store information that defines the
1314 c limited memory BFGS matrix:
1315 c ws(n,m) stores S, a set of s-vectors;
1316 c wy(n,m) stores Y, a set of y-vectors;
1317 c sy(m,m) stores S'Y;
1318 c wt(m,m) stores the
1319 c Cholesky factorization of (theta*S'S+LD^(-1)L').
1320 c On exit these arrays are unchanged.
1321 c
1322 c theta is a double precision variable.
1323 c On entry theta is the scaling factor specifying B_0 = theta I.
1324 c On exit theta is unchanged.
1325 c
1326 c col is an integer variable.
1327 c On entry col is the actual number of variable metric
1328 c corrections stored so far.
1329 c On exit col is unchanged.
1330 c
1331 c head is an integer variable.
1332 c On entry head is the location of the first s-vector (or y-vector)
1333 c in S (or Y).
1334 c On exit col is unchanged.
1335 c
1336 c p is a double precision working array of dimension 2m.
1337 c p will be used to store the vector p = W^(T)d.
1338 c
1339 c c is a double precision working array of dimension 2m.
1340 c c will be used to store the vector c = W^(T)(xcp-x).
1341 c
1342 c wbp is a double precision working array of dimension 2m.
1343 c wbp will be used to store the row of W corresponding
1344 c to a breakpoint.
1345 c
1346 c v is a double precision working array of dimension 2m.
1347 c
1348 c nseg is an integer variable.
1349 c On exit nseg records the number of quadratic segments explored
1350 c in searching for the GCP.
1351 c
1352 c sg and yg are double precision arrays of dimension m.
1353 c On entry sg and yg store S'g and Y'g correspondingly.
1354 c On exit they are unchanged.
1355 c
1356 c iprint is an INTEGER variable that must be set by the user.
1357 c It controls the frequency and type of output generated:
1358 c iprint<0 no output is generated;
1359 c iprint=0 print only one line at the last iteration;
1360 c 0<iprint<99 print also f and |proj g| every iprint iterations;
1361 c iprint=99 print details of every iteration except n-vectors;
1362 c iprint=100 print also the changes of active set and final x;
1363 c iprint>100 print details of every iteration including x and g;
1364 c When iprint > 0, the file iterate.dat will be created to
1365 c summarize the iteration.
1366 c
1367 c sbgnrm is a double precision variable.
1368 c On entry sbgnrm is the norm of the projected gradient at x.
1369 c On exit sbgnrm is unchanged.
1370 c
1371 c info is an integer variable.
1372 c On entry info is 0.
1373 c On exit info = 0 for normal return,
1374 c = nonzero for abnormal return when the the system
1375 c used in routine bmv is singular.
1376 c
1377 c Subprograms called:
1378 c
1379 c L-BFGS-B Library ... hpsolb, bmv.
1380 c
1381 c Linpack ... dscal dcopy, daxpy.
1382 c
1383 c
1384 c References:
1385 c
1386 c [1] R. H. Byrd, P. Lu, J. Nocedal and C. Zhu, ``A limited
1387 c memory algorithm for bound constrained optimization'',
1388 c SIAM J. Scientific Computing 16 (1995), no. 5, pp. 1190--1208.
1389 c
1390 c [2] C. Zhu, R.H. Byrd, P. Lu, J. Nocedal, ``L-BFGS-B: FORTRAN
1391 c Subroutines for Large Scale Bound Constrained Optimization''
1392 c Tech. Report, NAM-11, EECS Department, Northwestern University,
1393 c 1994.
1394 c
1395 c (Postscript files of these papers are available via anonymous
1396 c ftp to eecs.nwu.edu in the directory pub/lbfgs/lbfgs_bcm.)
1397 c
1398 c * * *
1399 c
1400 c NEOS, November 1994. (Latest revision June 1996.)
1401 c Optimization Technology Center.
1402 c Argonne National Laboratory and Northwestern University.
1403 c Written by
1404 c Ciyou Zhu
1405 c in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal.
1406 c
1407 c
1408 c ************
1409 
1410  logical xlower,xupper,bnded
1411  integer i,j,col2,nfree,nbreak,pointr,
1412  + ibp,nleft,ibkmin,iter
1413  double precision f1,f2,dt,dtm,tsum,dibp,zibp,dibp2,bkmin,
1414  + tu,tl,wmc,wmp,wmw,ddot,tj,tj0,neggi,sbgnrm,
1415  + f2_org
1416  double precision one,zero
1417  parameter(one=1.0d0,zero=0.0d0)
1418 
1419 c Check the status of the variables, reset iwhere(i) if necessary;
1420 c compute the Cauchy direction d and the breakpoints t; initialize
1421 c the derivative f1 and the vector p = W'd (for theta = 1).
1422 
1423  if (sbgnrm .le. zero) then
1424  if (iprint .ge. 0) write (6,*) 'Subgnorm = 0. GCP = X.'
1425  call dcopy(n,x,1,xcp,1)
1426  return
1427  endif
1428  bnded = .true.
1429  nfree = n + 1
1430  nbreak = 0
1431  ibkmin = 0
1432  bkmin = zero
1433  col2 = 2*col
1434  f1 = zero
1435  if (iprint .ge. 99) write (6,3010)
1436 
1437 c We set p to zero and build it up as we determine d.
1438 
1439  do 20 i = 1, col2
1440  p(i) = zero
1441  20 continue
1442 
1443 c In the following loop we determine for each variable its bound
1444 c status and its breakpoint, and update p accordingly.
1445 c Smallest breakpoint is identified.
1446 
1447  do 50 i = 1, n
1448  neggi = -g(i)
1449  if (iwhere(i) .ne. 3 .and. iwhere(i) .ne. -1) then
1450 c if x(i) is not a constant and has bounds,
1451 c compute the difference between x(i) and its bounds.
1452  if (nbd(i) .le. 2) tl = x(i) - l(i)
1453  if (nbd(i) .ge. 2) tu = u(i) - x(i)
1454 
1455 c If a variable is close enough to a bound
1456 c we treat it as at bound.
1457  xlower = nbd(i) .le. 2 .and. tl .le. zero
1458  xupper = nbd(i) .ge. 2 .and. tu .le. zero
1459 
1460 c reset iwhere(i).
1461  iwhere(i) = 0
1462  if (xlower) then
1463  if (neggi .le. zero) iwhere(i) = 1
1464  else if (xupper) then
1465  if (neggi .ge. zero) iwhere(i) = 2
1466  else
1467  if (abs(neggi) .le. zero) iwhere(i) = -3
1468  endif
1469  endif
1470  pointr = head
1471  if (iwhere(i) .ne. 0 .and. iwhere(i) .ne. -1) then
1472  d(i) = zero
1473  else
1474  d(i) = neggi
1475  f1 = f1 - neggi*neggi
1476 c calculate p := p - W'e_i* (g_i).
1477  do 40 j = 1, col
1478  p(j) = p(j) + wy(i,pointr)* neggi
1479  p(col + j) = p(col + j) + ws(i,pointr)*neggi
1480  pointr = mod(pointr,m) + 1
1481  40 continue
1482  if (nbd(i) .le. 2 .and. nbd(i) .ne. 0
1483  + .and. neggi .lt. zero) then
1484 c x(i) + d(i) is bounded; compute t(i).
1485  nbreak = nbreak + 1
1486  iorder(nbreak) = i
1487  t(nbreak) = tl/(-neggi)
1488  if (nbreak .eq. 1 .or. t(nbreak) .lt. bkmin) then
1489  bkmin = t(nbreak)
1490  ibkmin = nbreak
1491  endif
1492  else if (nbd(i) .ge. 2 .and. neggi .gt. zero) then
1493 c x(i) + d(i) is bounded; compute t(i).
1494  nbreak = nbreak + 1
1495  iorder(nbreak) = i
1496  t(nbreak) = tu/neggi
1497  if (nbreak .eq. 1 .or. t(nbreak) .lt. bkmin) then
1498  bkmin = t(nbreak)
1499  ibkmin = nbreak
1500  endif
1501  else
1502 c x(i) + d(i) is not bounded.
1503  nfree = nfree - 1
1504  iorder(nfree) = i
1505  if (abs(neggi) .gt. zero) bnded = .false.
1506  endif
1507  endif
1508  50 continue
1509 
1510 c The indices of the nonzero components of d are now stored
1511 c in iorder(1),...,iorder(nbreak) and iorder(nfree),...,iorder(n).
1512 c The smallest of the nbreak breakpoints is in t(ibkmin)=bkmin.
1513 
1514  if (theta .ne. one) then
1515 c complete the initialization of p for theta not= one.
1516  call dscal(col,theta,p(col+1),1)
1517  endif
1518 
1519 c Initialize GCP xcp = x.
1520 
1521  call dcopy(n,x,1,xcp,1)
1522 
1523  if (nbreak .eq. 0 .and. nfree .eq. n + 1) then
1524 c is a zero vector, return with the initial xcp as GCP.
1525  if (iprint .gt. 100) write (6,1010) (xcp(i), i = 1, n)
1526  return
1527  endif
1528 
1529 c Initialize c = W'(xcp - x) = 0.
1530 
1531  do 60 j = 1, col2
1532  c(j) = zero
1533  60 continue
1534 
1535 c Initialize derivative f2.
1536 
1537  f2 = -theta*f1
1538  f2_org = f2
1539  if (col .gt. 0) then
1540  call bmv(m,sy,wt,col,p,v,info)
1541  if (info .ne. 0) return
1542  f2 = f2 - ddot(col2,v,1,p,1)
1543  endif
1544  dtm = -f1/f2
1545  tsum = zero
1546  nseg = 1
1547  if (iprint .ge. 99)
1548  + write (6,*) 'There are ',nbreak,' breakpoints '
1549 
1550 c If there are no breakpoints, locate the GCP and return.
1551 
1552  if (nbreak .eq. 0) goto 888
1553 
1554  nleft = nbreak
1555  iter = 1
1556 
1557 
1558  tj = zero
1559 
1560 c------------------- the beginning of the loop -------------------------
1561 
1562  777 continue
1563 
1564 c Find the next smallest breakpoint;
1565 c compute dt = t(nleft) - t(nleft + 1).
1566 
1567  tj0 = tj
1568  if (iter .eq. 1) then
1569 c Since we already have the smallest breakpoint we need not do
1570 c heapsort yet. Often only one breakpoint is used and the
1571 c cost of heapsort is avoided.
1572  tj = bkmin
1573  ibp = iorder(ibkmin)
1574  else
1575  if (iter .eq. 2) then
1576 c Replace the already used smallest breakpoint with the
1577 c breakpoint numbered nbreak > nlast, before heapsort call.
1578  if (ibkmin .ne. nbreak) then
1579  t(ibkmin) = t(nbreak)
1580  iorder(ibkmin) = iorder(nbreak)
1581  endif
1582 c Update heap structure of breakpoints
1583 c (if iter=2, initialize heap).
1584  endif
1585  call hpsolb(nleft,t,iorder,iter-2)
1586  tj = t(nleft)
1587  ibp = iorder(nleft)
1588  endif
1589 
1590  dt = tj - tj0
1591 
1592  if (dt .ne. zero .and. iprint .ge. 100) then
1593  write (6,4011) nseg,f1,f2
1594  write (6,5010) dt
1595  write (6,6010) dtm
1596  endif
1597 
1598 c If a minimizer is within this interval, locate the GCP and return.
1599 
1600  if (dtm .lt. dt) goto 888
1601 
1602 c Otherwise fix one variable and
1603 c reset the corresponding component of d to zero.
1604 
1605  tsum = tsum + dt
1606  nleft = nleft - 1
1607  iter = iter + 1
1608  dibp = d(ibp)
1609  d(ibp) = zero
1610  if (dibp .gt. zero) then
1611  zibp = u(ibp) - x(ibp)
1612  xcp(ibp) = u(ibp)
1613  iwhere(ibp) = 2
1614  else
1615  zibp = l(ibp) - x(ibp)
1616  xcp(ibp) = l(ibp)
1617  iwhere(ibp) = 1
1618  endif
1619  if (iprint .ge. 100) write (6,*) 'Variable ',ibp,' is fixed.'
1620  if (nleft .eq. 0 .and. nbreak .eq. n) then
1621 c all n variables are fixed,
1622 c return with xcp as GCP.
1623  dtm = dt
1624  goto 999
1625  endif
1626 
1627 c Update the derivative information.
1628 
1629  nseg = nseg + 1
1630  dibp2 = dibp**2
1631 
1632 c Update f1 and f2.
1633 
1634 c temporarily set f1 and f2 for col=0.
1635  f1 = f1 + dt*f2 + dibp2 - theta*dibp*zibp
1636  f2 = f2 - theta*dibp2
1637 
1638  if (col .gt. 0) then
1639 c update c = c + dt*p.
1640  call daxpy(col2,dt,p,1,c,1)
1641 
1642 c choose wbp,
1643 c the row of W corresponding to the breakpoint encountered.
1644  pointr = head
1645  do 70 j = 1,col
1646  wbp(j) = wy(ibp,pointr)
1647  wbp(col + j) = theta*ws(ibp,pointr)
1648  pointr = mod(pointr,m) + 1
1649  70 continue
1650 
1651 c compute (wbp)Mc, (wbp)Mp, and (wbp)M(wbp)'.
1652  call bmv(m,sy,wt,col,wbp,v,info)
1653  if (info .ne. 0) return
1654  wmc = ddot(col2,c,1,v,1)
1655  wmp = ddot(col2,p,1,v,1)
1656  wmw = ddot(col2,wbp,1,v,1)
1657 
1658 c update p = p - dibp*wbp.
1659  call daxpy(col2,-dibp,wbp,1,p,1)
1660 
1661 c complete updating f1 and f2 while col > 0.
1662  f1 = f1 + dibp*wmc
1663  f2 = f2 + 2.0d0*dibp*wmp - dibp2*wmw
1664  endif
1665 
1666  f2 = max(epsmch*f2_org,f2)
1667  if (nleft .gt. 0) then
1668  dtm = -f1/f2
1669  goto 777
1670 c to repeat the loop for unsearched intervals.
1671  else if(bnded) then
1672  f1 = zero
1673  f2 = zero
1674  dtm = zero
1675  else
1676  dtm = -f1/f2
1677  endif
1678 
1679 c------------------- the end of the loop -------------------------------
1680 
1681  888 continue
1682  if (iprint .ge. 99) then
1683  write (6,*)
1684  write (6,*) 'GCP found in this segment'
1685  write (6,4010) nseg,f1,f2
1686  write (6,6010) dtm
1687  endif
1688  if (dtm .le. zero) dtm = zero
1689  tsum = tsum + dtm
1690 
1691 c Move free variables (i.e., the ones w/o breakpoints) and
1692 c the variables whose breakpoints haven't been reached.
1693 
1694  call daxpy(n,tsum,d,1,xcp,1)
1695 
1696  999 continue
1697 
1698 c Update c = c + dtm*p = W'(x^c - x)
1699 c which will be used in computing r = Z'(B(x^c - x) + g).
1700 
1701  if (col .gt. 0) call daxpy(col2,dtm,p,1,c,1)
1702  if (iprint .gt. 100) write (6,1010) (xcp(i),i = 1,n)
1703  if (iprint .ge. 99) write (6,2010)
1704 
1705  1010 format ('Cauchy X = ',/,(4x,1p,6(1x,d11.4)))
1706  2010 format (/,'---------------- exit CAUCHY----------------------',/)
1707  3010 format (/,'---------------- CAUCHY entered-------------------')
1708  4010 format ('Piece ',i3,' --f1, f2 at start point ',1p,2(1x,d11.4))
1709  4011 format (/,'Piece ',i3,' --f1, f2 at start point ',
1710  + 1p,2(1x,d11.4))
1711  5010 format ('Distance to the next break point = ',1p,d11.4)
1712  6010 format ('Distance to the stationary point = ',1p,d11.4)
1713 
1714  return
1715 
#define max(a, b)
Definition: cascade.c:32
subroutine dcopy(N, DX, INCX, DY, INCY)
Definition: dgmres.f:1381
subroutine bmv(m, sy, wt, col, v, p, info)
Definition: lbfgsb.f:1107
subroutine daxpy(N, DA, DX, INCX, DY, INCY)
Definition: dgmres.f:1276
subroutine dscal(n, da, dx, incx)
Definition: dgesv.f:1746
static double * f1
Definition: objectivemain_se.c:47
double precision function ddot(N, DX, INCX, DY, INCY)
Definition: dgmres.f:2469
subroutine hpsolb(n, t, iorder, iheap)
Definition: lbfgsb.f:2342

◆ cmprlb()

subroutine cmprlb ( integer  n,
integer  m,
double precision, dimension(n)  x,
double precision, dimension(n)  g,
double precision, dimension(n, m)  ws,
double precision, dimension(n, m)  wy,
double precision, dimension(m, m)  sy,
double precision, dimension(m, m)  wt,
double precision, dimension(n)  z,
double precision, dimension(n)  r,
double precision, dimension(4*m)  wa,
integer, dimension(n)  index,
double precision  theta,
integer  col,
integer  head,
integer  nfree,
logical  cnstnd,
integer  info 
)
1722 
1723  logical cnstnd
1724  integer n, m, col, head, nfree, info, index(n)
1725  double precision theta,
1726  + x(n), g(n), z(n), r(n), wa(4*m),
1727  + ws(n, m), wy(n, m), sy(m, m), wt(m, m)
1728 
1729 c ************
1730 c
1731 c Subroutine cmprlb
1732 c
1733 c This subroutine computes r=-Z'B(xcp-xk)-Z'g by using
1734 c wa(2m+1)=W'(xcp-x) from subroutine cauchy.
1735 c
1736 c Subprograms called:
1737 c
1738 c L-BFGS-B Library ... bmv.
1739 c
1740 c
1741 c * * *
1742 c
1743 c NEOS, November 1994. (Latest revision June 1996.)
1744 c Optimization Technology Center.
1745 c Argonne National Laboratory and Northwestern University.
1746 c Written by
1747 c Ciyou Zhu
1748 c in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal.
1749 c
1750 c
1751 c ************
1752 
1753  integer i,j,k,pointr
1754  double precision a1,a2
1755 
1756  if (.not. cnstnd .and. col .gt. 0) then
1757  do 26 i = 1, n
1758  r(i) = -g(i)
1759  26 continue
1760  else
1761  do 30 i = 1, nfree
1762  k = index(i)
1763  r(i) = -theta*(z(k) - x(k)) - g(k)
1764  30 continue
1765  call bmv(m,sy,wt,col,wa(2*m+1),wa(1),info)
1766  if (info .ne. 0) then
1767  info = -8
1768  return
1769  endif
1770  pointr = head
1771  do 34 j = 1, col
1772  a1 = wa(j)
1773  a2 = theta*wa(col + j)
1774  do 32 i = 1, nfree
1775  k = index(i)
1776  r(i) = r(i) + wy(k,pointr)*a1 + ws(k,pointr)*a2
1777  32 continue
1778  pointr = mod(pointr,m) + 1
1779  34 continue
1780  endif
1781 
1782  return
1783 
subroutine bmv(m, sy, wt, col, v, p, info)
Definition: lbfgsb.f:1107

◆ dcsrch()

subroutine dcsrch ( double precision  f,
double precision  g,
double precision  stp,
double precision  ftol,
double precision  gtol,
double precision  xtol,
double precision  stpmin,
double precision  stpmax,
character*(*)  task,
integer, dimension(2)  isave,
double precision, dimension(13)  dsave 
)
3349  character*(*) task
3350  integer isave(2)
3351  double precision f,g,stp,ftol,gtol,xtol,stpmin,stpmax
3352  double precision dsave(13)
3353 c **********
3354 c
3355 c Subroutine dcsrch
3356 c
3357 c this subroutine finds a step that satisfies a sufficient
3358 c decrease condition and a curvature condition.
3359 c
3360 c each call of the subroutine updates an interval with
3361 c endpoints stx and sty. the interval is initially chosen
3362 c so that it contains a minimizer of the modified function
3363 c
3364 c psi(stp) = f(stp) - f(0) - ftol*stp*f'(0).
3365 c
3366 c If psi(stp) <= 0 and f'(stp) >= 0 for some step, then the
3367 c interval is chosen so that it contains a minimizer of f.
3368 c
3369 c the algorithm is designed to find a step that satisfies
3370 c the sufficient decrease condition
3371 c
3372 c f(stp) <= f(0) + ftol*stp*f'(0),
3373 c
3374 c and the curvature condition
3375 c
3376 c abs(f'(stp)) <= gtol*abs(f'(0)).
3377 c
3378 c If ftol is less than gtol and if, for example, the function
3379 c is bounded below, then there is always a step which satisfies
3380 c both conditions.
3381 c
3382 c If no step can be found that satisfies both conditions, then
3383 c the algorithm stops with a warning. In this case stp only
3384 c satisfies the sufficient decrease condition.
3385 c
3386 c A typical invocation of dcsrch has the following outline:
3387 c
3388 c task = 'start'
3389 c 10 continue
3390 c call dcsrch( ... )
3391 .eq.c if (task 'fg') then
3392 c Evaluate the function and the gradient at stp
3393 c goto 10
3394 c end if
3395 c
3396 c NOTE: The user must no alter work arrays between calls.
3397 c
3398 c The subroutine statement is
3399 c
3400 c subroutine dcsrch(f,g,stp,ftol,gtol,xtol,stpmin,stpmax,
3401 c task,isave,dsave)
3402 c where
3403 c
3404 c f is a double precision variable.
3405 c On initial entry f is the value of the function at 0.
3406 c On subsequent entries f is the value of the
3407 c function at stp.
3408 c On exit f is the value of the function at stp.
3409 c
3410 c g is a double precision variable.
3411 c On initial entry g is the derivative of the function at 0.
3412 c On subsequent entries g is the derivative of the
3413 c function at stp.
3414 c On exit g is the derivative of the function at stp.
3415 c
3416 c stp is a double precision variable.
3417 c On entry stp is the current estimate of a satisfactory
3418 c step. On initial entry, a positive initial estimate
3419 c must be provided.
3420 c On exit stp is the current estimate of a satisfactory step
3421 c if task = 'fg'. If task = 'conv' then stp satisfies
3422 c the sufficient decrease and curvature condition.
3423 c
3424 c ftol is a double precision variable.
3425 c On entry ftol specifies a nonnegative tolerance for the
3426 c sufficient decrease condition.
3427 c On exit ftol is unchanged.
3428 c
3429 c gtol is a double precision variable.
3430 c On entry gtol specifies a nonnegative tolerance for the
3431 c curvature condition.
3432 c On exit gtol is unchanged.
3433 c
3434 c xtol is a double precision variable.
3435 c On entry xtol specifies a nonnegative relative tolerance
3436 c for an acceptable step. The subroutine exits with a
3437 c warning if the relative difference between sty and stx
3438 c is less than xtol.
3439 c On exit xtol is unchanged.
3440 c
3441 c stpmin is a double precision variable.
3442 c On entry stpmin is a nonnegative lower bound for the step.
3443 c On exit stpmin is unchanged.
3444 c
3445 c stpmax is a double precision variable.
3446 c On entry stpmax is a nonnegative upper bound for the step.
3447 c On exit stpmax is unchanged.
3448 c
3449 c task is a character variable of length at least 60.
3450 c On initial entry task must be set to 'start'.
3451 c On exit task indicates the required action:
3452 c
3453 c If task(1:2) = 'fg' then evaluate the function and
3454 c derivative at stp and call dcsrch again.
3455 c
3456 c If task(1:4) = 'conv' then the search is successful.
3457 c
3458 c If task(1:4) = 'warn' then the subroutine is not able
3459 c to satisfy the convergence conditions. The exit value of
3460 c stp contains the best point found during the search.
3461 c
3462 c If task(1:5) = 'error' then there is an error in the
3463 c input arguments.
3464 c
3465 c On exit with convergence, a warning or an error, the
3466 c variable task contains additional information.
3467 c
3468 c isave is an integer work array of dimension 2.
3469 c
3470 c dsave is a double precision work array of dimension 13.
3471 c
3472 c Subprograms called
3473 c
3474 c MINPACK-2 ... dcstep
3475 c
3476 c MINPACK-1 Project. June 1983.
3477 c Argonne National Laboratory.
3478 c Jorge J. More' and david j. thuente.
3479 c
3480 c minpack-2 project. october 1993.
3481 c argonne national laboratory and university of minnesota.
3482 c brett m. averick, richard g. carter, and jorge j. more'.
3483 c
3484 c **********
3485  double precision zero,p5,p66
3486  parameter(zero=0.0d0,p5=0.5d0,p66=0.66d0)
3487  double precision xtrapl,xtrapu
3488  parameter(xtrapl=1.1d0,xtrapu=4.0d0)
3489 
3490  logical brackt
3491  integer stage
3492  double precision finit,ftest,fm,fx,fxm,fy,fym,ginit,gtest,
3493  + gm,gx,gxm,gy,gym,stx,sty,stmin,stmax,width,width1
3494 
3495 c Initialization block.
3496 
3497 .eq. if (task(1:5) 'start') then
3498 
3499 c Check the input arguments for errors.
3500 
3501 .lt. if (stp stpmin) task = 'error: stp .LT. stpmin'
3502 .gt. if (stp stpmax) task = 'error: stp .GT. stpmax'
3503 .ge. if (g zero) task = 'error: initial g .GE. zero'
3504 .lt. if (ftol zero) task = 'error: ftol .LT. zero'
3505 .lt. if (gtol zero) task = 'error: gtol .LT. zero'
3506 .lt. if (xtol zero) task = 'error: xtol .LT. zero'
3507 .lt. if (stpmin zero) task = 'error: stpmin .LT. zero'
3508 .lt. if (stpmax stpmin) task = 'error: stpmax .LT. stpmin'
3509 
3510 c Exit if there are errors on input.
3511 
3512 .eq. if (task(1:5) 'error') return
3513 
3514 c Initialize local variables.
3515 
3516  brackt = .false.
3517  stage = 1
3518  finit = f
3519  ginit = g
3520  gtest = ftol*ginit
3521  width = stpmax - stpmin
3522  width1 = width/p5
3523 
3524 c The variables stx, fx, gx contain the values of the step,
3525 c function, and derivative at the best step.
3526 c The variables sty, fy, gy contain the value of the step,
3527 c function, and derivative at sty.
3528 c The variables stp, f, g contain the values of the step,
3529 c function, and derivative at stp.
3530 
3531  stx = zero
3532  fx = finit
3533  gx = ginit
3534  sty = zero
3535  fy = finit
3536  gy = ginit
3537  stmin = zero
3538  stmax = stp + xtrapu*stp
3539  task = 'fg'
3540 
3541  goto 1000
3542 
3543  else
3544 
3545 c Restore local variables.
3546 
3547 .eq. if (isave(1) 1) then
3548  brackt = .true.
3549  else
3550  brackt = .false.
3551  endif
3552  stage = isave(2)
3553  ginit = dsave(1)
3554  gtest = dsave(2)
3555  gx = dsave(3)
3556  gy = dsave(4)
3557  finit = dsave(5)
3558  fx = dsave(6)
3559  fy = dsave(7)
3560  stx = dsave(8)
3561  sty = dsave(9)
3562  stmin = dsave(10)
3563  stmax = dsave(11)
3564  width = dsave(12)
3565  width1 = dsave(13)
3566 
3567  endif
3568 
3569 c If psi(stp) <= 0 and f'(stp) >= 0 for some step, then the
3570 c algorithm enters the second stage.
3571 
3572  ftest = finit + stp*gtest
3573  if (stage .eq. 1 .and. f .le. ftest .and. g .ge. zero)
3574  + stage = 2
3575 
3576 c test for warnings.
3577 
3578  if (brackt .and. (stp .le. stmin .or. stp .ge. stmax))
3579  + task = 'WARNING: ROUNDING ERRORS PREVENT PROGRESS'
3580  if (brackt .and. stmax - stmin .le. xtol*stmax)
3581  + task = 'WARNING: XTOL TEST SATISFIED'
3582  if (stp .eq. stpmax .and. f .le. ftest .and. g .le. gtest)
3583  + task = 'WARNING: STP = STPMAX'
3584  if (stp .eq. stpmin .and. (f .gt. ftest .or. g .ge. gtest))
3585  + task = 'WARNING: STP = STPMIN'
3586 
3587 c test for convergence.
3588 
3589  if (f .le. ftest .and. abs(g) .le. gtol*(-ginit))
3590  + task = 'CONVERGENCE'
3591 
3592 c test for termination.
3593 
3594  if (task(1:4) .eq. 'WARN' .or. task(1:4) .eq. 'CONV') goto 1000
3595 
3596 c a modified function is used to predict the step during the
3597 c first stage if a lower function value has been obtained but
3598 c the decrease is not sufficient.
3599 
3600  if (stage .eq. 1 .and. f .le. fx .and. f .gt. ftest) then
3601 
3602 c define the modified function and derivative values.
3603 
3604  fm = f - stp*gtest
3605  fxm = fx - stx*gtest
3606  fym = fy - sty*gtest
3607  gm = g - gtest
3608  gxm = gx - gtest
3609  gym = gy - gtest
3610 
3611 c Call dcstep to update stx, sty, and to compute the new step.
3612 
3613  call dcstep(stx,fxm,gxm,sty,fym,gym,stp,fm,gm,
3614  + brackt,stmin,stmax)
3615 
3616 c reset the function and derivative values for f.
3617 
3618  fx = fxm + stx*gtest
3619  fy = fym + sty*gtest
3620  gx = gxm + gtest
3621  gy = gym + gtest
3622 
3623  else
3624 
3625 c Call dcstep to update stx, sty, and to compute the new step.
3626 
3627  call dcstep(stx,fx,gx,sty,fy,gy,stp,f,g,
3628  + brackt,stmin,stmax)
3629 
3630  endif
3631 
3632 c decide if a bisection step is needed.
3633 
3634  if (brackt) then
3635  if (abs(sty-stx) .ge. p66*width1) stp = stx + p5*(sty - stx)
3636  width1 = width
3637  width = abs(sty-stx)
3638  endif
3639 
3640 c set the minimum and maximum steps allowed for stp.
3641 
3642  if (brackt) then
3643  stmin = min(stx,sty)
3644  stmax = max(stx,sty)
3645  else
3646  stmin = stp + xtrapl*(stp - stx)
3647  stmax = stp + xtrapu*(stp - stx)
3648  endif
3649 
3650 c force the step to be within the bounds stpmax and stpmin.
3651 
3652  stp = max(stp,stpmin)
3653  stp = min(stp,stpmax)
3654 
3655 c If further progress is not possible, let stp be the best
3656 c point obtained during the search.
3657 
3658  if (brackt .and. (stp .le. stmin .or. stp .ge. stmax)
3659  + .or. (brackt .and. stmax-stmin .le. xtol*stmax)) stp = stx
3660 
3661 c obtain another function and derivative.
3662 
3663  task = 'FG'
3664 
3665  1000 continue
3666 
3667 c Save local variables.
3668 
3669  if (brackt) then
3670  isave(1) = 1
3671  else
3672  isave(1) = 0
3673  endif
3674  isave(2) = stage
3675  dsave(1) = ginit
3676  dsave(2) = gtest
3677  dsave(3) = gx
3678  dsave(4) = gy
3679  dsave(5) = finit
3680  dsave(6) = fx
3681  dsave(7) = fy
3682  dsave(8) = stx
3683  dsave(9) = sty
3684  dsave(10) = stmin
3685  dsave(11) = stmax
3686  dsave(12) = width
3687  dsave(13) = width1
3688 
3689  return
#define max(a, b)
Definition: cascade.c:32
#define min(a, b)
Definition: cascade.c:31
subroutine dcsrch(f, g, stp, ftol, gtol, xtol, stpmin, stpmax, task, isave, dsave)
Definition: lbfgsb.f:3349
subroutine steps(inpc, textpart, iperturb, iprestr, nbody, nforc, nload, ithermal, t0, t1, nk, irstrt, istep, istat, n, jmax, ctrl, iline, ipol, inl, ipoinp, inp, newstep, ipoinpc, network)
Definition: steps.f:22
subroutine dcstep(stx, fx, dx, sty, fy, dy, stp, fp, dp, brackt, stpmin, stpmax)
Definition: lbfgsb.f:3696

◆ dcstep()

subroutine dcstep ( double precision  stx,
double precision  fx,
double precision  dx,
double precision  sty,
double precision  fy,
double precision  dy,
double precision  stp,
double precision  fp,
double precision  dp,
logical  brackt,
double precision  stpmin,
double precision  stpmax 
)
3696  logical brackt
3697  double precision stx,fx,dx,sty,fy,dy,stp,fp,dp,stpmin,stpmax
3698 c **********
3699 c
3700 c Subroutine dcstep
3701 c
3702 c This subroutine computes a safeguarded step for a search
3703 c procedure and updates an interval that contains a step that
3704 c satisfies a sufficient decrease and a curvature condition.
3705 c
3706 c The parameter stx contains the step with the least function
3707 c value. If brackt is set to .true. then a minimizer has
3708 c been bracketed in an interval with endpoints stx and sty.
3709 c The parameter stp contains the current step.
3710 c The subroutine assumes that if brackt is set to .true. then
3711 c
3712 c min(stx,sty) < stp < max(stx,sty),
3713 c
3714 c and that the derivative at stx is negative in the direction
3715 c of the step.
3716 c
3717 c The subroutine statement is
3718 c
3719 c subroutine dcstep(stx,fx,dx,sty,fy,dy,stp,fp,dp,brackt,
3720 c stpmin,stpmax)
3721 c
3722 c where
3723 c
3724 c stx is a double precision variable.
3725 c On entry stx is the best step obtained so far and is an
3726 c endpoint of the interval that contains the minimizer.
3727 c On exit stx is the updated best step.
3728 c
3729 c fx is a double precision variable.
3730 c On entry fx is the function at stx.
3731 c On exit fx is the function at stx.
3732 c
3733 c dx is a double precision variable.
3734 c On entry dx is the derivative of the function at
3735 c stx. The derivative must be negative in the direction of
3736 c the step, that is, dx and stp - stx must have opposite
3737 c signs.
3738 c On exit dx is the derivative of the function at stx.
3739 c
3740 c sty is a double precision variable.
3741 c On entry sty is the second endpoint of the interval that
3742 c contains the minimizer.
3743 c On exit sty is the updated endpoint of the interval that
3744 c contains the minimizer.
3745 c
3746 c fy is a double precision variable.
3747 c On entry fy is the function at sty.
3748 c On exit fy is the function at sty.
3749 c
3750 c dy is a double precision variable.
3751 c On entry dy is the derivative of the function at sty.
3752 c On exit dy is the derivative of the function at the exit sty.
3753 c
3754 c stp is a double precision variable.
3755 c On entry stp is the current step. If brackt is set to .true.
3756 c then on input stp must be between stx and sty.
3757 c On exit stp is a new trial step.
3758 c
3759 c fp is a double precision variable.
3760 c On entry fp is the function at stp
3761 c On exit fp is unchanged.
3762 c
3763 c dp is a double precision variable.
3764 c On entry dp is the the derivative of the function at stp.
3765 c On exit dp is unchanged.
3766 c
3767 c brackt is an logical variable.
3768 c On entry brackt specifies if a minimizer has been bracketed.
3769 c Initially brackt must be set to .false.
3770 c On exit brackt specifies if a minimizer has been bracketed.
3771 c When a minimizer is bracketed brackt is set to .true.
3772 c
3773 c stpmin is a double precision variable.
3774 c On entry stpmin is a lower bound for the step.
3775 c On exit stpmin is unchanged.
3776 c
3777 c stpmax is a double precision variable.
3778 c On entry stpmax is an upper bound for the step.
3779 c On exit stpmax is unchanged.
3780 c
3781 c MINPACK-1 Project. June 1983
3782 c Argonne National Laboratory.
3783 c Jorge J. More' and David J. Thuente.
3784 c
3785 c MINPACK-2 Project. October 1993.
3786 c Argonne National Laboratory and University of Minnesota.
3787 c Brett M. Averick and Jorge J. More'.
3788 c
3789 c **********
3790  double precision zero,p66,two,three
3791  parameter(zero=0.0d0,p66=0.66d0,two=2.0d0,three=3.0d0)
3792 
3793  double precision gamma,p,q,r,s,sgnd,stpc,stpf,stpq,theta
3794 
3795  sgnd = dp*(dx/abs(dx))
3796 
3797 c First case: A higher function value. The minimum is bracketed.
3798 c If the cubic step is closer to stx than the quadratic step, the
3799 c cubic step is taken, otherwise the average of the cubic and
3800 c quadratic steps is taken.
3801 
3802  if (fp .gt. fx) then
3803  theta = three*(fx - fp)/(stp - stx) + dx + dp
3804  s = max(abs(theta),abs(dx),abs(dp))
3805  gamma = s*sqrt((theta/s)**2 - (dx/s)*(dp/s))
3806  if (stp .lt. stx) gamma = -gamma
3807  p = (gamma - dx) + theta
3808  q = ((gamma - dx) + gamma) + dp
3809  r = p/q
3810  stpc = stx + r*(stp - stx)
3811  stpq = stx + ((dx/((fx - fp)/(stp - stx) + dx))/two)*
3812  + (stp - stx)
3813  if (abs(stpc-stx) .lt. abs(stpq-stx)) then
3814  stpf = stpc
3815  else
3816  stpf = stpc + (stpq - stpc)/two
3817  endif
3818  brackt = .true.
3819 
3820 c Second case: A lower function value and derivatives of opposite
3821 c sign. The minimum is bracketed. If the cubic step is farther from
3822 c stp than the secant step, the cubic step is taken, otherwise the
3823 c secant step is taken.
3824 
3825  else if (sgnd .lt. zero) then
3826  theta = three*(fx - fp)/(stp - stx) + dx + dp
3827  s = max(abs(theta),abs(dx),abs(dp))
3828  gamma = s*sqrt((theta/s)**2 - (dx/s)*(dp/s))
3829  if (stp .gt. stx) gamma = -gamma
3830  p = (gamma - dp) + theta
3831  q = ((gamma - dp) + gamma) + dx
3832  r = p/q
3833  stpc = stp + r*(stx - stp)
3834  stpq = stp + (dp/(dp - dx))*(stx - stp)
3835  if (abs(stpc-stp) .gt. abs(stpq-stp)) then
3836  stpf = stpc
3837  else
3838  stpf = stpq
3839  endif
3840  brackt = .true.
3841 
3842 c Third case: A lower function value, derivatives of the same sign,
3843 c and the magnitude of the derivative decreases.
3844 
3845  else if (abs(dp) .lt. abs(dx)) then
3846 
3847 c The cubic step is computed only if the cubic tends to infinity
3848 c in the direction of the step or if the minimum of the cubic
3849 c is beyond stp. Otherwise the cubic step is defined to be the
3850 c secant step.
3851 
3852  theta = three*(fx - fp)/(stp - stx) + dx + dp
3853  s = max(abs(theta),abs(dx),abs(dp))
3854 
3855 c The case gamma = 0 only arises if the cubic does not tend
3856 c to infinity in the direction of the step.
3857 
3858  gamma = s*sqrt(max(zero,(theta/s)**2-(dx/s)*(dp/s)))
3859  if (stp .gt. stx) gamma = -gamma
3860  p = (gamma - dp) + theta
3861  q = (gamma + (dx - dp)) + gamma
3862  r = p/q
3863  if (r .lt. zero .and. gamma .ne. zero) then
3864  stpc = stp + r*(stx - stp)
3865  else if (stp .gt. stx) then
3866  stpc = stpmax
3867  else
3868  stpc = stpmin
3869  endif
3870  stpq = stp + (dp/(dp - dx))*(stx - stp)
3871 
3872  if (brackt) then
3873 
3874 c A minimizer has been bracketed. If the cubic step is
3875 c closer to stp than the secant step, the cubic step is
3876 c taken, otherwise the secant step is taken.
3877 
3878  if (abs(stpc-stp) .lt. abs(stpq-stp)) then
3879  stpf = stpc
3880  else
3881  stpf = stpq
3882  endif
3883  if (stp .gt. stx) then
3884  stpf = min(stp+p66*(sty-stp),stpf)
3885  else
3886  stpf = max(stp+p66*(sty-stp),stpf)
3887  endif
3888  else
3889 
3890 c A minimizer has not been bracketed. If the cubic step is
3891 c farther from stp than the secant step, the cubic step is
3892 c taken, otherwise the secant step is taken.
3893 
3894  if (abs(stpc-stp) .gt. abs(stpq-stp)) then
3895  stpf = stpc
3896  else
3897  stpf = stpq
3898  endif
3899  stpf = min(stpmax,stpf)
3900  stpf = max(stpmin,stpf)
3901  endif
3902 
3903 c Fourth case: A lower function value, derivatives of the same sign,
3904 c and the magnitude of the derivative does not decrease. If the
3905 c minimum is not bracketed, the step is either stpmin or stpmax,
3906 c otherwise the cubic step is taken.
3907 
3908  else
3909  if (brackt) then
3910  theta = three*(fp - fy)/(sty - stp) + dy + dp
3911  s = max(abs(theta),abs(dy),abs(dp))
3912  gamma = s*sqrt((theta/s)**2 - (dy/s)*(dp/s))
3913  if (stp .gt. sty) gamma = -gamma
3914  p = (gamma - dp) + theta
3915  q = ((gamma - dp) + gamma) + dy
3916  r = p/q
3917  stpc = stp + r*(sty - stp)
3918  stpf = stpc
3919  else if (stp .gt. stx) then
3920  stpf = stpmax
3921  else
3922  stpf = stpmin
3923  endif
3924  endif
3925 
3926 c Update the interval which contains a minimizer.
3927 
3928  if (fp .gt. fx) then
3929  sty = stp
3930  fy = fp
3931  dy = dp
3932  else
3933  if (sgnd .lt. zero) then
3934  sty = stx
3935  fy = fx
3936  dy = dx
3937  endif
3938  stx = stp
3939  fx = fp
3940  dx = dp
3941  endif
3942 
3943 c Compute the new step.
3944 
3945  stp = stpf
3946 
3947  return
#define max(a, b)
Definition: cascade.c:32
#define min(a, b)
Definition: cascade.c:31

◆ errclb()

subroutine errclb ( integer  n,
integer  m,
double precision  factr,
double precision, dimension(n)  l,
double precision, dimension(n)  u,
integer, dimension(n)  nbd,
character*60  task,
integer  info,
integer  k 
)
1789 
1790  character*60 task
1791  integer n, m, info, k, nbd(n)
1792  double precision factr, l(n), u(n)
1793 
1794 c ************
1795 c
1796 c Subroutine errclb
1797 c
1798 c this subroutine checks the validity of the input data.
1799 c
1800 c
1801 c * * *
1802 c
1803 c neos, november 1994. (latest revision june 1996.)
1804 c optimization technology center.
1805 c argonne national laboratory and northwestern university.
1806 c written by
1807 c ciyou zhu
1808 c in collaboration with r.h. byrd, p. lu-chen and j. nocedal.
1809 c
1810 c
1811 c ************
1812 
1813  integer i
1814  double precision one,zero
1815  parameter(one=1.0d0,zero=0.0d0)
1816 
1817 c check the input arguments for errors.
1818 
1819  if (n .le. 0) task = .LE.'ERROR: N 0'
1820  if (m .le. 0) task = .LE.'ERROR: M 0'
1821  if (factr .lt. zero) task = .LT.'ERROR: FACTR 0'
1822 
1823 c check the validity of the arrays nbd(i), u(i), and l(i).
1824 
1825  do 10 i = 1, n
1826  if (nbd(i) .lt. 0 .or. nbd(i) .gt. 3) then
1827 c return
1828  task = 'ERROR: INVALID NBD'
1829  info = -6
1830  k = i
1831  endif
1832  if (nbd(i) .eq. 2) then
1833  if (l(i) .gt. u(i)) then
1834 c return
1835  task = 'ERROR: NO FEASIBLE SOLUTION'
1836  info = -7
1837  k = i
1838  endif
1839  endif
1840  10 continue
1841 
1842  return
1843 
subroutine errclb(n, m, factr, l, u, nbd, task, info, k)
Definition: lbfgsb.f:1789

◆ formk()

subroutine formk ( integer  n,
integer  nsub,
integer, dimension(n)  ind,
integer  nenter,
integer  ileave,
integer, dimension(n)  indx2,
integer  iupdat,
logical  updatd,
double precision, dimension(2*m, 2*m)  wn,
double precision, dimension(2*m, 2*m)  wn1,
integer  m,
double precision, dimension(n, m)  ws,
double precision, dimension(n, m)  wy,
double precision, dimension(m, m)  sy,
double precision  theta,
integer  col,
integer  head,
integer  info 
)
1851 
1852  integer n, nsub, m, col, head, nenter, ileave, iupdat,
1853  + info, ind(n), indx2(n)
1854  double precision theta, wn(2*m, 2*m), wn1(2*m, 2*m),
1855  + ws(n, m), wy(n, m), sy(m, m)
1856  logical updatd
1857 
1858 c ************
1859 c
1860 c Subroutine formk
1861 c
1862 c This subroutine forms the LEL^T factorization of the indefinite
1863 c
1864 c matrix K = [-D -Y'ZZ'Y/theta L_a'-R_z' ]
1865 c [L_a -R_z theta*S'AA'S ]
1866 c where E = [-I 0]
1867 c [ 0 I]
1868 c The matrix K can be shown to be equal to the matrix M^[-1]N
1869 c occurring in section 5.1 of [1], as well as to the matrix
1870 c Mbar^[-1] Nbar in section 5.3.
1871 c
1872 c n is an integer variable.
1873 c On entry n is the dimension of the problem.
1874 c On exit n is unchanged.
1875 c
1876 c nsub is an integer variable
1877 c On entry nsub is the number of subspace variables in free set.
1878 c On exit nsub is not changed.
1879 c
1880 c ind is an integer array of dimension nsub.
1881 c On entry ind specifies the indices of subspace variables.
1882 c On exit ind is unchanged.
1883 c
1884 c nenter is an integer variable.
1885 c On entry nenter is the number of variables entering the
1886 c free set.
1887 c On exit nenter is unchanged.
1888 c
1889 c ileave is an integer variable.
1890 c On entry indx2(ileave),...,indx2(n) are the variables leaving
1891 c the free set.
1892 c On exit ileave is unchanged.
1893 c
1894 c indx2 is an integer array of dimension n.
1895 c On entry indx2(1),...,indx2(nenter) are the variables entering
1896 c the free set, while indx2(ileave),...,indx2(n) are the
1897 c variables leaving the free set.
1898 c On exit indx2 is unchanged.
1899 c
1900 c iupdat is an integer variable.
1901 c On entry iupdat is the total number of BFGS updates made so far.
1902 c On exit iupdat is unchanged.
1903 c
1904 c updatd is a logical variable.
1905 c On entry 'updatd' is true if the L-BFGS matrix is updatd.
1906 c On exit 'updatd' is unchanged.
1907 c
1908 c wn is a double precision array of dimension 2m x 2m.
1909 c On entry wn is unspecified.
1910 c On exit the upper triangle of wn stores the LEL^T factorization
1911 c of the 2*col x 2*col indefinite matrix
1912 c [-D -Y'ZZ'Y/theta L_a'-R_z' ]
1913 c [L_a -R_z theta*S'AA'S ]
1914 c
1915 c wn1 is a double precision array of dimension 2m x 2m.
1916 c On entry wn1 stores the lower triangular part of
1917 c [Y' ZZ'Y L_a'+R_z']
1918 c [L_a+R_z S'AA'S ]
1919 c in the previous iteration.
1920 c On exit wn1 stores the corresponding updated matrices.
1921 c The purpose of wn1 is just to store these inner products
1922 c so they can be easily updated and inserted into wn.
1923 c
1924 c m is an integer variable.
1925 c On entry m is the maximum number of variable metric corrections
1926 c used to define the limited memory matrix.
1927 c On exit m is unchanged.
1928 c
1929 c ws, wy, sy, and wtyy are double precision arrays;
1930 c theta is a double precision variable;
1931 c col is an integer variable;
1932 c head is an integer variable.
1933 c On entry they store the information defining the
1934 c limited memory BFGS matrix:
1935 c ws(n,m) stores S, a set of s-vectors;
1936 c wy(n,m) stores Y, a set of y-vectors;
1937 c sy(m,m) stores S'Y;
1938 c wtyy(m,m) stores the Cholesky factorization
1939 c of (theta*S'S+LD^(-1)L')
1940 c theta is the scaling factor specifying B_0 = theta I;
1941 c col is the number of variable metric corrections stored;
1942 c head is the location of the 1st s- (or y-) vector in S (or Y).
1943 c On exit they are unchanged.
1944 c
1945 c info is an integer variable.
1946 c On entry info is unspecified.
1947 c On exit info = 0 for normal return;
1948 c = -1 when the 1st Cholesky factorization failed;
1949 c = -2 when the 2st Cholesky factorization failed.
1950 c
1951 c Subprograms called:
1952 c
1953 c Linpack ... dcopy, dpofa, dtrsl.
1954 c
1955 c
1956 c References:
1957 c [1] R. H. Byrd, P. Lu, J. Nocedal and C. Zhu, ``A limited
1958 c memory algorithm for bound constrained optimization'',
1959 c SIAM J. Scientific Computing 16 (1995), no. 5, pp. 1190--1208.
1960 c
1961 c [2] C. Zhu, R.H. Byrd, P. Lu, J. Nocedal, ``L-BFGS-B: a
1962 c limited memory FORTRAN code for solving bound constrained
1963 c optimization problems'', Tech. Report, NAM-11, EECS Department,
1964 c Northwestern University, 1994.
1965 c
1966 c (Postscript files of these papers are available via anonymous
1967 c ftp to eecs.nwu.edu in the directory pub/lbfgs/lbfgs_bcm.)
1968 c
1969 c * * *
1970 c
1971 c NEOS, November 1994. (Latest revision June 1996.)
1972 c Optimization Technology Center.
1973 c Argonne National Laboratory and Northwestern University.
1974 c Written by
1975 c Ciyou Zhu
1976 c in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal.
1977 c
1978 c
1979 c ************
1980 
1981  integer m2,ipntr,jpntr,iy,is,jy,js,is1,js1,k1,i,k,
1982  + col2,pbegin,pend,dbegin,dend,upcl
1983  double precision ddot,temp1,temp2,temp3,temp4
1984  double precision one,zero
1985  parameter(one=1.0d0,zero=0.0d0)
1986 
1987 c Form the lower triangular part of
1988 c WN1 = [Y' ZZ'Y L_a'+R_z']
1989 c [L_a+R_z S'AA'S ]
1990 c where L_a is the strictly lower triangular part of S'AA'Y
1991 c R_z is the upper triangular part of S'ZZ'Y.
1992 
1993  if (updatd) then
1994  if (iupdat .gt. m) then
1995 c shift old part of WN1.
1996  do 10 jy = 1, m - 1
1997  js = m + jy
1998  call dcopy(m-jy,wn1(jy+1,jy+1),1,wn1(jy,jy),1)
1999  call dcopy(m-jy,wn1(js+1,js+1),1,wn1(js,js),1)
2000  call dcopy(m-1,wn1(m+2,jy+1),1,wn1(m+1,jy),1)
2001  10 continue
2002  endif
2003 
2004 c put new rows in blocks (1,1), (2,1) and (2,2).
2005  pbegin = 1
2006  pend = nsub
2007  dbegin = nsub + 1
2008  dend = n
2009  iy = col
2010  is = m + col
2011  ipntr = head + col - 1
2012  if (ipntr .gt. m) ipntr = ipntr - m
2013  jpntr = head
2014  do 20 jy = 1, col
2015  js = m + jy
2016  temp1 = zero
2017  temp2 = zero
2018  temp3 = zero
2019 c compute element jy of row 'col' of Y'ZZ'Y
2020  do 15 k = pbegin, pend
2021  k1 = ind(k)
2022  temp1 = temp1 + wy(k1,ipntr)*wy(k1,jpntr)
2023  15 continue
2024 c compute elements jy of row 'col' of L_a and S'AA'S
2025  do 16 k = dbegin, dend
2026  k1 = ind(k)
2027  temp2 = temp2 + ws(k1,ipntr)*ws(k1,jpntr)
2028  temp3 = temp3 + ws(k1,ipntr)*wy(k1,jpntr)
2029  16 continue
2030  wn1(iy,jy) = temp1
2031  wn1(is,js) = temp2
2032  wn1(is,jy) = temp3
2033  jpntr = mod(jpntr,m) + 1
2034  20 continue
2035 
2036 c put new column in block (2,1).
2037  jy = col
2038  jpntr = head + col - 1
2039  if (jpntr .gt. m) jpntr = jpntr - m
2040  ipntr = head
2041  do 30 i = 1, col
2042  is = m + i
2043  temp3 = zero
2044 c compute element i of column 'col' of R_z
2045  do 25 k = pbegin, pend
2046  k1 = ind(k)
2047  temp3 = temp3 + ws(k1,ipntr)*wy(k1,jpntr)
2048  25 continue
2049  ipntr = mod(ipntr,m) + 1
2050  wn1(is,jy) = temp3
2051  30 continue
2052  upcl = col - 1
2053  else
2054  upcl = col
2055  endif
2056 
2057 c modify the old parts in blocks (1,1) and (2,2) due to changes
2058 c in the set of free variables.
2059  ipntr = head
2060  do 45 iy = 1, upcl
2061  is = m + iy
2062  jpntr = head
2063  do 40 jy = 1, iy
2064  js = m + jy
2065  temp1 = zero
2066  temp2 = zero
2067  temp3 = zero
2068  temp4 = zero
2069  do 35 k = 1, nenter
2070  k1 = indx2(k)
2071  temp1 = temp1 + wy(k1,ipntr)*wy(k1,jpntr)
2072  temp2 = temp2 + ws(k1,ipntr)*ws(k1,jpntr)
2073  35 continue
2074  do 36 k = ileave, n
2075  k1 = indx2(k)
2076  temp3 = temp3 + wy(k1,ipntr)*wy(k1,jpntr)
2077  temp4 = temp4 + ws(k1,ipntr)*ws(k1,jpntr)
2078  36 continue
2079  wn1(iy,jy) = wn1(iy,jy) + temp1 - temp3
2080  wn1(is,js) = wn1(is,js) - temp2 + temp4
2081  jpntr = mod(jpntr,m) + 1
2082  40 continue
2083  ipntr = mod(ipntr,m) + 1
2084  45 continue
2085 
2086 c modify the old parts in block (2,1).
2087  ipntr = head
2088  do 60 is = m + 1, m + upcl
2089  jpntr = head
2090  do 55 jy = 1, upcl
2091  temp1 = zero
2092  temp3 = zero
2093  do 50 k = 1, nenter
2094  k1 = indx2(k)
2095  temp1 = temp1 + ws(k1,ipntr)*wy(k1,jpntr)
2096  50 continue
2097  do 51 k = ileave, n
2098  k1 = indx2(k)
2099  temp3 = temp3 + ws(k1,ipntr)*wy(k1,jpntr)
2100  51 continue
2101  if (is .le. jy + m) then
2102  wn1(is,jy) = wn1(is,jy) + temp1 - temp3
2103  else
2104  wn1(is,jy) = wn1(is,jy) - temp1 + temp3
2105  endif
2106  jpntr = mod(jpntr,m) + 1
2107  55 continue
2108  ipntr = mod(ipntr,m) + 1
2109  60 continue
2110 
2111 c Form the upper triangle of WN = [D+Y' ZZ'Y/theta -L_a'+R_z' ]
2112 c [-L_a +R_z S'AA'S*theta]
2113 
2114  m2 = 2*m
2115  do 70 iy = 1, col
2116  is = col + iy
2117  is1 = m + iy
2118  do 65 jy = 1, iy
2119  js = col + jy
2120  js1 = m + jy
2121  wn(jy,iy) = wn1(iy,jy)/theta
2122  wn(js,is) = wn1(is1,js1)*theta
2123  65 continue
2124  do 66 jy = 1, iy - 1
2125  wn(jy,is) = -wn1(is1,jy)
2126  66 continue
2127  do 67 jy = iy, col
2128  wn(jy,is) = wn1(is1,jy)
2129  67 continue
2130  wn(iy,iy) = wn(iy,iy) + sy(iy,iy)
2131  70 continue
2132 
2133 c Form the upper triangle of WN= [ LL' L^-1(-L_a'+R_z')]
2134 c [(-L_a +R_z)L'^-1 S'AA'S*theta ]
2135 
2136 c first Cholesky factor (1,1) block of wn to get LL'
2137 c with L' stored in the upper triangle of wn.
2138  call dpofa(wn,m2,col,info)
2139  if (info .ne. 0) then
2140  info = -1
2141  return
2142  endif
2143 c then form L^-1(-L_a'+R_z') in the (1,2) block.
2144  col2 = 2*col
2145  do 71 js = col+1 ,col2
2146  call dtrsl(wn,m2,col,wn(1,js),11,info)
2147  71 continue
2148 
2149 c Form S'AA'S*theta + (L^-1(-L_a'+R_z'))'L^-1(-L_a'+R_z') in the
2150 c upper triangle of (2,2) block of wn.
2151 
2152 
2153  do 72 is = col+1, col2
2154  do 74 js = is, col2
2155  wn(is,js) = wn(is,js) + ddot(col,wn(1,is),1,wn(1,js),1)
2156  74 continue
2157  72 continue
2158 
2159 c Cholesky factorization of (2,2) block of wn.
2160 
2161  call dpofa(wn(col+1,col+1),m2,col,info)
2162  if (info .ne. 0) then
2163  info = -2
2164  return
2165  endif
2166 
2167  return
2168 
subroutine dcopy(N, DX, INCX, DY, INCY)
Definition: dgmres.f:1381
subroutine dtrsl(t, ldt, n, b, job, info)
Definition: linpack.f:82
subroutine dpofa(a, lda, n, info)
Definition: linpack.f:7
double precision function ddot(N, DX, INCX, DY, INCY)
Definition: dgmres.f:2469

◆ formt()

subroutine formt ( integer  m,
double precision, dimension(m, m)  wt,
double precision, dimension(m, m)  sy,
double precision, dimension(m, m)  ss,
integer  col,
double precision  theta,
integer  info 
)
2174 
2175  integer m, col, info
2176  double precision theta, wt(m, m), sy(m, m), ss(m, m)
2177 
2178 c ************
2179 c
2180 c Subroutine formt
2181 c
2182 c This subroutine forms the upper half of the pos. def. and symm.
2183 c T = theta*SS + L*D^(-1)*L', stores T in the upper triangle
2184 c of the array wt, and performs the Cholesky factorization of T
2185 c to produce J*J', with J' stored in the upper triangle of wt.
2186 c
2187 c Subprograms called:
2188 c
2189 c Linpack ... dpofa.
2190 c
2191 c
2192 c * * *
2193 c
2194 c NEOS, November 1994. (Latest revision June 1996.)
2195 c Optimization Technology Center.
2196 c Argonne National Laboratory and Northwestern University.
2197 c Written by
2198 c Ciyou Zhu
2199 c in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal.
2200 c
2201 c
2202 c ************
2203 
2204  integer i,j,k,k1
2205  double precision ddum
2206  double precision zero
2207  parameter(zero=0.0d0)
2208 
2209 
2210 c Form the upper half of T = theta*SS + L*D^(-1)*L',
2211 c store T in the upper triangle of the array wt.
2212 
2213  do 52 j = 1, col
2214  wt(1,j) = theta*ss(1,j)
2215  52 continue
2216  do 55 i = 2, col
2217  do 54 j = i, col
2218  k1 = min(i,j) - 1
2219  ddum = zero
2220  do 53 k = 1, k1
2221  ddum = ddum + sy(i,k)*sy(j,k)/sy(k,k)
2222  53 continue
2223  wt(i,j) = ddum + theta*ss(i,j)
2224  54 continue
2225  55 continue
2226 
2227 c Cholesky factorize T to J*J' with
2228 c J' stored in the upper triangle of wt.
2229 
2230  call dpofa(wt,m,col,info)
2231  if (info .ne. 0) then
2232  info = -3
2233  endif
2234 
2235  return
2236 
#define min(a, b)
Definition: cascade.c:31
subroutine dpofa(a, lda, n, info)
Definition: linpack.f:7

◆ freev()

subroutine freev ( integer  n,
integer  nfree,
integer, dimension(n)  index,
integer  nenter,
integer  ileave,
integer, dimension(n)  indx2,
integer, dimension(n)  iwhere,
logical  wrk,
logical  updatd,
logical  cnstnd,
integer  iprint,
integer  iter 
)
2243 
2244  integer n, nfree, nenter, ileave, iprint, iter,
2245  + index(n), indx2(n), iwhere(n)
2246  logical wrk, updatd, cnstnd
2247 
2248 c ************
2249 c
2250 c Subroutine freev
2251 c
2252 c This subroutine counts the entering and leaving variables when
2253 c iter > 0, and finds the index set of free and active variables
2254 c at the GCP.
2255 c
2256 c cnstnd is a logical variable indicating whether bounds are present
2257 c
2258 c index is an integer array of dimension n
2259 c for i=1,...,nfree, index(i) are the indices of free variables
2260 c for i=nfree+1,...,n, index(i) are the indices of bound variables
2261 c On entry after the first iteration, index gives
2262 c the free variables at the previous iteration.
2263 c On exit it gives the free variables based on the determination
2264 c in cauchy using the array iwhere.
2265 c
2266 c indx2 is an integer array of dimension n
2267 c On entry indx2 is unspecified.
2268 c On exit with iter>0, indx2 indicates which variables
2269 c have changed status since the previous iteration.
2270 c For i= 1,...,nenter, indx2(i) have changed from bound to free.
2271 c For i= ileave+1,...,n, indx2(i) have changed from free to bound.
2272 c
2273 c
2274 c * * *
2275 c
2276 c NEOS, November 1994. (Latest revision June 1996.)
2277 c Optimization Technology Center.
2278 c Argonne National Laboratory and Northwestern University.
2279 c Written by
2280 c Ciyou Zhu
2281 c in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal.
2282 c
2283 c
2284 c ************
2285 
2286  integer iact,i,k
2287 
2288  nenter = 0
2289  ileave = n + 1
2290  if (iter .gt. 0 .and. cnstnd) then
2291 c count the entering and leaving variables.
2292  do 20 i = 1, nfree
2293  k = index(i)
2294 
2295 c write(6,*) ' k = index(i) ', k
2296 c write(6,*) ' index = ', i
2297 
2298  if (iwhere(k) .gt. 0) then
2299  ileave = ileave - 1
2300  indx2(ileave) = k
2301  if (iprint .ge. 100) write (6,*)
2302  + 'Variable ',k,' leaves the set of free variables'
2303  endif
2304  20 continue
2305  do 22 i = 1 + nfree, n
2306  k = index(i)
2307  if (iwhere(k) .le. 0) then
2308  nenter = nenter + 1
2309  indx2(nenter) = k
2310  if (iprint .ge. 100) write (6,*)
2311  + 'Variable ',k,' enters the set of free variables'
2312  endif
2313  22 continue
2314  if (iprint .ge. 99) write (6,*)
2315  + n+1-ileave,' variables leave; ',nenter,' variables enter'
2316  endif
2317  wrk = (ileave .lt. n+1) .or. (nenter .gt. 0) .or. updatd
2318 
2319 c Find the index set of free and active variables at the GCP.
2320 
2321  nfree = 0
2322  iact = n + 1
2323  do 24 i = 1, n
2324  if (iwhere(i) .le. 0) then
2325  nfree = nfree + 1
2326  index(nfree) = i
2327  else
2328  iact = iact - 1
2329  index(iact) = i
2330  endif
2331  24 continue
2332  if (iprint .ge. 99) write (6,*)
2333  + nfree,' variables are free at GCP ',iter + 1
2334 
2335  return
2336 

◆ hpsolb()

subroutine hpsolb ( integer  n,
double precision, dimension(n)  t,
integer, dimension(n)  iorder,
integer  iheap 
)
2342  integer iheap, n, iorder(n)
2343  double precision t(n)
2344 
2345 c ************
2346 c
2347 c Subroutine hpsolb
2348 c
2349 c This subroutine sorts out the least element of t, and puts the
2350 c remaining elements of t in a heap.
2351 c
2352 c n is an integer variable.
2353 c On entry n is the dimension of the arrays t and iorder.
2354 c On exit n is unchanged.
2355 c
2356 c t is a double precision array of dimension n.
2357 c On entry t stores the elements to be sorted,
2358 c On exit t(n) stores the least elements of t, and t(1) to t(n-1)
2359 c stores the remaining elements in the form of a heap.
2360 c
2361 c iorder is an integer array of dimension n.
2362 c On entry iorder(i) is the index of t(i).
2363 c On exit iorder(i) is still the index of t(i), but iorder may be
2364 c permuted in accordance with t.
2365 c
2366 c iheap is an integer variable specifying the task.
2367 c On entry iheap should be set as follows:
2368 c iheap .eq. 0 if t(1) to t(n) is not in the form of a heap,
2369 c iheap .ne. 0 if otherwise.
2370 c On exit iheap is unchanged.
2371 c
2372 c
2373 c References:
2374 c Algorithm 232 of CACM (J. W. J. Williams): HEAPSORT.
2375 c
2376 c * * *
2377 c
2378 c NEOS, November 1994. (Latest revision June 1996.)
2379 c Optimization Technology Center.
2380 c Argonne National Laboratory and Northwestern University.
2381 c Written by
2382 c Ciyou Zhu
2383 c in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal.
2384 c
2385 c ************
2386 
2387  integer i,j,k,indxin,indxou
2388  double precision ddum,out
2389 
2390  if (iheap .eq. 0) then
2391 
2392 c Rearrange the elements t(1) to t(n) to form a heap.
2393 
2394  do 20 k = 2, n
2395  ddum = t(k)
2396  indxin = iorder(k)
2397 
2398 c Add ddum to the heap.
2399  i = k
2400  10 continue
2401  if (i.gt.1) then
2402  j = i/2
2403  if (ddum .lt. t(j)) then
2404  t(i) = t(j)
2405  iorder(i) = iorder(j)
2406  i = j
2407  goto 10
2408  endif
2409  endif
2410  t(i) = ddum
2411  iorder(i) = indxin
2412  20 continue
2413  endif
2414 
2415 c Assign to 'out' the value of t(1), the least member of the heap,
2416 c and rearrange the remaining members to form a heap as
2417 c elements 1 to n-1 of t.
2418 
2419  if (n .gt. 1) then
2420  i = 1
2421  out = t(1)
2422  indxou = iorder(1)
2423  ddum = t(n)
2424  indxin = iorder(n)
2425 
2426 c Restore the heap
2427  30 continue
2428  j = i+i
2429  if (j .le. n-1) then
2430  if (t(j+1) .lt. t(j)) j = j+1
2431  if (t(j) .lt. ddum ) then
2432  t(i) = t(j)
2433  iorder(i) = iorder(j)
2434  i = j
2435  goto 30
2436  endif
2437  endif
2438  t(i) = ddum
2439  iorder(i) = indxin
2440 
2441 c Put the least member in t(n).
2442 
2443  t(n) = out
2444  iorder(n) = indxou
2445  endif
2446 
2447  return
2448 

◆ lnsrlb()

subroutine lnsrlb ( integer  n,
double precision, dimension(n)  l,
double precision, dimension(n)  u,
integer, dimension(n)  nbd,
double precision, dimension(n)  x,
double precision  f,
double precision  fold,
double precision  gd,
double precision  gdold,
double precision, dimension(n)  g,
double precision, dimension(n)  d,
double precision, dimension(n)  r,
double precision, dimension(n)  t,
double precision, dimension(n)  z,
double precision  stp,
double precision  dnorm,
double precision  dtd,
double precision  xstep,
double precision  stpmx,
integer  iter,
integer  ifun,
integer  iback,
integer  nfgv,
integer  info,
character*60  task,
logical  boxed,
logical  cnstnd,
character*60  csave,
integer, dimension(2)  isave,
double precision, dimension(13)  dsave 
)
2457 
2458  character*60 task, csave
2459  logical boxed, cnstnd
2460  integer n, iter, ifun, iback, nfgv, info,
2461  + nbd(n), isave(2)
2462  double precision f, fold, gd, gdold, stp, dnorm, dtd, xstep,
2463  + stpmx, x(n), l(n), u(n), g(n), d(n), r(n), t(n),
2464  + z(n), dsave(13)
2465 c **********
2466 c
2467 c Subroutine lnsrlb
2468 c
2469 c this subroutine calls subroutine dcsrch from the minpack2 library
2470 c to perform the line search. Subroutine dscrch is safeguarded so
2471 c that all trial points lie within the feasible region.
2472 c
2473 c subprograms called:
2474 c
2475 c minpack2 library ... dcsrch.
2476 c
2477 c linpack ... dtrsl, ddot.
2478 c
2479 c
2480 c * * *
2481 c
2482 c neos, november 1994. (latest revision june 1996.)
2483 c optimization technology center.
2484 c argonne national laboratory and northwestern university.
2485 c written by
2486 c ciyou zhu
2487 c in collaboration with r.h. byrd, p. lu-chen and j. nocedal.
2488 c
2489 c
2490 c **********
2491 
2492  integer i
2493  double precision ddot,a1,a2
2494  double precision one,zero,big
2495  parameter(one=1.0d0,zero=0.0d0,big=1.0d+10)
2496  double precision ftol,gtol,xtol
2497  parameter(ftol=1.0d-3,gtol=0.9d0,xtol=0.1d0)
2498 
2499  if (task(1:5) .eq. 'FG_LN') goto 556
2500 
2501  dtd = ddot(n,d,1,d,1)
2502  dnorm = sqrt(dtd)
2503 
2504 c determine the maximum step length.
2505 
2506  stpmx = big
2507  if (cnstnd) then
2508  if (iter .eq. 0) then
2509  stpmx = one
2510  else
2511  do 43 i = 1, n
2512  a1 = d(i)
2513  if (nbd(i) .ne. 0) then
2514  if (a1 .lt. zero .and. nbd(i) .le. 2) then
2515  a2 = l(i) - x(i)
2516  if (a2 .ge. zero) then
2517  stpmx = zero
2518  else if (a1*stpmx .lt. a2) then
2519  stpmx = a2/a1
2520  endif
2521  else if (a1 .gt. zero .and. nbd(i) .ge. 2) then
2522  a2 = u(i) - x(i)
2523  if (a2 .le. zero) then
2524  stpmx = zero
2525  else if (a1*stpmx .gt. a2) then
2526  stpmx = a2/a1
2527  endif
2528  endif
2529  endif
2530  43 continue
2531  endif
2532  endif
2533 
2534  if (iter .eq. 0 .and. .not. boxed) then
2535  stp = min(one/dnorm, stpmx)
2536  else
2537  stp = one
2538  endif
2539 
2540  call dcopy(n,x,1,t,1)
2541  call dcopy(n,g,1,r,1)
2542  fold = f
2543  ifun = 0
2544  iback = 0
2545  csave = 'START'
2546  556 continue
2547  gd = ddot(n,g,1,d,1)
2548  if (ifun .eq. 0) then
2549  gdold=gd
2550  if (gd .ge. zero) then
2551 c the directional derivative >=0.
2552 c line search is impossible.
2553  write(6,*)' ascent direction in projection gd = ', gd
2554  info = -4
2555  return
2556  endif
2557  endif
2558 
2559  call dcsrch(f,gd,stp,ftol,gtol,xtol,zero,stpmx,csave,isave,dsave)
2560 
2561  xstep = stp*dnorm
2562  if (csave(1:4) .ne. 'CONV' .and. csave(1:4) .ne. 'WARN') then
2563  task = 'FG_LNSRCH'
2564  ifun = ifun + 1
2565  nfgv = nfgv + 1
2566  iback = ifun - 1
2567  if (stp .eq. one) then
2568  call dcopy(n,z,1,x,1)
2569  else
2570  do 41 i = 1, n
2571  x(i) = stp*d(i) + t(i)
2572  41 continue
2573  endif
2574  else
2575  task = 'NEW_X'
2576  endif
2577 
2578  return
2579 
subroutine dcopy(N, DX, INCX, DY, INCY)
Definition: dgmres.f:1381
subroutine dtrsl(t, ldt, n, b, job, info)
Definition: linpack.f:82
#define min(a, b)
Definition: cascade.c:31
subroutine dcsrch(f, g, stp, ftol, gtol, xtol, stpmin, stpmax, task, isave, dsave)
Definition: lbfgsb.f:3349
subroutine lnsrlb(n, l, u, nbd, x, f, fold, gd, gdold, g, d, r, t, z, stp, dnorm, dtd, xstep, stpmx, iter, ifun, iback, nfgv, info, task, boxed, cnstnd, csave, isave, dsave)
Definition: lbfgsb.f:2457
double precision function ddot(N, DX, INCX, DY, INCY)
Definition: dgmres.f:2469

◆ mainlb()

subroutine mainlb ( integer  n,
integer  m,
double precision, dimension(n)  x,
double precision, dimension(n)  l,
double precision, dimension(n)  u,
integer, dimension(n)  nbd,
double precision  f,
double precision, dimension(n)  g,
double precision  factr,
double precision  pgtol,
double precision, dimension(n, m)  ws,
double precision, dimension(n, m)  wy,
double precision, dimension(m, m)  sy,
double precision, dimension(m, m)  ss,
double precision, dimension(m, m)  wt,
double precision, dimension(2*m, 2*m)  wn,
double precision, dimension(2*m, 2*m)  snd,
double precision, dimension(n)  z,
double precision, dimension(n)  r,
double precision, dimension(n)  d,
double precision, dimension(n)  t,
double precision, dimension(n)  xp,
double precision, dimension(8*m)  wa,
integer, dimension(n)  index,
integer, dimension(n)  iwhere,
integer, dimension(n)  indx2,
character*60  task,
integer  iprint,
character*60  csave,
logical, dimension(4)  lsave,
integer, dimension(23)  isave,
double precision, dimension(29)  dsave 
)
291  implicit none
292  character*60 task, csave
293  logical lsave(4)
294  integer n, m, iprint, nbd(n), index(n),
295  + iwhere(n), indx2(n), isave(23)
296  double precision f, factr, pgtol,
297  + x(n), l(n), u(n), g(n), z(n), r(n), d(n), t(n),
298 c-jlm-jn
299  + xp(n),
300  + wa(8*m),
301  + ws(n, m), wy(n, m), sy(m, m), ss(m, m),
302  + wt(m, m), wn(2*m, 2*m), snd(2*m, 2*m), dsave(29)
303 
304 c ************
305 c
306 c Subroutine mainlb
307 c
308 c This subroutine solves bound constrained optimization problems by
309 c using the compact formula of the limited memory BFGS updates.
310 c
311 c n is an integer variable.
312 c On entry n is the number of variables.
313 c On exit n is unchanged.
314 c
315 c m is an integer variable.
316 c On entry m is the maximum number of variable metric
317 c corrections allowed in the limited memory matrix.
318 c On exit m is unchanged.
319 c
320 c x is a double precision array of dimension n.
321 c On entry x is an approximation to the solution.
322 c On exit x is the current approximation.
323 c
324 c l is a double precision array of dimension n.
325 c On entry l is the lower bound of x.
326 c On exit l is unchanged.
327 c
328 c u is a double precision array of dimension n.
329 c On entry u is the upper bound of x.
330 c On exit u is unchanged.
331 c
332 c nbd is an integer array of dimension n.
333 c On entry nbd represents the type of bounds imposed on the
334 c variables, and must be specified as follows:
335 c nbd(i)=0 if x(i) is unbounded,
336 c 1 if x(i) has only a lower bound,
337 c 2 if x(i) has both lower and upper bounds,
338 c 3 if x(i) has only an upper bound.
339 c On exit nbd is unchanged.
340 c
341 c f is a double precision variable.
342 c On first entry f is unspecified.
343 c On final exit f is the value of the function at x.
344 c
345 c g is a double precision array of dimension n.
346 c On first entry g is unspecified.
347 c On final exit g is the value of the gradient at x.
348 c
349 c factr is a double precision variable.
350 c On entry factr >= 0 is specified by the user. The iteration
351 c will stop when
352 c
353 c (f^k - f^{k+1})/max{|f^k|,|f^{k+1}|,1} <= factr*epsmch
354 c
355 c where epsmch is the machine precision, which is automatically
356 c generated by the code.
357 c On exit factr is unchanged.
358 c
359 c pgtol is a double precision variable.
360 c On entry pgtol >= 0 is specified by the user. The iteration
361 c will stop when
362 c
363 c max{|proj g_i | i = 1, ..., n} <= pgtol
364 c
365 c where pg_i is the ith component of the projected gradient.
366 c On exit pgtol is unchanged.
367 c
368 c ws, wy, sy, and wt are double precision working arrays used to
369 c store the following information defining the limited memory
370 c BFGS matrix:
371 c ws, of dimension n x m, stores S, the matrix of s-vectors;
372 c wy, of dimension n x m, stores Y, the matrix of y-vectors;
373 c sy, of dimension m x m, stores S'Y;
374 c ss, of dimension m x m, stores S'S;
375 c yy, of dimension m x m, stores Y'Y;
376 c wt, of dimension m x m, stores the Cholesky factorization
377 c of (theta*S'S+LD^(-1)L'); see eq.
378 c (2.26) in [3].
379 c
380 c wn is a double precision working array of dimension 2m x 2m
381 c used to store the LEL^T factorization of the indefinite matrix
382 c K = [-D -Y'ZZ'Y/theta L_a'-R_z' ]
383 c [L_a -R_z theta*S'AA'S ]
384 c
385 c where E = [-I 0]
386 c [ 0 I]
387 c
388 c snd is a double precision working array of dimension 2m x 2m
389 c used to store the lower triangular part of
390 c N = [Y' ZZ'Y L_a'+R_z']
391 c [L_a +R_z S'AA'S ]
392 c
393 c z(n),r(n),d(n),t(n), xp(n),wa(8*m) are double precision working arrays.
394 c z is used at different times to store the Cauchy point and
395 c the Newton point.
396 c xp is used to safeguard the projected Newton direction
397 c
398 c sg(m),sgo(m),yg(m),ygo(m) are double precision working arrays.
399 c
400 c index is an integer working array of dimension n.
401 c In subroutine freev, index is used to store the free and fixed
402 c variables at the Generalized Cauchy Point (GCP).
403 c
404 c iwhere is an integer working array of dimension n used to record
405 c the status of the vector x for GCP computation.
406 c iwhere(i)=0 or -3 if x(i) is free and has bounds,
407 c 1 if x(i) is fixed at l(i), and l(i) .ne. u(i)
408 c 2 if x(i) is fixed at u(i), and u(i) .ne. l(i)
409 c 3 if x(i) is always fixed, i.e., u(i)=x(i)=l(i)
410 c -1 if x(i) is always free, i.e., no bounds on it.
411 c
412 c indx2 is an integer working array of dimension n.
413 c Within subroutine cauchy, indx2 corresponds to the array iorder.
414 c In subroutine freev, a list of variables entering and leaving
415 c the free set is stored in indx2, and it is passed on to
416 c subroutine formk with this information.
417 c
418 c task is a working string of characters of length 60 indicating
419 c the current job when entering and leaving this subroutine.
420 c
421 c iprint is an INTEGER variable that must be set by the user.
422 c It controls the frequency and type of output generated:
423 c iprint<0 no output is generated;
424 c iprint=0 print only one line at the last iteration;
425 c 0<iprint<99 print also f and |proj g| every iprint iterations;
426 c iprint=99 print details of every iteration except n-vectors;
427 c iprint=100 print also the changes of active set and final x;
428 c iprint>100 print details of every iteration including x and g;
429 c When iprint > 0, the file iterate.dat will be created to
430 c summarize the iteration.
431 c
432 c csave is a working string of characters of length 60.
433 c
434 c lsave is a logical working array of dimension 4.
435 c
436 c isave is an integer working array of dimension 23.
437 c
438 c dsave is a double precision working array of dimension 29.
439 c
440 c
441 c Subprograms called
442 c
443 c L-BFGS-B Library ... cauchy, subsm, lnsrlb, formk,
444 c
445 c errclb, prn1lb, prn2lb, prn3lb, active, projgr,
446 c
447 c freev, cmprlb, matupd, formt.
448 c
449 c Minpack2 Library ... timer
450 c
451 c Linpack Library ... dcopy, ddot.
452 c
453 c
454 c References:
455 c
456 c [1] R. H. Byrd, P. Lu, J. Nocedal and C. Zhu, ``A limited
457 c memory algorithm for bound constrained optimization'',
458 c SIAM J. Scientific Computing 16 (1995), no. 5, pp. 1190--1208.
459 c
460 c [2] C. Zhu, R.H. Byrd, P. Lu, J. Nocedal, ``L-BFGS-B: FORTRAN
461 c Subroutines for Large Scale Bound Constrained Optimization''
462 c Tech. Report, NAM-11, EECS Department, Northwestern University,
463 c 1994.
464 c
465 c [3] R. Byrd, J. Nocedal and R. Schnabel "Representations of
466 c Quasi-Newton Matrices and their use in Limited Memory Methods'',
467 c Mathematical Programming 63 (1994), no. 4, pp. 129-156.
468 c
469 c (Postscript files of these papers are available via anonymous
470 c ftp to eecs.nwu.edu in the directory pub/lbfgs/lbfgs_bcm.)
471 c
472 c * * *
473 c
474 c NEOS, November 1994. (Latest revision June 1996.)
475 c Optimization Technology Center.
476 c Argonne National Laboratory and Northwestern University.
477 c Written by
478 c Ciyou Zhu
479 c in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal.
480 c
481 c
482 c ************
483 
484  logical prjctd,cnstnd,boxed,updatd,wrk
485  character*3 word
486  integer i,k,nintol,itfile,iback,nskip,
487  + head,col,iter,itail,iupdat,
488  + nseg,nfgv,info,ifun,
489  + iword,nfree,nact,ileave,nenter
490  double precision theta,fold,ddot,dr,rr,tol,
491  + xstep,sbgnrm,ddum,dnorm,dtd,epsmch,
492  + cpu1,cpu2,cachyt,sbtime,lnscht,time1,time2,
493  + gd,gdold,stp,stpmx,time
494  double precision one,zero
495  parameter(one=1.0d0,zero=0.0d0)
496 
497  if (task .eq. 'START') then
498 
499  epsmch = epsilon(one)
500 
501  call timer(time1)
502 
503 c Initialize counters and scalars when task='START'.
504 
505 c for the limited memory BFGS matrices:
506  col = 0
507  head = 1
508  theta = one
509  iupdat = 0
510  updatd = .false.
511  iback = 0
512  itail = 0
513  iword = 0
514  nact = 0
515  ileave = 0
516  nenter = 0
517  fold = zero
518  dnorm = zero
519  cpu1 = zero
520  gd = zero
521  stpmx = zero
522  sbgnrm = zero
523  stp = zero
524  gdold = zero
525  dtd = zero
526 
527 c for operation counts:
528  iter = 0
529  nfgv = 0
530  nseg = 0
531  nintol = 0
532  nskip = 0
533  nfree = n
534  ifun = 0
535 c for stopping tolerance:
536  tol = factr*epsmch
537 
538 c for measuring running time:
539  cachyt = 0
540  sbtime = 0
541  lnscht = 0
542 
543 c 'word' records the status of subspace solutions.
544  word = '---'
545 
546 c 'info' records the termination information.
547  info = 0
548 
549  itfile = 8
550  if (iprint .ge. 1) then
551 c open a summary file 'iterate.dat'
552  open (8, file = 'iterate.dat', status = 'unknown')
553  endif
554 
555 c Check the input arguments for errors.
556 
557  call errclb(n,m,factr,l,u,nbd,task,info,k)
558  if (task(1:5) .eq. 'ERROR') then
559  call prn3lb(n,x,f,task,iprint,info,itfile,
560  + iter,nfgv,nintol,nskip,nact,sbgnrm,
561  + zero,nseg,word,iback,stp,xstep,k,
562  + cachyt,sbtime,lnscht)
563  return
564  endif
565 
566  call prn1lb(n,m,l,u,x,iprint,itfile,epsmch)
567 
568 c Initialize iwhere & project x onto the feasible set.
569 
570  call active(n,l,u,nbd,x,iwhere,iprint,prjctd,cnstnd,boxed)
571 
572 c The end of the initialization.
573 
574  else
575 c restore local variables.
576 
577  prjctd = lsave(1)
578  cnstnd = lsave(2)
579  boxed = lsave(3)
580  updatd = lsave(4)
581 
582  nintol = isave(1)
583  itfile = isave(3)
584  iback = isave(4)
585  nskip = isave(5)
586  head = isave(6)
587  col = isave(7)
588  itail = isave(8)
589  iter = isave(9)
590  iupdat = isave(10)
591  nseg = isave(12)
592  nfgv = isave(13)
593  info = isave(14)
594  ifun = isave(15)
595  iword = isave(16)
596  nfree = isave(17)
597  nact = isave(18)
598  ileave = isave(19)
599  nenter = isave(20)
600 
601  theta = dsave(1)
602  fold = dsave(2)
603  tol = dsave(3)
604  dnorm = dsave(4)
605  epsmch = dsave(5)
606  cpu1 = dsave(6)
607  cachyt = dsave(7)
608  sbtime = dsave(8)
609  lnscht = dsave(9)
610  time1 = dsave(10)
611  gd = dsave(11)
612  stpmx = dsave(12)
613  sbgnrm = dsave(13)
614  stp = dsave(14)
615  gdold = dsave(15)
616  dtd = dsave(16)
617 
618 c After returning from the driver go to the point where execution
619 c is to resume.
620 
621  if (task(1:5) .eq. 'FG_LN') goto 666
622  if (task(1:5) .eq. 'NEW_X') goto 777
623  if (task(1:5) .eq. 'FG_ST') goto 111
624  if (task(1:4) .eq. 'STOP') then
625  if (task(7:9) .eq. 'CPU') then
626 c restore the previous iterate.
627  call dcopy(n,t,1,x,1)
628  call dcopy(n,r,1,g,1)
629  f = fold
630  endif
631  goto 999
632  endif
633  endif
634 
635 c Compute f0 and g0.
636 
637  task = 'FG_START'
638 c return to the driver to calculate f and g; reenter at 111.
639  goto 1000
640  111 continue
641  nfgv = 1
642 
643 c Compute the infinity norm of the (-) projected gradient.
644 
645  call projgr(n,l,u,nbd,x,g,sbgnrm)
646 
647  if (iprint .ge. 1) then
648  write (6,1002) iter,f,sbgnrm
649  write (itfile,1003) iter,nfgv,sbgnrm,f
650  endif
651  if (sbgnrm .le. pgtol) then
652 c terminate the algorithm.
653  task = 'CONVERGENCE: NORM_OF_PROJECTED_GRADIENT_<=_PGTOL'
654  goto 999
655  endif
656 
657 c ----------------- the beginning of the loop --------------------------
658 
659  222 continue
660  if (iprint .ge. 99) write (6,1001) iter + 1
661  iword = -1
662 c
663  if (.not. cnstnd .and. col .gt. 0) then
664 c skip the search for GCP.
665  call dcopy(n,x,1,z,1)
666  wrk = updatd
667  nseg = 0
668  goto 333
669  endif
670 
671 cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
672 c
673 c Compute the Generalized Cauchy Point (GCP).
674 c
675 cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
676 
677  call timer(cpu1)
678  call cauchy(n,x,l,u,nbd,g,indx2,iwhere,t,d,z,
679  + m,wy,ws,sy,wt,theta,col,head,
680  + wa(1),wa(2*m+1),wa(4*m+1),wa(6*m+1),nseg,
681  + iprint, sbgnrm, info, epsmch)
682  if (info .ne. 0) then
683 c singular triangular system detected; refresh the lbfgs memory.
684  if(iprint .ge. 1) write (6, 1005)
685  info = 0
686  col = 0
687  head = 1
688  theta = one
689  iupdat = 0
690  updatd = .false.
691  call timer(cpu2)
692  cachyt = cachyt + cpu2 - cpu1
693  goto 222
694  endif
695  call timer(cpu2)
696  cachyt = cachyt + cpu2 - cpu1
697  nintol = nintol + nseg
698 
699 c Count the entering and leaving variables for iter > 0;
700 c find the index set of free and active variables at the GCP.
701 
702  call freev(n,nfree,index,nenter,ileave,indx2,
703  + iwhere,wrk,updatd,cnstnd,iprint,iter)
704  nact = n - nfree
705 
706  333 continue
707 
708 c If there are no free variables or B=theta*I, then
709 c skip the subspace minimization.
710 
711  if (nfree .eq. 0 .or. col .eq. 0) goto 555
712 
713 cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
714 c
715 c Subspace minimization.
716 c
717 cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
718 
719  call timer(cpu1)
720 
721 c Form the LEL^T factorization of the indefinite
722 c matrix K = [-D -Y'ZZ'Y/theta L_a'-R_z' ]
723 c [L_a -R_z theta*S'AA'S ]
724 c where E = [-I 0]
725 c [ 0 I]
726 
727  if (wrk) call formk(n,nfree,index,nenter,ileave,indx2,iupdat,
728  + updatd,wn,snd,m,ws,wy,sy,theta,col,head,info)
729  if (info .ne. 0) then
730 c nonpositive definiteness in Cholesky factorization;
731 c refresh the lbfgs memory and restart the iteration.
732  if(iprint .ge. 1) write (6, 1006)
733  info = 0
734  col = 0
735  head = 1
736  theta = one
737  iupdat = 0
738  updatd = .false.
739  call timer(cpu2)
740  sbtime = sbtime + cpu2 - cpu1
741  goto 222
742  endif
743 
744 c compute r=-Z'B(xcp-xk)-Z'g (using wa(2m+1)=W'(xcp-x)
745 c from 'cauchy').
746  call cmprlb(n,m,x,g,ws,wy,sy,wt,z,r,wa,index,
747  + theta,col,head,nfree,cnstnd,info)
748  if (info .ne. 0) goto 444
749 
750 c-jlm-jn call the direct method.
751 
752  call subsm( n, m, nfree, index, l, u, nbd, z, r, xp, ws, wy,
753  + theta, x, g, col, head, iword, wa, wn, iprint, info)
754  444 continue
755  if (info .ne. 0) then
756 c singular triangular system detected;
757 c refresh the lbfgs memory and restart the iteration.
758  if(iprint .ge. 1) write (6, 1005)
759  info = 0
760  col = 0
761  head = 1
762  theta = one
763  iupdat = 0
764  updatd = .false.
765  call timer(cpu2)
766  sbtime = sbtime + cpu2 - cpu1
767  goto 222
768  endif
769 
770  call timer(cpu2)
771  sbtime = sbtime + cpu2 - cpu1
772  555 continue
773 
774 cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
775 c
776 c Line search and optimality tests.
777 c
778 cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
779 
780 c Generate the search direction d:=z-x.
781 
782  do 40 i = 1, n
783  d(i) = z(i) - x(i)
784  40 continue
785  call timer(cpu1)
786  666 continue
787  call lnsrlb(n,l,u,nbd,x,f,fold,gd,gdold,g,d,r,t,z,stp,dnorm,
788  + dtd,xstep,stpmx,iter,ifun,iback,nfgv,info,task,
789  + boxed,cnstnd,csave,isave(22),dsave(17))
790  if (info .ne. 0 .or. iback .ge. 20) then
791 c restore the previous iterate.
792  call dcopy(n,t,1,x,1)
793  call dcopy(n,r,1,g,1)
794  f = fold
795  if (col .eq. 0) then
796 c abnormal termination.
797  if (info .eq. 0) then
798  info = -9
799 c restore the actual number of f and g evaluations etc.
800  nfgv = nfgv - 1
801  ifun = ifun - 1
802  iback = iback - 1
803  endif
804  task = 'ABNORMAL_TERMINATION_IN_LNSRCH'
805  iter = iter + 1
806  goto 999
807  else
808 c refresh the lbfgs memory and restart the iteration.
809  if(iprint .ge. 1) write (6, 1008)
810  if (info .eq. 0) nfgv = nfgv - 1
811  info = 0
812  col = 0
813  head = 1
814  theta = one
815  iupdat = 0
816  updatd = .false.
817  task = 'RESTART_FROM_LNSRCH'
818  call timer(cpu2)
819  lnscht = lnscht + cpu2 - cpu1
820  goto 222
821  endif
822  else if (task(1:5) .eq. 'FG_LN') then
823 c return to the driver for calculating f and g; reenter at 666.
824  goto 1000
825  else
826 c calculate and print out the quantities related to the new X.
827  call timer(cpu2)
828  lnscht = lnscht + cpu2 - cpu1
829  iter = iter + 1
830 
831 c Compute the infinity norm of the projected (-)gradient.
832 
833  call projgr(n,l,u,nbd,x,g,sbgnrm)
834 
835 c Print iteration information.
836 
837  call prn2lb(n,x,f,g,iprint,itfile,iter,nfgv,nact,
838  + sbgnrm,nseg,word,iword,iback,stp,xstep)
839  goto 1000
840  endif
841  777 continue
842 
843 c Test for termination.
844 
845  if (sbgnrm .le. pgtol) then
846 c terminate the algorithm.
847  task = 'CONVERGENCE: NORM_OF_PROJECTED_GRADIENT_<=_PGTOL'
848  goto 999
849  endif
850 
851  ddum = max(abs(fold), abs(f), one)
852  if ((fold - f) .le. tol*ddum) then
853 c terminate the algorithm.
854  task = 'CONVERGENCE: REL_REDUCTION_OF_F_<=_FACTR*EPSMCH'
855  if (iback .ge. 10) info = -5
856 c i.e., to issue a warning if iback>10 in the line search.
857  goto 999
858  endif
859 
860 c Compute d=newx-oldx, r=newg-oldg, rr=y'y and dr=y's.
861 
862  do 42 i = 1, n
863  r(i) = g(i) - r(i)
864  42 continue
865  rr = ddot(n,r,1,r,1)
866  if (stp .eq. one) then
867  dr = gd - gdold
868  ddum = -gdold
869  else
870  dr = (gd - gdold)*stp
871  call dscal(n,stp,d,1)
872  ddum = -gdold*stp
873  endif
874 
875  if (dr .le. epsmch*ddum) then
876 c skip the L-BFGS update.
877  nskip = nskip + 1
878  updatd = .false.
879  if (iprint .ge. 1) write (6,1004) dr, ddum
880  goto 888
881  endif
882 
883 cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
884 c
885 c Update the L-BFGS matrix.
886 c
887 cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc
888 
889  updatd = .true.
890  iupdat = iupdat + 1
891 
892 c Update matrices WS and WY and form the middle matrix in B.
893 
894  call matupd(n,m,ws,wy,sy,ss,d,r,itail,
895  + iupdat,col,head,theta,rr,dr,stp,dtd)
896 
897 c Form the upper half of the pds T = theta*SS + L*D^(-1)*L';
898 c Store T in the upper triangular of the array wt;
899 c Cholesky factorize T to J*J' with
900 c J' stored in the upper triangular of wt.
901 
902  call formt(m,wt,sy,ss,col,theta,info)
903 
904  if (info .ne. 0) then
905 c nonpositive definiteness in Cholesky factorization;
906 c refresh the lbfgs memory and restart the iteration.
907  if(iprint .ge. 1) write (6, 1007)
908  info = 0
909  col = 0
910  head = 1
911  theta = one
912  iupdat = 0
913  updatd = .false.
914  goto 222
915  endif
916 
917 c Now the inverse of the middle matrix in B is
918 
919 c [ D^(1/2) O ] [ -D^(1/2) D^(-1/2)*L' ]
920 c [ -L*D^(-1/2) J ] [ 0 J' ]
921 
922  888 continue
923 
924 c -------------------- the end of the loop -----------------------------
925 
926  goto 222
927  999 continue
928  call timer(time2)
929  time = time2 - time1
930  call prn3lb(n,x,f,task,iprint,info,itfile,
931  + iter,nfgv,nintol,nskip,nact,sbgnrm,
932  + time,nseg,word,iback,stp,xstep,k,
933  + cachyt,sbtime,lnscht)
934  1000 continue
935 
936 c Save local variables.
937 
938  lsave(1) = prjctd
939  lsave(2) = cnstnd
940  lsave(3) = boxed
941  lsave(4) = updatd
942 
943  isave(1) = nintol
944  isave(3) = itfile
945  isave(4) = iback
946  isave(5) = nskip
947  isave(6) = head
948  isave(7) = col
949  isave(8) = itail
950  isave(9) = iter
951  isave(10) = iupdat
952  isave(12) = nseg
953  isave(13) = nfgv
954  isave(14) = info
955  isave(15) = ifun
956  isave(16) = iword
957  isave(17) = nfree
958  isave(18) = nact
959  isave(19) = ileave
960  isave(20) = nenter
961 
962  dsave(1) = theta
963  dsave(2) = fold
964  dsave(3) = tol
965  dsave(4) = dnorm
966  dsave(5) = epsmch
967  dsave(6) = cpu1
968  dsave(7) = cachyt
969  dsave(8) = sbtime
970  dsave(9) = lnscht
971  dsave(10) = time1
972  dsave(11) = gd
973  dsave(12) = stpmx
974  dsave(13) = sbgnrm
975  dsave(14) = stp
976  dsave(15) = gdold
977  dsave(16) = dtd
978 
979  1001 format (//,'ITERATION ',i5)
980  1002 format
981  + (/,'At iterate',i5,4x,'f= ',1p,d12.5,4x,'|proj g|= ',1p,d12.5)
982  1003 format (2(1x,i4),5x,'-',5x,'-',3x,'-',5x,'-',5x,'-',8x,'-',3x,
983  + 1p,2(1x,d10.3))
984  1004 format (' ys=',1p,e10.3,' -gs=',1p,e10.3,' BFGS update SKIPPED')
985  1005 format (/,
986  +' Singular triangular system detected;',/,
987  +' refresh the lbfgs memory and restart the iteration.')
988  1006 format (/,
989  +' Nonpositive definiteness in Cholesky factorization in formk;',/,
990  +' refresh the lbfgs memory and restart the iteration.')
991  1007 format (/,
992  +' Nonpositive definiteness in Cholesky factorization in formt;',/,
993  +' refresh the lbfgs memory and restart the iteration.')
994  1008 format (/,
995  +' Bad direction in the line search;',/,
996  +' refresh the lbfgs memory and restart the iteration.')
997 
998  return
999 
subroutine timer(ttime)
Definition: timer.f:7
#define max(a, b)
Definition: cascade.c:32
subroutine dcopy(N, DX, INCX, DY, INCY)
Definition: dgmres.f:1381
subroutine formk(n, nsub, ind, nenter, ileave, indx2, iupdat, updatd, wn, wn1, m, ws, wy, sy, theta, col, head, info)
Definition: lbfgsb.f:1851
subroutine freev(n, nfree, index, nenter, ileave, indx2, iwhere, wrk, updatd, cnstnd, iprint, iter)
Definition: lbfgsb.f:2243
subroutine matupd(n, m, ws, wy, sy, ss, d, r, itail, iupdat, col, head, theta, rr, dr, stp, dtd)
Definition: lbfgsb.f:2586
subroutine active(n, l, u, nbd, x, iwhere, iprint, prjctd, cnstnd, boxed)
Definition: lbfgsb.f:1006
subroutine errclb(n, m, factr, l, u, nbd, task, info, k)
Definition: lbfgsb.f:1789
subroutine dscal(n, da, dx, incx)
Definition: dgesv.f:1746
subroutine formt(m, wt, sy, ss, col, theta, info)
Definition: lbfgsb.f:2174
subroutine cmprlb(n, m, x, g, ws, wy, sy, wt, z, r, wa, index, theta, col, head, nfree, cnstnd, info)
Definition: lbfgsb.f:1722
subroutine lnsrlb(n, l, u, nbd, x, f, fold, gd, gdold, g, d, r, t, z, stp, dnorm, dtd, xstep, stpmx, iter, ifun, iback, nfgv, info, task, boxed, cnstnd, csave, isave, dsave)
Definition: lbfgsb.f:2457
subroutine cauchy(n, x, l, u, nbd, g, iorder, iwhere, t, d, xcp, m, wy, ws, sy, wt, theta, col, head, p, c, wbp, v, nseg, iprint, sbgnrm, info, epsmch)
Definition: lbfgsb.f:1225
static double * time1
Definition: mafillsmmain.c:41
subroutine prn1lb(n, m, l, u, x, iprint, itfile, epsmch)
Definition: lbfgsb.f:2672
subroutine prn3lb(n, x, f, task, iprint, info, itfile, iter, nfgv, nintol, nskip, nact, sbgnrm, time, nseg, word, iback, stp, xstep, k, cachyt, sbtime, lnscht)
Definition: lbfgsb.f:2814
subroutine subsm(n, m, nsub, ind, l, u, nbd, x, d, xp, ws, wy, theta, xx, gg, col, head, iword, wv, wn, iprint, info)
Definition: lbfgsb.f:2994
subroutine prn2lb(n, x, f, g, iprint, itfile, iter, nfgv, nact, sbgnrm, nseg, word, iword, iback, stp, xstep)
Definition: lbfgsb.f:2744
double precision function ddot(N, DX, INCX, DY, INCY)
Definition: dgmres.f:2469
subroutine projgr(n, l, u, nbd, x, g, sbgnrm)
Definition: lbfgsb.f:2943

◆ matupd()

subroutine matupd ( integer  n,
integer  m,
double precision, dimension(n, m)  ws,
double precision, dimension(n, m)  wy,
double precision, dimension(m, m)  sy,
double precision, dimension(m, m)  ss,
double precision, dimension(n)  d,
double precision, dimension(n)  r,
integer  itail,
integer  iupdat,
integer  col,
integer  head,
double precision  theta,
double precision  rr,
double precision  dr,
double precision  stp,
double precision  dtd 
)
2586 
2587  integer n, m, itail, iupdat, col, head
2588  double precision theta, rr, dr, stp, dtd, d(n), r(n),
2589  + ws(n, m), wy(n, m), sy(m, m), ss(m, m)
2590 
2591 c ************
2592 c
2593 c Subroutine matupd
2594 c
2595 c This subroutine updates matrices WS and WY, and forms the
2596 c middle matrix in B.
2597 c
2598 c Subprograms called:
2599 c
2600 c Linpack ... dcopy, ddot.
2601 c
2602 c
2603 c * * *
2604 c
2605 c NEOS, November 1994. (Latest revision June 1996.)
2606 c Optimization Technology Center.
2607 c Argonne National Laboratory and Northwestern University.
2608 c Written by
2609 c Ciyou Zhu
2610 c in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal.
2611 c
2612 c
2613 c ************
2614 
2615  integer j,pointr
2616  double precision ddot
2617  double precision one
2618  parameter(one=1.0d0)
2619 
2620 c Set pointers for matrices WS and WY.
2621 
2622  if (iupdat .le. m) then
2623  col = iupdat
2624  itail = mod(head+iupdat-2,m) + 1
2625  else
2626  itail = mod(itail,m) + 1
2627  head = mod(head,m) + 1
2628  endif
2629 
2630 c Update matrices WS and WY.
2631 
2632  call dcopy(n,d,1,ws(1,itail),1)
2633  call dcopy(n,r,1,wy(1,itail),1)
2634 
2635 c Set theta=yy/ys.
2636 
2637  theta = rr/dr
2638 
2639 c Form the middle matrix in B.
2640 
2641 c update the upper triangle of SS,
2642 c and the lower triangle of SY:
2643  if (iupdat .gt. m) then
2644 c move old information
2645  do 50 j = 1, col - 1
2646  call dcopy(j,ss(2,j+1),1,ss(1,j),1)
2647  call dcopy(col-j,sy(j+1,j+1),1,sy(j,j),1)
2648  50 continue
2649  endif
2650 c add new information: the last row of SY
2651 c and the last column of SS:
2652  pointr = head
2653  do 51 j = 1, col - 1
2654  sy(col,j) = ddot(n,d,1,wy(1,pointr),1)
2655  ss(j,col) = ddot(n,ws(1,pointr),1,d,1)
2656  pointr = mod(pointr,m) + 1
2657  51 continue
2658  if (stp .eq. one) then
2659  ss(col,col) = dtd
2660  else
2661  ss(col,col) = stp*stp*dtd
2662  endif
2663  sy(col,col) = dr
2664 
2665  return
2666 
subroutine dcopy(N, DX, INCX, DY, INCY)
Definition: dgmres.f:1381
double precision function ddot(N, DX, INCX, DY, INCY)
Definition: dgmres.f:2469

◆ prn1lb()

subroutine prn1lb ( integer  n,
integer  m,
double precision, dimension(n)  l,
double precision, dimension(n)  u,
double precision, dimension(n)  x,
integer  iprint,
integer  itfile,
double precision  epsmch 
)
2672 
2673  integer n, m, iprint, itfile
2674  double precision epsmch, x(n), l(n), u(n)
2675 
2676 c ************
2677 c
2678 c Subroutine prn1lb
2679 c
2680 c This subroutine prints the input data, initial point, upper and
2681 c lower bounds of each variable, machine precision, as well as
2682 c the headings of the output.
2683 c
2684 c
2685 c * * *
2686 c
2687 c NEOS, November 1994. (Latest revision June 1996.)
2688 c Optimization Technology Center.
2689 c Argonne National Laboratory and Northwestern University.
2690 c Written by
2691 c Ciyou Zhu
2692 c in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal.
2693 c
2694 c
2695 c ************
2696 
2697  integer i
2698 
2699  if (iprint .ge. 0) then
2700  write (6,7001) epsmch
2701  write (6,*) 'N = ',n,' M = ',m
2702  if (iprint .ge. 1) then
2703  write (itfile,2001) epsmch
2704  write (itfile,*)'N = ',n,' M = ',m
2705  write (itfile,9001)
2706  if (iprint .gt. 100) then
2707  write (6,1004) 'L =',(l(i),i = 1,n)
2708  write (6,1004) 'X0 =',(x(i),i = 1,n)
2709  write (6,1004) 'U =',(u(i),i = 1,n)
2710  endif
2711  endif
2712  endif
2713 
2714  1004 format (/,a4, 1p, 6(1x,d11.4),/,(4x,1p,6(1x,d11.4)))
2715  2001 format ('RUNNING THE L-BFGS-B CODE',/,/,
2716  + 'it = iteration number',/,
2717  + 'nf = number of function evaluations',/,
2718  + 'nseg = number of segments explored during the Cauchy search',/,
2719  + 'nact = number of active bounds at the generalized Cauchy point'
2720  + ,/,
2721  + 'sub = manner in which the subspace minimization terminated:'
2722  + ,/,' con = converged, bnd = a bound was reached',/,
2723  + 'itls = number of iterations performed in the line search',/,
2724  + 'stepl = step length used',/,
2725  + 'tstep = norm of the displacement (total step)',/,
2726  + 'projg = norm of the projected gradient',/,
2727  + 'f = function value',/,/,
2728  + ' * * *',/,/,
2729  + 'Machine precision =',1p,d10.3)
2730  7001 format ('RUNNING THE L-BFGS-B CODE',/,/,
2731  + ' * * *',/,/,
2732  + 'Machine precision =',1p,d10.3)
2733  9001 format (/,3x,'it',3x,'nf',2x,'nseg',2x,'nact',2x,'sub',2x,'itls',
2734  + 2x,'stepl',4x,'tstep',5x,'projg',8x,'f')
2735 
2736  return
2737 

◆ prn2lb()

subroutine prn2lb ( integer  n,
double precision, dimension(n)  x,
double precision  f,
double precision, dimension(n)  g,
integer  iprint,
integer  itfile,
integer  iter,
integer  nfgv,
integer  nact,
double precision  sbgnrm,
integer  nseg,
character*3  word,
integer  iword,
integer  iback,
double precision  stp,
double precision  xstep 
)
2744 
2745  character*3 word
2746  integer n, iprint, itfile, iter, nfgv, nact, nseg,
2747  + iword, iback
2748  double precision f, sbgnrm, stp, xstep, x(n), g(n)
2749 
2750 c ************
2751 c
2752 c Subroutine prn2lb
2753 c
2754 c this subroutine prints out new information after a successful
2755 c line search.
2756 c
2757 c
2758 c * * *
2759 c
2760 c neos, november 1994. (latest revision june 1996.)
2761 c optimization technology center.
2762 c argonne national laboratory and northwestern university.
2763 c written by
2764 c ciyou zhu
2765 c in collaboration with r.h. byrd, p. lu-chen and j. nocedal.
2766 c
2767 c
2768 c ************
2769 
2770  integer i,imod
2771 
2772 c 'word' records the status of subspace solutions.
2773  if (iword .eq. 0) then
2774 c the subspace minimization converged.
2775  word = 'con'
2776  else if (iword .eq. 1) then
2777 c the subspace minimization stopped at a bound.
2778  word = 'bnd'
2779  else if (iword .eq. 5) then
2780 c the truncated newton step has been used.
2781  word = 'TNT'
2782  else
2783  word = '---'
2784  endif
2785  if (iprint .ge. 99) then
2786  write (6,*) 'LINE SEARCH',iback,' times; norm of step = ',xstep
2787  write (6,2001) iter,f,sbgnrm
2788  if (iprint .gt. 100) then
2789  write (6,1004) 'X =',(x(i), i = 1, n)
2790  write (6,1004) 'G =',(g(i), i = 1, n)
2791  endif
2792  else if (iprint .gt. 0) then
2793  imod = mod(iter,iprint)
2794  if (imod .eq. 0) write (6,2001) iter,f,sbgnrm
2795  endif
2796  if (iprint .ge. 1) write (itfile,3001)
2797  + iter,nfgv,nseg,nact,word,iback,stp,xstep,sbgnrm,f
2798 
2799  1004 format (/,a4, 1p, 6(1x,d11.4),/,(4x,1p,6(1x,d11.4)))
2800  2001 format
2801  + (/,'At iterate',i5,4x,'f= ',1p,d12.5,4x,'|proj g|= ',1p,d12.5)
2802  3001 format(2(1x,i4),2(1x,i5),2x,a3,1x,i4,1p,2(2x,d7.1),1p,2(1x,d10.3))
2803 
2804  return
2805 
subroutine newton(icalccg, ne, ipkon, lakon, kon, t0, co, rhcon, nrhcon, ntmat_, physcon, nelem, cgr, bodyf, ielmat, ithermal, vold, mi)
Definition: newton.f:22
subroutine subspace(d, aa, bb, cc, alpham, betam, nev, xini, cd, cv, time, rwork, lrw, m, jout, rpar, bj, iwork, liw, iddebdf, bjp)
Definition: subspace.f:21
subroutine prn2lb(n, x, f, g, iprint, itfile, iter, nfgv, nact, sbgnrm, nseg, word, iword, iback, stp, xstep)
Definition: lbfgsb.f:2744

◆ prn3lb()

subroutine prn3lb ( integer  n,
double precision, dimension(n)  x,
double precision  f,
character*60  task,
integer  iprint,
integer  info,
integer  itfile,
integer  iter,
integer  nfgv,
integer  nintol,
integer  nskip,
integer  nact,
double precision  sbgnrm,
double precision  time,
integer  nseg,
character*3  word,
integer  iback,
double precision  stp,
double precision  xstep,
integer  k,
double precision  cachyt,
double precision  sbtime,
double precision  lnscht 
)
2814 
2815  character*60 task
2816  character*3 word
2817  integer n, iprint, info, itfile, iter, nfgv, nintol,
2818  + nskip, nact, nseg, iback, k
2819  double precision f, sbgnrm, time, stp, xstep, cachyt, sbtime,
2820  + lnscht, x(n)
2821 
2822 c ************
2823 c
2824 c Subroutine prn3lb
2825 c
2826 c this subroutine prints out information when either a built-in
2827 c convergence test is satisfied or when an error message is
2828 c generated.
2829 c
2830 c
2831 c * * *
2832 c
2833 c neos, november 1994. (latest revision june 1996.)
2834 c optimization technology center.
2835 c argonne national laboratory and northwestern university.
2836 c written by
2837 c ciyou zhu
2838 c in collaboration with r.h. byrd, p. lu-chen and j. nocedal.
2839 c
2840 c
2841 c ************
2842 
2843  integer i
2844 
2845  if (task(1:5) .eq. 'ERROR') goto 999
2846 
2847  if (iprint .ge. 0) then
2848  write (6,3003)
2849  write (6,3004)
2850  write(6,3005) n,iter,nfgv,nintol,nskip,nact,sbgnrm,f
2851  if (iprint .ge. 100) then
2852  write (6,1004) 'X =',(x(i),i = 1,n)
2853  endif
2854  if (iprint .ge. 1) write (6,*) ' F =',f
2855  endif
2856  999 continue
2857  if (iprint .ge. 0) then
2858  write (6,3009) task
2859  if (info .ne. 0) then
2860  if (info .eq. -1) write (6,9011)
2861  if (info .eq. -2) write (6,9012)
2862  if (info .eq. -3) write (6,9013)
2863  if (info .eq. -4) write (6,9014)
2864  if (info .eq. -5) write (6,9015)
2865  if (info .eq. -6) write (6,*)' Input nbd(',k,') is invalid.'
2866  if (info .eq. -7)
2867  + write (6,*)' l(',k,') > u(',k,'). No feasible solution.'
2868  if (info .eq. -8) write (6,9018)
2869  if (info .eq. -9) write (6,9019)
2870  endif
2871  if (iprint .ge. 1) write (6,3007) cachyt,sbtime,lnscht
2872  write (6,3008) time
2873  if (iprint .ge. 1) then
2874  if (info .eq. -4 .or. info .eq. -9) then
2875  write (itfile,3002)
2876  + iter,nfgv,nseg,nact,word,iback,stp,xstep
2877  endif
2878  write (itfile,3009) task
2879  if (info .ne. 0) then
2880  if (info .eq. -1) write (itfile,9011)
2881  if (info .eq. -2) write (itfile,9012)
2882  if (info .eq. -3) write (itfile,9013)
2883  if (info .eq. -4) write (itfile,9014)
2884  if (info .eq. -5) write (itfile,9015)
2885  if (info .eq. -8) write (itfile,9018)
2886  if (info .eq. -9) write (itfile,9019)
2887  endif
2888  write (itfile,3008) time
2889  endif
2890  endif
2891 
2892  1004 format (/,a4, 1p, 6(1x,d11.4),/,(4x,1p,6(1x,d11.4)))
2893  3002 format(2(1x,i4),2(1x,i5),2x,a3,1x,i4,1p,2(2x,d7.1),6x,'-',10x,'-')
2894  3003 format (/,
2895  + ' * * *',/,/,
2896  + 'Tit = total number of iterations',/,
2897  + 'Tnf = total number of function evaluations',/,
2898  + 'Tnint = total number of segments explored during',
2899  + ' Cauchy searches',/,
2900  + 'Skip = number of BFGS updates skipped',/,
2901  + 'Nact = number of active bounds at final generalized',
2902  + ' Cauchy point',/,
2903  + 'Projg = norm of the final projected gradient',/,
2904  + 'F = final function value',/,/,
2905  + ' * * *')
2906  3004 format (/,3x,'N',4x,'Tit',5x,'Tnf',2x,'Tnint',2x,
2907  + 'Skip',2x,'Nact',5x,'Projg',8x,'F')
2908  3005 format (i5,2(1x,i6),(1x,i6),(2x,i4),(1x,i5),1p,2(2x,d10.3))
2909  3007 format (/,' Cauchy time',1p,e10.3,' seconds.',/
2910  + ' Subspace minimization time',1p,e10.3,' seconds.',/
2911  + ' Line search time',1p,e10.3,' seconds.')
2912  3008 format (/,' Total User time',1p,e10.3,' seconds.',/)
2913  3009 format (/,a60)
2914  9011 format (/,
2915  +' Matrix in 1st Cholesky factorization in formk is not Pos. Def.')
2916  9012 format (/,
2917  +' Matrix in 2st Cholesky factorization in formk is not Pos. Def.')
2918  9013 format (/,
2919  +' Matrix in the Cholesky factorization in formt is not Pos. Def.')
2920  9014 format (/,
2921  +' Derivative >= 0, backtracking line search impossible.',/,
2922  +' Previous x, f and g restored.',/,
2923  +' Possible causes: 1 error in function or gradient evaluation;',/,
2924  +' 2 rounding errors dominate computation.')
2925  9015 format (/,
2926  +' Warning: more than 10 function and gradient',/,
2927  +' evaluations in the last line search. Termination',/,
2928  +' may possibly be caused by a bad search direction.')
2929  9018 format (/,' The triangular system is singular.')
2930  9019 format (/,
2931  +' Line search cannot locate an adequate point after 20 function',/
2932  +,' and gradient evaluations. Previous x, f and g restored.',/,
2933  +' Possible causes: 1 error in function or gradient evaluation;',/,
2934  +' 2 rounding error dominate computation.')
2935 
2936  return
2937 
subroutine prn3lb(n, x, f, task, iprint, info, itfile, iter, nfgv, nintol, nskip, nact, sbgnrm, time, nseg, word, iback, stp, xstep, k, cachyt, sbtime, lnscht)
Definition: lbfgsb.f:2814

◆ projgr()

subroutine projgr ( integer  n,
double precision, dimension(n)  l,
double precision, dimension(n)  u,
integer, dimension(n)  nbd,
double precision, dimension(n)  x,
double precision, dimension(n)  g,
double precision  sbgnrm 
)
2943 
2944  integer n, nbd(n)
2945  double precision sbgnrm, x(n), l(n), u(n), g(n)
2946 
2947 c ************
2948 c
2949 c Subroutine projgr
2950 c
2951 c This subroutine computes the infinity norm of the projected
2952 c gradient.
2953 c
2954 c
2955 c * * *
2956 c
2957 c NEOS, November 1994. (Latest revision June 1996.)
2958 c Optimization Technology Center.
2959 c Argonne National Laboratory and Northwestern University.
2960 c Written by
2961 c Ciyou Zhu
2962 c in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal.
2963 c
2964 c
2965 c ************
2966 
2967  integer i
2968  double precision gi
2969  double precision one,zero
2970  parameter(one=1.0d0,zero=0.0d0)
2971 
2972  sbgnrm = zero
2973  do 15 i = 1, n
2974  gi = g(i)
2975  if (nbd(i) .ne. 0) then
2976  if (gi .lt. zero) then
2977  if (nbd(i) .ge. 2) gi = max((x(i)-u(i)),gi)
2978  else
2979  if (nbd(i) .le. 2) gi = min((x(i)-l(i)),gi)
2980  endif
2981  endif
2982  sbgnrm = max(sbgnrm,abs(gi))
2983  15 continue
2984 
2985  return
2986 
#define max(a, b)
Definition: cascade.c:32
#define min(a, b)
Definition: cascade.c:31

◆ setulb()

subroutine setulb ( integer  n,
integer  m,
double precision, dimension(n)  x,
double precision, dimension(n)  l,
double precision, dimension(n)  u,
integer, dimension(n)  nbd,
double precision  f,
double precision, dimension(n)  g,
double precision  factr,
double precision  pgtol,
double precision, dimension(2*m*n + 5*n + 11*m*m + 8*m)  wa,
integer, dimension(3*n)  iwa,
character*60  task,
integer  iprint,
character*60  csave,
logical, dimension(4)  lsave,
integer, dimension(44)  isave,
double precision, dimension(29)  dsave 
)
49 
50  character*60 task, csave
51  logical lsave(4)
52  integer n, m, iprint,
53  + nbd(n), iwa(3*n), isave(44)
54  double precision f, factr, pgtol, x(n), l(n), u(n), g(n),
55 c
56 c-jlm-jn
57  + wa(2*m*n + 5*n + 11*m*m + 8*m), dsave(29)
58 
59 c ************
60 c
61 c Subroutine setulb
62 c
63 c this subroutine partitions the working arrays wa and iwa, and
64 c then uses the limited memory bfgs method to solve the bound
65 c constrained optimization problem by calling mainlb.
66 c(the direct method will be used in the subspace minimization.)
67 c
68 c n is an integer variable.
69 c on entry n is the dimension of the problem.
70 c on exit n is unchanged.
71 c
72 c m is an integer variable.
73 c on entry m is the maximum number of variable metric corrections
74 c used to define the limited memory matrix.
75 c on exit m is unchanged.
76 c
77 c x is a double precision array of dimension n.
78 c on entry x is an approximation to the solution.
79 c on exit x is the current approximation.
80 c
81 c l is a double precision array of dimension n.
82 c on entry l is the lower bound on x.
83 c on exit l is unchanged.
84 c
85 c u is a double precision array of dimension n.
86 c on entry u is the upper bound on x.
87 c on exit u is unchanged.
88 c
89 c nbd is an integer array of dimension n.
90 c on entry nbd represents the type of bounds imposed on the
91 c variables, and must be specified as follows:
92 c nbd(i)=0 if x(i) is unbounded,
93 c 1 if x(i) has only a lower bound,
94 c 2 if x(i) has both lower and upper bounds, and
95 c 3 if x(i) has only an upper bound.
96 c on exit nbd is unchanged.
97 c
98 c f is a double precision variable.
99 c on first entry f is unspecified.
100 c on final exit f is the value of the function at x.
101 c
102 c g is a double precision array of dimension n.
103 c on first entry g is unspecified.
104 c on final exit g is the value of the gradient at x.
105 c
106 c factr is a double precision variable.
107 c on entry factr >= 0 is specified by the user. the iteration
108 c will stop when
109 c
110 c(f^k - f^{k+1})/max{|f^k|,|f^{k+1}|,1} <= factr*epsmch
111 c
112 c where epsmch is the machine precision, which is automatically
113 c generated by the code. typical values for factr: 1.d+12 for
114 c low accuracy; 1.d+7 for moderate accuracy; 1.d+1 for extremely
115 c high accuracy.
116 c on exit factr is unchanged.
117 c
118 c pgtol is a double precision variable.
119 c on entry pgtol >= 0 is specified by the user. the iteration
120 c will stop when
121 c
122 c max{|proj g_i | i = 1, ..., n} <= pgtol
123 c
124 c where pg_i is the ith component of the projected gradient.
125 c on exit pgtol is unchanged.
126 c
127 c wa is a double precision working array of length
128 c(2mmax + 5)nmax + 12mmax^2 + 12mmax.
129 c
130 c iwa is an integer working array of length 3nmax.
131 c
132 c task is a working string of characters of length 60 indicating
133 c the current job when entering and quitting this subroutine.
134 c
135 c iprint is an integer variable that must be set by the user.
136 c it controls the frequency and type of output generated:
137 c iprint<0 no output is generated;
138 c iprint=0 print only one line at the last iteration;
139 c 0<iprint<99 print also f and |proj g| every iprint iterations;
140 c iprint=99 print details of every iteration except n-vectors;
141 c iprint=100 print also the changes of active set and final x;
142 c iprint>100 print details of every iteration including x and g;
143 c when iprint > 0, the file iterate.dat will be created to
144 c summarize the iteration.
145 c
146 c csave is a working string of characters of length 60.
147 c
148 c lsave is a logical working array of dimension 4.
149 c on exit with 'task' = new_x, the following information is
150 c available:
151 c If lsave(1) = .true. then the initial x has been replaced by
152 c its projection in the feasible set;
153 c If lsave(2) = .true. then the problem is constrained;
154 c If lsave(3) = .true. then each variable has upper and lower
155 c bounds;
156 c
157 c isave is an integer working array of dimension 44.
158 c on exit with 'task' = new_x, the following information is
159 c available:
160 c isave(22) = the total number of intervals explored in the
161 c search of cauchy points;
162 c isave(26) = the total number of skipped bfgs updates before
163 c the current iteration;
164 c isave(30) = the number of current iteration;
165 c isave(31) = the total number of bfgs updates prior the current
166 c iteration;
167 c isave(33) = the number of intervals explored in the search of
168 c cauchy point in the current iteration;
169 c isave(34) = the total number of function and gradient
170 c evaluations;
171 c isave(36) = the number of function value or gradient
172 c evaluations in the current iteration;
173 c if isave(37) = 0 then the subspace argmin is within the box;
174 c if isave(37) = 1 then the subspace argmin is beyond the box;
175 c isave(38) = the number of free variables in the current
176 c iteration;
177 c isave(39) = the number of active constraints in the current
178 c iteration;
179 c n + 1 - isave(40) = the number of variables leaving the set of
180 c active constraints in the current iteration;
181 c isave(41) = the number of variables entering the set of active
182 c constraints in the current iteration.
183 c
184 c dsave is a double precision working array of dimension 29.
185 c on exit with 'task' = new_x, the following information is
186 c available:
187 c dsave(1) = current 'theta' in the bfgs matrix;
188 c dsave(2) = f(x) in the previous iteration;
189 c dsave(3) = factr*epsmch;
190 c dsave(4) = 2-norm of the line search direction vector;
191 c dsave(5) = the machine precision epsmch generated by the code;
192 c dsave(7) = the accumulated time spent on searching for
193 c cauchy points;
194 c dsave(8) = the accumulated time spent on
195 c subspace minimization;
196 c dsave(9) = the accumulated time spent on line search;
197 c dsave(11) = the slope of the line search function at
198 c the current point of line search;
199 c dsave(12) = the maximum relative step length imposed in
200 c line search;
201 c dsave(13) = the infinity norm of the projected gradient;
202 c dsave(14) = the relative step length in the line search;
203 c dsave(15) = the slope of the line search function at
204 c the starting point of the line search;
205 c dsave(16) = the square of the 2-norm of the line search
206 c direction vector.
207 c
208 c subprograms called:
209 c
210 c l-bfgs-b library ... mainlb.
211 c
212 c
213 c references:
214 c
215 c [1] r. h. byrd, p. lu, j. nocedal and c. zhu, ``a limited
216 c memory algorithm for bound constrained optimization'',
217 c siam j. scientific computing 16 (1995), no. 5, pp. 1190--1208.
218 c
219 c [2] c. zhu, r.h. byrd, p. lu, j. nocedal, ``l-bfgs-b: a
220 c limited memory fortran code for solving bound constrained
221 c optimization problems'', tech. report, nam-11, eecs department,
222 c northwestern university, 1994.
223 c
224 c(postscript files of these papers are available via anonymous
225 c ftp to eecs.nwu.edu in the directory pub/lbfgs/lbfgs_bcm.)
226 c
227 c * * *
228 c
229 c neos, november 1994. (latest revision june 1996.)
230 c optimization technology center.
231 c argonne national laboratory and northwestern university.
232 c written by
233 c ciyou zhu
234 c in collaboration with r.h. byrd, p. lu-chen and j. nocedal.
235 c
236 c
237 c ************
238 c-jlm-jn
239  integer lws,lr,lz,lt,ld,lxp,lwa,
240  + lwy,lsy,lss,lwt,lwn,lsnd
241 
242  if (task .eq. 'START') then
243  isave(1) = m*n
244  isave(2) = m**2
245  isave(3) = 4*m**2
246  isave(4) = 1 ! ws m*n
247  isave(5) = isave(4) + isave(1) ! wy m*n
248  isave(6) = isave(5) + isave(1) ! wsy m**2
249  isave(7) = isave(6) + isave(2) ! wss m**2
250  isave(8) = isave(7) + isave(2) ! wt m**2
251  isave(9) = isave(8) + isave(2) ! wn 4*m**2
252  isave(10) = isave(9) + isave(3) ! wsnd 4*m**2
253  isave(11) = isave(10) + isave(3) ! wz n
254  isave(12) = isave(11) + n ! wr n
255  isave(13) = isave(12) + n ! wd n
256  isave(14) = isave(13) + n ! wt n
257  isave(15) = isave(14) + n ! wxp n
258  isave(16) = isave(15) + n ! wa 8*m
259  endif
260  lws = isave(4)
261  lwy = isave(5)
262  lsy = isave(6)
263  lss = isave(7)
264  lwt = isave(8)
265  lwn = isave(9)
266  lsnd = isave(10)
267  lz = isave(11)
268  lr = isave(12)
269  ld = isave(13)
270  lt = isave(14)
271  lxp = isave(15)
272  lwa = isave(16)
273 
274  call mainlb(n,m,x,l,u,nbd,f,g,factr,pgtol,
275  + wa(lws),wa(lwy),wa(lsy),wa(lss), wa(lwt),
276  + wa(lwn),wa(lsnd),wa(lz),wa(lr),wa(ld),wa(lt),wa(lxp),
277  + wa(lwa),
278  + iwa(1),iwa(n+1),iwa(2*n+1),task,iprint,
279  + csave,lsave,isave(22),dsave)
280 
281  return
282 
subroutine subspace(d, aa, bb, cc, alpham, betam, nev, xini, cd, cv, time, rwork, lrw, m, jout, rpar, bj, iwork, liw, iddebdf, bjp)
Definition: subspace.f:21
#define max(a, b)
Definition: cascade.c:32
subroutine norm(vel, velnorm, nef)
Definition: norm.f:20
subroutine stop()
Definition: stop.f:20
subroutine active(n, l, u, nbd, x, iwhere, iprint, prjctd, cnstnd, boxed)
Definition: lbfgsb.f:1006
subroutine mainlb(n, m, x, l, u, nbd, f, g, factr, pgtol, ws, wy, sy, ss, wt, wn, snd, z, r, d, t, xp, wa, index, iwhere, indx2, task, iprint, csave, lsave, isave, dsave)
Definition: lbfgsb.f:291
subroutine cauchy(n, x, l, u, nbd, g, iorder, iwhere, t, d, xcp, m, wy, ws, sy, wt, theta, col, head, p, c, wbp, v, nseg, iprint, sbgnrm, info, epsmch)
Definition: lbfgsb.f:1225
subroutine setulb(n, m, x, l, u, nbd, f, g, factr, pgtol, wa, iwa, task, iprint, csave, lsave, isave, dsave)
Definition: lbfgsb.f:49
subroutine constraints(inpc, textpart, istep, istat, n, iline, ipol, inl, ipoinp, inp, ipoinpc, nener, nobject, objectset)
Definition: constraints.f:21

◆ subsm()

subroutine subsm ( integer  n,
integer  m,
integer  nsub,
integer, dimension(nsub)  ind,
double precision, dimension(n)  l,
double precision, dimension(n)  u,
integer, dimension(n)  nbd,
double precision, dimension(n)  x,
double precision, dimension(n)  d,
double precision, dimension(n)  xp,
double precision, dimension(n, m)  ws,
double precision, dimension(n, m)  wy,
double precision  theta,
double precision, dimension(n)  xx,
double precision, dimension(n)  gg,
integer  col,
integer  head,
integer  iword,
double precision, dimension(2*m)  wv,
double precision, dimension(2*m, 2*m)  wn,
integer  iprint,
integer  info 
)
2994  implicit none
2995  integer n, m, nsub, col, head, iword, iprint, info,
2996  + ind(nsub), nbd(n)
2997  double precision theta,
2998  + l(n), u(n), x(n), d(n), xp(n), xx(n), gg(n),
2999  + ws(n, m), wy(n, m),
3000  + wv(2*m), wn(2*m, 2*m)
3001 
3002 c **********************************************************************
3003 c
3004 c This routine contains the major changes in the updated version.
3005 c The changes are described in the accompanying paper
3006 c
3007 c Jose Luis Morales, Jorge Nocedal
3008 c "Remark On Algorithm 788: L-BFGS-B: Fortran Subroutines for Large-Scale
3009 c Bound Constrained Optimization". Decemmber 27, 2010.
3010 c
3011 c J.L. Morales Departamento de Matematicas,
3012 c Instituto Tecnologico Autonomo de Mexico
3013 c Mexico D.F.
3014 c
3015 c J, Nocedal Department of Electrical Engineering and
3016 c Computer Science.
3017 c Northwestern University. Evanston, IL. USA
3018 c
3019 c January 17, 2011
3020 c
3021 c **********************************************************************
3022 c
3023 c
3024 c Subroutine subsm
3025 c
3026 c Given xcp, l, u, r, an index set that specifies
3027 c the active set at xcp, and an l-BFGS matrix B
3028 c (in terms of WY, WS, SY, WT, head, col, and theta),
3029 c this subroutine computes an approximate solution
3030 c of the subspace problem
3031 c
3032 c (P) min Q(x) = r'(x-xcp) + 1/2 (x-xcp)' B (x-xcp)
3033 c
3034 c subject to l<=x<=u
3035 c x_i=xcp_i for all i in A(xcp)
3036 c
3037 c along the subspace unconstrained Newton direction
3038 c
3039 c d = -(Z'BZ)^(-1) r.
3040 c
3041 c The formula for the Newton direction, given the L-BFGS matrix
3042 c and the Sherman-Morrison formula, is
3043 c
3044 c d = (1/theta)r + (1/theta*2) Z'WK^(-1)W'Z r.
3045 c
3046 c where
3047 c K = [-D -Y'ZZ'Y/theta L_a'-R_z' ]
3048 c [L_a -R_z theta*S'AA'S ]
3049 c
3050 c Note that this procedure for computing d differs
3051 c from that described in [1]. One can show that the matrix K is
3052 c equal to the matrix M^[-1]N in that paper.
3053 c
3054 c n is an integer variable.
3055 c On entry n is the dimension of the problem.
3056 c On exit n is unchanged.
3057 c
3058 c m is an integer variable.
3059 c On entry m is the maximum number of variable metric corrections
3060 c used to define the limited memory matrix.
3061 c On exit m is unchanged.
3062 c
3063 c nsub is an integer variable.
3064 c On entry nsub is the number of free variables.
3065 c On exit nsub is unchanged.
3066 c
3067 c ind is an integer array of dimension nsub.
3068 c On entry ind specifies the coordinate indices of free variables.
3069 c On exit ind is unchanged.
3070 c
3071 c l is a double precision array of dimension n.
3072 c On entry l is the lower bound of x.
3073 c On exit l is unchanged.
3074 c
3075 c u is a double precision array of dimension n.
3076 c On entry u is the upper bound of x.
3077 c On exit u is unchanged.
3078 c
3079 c nbd is a integer array of dimension n.
3080 c On entry nbd represents the type of bounds imposed on the
3081 c variables, and must be specified as follows:
3082 c nbd(i)=0 if x(i) is unbounded,
3083 c 1 if x(i) has only a lower bound,
3084 c 2 if x(i) has both lower and upper bounds, and
3085 c 3 if x(i) has only an upper bound.
3086 c On exit nbd is unchanged.
3087 c
3088 c x is a double precision array of dimension n.
3089 c On entry x specifies the Cauchy point xcp.
3090 c On exit x(i) is the minimizer of Q over the subspace of
3091 c free variables.
3092 c
3093 c d is a double precision array of dimension n.
3094 c On entry d is the reduced gradient of Q at xcp.
3095 c On exit d is the Newton direction of Q.
3096 c
3097 c xp is a double precision array of dimension n.
3098 c used to safeguard the projected Newton direction
3099 c
3100 c xx is a double precision array of dimension n
3101 c On entry it holds the current iterate
3102 c On output it is unchanged
3103 
3104 c gg is a double precision array of dimension n
3105 c On entry it holds the gradient at the current iterate
3106 c On output it is unchanged
3107 c
3108 c ws and wy are double precision arrays;
3109 c theta is a double precision variable;
3110 c col is an integer variable;
3111 c head is an integer variable.
3112 c On entry they store the information defining the
3113 c limited memory BFGS matrix:
3114 c ws(n,m) stores S, a set of s-vectors;
3115 c wy(n,m) stores Y, a set of y-vectors;
3116 c theta is the scaling factor specifying B_0 = theta I;
3117 c col is the number of variable metric corrections stored;
3118 c head is the location of the 1st s- (or y-) vector in S (or Y).
3119 c On exit they are unchanged.
3120 c
3121 c iword is an integer variable.
3122 c On entry iword is unspecified.
3123 c On exit iword specifies the status of the subspace solution.
3124 c iword = 0 if the solution is in the box,
3125 c 1 if some bound is encountered.
3126 c
3127 c wv is a double precision working array of dimension 2m.
3128 c
3129 c wn is a double precision array of dimension 2m x 2m.
3130 c On entry the upper triangle of wn stores the LEL^T factorization
3131 c of the indefinite matrix
3132 c
3133 c K = [-D -Y'ZZ'Y/theta L_a'-R_z' ]
3134 c [L_a -R_z theta*S'AA'S ]
3135 c where E = [-I 0]
3136 c [ 0 I]
3137 c On exit wn is unchanged.
3138 c
3139 c iprint is an INTEGER variable that must be set by the user.
3140 c It controls the frequency and type of output generated:
3141 c iprint<0 no output is generated;
3142 c iprint=0 print only one line at the last iteration;
3143 c 0<iprint<99 print also f and |proj g| every iprint iterations;
3144 c iprint=99 print details of every iteration except n-vectors;
3145 c iprint=100 print also the changes of active set and final x;
3146 c iprint>100 print details of every iteration including x and g;
3147 c When iprint > 0, the file iterate.dat will be created to
3148 c summarize the iteration.
3149 c
3150 c info is an integer variable.
3151 c On entry info is unspecified.
3152 c On exit info = 0 for normal return,
3153 c = nonzero for abnormal return
3154 c when the matrix K is ill-conditioned.
3155 c
3156 c Subprograms called:
3157 c
3158 c Linpack dtrsl.
3159 c
3160 c
3161 c References:
3162 c
3163 c [1] R. H. Byrd, P. Lu, J. Nocedal and C. Zhu, ``A limited
3164 c memory algorithm for bound constrained optimization'',
3165 c SIAM J. Scientific Computing 16 (1995), no. 5, pp. 1190--1208.
3166 c
3167 c
3168 c
3169 c * * *
3170 c
3171 c NEOS, November 1994. (Latest revision June 1996.)
3172 c Optimization Technology Center.
3173 c Argonne National Laboratory and Northwestern University.
3174 c Written by
3175 c Ciyou Zhu
3176 c in collaboration with R.H. Byrd, P. Lu-Chen and J. Nocedal.
3177 c
3178 c
3179 c ************
3180 
3181  integer pointr,m2,col2,ibd,jy,js,i,j,k
3182  double precision alpha, xk, dk, temp1, temp2
3183  double precision one,zero
3184  parameter(one=1.0d0,zero=0.0d0)
3185 c
3186  double precision dd_p
3187 
3188  if (nsub .le. 0) return
3189  if (iprint .ge. 99) write (6,1001)
3190 
3191 c Compute wv = W'Zd.
3192 
3193  pointr = head
3194  do 20 i = 1, col
3195  temp1 = zero
3196  temp2 = zero
3197  do 10 j = 1, nsub
3198  k = ind(j)
3199  temp1 = temp1 + wy(k,pointr)*d(j)
3200  temp2 = temp2 + ws(k,pointr)*d(j)
3201  10 continue
3202  wv(i) = temp1
3203  wv(col + i) = theta*temp2
3204  pointr = mod(pointr,m) + 1
3205  20 continue
3206 
3207 c Compute wv:=K^(-1)wv.
3208 
3209  m2 = 2*m
3210  col2 = 2*col
3211  call dtrsl(wn,m2,col2,wv,11,info)
3212  if (info .ne. 0) return
3213  do 25 i = 1, col
3214  wv(i) = -wv(i)
3215  25 continue
3216  call dtrsl(wn,m2,col2,wv,01,info)
3217  if (info .ne. 0) return
3218 
3219 c Compute d = (1/theta)d + (1/theta**2)Z'W wv.
3220 
3221  pointr = head
3222  do 40 jy = 1, col
3223  js = col + jy
3224  do 30 i = 1, nsub
3225  k = ind(i)
3226  d(i) = d(i) + wy(k,pointr)*wv(jy)/theta
3227  + + ws(k,pointr)*wv(js)
3228  30 continue
3229  pointr = mod(pointr,m) + 1
3230  40 continue
3231 
3232  call dscal( nsub, one/theta, d, 1 )
3233 c
3234 c-----------------------------------------------------------------
3235 c Let us try the projection, d is the Newton direction
3236 
3237  iword = 0
3238 
3239  call dcopy ( n, x, 1, xp, 1 )
3240 c
3241  do 50 i=1, nsub
3242  k = ind(i)
3243  dk = d(i)
3244  xk = x(k)
3245  if ( nbd(k) .ne. 0 ) then
3246 c
3247  if ( nbd(k).eq.1 ) then ! lower bounds only
3248  x(k) = max( l(k), xk + dk )
3249  if ( x(k).eq.l(k) ) iword = 1
3250  else
3251 c
3252  if ( nbd(k).eq.2 ) then ! upper and lower bounds
3253  xk = max( l(k), xk + dk )
3254  x(k) = min( u(k), xk )
3255  if ( x(k).eq.l(k) .or. x(k).eq.u(k) ) iword = 1
3256  else
3257 c
3258  if ( nbd(k).eq.3 ) then ! upper bounds only
3259  x(k) = min( u(k), xk + dk )
3260  if ( x(k).eq.u(k) ) iword = 1
3261  end if
3262  end if
3263  end if
3264 c
3265  else ! free variables
3266  x(k) = xk + dk
3267  end if
3268  50 continue
3269 c
3270  if ( iword.eq.0 ) then
3271  go to 911
3272  end if
3273 c
3274 c check sign of the directional derivative
3275 c
3276  dd_p = zero
3277  do 55 i=1, n
3278  dd_p = dd_p + (x(i) - xx(i))*gg(i)
3279  55 continue
3280  if ( dd_p .gt.zero ) then
3281  call dcopy( n, xp, 1, x, 1 )
3282  write(6,*) ' Positive dir derivative in projection '
3283  write(6,*) ' Using the backtracking step '
3284  else
3285  go to 911
3286  endif
3287 c
3288 c-----------------------------------------------------------------
3289 c
3290  alpha = one
3291  temp1 = alpha
3292  ibd = 0
3293  do 60 i = 1, nsub
3294  k = ind(i)
3295  dk = d(i)
3296  if (nbd(k) .ne. 0) then
3297  if (dk .lt. zero .and. nbd(k) .le. 2) then
3298  temp2 = l(k) - x(k)
3299  if (temp2 .ge. zero) then
3300  temp1 = zero
3301  else if (dk*alpha .lt. temp2) then
3302  temp1 = temp2/dk
3303  endif
3304  else if (dk .gt. zero .and. nbd(k) .ge. 2) then
3305  temp2 = u(k) - x(k)
3306  if (temp2 .le. zero) then
3307  temp1 = zero
3308  else if (dk*alpha .gt. temp2) then
3309  temp1 = temp2/dk
3310  endif
3311  endif
3312  if (temp1 .lt. alpha) then
3313  alpha = temp1
3314  ibd = i
3315  endif
3316  endif
3317  60 continue
3318 
3319  if (alpha .lt. one) then
3320  dk = d(ibd)
3321  k = ind(ibd)
3322  if (dk .gt. zero) then
3323  x(k) = u(k)
3324  d(ibd) = zero
3325  else if (dk .lt. zero) then
3326  x(k) = l(k)
3327  d(ibd) = zero
3328  endif
3329  endif
3330  do 70 i = 1, nsub
3331  k = ind(i)
3332  x(k) = x(k) + alpha*d(i)
3333  70 continue
3334 cccccc
3335  911 continue
3336 
3337  if (iprint .ge. 99) write (6,1004)
3338 
3339  1001 format (/,'----------------SUBSM entered-----------------',/)
3340  1004 format (/,'----------------exit SUBSM --------------------',/)
3341 
3342  return
3343 
#define max(a, b)
Definition: cascade.c:32
subroutine dcopy(N, DX, INCX, DY, INCY)
Definition: dgmres.f:1381
subroutine dtrsl(t, ldt, n, b, job, info)
Definition: linpack.f:82
#define min(a, b)
Definition: cascade.c:31
subroutine dscal(n, da, dx, incx)
Definition: dgesv.f:1746
Hosted by OpenAircraft.com, (Michigan UAV, LLC)