📄 direct.f
字号:
C+-----------------------------------------------------------------------+C| Program : Direct.f |C| Last modified : 07-16-2001 |C| Written by : Joerg Gablonsky (jmgablon@unity.ncsu.edu) |C| North Carolina State University |C| Dept. of Mathematics |C| DIRECT is a method to solve problems of the form: |C| min f: Q --> R, |C| where f is the function to be minimized and Q is an n-dimensional |C| hyperrectangle given by the the following equation: |C| |C| Q={ x : l(i) <= x(i) <= u(i), i = 1,...,n }. |C| Note: This version of DIRECT can also handle hidden constraints. By |C| this we mean that the function may not be defined over the whole|C| hyperrectangle Q, but only over a subset, which is not given |C| analytically. |C| |C| We now give a brief outline of the algorithm: |C| |C| The algorithm starts with mapping the hyperrectangle Q to the |C| n-dimensional unit hypercube. DIRECT then samples the function at |C| the center of this hypercube and at 2n more points, 2 in each |C| coordinate direction. Uisng these function values, DIRECT then |C| divides the domain into hyperrectangles, each having exactly one of |C| the sampling points as its center. In each iteration, DIRECT chooses|C| some of the existing hyperrectangles to be further divided. |C| We provide two different strategies of how to decide which |C| hyperrectangles DIRECT divides and several different convergence |C| criteria. |C| |C| DIRECT was designed to solve problems where the function f is |C| Lipschitz continues. However, DIRECT has proven to be effective on |C| more complex problems than these. |C+-----------------------------------------------------------------------+ SUBROUTINE Direct(fcn, x, n, eps, maxf, maxT, fmin, l, u, + algmethod, Ierror, logfile, + fglobal, fglper, volper, sigmaper, + iidata, iisize, ddata, idsize, cdata, icsize)C+-----------------------------------------------------------------------+C| SUBROUTINE Direct |C| On entry |C| fcn -- The argument containing the name of the user-supplied |C| SUBROUTINE that returns values for the function to be |C| minimized. |C| n -- The dimension of the problem. |C| eps -- Exceeding value. If eps > 0, we use the same epsilon for |C| all iterations. If eps < 0, we use the update formula from |C| Jones: |C| eps = max(1.D-4*abs(fmin),epsfix), |C| where epsfix = abs(eps), the absolute value of eps which is|C| passed to the function. |C| maxf -- The maximum number of function evaluations. |C| maxT -- The maximum number of iterations. |C| Direct stops when either the maximum number of iterations |C| is reached or more than maxf function-evalutions were made.|C| l -- The lower bounds of the hyperbox. |C| u -- The upper bounds of the hyperbox. |C|algmethod-- Choose the method, that is either use the original method |C| as described by Jones et.al. (0) or use our modification(1)|C| logfile -- File-Handle for the logfile. DIRECT expects this file to be|C| opened and closed by the user outside of DIRECT. We moved |C| this to the outside so the user can add extra informations |C| to this file before and after the call to DIRECT. |C| fglobal -- Function value of the global optimum. If this value is not |C| known (that is, we solve a real problem, not a testproblem)|C| set this value to -1.D100 and fglper (see below) to 0.D0. |C| fglper -- Terminate the optimization when the percent error |C| 100(f_min - fglobal)/max(1,abs(fglobal)) < fglper. |C| volper -- Terminate the optimization when the volume of the |C| hyperrectangle S with f(c(S)) = fmin is less then volper |C| percent of the volume of the original hyperrectangle. |C|sigmaper -- Terminate the optimization when the measure of the |C| hyperrectangle S with f(c(S)) = fmin is less then sigmaper.|C| |C| User data that is passed through without being changed: |C| iidata -- Integer Array of user data. This array of size iisize is |C| passed to the function to be optimized and can be used to |C| transfer data to this function. The contents are not |C| changed by DIRECT. |C| iisize -- Size of array iidata. |C| ddata -- DOUBLE PRECISION array of user data. See iidata. |C| idsize -- Size of array ddata. |C| cdata -- Character array. See iidata. |C| icsize -- Size of array ddata. |C| |C| On return |C| |C| x -- The final point obtained in the optimization process. |C| X should be a good approximation to the global minimum |C| for the function within the hyper-box. |C| |C| fmin -- The value of the function at x. |C| Ierror -- Error flag. If Ierror is lower 0, an error has occured. The|C| values of Ierror mean |C| Fatal errors : |C| -1 u(i) <= l(i) for some i. |C| -2 maxf is too large. |C| -3 Initialization in DIRpreprc failed. |C| -4 Error in DIRSamplepoints, that is there was an error |C| in the creation of the sample points. |C| -5 Error in DIRSamplef, that is an error occured while |C| the function was sampled. |C| -6 Error in DIRDoubleInsert, that is an error occured |C| DIRECT tried to add all hyperrectangles with the same|C| size and function value at the center. Either |C| increase maxdiv or use our modification (Jones = 1). |C| Termination values : |C| 1 Number of function evaluations done is larger then |C| maxf. |C| 2 Number of iterations is equal to maxT. |C| 3 The best function value found is within fglper of |C| the (known) global optimum, that is |C| 100(fmin - fglobal/max(1,|fglobal|)) < fglper. |C| Note that this termination signal only occurs when |C| the global optimal value is known, that is, a test |C| function is optimized. |C| 4 The volume of the hyperrectangle with fmin at its |C| center is less than volper percent of the volume of |C| the original hyperrectangle. |C| 5 The measure of the hyperrectangle with fmin at its |C| center is less than sigmaper. |C| |C| SUBROUTINEs used : |C| |C| DIRheader, DIRInitSpecific, DIRInitList, DIRpreprc, DIRInit, DIRChoose|C| DIRDoubleInsert, DIRGet_I, DIRSamplepoints, DIRSamplef, DIRDivide |C| DIRInsertList, DIRreplaceInf, DIRWritehistbox, DIRsummary, Findareas |C| |C| Functions used : |C| |C| DIRgetMaxdeep, DIRgetlevel |C+-----------------------------------------------------------------------+ IMPLICIT NONEC+-----------------------------------------------------------------------+C| Parameters |C+-----------------------------------------------------------------------+C+-----------------------------------------------------------------------+C| The maximum of function evaluations allowed. |C| The maximum dept of the algorithm. |C| The maximum number of divisions allowed. |C| The maximal dimension of the problem. |C+-----------------------------------------------------------------------+ INTEGER maxfunc, maxdeep, maxdiv, MaxDim, mdeep PARAMETER (Maxfunc = 90000) PARAMETER (maxdeep = 600) PARAMETER (maxdiv = 3000) PARAMETER (MaxDim = 64)C+-----------------------------------------------------------------------+C| Global Variables. |C+-----------------------------------------------------------------------+ INTEGER JONES COMMON /directcontrol/ JONESC+-----------------------------------------------------------------------+C| EXTERNAL Variables. |C+-----------------------------------------------------------------------+ EXTERNAL fcn INTEGER n, maxf, maxT, algmethod, Ierror, logfile, dwrit DOUBLE PRECISION x(n),fmin,eps,l(n),u(n) DOUBLE PRECISION fglobal, fglper, volper, sigmaperC+-----------------------------------------------------------------------+C| User Variables. |C| These can be used to pass user defined data to the function to be |C| optimized. |C+-----------------------------------------------------------------------+ INTEGER iisize, idsize, icsize INTEGER iidata(iisize) DOUBLE PRECISION ddata(idsize) Character*40 cdata(icsize)C+-----------------------------------------------------------------------+C| Place to define, if needed, some application-specific variables. |C| Note: You should try to use the arrays defined above for this. |C+-----------------------------------------------------------------------+C+-----------------------------------------------------------------------+C| End of application - specific variables ! |C+-----------------------------------------------------------------------+C+-----------------------------------------------------------------------+C| Internal variables : |C| f -- values of functions. |C|divfactor-- Factor used for termination with known global minimum. |C| anchor -- anchors of lists with deepness i, -1 is anchor for list of |C| NaN - values. |C| S -- List of potentially optimal points. |C| point -- lists |C| free -- first free position |C| c -- midpoints of arrays |C| thirds -- Precalculated values of 1/3^i. |C| levels -- Length of intervals. |C| length -- Length of intervall (index) |C| t -- actual iteration |C| j -- loop-variable |C| actdeep -- the actual minimal interval-length index |C| Minpos -- position of the actual minimum |C| file -- The filehandle for a datafile. |C| maxpos -- The number of intervalls, which are truncated. |C| help -- A help variable. |C| numfunc -- The actual number of function evaluations. |C| file2 -- The filehandle for an other datafile. |C| ArrayI -- Array with the indexes of the sides with maximum length. |C| maxi -- Number of directions with maximal side length. |C| oops -- Flag which shows if anything went wrong in the |C| initialisation. |C| cheat -- Obsolete. If equal 1, we don't allow Ktilde > kmax. |C| writed -- If writed=1, store final division to plot with Matlab. |C| List2 -- List of indicies of intervalls, which are to be truncated. |C| i -- Another loop-variable. |C|actmaxdeep-- The actual maximum (minimum) of possible Interval length. |C| oldpos -- The old index of the minimum. Used to print only, if there |C| is a new minimum found. |C| tstart -- The start of the outer loop. |C| start -- The postion of the starting point in the inner loop. |C| Newtosample -- The total number of points to sample in the inner loop.|C| w -- Array used to divide the intervalls |C| kmax -- Obsolete. If cheat = 1, Ktilde was not allowed to be larger|C| than kmax. If Ktilde > kmax, we set ktilde = kmax. |C| delta -- The distance to new points from center of old hyperrec. |C| pos1 -- Help variable used as an index. |C| version -- Store the version number of DIRECT. |C| oldmaxf -- Store the original function budget. |C|increase -- Flag used to keep track if function budget was increased |C| because no feasible point was found. |C| freeold -- Keep track which index was free before. Used with |C| SUBROUTINE DIRReplaceInf. |C|actdeep_div-- Keep track of the current depths for divisions. |C| oldl -- Array used to store the original bounds of the domain. |C| oldu -- Array used to store the original bounds of the domain. |C| epsfix -- If eps < 0, we use Jones update formula. epsfix stores the |C| absolute value of epsilon. |C|iepschange-- flag iepschange to store if epsilon stays fixed or is |C| changed. |C|DIRgetMaxdeep-- Function to calculate the level of a hyperrectangle. |C|DIRgetlevel-- Function to calculate the level and stage of a hyperrec. |C| fmax -- Keep track of the maximum value of the function found. |C|Ifeasiblef-- Keep track if a feasible point has been found so far. |C| Ifeasiblef = 0 means a feasible point has been found, |C| Ifeasiblef = 1 no feasible point has been found. |C| dwrit -- Controls the level of output. So far not used a lot, set to|C| 0. If its value is set to 2, more output, exspecially from |C| Subroutine DIRChoose. |C+-----------------------------------------------------------------------+ DOUBLE PRECISION f(maxfunc,2), divfactor
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -