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

Comparing trunk/OOPSE/libmdtools/Constraint.hpp (file contents):
Revision 987 by tim, Tue Jan 27 19:15:20 2004 UTC vs.
Revision 1023 by tim, Wed Feb 4 22:26:00 2004 UTC

# Line 1 | Line 1
1   #ifndef _CONSTRAINT_H_
2   #define _CONSTRAINT_H_
3  
4 + #include <iostream>
5   #include <vector>
6  
7 < #include "NLModel.hpp"
7 > #include "SymMatrix.hpp"
8  
9   #define ERROR_CONSTRAINT 10
10  
11   using namespace std;
12  
13 < enum ConsType {simpleBound = 1, linearEqu = 2, linearInequ = 4,
14 <                                     nonlinearEqu = 8, nonlinearInequ =16};
13 > typedef enum  {simpleBound = 1, linearEqu = 2, linearInequ = 4,
14 >                                     nonlinearEqu = 8, nonlinearInequ =16} ConsType;
15  
16 < enum BoundType{upper, lower, equ};
16 > typedef enum {btUpper, btLower, btEqu} BoundType;
17  
18 + /**
19 + * Abstract class of constraint for nonlinear optimization problem
20 + */
21   class ConstraintBase{
22    public:
23      ConstraintBase();
24      ConstraintBase(int dim);
25  
26      virtual void setDim(int dim);
27 <    bool isDimSet();
27 >    bool isDimSet() {return init_ndim;}
28      
29 <    int getConsType() { return consType};
29 >    int getConsType() { return consType;}
30      virtual double calcResidual(vector<double>& x) = 0;
31      virtual vector<double> calcConsGrad(vector<double>& x) = 0;
32      virtual SymMatrix calcConsHessian(vector<double>& x) = 0;
# Line 38 | Line 42 | class SimpleBoundCons : public ConstraintBase{
42    
43   };
44  
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
45   #endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines