20 |
|
//abstract class of nonlinear optimization model |
21 |
|
class NLModel{ |
22 |
|
public: |
23 |
< |
NLModel(ConstraintList* cons) {constraints = cons;} |
23 |
> |
NLModel(int dim, ConstraintList* cons) { ndim = dim, constraints = cons;} |
24 |
|
virtual ~NLModel() { if (constraints != NULL) delete constraints;} |
25 |
|
|
26 |
|
virtual void setX(const vector<double>& x)= 0; |
35 |
|
int getConsType() { return constraints->getConsType();} |
36 |
|
|
37 |
|
virtual double calcF() = 0; |
38 |
< |
virtual double calcF(const vector<double>& x) = 0; |
38 |
> |
virtual double calcF(vector<double>& x) = 0; |
39 |
|
virtual vector<double> calcGrad() = 0; |
40 |
|
virtual vector<double> calcGrad(vector<double>& x) = 0; |
41 |
|
virtual SymMatrix calcHessian() = 0; |
42 |
|
virtual SymMatrix calcHessian(vector<double>& x) = 0; |
43 |
|
|
44 |
|
#ifdef IS_MPI |
45 |
< |
void setMPIINITFunctor(MPIINITFunctor* func); |
46 |
< |
int getLocalDim() {return localDim;} |
45 |
> |
//void setMPIINITFunctor(MPIINITFunctor* func); |
46 |
> |
//int getLocalDim() {return localDim;} |
47 |
|
|
48 |
< |
virtual void update(); //a hook function to load balancing |
48 |
> |
//virtual void update(); //a hook function to load balancing |
49 |
|
#endif |
50 |
|
|
51 |
|
protected: |
52 |
+ |
NLModel() {} |
53 |
|
ConstraintList* constraints; //constraints of nonlinear optimization model |
54 |
|
int numOfFunEval; //number of function evaluation |
55 |
|
int ndim; |
58 |
|
bool mpiInitFlag; |
59 |
|
int myRank; //rank of current node |
60 |
|
int numOfProc; // number of processors |
61 |
< |
MPIINITFunctor * mpiInitFunc; |
61 |
> |
//MPIINITFunctor * mpiInitFunc; |
62 |
|
|
63 |
|
int localDim; |
64 |
|
vector<int> procMappingArray; |
70 |
|
class NLModel0 : public NLModel{ |
71 |
|
public: |
72 |
|
|
73 |
< |
NLModel0(int dim, ConstraintList* cons = NULL); |
73 |
> |
NLModel0(int dim, ConstraintList* cons) : NLModel(dim, cons) { currentX.resize(dim);} |
74 |
|
~NLModel0() {} |
75 |
|
|
76 |
|
virtual void setX(const vector<double>& x) {currentX = x;} |
91 |
|
//virtual SymMatrix FiniteHessian(vector<double>& x, double fx, vector<double>& h); |
92 |
|
SymMatrix FiniteHessian(vector<double>& x, double fx, vector<double>& h); |
93 |
|
protected: |
94 |
+ |
NLModel0() {} |
95 |
|
|
96 |
|
FDType fdType; |
97 |
|
vector<double> currentX; |
100 |
|
|
101 |
|
//concrete class of nonlinear optimization model without derivatives |
102 |
|
|
103 |
< |
class ConcreteNLMode0 : public NLModel0{ |
103 |
> |
class ConcreteNLModel0 : public NLModel0{ |
104 |
|
|
105 |
|
public: |
106 |
|
|
107 |
< |
ConcreteNLMode0(int dim, ObjFunctor0* func , ConstraintList* cons = NULL); |
108 |
< |
ConcreteNLMode0(int dim, ConstraintList* cons = NULL); |
107 |
> |
ConcreteNLModel0(int dim, ObjFunctor0* func , ConstraintList* cons = NULL) : NLModel0(dim, cons){objfunc = func;} |
108 |
> |
|
109 |
|
|
110 |
|
virtual double calcF(); |
111 |
|
virtual double calcF(vector<double>& x); |
124 |
|
class NLModel1 : public NLModel0{ |
125 |
|
|
126 |
|
public: |
127 |
< |
|
127 |
> |
NLModel1(int dim, ConstraintList* cons ) : NLModel0(dim, cons){currentGrad.resize(dim);} |
128 |
|
//Using finite difference methods to approximate the hessian |
129 |
|
//It is inappropriate to apply this method in large scale problem |
130 |
|
virtual SymMatrix FiniteHessian(vector<double>& x, vector<double>& h); |
137 |
|
}; |
138 |
|
|
139 |
|
//concrete class of nonlinear optimization model with first derivatives |
140 |
< |
class ConcreteNLMode1 : NLModel1{ |
140 |
> |
class ConcreteNLModel1 : public NLModel1{ |
141 |
|
|
142 |
|
public: |
143 |
|
|
144 |
< |
ConcreteNLMode1(int dim, ObjFunctor1* func , ConstraintList* cons = NULL); |
143 |
< |
ConcreteNLMode1(int dim, ConstraintList* cons = NULL); |
144 |
> |
ConcreteNLModel1(int dim, ObjFunctor1* func , ConstraintList* cons = NULL); |
145 |
|
|
146 |
+ |
|
147 |
|
virtual double calcF(); |
148 |
|
virtual double calcF(vector<double>& x); |
149 |
|
virtual vector<double> calcGrad(); |