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 |
< |
typedef enum {linear, quadratic, general}; |
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{ |
38 |
|
|
39 |
|
#ifdef IS_MPI |
40 |
|
void setMPIINITFunctor(MPIINITFunctor* func); |
41 |
+ |
int getLocalDim() {return localDim;} |
42 |
+ |
|
43 |
+ |
virtual void update(); //a hook function to load balancing |
44 |
|
#endif |
45 |
|
|
46 |
|
protected: |
49 |
|
|
50 |
|
#ifdef IS_MPI |
51 |
|
bool mpiInitFlag; |
52 |
+ |
int myRank; //rank of current node |
53 |
+ |
int numOfProc; // number of processors |
54 |
|
MPIINITFunctor * mpiInitFunc; |
55 |
+ |
|
56 |
|
int localDim; |
57 |
+ |
vector<int> procMappingArray; |
58 |
+ |
int beginGlobalIndex; |
59 |
|
#endif |
60 |
|
}; |
61 |
|
|
77 |
|
|
78 |
|
//Using finite difference methods to approximate the hessian |
79 |
|
//It is inappropriate to apply this method in large scale problem |
80 |
< |
virtual SymMatrix FDHessian(vector<double>& sx); |
80 |
> |
virtual SymMatrix FiniteHessian(vector<double>& sx); |
81 |
|
|
82 |
|
FDType fdType; |
83 |
|
vector<double> currentX; |
89 |
|
|
90 |
|
//Using finite difference methods to approximate the hessian |
91 |
|
//It is inappropriate to apply this method in large scale problem |
92 |
< |
virtual SymMatrix FDHessian(vector<double>& sx); |
92 |
> |
virtual SymMatrix ForwardHessian(vector<double>& sx); |
93 |
|
|
94 |
|
protected: |
95 |
|
vector<double> currentGrad; |
96 |
|
}; |
97 |
|
|
98 |
< |
class NLF1 : NLModel1{ |
98 |
> |
//concrete class of nonlinear optimization model with first derivatives |
99 |
> |
class ConcreteNLMode1 : NLModel1{ |
100 |
|
public: |
101 |
< |
NLModel1(int dim, ObjFunctor1* func , ConstraintList* cons = NULL); |
102 |
< |
NLModel1(int dim, ConstraintList* cons = NULL); |
101 |
> |
ConcreteNLMode1(int dim, ObjFunctor1* func , ConstraintList* cons = NULL); |
102 |
> |
ConcreteNLMode1(int dim, ConstraintList* cons = NULL); |
103 |
|
|
104 |
|
virtual double calcF(); |
105 |
|
virtual double calcF(const vector<double>& x); |