/*
  File name: conjg.h
  Created by: Ljubomir Buturovic
  Created: 11/27/2003
  Purpose: declarations for conjg.c, the conjugate gradient function
  optimizer.
*/

/*
  Copyright 2004 Ljubomir J. Buturovic

  Permission is hereby granted, free of charge, to any person
  obtaining a copy of this software and associated documentation files
  (the "Software"), to deal in the Software without restriction,
  including without limitation the rights to use, copy, modify, merge,
  publish, distribute, sublicense, and/or sell copies of the Software,
  and to permit persons to whom the Software is furnished to do so,
  subject to the following conditions:

  The above copyright notice and this permission notice shall be
  included in all copies or substantial portions of the Software.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  SOFTWARE.
*/

#include "crit.h"

/*
  Conjugate gradient method for solving unconstrained nonlinear
  optimization problems, as described in the paper:

  Gilbert, J.C. and Nocedal, J. (1992). "Global convergence properties
  of conjugate gradient methods", Siam Journal on Optimization,
  vol. 2, pp. 21-42.

  cgfam() returns minimum value of function 'func' of 'n' variables,
  using the above method. On input, set 'irest' to 0 for no restarts,
  1 to restart every n steps; 'eps' is the convergence constant;
  'method' is the method code method (1 : Fletcher-Reeves; 2:
  Polak-Ribiere, 3: positive Polak-Ribiere ( beta=max{beta,0} );
  'itmax' is the maximum allowed number of iterations; 'parameters' is
  a pointer to a structure used to pass additional arguments to the
  criterion function.

  The signatures of func() and grad() must be:

  double func(double *x, int n, int iteration, void *parameters, int *errc);
  void   grad(double *x, int n, double *grad, void *parameters, int *errc);
  
  Here, 'x' is the n-dimensional point at which the function is
  evaluated.  'parameters' is a pointer to the structure used to pass
  additional arguments to func() and grad(). 'iteration' is the
  current iteration, set by cgfam(). In case of successful evaluation,
  func() and grad() must set *errc to 0, and non-zero otherwise.
  
  On success, cgfam() returns the minimum value, sets x to the minimum
  point, iter to the number of iterations, and iflag and errc to 0; on
  error, it sets iflag and/or errc to the appropriate error codes. The
  iflag error codes are:

  iflag = -1 : line search failure
  iflag = -2 : descent was not obtained

  The errc error codes are EINVAL for bad arguments, malloc() error
  codes and function/gradient evaluation error codes as set by
  func()/grad().
*/
double cgfam(int n, double *x, crit_dfunc *func, crit_gradient *grad, 
	     int irest, double eps, int method, void *parameters, int itmax, 
	     int *iter, int *iflag, int *errc);


syntax highlighted by Code2HTML, v. 0.9.1