47. TAO Interface with Solvers

TAO solvers must be written in C++ and include several routines with a particular calling sequence. Two of these routines are mandatory: one that initializes the TAO structure with the appropriate information and one that applies the algorithm to a problem instance. Additional routines may be written to set some options within the solver, view the solver, setup appropriate data structures, and destroy these data structures. In each of these routines except the initialization routine, there are two arguments.

The first argument is always the TAO structure. This structure may be used to obtain the vectors used to store the variables and the function gradient, evaluate a function and gradient, solve a set of linear equations, perform a line search, and apply a convergence test.

The second argument is specific to this solver. This pointer will be set in the initialization routine and cast to an appropriate type in the other routines. To implement the Fletcher - Reeves conjugate gradient algorithm, for instance, the following structure may be useful.

typedef struct{ 
 
  double beta; 
 
  TaoVec *gg; 
  TaoVec *dx;   /* step direction */ 
  TaoVec *ww;   /* work vector    */ 
 
} TAO_CG; 
This structure contains two work vectors and a scalar. Vectors for the solution and gradient are not needed here because the TAO structure has pointers to them.