lincoa.f 64 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909
  1. SUBROUTINE LINCOA (N,NPT,M,A,IA,B,X,RHOBEG,RHOEND,IPRINT,
  2. 1 MAXFUN,W)
  3. IMPLICIT REAL*8 (A-H,O-Z)
  4. DIMENSION A(IA,*),B(*),X(*),W(*)
  5. C
  6. C This subroutine seeks the least value of a function of many variables,
  7. C subject to general linear inequality constraints, by a trust region
  8. C method that forms quadratic models by interpolation. Usually there
  9. C is much freedom in each new model after satisfying the interpolation
  10. C conditions, which is taken up by minimizing the Frobenius norm of
  11. C the change to the second derivative matrix of the model. One new
  12. C function value is calculated on each iteration, usually at a point
  13. C where the current model predicts a reduction in the least value so
  14. C far of the objective function subject to the linear constraints.
  15. C Alternatively, a new vector of variables may be chosen to replace
  16. C an interpolation point that may be too far away for reliability, and
  17. C then the new point does not have to satisfy the linear constraints.
  18. C The arguments of the subroutine are as follows.
  19. C
  20. C N must be set to the number of variables and must be at least two.
  21. C NPT must be set to the number of interpolation conditions, which is
  22. C required to be in the interval [N+2,(N+1)(N+2)/2]. Typical choices
  23. C of the author are NPT=N+6 and NPT=2*N+1. Larger values tend to be
  24. C highly inefficent when the number of variables is substantial, due
  25. C to the amount of work and extra difficulty of adjusting more points.
  26. C M must be set to the number of linear inequality constraints.
  27. C A is a matrix whose columns are the constraint gradients, which are
  28. C required to be nonzero.
  29. C IA is the first dimension of the array A, which must be at least N.
  30. C B is the vector of right hand sides of the constraints, the J-th
  31. C constraint being that the scalar product of A(.,J) with X(.) is at
  32. C most B(J). The initial vector X(.) is made feasible by increasing
  33. C the value of B(J) if necessary.
  34. C X is the vector of variables. Initial values of X(1),X(2),...,X(N)
  35. C must be supplied. If they do not satisfy the constraints, then B
  36. C is increased as mentioned above. X contains on return the variables
  37. C that have given the least calculated F subject to the constraints.
  38. C RHOBEG and RHOEND must be set to the initial and final values of a
  39. C trust region radius, so both must be positive with RHOEND<=RHOBEG.
  40. C Typically, RHOBEG should be about one tenth of the greatest expected
  41. C change to a variable, and RHOEND should indicate the accuracy that
  42. C is required in the final values of the variables.
  43. C The value of IPRINT should be set to 0, 1, 2 or 3, which controls the
  44. C amount of printing. Specifically, there is no output if IPRINT=0 and
  45. C there is output only at the return if IPRINT=1. Otherwise, the best
  46. C feasible vector of variables so far and the corresponding value of
  47. C the objective function are printed whenever RHO is reduced, where
  48. C RHO is the current lower bound on the trust region radius. Further,
  49. C each new value of F with its variables are output if IPRINT=3.
  50. C MAXFUN must be set to an upper bound on the number of calls of CALFUN,
  51. C its value being at least NPT+1.
  52. C W is an array used for working space. Its length must be at least
  53. C M*(2+N) + NPT*(4+N+NPT) + N*(9+3*N) + MAX [ M+3*N, 2*M+N, 2*NPT ].
  54. C On return, W(1) is set to the final value of F, and W(2) is set to
  55. C the total number of function evaluations plus 0.5.
  56. C
  57. C SUBROUTINE CALFUN (N,X,F) has to be provided by the user. It must set
  58. C F to the value of the objective function for the variables X(1),
  59. C X(2),...,X(N). The value of the argument F is positive when CALFUN
  60. C is called if and only if the current X satisfies the constraints
  61. C to working accuracy.
  62. C
  63. C Check that N, NPT and MAXFUN are acceptable.
  64. C
  65. ZERO=0.0D0
  66. SMALLX=1.0D-6*RHOEND
  67. NP=N+1
  68. NPTM=NPT-NP
  69. IF (N .LE. 1) THEN
  70. PRINT 10
  71. 10 FORMAT (/4X,'Return from LINCOA because N is less than 2.')
  72. GOTO 80
  73. END IF
  74. IF (NPT .LT. N+2 .OR. NPT .GT. ((N+2)*NP)/2) THEN
  75. PRINT 20
  76. 20 FORMAT (/4X,'Return from LINCOA because NPT is not in',
  77. 1 ' the required interval.')
  78. GOTO 80
  79. END IF
  80. IF (MAXFUN .LE. NPT) THEN
  81. PRINT 30
  82. 30 FORMAT (/4X,'Return from LINCOA because MAXFUN is less',
  83. 1 ' than NPT+1.')
  84. GOTO 80
  85. END IF
  86. C
  87. C Normalize the constraints, and copy the resultant constraint matrix
  88. C and right hand sides into working space, after increasing the right
  89. C hand sides if necessary so that the starting point is feasible.
  90. C
  91. IAMAT=MAX0(M+3*N,2*M+N,2*NPT)+1
  92. IB=IAMAT+M*N
  93. IFLAG=0
  94. IF (M .GT. 0) THEN
  95. IW=IAMAT-1
  96. DO 60 J=1,M
  97. SUM=ZERO
  98. TEMP=ZERO
  99. DO 40 I=1,N
  100. SUM=SUM+A(I,J)*X(I)
  101. 40 TEMP=TEMP+A(I,J)**2
  102. IF (TEMP .EQ. ZERO) THEN
  103. PRINT 50
  104. 50 FORMAT (/4X,'Return from LINCOA because the gradient of',
  105. 1 ' a constraint is zero.')
  106. GOTO 80
  107. END IF
  108. TEMP=DSQRT(TEMP)
  109. IF (SUM-B(J) .GT. SMALLX*TEMP) IFLAG=1
  110. W(IB+J-1)=DMAX1(B(J),SUM)/TEMP
  111. DO 60 I=1,N
  112. IW=IW+1
  113. 60 W(IW)=A(I,J)/TEMP
  114. END IF
  115. IF (IFLAG .EQ. 1) THEN
  116. IF (IPRINT .GT. 0) PRINT 70
  117. 70 FORMAT (/4X,'LINCOA has made the initial X feasible by',
  118. 1 ' increasing part(s) of B.')
  119. END IF
  120. C
  121. C Partition the working space array, so that different parts of it can be
  122. C treated separately by the subroutine that performs the main calculation.
  123. C
  124. NDIM=NPT+N
  125. IXB=IB+M
  126. IXP=IXB+N
  127. IFV=IXP+N*NPT
  128. IXS=IFV+NPT
  129. IXO=IXS+N
  130. IGO=IXO+N
  131. IHQ=IGO+N
  132. IPQ=IHQ+(N*NP)/2
  133. IBMAT=IPQ+NPT
  134. IZMAT=IBMAT+NDIM*N
  135. ISTP=IZMAT+NPT*NPTM
  136. ISP=ISTP+N
  137. IXN=ISP+NPT+NPT
  138. IAC=IXN+N
  139. IRC=IAC+N
  140. IQF=IRC+M
  141. IRF=IQF+N*N
  142. IPQW=IRF+(N*NP)/2
  143. C
  144. C The above settings provide a partition of W for subroutine LINCOB.
  145. C
  146. CALL LINCOB (N,NPT,M,W(IAMAT),W(IB),X,RHOBEG,RHOEND,IPRINT,
  147. 1 MAXFUN,W(IXB),W(IXP),W(IFV),W(IXS),W(IXO),W(IGO),W(IHQ),
  148. 2 W(IPQ),W(IBMAT),W(IZMAT),NDIM,W(ISTP),W(ISP),W(IXN),W(IAC),
  149. 3 W(IRC),W(IQF),W(IRF),W(IPQW),W)
  150. 80 RETURN
  151. END
  152. SUBROUTINE GETACT (N,M,AMAT,B,NACT,IACT,QFAC,RFAC,SNORM,
  153. 1 RESNEW,RESACT,G,DW,VLAM,W)
  154. IMPLICIT REAL*8 (A-H,O-Z)
  155. DIMENSION AMAT(N,*),B(*),IACT(*),QFAC(N,*),RFAC(*),
  156. 1 RESNEW(*),RESACT(*),G(*),DW(*),VLAM(*),W(*)
  157. C
  158. C N, M, AMAT, B, NACT, IACT, QFAC and RFAC are the same as the terms
  159. C with these names in SUBROUTINE LINCOB. The current values must be
  160. C set on entry. NACT, IACT, QFAC and RFAC are kept up to date when
  161. C GETACT changes the current active set.
  162. C SNORM, RESNEW, RESACT, G and DW are the same as the terms with these
  163. C names in SUBROUTINE TRSTEP. The elements of RESNEW and RESACT are
  164. C also kept up to date.
  165. C VLAM and W are used for working space, the vector VLAM being reserved
  166. C for the Lagrange multipliers of the calculation. Their lengths must
  167. C be at least N.
  168. C The main purpose of GETACT is to pick the current active set. It is
  169. C defined by the property that the projection of -G into the space
  170. C orthogonal to the active constraint normals is as large as possible,
  171. C subject to this projected steepest descent direction moving no closer
  172. C to the boundary of every constraint whose current residual is at most
  173. C 0.2*SNORM. On return, the settings in NACT, IACT, QFAC and RFAC are
  174. C all appropriate to this choice of active set.
  175. C Occasionally this projected direction is zero, and then the final value
  176. C of W(1) is set to zero. Otherwise, the direction itself is returned
  177. C in DW, and W(1) is set to the square of the length of the direction.
  178. C
  179. C Set some constants and a temporary VLAM.
  180. C
  181. ONE=1.0D0
  182. TINY=1.0D-60
  183. ZERO=0.0D0
  184. TDEL=0.2D0*SNORM
  185. DDSAV=ZERO
  186. DO 10 I=1,N
  187. DDSAV=DDSAV+G(I)**2
  188. 10 VLAM(I)=ZERO
  189. DDSAV=DDSAV+DDSAV
  190. C
  191. C Set the initial QFAC to the identity matrix in the case NACT=0.
  192. C
  193. IF (NACT .EQ. 0) THEN
  194. DO 30 I=1,N
  195. DO 20 J=1,N
  196. 20 QFAC(I,J)=ZERO
  197. 30 QFAC(I,I)=ONE
  198. GOTO 100
  199. END IF
  200. C
  201. C Remove any constraints from the initial active set whose residuals
  202. C exceed TDEL.
  203. C
  204. IFLAG=1
  205. IC=NACT
  206. 40 IF (RESACT(IC) .GT. TDEL) GOTO 800
  207. 50 IC=IC-1
  208. IF (IC .GT. 0) GOTO 40
  209. C
  210. C Remove any constraints from the initial active set whose Lagrange
  211. C multipliers are nonnegative, and set the surviving multipliers.
  212. C
  213. IFLAG=2
  214. 60 IF (NACT .EQ. 0) GOTO 100
  215. IC=NACT
  216. 70 TEMP=ZERO
  217. DO 80 I=1,N
  218. 80 TEMP=TEMP+QFAC(I,IC)*G(I)
  219. IDIAG=(IC*IC+IC)/2
  220. IF (IC .LT. NACT) THEN
  221. JW=IDIAG+IC
  222. DO 90 J=IC+1,NACT
  223. TEMP=TEMP-RFAC(JW)*VLAM(J)
  224. 90 JW=JW+J
  225. END IF
  226. IF (TEMP .GE. ZERO) GOTO 800
  227. VLAM(IC)=TEMP/RFAC(IDIAG)
  228. IC=IC-1
  229. IF (IC .GT. 0) GOTO 70
  230. C
  231. C Set the new search direction D. Terminate if the 2-norm of D is zero
  232. C or does not decrease, or if NACT=N holds. The situation NACT=N
  233. C occurs for sufficiently large SNORM if the origin is in the convex
  234. C hull of the constraint gradients.
  235. C
  236. 100 IF (NACT .EQ. N) GOTO 290
  237. DO 110 J=NACT+1,N
  238. W(J)=ZERO
  239. DO 110 I=1,N
  240. 110 W(J)=W(J)+QFAC(I,J)*G(I)
  241. DD=ZERO
  242. DO 130 I=1,N
  243. DW(I)=ZERO
  244. DO 120 J=NACT+1,N
  245. 120 DW(I)=DW(I)-W(J)*QFAC(I,J)
  246. 130 DD=DD+DW(I)**2
  247. IF (DD .GE. DDSAV) GOTO 290
  248. IF (DD .EQ. ZERO) GOTO 300
  249. DDSAV=DD
  250. DNORM=DSQRT(DD)
  251. C
  252. C Pick the next integer L or terminate, a positive value of L being
  253. C the index of the most violated constraint. The purpose of CTOL
  254. C below is to estimate whether a positive value of VIOLMX may be
  255. C due to computer rounding errors.
  256. C
  257. L=0
  258. IF (M .GT. 0) THEN
  259. TEST=DNORM/SNORM
  260. VIOLMX=ZERO
  261. DO 150 J=1,M
  262. IF (RESNEW(J) .GT. ZERO .AND. RESNEW(J) .LE. TDEL) THEN
  263. SUM=ZERO
  264. DO 140 I=1,N
  265. 140 SUM=SUM+AMAT(I,J)*DW(I)
  266. IF (SUM .GT. TEST*RESNEW(J)) THEN
  267. IF (SUM .GT. VIOLMX) THEN
  268. L=J
  269. VIOLMX=SUM
  270. END IF
  271. END IF
  272. END IF
  273. 150 CONTINUE
  274. CTOL=ZERO
  275. TEMP=0.01D0*DNORM
  276. IF (VIOLMX .GT. ZERO .AND. VIOLMX .LT. TEMP) THEN
  277. IF (NACT .GT. 0) THEN
  278. DO 170 K=1,NACT
  279. J=IACT(K)
  280. SUM=ZERO
  281. DO 160 I=1,N
  282. 160 SUM=SUM+DW(I)*AMAT(I,J)
  283. 170 CTOL=DMAX1(CTOL,DABS(SUM))
  284. END IF
  285. END IF
  286. END IF
  287. W(1)=ONE
  288. IF (L .EQ. 0) GOTO 300
  289. IF (VIOLMX .LE. 10.0D0*CTOL) GOTO 300
  290. C
  291. C Apply Givens rotations to the last (N-NACT) columns of QFAC so that
  292. C the first (NACT+1) columns of QFAC are the ones required for the
  293. C addition of the L-th constraint, and add the appropriate column
  294. C to RFAC.
  295. C
  296. NACTP=NACT+1
  297. IDIAG=(NACTP*NACTP-NACTP)/2
  298. RDIAG=ZERO
  299. DO 200 J=N,1,-1
  300. SPROD=ZERO
  301. DO 180 I=1,N
  302. 180 SPROD=SPROD+QFAC(I,J)*AMAT(I,L)
  303. IF (J .LE. NACT) THEN
  304. RFAC(IDIAG+J)=SPROD
  305. ELSE
  306. IF (DABS(RDIAG) .LE. 1.0D-20*DABS(SPROD)) THEN
  307. RDIAG=SPROD
  308. ELSE
  309. TEMP=DSQRT(SPROD*SPROD+RDIAG*RDIAG)
  310. COSV=SPROD/TEMP
  311. SINV=RDIAG/TEMP
  312. RDIAG=TEMP
  313. DO 190 I=1,N
  314. TEMP=COSV*QFAC(I,J)+SINV*QFAC(I,J+1)
  315. QFAC(I,J+1)=-SINV*QFAC(I,J)+COSV*QFAC(I,J+1)
  316. 190 QFAC(I,J)=TEMP
  317. END IF
  318. END IF
  319. 200 CONTINUE
  320. IF (RDIAG .LT. ZERO) THEN
  321. DO 210 I=1,N
  322. 210 QFAC(I,NACTP)=-QFAC(I,NACTP)
  323. END IF
  324. RFAC(IDIAG+NACTP)=DABS(RDIAG)
  325. NACT=NACTP
  326. IACT(NACT)=L
  327. RESACT(NACT)=RESNEW(L)
  328. VLAM(NACT)=ZERO
  329. RESNEW(L)=ZERO
  330. C
  331. C Set the components of the vector VMU in W.
  332. C
  333. 220 W(NACT)=ONE/RFAC((NACT*NACT+NACT)/2)**2
  334. IF (NACT .GT. 1) THEN
  335. DO 240 I=NACT-1,1,-1
  336. IDIAG=(I*I+I)/2
  337. JW=IDIAG+I
  338. SUM=ZERO
  339. DO 230 J=I+1,NACT
  340. SUM=SUM-RFAC(JW)*W(J)
  341. 230 JW=JW+J
  342. 240 W(I)=SUM/RFAC(IDIAG)
  343. END IF
  344. C
  345. C Calculate the multiple of VMU to subtract from VLAM, and update VLAM.
  346. C
  347. VMULT=VIOLMX
  348. IC=0
  349. J=1
  350. 250 IF (J .LT. NACT) THEN
  351. IF (VLAM(J) .GE. VMULT*W(J)) THEN
  352. IC=J
  353. VMULT=VLAM(J)/W(J)
  354. END IF
  355. J=J+1
  356. GOTO 250
  357. END IF
  358. DO 260 J=1,NACT
  359. 260 VLAM(J)=VLAM(J)-VMULT*W(J)
  360. IF (IC .GT. 0) VLAM(IC)=ZERO
  361. VIOLMX=DMAX1(VIOLMX-VMULT,ZERO)
  362. IF (IC .EQ. 0) VIOLMX=ZERO
  363. C
  364. C Reduce the active set if necessary, so that all components of the
  365. C new VLAM are negative, with resetting of the residuals of the
  366. C constraints that become inactive.
  367. C
  368. IFLAG=3
  369. IC=NACT
  370. 270 IF (VLAM(IC) .LT. ZERO) GOTO 280
  371. RESNEW(IACT(IC))=DMAX1(RESACT(IC),TINY)
  372. GOTO 800
  373. 280 IC=IC-1
  374. IF (IC .GT. 0) GOTO 270
  375. C
  376. C Calculate the next VMU if VIOLMX is positive. Return if NACT=N holds,
  377. C as then the active constraints imply D=0. Otherwise, go to label
  378. C 100, to calculate the new D and to test for termination.
  379. C
  380. IF (VIOLMX .GT. ZERO) GOTO 220
  381. IF (NACT .LT. N) GOTO 100
  382. 290 DD=ZERO
  383. 300 W(1)=DD
  384. RETURN
  385. C
  386. C These instructions rearrange the active constraints so that the new
  387. C value of IACT(NACT) is the old value of IACT(IC). A sequence of
  388. C Givens rotations is applied to the current QFAC and RFAC. Then NACT
  389. C is reduced by one.
  390. C
  391. 800 RESNEW(IACT(IC))=DMAX1(RESACT(IC),TINY)
  392. JC=IC
  393. 810 IF (JC .LT. NACT) THEN
  394. JCP=JC+1
  395. IDIAG=JC*JCP/2
  396. JW=IDIAG+JCP
  397. TEMP=DSQRT(RFAC(JW-1)**2+RFAC(JW)**2)
  398. CVAL=RFAC(JW)/TEMP
  399. SVAL=RFAC(JW-1)/TEMP
  400. RFAC(JW-1)=SVAL*RFAC(IDIAG)
  401. RFAC(JW)=CVAL*RFAC(IDIAG)
  402. RFAC(IDIAG)=TEMP
  403. IF (JCP .LT. NACT) THEN
  404. DO 820 J=JCP+1,NACT
  405. TEMP=SVAL*RFAC(JW+JC)+CVAL*RFAC(JW+JCP)
  406. RFAC(JW+JCP)=CVAL*RFAC(JW+JC)-SVAL*RFAC(JW+JCP)
  407. RFAC(JW+JC)=TEMP
  408. 820 JW=JW+J
  409. END IF
  410. JDIAG=IDIAG-JC
  411. DO 830 I=1,N
  412. IF (I .LT. JC) THEN
  413. TEMP=RFAC(IDIAG+I)
  414. RFAC(IDIAG+I)=RFAC(JDIAG+I)
  415. RFAC(JDIAG+I)=TEMP
  416. END IF
  417. TEMP=SVAL*QFAC(I,JC)+CVAL*QFAC(I,JCP)
  418. QFAC(I,JCP)=CVAL*QFAC(I,JC)-SVAL*QFAC(I,JCP)
  419. 830 QFAC(I,JC)=TEMP
  420. IACT(JC)=IACT(JCP)
  421. RESACT(JC)=RESACT(JCP)
  422. VLAM(JC)=VLAM(JCP)
  423. JC=JCP
  424. GOTO 810
  425. END IF
  426. NACT=NACT-1
  427. GOTO (50,60,280),IFLAG
  428. END
  429. SUBROUTINE LINCOB (N,NPT,M,AMAT,B,X,RHOBEG,RHOEND,IPRINT,
  430. 1 MAXFUN,XBASE,XPT,FVAL,XSAV,XOPT,GOPT,HQ,PQ,BMAT,ZMAT,NDIM,
  431. 2 STEP,SP,XNEW,IACT,RESCON,QFAC,RFAC,PQW,W)
  432. IMPLICIT REAL*8 (A-H,O-Z)
  433. DIMENSION AMAT(N,*),B(*),X(*),XBASE(*),XPT(NPT,*),FVAL(*),
  434. 1 XSAV(*),XOPT(*),GOPT(*),HQ(*),PQ(*),BMAT(NDIM,*),
  435. 2 ZMAT(NPT,*),STEP(*),SP(*),XNEW(*),IACT(*),RESCON(*),
  436. 3 QFAC(N,*),RFAC(*),PQW(*),W(*)
  437. C
  438. C The arguments N, NPT, M, X, RHOBEG, RHOEND, IPRINT and MAXFUN are
  439. C identical to the corresponding arguments in SUBROUTINE LINCOA.
  440. C AMAT is a matrix whose columns are the constraint gradients, scaled
  441. C so that they have unit length.
  442. C B contains on entry the right hand sides of the constraints, scaled
  443. C as above, but later B is modified for variables relative to XBASE.
  444. C XBASE holds a shift of origin that should reduce the contributions
  445. C from rounding errors to values of the model and Lagrange functions.
  446. C XPT contains the interpolation point coordinates relative to XBASE.
  447. C FVAL holds the values of F at the interpolation points.
  448. C XSAV holds the best feasible vector of variables so far, without any
  449. C shift of origin.
  450. C XOPT is set to XSAV-XBASE, which is the displacement from XBASE of
  451. C the feasible vector of variables that provides the least calculated
  452. C F so far, this vector being the current trust region centre.
  453. C GOPT holds the gradient of the quadratic model at XSAV = XBASE+XOPT.
  454. C HQ holds the explicit second derivatives of the quadratic model.
  455. C PQ contains the parameters of the implicit second derivatives of the
  456. C quadratic model.
  457. C BMAT holds the last N columns of the big inverse matrix H.
  458. C ZMAT holds the factorization of the leading NPT by NPT submatrix
  459. C of H, this factorization being ZMAT times Diag(DZ) times ZMAT^T,
  460. C where the elements of DZ are plus or minus one, as specified by IDZ.
  461. C NDIM is the first dimension of BMAT and has the value NPT+N.
  462. C STEP is employed for trial steps from XOPT. It is also used for working
  463. C space when XBASE is shifted and in PRELIM.
  464. C SP is reserved for the scalar products XOPT^T XPT(K,.), K=1,2,...,NPT,
  465. C followed by STEP^T XPT(K,.), K=1,2,...,NPT.
  466. C XNEW is the displacement from XBASE of the vector of variables for
  467. C the current calculation of F, except that SUBROUTINE TRSTEP uses it
  468. C for working space.
  469. C IACT is an integer array for the indices of the active constraints.
  470. C RESCON holds useful information about the constraint residuals. Every
  471. C nonnegative RESCON(J) is the residual of the J-th constraint at the
  472. C current trust region centre. Otherwise, if RESCON(J) is negative, the
  473. C J-th constraint holds as a strict inequality at the trust region
  474. C centre, its residual being at least |RESCON(J)|; further, the value
  475. C of |RESCON(J)| is at least the current trust region radius DELTA.
  476. C QFAC is the orthogonal part of the QR factorization of the matrix of
  477. C active constraint gradients, these gradients being ordered in
  478. C accordance with IACT. When NACT is less than N, columns are added
  479. C to QFAC to complete an N by N orthogonal matrix, which is important
  480. C for keeping calculated steps sufficiently close to the boundaries
  481. C of the active constraints.
  482. C RFAC is the upper triangular part of this QR factorization, beginning
  483. C with the first diagonal element, followed by the two elements in the
  484. C upper triangular part of the second column and so on.
  485. C PQW is used for working space, mainly for storing second derivative
  486. C coefficients of quadratic functions. Its length is NPT+N.
  487. C The array W is also used for working space. The required number of
  488. C elements, namely MAX[M+3*N,2*M+N,2*NPT], is set in LINCOA.
  489. C
  490. C Set some constants.
  491. C
  492. HALF=0.5D0
  493. ONE=1.0D0
  494. TENTH=0.1D0
  495. ZERO=0.0D0
  496. NP=N+1
  497. NH=(N*NP)/2
  498. NPTM=NPT-NP
  499. C
  500. C Set the elements of XBASE, XPT, FVAL, XSAV, XOPT, GOPT, HQ, PQ, BMAT,
  501. C ZMAT and SP for the first iteration. An important feature is that,
  502. C if the interpolation point XPT(K,.) is not feasible, where K is any
  503. C integer from [1,NPT], then a change is made to XPT(K,.) if necessary
  504. C so that the constraint violation is at least 0.2*RHOBEG. Also KOPT
  505. C is set so that XPT(KOPT,.) is the initial trust region centre.
  506. C
  507. CALL PRELIM (N,NPT,M,AMAT,B,X,RHOBEG,IPRINT,XBASE,XPT,FVAL,
  508. 1 XSAV,XOPT,GOPT,KOPT,HQ,PQ,BMAT,ZMAT,IDZ,NDIM,SP,RESCON,
  509. 2 STEP,PQW,W)
  510. C
  511. C Begin the iterative procedure.
  512. C
  513. NF=NPT
  514. FOPT=FVAL(KOPT)
  515. RHO=RHOBEG
  516. DELTA=RHO
  517. IFEAS=0
  518. NACT=0
  519. ITEST=3
  520. 10 KNEW=0
  521. NVALA=0
  522. NVALB=0
  523. C
  524. C Shift XBASE if XOPT may be too far from XBASE. First make the changes
  525. C to BMAT that do not depend on ZMAT.
  526. C
  527. 20 FSAVE=FOPT
  528. XOPTSQ=ZERO
  529. DO 30 I=1,N
  530. 30 XOPTSQ=XOPTSQ+XOPT(I)**2
  531. IF (XOPTSQ .GE. 1.0D4*DELTA*DELTA) THEN
  532. QOPTSQ=0.25D0*XOPTSQ
  533. DO 50 K=1,NPT
  534. SUM=ZERO
  535. DO 40 I=1,N
  536. 40 SUM=SUM+XPT(K,I)*XOPT(I)
  537. SUM=SUM-HALF*XOPTSQ
  538. W(NPT+K)=SUM
  539. SP(K)=ZERO
  540. DO 50 I=1,N
  541. XPT(K,I)=XPT(K,I)-HALF*XOPT(I)
  542. STEP(I)=BMAT(K,I)
  543. W(I)=SUM*XPT(K,I)+QOPTSQ*XOPT(I)
  544. IP=NPT+I
  545. DO 50 J=1,I
  546. 50 BMAT(IP,J)=BMAT(IP,J)+STEP(I)*W(J)+W(I)*STEP(J)
  547. C
  548. C Then the revisions of BMAT that depend on ZMAT are calculated.
  549. C
  550. DO 90 K=1,NPTM
  551. SUMZ=ZERO
  552. DO 60 I=1,NPT
  553. SUMZ=SUMZ+ZMAT(I,K)
  554. 60 W(I)=W(NPT+I)*ZMAT(I,K)
  555. DO 80 J=1,N
  556. SUM=QOPTSQ*SUMZ*XOPT(J)
  557. DO 70 I=1,NPT
  558. 70 SUM=SUM+W(I)*XPT(I,J)
  559. STEP(J)=SUM
  560. IF (K .LT. IDZ) SUM=-SUM
  561. DO 80 I=1,NPT
  562. 80 BMAT(I,J)=BMAT(I,J)+SUM*ZMAT(I,K)
  563. DO 90 I=1,N
  564. IP=I+NPT
  565. TEMP=STEP(I)
  566. IF (K .LT. IDZ) TEMP=-TEMP
  567. DO 90 J=1,I
  568. 90 BMAT(IP,J)=BMAT(IP,J)+TEMP*STEP(J)
  569. C
  570. C Update the right hand sides of the constraints.
  571. C
  572. IF (M .GT. 0) THEN
  573. DO 110 J=1,M
  574. TEMP=ZERO
  575. DO 100 I=1,N
  576. 100 TEMP=TEMP+AMAT(I,J)*XOPT(I)
  577. 110 B(J)=B(J)-TEMP
  578. END IF
  579. C
  580. C The following instructions complete the shift of XBASE, including the
  581. C changes to the parameters of the quadratic model.
  582. C
  583. IH=0
  584. DO 130 J=1,N
  585. W(J)=ZERO
  586. DO 120 K=1,NPT
  587. W(J)=W(J)+PQ(K)*XPT(K,J)
  588. 120 XPT(K,J)=XPT(K,J)-HALF*XOPT(J)
  589. DO 130 I=1,J
  590. IH=IH+1
  591. HQ(IH)=HQ(IH)+W(I)*XOPT(J)+XOPT(I)*W(J)
  592. 130 BMAT(NPT+I,J)=BMAT(NPT+J,I)
  593. DO 140 J=1,N
  594. XBASE(J)=XBASE(J)+XOPT(J)
  595. XOPT(J)=ZERO
  596. 140 XPT(KOPT,J)=ZERO
  597. END IF
  598. C
  599. C In the case KNEW=0, generate the next trust region step by calling
  600. C TRSTEP, where SNORM is the current trust region radius initially.
  601. C The final value of SNORM is the length of the calculated step,
  602. C except that SNORM is zero on return if the projected gradient is
  603. C unsuitable for starting the conjugate gradient iterations.
  604. C
  605. DELSAV=DELTA
  606. KSAVE=KNEW
  607. IF (KNEW .EQ. 0) THEN
  608. SNORM=DELTA
  609. DO 150 I=1,N
  610. 150 XNEW(I)=GOPT(I)
  611. CALL TRSTEP (N,NPT,M,AMAT,B,XPT,HQ,PQ,NACT,IACT,RESCON,
  612. 1 QFAC,RFAC,SNORM,STEP,XNEW,W,W(M+1),PQW,PQW(NP),W(M+NP))
  613. C
  614. C A trust region step is applied whenever its length, namely SNORM, is at
  615. C least HALF*DELTA. It is also applied if its length is at least 0.1999
  616. C times DELTA and if a line search of TRSTEP has caused a change to the
  617. C active set. Otherwise there is a branch below to label 530 or 560.
  618. C
  619. TEMP=HALF*DELTA
  620. IF (XNEW(1) .GE. HALF) TEMP=0.1999D0*DELTA
  621. IF (SNORM .LE. TEMP) THEN
  622. DELTA=HALF*DELTA
  623. IF (DELTA .LE. 1.4D0*RHO) DELTA=RHO
  624. NVALA=NVALA+1
  625. NVALB=NVALB+1
  626. TEMP=SNORM/RHO
  627. IF (DELSAV .GT. RHO) TEMP=ONE
  628. IF (TEMP .GE. HALF) NVALA=ZERO
  629. IF (TEMP .GE. TENTH) NVALB=ZERO
  630. IF (DELSAV .GT. RHO) GOTO 530
  631. IF (NVALA .LT. 5 .AND. NVALB .LT. 3) GOTO 530
  632. IF (SNORM .GT. ZERO) KSAVE=-1
  633. GOTO 560
  634. END IF
  635. NVALA=ZERO
  636. NVALB=ZERO
  637. C
  638. C Alternatively, KNEW is positive. Then the model step is calculated
  639. C within a trust region of radius DEL, after setting the gradient at
  640. C XBASE and the second derivative parameters of the KNEW-th Lagrange
  641. C function in W(1) to W(N) and in PQW(1) to PQW(NPT), respectively.
  642. C
  643. ELSE
  644. DEL=DMAX1(TENTH*DELTA,RHO)
  645. DO 160 I=1,N
  646. 160 W(I)=BMAT(KNEW,I)
  647. DO 170 K=1,NPT
  648. 170 PQW(K)=ZERO
  649. DO 180 J=1,NPTM
  650. TEMP=ZMAT(KNEW,J)
  651. IF (J .LT. IDZ) TEMP=-TEMP
  652. DO 180 K=1,NPT
  653. 180 PQW(K)=PQW(K)+TEMP*ZMAT(K,J)
  654. CALL QMSTEP (N,NPT,M,AMAT,B,XPT,XOPT,NACT,IACT,RESCON,
  655. 1 QFAC,KOPT,KNEW,DEL,STEP,W,PQW,W(NP),W(NP+M),IFEAS)
  656. END IF
  657. C
  658. C Set VQUAD to the change to the quadratic model when the move STEP is
  659. C made from XOPT. If STEP is a trust region step, then VQUAD should be
  660. C negative. If it is nonnegative due to rounding errors in this case,
  661. C there is a branch to label 530 to try to improve the model.
  662. C
  663. VQUAD=ZERO
  664. IH=0
  665. DO 190 J=1,N
  666. VQUAD=VQUAD+STEP(J)*GOPT(J)
  667. DO 190 I=1,J
  668. IH=IH+1
  669. TEMP=STEP(I)*STEP(J)
  670. IF (I .EQ. J) TEMP=HALF*TEMP
  671. 190 VQUAD=VQUAD+TEMP*HQ(IH)
  672. DO 210 K=1,NPT
  673. TEMP=ZERO
  674. DO 200 J=1,N
  675. TEMP=TEMP+XPT(K,J)*STEP(J)
  676. 200 SP(NPT+K)=TEMP
  677. 210 VQUAD=VQUAD+HALF*PQ(K)*TEMP*TEMP
  678. IF (KSAVE .EQ. 0 .AND. VQUAD .GE. ZERO) GOTO 530
  679. C
  680. C Calculate the next value of the objective function. The difference
  681. C between the actual new value of F and the value predicted by the
  682. C model is recorded in DIFF.
  683. C
  684. 220 NF=NF+1
  685. IF (NF .GT. MAXFUN) THEN
  686. NF=NF-1
  687. IF (IPRINT .GT. 0) PRINT 230
  688. 230 FORMAT (/4X,'Return from LINCOA because CALFUN has been',
  689. 1 ' called MAXFUN times.')
  690. GOTO 600
  691. END IF
  692. XDIFF=ZERO
  693. DO 240 I=1,N
  694. XNEW(I)=XOPT(I)+STEP(I)
  695. X(I)=XBASE(I)+XNEW(I)
  696. 240 XDIFF=XDIFF+(X(I)-XSAV(I))**2
  697. XDIFF=DSQRT(XDIFF)
  698. IF (KSAVE .EQ. -1) XDIFF=RHO
  699. IF (XDIFF .LE. TENTH*RHO .OR. XDIFF .GE. DELTA+DELTA) THEN
  700. IFEAS=0
  701. IF (IPRINT .GT. 0) PRINT 250
  702. 250 FORMAT (/4X,'Return from LINCOA because rounding errors',
  703. 1 ' prevent reasonable changes to X.')
  704. GOTO 600
  705. END IF
  706. IF (KSAVE .LE. 0) IFEAS=1
  707. F=DFLOAT(IFEAS)
  708. CALL CALFUN (N,X,F)
  709. IF (IPRINT .EQ. 3) THEN
  710. PRINT 260, NF,F,(X(I),I=1,N)
  711. 260 FORMAT (/4X,'Function number',I6,' F =',1PD18.10,
  712. 1 ' The corresponding X is:'/(2X,5D15.6))
  713. END IF
  714. IF (KSAVE .EQ. -1) GOTO 600
  715. DIFF=F-FOPT-VQUAD
  716. C
  717. C If X is feasible, then set DFFALT to the difference between the new
  718. C value of F and the value predicted by the alternative model.
  719. C
  720. IF (IFEAS .EQ. 1 .AND. ITEST .LT. 3) THEN
  721. DO 270 K=1,NPT
  722. PQW(K)=ZERO
  723. 270 W(K)=FVAL(K)-FVAL(KOPT)
  724. DO 290 J=1,NPTM
  725. SUM=ZERO
  726. DO 280 I=1,NPT
  727. 280 SUM=SUM+W(I)*ZMAT(I,J)
  728. IF (J .LT. IDZ) SUM=-SUM
  729. DO 290 K=1,NPT
  730. 290 PQW(K)=PQW(K)+SUM*ZMAT(K,J)
  731. VQALT=ZERO
  732. DO 310 K=1,NPT
  733. SUM=ZERO
  734. DO 300 J=1,N
  735. 300 SUM=SUM+BMAT(K,J)*STEP(J)
  736. VQALT=VQALT+SUM*W(K)
  737. 310 VQALT=VQALT+PQW(K)*SP(NPT+K)*(HALF*SP(NPT+K)+SP(K))
  738. DFFALT=F-FOPT-VQALT
  739. END IF
  740. IF (ITEST .EQ. 3) THEN
  741. DFFALT=DIFF
  742. ITEST=0
  743. END IF
  744. C
  745. C Pick the next value of DELTA after a trust region step.
  746. C
  747. IF (KSAVE .EQ. 0) THEN
  748. RATIO=(F-FOPT)/VQUAD
  749. IF (RATIO .LE. TENTH) THEN
  750. DELTA=HALF*DELTA
  751. ELSE IF (RATIO .LE. 0.7D0) THEN
  752. DELTA=DMAX1(HALF*DELTA,SNORM)
  753. ELSE
  754. TEMP=DSQRT(2.0D0)*DELTA
  755. DELTA=DMAX1(HALF*DELTA,SNORM+SNORM)
  756. DELTA=DMIN1(DELTA,TEMP)
  757. END IF
  758. IF (DELTA .LE. 1.4D0*RHO) DELTA=RHO
  759. END IF
  760. C
  761. C Update BMAT, ZMAT and IDZ, so that the KNEW-th interpolation point
  762. C can be moved. If STEP is a trust region step, then KNEW is zero at
  763. C present, but a positive value is picked by subroutine UPDATE.
  764. C
  765. CALL UPDATE (N,NPT,XPT,BMAT,ZMAT,IDZ,NDIM,SP,STEP,KOPT,
  766. 1 KNEW,PQW,W)
  767. IF (KNEW .EQ. 0) THEN
  768. IF (IPRINT .GT. 0) PRINT 320
  769. 320 FORMAT (/4X,'Return from LINCOA because the denominator'
  770. 1 ' of the updating formula is zero.')
  771. GOTO 600
  772. END IF
  773. C
  774. C If ITEST is increased to 3, then the next quadratic model is the
  775. C one whose second derivative matrix is least subject to the new
  776. C interpolation conditions. Otherwise the new model is constructed
  777. C by the symmetric Broyden method in the usual way.
  778. C
  779. IF (IFEAS .EQ. 1) THEN
  780. ITEST=ITEST+1
  781. IF (DABS(DFFALT) .GE. TENTH*DABS(DIFF)) ITEST=0
  782. END IF
  783. C
  784. C Update the second derivatives of the model by the symmetric Broyden
  785. C method, using PQW for the second derivative parameters of the new
  786. C KNEW-th Lagrange function. The contribution from the old parameter
  787. C PQ(KNEW) is included in the second derivative matrix HQ. W is used
  788. C later for the gradient of the new KNEW-th Lagrange function.
  789. C
  790. IF (ITEST .LT. 3) THEN
  791. DO 330 K=1,NPT
  792. 330 PQW(K)=ZERO
  793. DO 350 J=1,NPTM
  794. TEMP=ZMAT(KNEW,J)
  795. IF (TEMP .NE. ZERO) THEN
  796. IF (J .LT. IDZ) TEMP=-TEMP
  797. DO 340 K=1,NPT
  798. 340 PQW(K)=PQW(K)+TEMP*ZMAT(K,J)
  799. END IF
  800. 350 CONTINUE
  801. IH=0
  802. DO 360 I=1,N
  803. W(I)=BMAT(KNEW,I)
  804. TEMP=PQ(KNEW)*XPT(KNEW,I)
  805. DO 360 J=1,I
  806. IH=IH+1
  807. 360 HQ(IH)=HQ(IH)+TEMP*XPT(KNEW,J)
  808. PQ(KNEW)=ZERO
  809. DO 370 K=1,NPT
  810. 370 PQ(K)=PQ(K)+DIFF*PQW(K)
  811. END IF
  812. C
  813. C Include the new interpolation point with the corresponding updates of
  814. C SP. Also make the changes of the symmetric Broyden method to GOPT at
  815. C the old XOPT if ITEST is less than 3.
  816. C
  817. FVAL(KNEW)=F
  818. SP(KNEW)=SP(KOPT)+SP(NPT+KOPT)
  819. SSQ=ZERO
  820. DO 380 I=1,N
  821. XPT(KNEW,I)=XNEW(I)
  822. 380 SSQ=SSQ+STEP(I)**2
  823. SP(NPT+KNEW)=SP(NPT+KOPT)+SSQ
  824. IF (ITEST .LT. 3) THEN
  825. DO 390 K=1,NPT
  826. TEMP=PQW(K)*SP(K)
  827. DO 390 I=1,N
  828. 390 W(I)=W(I)+TEMP*XPT(K,I)
  829. DO 400 I=1,N
  830. 400 GOPT(I)=GOPT(I)+DIFF*W(I)
  831. END IF
  832. C
  833. C Update FOPT, XSAV, XOPT, KOPT, RESCON and SP if the new F is the
  834. C least calculated value so far with a feasible vector of variables.
  835. C
  836. IF (F .LT. FOPT .AND. IFEAS .EQ. 1) THEN
  837. FOPT=F
  838. DO 410 J=1,N
  839. XSAV(J)=X(J)
  840. 410 XOPT(J)=XNEW(J)
  841. KOPT=KNEW
  842. SNORM=DSQRT(SSQ)
  843. DO 430 J=1,M
  844. IF (RESCON(J) .GE. DELTA+SNORM) THEN
  845. RESCON(J)=SNORM-RESCON(J)
  846. ELSE
  847. RESCON(J)=RESCON(J)+SNORM
  848. IF (RESCON(J)+DELTA .GT. ZERO) THEN
  849. TEMP=B(J)
  850. DO 420 I=1,N
  851. 420 TEMP=TEMP-XOPT(I)*AMAT(I,J)
  852. TEMP=DMAX1(TEMP,ZERO)
  853. IF (TEMP .GE. DELTA) TEMP=-TEMP
  854. RESCON(J)=TEMP
  855. END IF
  856. END IF
  857. 430 CONTINUE
  858. DO 440 K=1,NPT
  859. 440 SP(K)=SP(K)+SP(NPT+K)
  860. C
  861. C Also revise GOPT when symmetric Broyden updating is applied.
  862. C
  863. IF (ITEST .LT. 3) THEN
  864. IH=0
  865. DO 450 J=1,N
  866. DO 450 I=1,J
  867. IH=IH+1
  868. IF (I .LT. J) GOPT(J)=GOPT(J)+HQ(IH)*STEP(I)
  869. 450 GOPT(I)=GOPT(I)+HQ(IH)*STEP(J)
  870. DO 460 K=1,NPT
  871. TEMP=PQ(K)*SP(NPT+K)
  872. DO 460 I=1,N
  873. 460 GOPT(I)=GOPT(I)+TEMP*XPT(K,I)
  874. END IF
  875. END IF
  876. C
  877. C Replace the current model by the least Frobenius norm interpolant if
  878. C this interpolant gives substantial reductions in the predictions
  879. C of values of F at feasible points.
  880. C
  881. IF (ITEST .EQ. 3) THEN
  882. DO 470 K=1,NPT
  883. PQ(K)=ZERO
  884. 470 W(K)=FVAL(K)-FVAL(KOPT)
  885. DO 490 J=1,NPTM
  886. SUM=ZERO
  887. DO 480 I=1,NPT
  888. 480 SUM=SUM+W(I)*ZMAT(I,J)
  889. IF (J .LT. IDZ) SUM=-SUM
  890. DO 490 K=1,NPT
  891. 490 PQ(K)=PQ(K)+SUM*ZMAT(K,J)
  892. DO 500 J=1,N
  893. GOPT(J)=ZERO
  894. DO 500 I=1,NPT
  895. 500 GOPT(J)=GOPT(J)+W(I)*BMAT(I,J)
  896. DO 510 K=1,NPT
  897. TEMP=PQ(K)*SP(K)
  898. DO 510 I=1,N
  899. 510 GOPT(I)=GOPT(I)+TEMP*XPT(K,I)
  900. DO 520 IH=1,NH
  901. 520 HQ(IH)=ZERO
  902. END IF
  903. C
  904. C If a trust region step has provided a sufficient decrease in F, then
  905. C branch for another trust region calculation. Every iteration that
  906. C takes a model step is followed by an attempt to take a trust region
  907. C step.
  908. C
  909. KNEW=0
  910. IF (KSAVE .GT. 0) GOTO 20
  911. IF (RATIO .GE. TENTH) GOTO 20
  912. C
  913. C Alternatively, find out if the interpolation points are close enough
  914. C to the best point so far.
  915. C
  916. 530 DISTSQ=DMAX1(DELTA*DELTA,4.0D0*RHO*RHO)
  917. DO 550 K=1,NPT
  918. SUM=ZERO
  919. DO 540 J=1,N
  920. 540 SUM=SUM+(XPT(K,J)-XOPT(J))**2
  921. IF (SUM .GT. DISTSQ) THEN
  922. KNEW=K
  923. DISTSQ=SUM
  924. END IF
  925. 550 CONTINUE
  926. C
  927. C If KNEW is positive, then branch back for the next iteration, which
  928. C will generate a "model step". Otherwise, if the current iteration
  929. C has reduced F, or if DELTA was above its lower bound when the last
  930. C trust region step was calculated, then try a "trust region" step
  931. C instead.
  932. C
  933. IF (KNEW .GT. 0) GOTO 20
  934. KNEW=0
  935. IF (FOPT .LT. FSAVE) GOTO 20
  936. IF (DELSAV .GT. RHO) GOTO 20
  937. C
  938. C The calculations with the current value of RHO are complete.
  939. C Pick the next value of RHO.
  940. C
  941. 560 IF (RHO .GT. RHOEND) THEN
  942. DELTA=HALF*RHO
  943. IF (RHO .GT. 250.0D0*RHOEND) THEN
  944. RHO=TENTH*RHO
  945. ELSE IF (RHO .LE. 16.0D0*RHOEND) THEN
  946. RHO=RHOEND
  947. ELSE
  948. RHO=DSQRT(RHO*RHOEND)
  949. END IF
  950. DELTA=DMAX1(DELTA,RHO)
  951. IF (IPRINT .GE. 2) THEN
  952. IF (IPRINT .GE. 3) PRINT 570
  953. 570 FORMAT (5X)
  954. PRINT 580, RHO,NF
  955. 580 FORMAT (/4X,'New RHO =',1PD11.4,5X,'Number of',
  956. 1 ' function values =',I6)
  957. PRINT 590, FOPT,(XBASE(I)+XOPT(I),I=1,N)
  958. 590 FORMAT (4X,'Least value of F =',1PD23.15,9X,
  959. 1 'The corresponding X is:'/(2X,5D15.6))
  960. END IF
  961. GOTO 10
  962. END IF
  963. C
  964. C Return from the calculation, after branching to label 220 for another
  965. C Newton-Raphson step if it has not been tried before.
  966. C
  967. IF (KSAVE .EQ. -1) GOTO 220
  968. 600 IF (FOPT .LE. F .OR. IFEAS .EQ. 0) THEN
  969. DO 610 I=1,N
  970. 610 X(I)=XSAV(I)
  971. F=FOPT
  972. END IF
  973. IF (IPRINT .GE. 1) THEN
  974. PRINT 620, NF
  975. 620 FORMAT (/4X,'At the return from LINCOA',5X,
  976. 1 'Number of function values =',I6)
  977. PRINT 590, F,(X(I),I=1,N)
  978. END IF
  979. W(1)=F
  980. W(2)=DFLOAT(NF)+HALF
  981. RETURN
  982. END
  983. SUBROUTINE PRELIM (N,NPT,M,AMAT,B,X,RHOBEG,IPRINT,XBASE,
  984. 1 XPT,FVAL,XSAV,XOPT,GOPT,KOPT,HQ,PQ,BMAT,ZMAT,IDZ,NDIM,
  985. 2 SP,RESCON,STEP,PQW,W)
  986. IMPLICIT REAL*8 (A-H,O-Z)
  987. DIMENSION AMAT(N,*),B(*),X(*),XBASE(*),XPT(NPT,*),FVAL(*),
  988. 1 XSAV(*),XOPT(*),GOPT(*),HQ(*),PQ(*),BMAT(NDIM,*),ZMAT(NPT,*),
  989. 2 SP(*),RESCON(*),STEP(*),PQW(*),W(*)
  990. C
  991. C The arguments N, NPT, M, AMAT, B, X, RHOBEG, IPRINT, XBASE, XPT, FVAL,
  992. C XSAV, XOPT, GOPT, HQ, PQ, BMAT, ZMAT, NDIM, SP and RESCON are the
  993. C same as the corresponding arguments in SUBROUTINE LINCOB.
  994. C KOPT is set to the integer such that XPT(KOPT,.) is the initial trust
  995. C region centre.
  996. C IDZ is going to be set to one, so that every element of Diag(DZ) is
  997. C one in the product ZMAT times Diag(DZ) times ZMAT^T, which is the
  998. C factorization of the leading NPT by NPT submatrix of H.
  999. C STEP, PQW and W are used for working space, the arrays STEP and PQW
  1000. C being taken from LINCOB. The length of W must be at least N+NPT.
  1001. C
  1002. C SUBROUTINE PRELIM provides the elements of XBASE, XPT, BMAT and ZMAT
  1003. C for the first iteration, an important feature being that, if any of
  1004. C of the columns of XPT is an infeasible point, then the largest of
  1005. C the constraint violations there is at least 0.2*RHOBEG. It also sets
  1006. C the initial elements of FVAL, XOPT, GOPT, HQ, PQ, SP and RESCON.
  1007. C
  1008. C Set some constants.
  1009. C
  1010. HALF=0.5D0
  1011. ONE=1.0D0
  1012. ZERO=0.0D0
  1013. NPTM=NPT-N-1
  1014. RHOSQ=RHOBEG*RHOBEG
  1015. RECIP=ONE/RHOSQ
  1016. RECIQ=DSQRT(HALF)/RHOSQ
  1017. TEST=0.2D0*RHOBEG
  1018. IDZ=1
  1019. KBASE=1
  1020. C
  1021. C Set the initial elements of XPT, BMAT, SP and ZMAT to zero.
  1022. C
  1023. DO 20 J=1,N
  1024. XBASE(J)=X(J)
  1025. DO 10 K=1,NPT
  1026. 10 XPT(K,J)=ZERO
  1027. DO 20 I=1,NDIM
  1028. 20 BMAT(I,J)=ZERO
  1029. DO 30 K=1,NPT
  1030. SP(K)=ZERO
  1031. DO 30 J=1,NPT-N-1
  1032. 30 ZMAT(K,J)=ZERO
  1033. C
  1034. C Set the nonzero coordinates of XPT(K,.), K=1,2,...,min[2*N+1,NPT],
  1035. C but they may be altered later to make a constraint violation
  1036. C sufficiently large. The initial nonzero elements of BMAT and of
  1037. C the first min[N,NPT-N-1] columns of ZMAT are set also.
  1038. C
  1039. DO 40 J=1,N
  1040. XPT(J+1,J)=RHOBEG
  1041. IF (J .LT. NPT-N) THEN
  1042. JP=N+J+1
  1043. XPT(JP,J)=-RHOBEG
  1044. BMAT(J+1,J)=HALF/RHOBEG
  1045. BMAT(JP,J)=-HALF/RHOBEG
  1046. ZMAT(1,J)=-RECIQ-RECIQ
  1047. ZMAT(J+1,J)=RECIQ
  1048. ZMAT(JP,J)=RECIQ
  1049. ELSE
  1050. BMAT(1,J)=-ONE/RHOBEG
  1051. BMAT(J+1,J)=ONE/RHOBEG
  1052. BMAT(NPT+J,J)=-HALF*RHOSQ
  1053. END IF
  1054. 40 CONTINUE
  1055. C
  1056. C Set the remaining initial nonzero elements of XPT and ZMAT when the
  1057. C number of interpolation points exceeds 2*N+1.
  1058. C
  1059. IF (NPT .GT. 2*N+1) THEN
  1060. DO 50 K=N+1,NPT-N-1
  1061. ITEMP=(K-1)/N
  1062. IPT=K-ITEMP*N
  1063. JPT=IPT+ITEMP
  1064. IF (JPT .GT. N) JPT=JPT-N
  1065. XPT(N+K+1,IPT)=RHOBEG
  1066. XPT(N+K+1,JPT)=RHOBEG
  1067. ZMAT(1,K)=RECIP
  1068. ZMAT(IPT+1,K)=-RECIP
  1069. ZMAT(JPT+1,K)=-RECIP
  1070. 50 ZMAT(N+K+1,K)=RECIP
  1071. END IF
  1072. C
  1073. C Update the constraint right hand sides to allow for the shift XBASE.
  1074. C
  1075. IF (M .GT. 0) THEN
  1076. DO 70 J=1,M
  1077. TEMP=ZERO
  1078. DO 60 I=1,N
  1079. 60 TEMP=TEMP+AMAT(I,J)*XBASE(I)
  1080. 70 B(J)=B(J)-TEMP
  1081. END IF
  1082. C
  1083. C Go through the initial points, shifting every infeasible point if
  1084. C necessary so that its constraint violation is at least 0.2*RHOBEG.
  1085. C
  1086. DO 150 NF=1,NPT
  1087. FEAS=ONE
  1088. BIGV=ZERO
  1089. J=0
  1090. 80 J=J+1
  1091. IF (J .LE. M .AND. NF .GE. 2) THEN
  1092. RESID=-B(J)
  1093. DO 90 I=1,N
  1094. 90 RESID=RESID+XPT(NF,I)*AMAT(I,J)
  1095. IF (RESID .LE. BIGV) GOTO 80
  1096. BIGV=RESID
  1097. JSAV=J
  1098. IF (RESID .LE. TEST) THEN
  1099. FEAS=-ONE
  1100. GOTO 80
  1101. END IF
  1102. FEAS=ZERO
  1103. END IF
  1104. IF (FEAS .LT. ZERO) THEN
  1105. DO 100 I=1,N
  1106. 100 STEP(I)=XPT(NF,I)+(TEST-BIGV)*AMAT(I,JSAV)
  1107. DO 110 K=1,NPT
  1108. SP(NPT+K)=ZERO
  1109. DO 110 J=1,N
  1110. 110 SP(NPT+K)=SP(NPT+K)+XPT(K,J)*STEP(J)
  1111. CALL UPDATE (N,NPT,XPT,BMAT,ZMAT,IDZ,NDIM,SP,STEP,
  1112. 1 KBASE,NF,PQW,W)
  1113. DO 120 I=1,N
  1114. 120 XPT(NF,I)=STEP(I)
  1115. END IF
  1116. C
  1117. C Calculate the objective function at the current interpolation point,
  1118. C and set KOPT to the index of the first trust region centre.
  1119. C
  1120. DO 130 J=1,N
  1121. 130 X(J)=XBASE(J)+XPT(NF,J)
  1122. F=FEAS
  1123. CALL CALFUN (N,X,F)
  1124. IF (IPRINT .EQ. 3) THEN
  1125. PRINT 140, NF,F,(X(I),I=1,N)
  1126. 140 FORMAT (/4X,'Function number',I6,' F =',1PD18.10,
  1127. 1 ' The corresponding X is:'/(2X,5D15.6))
  1128. END IF
  1129. IF (NF .EQ. 1) THEN
  1130. KOPT=1
  1131. ELSE IF (F .LT. FVAL(KOPT) .AND. FEAS .GT. ZERO) THEN
  1132. KOPT=NF
  1133. END IF
  1134. 150 FVAL(NF)=F
  1135. C
  1136. C Set PQ for the first quadratic model.
  1137. C
  1138. DO 160 J=1,NPTM
  1139. W(J)=ZERO
  1140. DO 160 K=1,NPT
  1141. 160 W(J)=W(J)+ZMAT(K,J)*FVAL(K)
  1142. DO 170 K=1,NPT
  1143. PQ(K)=ZERO
  1144. DO 170 J=1,NPTM
  1145. 170 PQ(K)=PQ(K)+ZMAT(K,J)*W(J)
  1146. C
  1147. C Set XOPT, SP, GOPT and HQ for the first quadratic model.
  1148. C
  1149. DO 180 J=1,N
  1150. XOPT(J)=XPT(KOPT,J)
  1151. XSAV(J)=XBASE(J)+XOPT(J)
  1152. 180 GOPT(J)=ZERO
  1153. DO 200 K=1,NPT
  1154. SP(K)=ZERO
  1155. DO 190 J=1,N
  1156. 190 SP(K)=SP(K)+XPT(K,J)*XOPT(J)
  1157. TEMP=PQ(K)*SP(K)
  1158. DO 200 J=1,N
  1159. 200 GOPT(J)=GOPT(J)+FVAL(K)*BMAT(K,J)+TEMP*XPT(K,J)
  1160. DO 210 I=1,(N*N+N)/2
  1161. 210 HQ(I)=ZERO
  1162. C
  1163. C Set the initial elements of RESCON.
  1164. C
  1165. DO 230 J=1,M
  1166. TEMP=B(J)
  1167. DO 220 I=1,N
  1168. 220 TEMP=TEMP-XOPT(I)*AMAT(I,J)
  1169. TEMP=DMAX1(TEMP,ZERO)
  1170. IF (TEMP .GE. RHOBEG) TEMP=-TEMP
  1171. 230 RESCON(J)=TEMP
  1172. RETURN
  1173. END
  1174. SUBROUTINE QMSTEP (N,NPT,M,AMAT,B,XPT,XOPT,NACT,IACT,
  1175. 1 RESCON,QFAC,KOPT,KNEW,DEL,STEP,GL,PQW,RSTAT,W,IFEAS)
  1176. IMPLICIT REAL*8 (A-H,O-Z)
  1177. DIMENSION AMAT(N,*),B(*),XPT(NPT,*),XOPT(*),IACT(*),
  1178. 1 RESCON(*),QFAC(N,*),STEP(*),GL(*),PQW(*),RSTAT(*),W(*)
  1179. C
  1180. C N, NPT, M, AMAT, B, XPT, XOPT, NACT, IACT, RESCON, QFAC, KOPT are the
  1181. C same as the terms with these names in SUBROUTINE LINCOB.
  1182. C KNEW is the index of the interpolation point that is going to be moved.
  1183. C DEL is the current restriction on the length of STEP, which is never
  1184. C greater than the current trust region radius DELTA.
  1185. C STEP will be set to the required step from XOPT to the new point.
  1186. C GL must be set on entry to the gradient of LFUNC at XBASE, where LFUNC
  1187. C is the KNEW-th Lagrange function. It is used also for some other
  1188. C gradients of LFUNC.
  1189. C PQW provides the second derivative parameters of LFUNC.
  1190. C RSTAT and W are used for working space. Their lengths must be at least
  1191. C M and N, respectively. RSTAT(J) is set to -1.0, 0.0, or 1.0 if the
  1192. C J-th constraint is irrelevant, active, or both inactive and relevant,
  1193. C respectively.
  1194. C IFEAS will be set to 0 or 1 if XOPT+STEP is infeasible or feasible.
  1195. C
  1196. C STEP is chosen to provide a relatively large value of the modulus of
  1197. C LFUNC(XOPT+STEP), subject to ||STEP|| .LE. DEL. A projected STEP is
  1198. C calculated too, within the trust region, that does not alter the
  1199. C residuals of the active constraints. The projected step is preferred
  1200. C if its value of | LFUNC(XOPT+STEP) | is at least one fifth of the
  1201. C original one, but the greatest violation of a linear constraint must
  1202. C be at least 0.2*DEL, in order to keep the interpolation points apart.
  1203. C The remedy when the maximum constraint violation is too small is to
  1204. C restore the original step, which is perturbed if necessary so that
  1205. C its maximum constraint violation becomes 0.2*DEL.
  1206. C
  1207. C Set some constants.
  1208. C
  1209. HALF=0.5D0
  1210. ONE=1.0D0
  1211. TENTH=0.1D0
  1212. ZERO=0.0D0
  1213. TEST=0.2D0*DEL
  1214. C
  1215. C Replace GL by the gradient of LFUNC at the trust region centre, and
  1216. C set the elements of RSTAT.
  1217. C
  1218. DO 20 K=1,NPT
  1219. TEMP=ZERO
  1220. DO 10 J=1,N
  1221. 10 TEMP=TEMP+XPT(K,J)*XOPT(J)
  1222. TEMP=PQW(K)*TEMP
  1223. DO 20 I=1,N
  1224. 20 GL(I)=GL(I)+TEMP*XPT(K,I)
  1225. IF (M .GT. 0) THEN
  1226. DO 30 J=1,M
  1227. RSTAT(J)=ONE
  1228. 30 IF (DABS(RESCON(J)) .GE. DEL) RSTAT(J)=-ONE
  1229. DO 40 K=1,NACT
  1230. 40 RSTAT(IACT(K))=ZERO
  1231. END IF
  1232. C
  1233. C Find the greatest modulus of LFUNC on a line through XOPT and
  1234. C another interpolation point within the trust region.
  1235. C
  1236. IFLAG=0
  1237. VBIG=ZERO
  1238. DO 60 K=1,NPT
  1239. IF (K .EQ. KOPT) GOTO 60
  1240. SS=ZERO
  1241. SP=ZERO
  1242. DO 50 I=1,N
  1243. TEMP=XPT(K,I)-XOPT(I)
  1244. SS=SS+TEMP*TEMP
  1245. 50 SP=SP+GL(I)*TEMP
  1246. STP=-DEL/DSQRT(SS)
  1247. IF (K .EQ. KNEW) THEN
  1248. IF (SP*(SP-ONE) .LT. ZERO) STP=-STP
  1249. VLAG=DABS(STP*SP)+STP*STP*DABS(SP-ONE)
  1250. ELSE
  1251. VLAG=DABS(STP*(ONE-STP)*SP)
  1252. END IF
  1253. IF (VLAG .GT. VBIG) THEN
  1254. KSAV=K
  1255. STPSAV=STP
  1256. VBIG=VLAG
  1257. END IF
  1258. 60 CONTINUE
  1259. C
  1260. C Set STEP to the move that gives the greatest modulus calculated above.
  1261. C This move may be replaced by a steepest ascent step from XOPT.
  1262. C
  1263. GG=ZERO
  1264. DO 70 I=1,N
  1265. GG=GG+GL(I)**2
  1266. 70 STEP(I)=STPSAV*(XPT(KSAV,I)-XOPT(I))
  1267. VGRAD=DEL*DSQRT(GG)
  1268. IF (VGRAD .LE. TENTH*VBIG) GOTO 220
  1269. C
  1270. C Make the replacement if it provides a larger value of VBIG.
  1271. C
  1272. GHG=ZERO
  1273. DO 90 K=1,NPT
  1274. TEMP=ZERO
  1275. DO 80 J=1,N
  1276. 80 TEMP=TEMP+XPT(K,J)*GL(J)
  1277. 90 GHG=GHG+PQW(K)*TEMP*TEMP
  1278. VNEW=VGRAD+DABS(HALF*DEL*DEL*GHG/GG)
  1279. IF (VNEW .GT. VBIG) THEN
  1280. VBIG=VNEW
  1281. STP=DEL/DSQRT(GG)
  1282. IF (GHG .LT. ZERO) STP=-STP
  1283. DO 100 I=1,N
  1284. 100 STEP(I)=STP*GL(I)
  1285. END IF
  1286. IF (NACT .EQ. 0 .OR. NACT .EQ. N) GOTO 220
  1287. C
  1288. C Overwrite GL by its projection. Then set VNEW to the greatest
  1289. C value of |LFUNC| on the projected gradient from XOPT subject to
  1290. C the trust region bound. If VNEW is sufficiently large, then STEP
  1291. C may be changed to a move along the projected gradient.
  1292. C
  1293. DO 110 K=NACT+1,N
  1294. W(K)=ZERO
  1295. DO 110 I=1,N
  1296. 110 W(K)=W(K)+GL(I)*QFAC(I,K)
  1297. GG=ZERO
  1298. DO 130 I=1,N
  1299. GL(I)=ZERO
  1300. DO 120 K=NACT+1,N
  1301. 120 GL(I)=GL(I)+QFAC(I,K)*W(K)
  1302. 130 GG=GG+GL(I)**2
  1303. VGRAD=DEL*DSQRT(GG)
  1304. IF (VGRAD .LE. TENTH*VBIG) GOTO 220
  1305. GHG=ZERO
  1306. DO 150 K=1,NPT
  1307. TEMP=ZERO
  1308. DO 140 J=1,N
  1309. 140 TEMP=TEMP+XPT(K,J)*GL(J)
  1310. 150 GHG=GHG+PQW(K)*TEMP*TEMP
  1311. VNEW=VGRAD+DABS(HALF*DEL*DEL*GHG/GG)
  1312. C
  1313. C Set W to the possible move along the projected gradient.
  1314. C
  1315. STP=DEL/DSQRT(GG)
  1316. IF (GHG .LT. ZERO) STP=-STP
  1317. WW=ZERO
  1318. DO 160 I=1,N
  1319. W(I)=STP*GL(I)
  1320. 160 WW=WW+W(I)**2
  1321. C
  1322. C Set STEP to W if W gives a sufficiently large value of the modulus
  1323. C of the Lagrange function, and if W either preserves feasibility
  1324. C or gives a constraint violation of at least 0.2*DEL. The purpose
  1325. C of CTOL below is to provide a check on feasibility that includes
  1326. C a tolerance for contributions from computer rounding errors.
  1327. C
  1328. IF (VNEW/VBIG .GE. 0.2D0) THEN
  1329. IFEAS=1
  1330. BIGV=ZERO
  1331. J=0
  1332. 170 J=J+1
  1333. IF (J .LE. M) THEN
  1334. IF (RSTAT(J) .EQ. ONE) THEN
  1335. TEMP=-RESCON(J)
  1336. DO 180 I=1,N
  1337. 180 TEMP=TEMP+W(I)*AMAT(I,J)
  1338. BIGV=DMAX1(BIGV,TEMP)
  1339. END IF
  1340. IF (BIGV .LT. TEST) GOTO 170
  1341. IFEAS=0
  1342. END IF
  1343. CTOL=ZERO
  1344. TEMP=0.01D0*DSQRT(WW)
  1345. IF (BIGV .GT. ZERO .AND. BIGV .LT. TEMP) THEN
  1346. DO 200 K=1,NACT
  1347. J=IACT(K)
  1348. SUM=ZERO
  1349. DO 190 I=1,N
  1350. 190 SUM=SUM+W(I)*AMAT(I,J)
  1351. 200 CTOL=DMAX1(CTOL,DABS(SUM))
  1352. END IF
  1353. IF (BIGV .LE. 10.0D0*CTOL .OR. BIGV .GE. TEST) THEN
  1354. DO 210 I=1,N
  1355. 210 STEP(I)=W(I)
  1356. GOTO 260
  1357. END IF
  1358. END IF
  1359. C
  1360. C Calculate the greatest constraint violation at XOPT+STEP with STEP at
  1361. C its original value. Modify STEP if this violation is unacceptable.
  1362. C
  1363. 220 IFEAS=1
  1364. BIGV=ZERO
  1365. RESMAX=ZERO
  1366. J=0
  1367. 230 J=J+1
  1368. IF (J .LE. M) THEN
  1369. IF (RSTAT(J) .LT. ZERO) GOTO 230
  1370. TEMP=-RESCON(J)
  1371. DO 240 I=1,N
  1372. 240 TEMP=TEMP+STEP(I)*AMAT(I,J)
  1373. RESMAX=DMAX1(RESMAX,TEMP)
  1374. IF (TEMP .LT. TEST) THEN
  1375. IF (TEMP .LE. BIGV) GOTO 230
  1376. BIGV=TEMP
  1377. JSAV=J
  1378. IFEAS=-1
  1379. GOTO 230
  1380. END IF
  1381. IFEAS=0
  1382. END IF
  1383. IF (IFEAS .EQ. -1) THEN
  1384. DO 250 I=1,N
  1385. 250 STEP(I)=STEP(I)+(TEST-BIGV)*AMAT(I,JSAV)
  1386. IFEAS=0
  1387. END IF
  1388. C
  1389. C Return the calculated STEP and the value of IFEAS.
  1390. C
  1391. 260 RETURN
  1392. END
  1393. SUBROUTINE TRSTEP (N,NPT,M,AMAT,B,XPT,HQ,PQ,NACT,IACT,RESCON,
  1394. 1 QFAC,RFAC,SNORM,STEP,G,RESNEW,RESACT,D,DW,W)
  1395. IMPLICIT REAL*8 (A-H,O-Z)
  1396. DIMENSION AMAT(N,*),B(*),XPT(NPT,*),HQ(*),PQ(*),IACT(*),
  1397. 1 RESCON(*),QFAC(N,*),RFAC(*),STEP(*),G(*),RESNEW(*),RESACT(*),
  1398. 2 D(*),DW(*),W(*)
  1399. C
  1400. C N, NPT, M, AMAT, B, XPT, HQ, PQ, NACT, IACT, RESCON, QFAC and RFAC
  1401. C are the same as the terms with these names in LINCOB. If RESCON(J)
  1402. C is negative, then |RESCON(J)| must be no less than the trust region
  1403. C radius, so that the J-th constraint can be ignored.
  1404. C SNORM is set to the trust region radius DELTA initially. On the
  1405. C return, however, it is the length of the calculated STEP, which is
  1406. C set to zero if the constraints do not allow a long enough step.
  1407. C STEP is the total calculated step so far from the trust region centre,
  1408. C its final value being given by the sequence of CG iterations, which
  1409. C terminate if the trust region boundary is reached.
  1410. C G must be set on entry to the gradient of the quadratic model at the
  1411. C trust region centre. It is used as working space, however, and is
  1412. C always the gradient of the model at the current STEP, except that
  1413. C on return the value of G(1) is set to ONE instead of to ZERO if
  1414. C and only if GETACT is called more than once.
  1415. C RESNEW, RESACT, D, DW and W are used for working space. A negative
  1416. C value of RESNEW(J) indicates that the J-th constraint does not
  1417. C restrict the CG steps of the current trust region calculation, a
  1418. C zero value of RESNEW(J) indicates that the J-th constraint is active,
  1419. C and otherwise RESNEW(J) is set to the greater of TINY and the actual
  1420. C residual of the J-th constraint for the current STEP. RESACT holds
  1421. C the residuals of the active constraints, which may be positive.
  1422. C D is the search direction of each line search. DW is either another
  1423. C search direction or the change in gradient along D. The length of W
  1424. C must be at least MAX[M,2*N].
  1425. C
  1426. C Set some numbers for the conjugate gradient iterations.
  1427. C
  1428. HALF=0.5D0
  1429. ONE=1.0D0
  1430. TINY=1.0D-60
  1431. ZERO=0.0D0
  1432. CTEST=0.01D0
  1433. SNSQ=SNORM*SNORM
  1434. C
  1435. C Set the initial elements of RESNEW, RESACT and STEP.
  1436. C
  1437. IF (M .GT. 0) THEN
  1438. DO 10 J=1,M
  1439. RESNEW(J)=RESCON(J)
  1440. IF (RESCON(J) .GE. SNORM) THEN
  1441. RESNEW(J)=-ONE
  1442. ELSE IF (RESCON(J) .GE. ZERO) THEN
  1443. RESNEW(J)=DMAX1(RESNEW(J),TINY)
  1444. END IF
  1445. 10 CONTINUE
  1446. IF (NACT .GT. 0) THEN
  1447. DO 20 K=1,NACT
  1448. RESACT(K)=RESCON(IACT(K))
  1449. 20 RESNEW(IACT(K))=ZERO
  1450. END IF
  1451. END IF
  1452. DO 30 I=1,N
  1453. 30 STEP(I)=ZERO
  1454. SS=ZERO
  1455. REDUCT=ZERO
  1456. NCALL=0
  1457. C
  1458. C GETACT picks the active set for the current STEP. It also sets DW to
  1459. C the vector closest to -G that is orthogonal to the normals of the
  1460. C active constraints. DW is scaled to have length 0.2*SNORM, as then
  1461. C a move of DW from STEP is allowed by the linear constraints.
  1462. C
  1463. 40 NCALL=NCALL+1
  1464. CALL GETACT (N,M,AMAT,B,NACT,IACT,QFAC,RFAC,SNORM,RESNEW,
  1465. 1 RESACT,G,DW,W,W(N+1))
  1466. IF (W(N+1) .EQ. ZERO) GOTO 320
  1467. SCALE=0.2D0*SNORM/DSQRT(W(N+1))
  1468. DO 50 I=1,N
  1469. 50 DW(I)=SCALE*DW(I)
  1470. C
  1471. C If the modulus of the residual of an active constraint is substantial,
  1472. C then set D to the shortest move from STEP to the boundaries of the
  1473. C active constraints.
  1474. C
  1475. RESMAX=ZERO
  1476. IF (NACT .GT. 0) THEN
  1477. DO 60 K=1,NACT
  1478. 60 RESMAX=DMAX1(RESMAX,RESACT(K))
  1479. END IF
  1480. GAMMA=ZERO
  1481. IF (RESMAX .GT. 1.0D-4*SNORM) THEN
  1482. IR=0
  1483. DO 80 K=1,NACT
  1484. TEMP=RESACT(K)
  1485. IF (K .GE. 2) THEN
  1486. DO 70 I=1,K-1
  1487. IR=IR+1
  1488. 70 TEMP=TEMP-RFAC(IR)*W(I)
  1489. END IF
  1490. IR=IR+1
  1491. 80 W(K)=TEMP/RFAC(IR)
  1492. DO 90 I=1,N
  1493. D(I)=ZERO
  1494. DO 90 K=1,NACT
  1495. 90 D(I)=D(I)+W(K)*QFAC(I,K)
  1496. C
  1497. C The vector D that has just been calculated is also the shortest move
  1498. C from STEP+DW to the boundaries of the active constraints. Set GAMMA
  1499. C to the greatest steplength of this move that satisfies the trust
  1500. C region bound.
  1501. C
  1502. RHS=SNSQ
  1503. DS=ZERO
  1504. DD=ZERO
  1505. DO 100 I=1,N
  1506. SUM=STEP(I)+DW(I)
  1507. RHS=RHS-SUM*SUM
  1508. DS=DS+D(I)*SUM
  1509. 100 DD=DD+D(I)**2
  1510. IF (RHS .GT. ZERO) THEN
  1511. TEMP=DSQRT(DS*DS+DD*RHS)
  1512. IF (DS .LE. ZERO) THEN
  1513. GAMMA=(TEMP-DS)/DD
  1514. ELSE
  1515. GAMMA=RHS/(TEMP+DS)
  1516. END IF
  1517. END IF
  1518. C
  1519. C Reduce the steplength GAMMA if necessary so that the move along D
  1520. C also satisfies the linear constraints.
  1521. C
  1522. J=0
  1523. 110 IF (GAMMA .GT. ZERO) THEN
  1524. J=J+1
  1525. IF (RESNEW(J) .GT. ZERO) THEN
  1526. AD=ZERO
  1527. ADW=ZERO
  1528. DO 120 I=1,N
  1529. AD=AD+AMAT(I,J)*D(I)
  1530. 120 ADW=ADW+AMAT(I,J)*DW(I)
  1531. IF (AD .GT. ZERO) THEN
  1532. TEMP=DMAX1((RESNEW(J)-ADW)/AD,ZERO)
  1533. GAMMA=DMIN1(GAMMA,TEMP)
  1534. END IF
  1535. END IF
  1536. IF (J .LT. M) GOTO 110
  1537. END IF
  1538. GAMMA=DMIN1(GAMMA,ONE)
  1539. END IF
  1540. C
  1541. C Set the next direction for seeking a reduction in the model function
  1542. C subject to the trust region bound and the linear constraints.
  1543. C
  1544. IF (GAMMA .LE. ZERO) THEN
  1545. DO 130 I=1,N
  1546. 130 D(I)=DW(I)
  1547. ICOUNT=NACT
  1548. ELSE
  1549. DO 140 I=1,N
  1550. 140 D(I)=DW(I)+GAMMA*D(I)
  1551. ICOUNT=NACT-1
  1552. END IF
  1553. ALPBD=ONE
  1554. C
  1555. C Set ALPHA to the steplength from STEP along D to the trust region
  1556. C boundary. Return if the first derivative term of this step is
  1557. C sufficiently small or if no further progress is possible.
  1558. C
  1559. 150 ICOUNT=ICOUNT+1
  1560. RHS=SNSQ-SS
  1561. IF (RHS .LE. ZERO) GOTO 320
  1562. DG=ZERO
  1563. DS=ZERO
  1564. DD=ZERO
  1565. DO 160 I=1,N
  1566. DG=DG+D(I)*G(I)
  1567. DS=DS+D(I)*STEP(I)
  1568. 160 DD=DD+D(I)**2
  1569. IF (DG .GE. ZERO) GOTO 320
  1570. TEMP=DSQRT(RHS*DD+DS*DS)
  1571. IF (DS .LE. ZERO) THEN
  1572. ALPHA=(TEMP-DS)/DD
  1573. ELSE
  1574. ALPHA=RHS/(TEMP+DS)
  1575. END IF
  1576. IF (-ALPHA*DG .LE. CTEST*REDUCT) GOTO 320
  1577. C
  1578. C Set DW to the change in gradient along D.
  1579. C
  1580. IH=0
  1581. DO 170 J=1,N
  1582. DW(J)=ZERO
  1583. DO 170 I=1,J
  1584. IH=IH+1
  1585. IF (I .LT. J) DW(J)=DW(J)+HQ(IH)*D(I)
  1586. 170 DW(I)=DW(I)+HQ(IH)*D(J)
  1587. DO 190 K=1,NPT
  1588. TEMP=ZERO
  1589. DO 180 J=1,N
  1590. 180 TEMP=TEMP+XPT(K,J)*D(J)
  1591. TEMP=PQ(K)*TEMP
  1592. DO 190 I=1,N
  1593. 190 DW(I)=DW(I)+TEMP*XPT(K,I)
  1594. C
  1595. C Set DGD to the curvature of the model along D. Then reduce ALPHA if
  1596. C necessary to the value that minimizes the model.
  1597. C
  1598. DGD=ZERO
  1599. DO 200 I=1,N
  1600. 200 DGD=DGD+D(I)*DW(I)
  1601. ALPHT=ALPHA
  1602. IF (DG+ALPHA*DGD .GT. ZERO) THEN
  1603. ALPHA=-DG/DGD
  1604. END IF
  1605. C
  1606. C Make a further reduction in ALPHA if necessary to preserve feasibility,
  1607. C and put some scalar products of D with constraint gradients in W.
  1608. C
  1609. ALPHM=ALPHA
  1610. JSAV=0
  1611. IF (M .GT. 0) THEN
  1612. DO 220 J=1,M
  1613. AD=ZERO
  1614. IF (RESNEW(J) .GT. ZERO) THEN
  1615. DO 210 I=1,N
  1616. 210 AD=AD+AMAT(I,J)*D(I)
  1617. IF (ALPHA*AD .GT. RESNEW(J)) THEN
  1618. ALPHA=RESNEW(J)/AD
  1619. JSAV=J
  1620. END IF
  1621. END IF
  1622. 220 W(J)=AD
  1623. END IF
  1624. ALPHA=DMAX1(ALPHA,ALPBD)
  1625. ALPHA=DMIN1(ALPHA,ALPHM)
  1626. IF (ICOUNT .EQ. NACT) ALPHA=DMIN1(ALPHA,ONE)
  1627. C
  1628. C Update STEP, G, RESNEW, RESACT and REDUCT.
  1629. C
  1630. SS=ZERO
  1631. DO 230 I=1,N
  1632. STEP(I)=STEP(I)+ALPHA*D(I)
  1633. SS=SS+STEP(I)**2
  1634. 230 G(I)=G(I)+ALPHA*DW(I)
  1635. IF (M .GT. 0) THEN
  1636. DO 240 J=1,M
  1637. IF (RESNEW(J) .GT. ZERO) THEN
  1638. RESNEW(J)=DMAX1(RESNEW(J)-ALPHA*W(J),TINY)
  1639. END IF
  1640. 240 CONTINUE
  1641. END IF
  1642. IF (ICOUNT .EQ. NACT .AND. NACT .GT. 0) THEN
  1643. DO 250 K=1,NACT
  1644. 250 RESACT(K)=(ONE-GAMMA)*RESACT(K)
  1645. END IF
  1646. REDUCT=REDUCT-ALPHA*(DG+HALF*ALPHA*DGD)
  1647. C
  1648. C Test for termination. Branch to label 40 if there is a new active
  1649. C constraint and if the distance from STEP to the trust region
  1650. C boundary is at least 0.2*SNORM.
  1651. C
  1652. IF (ALPHA .EQ. ALPHT) GOTO 320
  1653. TEMP=-ALPHM*(DG+HALF*ALPHM*DGD)
  1654. IF (TEMP .LE. CTEST*REDUCT) GOTO 320
  1655. IF (JSAV .GT. 0) THEN
  1656. IF (SS .LE. 0.64D0*SNSQ) GOTO 40
  1657. GOTO 320
  1658. END IF
  1659. IF (ICOUNT .EQ. N) GOTO 320
  1660. C
  1661. C Calculate the next search direction, which is conjugate to the
  1662. C previous one except in the case ICOUNT=NACT.
  1663. C
  1664. IF (NACT .GT. 0) THEN
  1665. DO 260 J=NACT+1,N
  1666. W(J)=ZERO
  1667. DO 260 I=1,N
  1668. 260 W(J)=W(J)+G(I)*QFAC(I,J)
  1669. DO 280 I=1,N
  1670. TEMP=ZERO
  1671. DO 270 J=NACT+1,N
  1672. 270 TEMP=TEMP+QFAC(I,J)*W(J)
  1673. 280 W(N+I)=TEMP
  1674. ELSE
  1675. DO 290 I=1,N
  1676. 290 W(N+I)=G(I)
  1677. END IF
  1678. IF (ICOUNT .EQ. NACT) THEN
  1679. BETA=ZERO
  1680. ELSE
  1681. WGD=ZERO
  1682. DO 300 I=1,N
  1683. 300 WGD=WGD+W(N+I)*DW(I)
  1684. BETA=WGD/DGD
  1685. END IF
  1686. DO 310 I=1,N
  1687. 310 D(I)=-W(N+I)+BETA*D(I)
  1688. ALPBD=ZERO
  1689. GOTO 150
  1690. C
  1691. C Return from the subroutine.
  1692. C
  1693. 320 SNORM=ZERO
  1694. IF (REDUCT .GT. ZERO) SNORM=DSQRT(SS)
  1695. G(1)=ZERO
  1696. IF (NCALL .GT. 1) G(1)=ONE
  1697. RETURN
  1698. END
  1699. SUBROUTINE UPDATE (N,NPT,XPT,BMAT,ZMAT,IDZ,NDIM,SP,STEP,
  1700. 1 KOPT,KNEW,VLAG,W)
  1701. IMPLICIT REAL*8 (A-H,O-Z)
  1702. DIMENSION XPT(NPT,*),BMAT(NDIM,*),ZMAT(NPT,*),SP(*),STEP(*),
  1703. 2 VLAG(*),W(*)
  1704. C
  1705. C The arguments N, NPT, XPT, BMAT, ZMAT, IDZ, NDIM ,SP and STEP are
  1706. C identical to the corresponding arguments in SUBROUTINE LINCOB.
  1707. C KOPT is such that XPT(KOPT,.) is the current trust region centre.
  1708. C KNEW on exit is usually positive, and then it is the index of an
  1709. C interpolation point to be moved to the position XPT(KOPT,.)+STEP(.).
  1710. C It is set on entry either to its final value or to 0. In the latter
  1711. C case, the final value of KNEW is chosen to maximize the denominator
  1712. C of the matrix updating formula times a weighting factor.
  1713. C VLAG and W are used for working space, the first NPT+N elements of
  1714. C both of these vectors being required.
  1715. C
  1716. C The arrays BMAT and ZMAT with IDZ are updated, the new matrices being
  1717. C the ones that are suitable after the shift of the KNEW-th point to
  1718. C the new position XPT(KOPT,.)+STEP(.). A return with KNEW set to zero
  1719. C occurs if the calculation fails due to a zero denominator in the
  1720. C updating formula, which should never happen.
  1721. C
  1722. C Set some constants.
  1723. C
  1724. HALF=0.5D0
  1725. ONE=1.0D0
  1726. ZERO=0.0D0
  1727. NPTM=NPT-N-1
  1728. C
  1729. C Calculate VLAG and BETA for the current choice of STEP. The first NPT
  1730. C elements of VLAG are set to the values of the Lagrange functions at
  1731. C XPT(KOPT,.)+STEP(.). The first NPT components of W_check are held
  1732. C in W, where W_check is defined in a paper on the updating method.
  1733. C
  1734. DO 20 K=1,NPT
  1735. W(K)=SP(NPT+K)*(HALF*SP(NPT+K)+SP(K))
  1736. SUM=ZERO
  1737. DO 10 J=1,N
  1738. 10 SUM=SUM+BMAT(K,J)*STEP(J)
  1739. 20 VLAG(K)=SUM
  1740. BETA=ZERO
  1741. DO 40 K=1,NPTM
  1742. SUM=ZERO
  1743. DO 30 I=1,NPT
  1744. 30 SUM=SUM+ZMAT(I,K)*W(I)
  1745. IF (K .LT. IDZ) THEN
  1746. BETA=BETA+SUM*SUM
  1747. SUM=-SUM
  1748. ELSE
  1749. BETA=BETA-SUM*SUM
  1750. END IF
  1751. DO 40 I=1,NPT
  1752. 40 VLAG(I)=VLAG(I)+SUM*ZMAT(I,K)
  1753. BSUM=ZERO
  1754. DX=ZERO
  1755. SSQ=ZERO
  1756. DO 70 J=1,N
  1757. SUM=ZERO
  1758. DO 50 I=1,NPT
  1759. 50 SUM=SUM+W(I)*BMAT(I,J)
  1760. BSUM=BSUM+SUM*STEP(J)
  1761. JP=NPT+J
  1762. DO 60 K=1,N
  1763. 60 SUM=SUM+BMAT(JP,K)*STEP(K)
  1764. VLAG(JP)=SUM
  1765. BSUM=BSUM+SUM*STEP(J)
  1766. DX=DX+STEP(J)*XPT(KOPT,J)
  1767. 70 SSQ=SSQ+STEP(J)**2
  1768. BETA=DX*DX+SSQ*(SP(KOPT)+DX+DX+HALF*SSQ)+BETA-BSUM
  1769. VLAG(KOPT)=VLAG(KOPT)+ONE
  1770. C
  1771. C If KNEW is zero initially, then pick the index of the interpolation
  1772. C point to be deleted, by maximizing the absolute value of the
  1773. C denominator of the updating formula times a weighting factor.
  1774. C
  1775. C
  1776. IF (KNEW .EQ. 0) THEN
  1777. DENMAX=ZERO
  1778. DO 100 K=1,NPT
  1779. HDIAG=ZERO
  1780. DO 80 J=1,NPTM
  1781. TEMP=ONE
  1782. IF (J .LT. IDZ) TEMP=-ONE
  1783. 80 HDIAG=HDIAG+TEMP*ZMAT(K,J)**2
  1784. DENABS=DABS(BETA*HDIAG+VLAG(K)**2)
  1785. DISTSQ=ZERO
  1786. DO 90 J=1,N
  1787. 90 DISTSQ=DISTSQ+(XPT(K,J)-XPT(KOPT,J))**2
  1788. TEMP=DENABS*DISTSQ*DISTSQ
  1789. IF (TEMP .GT. DENMAX) THEN
  1790. DENMAX=TEMP
  1791. KNEW=K
  1792. END IF
  1793. 100 CONTINUE
  1794. END IF
  1795. C
  1796. C Apply the rotations that put zeros in the KNEW-th row of ZMAT.
  1797. C
  1798. JL=1
  1799. IF (NPTM .GE. 2) THEN
  1800. DO 120 J=2,NPTM
  1801. IF (J .EQ. IDZ) THEN
  1802. JL=IDZ
  1803. ELSE IF (ZMAT(KNEW,J) .NE. ZERO) THEN
  1804. TEMP=DSQRT(ZMAT(KNEW,JL)**2+ZMAT(KNEW,J)**2)
  1805. TEMPA=ZMAT(KNEW,JL)/TEMP
  1806. TEMPB=ZMAT(KNEW,J)/TEMP
  1807. DO 110 I=1,NPT
  1808. TEMP=TEMPA*ZMAT(I,JL)+TEMPB*ZMAT(I,J)
  1809. ZMAT(I,J)=TEMPA*ZMAT(I,J)-TEMPB*ZMAT(I,JL)
  1810. 110 ZMAT(I,JL)=TEMP
  1811. ZMAT(KNEW,J)=ZERO
  1812. END IF
  1813. 120 CONTINUE
  1814. END IF
  1815. C
  1816. C Put the first NPT components of the KNEW-th column of the Z Z^T matrix
  1817. C into W, and calculate the parameters of the updating formula.
  1818. C
  1819. TEMPA=ZMAT(KNEW,1)
  1820. IF (IDZ .GE. 2) TEMPA=-TEMPA
  1821. IF (JL .GT. 1) TEMPB=ZMAT(KNEW,JL)
  1822. DO 130 I=1,NPT
  1823. W(I)=TEMPA*ZMAT(I,1)
  1824. IF (JL .GT. 1) W(I)=W(I)+TEMPB*ZMAT(I,JL)
  1825. 130 CONTINUE
  1826. ALPHA=W(KNEW)
  1827. TAU=VLAG(KNEW)
  1828. TAUSQ=TAU*TAU
  1829. DENOM=ALPHA*BETA+TAUSQ
  1830. VLAG(KNEW)=VLAG(KNEW)-ONE
  1831. IF (DENOM .EQ. ZERO) THEN
  1832. KNEW=0
  1833. GOTO 180
  1834. END IF
  1835. SQRTDN=DSQRT(DABS(DENOM))
  1836. C
  1837. C Complete the updating of ZMAT when there is only one nonzero element
  1838. C in the KNEW-th row of the new matrix ZMAT. IFLAG is set to one when
  1839. C the value of IDZ is going to be reduced.
  1840. C
  1841. IFLAG=0
  1842. IF (JL .EQ. 1) THEN
  1843. TEMPA=TAU/SQRTDN
  1844. TEMPB=ZMAT(KNEW,1)/SQRTDN
  1845. DO 140 I=1,NPT
  1846. 140 ZMAT(I,1)=TEMPA*ZMAT(I,1)-TEMPB*VLAG(I)
  1847. IF (DENOM .LT. ZERO) THEN
  1848. IF (IDZ .EQ. 1) THEN
  1849. IDZ=2
  1850. ELSE
  1851. IFLAG=1
  1852. END IF
  1853. END IF
  1854. ELSE
  1855. C
  1856. C Complete the updating of ZMAT in the alternative case.
  1857. C
  1858. JA=1
  1859. IF (BETA .GE. ZERO) JA=JL
  1860. JB=JL+1-JA
  1861. TEMP=ZMAT(KNEW,JB)/DENOM
  1862. TEMPA=TEMP*BETA
  1863. TEMPB=TEMP*TAU
  1864. TEMP=ZMAT(KNEW,JA)
  1865. SCALA=ONE/DSQRT(DABS(BETA)*TEMP*TEMP+TAUSQ)
  1866. SCALB=SCALA*SQRTDN
  1867. DO 150 I=1,NPT
  1868. ZMAT(I,JA)=SCALA*(TAU*ZMAT(I,JA)-TEMP*VLAG(I))
  1869. 150 ZMAT(I,JB)=SCALB*(ZMAT(I,JB)-TEMPA*W(I)-TEMPB*VLAG(I))
  1870. IF (DENOM .LE. ZERO) THEN
  1871. IF (BETA .LT. ZERO) THEN
  1872. IDZ=IDZ+1
  1873. ELSE
  1874. IFLAG=1
  1875. END IF
  1876. END IF
  1877. END IF
  1878. C
  1879. C Reduce IDZ when the diagonal part of the ZMAT times Diag(DZ) times
  1880. C ZMAT^T factorization gains another positive element. Then exchange
  1881. C the first and IDZ-th columns of ZMAT.
  1882. C
  1883. IF (IFLAG .EQ. 1) THEN
  1884. IDZ=IDZ-1
  1885. DO 160 I=1,NPT
  1886. TEMP=ZMAT(I,1)
  1887. ZMAT(I,1)=ZMAT(I,IDZ)
  1888. 160 ZMAT(I,IDZ)=TEMP
  1889. END IF
  1890. C
  1891. C Finally, update the matrix BMAT.
  1892. C
  1893. DO 170 J=1,N
  1894. JP=NPT+J
  1895. W(JP)=BMAT(KNEW,J)
  1896. TEMPA=(ALPHA*VLAG(JP)-TAU*W(JP))/DENOM
  1897. TEMPB=(-BETA*W(JP)-TAU*VLAG(JP))/DENOM
  1898. DO 170 I=1,JP
  1899. BMAT(I,J)=BMAT(I,J)+TEMPA*VLAG(I)+TEMPB*W(I)
  1900. IF (I .GT. NPT) BMAT(JP,I-NPT)=BMAT(I,J)
  1901. 170 CONTINUE
  1902. 180 RETURN
  1903. END