Actual source code: unit.c

      2: #include "tao_solver.h"  /*I "tao_solver.h" I*/
      3: #include "src/tao_impl.h"

      5: static int TaoSetOptions_UnitStep(TAO_SOLVER,void*);
      6: static int TaoView_UnitStep(TAO_SOLVER,void*);
      7: static int TaoApply_UnitStep(TAO_SOLVER,TaoVec*,TaoVec*,TaoVec*,TaoVec*,
      8:                                 double*,double*,int*,void*);
      9: static int TaoDestroy_UnitStep(TAO_SOLVER,void*);

     11: /* ---------------------------------------------------------- */
     14: static int TaoDestroy_UnitStep(TAO_SOLVER tao,void *linectx)
     15: {
     16:   TaoFunctionBegin;
     17:   TaoFunctionReturn(0);
     18: }
     19: /*------------------------------------------------------------*/
     22: static int TaoSetOptions_UnitStep(TAO_SOLVER tao,void *linectx)
     23: {
     24:   int info;
     25:   TaoFunctionBegin;
     26:   info = TaoOptionsHead("No Unit line search options");CHKERRQ(info);
     27:   info = TaoOptionsTail();CHKERRQ(info);
     28:   TaoFunctionReturn(0);
     29: }
     30: /*------------------------------------------------------------*/

     34: static int TaoView_UnitStep(TAO_SOLVER tao,void *ctx)
     35: {
     36:   int info;
     37:   TaoFunctionBegin;
     38:   info=TaoPrintStatement(tao,"  Line Search: Unit Step.\n");CHKERRQ(info);
     39:   TaoFunctionReturn(0);
     40: }
     41: /* ---------------------------------------------------------- */
     44: /* @ TaoApply_LineSearch - This routine takes step length of 1.0.

     46:    Input Parameters:
     47: +  tao - TAO_SOLVER context
     48: .  X - current iterate (on output X contains new iterate, X + step*S)
     49: .  S - search direction
     50: .  f - objective function evaluated at X
     51: .  G - gradient evaluated at X
     52: .  W - work vector
     53: .  gdx - inner product of gradient and the direction of the first linear manifold being searched
     54: -  step - initial estimate of step length

     56:    Output parameters:
     57: +  f - objective function evaluated at new iterate, X + step*S
     58: .  G - gradient evaluated at new iterate, X + step*S
     59: .  X - new iterate
     60: -  step - final step length

     62:    Info is set to 0.

     64: @ */
     65: static int TaoApply_UnitStep(TAO_SOLVER tao,TaoVec* X,TaoVec* G,TaoVec* S,TaoVec* Gold,double *f,
     66:                         double *step,int *info2,void*ctx)
     67: {
     68:   int       info;
     69:   double fnew;
     70:   TaoVec *XL,*XU;

     72:   TaoFunctionBegin;
     73:   info = X->Axpy(*step,S);CHKERRQ(info);
     74:   info = TaoGetVariableBounds(tao,&XL,&XU); CHKERRQ(info);
     75:   if (XL && XU){
     76:     info = X->Median(XL,X,XU);CHKERRQ(info);
     77:   }
     78:   info = TaoComputeMeritFunctionGradient(tao,X,&fnew,G); CHKERRQ(info);
     79:   info = PetscLogInfo((tao,"Tao Apply Unit Step: %4.4e\n",*step));
     80:          CHKERRQ(info);
     81:   if (*f<fnew){
     82:     info = PetscLogInfo((tao,"Tao Apply Unit Step, FINCREASE: F old:= %12.10e, F new: %12.10e\n",*f,fnew)); CHKERRQ(info);
     83:   }
     84:   *f=fnew;
     85:   *info2 = 0;
     86:   TaoFunctionReturn(0);
     87: }

     90: /* ---------------------------------------------------------- */

     94: /*@C
     95:    TaoCreateUnitLineSearch - Always use step length of 1.0

     97:    Input Parameters:
     98: .  tao - TAO_SOLVER context

    100:    Note:
    101:    This routine is never used by default.

    103:    Level: advanced

    105: .keywords: TAO_SOLVER, linesearch
    106: @*/
    107: int TaoCreateUnitLineSearch(TAO_SOLVER tao)
    108: {
    109:   int info;

    111:   TaoFunctionBegin;
    112:   info = TaoSetLineSearch(tao,0,
    113:                           TaoSetOptions_UnitStep,
    114:                           TaoApply_UnitStep,
    115:                           TaoView_UnitStep,
    116:                           TaoDestroy_UnitStep,
    117:                           0);CHKERRQ(info);

    119:   TaoFunctionReturn(0);
    120: }