Instructions for calling Direct Search
Libraries from FORTRAN
(For now, only machines with GNU compilers should be used.)
First, download the Direct Search tarball from
the website. Untar it in a new directory, but don't compile yet. Now
copy the file SearchWrappers.tar
by holding down the shift key and clicking on the link. Untar this file
in the directory with the direct search classes. Typing "make -f
Makefile.linux.f" will make a sample executable on Linux called
MySearch that optimizes the objective function in MyMain.f. You
can modify the sample program MyMain.f to suit your needs.
The user must provide two things:
- A FORTRAN subroutine which implements the objective function
- A main routine which calls the FORTRAN wrappers
You can call the FORTRAN subroutine whatever you like, but
it must have the following signature:
objf(x, f, n)
double precision x(n), f
integer n
where n is the dimension of the problem, x is the array of
points to evaluate, and f is the function evaluation. The order of
arguments is hardcoded in the C++, and must be maintained. An example
of a subroutine that implements an objective function is given in the
file MyMain.f, along with a main
routine to call the wrappers. The objective function also shows how
bounds can be constructed by heavily penalizing x values outside the
bounds.
Next, you will write a FORTRAN routine to call the direct
search you are interested in. While this routine will serve as the main
program, it must actually be considered a subroutine to interact with
the C++ classes. It should be initiated with the line:
subroutine mymain
where mymain is the hard-coded name for the subroutine.
There are eight types of searches provided by the direct
search classes, including five pattern searchs and three simplex
searches. You may access them by calling any of the four subroutines in
the file direct.f , which comes as part
of the wrapper library.The functions are as follows:
subroutine pattrn(choice, obj, n, x, step1, step2,
maxf, istat, aux, iaux)
- The integer choice refers to the search type preferred. The
five types of pattern searches are
- Coordinate Search
- Compass Search
- NLess Search
- Hooke and Jeeves Method
- Edited Hooke and Jeeves (changes by E.
Dolan)
- obj is a pointer to the subroutine containing the
objective function evaluation. Name this subroutine whatever you want.
Just be sure it follows the signature given above and declare it as
external if it's not in your main file.
- The integer n is the dimension of the problem
- Double precision x is the starting point of the
objective function. It may be one value or an array of values,
depending on n.
- Double precision step1 is the starting step length.
If -1 is passed, a default of 0.25 is used.
- Double precision step2 is the ending step length. If
-1 is passed, a default of 10E-8 is used.
- The integer maxf is the maximum allowable number of
function calls. If -1 is passed, no maximum is set.
- The integer istat gives the completion status. Since
no failure criteria are currently implemented in the classes, istat
should always return as 1.
- The double precision array aux is of size n+2. The
first value is the final step length. The second value is the minimum
function evaluation. This is followed by an n-sized array containing
the x values at the minimum.
- The integer iaux returns the number of function
evaluations.
subroutine shh(obj, n, x, right, step1, step2, maxf, stddev,
istat, aux, iaux)
- This is a Simplex Search based on the work of Spendley,
Hext, and Himsworth.
- The arguments obj, n, x, step2,maxf,istat,aux,
and iaux have the same meanings as in the pattrn() subroutine.
- The logical right is set to true if the user wants a
right simplex. It is set to false if the user prefers a regular simplex.
- The double precision step1 represents the starting
edgelengths of the simplex. If the user wants a regular simplex, only
one value is required. If the user wants a right simplex, the program
expects an array of n edgelengths. (The n+1 edge will be calculated
automatically.) Set the first value to -1 to use the default of 2.0 for
the edgelengths.
- The logical stddev is set to true if the user wants
stopping criteria dependent on standard deviation. If it is false, the
search will stop based on delta.
subroutine nm(obj, n, x, right, sigma, alpha, beta, gamma,
step1, step2, maxf, stddev, istat, aux, iaux)
- This is a Simplex Search based on the work of Nelder and
Meade.
- The arguments obj, n, x, step2,maxf,istat,aux,
and iaux have the same meanings as in the pattrn() subroutine.
- The arguments right, step1, and stddev
have the same meanings as in the shh() subroutine.
- The double precision sigma is the shrinking
coeffient. If -1 is passed, a default of 0.5 is used.
- The double precision alpha is the reflection
coeffient. If -1 is passed, a default of 1.0 is used.
- The double precision beta is the contraction
coeffient. If -1 is passed, a default of 0.5 is used.
- The double precision gamma is the expansion
coeffient. If -1 is passed, a default of 2.0 is used.
subroutine smd(obj, n, x, right, step1, step2, maxf, stddev,
istat, aux, iaux)
- This simplex search implements a sequential multidirectional
search.
- The arguments are exactly the same as the subroutine shh().
Any of these subroutines may be used to find the minimum of
your objective function. The main routine provided in MyMain.f is an
example of an interactive routine which queries the user and calls the
appropriate subroutine. By performing a simple search and replace on
the provided objective function "objf", the user can insert their own
objective function into the calls.
To see how the example program works, you can use and modify
the data file sample.dat. Simply run
"MySearch<sample.dat".
|