ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/NLModel.hpp
(Generate patch)

Comparing trunk/OOPSE/libmdtools/NLModel.hpp (file contents):
Revision 996 by tim, Wed Jan 28 22:44:44 2004 UTC vs.
Revision 1010 by tim, Tue Feb 3 20:43:08 2004 UTC

# Line 3 | Line 3
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{
22    public:    
23      NLModel(ConstraintList* cons) {constraints = cons;}
24      virtual ~NLModel() {  if (constraints != NULL) delete constraints;}
25 +
26      virtual void setX(const vector<double>& x)= 0;
27  
28 <    virtual void setF(const vector<double>& fx)= 0;
28 >    virtual int  getDim() {return ndim;}
29  
27    virtual int  getDim() const = 0;
28
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;
# Line 46 | Line 47 | class NLModel{
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;
# Line 66 | Line 68 | class NLModel0 : public NLModel{
68      NLModel0(int dim,  ConstraintList* cons = NULL);
69      ~NLModel0() {}
70  
71 <  protected:
71 >    virtual void setX(const vector<double>& x);
72  
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>& sx);
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 currentF;
89   };
90  
91 + //concrete class of nonlinear optimization model without derivatives
92 +
93 + class ConcreteNLMode0 : public NLModel0{
94 +
95 +  public:
96 +
97 +    ConcreteNLMode0(int dim, ObjFunctor0* func ,  ConstraintList* cons = NULL);
98 +    ConcreteNLMode0(int dim, ConstraintList* cons = NULL);
99 +
100 +    virtual double calcF();
101 +    virtual double calcF(const vector<double>& x);
102 +    virtual vector<double> calcGrad();
103 +    virtual vector<double> calcGrad(vector<double>& x);
104 +    virtual SymMatrix calcHessian() ;
105 +    virtual SymMatrix calcHessian(vector<double>& x) ;
106 +    
107 +  protected:
108 +
109 +    ObjFunctor0* objfunc;
110 +
111 + };
112 +
113   //abstract class of nonlinear optimization model with first derivatives
114   class NLModel1 : public NLModel0{
115 +
116    public:
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 ForwardHessian(vector<double>& sx);
120 >    virtual SymMatrix FiniteHessian(vector<double>& x, vector<double>& h);
121      
122    protected:
123 +
124      vector<double> currentGrad;
125   };
126  
127   //concrete class of nonlinear optimization model with first derivatives
128   class ConcreteNLMode1 : NLModel1{
129 +
130    public:
131 +
132      ConcreteNLMode1(int dim, ObjFunctor1* func ,  ConstraintList* cons = NULL);
133      ConcreteNLMode1(int dim, ConstraintList* cons = NULL);
134      
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  
142    protected:
143 +
144      ObjFunctor1* objfunc;
145   };
146  
115
147   /*
148 + //abstract class of nonlinear optimization model with second derivatives
149   class NLModel2 : public NLModel1{
150    public:
151 +    
152 +  protected:    
153 +    SymMatrix currentHessian;
154  
155 <    NLModel2(int dim, ObjFunctor2* func ,  ConstraintList* cons = NULL);
156 <    ~NLModel2() {}  
155 > };
156 >
157 > //concrete class of nonlinear optimization model with second derivatives
158 > class ConcreteNLModel2 : public NLModel2{
159 >  public:
160 >
161 >    ConcreteNLModel2(int dim, ObjFunctor2* func ,  ConstraintList* cons = NULL);
162 >    ConcreteNLModel2(int dim, ConstraintList* cons = NULL);
163      
164      virtual double calcF();
165      virtual double calcF(const vector<double>& x);
# Line 129 | Line 170 | class NLModel2 : public NLModel1{
170      
171    protected:
172      
132    SymMatrix hessian;
173      ObjFunctor2* objFunc;
174   };
175   */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines