email.txt 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412
  1. COBYLA
  2. ~~~~~~
  3. Here is a single-precision Fortran implementation of the algorithm for
  4. constrained optimization that is the subject of the report I have written on
  5. "A direct search optimization method that models the objective and constraint
  6. functions by linear interpolation". This report has the number DAMTP 1992/NA5,
  7. University of Cambridge, and it has been published in the proceedings of the
  8. conference on Numerical Analysis and Optimization that was held in Oaxaca,
  9. Mexico in January, 1992, which is the book "Advances in Optimization and
  10. Numerical Analysis" (eds. Susana Gomez and Jean-Pierre Hennart), Kluwer
  11. Academic Publishers (1994).
  12. The instructions for using the Fortran code are given in the comments of
  13. SUBROUTINE COBYLA, which is the interface between the user and the main
  14. calculation that is done by SUBROUTINE COBYLB. There is a need for a linear
  15. programming problem to be solved subject to a Euclidean norm trust region
  16. constraint. Therefore SUBROUTINE TRSTLP is provided too, but you may have some
  17. software that you prefer to use instead. These 3 subroutines are separated by
  18. lines of hyphens below. Further, there follows the main program, the CALCFC
  19. subroutine and the output that are appropriate to the numerical examples that
  20. are discussed in the last section of DAMTP 1992/NA5. Please note, however,
  21. that some cosmetic restructuring of the software has caused the given output
  22. to differ slightly from Table 1 of the report.
  23. There are no restrictions on the use of the software, nor do I offer any
  24. guarantees of success. Indeed, at the time of writing this note I had applied
  25. it only to test problems that have up to 10 variables.
  26. Mike Powell (May 7th, 1992).
  27. -------------------------------------------------------------------------------
  28. SUBROUTINE COBYLA (N,M,X,RHOBEG,RHOEND,IPRINT,MAXFUN,W,IACT)
  29. DIMENSION X(*),W(*),IACT(*)
  30. C
  31. C This subroutine minimizes an objective function F(X) subject to M
  32. C inequality constraints on X, where X is a vector of variables that has
  33. C N components. The algorithm employs linear approximations to the
  34. C objective and constraint functions, the approximations being formed by
  35. C linear interpolation at N+1 points in the space of the variables.
  36. C We regard these interpolation points as vertices of a simplex. The
  37. C parameter RHO controls the size of the simplex and it is reduced
  38. C automatically from RHOBEG to RHOEND. For each RHO the subroutine tries
  39. C to achieve a good vector of variables for the current size, and then
  40. C RHO is reduced until the value RHOEND is reached. Therefore RHOBEG and
  41. C RHOEND should be set to reasonable initial changes to and the required
  42. C accuracy in the variables respectively, but this accuracy should be
  43. C viewed as a subject for experimentation because it is not guaranteed.
  44. C The subroutine has an advantage over many of its competitors, however,
  45. C which is that it treats each constraint individually when calculating
  46. C a change to the variables, instead of lumping the constraints together
  47. C into a single penalty function. The name of the subroutine is derived
  48. C from the phrase Constrained Optimization BY Linear Approximations.
  49. C
  50. C The user must set the values of N, M, RHOBEG and RHOEND, and must
  51. C provide an initial vector of variables in X. Further, the value of
  52. C IPRINT should be set to 0, 1, 2 or 3, which controls the amount of
  53. C printing during the calculation. Specifically, there is no output if
  54. C IPRINT=0 and there is output only at the end of the calculation if
  55. C IPRINT=1. Otherwise each new value of RHO and SIGMA is printed.
  56. C Further, the vector of variables and some function information are
  57. C given either when RHO is reduced or when each new value of F(X) is
  58. C computed in the cases IPRINT=2 or IPRINT=3 respectively. Here SIGMA
  59. C is a penalty parameter, it being assumed that a change to X is an
  60. C improvement if it reduces the merit function
  61. C F(X)+SIGMA*MAX(0.0,-C1(X),-C2(X),...,-CM(X)),
  62. C where C1,C2,...,CM denote the constraint functions that should become
  63. C nonnegative eventually, at least to the precision of RHOEND. In the
  64. C printed output the displayed term that is multiplied by SIGMA is
  65. C called MAXCV, which stands for 'MAXimum Constraint Violation'. The
  66. C argument MAXFUN is an integer variable that must be set by the user to a
  67. C limit on the number of calls of CALCFC, the purpose of this routine being
  68. C given below. The value of MAXFUN will be altered to the number of calls
  69. C of CALCFC that are made. The arguments W and IACT provide real and
  70. C integer arrays that are used as working space. Their lengths must be at
  71. C least N*(3*N+2*M+11)+4*M+6 and M+1 respectively.
  72. C
  73. C In order to define the objective and constraint functions, we require
  74. C a subroutine that has the name and arguments
  75. C SUBROUTINE CALCFC (N,M,X,F,CON)
  76. C DIMENSION X(*),CON(*) .
  77. C The values of N and M are fixed and have been defined already, while
  78. C X is now the current vector of variables. The subroutine should return
  79. C the objective and constraint functions at X in F and CON(1),CON(2),
  80. C ...,CON(M). Note that we are trying to adjust X so that F(X) is as
  81. C small as possible subject to the constraint functions being nonnegative.
  82. C
  83. C Partition the working space array W to provide the storage that is needed
  84. C for the main calculation.
  85. C
  86. MPP=M+2
  87. ICON=1
  88. ISIM=ICON+MPP
  89. ISIMI=ISIM+N*N+N
  90. IDATM=ISIMI+N*N
  91. IA=IDATM+N*MPP+MPP
  92. IVSIG=IA+M*N+N
  93. IVETA=IVSIG+N
  94. ISIGB=IVETA+N
  95. IDX=ISIGB+N
  96. IWORK=IDX+N
  97. CALL COBYLB (N,M,MPP,X,RHOBEG,RHOEND,IPRINT,MAXFUN,W(ICON),
  98. 1 W(ISIM),W(ISIMI),W(IDATM),W(IA),W(IVSIG),W(IVETA),W(ISIGB),
  99. 2 W(IDX),W(IWORK),IACT)
  100. RETURN
  101. END
  102. C------------------------------------------------------------------------------
  103. SUBROUTINE COBYLB (N,M,MPP,X,RHOBEG,RHOEND,IPRINT,MAXFUN,
  104. 1 CON,SIM,SIMI,DATMAT,A,VSIG,VETA,SIGBAR,DX,W,IACT)
  105. DIMENSION X(*),CON(*),SIM(N,*),SIMI(N,*),DATMAT(MPP,*),
  106. 1 A(N,*),VSIG(*),VETA(*),SIGBAR(*),DX(*),W(*),IACT(*)
  107. C
  108. C Set the initial values of some parameters. The last column of SIM holds
  109. C the optimal vertex of the current simplex, and the preceding N columns
  110. C hold the displacements from the optimal vertex to the other vertices.
  111. C Further, SIMI holds the inverse of the matrix that is contained in the
  112. C first N columns of SIM.
  113. C
  114. IPTEM=MIN0(N,5)
  115. IPTEMP=IPTEM+1
  116. NP=N+1
  117. MP=M+1
  118. ALPHA=0.25
  119. BETA=2.1
  120. GAMMA=0.5
  121. DELTA=1.1
  122. RHO=RHOBEG
  123. PARMU=0.0
  124. IF (IPRINT .GE. 2) PRINT 10, RHO
  125. 10 FORMAT (/3X,'The initial value of RHO is',1PE13.6,2X,
  126. 1 'and PARMU is set to zero.')
  127. NFVALS=0
  128. TEMP=1.0/RHO
  129. DO 30 I=1,N
  130. SIM(I,NP)=X(I)
  131. DO 20 J=1,N
  132. SIM(I,J)=0.0
  133. 20 SIMI(I,J)=0.0
  134. SIM(I,I)=RHO
  135. 30 SIMI(I,I)=TEMP
  136. JDROP=NP
  137. IBRNCH=0
  138. C
  139. C Make the next call of the user-supplied subroutine CALCFC. These
  140. C instructions are also used for calling CALCFC during the iterations of
  141. C the algorithm.
  142. C
  143. 40 IF (NFVALS .GE. MAXFUN .AND. NFVALS .GT. 0) THEN
  144. IF (IPRINT .GE. 1) PRINT 50
  145. 50 FORMAT (/3X,'Return from subroutine COBYLA because the ',
  146. 1 'MAXFUN limit has been reached.')
  147. GOTO 600
  148. END IF
  149. NFVALS=NFVALS+1
  150. CALL CALCFC (N,M,X,F,CON)
  151. RESMAX=0.0
  152. IF (M .GT. 0) THEN
  153. DO 60 K=1,M
  154. 60 RESMAX=AMAX1(RESMAX,-CON(K))
  155. END IF
  156. IF (NFVALS .EQ. IPRINT-1 .OR. IPRINT .EQ. 3) THEN
  157. PRINT 70, NFVALS,F,RESMAX,(X(I),I=1,IPTEM)
  158. 70 FORMAT (/3X,'NFVALS =',I5,3X,'F =',1PE13.6,4X,'MAXCV =',
  159. 1 1PE13.6/3X,'X =',1PE13.6,1P4E15.6)
  160. IF (IPTEM .LT. N) PRINT 80, (X(I),I=IPTEMP,N)
  161. 80 FORMAT (1PE19.6,1P4E15.6)
  162. END IF
  163. CON(MP)=F
  164. CON(MPP)=RESMAX
  165. IF (IBRNCH .EQ. 1) GOTO 440
  166. C
  167. C Set the recently calculated function values in a column of DATMAT. This
  168. C array has a column for each vertex of the current simplex, the entries of
  169. C each column being the values of the constraint functions (if any)
  170. C followed by the objective function and the greatest constraint violation
  171. C at the vertex.
  172. C
  173. DO 90 K=1,MPP
  174. 90 DATMAT(K,JDROP)=CON(K)
  175. IF (NFVALS .GT. NP) GOTO 130
  176. C
  177. C Exchange the new vertex of the initial simplex with the optimal vertex if
  178. C necessary. Then, if the initial simplex is not complete, pick its next
  179. C vertex and calculate the function values there.
  180. C
  181. IF (JDROP .LE. N) THEN
  182. IF (DATMAT(MP,NP) .LE. F) THEN
  183. X(JDROP)=SIM(JDROP,NP)
  184. ELSE
  185. SIM(JDROP,NP)=X(JDROP)
  186. DO 100 K=1,MPP
  187. DATMAT(K,JDROP)=DATMAT(K,NP)
  188. 100 DATMAT(K,NP)=CON(K)
  189. DO 120 K=1,JDROP
  190. SIM(JDROP,K)=-RHO
  191. TEMP=0.0
  192. DO 110 I=K,JDROP
  193. 110 TEMP=TEMP-SIMI(I,K)
  194. 120 SIMI(JDROP,K)=TEMP
  195. END IF
  196. END IF
  197. IF (NFVALS .LE. N) THEN
  198. JDROP=NFVALS
  199. X(JDROP)=X(JDROP)+RHO
  200. GOTO 40
  201. END IF
  202. 130 IBRNCH=1
  203. C
  204. C Identify the optimal vertex of the current simplex.
  205. C
  206. 140 PHIMIN=DATMAT(MP,NP)+PARMU*DATMAT(MPP,NP)
  207. NBEST=NP
  208. DO 150 J=1,N
  209. TEMP=DATMAT(MP,J)+PARMU*DATMAT(MPP,J)
  210. IF (TEMP .LT. PHIMIN) THEN
  211. NBEST=J
  212. PHIMIN=TEMP
  213. ELSE IF (TEMP .EQ. PHIMIN .AND. PARMU .EQ. 0.0) THEN
  214. IF (DATMAT(MPP,J) .LT. DATMAT(MPP,NBEST)) NBEST=J
  215. END IF
  216. 150 CONTINUE
  217. C
  218. C Switch the best vertex into pole position if it is not there already,
  219. C and also update SIM, SIMI and DATMAT.
  220. C
  221. IF (NBEST .LE. N) THEN
  222. DO 160 I=1,MPP
  223. TEMP=DATMAT(I,NP)
  224. DATMAT(I,NP)=DATMAT(I,NBEST)
  225. 160 DATMAT(I,NBEST)=TEMP
  226. DO 180 I=1,N
  227. TEMP=SIM(I,NBEST)
  228. SIM(I,NBEST)=0.0
  229. SIM(I,NP)=SIM(I,NP)+TEMP
  230. TEMPA=0.0
  231. DO 170 K=1,N
  232. SIM(I,K)=SIM(I,K)-TEMP
  233. 170 TEMPA=TEMPA-SIMI(K,I)
  234. 180 SIMI(NBEST,I)=TEMPA
  235. END IF
  236. C
  237. C Make an error return if SIGI is a poor approximation to the inverse of
  238. C the leading N by N submatrix of SIG.
  239. C
  240. ERROR=0.0
  241. DO 200 I=1,N
  242. DO 200 J=1,N
  243. TEMP=0.0
  244. IF (I .EQ. J) TEMP=TEMP-1.0
  245. DO 190 K=1,N
  246. 190 TEMP=TEMP+SIMI(I,K)*SIM(K,J)
  247. 200 ERROR=AMAX1(ERROR,ABS(TEMP))
  248. IF (ERROR .GT. 0.1) THEN
  249. IF (IPRINT .GE. 1) PRINT 210
  250. 210 FORMAT (/3X,'Return from subroutine COBYLA because ',
  251. 1 'rounding errors are becoming damaging.')
  252. GOTO 600
  253. END IF
  254. C
  255. C Calculate the coefficients of the linear approximations to the objective
  256. C and constraint functions, placing minus the objective function gradient
  257. C after the constraint gradients in the array A. The vector W is used for
  258. C working space.
  259. C
  260. DO 240 K=1,MP
  261. CON(K)=-DATMAT(K,NP)
  262. DO 220 J=1,N
  263. 220 W(J)=DATMAT(K,J)+CON(K)
  264. DO 240 I=1,N
  265. TEMP=0.0
  266. DO 230 J=1,N
  267. 230 TEMP=TEMP+W(J)*SIMI(J,I)
  268. IF (K .EQ. MP) TEMP=-TEMP
  269. 240 A(I,K)=TEMP
  270. C
  271. C Calculate the values of sigma and eta, and set IFLAG=0 if the current
  272. C simplex is not acceptable.
  273. C
  274. IFLAG=1
  275. PARSIG=ALPHA*RHO
  276. PARETA=BETA*RHO
  277. DO 260 J=1,N
  278. WSIG=0.0
  279. WETA=0.0
  280. DO 250 I=1,N
  281. WSIG=WSIG+SIMI(J,I)**2
  282. 250 WETA=WETA+SIM(I,J)**2
  283. VSIG(J)=1.0/SQRT(WSIG)
  284. VETA(J)=SQRT(WETA)
  285. IF (VSIG(J) .LT. PARSIG .OR. VETA(J) .GT. PARETA) IFLAG=0
  286. 260 CONTINUE
  287. C
  288. C If a new vertex is needed to improve acceptability, then decide which
  289. C vertex to drop from the simplex.
  290. C
  291. IF (IBRNCH .EQ. 1 .OR. IFLAG .EQ. 1) GOTO 370
  292. JDROP=0
  293. TEMP=PARETA
  294. DO 270 J=1,N
  295. IF (VETA(J) .GT. TEMP) THEN
  296. JDROP=J
  297. TEMP=VETA(J)
  298. END IF
  299. 270 CONTINUE
  300. IF (JDROP .EQ. 0) THEN
  301. DO 280 J=1,N
  302. IF (VSIG(J) .LT. TEMP) THEN
  303. JDROP=J
  304. TEMP=VSIG(J)
  305. END IF
  306. 280 CONTINUE
  307. END IF
  308. C
  309. C Calculate the step to the new vertex and its sign.
  310. C
  311. TEMP=GAMMA*RHO*VSIG(JDROP)
  312. DO 290 I=1,N
  313. 290 DX(I)=TEMP*SIMI(JDROP,I)
  314. CVMAXP=0.0
  315. CVMAXM=0.0
  316. DO 310 K=1,MP
  317. SUM=0.0
  318. DO 300 I=1,N
  319. 300 SUM=SUM+A(I,K)*DX(I)
  320. IF (K .LT. MP) THEN
  321. TEMP=DATMAT(K,NP)
  322. CVMAXP=AMAX1(CVMAXP,-SUM-TEMP)
  323. CVMAXM=AMAX1(CVMAXM,SUM-TEMP)
  324. END IF
  325. 310 CONTINUE
  326. DXSIGN=1.0
  327. IF (PARMU*(CVMAXP-CVMAXM) .GT. SUM+SUM) DXSIGN=-1.0
  328. C
  329. C Update the elements of SIM and SIMI, and set the next X.
  330. C
  331. TEMP=0.0
  332. DO 320 I=1,N
  333. DX(I)=DXSIGN*DX(I)
  334. SIM(I,JDROP)=DX(I)
  335. 320 TEMP=TEMP+SIMI(JDROP,I)*DX(I)
  336. DO 330 I=1,N
  337. 330 SIMI(JDROP,I)=SIMI(JDROP,I)/TEMP
  338. DO 360 J=1,N
  339. IF (J .NE. JDROP) THEN
  340. TEMP=0.0
  341. DO 340 I=1,N
  342. 340 TEMP=TEMP+SIMI(J,I)*DX(I)
  343. DO 350 I=1,N
  344. 350 SIMI(J,I)=SIMI(J,I)-TEMP*SIMI(JDROP,I)
  345. END IF
  346. 360 X(J)=SIM(J,NP)+DX(J)
  347. GOTO 40
  348. C
  349. C Calculate DX=x(*)-x(0). Branch if the length of DX is less than 0.5*RHO.
  350. C
  351. 370 IZ=1
  352. IZDOTA=IZ+N*N
  353. IVMC=IZDOTA+N
  354. ISDIRN=IVMC+MP
  355. IDXNEW=ISDIRN+N
  356. IVMD=IDXNEW+N
  357. CALL TRSTLP (N,M,A,CON,RHO,DX,IFULL,IACT,W(IZ),W(IZDOTA),
  358. 1 W(IVMC),W(ISDIRN),W(IDXNEW),W(IVMD))
  359. IF (IFULL .EQ. 0) THEN
  360. TEMP=0.0
  361. DO 380 I=1,N
  362. 380 TEMP=TEMP+DX(I)**2
  363. IF (TEMP .LT. 0.25*RHO*RHO) THEN
  364. IBRNCH=1
  365. GOTO 550
  366. END IF
  367. END IF
  368. C
  369. C Predict the change to F and the new maximum constraint violation if the
  370. C variables are altered from x(0) to x(0)+DX.
  371. C
  372. RESNEW=0.0
  373. CON(MP)=0.0
  374. DO 400 K=1,MP
  375. SUM=CON(K)
  376. DO 390 I=1,N
  377. 390 SUM=SUM-A(I,K)*DX(I)
  378. IF (K .LT. MP) RESNEW=AMAX1(RESNEW,SUM)
  379. 400 CONTINUE
  380. C
  381. C Increase PARMU if necessary and branch back if this change alters the
  382. C optimal vertex. Otherwise PREREM and PREREC will be set to the predicted
  383. C reductions in the merit function and the maximum constraint violation
  384. C respectively.
  385. C
  386. BARMU=0.0
  387. PREREC=DATMAT(MPP,NP)-RESNEW
  388. IF (PREREC .GT. 0.0) BARMU=SUM/PREREC
  389. IF (PARMU .LT. 1.5*BARMU) THEN
  390. PARMU=2.0*BARMU
  391. IF (IPRINT .GE. 2) PRINT 410, PARMU
  392. 410 FORMAT (/3X,'Increase in PARMU to',1PE13.6)
  393. PHI=DATMAT(MP,NP)+PARMU*DATMAT(MPP,NP)
  394. DO 420 J=1,N
  395. TEMP=DATMAT(MP,J)+PARMU*DATMAT(MPP,J)
  396. IF (TEMP .LT. PHI) GOTO 140
  397. IF (TEMP .EQ. PHI .AND. PARMU .EQ. 0.0) THEN
  398. IF (DATMAT(MPP,J) .LT. DATMAT(MPP,NP)) GOTO 140
  399. END IF
  400. 420 CONTINUE
  401. END IF
  402. PREREM=PARMU*PREREC-SUM
  403. C
  404. C Calculate the constraint and objective functions at x(*). Then find the
  405. C actual reduction in the merit function.
  406. C
  407. DO 430 I=1,N
  408. 430 X(I)=SIM(I,NP)+DX(I)
  409. IBRNCH=1
  410. GOTO 40
  411. 440 VMOLD=DATMAT(MP,NP)+PARMU*DATMAT(MPP,NP)
  412. VMNEW=F+PARMU*RESMAX
  413. TRURED=VMOLD-VMNEW
  414. IF (PARMU .EQ. 0.0 .AND. F .EQ. DATMAT(MP,NP)) THEN
  415. PREREM=PREREC
  416. TRURED=DATMAT(MPP,NP)-RESMAX
  417. END IF
  418. C
  419. C Begin the operations that decide whether x(*) should replace one of the
  420. C vertices of the current simplex, the change being mandatory if TRURED is
  421. C positive. Firstly, JDROP is set to the index of the vertex that is to be
  422. C replaced.
  423. C
  424. RATIO=0.0
  425. IF (TRURED .LE. 0.0) RATIO=1.0
  426. JDROP=0
  427. DO 460 J=1,N
  428. TEMP=0.0
  429. DO 450 I=1,N
  430. 450 TEMP=TEMP+SIMI(J,I)*DX(I)
  431. TEMP=ABS(TEMP)
  432. IF (TEMP .GT. RATIO) THEN
  433. JDROP=J
  434. RATIO=TEMP
  435. END IF
  436. 460 SIGBAR(J)=TEMP*VSIG(J)
  437. C
  438. C Calculate the value of ell.
  439. C
  440. EDGMAX=DELTA*RHO
  441. L=0
  442. DO 480 J=1,N
  443. IF (SIGBAR(J) .GE. PARSIG .OR. SIGBAR(J) .GE. VSIG(J)) THEN
  444. TEMP=VETA(J)
  445. IF (TRURED .GT. 0.0) THEN
  446. TEMP=0.0
  447. DO 470 I=1,N
  448. 470 TEMP=TEMP+(DX(I)-SIM(I,J))**2
  449. TEMP=SQRT(TEMP)
  450. END IF
  451. IF (TEMP .GT. EDGMAX) THEN
  452. L=J
  453. EDGMAX=TEMP
  454. END IF
  455. END IF
  456. 480 CONTINUE
  457. IF (L .GT. 0) JDROP=L
  458. IF (JDROP .EQ. 0) GOTO 550
  459. C
  460. C Revise the simplex by updating the elements of SIM, SIMI and DATMAT.
  461. C
  462. TEMP=0.0
  463. DO 490 I=1,N
  464. SIM(I,JDROP)=DX(I)
  465. 490 TEMP=TEMP+SIMI(JDROP,I)*DX(I)
  466. DO 500 I=1,N
  467. 500 SIMI(JDROP,I)=SIMI(JDROP,I)/TEMP
  468. DO 530 J=1,N
  469. IF (J .NE. JDROP) THEN
  470. TEMP=0.0
  471. DO 510 I=1,N
  472. 510 TEMP=TEMP+SIMI(J,I)*DX(I)
  473. DO 520 I=1,N
  474. 520 SIMI(J,I)=SIMI(J,I)-TEMP*SIMI(JDROP,I)
  475. END IF
  476. 530 CONTINUE
  477. DO 540 K=1,MPP
  478. 540 DATMAT(K,JDROP)=CON(K)
  479. C
  480. C Branch back for further iterations with the current RHO.
  481. C
  482. IF (TRURED .GT. 0.0 .AND. TRURED .GE. 0.1*PREREM) GOTO 140
  483. 550 IF (IFLAG .EQ. 0) THEN
  484. IBRNCH=0
  485. GOTO 140
  486. END IF
  487. C
  488. C Otherwise reduce RHO if it is not at its least value and reset PARMU.
  489. C
  490. IF (RHO .GT. RHOEND) THEN
  491. RHO=0.5*RHO
  492. IF (RHO .LE. 1.5*RHOEND) RHO=RHOEND
  493. IF (PARMU .GT. 0.0) THEN
  494. DENOM=0.0
  495. DO 570 K=1,MP
  496. CMIN=DATMAT(K,NP)
  497. CMAX=CMIN
  498. DO 560 I=1,N
  499. CMIN=AMIN1(CMIN,DATMAT(K,I))
  500. 560 CMAX=AMAX1(CMAX,DATMAT(K,I))
  501. IF (K .LE. M .AND. CMIN .LT. 0.5*CMAX) THEN
  502. TEMP=AMAX1(CMAX,0.0)-CMIN
  503. IF (DENOM .LE. 0.0) THEN
  504. DENOM=TEMP
  505. ELSE
  506. DENOM=AMIN1(DENOM,TEMP)
  507. END IF
  508. END IF
  509. 570 CONTINUE
  510. IF (DENOM .EQ. 0.0) THEN
  511. PARMU=0.0
  512. ELSE IF (CMAX-CMIN .LT. PARMU*DENOM) THEN
  513. PARMU=(CMAX-CMIN)/DENOM
  514. END IF
  515. END IF
  516. IF (IPRINT .GE. 2) PRINT 580, RHO,PARMU
  517. 580 FORMAT (/3X,'Reduction in RHO to',1PE13.6,' and PARMU =',
  518. 1 1PE13.6)
  519. IF (IPRINT .EQ. 2) THEN
  520. PRINT 70, NFVALS,DATMAT(MP,NP),DATMAT(MPP,NP),
  521. 1 (SIM(I,NP),I=1,IPTEM)
  522. IF (IPTEM .LT. N) PRINT 80, (X(I),I=IPTEMP,N)
  523. END IF
  524. GOTO 140
  525. END IF
  526. C
  527. C Return the best calculated values of the variables.
  528. C
  529. IF (IPRINT .GE. 1) PRINT 590
  530. 590 FORMAT (/3X,'Normal return from subroutine COBYLA')
  531. IF (IFULL .EQ. 1) GOTO 620
  532. 600 DO 610 I=1,N
  533. 610 X(I)=SIM(I,NP)
  534. F=DATMAT(MP,NP)
  535. RESMAX=DATMAT(MPP,NP)
  536. 620 IF (IPRINT .GE. 1) THEN
  537. PRINT 70, NFVALS,F,RESMAX,(X(I),I=1,IPTEM)
  538. IF (IPTEM .LT. N) PRINT 80, (X(I),I=IPTEMP,N)
  539. END IF
  540. MAXFUN=NFVALS
  541. RETURN
  542. END
  543. C------------------------------------------------------------------------------
  544. SUBROUTINE TRSTLP (N,M,A,B,RHO,DX,IFULL,IACT,Z,ZDOTA,VMULTC,
  545. 1 SDIRN,DXNEW,VMULTD)
  546. DIMENSION A(N,*),B(*),DX(*),IACT(*),Z(N,*),ZDOTA(*),
  547. 1 VMULTC(*),SDIRN(*),DXNEW(*),VMULTD(*)
  548. C
  549. C This subroutine calculates an N-component vector DX by applying the
  550. C following two stages. In the first stage, DX is set to the shortest
  551. C vector that minimizes the greatest violation of the constraints
  552. C A(1,K)*DX(1)+A(2,K)*DX(2)+...+A(N,K)*DX(N) .GE. B(K), K=2,3,...,M,
  553. C subject to the Euclidean length of DX being at most RHO. If its length is
  554. C strictly less than RHO, then we use the resultant freedom in DX to
  555. C minimize the objective function
  556. C -A(1,M+1)*DX(1)-A(2,M+1)*DX(2)-...-A(N,M+1)*DX(N)
  557. C subject to no increase in any greatest constraint violation. This
  558. C notation allows the gradient of the objective function to be regarded as
  559. C the gradient of a constraint. Therefore the two stages are distinguished
  560. C by MCON .EQ. M and MCON .GT. M respectively. It is possible that a
  561. C degeneracy may prevent DX from attaining the target length RHO. Then the
  562. C value IFULL=0 would be set, but usually IFULL=1 on return.
  563. C
  564. C In general NACT is the number of constraints in the active set and
  565. C IACT(1),...,IACT(NACT) are their indices, while the remainder of IACT
  566. C contains a permutation of the remaining constraint indices. Further, Z is
  567. C an orthogonal matrix whose first NACT columns can be regarded as the
  568. C result of Gram-Schmidt applied to the active constraint gradients. For
  569. C J=1,2,...,NACT, the number ZDOTA(J) is the scalar product of the J-th
  570. C column of Z with the gradient of the J-th active constraint. DX is the
  571. C current vector of variables and here the residuals of the active
  572. C constraints should be zero. Further, the active constraints have
  573. C nonnegative Lagrange multipliers that are held at the beginning of
  574. C VMULTC. The remainder of this vector holds the residuals of the inactive
  575. C constraints at DX, the ordering of the components of VMULTC being in
  576. C agreement with the permutation of the indices of the constraints that is
  577. C in IACT. All these residuals are nonnegative, which is achieved by the
  578. C shift RESMAX that makes the least residual zero.
  579. C
  580. C Initialize Z and some other variables. The value of RESMAX will be
  581. C appropriate to DX=0, while ICON will be the index of a most violated
  582. C constraint if RESMAX is positive. Usually during the first stage the
  583. C vector SDIRN gives a search direction that reduces all the active
  584. C constraint violations by one simultaneously.
  585. C
  586. IFULL=1
  587. MCON=M
  588. NACT=0
  589. RESMAX=0.0
  590. DO 20 I=1,N
  591. DO 10 J=1,N
  592. 10 Z(I,J)=0.0
  593. Z(I,I)=1.0
  594. 20 DX(I)=0.0
  595. IF (M .GE. 1) THEN
  596. DO 30 K=1,M
  597. IF (B(K) .GT. RESMAX) THEN
  598. RESMAX=B(K)
  599. ICON=K
  600. END IF
  601. 30 CONTINUE
  602. DO 40 K=1,M
  603. IACT(K)=K
  604. 40 VMULTC(K)=RESMAX-B(K)
  605. END IF
  606. IF (RESMAX .EQ. 0.0) GOTO 480
  607. DO 50 I=1,N
  608. 50 SDIRN(I)=0.0
  609. C
  610. C End the current stage of the calculation if 3 consecutive iterations
  611. C have either failed to reduce the best calculated value of the objective
  612. C function or to increase the number of active constraints since the best
  613. C value was calculated. This strategy prevents cycling, but there is a
  614. C remote possibility that it will cause premature termination.
  615. C
  616. 60 OPTOLD=0.0
  617. ICOUNT=0
  618. 70 IF (MCON .EQ. M) THEN
  619. OPTNEW=RESMAX
  620. ELSE
  621. OPTNEW=0.0
  622. DO 80 I=1,N
  623. 80 OPTNEW=OPTNEW-DX(I)*A(I,MCON)
  624. END IF
  625. IF (ICOUNT .EQ. 0 .OR. OPTNEW .LT. OPTOLD) THEN
  626. OPTOLD=OPTNEW
  627. NACTX=NACT
  628. ICOUNT=3
  629. ELSE IF (NACT .GT. NACTX) THEN
  630. NACTX=NACT
  631. ICOUNT=3
  632. ELSE
  633. ICOUNT=ICOUNT-1
  634. IF (ICOUNT .EQ. 0) GOTO 490
  635. END IF
  636. C
  637. C If ICON exceeds NACT, then we add the constraint with index IACT(ICON) to
  638. C the active set. Apply Givens rotations so that the last N-NACT-1 columns
  639. C of Z are orthogonal to the gradient of the new constraint, a scalar
  640. C product being set to zero if its nonzero value could be due to computer
  641. C rounding errors. The array DXNEW is used for working space.
  642. C
  643. IF (ICON .LE. NACT) GOTO 260
  644. KK=IACT(ICON)
  645. DO 90 I=1,N
  646. 90 DXNEW(I)=A(I,KK)
  647. TOT=0.0
  648. K=N
  649. 100 IF (K .GT. NACT) THEN
  650. SP=0.0
  651. SPABS=0.0
  652. DO 110 I=1,N
  653. TEMP=Z(I,K)*DXNEW(I)
  654. SP=SP+TEMP
  655. 110 SPABS=SPABS+ABS(TEMP)
  656. ACCA=SPABS+0.1*ABS(SP)
  657. ACCB=SPABS+0.2*ABS(SP)
  658. IF (SPABS .GE. ACCA .OR. ACCA .GE. ACCB) SP=0.0
  659. IF (TOT .EQ. 0.0) THEN
  660. TOT=SP
  661. ELSE
  662. KP=K+1
  663. TEMP=SQRT(SP*SP+TOT*TOT)
  664. ALPHA=SP/TEMP
  665. BETA=TOT/TEMP
  666. TOT=TEMP
  667. DO 120 I=1,N
  668. TEMP=ALPHA*Z(I,K)+BETA*Z(I,KP)
  669. Z(I,KP)=ALPHA*Z(I,KP)-BETA*Z(I,K)
  670. 120 Z(I,K)=TEMP
  671. END IF
  672. K=K-1
  673. GOTO 100
  674. END IF
  675. C
  676. C Add the new constraint if this can be done without a deletion from the
  677. C active set.
  678. C
  679. IF (TOT .NE. 0.0) THEN
  680. NACT=NACT+1
  681. ZDOTA(NACT)=TOT
  682. VMULTC(ICON)=VMULTC(NACT)
  683. VMULTC(NACT)=0.0
  684. GOTO 210
  685. END IF
  686. C
  687. C The next instruction is reached if a deletion has to be made from the
  688. C active set in order to make room for the new active constraint, because
  689. C the new constraint gradient is a linear combination of the gradients of
  690. C the old active constraints. Set the elements of VMULTD to the multipliers
  691. C of the linear combination. Further, set IOUT to the index of the
  692. C constraint to be deleted, but branch if no suitable index can be found.
  693. C
  694. RATIO=-1.0
  695. K=NACT
  696. 130 ZDOTV=0.0
  697. ZDVABS=0.0
  698. DO 140 I=1,N
  699. TEMP=Z(I,K)*DXNEW(I)
  700. ZDOTV=ZDOTV+TEMP
  701. 140 ZDVABS=ZDVABS+ABS(TEMP)
  702. ACCA=ZDVABS+0.1*ABS(ZDOTV)
  703. ACCB=ZDVABS+0.2*ABS(ZDOTV)
  704. IF (ZDVABS .LT. ACCA .AND. ACCA .LT. ACCB) THEN
  705. TEMP=ZDOTV/ZDOTA(K)
  706. IF (TEMP .GT. 0.0 .AND. IACT(K) .LE. M) THEN
  707. TEMPA=VMULTC(K)/TEMP
  708. IF (RATIO .LT. 0.0 .OR. TEMPA .LT. RATIO) THEN
  709. RATIO=TEMPA
  710. IOUT=K
  711. END IF
  712. END IF
  713. IF (K .GE. 2) THEN
  714. KW=IACT(K)
  715. DO 150 I=1,N
  716. 150 DXNEW(I)=DXNEW(I)-TEMP*A(I,KW)
  717. END IF
  718. VMULTD(K)=TEMP
  719. ELSE
  720. VMULTD(K)=0.0
  721. END IF
  722. K=K-1
  723. IF (K .GT. 0) GOTO 130
  724. IF (RATIO .LT. 0.0) GOTO 490
  725. C
  726. C Revise the Lagrange multipliers and reorder the active constraints so
  727. C that the one to be replaced is at the end of the list. Also calculate the
  728. C new value of ZDOTA(NACT) and branch if it is not acceptable.
  729. C
  730. DO 160 K=1,NACT
  731. 160 VMULTC(K)=AMAX1(0.0,VMULTC(K)-RATIO*VMULTD(K))
  732. IF (ICON .LT. NACT) THEN
  733. ISAVE=IACT(ICON)
  734. VSAVE=VMULTC(ICON)
  735. K=ICON
  736. 170 KP=K+1
  737. KW=IACT(KP)
  738. SP=0.0
  739. DO 180 I=1,N
  740. 180 SP=SP+Z(I,K)*A(I,KW)
  741. TEMP=SQRT(SP*SP+ZDOTA(KP)**2)
  742. ALPHA=ZDOTA(KP)/TEMP
  743. BETA=SP/TEMP
  744. ZDOTA(KP)=ALPHA*ZDOTA(K)
  745. ZDOTA(K)=TEMP
  746. DO 190 I=1,N
  747. TEMP=ALPHA*Z(I,KP)+BETA*Z(I,K)
  748. Z(I,KP)=ALPHA*Z(I,K)-BETA*Z(I,KP)
  749. 190 Z(I,K)=TEMP
  750. IACT(K)=KW
  751. VMULTC(K)=VMULTC(KP)
  752. K=KP
  753. IF (K .LT. NACT) GOTO 170
  754. IACT(K)=ISAVE
  755. VMULTC(K)=VSAVE
  756. END IF
  757. TEMP=0.0
  758. DO 200 I=1,N
  759. 200 TEMP=TEMP+Z(I,NACT)*A(I,KK)
  760. IF (TEMP .EQ. 0.0) GOTO 490
  761. ZDOTA(NACT)=TEMP
  762. VMULTC(ICON)=0.0
  763. VMULTC(NACT)=RATIO
  764. C
  765. C Update IACT and ensure that the objective function continues to be
  766. C treated as the last active constraint when MCON>M.
  767. C
  768. 210 IACT(ICON)=IACT(NACT)
  769. IACT(NACT)=KK
  770. IF (MCON .GT. M .AND. KK .NE. MCON) THEN
  771. K=NACT-1
  772. SP=0.0
  773. DO 220 I=1,N
  774. 220 SP=SP+Z(I,K)*A(I,KK)
  775. TEMP=SQRT(SP*SP+ZDOTA(NACT)**2)
  776. ALPHA=ZDOTA(NACT)/TEMP
  777. BETA=SP/TEMP
  778. ZDOTA(NACT)=ALPHA*ZDOTA(K)
  779. ZDOTA(K)=TEMP
  780. DO 230 I=1,N
  781. TEMP=ALPHA*Z(I,NACT)+BETA*Z(I,K)
  782. Z(I,NACT)=ALPHA*Z(I,K)-BETA*Z(I,NACT)
  783. 230 Z(I,K)=TEMP
  784. IACT(NACT)=IACT(K)
  785. IACT(K)=KK
  786. TEMP=VMULTC(K)
  787. VMULTC(K)=VMULTC(NACT)
  788. VMULTC(NACT)=TEMP
  789. END IF
  790. C
  791. C If stage one is in progress, then set SDIRN to the direction of the next
  792. C change to the current vector of variables.
  793. C
  794. IF (MCON .GT. M) GOTO 320
  795. KK=IACT(NACT)
  796. TEMP=0.0
  797. DO 240 I=1,N
  798. 240 TEMP=TEMP+SDIRN(I)*A(I,KK)
  799. TEMP=TEMP-1.0
  800. TEMP=TEMP/ZDOTA(NACT)
  801. DO 250 I=1,N
  802. 250 SDIRN(I)=SDIRN(I)-TEMP*Z(I,NACT)
  803. GOTO 340
  804. C
  805. C Delete the constraint that has the index IACT(ICON) from the active set.
  806. C
  807. 260 IF (ICON .LT. NACT) THEN
  808. ISAVE=IACT(ICON)
  809. VSAVE=VMULTC(ICON)
  810. K=ICON
  811. 270 KP=K+1
  812. KK=IACT(KP)
  813. SP=0.0
  814. DO 280 I=1,N
  815. 280 SP=SP+Z(I,K)*A(I,KK)
  816. TEMP=SQRT(SP*SP+ZDOTA(KP)**2)
  817. ALPHA=ZDOTA(KP)/TEMP
  818. BETA=SP/TEMP
  819. ZDOTA(KP)=ALPHA*ZDOTA(K)
  820. ZDOTA(K)=TEMP
  821. DO 290 I=1,N
  822. TEMP=ALPHA*Z(I,KP)+BETA*Z(I,K)
  823. Z(I,KP)=ALPHA*Z(I,K)-BETA*Z(I,KP)
  824. 290 Z(I,K)=TEMP
  825. IACT(K)=KK
  826. VMULTC(K)=VMULTC(KP)
  827. K=KP
  828. IF (K .LT. NACT) GOTO 270
  829. IACT(K)=ISAVE
  830. VMULTC(K)=VSAVE
  831. END IF
  832. NACT=NACT-1
  833. C
  834. C If stage one is in progress, then set SDIRN to the direction of the next
  835. C change to the current vector of variables.
  836. C
  837. IF (MCON .GT. M) GOTO 320
  838. TEMP=0.0
  839. DO 300 I=1,N
  840. 300 TEMP=TEMP+SDIRN(I)*Z(I,NACT+1)
  841. DO 310 I=1,N
  842. 310 SDIRN(I)=SDIRN(I)-TEMP*Z(I,NACT+1)
  843. GO TO 340
  844. C
  845. C Pick the next search direction of stage two.
  846. C
  847. 320 TEMP=1.0/ZDOTA(NACT)
  848. DO 330 I=1,N
  849. 330 SDIRN(I)=TEMP*Z(I,NACT)
  850. C
  851. C Calculate the step to the boundary of the trust region or take the step
  852. C that reduces RESMAX to zero. The two statements below that include the
  853. C factor 1.0E-6 prevent some harmless underflows that occurred in a test
  854. C calculation. Further, we skip the step if it could be zero within a
  855. C reasonable tolerance for computer rounding errors.
  856. C
  857. 340 DD=RHO*RHO
  858. SD=0.0
  859. SS=0.0
  860. DO 350 I=1,N
  861. IF (ABS(DX(I)) .GE. 1.0E-6*RHO) DD=DD-DX(I)**2
  862. SD=SD+DX(I)*SDIRN(I)
  863. 350 SS=SS+SDIRN(I)**2
  864. IF (DD .LE. 0.0) GOTO 490
  865. TEMP=SQRT(SS*DD)
  866. IF (ABS(SD) .GE. 1.0E-6*TEMP) TEMP=SQRT(SS*DD+SD*SD)
  867. STPFUL=DD/(TEMP+SD)
  868. STEP=STPFUL
  869. IF (MCON .EQ. M) THEN
  870. ACCA=STEP+0.1*RESMAX
  871. ACCB=STEP+0.2*RESMAX
  872. IF (STEP .GE. ACCA .OR. ACCA .GE. ACCB) GOTO 480
  873. STEP=AMIN1(STEP,RESMAX)
  874. END IF
  875. C
  876. C Set DXNEW to the new variables if STEP is the steplength, and reduce
  877. C RESMAX to the corresponding maximum residual if stage one is being done.
  878. C Because DXNEW will be changed during the calculation of some Lagrange
  879. C multipliers, it will be restored to the following value later.
  880. C
  881. DO 360 I=1,N
  882. 360 DXNEW(I)=DX(I)+STEP*SDIRN(I)
  883. IF (MCON .EQ. M) THEN
  884. RESOLD=RESMAX
  885. RESMAX=0.0
  886. DO 380 K=1,NACT
  887. KK=IACT(K)
  888. TEMP=B(KK)
  889. DO 370 I=1,N
  890. 370 TEMP=TEMP-A(I,KK)*DXNEW(I)
  891. RESMAX=AMAX1(RESMAX,TEMP)
  892. 380 CONTINUE
  893. END IF
  894. C
  895. C Set VMULTD to the VMULTC vector that would occur if DX became DXNEW. A
  896. C device is included to force VMULTD(K)=0.0 if deviations from this value
  897. C can be attributed to computer rounding errors. First calculate the new
  898. C Lagrange multipliers.
  899. C
  900. K=NACT
  901. 390 ZDOTW=0.0
  902. ZDWABS=0.0
  903. DO 400 I=1,N
  904. TEMP=Z(I,K)*DXNEW(I)
  905. ZDOTW=ZDOTW+TEMP
  906. 400 ZDWABS=ZDWABS+ABS(TEMP)
  907. ACCA=ZDWABS+0.1*ABS(ZDOTW)
  908. ACCB=ZDWABS+0.2*ABS(ZDOTW)
  909. IF (ZDWABS .GE. ACCA .OR. ACCA .GE. ACCB) ZDOTW=0.0
  910. VMULTD(K)=ZDOTW/ZDOTA(K)
  911. IF (K .GE. 2) THEN
  912. KK=IACT(K)
  913. DO 410 I=1,N
  914. 410 DXNEW(I)=DXNEW(I)-VMULTD(K)*A(I,KK)
  915. K=K-1
  916. GOTO 390
  917. END IF
  918. IF (MCON .GT. M) VMULTD(NACT)=AMAX1(0.0,VMULTD(NACT))
  919. C
  920. C Complete VMULTC by finding the new constraint residuals.
  921. C
  922. DO 420 I=1,N
  923. 420 DXNEW(I)=DX(I)+STEP*SDIRN(I)
  924. IF (MCON .GT. NACT) THEN
  925. KL=NACT+1
  926. DO 440 K=KL,MCON
  927. KK=IACT(K)
  928. SUM=RESMAX-B(KK)
  929. SUMABS=RESMAX+ABS(B(KK))
  930. DO 430 I=1,N
  931. TEMP=A(I,KK)*DXNEW(I)
  932. SUM=SUM+TEMP
  933. 430 SUMABS=SUMABS+ABS(TEMP)
  934. ACCA=SUMABS+0.1*ABS(SUM)
  935. ACCB=SUMABS+0.2*ABS(SUM)
  936. IF (SUMABS .GE. ACCA .OR. ACCA .GE. ACCB) SUM=0.0
  937. 440 VMULTD(K)=SUM
  938. END IF
  939. C
  940. C Calculate the fraction of the step from DX to DXNEW that will be taken.
  941. C
  942. RATIO=1.0
  943. ICON=0
  944. DO 450 K=1,MCON
  945. IF (VMULTD(K) .LT. 0.0) THEN
  946. TEMP=VMULTC(K)/(VMULTC(K)-VMULTD(K))
  947. IF (TEMP .LT. RATIO) THEN
  948. RATIO=TEMP
  949. ICON=K
  950. END IF
  951. END IF
  952. 450 CONTINUE
  953. C
  954. C Update DX, VMULTC and RESMAX.
  955. C
  956. TEMP=1.0-RATIO
  957. DO 460 I=1,N
  958. 460 DX(I)=TEMP*DX(I)+RATIO*DXNEW(I)
  959. DO 470 K=1,MCON
  960. 470 VMULTC(K)=AMAX1(0.0,TEMP*VMULTC(K)+RATIO*VMULTD(K))
  961. IF (MCON .EQ. M) RESMAX=RESOLD+RATIO*(RESMAX-RESOLD)
  962. C
  963. C If the full step is not acceptable then begin another iteration.
  964. C Otherwise switch to stage two or end the calculation.
  965. C
  966. IF (ICON .GT. 0) GOTO 70
  967. IF (STEP .EQ. STPFUL) GOTO 500
  968. 480 MCON=M+1
  969. ICON=MCON
  970. IACT(MCON)=MCON
  971. VMULTC(MCON)=0.0
  972. GOTO 60
  973. C
  974. C We employ any freedom that may be available to reduce the objective
  975. C function before returning a DX whose length is less than RHO.
  976. C
  977. 490 IF (MCON .EQ. M) GOTO 480
  978. IFULL=0
  979. 500 RETURN
  980. END
  981. C------------------------------------------------------------------------------
  982. C Main program of test problems in Report DAMTP 1992/NA5.
  983. C------------------------------------------------------------------------------
  984. COMMON NPROB
  985. DIMENSION X(10),XOPT(10),W(3000),IACT(51)
  986. DO 180 NPROB=1,10
  987. IF (NPROB .EQ. 1) THEN
  988. C
  989. C Minimization of a simple quadratic function of two variables.
  990. C
  991. PRINT 10
  992. 10 FORMAT (/7X,'Output from test problem 1 (Simple quadratic)')
  993. N=2
  994. M=0
  995. XOPT(1)=-1.0
  996. XOPT(2)=0.0
  997. ELSE IF (NPROB .EQ. 2) THEN
  998. C
  999. C Easy two dimensional minimization in unit circle.
  1000. C
  1001. PRINT 20
  1002. 20 FORMAT (/7X,'Output from test problem 2 (2D unit circle ',
  1003. 1 'calculation)')
  1004. N=2
  1005. M=1
  1006. XOPT(1)=SQRT(0.5)
  1007. XOPT(2)=-XOPT(1)
  1008. ELSE IF (NPROB .EQ. 3) THEN
  1009. C
  1010. C Easy three dimensional minimization in ellipsoid.
  1011. C
  1012. PRINT 30
  1013. 30 FORMAT (/7X,'Output from test problem 3 (3D ellipsoid ',
  1014. 1 'calculation)')
  1015. N=3
  1016. M=1
  1017. XOPT(1)=1.0/SQRT(3.0)
  1018. XOPT(2)=1.0/SQRT(6.0)
  1019. XOPT(3)=-1.0/3.0
  1020. ELSE IF (NPROB .EQ. 4) THEN
  1021. C
  1022. C Weak version of Rosenbrock's problem.
  1023. C
  1024. PRINT 40
  1025. 40 FORMAT (/7X,'Output from test problem 4 (Weak Rosenbrock)')
  1026. N=2
  1027. M=0
  1028. XOPT(1)=-1.0
  1029. XOPT(2)=1.0
  1030. ELSE IF (NPROB .EQ. 5) THEN
  1031. C
  1032. C Intermediate version of Rosenbrock's problem.
  1033. C
  1034. PRINT 50
  1035. 50 FORMAT (/7X,'Output from test problem 5 (Intermediate ',
  1036. 1 'Rosenbrock)')
  1037. N=2
  1038. M=0
  1039. XOPT(1)=-1.0
  1040. XOPT(2)=1.0
  1041. ELSE IF (NPROB .EQ. 6) THEN
  1042. C
  1043. C This problem is taken from Fletcher's book Practical Methods of
  1044. C Optimization and has the equation number (9.1.15).
  1045. C
  1046. PRINT 60
  1047. 60 FORMAT (/7X,'Output from test problem 6 (Equation ',
  1048. 1 '(9.1.15) in Fletcher)')
  1049. N=2
  1050. M=2
  1051. XOPT(1)=SQRT(0.5)
  1052. XOPT(2)=XOPT(1)
  1053. ELSE IF (NPROB .EQ. 7) THEN
  1054. C
  1055. C This problem is taken from Fletcher's book Practical Methods of
  1056. C Optimization and has the equation number (14.4.2).
  1057. C
  1058. PRINT 70
  1059. 70 FORMAT (/7X,'Output from test problem 7 (Equation ',
  1060. 1 '(14.4.2) in Fletcher)')
  1061. N=3
  1062. M=3
  1063. XOPT(1)=0.0
  1064. XOPT(2)=-3.0
  1065. XOPT(3)=-3.0
  1066. ELSE IF (NPROB .EQ. 8) THEN
  1067. C
  1068. C This problem is taken from page 66 of Hock and Schittkowski's book Test
  1069. C Examples for Nonlinear Programming Codes. It is their test problem Number
  1070. C 43, and has the name Rosen-Suzuki.
  1071. C
  1072. PRINT 80
  1073. 80 FORMAT (/7X,'Output from test problem 8 (Rosen-Suzuki)')
  1074. N=4
  1075. M=3
  1076. XOPT(1)=0.0
  1077. XOPT(2)=1.0
  1078. XOPT(3)=2.0
  1079. XOPT(4)=-1.0
  1080. ELSE IF (NPROB .EQ. 9) THEN
  1081. C
  1082. C This problem is taken from page 111 of Hock and Schittkowski's
  1083. C book Test Examples for Nonlinear Programming Codes. It is their
  1084. C test problem Number 100.
  1085. C
  1086. PRINT 90
  1087. 90 FORMAT (/7X,'Output from test problem 9 (Hock and ',
  1088. 1 'Schittkowski 100)')
  1089. N=7
  1090. M=4
  1091. XOPT(1)=2.330499
  1092. XOPT(2)=1.951372
  1093. XOPT(3)=-0.4775414
  1094. XOPT(4)=4.365726
  1095. XOPT(5)=-0.624487
  1096. XOPT(6)=1.038131
  1097. XOPT(7)=1.594227
  1098. ELSE IF (NPROB .EQ. 10) THEN
  1099. C
  1100. C This problem is taken from page 415 of Luenberger's book Applied
  1101. C Nonlinear Programming. It is to maximize the area of a hexagon of
  1102. C unit diameter.
  1103. C
  1104. PRINT 100
  1105. 100 FORMAT (/7X,'Output from test problem 10 (Hexagon area)')
  1106. N=9
  1107. M=14
  1108. END IF
  1109. DO 160 ICASE=1,2
  1110. DO 120 I=1,N
  1111. 120 X(I)=1.0
  1112. RHOBEG=0.5
  1113. RHOEND=0.001
  1114. IF (ICASE .EQ. 2) RHOEND=0.0001
  1115. IPRINT=1
  1116. MAXFUN=2000
  1117. CALL COBYLA (N,M,X,RHOBEG,RHOEND,IPRINT,MAXFUN,W,IACT)
  1118. IF (NPROB .EQ. 10) THEN
  1119. TEMPA=X(1)+X(3)+X(5)+X(7)
  1120. TEMPB=X(2)+X(4)+X(6)+X(8)
  1121. TEMPC=0.5/SQRT(TEMPA*TEMPA+TEMPB*TEMPB)
  1122. TEMPD=TEMPC*SQRT(3.0)
  1123. XOPT(1)=TEMPD*TEMPA+TEMPC*TEMPB
  1124. XOPT(2)=TEMPD*TEMPB-TEMPC*TEMPA
  1125. XOPT(3)=TEMPD*TEMPA-TEMPC*TEMPB
  1126. XOPT(4)=TEMPD*TEMPB+TEMPC*TEMPA
  1127. DO 130 I=1,4
  1128. 130 XOPT(I+4)=XOPT(I)
  1129. END IF
  1130. TEMP=0.0
  1131. DO 140 I=1,N
  1132. 140 TEMP=TEMP+(X(I)-XOPT(I))**2
  1133. PRINT 150, SQRT(TEMP)
  1134. 150 FORMAT (/5X,'Least squares error in variables =',1PE16.6)
  1135. 160 CONTINUE
  1136. PRINT 170
  1137. 170 FORMAT (2X,'----------------------------------------------',
  1138. 1 '--------------------')
  1139. 180 CONTINUE
  1140. STOP
  1141. END
  1142. C------------------------------------------------------------------------------
  1143. SUBROUTINE CALCFC (N,M,X,F,CON)
  1144. COMMON NPROB
  1145. DIMENSION X(*),CON(*)
  1146. IF (NPROB .EQ. 1) THEN
  1147. C
  1148. C Test problem 1 (Simple quadratic)
  1149. C
  1150. F=10.0*(X(1)+1.0)**2+X(2)**2
  1151. ELSE IF (NPROB .EQ. 2) THEN
  1152. C
  1153. C Test problem 2 (2D unit circle calculation)
  1154. C
  1155. F=X(1)*X(2)
  1156. CON(1)=1.0-X(1)**2-X(2)**2
  1157. ELSE IF (NPROB .EQ. 3) THEN
  1158. C
  1159. C Test problem 3 (3D ellipsoid calculation)
  1160. C
  1161. F=X(1)*X(2)*X(3)
  1162. CON(1)=1.0-X(1)**2-2.0*X(2)**2-3.0*X(3)**2
  1163. ELSE IF (NPROB .EQ. 4) THEN
  1164. C
  1165. C Test problem 4 (Weak Rosenbrock)
  1166. C
  1167. F=(X(1)**2-X(2))**2+(1.0+X(1))**2
  1168. ELSE IF (NPROB .EQ. 5) THEN
  1169. C
  1170. C Test problem 5 (Intermediate Rosenbrock)
  1171. C
  1172. F=10.0*(X(1)**2-X(2))**2+(1.0+X(1))**2
  1173. ELSE IF (NPROB .EQ. 6) THEN
  1174. C
  1175. C Test problem 6 (Equation (9.1.15) in Fletcher's book)
  1176. C
  1177. F=-X(1)-X(2)
  1178. CON(1)=X(2)-X(1)**2
  1179. CON(2)=1.0-X(1)**2-X(2)**2
  1180. ELSE IF (NPROB .EQ. 7) THEN
  1181. C
  1182. C Test problem 7 (Equation (14.4.2) in Fletcher's book)
  1183. C
  1184. F=X(3)
  1185. CON(1)=5.0*X(1)-X(2)+X(3)
  1186. CON(2)=X(3)-X(1)**2-X(2)**2-4.0*X(2)
  1187. CON(3)=X(3)-5.0*X(1)-X(2)
  1188. ELSE IF (NPROB .EQ. 8) THEN
  1189. C
  1190. C Test problem 8 (Rosen-Suzuki)
  1191. C
  1192. F=X(1)**2+X(2)**2+2.0*X(3)**2+X(4)**2-5.0*X(1)-5.0*X(2)
  1193. 1 -21.0*X(3)+7.0*X(4)
  1194. CON(1)=8.0-X(1)**2-X(2)**2-X(3)**2-X(4)**2-X(1)+X(2)
  1195. 1 -X(3)+X(4)
  1196. CON(2)=10.0-X(1)**2-2.0*X(2)**2-X(3)**2-2.0*X(4)**2+X(1)+X(4)
  1197. CON(3)=5.0-2.0*X(1)**2-X(2)**2-X(3)**2-2.0*X(1)+X(2)+X(4)
  1198. ELSE IF (NPROB .EQ. 9) THEN
  1199. C
  1200. C Test problem 9 (Hock and Schittkowski 100)
  1201. C
  1202. F=(X(1)-10.0)**2+5.0*(X(2)-12.0)**2+X(3)**4+3.0*(X(4)-11.0)**2
  1203. 1 +10.0*X(5)**6+7.0*X(6)**2+X(7)**4-4.0*X(6)*X(7)-10.0*X(6)
  1204. 2 -8.0*X(7)
  1205. CON(1)=127.0-2.0*X(1)**2-3.0*X(2)**4-X(3)-4.0*X(4)**2-5.0*X(5)
  1206. CON(2)=282.0-7.0*X(1)-3.0*X(2)-10.0*X(3)**2-X(4)+X(5)
  1207. CON(3)=196.0-23.0*X(1)-X(2)**2-6.0*X(6)**2+8.0*X(7)
  1208. CON(4)=-4.0*X(1)**2-X(2)**2+3.0*X(1)*X(2)-2.0*X(3)**2-5.0*X(6)
  1209. 1 +11.0*X(7)
  1210. ELSE IF (NPROB .EQ. 10) THEN
  1211. C
  1212. C Test problem 10 (Hexagon area)
  1213. C
  1214. F=-0.5*(X(1)*X(4)-X(2)*X(3)+X(3)*X(9)-X(5)*X(9)+X(5)*X(8)
  1215. 1 -X(6)*X(7))
  1216. CON(1)=1.0-X(3)**2-X(4)**2
  1217. CON(2)=1.0-X(9)**2
  1218. CON(3)=1.0-X(5)**2-X(6)**2
  1219. CON(4)=1.0-X(1)**2-(X(2)-X(9))**2
  1220. CON(5)=1.0-(X(1)-X(5))**2-(X(2)-X(6))**2
  1221. CON(6)=1.0-(X(1)-X(7))**2-(X(2)-X(8))**2
  1222. CON(7)=1.0-(X(3)-X(5))**2-(X(4)-X(6))**2
  1223. CON(8)=1.0-(X(3)-X(7))**2-(X(4)-X(8))**2
  1224. CON(9)=1.0-X(7)**2-(X(8)-X(9))**2
  1225. CON(10)=X(1)*X(4)-X(2)*X(3)
  1226. CON(11)=X(3)*X(9)
  1227. CON(12)=-X(5)*X(9)
  1228. CON(13)=X(5)*X(8)-X(6)*X(7)
  1229. CON(14)=X(9)
  1230. END IF
  1231. RETURN
  1232. END
  1233. -------------------------------------------------------------------------------
  1234. Output from test problem 1 (Simple quadratic)
  1235. Normal return from subroutine COBYLA
  1236. NFVALS = 37 F = 1.809750E-05 MAXCV = 0.000000E+00
  1237. X =-1.000879E+00 3.220609E-03
  1238. Least squares error in variables = 3.338389E-03
  1239. Normal return from subroutine COBYLA
  1240. NFVALS = 65 F = 1.153291E-07 MAXCV = 0.000000E+00
  1241. X =-9.999341E-01 2.682342E-04
  1242. Least squares error in variables = 2.762020E-04
  1243. ------------------------------------------------------------------
  1244. Output from test problem 2 (2D unit circle calculation)
  1245. Normal return from subroutine COBYLA
  1246. NFVALS = 37 F =-4.999994E-01 MAXCV = 2.026558E-06
  1247. X = 7.062163E-01 -7.079976E-01
  1248. Least squares error in variables = 1.259601E-03
  1249. Normal return from subroutine COBYLA
  1250. NFVALS = 44 F =-5.000000E-01 MAXCV = 5.960464E-08
  1251. X = 7.071500E-01 -7.070636E-01
  1252. Least squares error in variables = 6.107080E-05
  1253. ------------------------------------------------------------------
  1254. Output from test problem 3 (3D ellipsoid calculation)
  1255. Normal return from subroutine COBYLA
  1256. NFVALS = 52 F =-7.856688E-02 MAXCV = 6.288290E-06
  1257. X = 5.780203E-01 4.069204E-01 -3.340311E-01
  1258. Least squares error in variables = 1.642899E-03
  1259. Normal return from subroutine COBYLA
  1260. NFVALS = 65 F =-7.856742E-02 MAXCV = 8.940697E-08
  1261. X = 5.773363E-01 4.082997E-01 -3.332995E-01
  1262. Least squares error in variables = 6.312904E-05
  1263. ------------------------------------------------------------------
  1264. Output from test problem 4 (Weak Rosenbrock)
  1265. Normal return from subroutine COBYLA
  1266. NFVALS = 100 F = 3.125441E-05 MAXCV = 0.000000E+00
  1267. X =-9.958720E-01 9.879909E-01
  1268. Least squares error in variables = 1.269875E-02
  1269. Normal return from subroutine COBYLA
  1270. NFVALS = 173 F = 6.409362E-07 MAXCV = 0.000000E+00
  1271. X =-9.994782E-01 9.983495E-01
  1272. Least squares error in variables = 1.730967E-03
  1273. ------------------------------------------------------------------
  1274. Output from test problem 5 (Intermediate Rosenbrock)
  1275. Normal return from subroutine COBYLA
  1276. NFVALS = 347 F = 4.008353E-03 MAXCV = 0.000000E+00
  1277. X =-9.366965E-01 8.777190E-01
  1278. Least squares error in variables = 1.376952E-01
  1279. Normal return from subroutine COBYLA
  1280. NFVALS = 698 F = 9.516375E-05 MAXCV = 0.000000E+00
  1281. X =-9.904447E-01 9.803594E-01
  1282. Least squares error in variables = 2.184159E-02
  1283. ------------------------------------------------------------------
  1284. Output from test problem 6 (Equation (9.1.15) in Fletcher)
  1285. Normal return from subroutine COBYLA
  1286. NFVALS = 30 F =-1.414216E+00 MAXCV = 2.950430E-06
  1287. X = 7.071948E-01 7.070208E-01
  1288. Least squares error in variables = 1.230355E-04
  1289. Normal return from subroutine COBYLA
  1290. NFVALS = 40 F =-1.414214E+00 MAXCV = 0.000000E+00
  1291. X = 7.071791E-01 7.070344E-01
  1292. Least squares error in variables = 1.023325E-04
  1293. ------------------------------------------------------------------
  1294. Output from test problem 7 (Equation (14.4.2) in Fletcher)
  1295. Normal return from subroutine COBYLA
  1296. NFVALS = 28 F =-2.999881E+00 MAXCV = 0.000000E+00
  1297. X = 1.362514E-08 -2.999881E+00 -2.999881E+00
  1298. Least squares error in variables = 1.689246E-04
  1299. Normal return from subroutine COBYLA
  1300. NFVALS = 32 F =-3.000046E+00 MAXCV = 4.673004E-05
  1301. X = 1.207445E-08 -3.000000E+00 -3.000046E+00
  1302. Least squares error in variables = 4.649224E-05
  1303. ------------------------------------------------------------------
  1304. Output from test problem 8 (Rosen-Suzuki)
  1305. Normal return from subroutine COBYLA
  1306. NFVALS = 66 F =-4.400000E+01 MAXCV = 3.099442E-06
  1307. X =-6.020486E-04 9.995968E-01 2.000546E+00 -9.994259E-01
  1308. Least squares error in variables = 1.073541E-03
  1309. Normal return from subroutine COBYLA
  1310. NFVALS = 79 F =-4.400000E+01 MAXCV = 1.251698E-06
  1311. X =-2.246869E-04 9.996516E-01 2.000260E+00 -9.997578E-01
  1312. Least squares error in variables = 5.460466E-04
  1313. ------------------------------------------------------------------
  1314. Output from test problem 9 (Hock and Schittkowski 100)
  1315. Normal return from subroutine COBYLA
  1316. NFVALS = 237 F = 6.806309E+02 MAXCV = 0.000000E+00
  1317. X = 2.332463E+00 1.951341E+00 -4.587620E-01 4.364742E+00 -6.244753E-01
  1318. 1.038812E+00 1.593632E+00
  1319. Least squares error in variables = 1.892897E-02
  1320. Normal return from subroutine COBYLA
  1321. NFVALS = 248 F = 6.806310E+02 MAXCV = 1.907349E-05
  1322. X = 2.332446E+00 1.951307E+00 -4.577461E-01 4.364753E+00 -6.241184E-01
  1323. 1.039491E+00 1.593760E+00
  1324. Least squares error in variables = 1.996995E-02
  1325. ------------------------------------------------------------------
  1326. Output from test problem 10 (Hexagon area)
  1327. Normal return from subroutine COBYLA
  1328. NFVALS = 150 F =-8.660254E-01 MAXCV = 1.192093E-06
  1329. X = 6.605685E-01 7.507660E-01 -3.188329E-01 9.478114E-01 6.614124E-01
  1330. 7.500232E-01 -3.198982E-01 9.474520E-01 -6.671554E-11
  1331. Least squares error in variables = 1.124314E-03
  1332. Normal return from subroutine COBYLA
  1333. NFVALS = 173 F =-8.660254E-01 MAXCV = 3.352761E-07
  1334. X = 6.606672E-01 7.506790E-01 -3.195507E-01 9.475691E-01 6.608437E-01
  1335. 7.505235E-01 -3.197733E-01 9.474941E-01 -3.822812E-11
  1336. Least squares error in variables = 2.350494E-04
  1337. ------------------------------------------------------------------