ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/NLModel.hpp
Revision: 1000
Committed: Fri Jan 30 21:47:22 2004 UTC (20 years, 5 months ago) by tim
File size: 5150 byte(s)
Log Message:
using class  Minimizer1D derived from MinimizerBase instead of a functor to do line seach

File Contents

# Content
1 #ifndef _NLMODEL_H_
2 #define _NLMODEL_H_
3
4 #include <vector>
5 #include <utility>
6
7 #include "SymMatrix.hpp"
8 #include "Functor.hpp"
9
10 using namespace std;
11
12
13 typedef enum FDType {backward, forward, central} ;
14
15 // special property of nonlinear object function
16 typedef enum NLOFProp{linear, quadratic, general};
17
18 //abstract class of nonlinear optimization model
19 class NLModel{
20 public:
21 NLModel(ConstraintList* cons) {constraints = cons;}
22 virtual ~NLModel() { if (constraints != NULL) delete constraints;}
23
24 virtual void setX(const vector<double>& x)= 0;
25
26 virtual int getDim() const = 0;
27
28 bool hasConstraints() { return constraints == NULL ? false : true;}
29 int getConsType() { return constrains->getConsType();}
30
31 virtual double calcF() = 0;
32 virtual double calcF(const vector<double>& x) = 0;
33 virtual vector<double> calcGrad() = 0;
34 virtual vector<double> calcGrad(vector<double>& x) = 0;
35 virtual SymMatrix calcHessian() = 0;
36 virtual SymMatrix calcHessian(vector<double>& x) = 0;
37
38 #ifdef IS_MPI
39 void setMPIINITFunctor(MPIINITFunctor* func);
40 int getLocalDim() {return localDim;}
41
42 virtual void update(); //a hook function to load balancing
43 #endif
44
45 protected:
46 ConstraintList* constraints; //constraints of nonlinear optimization model
47 int numOfFunEval; //number of function evaluation
48
49 #ifdef IS_MPI
50 bool mpiInitFlag;
51 int myRank; //rank of current node
52 int numOfProc; // number of processors
53 MPIINITFunctor * mpiInitFunc;
54
55 int localDim;
56 vector<int> procMappingArray;
57 int beginGlobalIndex;
58 #endif
59 };
60
61 //abstract class of nonlinear optimization model without derivatives
62 class NLModel0 : public NLModel{
63 public:
64
65 NLModel0(int dim, ConstraintList* cons = NULL);
66 ~NLModel0() {}
67
68 virtual void setX(const vector<double>& x);
69
70 //Using finite difference methods to approximate the gradient
71 //It is inappropriate to apply these methods in large scale problem
72
73 vector<double> BackwardGrad(const vector<double>& x, double& fx, vector<double>& grad);
74 vector<double> ForwardGrad(const vector<double>& x, double& fx, vector<double>& grad);
75 vector<double> CentralGrad(const vector<double>& x, double& fx, vector<double>& grad);
76
77 //Using finite difference methods to approximate the hessian
78 //It is inappropriate to apply this method in large scale problem
79 virtual SymMatrix FiniteHessian(vector<double>& x, double fx, vector<double>& h);
80
81 protected:
82
83 FDType fdType;
84 vector<double> currentX;
85 double curretF;
86 };
87
88 //concrete class of nonlinear optimization model without derivatives
89
90 class ConcreteNLMode0 : public NLModel0{
91
92 public:
93
94 ConcreteNLMode0(int dim, ObjFunctor0* func , ConstraintList* cons = NULL);
95 ConcreteNLMode0(int dim, ConstraintList* cons = NULL);
96
97 virtual double calcF();
98 virtual double calcF(const vector<double>& x);
99 virtual vector<double> calcGrad();
100 virtual vector<double> calcGrad(vector<double>& x);
101 virtual SymMatrix calcHessian() ;
102 virtual SymMatrix calcHessian(vector<double>& x) ;
103
104 protected:
105
106 ObjFunctor0* objfunc;
107
108 };
109
110 //abstract class of nonlinear optimization model with first derivatives
111 class NLModel1 : public NLModel0{
112
113 public:
114
115 //Using finite difference methods to approximate the hessian
116 //It is inappropriate to apply this method in large scale problem
117 virtual SymMatrix FiniteHessian(vector<double>& x, double fx, vector<double>& h);
118
119 protected:
120
121 vector<double> currentGrad;
122 };
123
124 //concrete class of nonlinear optimization model with first derivatives
125 class ConcreteNLMode1 : NLModel1{
126
127 public:
128
129 ConcreteNLMode1(int dim, ObjFunctor1* func , ConstraintList* cons = NULL);
130 ConcreteNLMode1(int dim, ConstraintList* cons = NULL);
131
132 virtual double calcF();
133 virtual double calcF(const vector<double>& x);
134 virtual vector<double> calcGrad();
135 virtual vector<double> calcGrad(vector<double>& x);
136 virtual SymMatrix calcHessian() ;
137 virtual SymMatrix calcHessian(vector<double>& x) ;
138
139 protected:
140
141 ObjFunctor1* objfunc;
142 };
143
144 /*
145 //abstract class of nonlinear optimization model with second derivatives
146 class NLModel2 : public NLModel1{
147 public:
148
149 protected:
150 SymMatrix currentHessian;
151
152 };
153
154 //concrete class of nonlinear optimization model with second derivatives
155 class ConcreteNLModel2 : public NLModel2{
156 public:
157
158 ConcreteNLModel2(int dim, ObjFunctor2* func , ConstraintList* cons = NULL);
159 ConcreteNLModel2(int dim, ConstraintList* cons = NULL);
160
161 virtual double calcF();
162 virtual double calcF(const vector<double>& x);
163 virtual vector<double> calcGrad();
164 virtual vector<double> calcGrad(vector<double>& x);
165 virtual SymMatrix calcHessian() ;
166 virtual SymMatrix calcHessian(vector<double>& x) ;
167
168 protected:
169
170 ObjFunctor2* objFunc;
171 };
172 */
173 #endif

Properties

Name Value
svn:executable *