ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/group/trunk/OOPSE/libmdtools/Constraint.hpp
Revision: 987
Committed: Tue Jan 27 19:15:20 2004 UTC (20 years, 5 months ago) by tim
File size: 2675 byte(s)
Log Message:
revision of constraint for Nonlinear Optimization Model

File Contents

# User Rev Content
1 tim 987 #ifndef _CONSTRAINT_H_
2     #define _CONSTRAINT_H_
3    
4     #include <vector>
5    
6     #include "NLModel.hpp"
7    
8     #define ERROR_CONSTRAINT 10
9    
10     using namespace std;
11    
12     enum ConsType {simpleBound = 1, linearEqu = 2, linearInequ = 4,
13     nonlinearEqu = 8, nonlinearInequ =16};
14    
15     enum BoundType{upper, lower, equ};
16    
17     class ConstraintBase{
18     public:
19     ConstraintBase();
20     ConstraintBase(int dim);
21    
22     virtual void setDim(int dim);
23     bool isDimSet();
24    
25     int getConsType() { return consType};
26     virtual double calcResidual(vector<double>& x) = 0;
27     virtual vector<double> calcConsGrad(vector<double>& x) = 0;
28     virtual SymMatrix calcConsHessian(vector<double>& x) = 0;
29    
30     protected:
31    
32     bool init_ndim;
33     int ndim;
34    
35     double bound;
36     BoundType boundType;
37     ConsType consType;
38    
39     };
40    
41     class SimpleBoundCons : public ConstraintBase{
42     public:
43    
44     SimpleBoundCons(int theIndex, double b, bool flag);
45     SimpleBoundCons(int dim, int theIndex, double b, bool flag);
46    
47     virtual double calcResidual(vector<double>& x);
48     virtual vector<double> calcConsGrad(vector<double>& x);
49     virtual SymMatrix calcConsHessian(vector<double>& x);
50    
51     protected:
52    
53     int index;
54     };
55    
56     class LinearCons : public ConstraintBase{
57    
58     public:
59    
60     LinearCons(vector<int>& theIndex, vector<double>& , double b, BoundType bType);
61     LinearCons(int dim, vector<int>& theIndex, vector<double>& , double b, BoundType bType);
62     virtual double calcResidual(vector<double>& x);
63     virtual vector<double> calcConsGrad(vector<double>& x);
64     virtual SymMatrix calcConsHessian(vector<double>& x);
65    
66     protected:
67    
68     vector<int> index;
69     vector<double> coeff;
70     };
71    
72     class NonlinearCons : public ConstraintBase{
73    
74     public:
75     NonLinearCons(vector<int>& theIndex, NLModel* theModel , double b, BoundType bType);
76     NonLinearCons(int dim, vector<int>& theIndex, NLModel* theModel , double b, BoundType bType);
77    
78     void setDim(int dim);
79    
80     virtual double calcResidual(vector<double>& x);
81     virtual vector<double> calcConsGrad(vector<double>& x);
82     virtual SymMatrix calcConsHessian(vector<double>& x);
83    
84     protected:
85    
86     vector<int> index;
87     NLModel* model;
88    
89     };
90    
91     class ConstraintList{
92     public:
93     ConstraintList();
94     ~ConstraintList();
95    
96     addConstraint(ConstraintBase* cons);
97     int getNumOfCons() {return constraints.size();}
98     int getConsType() {return consType;}
99     vector<ConstraintBase*> getConstraints() {return constraints;}
100    
101     protected:
102    
103     vector<ConstraintBase*> constraints;
104     int consType;
105     };
106    
107     #endif

Properties

Name Value
svn:executable *