From xcai@s1.arc.umn.edu Wed Sep 23 12:21:42 1992
To: bsmith
Subject: line search


typedef struct {
  /*
    vectors
   */
  double *x;                 /* current solution */
  double *p;                 /* search directoin */
  double *tmp1, *tmp2;       /* work vectors */
  /*
    Vector operations
   */
  double (*norm)();          /* 2-norm of x */
  void   (*waxpy)();         /* w <- y + a * x */
  /*
    Functions
   */
  void   (*function)();      /* objective function */
  /*
    parameters
   */
  double alpha;              /* (0, 0.5) */
  double rho;                /* (0, 1)   */
  int    max_it;             /* maximum number of searches */
  int    it;                 /* actual iteration number */
  } LNSRCHCntx;

/* 
   Line search   x:      current solution
                 p:      search direction
                 nrmfx:  2-norm of F(x),  f(x) = 0.5 F(x)^T * F(x)
  */
#include "ntctx.h"
#include <math.h>

void lnsrch( Lctx, nrmfx )
LNSRCHCntx  *Lctx;
double       nrmfx;
{
  double *x     = Lctx->x;
  double *p     = Lctx->p;
  double *tmp1  = Lctx->tmp1;
  double *tmp2  = Lctx->tmp2;
  double alpha  = Lctx->alpha; 
  double rho    = Lctx->rho;
  int    max_it = Lctx->max_it;
  double lambda = 1.0, om0, om, r0, r, rr;
  int    it;

  rr  = nrmfx * nrmfx;                           /* F(x)^t * F(x) */
  r0  = 0.5 * rr;                                /* f(x) */
  om0 = rr;                                      /* F(x)^t * F(x) */
  (*Lctx->waxpy)(lambda, p, x, tmp1 );           /* tmp1 <- x + lambda * p */
  (*Lctx->function)( tmp1, tmp2 );               /* tmp2 <- F(x+p) */
  rr  = (*Lctx->norm)( tmp2 );
  rr  = rr * rr;                                 /* F(x+p)^t * F(x+p) */
  r   = 0.5 * rr;                                /* f(x+p) */
  om  = r0 - alpha * lambda * om0;
  it  = 0;
  while( r > om && it < max_it ){
    it++;
    lambda  = rho * lambda;                      /* lambda <- lambda * rho */
    (*Lctx->waxpy)(lambda, p, x, tmp1 );         /* tmp1 <- x + lambda * p */
    (*Lctx->function)( tmp1, tmp2 );             /* tmp2 <- F(x+lambda p) */
    rr      = (*Lctx->norm)( tmp2 );
    rr      = rr * rr;                           /* F(x+lambda p)^t * 
                                                            F(x+ lambdap) */
    r       = 0.5 * rr;                          /* f(x+lambda*p) */
    om      = r0 - alpha * lambda * om0;
  }
  /*x         = tmp1;                              /* new solution */
  NTCOPY(tmp1,x);
  Lctx->it = it;
}

