Actual source code: unit.c
2: #include "tao_solver.h" /*I "tao_solver.h" I*/
3: #include "src/tao_impl.h"
7: static int TaoDestroy_UnitStep(TAO_SOLVER tao,void *linectx)
8: {
9: TaoFunctionBegin;
10: TaoFunctionReturn(0);
11: }
15: static int TaoSetOptions_UnitStep(TAO_SOLVER tao,void *linectx)
16: {
17: int info;
18: TaoFunctionBegin;
19: info = TaoOptionsHead("No Unit line search options");CHKERRQ(info);
20: info = TaoOptionsTail();CHKERRQ(info);
21: TaoFunctionReturn(0);
22: }
26: static int TaoView_UnitStep(TAO_SOLVER tao,void *ctx)
27: {
28: int info;
29: TaoFunctionBegin;
30: info=TaoPrintStatement(tao," Line Search: Unit Step.\n");CHKERRQ(info);
31: TaoFunctionReturn(0);
32: }
36: /* @ TaoApply_LineSearch - This routine takes step length of 1.0.
38: Input Parameters:
39: + tao - TAO_SOLVER context
40: . X - current iterate (on output X contains new iterate, X + step*S)
41: . S - search direction
42: . f - objective function evaluated at X
43: . G - gradient evaluated at X
44: . W - work vector
45: . gdx - inner product of gradient and the direction of the first linear manifold being searched
46: - step - initial estimate of step length
48: Output parameters:
49: + f - objective function evaluated at new iterate, X + step*S
50: . G - gradient evaluated at new iterate, X + step*S
51: . X - new iterate
52: - step - final step length
54: Info is set to 0.
56: @ */
57: static int TaoApply_UnitStep(TAO_SOLVER tao,TaoVec* X,TaoVec* G,TaoVec* S,TaoVec* Gold,double *f, double *f_full,
58: double *step,int *info2,void*ctx)
59: {
60: int info;
61: double fnew;
62: TaoVec *XL,*XU;
64: TaoFunctionBegin;
65: info = X->Axpy(*step,S);CHKERRQ(info);
66: info = TaoGetVariableBounds(tao,&XL,&XU); CHKERRQ(info);
67: if (XL && XU){
68: info = X->Median(XL,X,XU);CHKERRQ(info);
69: }
70: info = TaoComputeMeritFunctionGradient(tao,X,&fnew,G); CHKERRQ(info);
71: info = PetscInfo1(tao,"Tao Apply Unit Step: %4.4e\n",*step);
72: CHKERRQ(info);
73: if (*f<fnew){
74: info = PetscInfo2(tao,"Tao Apply Unit Step, FINCREASE: F old:= %12.10e, F new: %12.10e\n",*f,fnew); CHKERRQ(info);
75: }
76: *f=fnew;
77: *f_full = fnew;
78: *info2 = 0;
79: TaoFunctionReturn(0);
80: }
84: /*@C
85: TaoCreateUnitLineSearch - Always use step length of 1.0
87: Input Parameters:
88: . tao - TAO_SOLVER context
90: Note:
91: This routine is never used by default.
93: Level: advanced
95: .keywords: TAO_SOLVER, linesearch
96: @*/
97: int TaoCreateUnitLineSearch(TAO_SOLVER tao)
98: {
99: int info;
101: TaoFunctionBegin;
102: info = TaoSetLineSearch(tao,0,
103: TaoSetOptions_UnitStep,
104: TaoApply_UnitStep,
105: TaoView_UnitStep,
106: TaoDestroy_UnitStep,
107: 0);CHKERRQ(info);
109: TaoFunctionReturn(0);
110: }