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* W,double *f, double *f_full,
58: double *step,TaoInt *info2,void*ctx)
59: {
60: int info;
61: double fnew;
62: TaoVec *XL,*XU;
64: TaoFunctionBegin;
65: tao->new_search=TAO_TRUE;
66: info = W->CopyFrom(X); CHKERRQ(info);
67: info = W->Axpy(*step,S);CHKERRQ(info);
68: info = TaoGetVariableBounds(tao,&XL,&XU); CHKERRQ(info);
69: if (XL && XU){
70: info = W->Median(XL,W,XU);CHKERRQ(info);
71: }
72: info = TaoComputeMeritFunctionGradient(tao,W,&fnew,G); CHKERRQ(info);
73: info = X->CopyFrom(W); CHKERRQ(info);
74: info = PetscInfo1(tao,"Tao Apply Unit Step: %4.4e\n",*step);
75: CHKERRQ(info);
76: if (*f<fnew){
77: info = PetscInfo2(tao,"Tao Apply Unit Step, FINCREASE: F old:= %12.10e, F new: %12.10e\n",*f,fnew); CHKERRQ(info);
78: }
79: *f=fnew;
80: *f_full = fnew;
81: *info2 = 0;
82: TaoFunctionReturn(0);
83: }
87: /*@C
88: TaoCreateUnitLineSearch - Always use step length of 1.0
90: Input Parameters:
91: . tao - TAO_SOLVER context
93: Note:
94: This routine is never used by default.
96: Level: advanced
98: .keywords: TAO_SOLVER, linesearch
99: @*/
100: int TaoCreateUnitLineSearch(TAO_SOLVER tao)
101: {
102: int info;
104: TaoFunctionBegin;
105: info = TaoSetLineSearch(tao,0,
106: TaoSetOptions_UnitStep,
107: TaoApply_UnitStep,
108: TaoView_UnitStep,
109: TaoDestroy_UnitStep,
110: 0);CHKERRQ(info);
112: TaoFunctionReturn(0);
113: }