Actual source code: taofloatapp.c
1: #include "src/tao_impl.h" /*I "tao_solver.h" I*/
2: #include "taofloatapp.h"
3: #include "src/vector/tvecsingle.h"
7: TaoABCFloatApplication::TaoABCFloatApplication(){
8: this->taox=0;
9: return;
10: }
15: TaoABCFloatApplication::~TaoABCFloatApplication(){
16: int info;
17: info = TaoVecDestroy(this->taox);
18: if (info) return;
19: return;
20: }
25: /* @C
26: SetDimension - Set the number of variables in this application.
28: Input Parameters:
29: . n - the number of variables
31: Note: This method should be called only once and be called before
32: the application is set to the solver.
34: Note: This routine creates a variables vector. Applications derived
35: from this object may create a TaoVec object and set the 'taox' field
36: another way.
38: Level: beginner
40: @*/
41: int TaoABCFloatApplication::SetNumberOfVariables(TaoInt n){
42: TaoFunctionBegin;
43: this->taox = new TaoVecFloatArray(n);
44: TaoFunctionReturn(0);
45: }
49: /* @C
50: GetSolutionAndGradient - Get the solution and and gradient arrays.
52: Output Parameters:
54: + n - the length of the arrays, which equals the number of variables
55: . x - variables vector
56: - g - gradient vector
58: Level: beginner
60: @ */
61: int TaoABCFloatApplication::GetSolutionAndGradient(float* &x, float* &g, TaoInt &n){
62: TaoInt nn;
63: int info;
64: float *xx;
65: TaoFunctionBegin;
66: info = this->taox->GetFloats(&xx,&nn);CHKERRQ(info);
67: x=xx; n=nn;
68: g=0;
69: info = this->taox->RestoreFloats(&xx,&nn); CHKERRQ(info);
70: TaoFunctionReturn(0);
71: }
75: int TaoABCFloatApplication::GetVariableVector(TaoVec **xx){
77: TaoFunctionBegin;
78: *xx= this->taox;
79: TaoFunctionReturn(0);
80: }
85: int TaoABCFloatApplication::EvaluateObjectiveFunction(TaoVec *xx, double *ff){
86: TaoFunctionBegin;
87: TaoFunctionReturn(1);
88: }
93: int TaoABCFloatApplication::EvaluateGradient(TaoVec *tx, TaoVec *tg){
94: TaoInt n;
95: int info;
96: float *xptr,*gptr;
97: float ff;
98: TaoVecFloatArray* xx = (TaoVecFloatArray*)(tx);
99: TaoVecFloatArray* gg = (TaoVecFloatArray*)(tg);
100: TaoFunctionBegin;
101: info = xx->GetFloats(&xptr,&n);CHKERRQ(info);
102: info = gg->GetFloats(&gptr,&n);CHKERRQ(info);
103: info = this->ComputeObjectiveAndGradient(xptr,n,&ff,gptr);CHKERRQ(info);
104: info = gg->RestoreFloats(&gptr,&n);CHKERRQ(info);
105: info = xx->RestoreFloats(&xptr,&n); CHKERRQ(info);
106: TaoFunctionReturn(0);
107: }
112: int TaoABCFloatApplication::EvaluateObjectiveAndGradient(TaoVec *tx, double *ff, TaoVec *tg){
113: TaoInt n;
114: int info;
115: float *xptr, *gptr;
116: float f;
117: TaoVecFloatArray* xx = (TaoVecFloatArray*)(tx);
118: TaoVecFloatArray* gg = (TaoVecFloatArray*)(tg);
120: TaoFunctionBegin;
121: info = xx->GetFloats(&xptr,&n);CHKERRQ(info);
122: info = gg->GetFloats(&gptr,&n);CHKERRQ(info);
123: info = this->ComputeObjectiveAndGradient(xptr,n,&f,gptr);CHKERRQ(info);
124: info = gg->RestoreFloats(&gptr,&n);CHKERRQ(info);
125: info = xx->RestoreFloats(&xptr,&n); CHKERRQ(info);
126: *ff=(double)f;
127: TaoFunctionReturn(0);
128: }
133: /*@C
134: ComputeObjectiveAndGradient - Compute the objective function and its gradient.
136: Input Parameters:
137: . x - an array with the point at which the function and gradient should be evalutated.
138: . g - an array that will contain the gradient vector.
139: + n - the length of the arrays, which equals the number of variables
141: Output Parameters:
143: . f - function value
144: . g - gradient vector
146: Level: beginner
148: @*/
149: // virtual int TaoABCFloatApplication::ComputeObjectiveAndGradient(float*x,TaoInt n,float*f,float *g){}
154: /*@C
155: StartingPoint - Define the starting point for the solver.
157: Collective on TAO_SOLVER
159: Input Parameters:
160: + x - vector to store initial variables
161: - n - length of variable vector array
163: Note: This virtual method should be implemented in the application
164: if a starting point other than 0 is desired.
166: Level: beginner
168: @*/
169: int TaoABCFloatApplication::StartingPoint(float *x, TaoInt n){
170: TaoInt i;
171: TaoFunctionBegin;
172: for (i=0;i<n;i++) x[i]=0.0;
173: TaoFunctionReturn(0);
174: }
179: int TaoABCFloatApplication::InitializeVariables(TaoVec *tx){
180: TaoInt n;
181: int info;
182: float *xptr;
183: TaoVecFloatArray* xx = (TaoVecFloatArray*)(tx);
184: TaoFunctionBegin;
185: info = xx->GetFloats(&xptr,&n);CHKERRQ(info);
186: info = this->StartingPoint(xptr,n);CHKERRQ(info);
187: info = xx->RestoreFloats(&xptr,&n);CHKERRQ(info);
188: TaoFunctionReturn(0);
189: }
193: int TaoABCFloatApplication::EvaluateVariableBounds(TaoVec *txl, TaoVec *txu){
194: TaoInt n;
195: int info;
196: float *xl,*xu;
197: TaoVecFloatArray* xxll = (TaoVecFloatArray*)(txl);
198: TaoVecFloatArray* xxuu = (TaoVecFloatArray*)(txu);
200: TaoFunctionBegin;
201:
202: info = xxll->GetFloats(&xl,&n);CHKERRQ(info);
203: info = xxuu->GetFloats(&xu,&n);CHKERRQ(info);
204: info = this->ComputeVariableBounds(xl, xu,n);CHKERRQ(info);
205: info = xxuu->RestoreFloats(&xu,&n);CHKERRQ(info);
206: info = xxll->RestoreFloats(&xl,&n); CHKERRQ(info);
207:
208: TaoFunctionReturn(0);
209: }
214: /*@C
215: StartingPoint - Define the lower and upper bounds on the variables.
217: Collective on TAO_SOLVER
219: Input Parameters:
220: + xl - array to store lower bounds
221: . xu - array to store upper bounds
222: - n - length of these arrays, which equals the number of variables
224: Note: This virtual method should be implemented by the application
225: if there are lower or upper bounds on the variables.
227: Level: beginner
229: @*/
230: int TaoABCFloatApplication::ComputeVariableBounds(float *xl, float *xu, TaoInt n){
231: TaoInt i;
232: TaoFunctionBegin;
233: for (i=0;i<n;i++){
234: xl[i]=TAO_NINFINITY;
235: xu[i]=TAO_INFINITY;
236: }
237: TaoFunctionReturn(0);
238: }