| 3 |
|
|
| 4 |
|
#include <vector> |
| 5 |
|
#include <utility> |
| 6 |
+ |
#include <math.h> |
| 7 |
|
|
| 8 |
|
#include "SymMatrix.hpp" |
| 9 |
|
#include "Functor.hpp" |
| 10 |
+ |
#include "ConstraintList.hpp" |
| 11 |
|
|
| 12 |
|
using namespace std; |
| 13 |
|
|
| 14 |
|
|
| 15 |
< |
typedef enum FDType {backward, forward, central} ; |
| 15 |
> |
typedef enum {backward, forward, central} FDType; |
| 16 |
|
|
| 17 |
|
// special property of nonlinear object function |
| 18 |
< |
typedef enum NLOFProp{linear, quadratic, general}; |
| 18 |
> |
typedef enum {linear, quadratic, general} NLOFProp; |
| 19 |
|
|
| 20 |
|
//abstract class of nonlinear optimization model |
| 21 |
|
class NLModel{ |
| 25 |
|
|
| 26 |
|
virtual void setX(const vector<double>& x)= 0; |
| 27 |
|
|
| 28 |
< |
virtual int getDim() const = 0; |
| 28 |
> |
virtual int getDim() {return ndim;} |
| 29 |
|
|
| 30 |
|
bool hasConstraints() { return constraints == NULL ? false : true;} |
| 31 |
< |
int getConsType() { return constrains->getConsType();} |
| 31 |
> |
int getConsType() { return constraints->getConsType();} |
| 32 |
|
|
| 33 |
|
virtual double calcF() = 0; |
| 34 |
|
virtual double calcF(const vector<double>& x) = 0; |
| 47 |
|
protected: |
| 48 |
|
ConstraintList* constraints; //constraints of nonlinear optimization model |
| 49 |
|
int numOfFunEval; //number of function evaluation |
| 50 |
+ |
int ndim; |
| 51 |
|
|
| 52 |
|
#ifdef IS_MPI |
| 53 |
|
bool mpiInitFlag; |
| 73 |
|
//Using finite difference methods to approximate the gradient |
| 74 |
|
//It is inappropriate to apply these methods in large scale problem |
| 75 |
|
|
| 76 |
< |
vector<double> BackwardGrad(const vector<double>& x, double& fx, vector<double>& grad); |
| 77 |
< |
vector<double> ForwardGrad(const vector<double>& x, double& fx, vector<double>& grad); |
| 78 |
< |
vector<double> CentralGrad(const vector<double>& x, double& fx, vector<double>& grad); |
| 76 |
> |
vector<double> BackwardGrad(const vector<double>& x, double& fx, vector<double>& grad, const vector<double>& h); |
| 77 |
> |
vector<double> ForwardGrad(const vector<double>& x, double& fx, vector<double>& grad, const vector<double>& h); |
| 78 |
> |
vector<double> CentralGrad(const vector<double>& x, double& fx, vector<double>& grad, const vector<double>& h); |
| 79 |
|
|
| 80 |
|
//Using finite difference methods to approximate the hessian |
| 81 |
|
//It is inappropriate to apply this method in large scale problem |
| 82 |
< |
virtual SymMatrix FiniteHessian(vector<double>& x, double fx, vector<double>& h); |
| 82 |
> |
//virtual SymMatrix FiniteHessian(vector<double>& x, double fx, vector<double>& h); |
| 83 |
|
|
| 84 |
|
protected: |
| 85 |
|
|
| 86 |
|
FDType fdType; |
| 87 |
|
vector<double> currentX; |
| 88 |
< |
double curretF; |
| 88 |
> |
double currentF; |
| 89 |
|
}; |
| 90 |
|
|
| 91 |
|
//concrete class of nonlinear optimization model without derivatives |
| 117 |
|
|
| 118 |
|
//Using finite difference methods to approximate the hessian |
| 119 |
|
//It is inappropriate to apply this method in large scale problem |
| 120 |
< |
virtual SymMatrix FiniteHessian(vector<double>& x, double fx, vector<double>& h); |
| 120 |
> |
virtual SymMatrix FiniteHessian(vector<double>& x, vector<double>& h); |
| 121 |
|
|
| 122 |
|
protected: |
| 123 |
|
|
| 135 |
|
virtual double calcF(); |
| 136 |
|
virtual double calcF(const vector<double>& x); |
| 137 |
|
virtual vector<double> calcGrad(); |
| 138 |
< |
virtual vector<double> calcGrad(vector<double>& x); |
| 138 |
> |
virtual vector<double> calcGrad(const vector<double>& x); |
| 139 |
|
virtual SymMatrix calcHessian() ; |
| 140 |
|
virtual SymMatrix calcHessian(vector<double>& x) ; |
| 141 |
|
|