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 995 by tim, Wed Jan 28 20:40:26 2004 UTC vs.
Revision 1010 by tim, Tue Feb 3 20:43:08 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 < typedef 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 < typedef enum BoundType{upper, lower, equ};
16 > typedef enum {btUpper, btLower, btEqu} BoundType;
17  
18   /**
19   * Abstract class of constraint for nonlinear optimization problem
# Line 25 | Line 26 | class ConstraintBase{
26      virtual void setDim(int dim);
27      bool isDimSet();
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 41 | Line 42 | class ConstraintBase{
42    
43   };
44  
44 /**
45 * Simple Bound Constraint for nonlinear optimization problem
46 * boundType is used to  identify whether it is upper bound or lower bound
47 */
48 class SimpleBoundCons : public ConstraintBase{
49  public:
50    
51    SimpleBoundCons(int theIndex, double b, bool flag);
52    SimpleBoundCons(int dim, int theIndex, double b, bool flag);
53    
54     virtual double calcResidual(vector<double>& x);
55    virtual vector<double> calcConsGrad(vector<double>& x);
56    virtual SymMatrix calcConsHessian(vector<double>& x);
57
58  protected:
59  
60    int index;    
61 };
62
63 /**
64 * Linear Constraint for nonlinear optimization problem
65 * boundType is used to  identify whether it is linear equation constraint or linear inequality
66 * constraint. If it is inear inequality constraint
67 */
68
69 class LinearCons : public ConstraintBase{
70
71  public:
72
73    LinearCons(vector<int>& theIndex, vector<double>& , double b, BoundType bType);
74    LinearCons(int dim, vector<int>& theIndex, vector<double>& , double b, BoundType bType);
75    virtual double calcResidual(vector<double>& x);
76    virtual vector<double> calcConsGrad(vector<double>& x);
77    virtual SymMatrix calcConsHessian(vector<double>& x);
78
79  protected:
80    
81    vector<int> index;
82    vector<double> coeff;
83 };
84
85 /**
86 * Linear Constraint for nonlinear optimization problem
87 * boundType is used to  identify whether it is linear equality constraint or linear inequality
88 * constraint
89 */
90
91
92 class NonlinearCons : public ConstraintBase{
93
94  public:
95    NonLinearCons(vector<int>& theIndex, NLModel* theModel , double b, BoundType bType);
96    NonLinearCons(int dim, vector<int>& theIndex, NLModel* theModel , double b, BoundType bType);
97
98    void setDim(int dim);
99    
100    virtual double calcResidual(vector<double>& x);
101    virtual vector<double> calcConsGrad(vector<double>& x);
102    virtual SymMatrix calcConsHessian(vector<double>& x);
103    
104  protected:
105    
106    vector<int> index;
107    NLModel* model;
108
109 };
110
111 class ConstraintList{
112  public:
113    ConstraintList();
114    ~ConstraintList();
115
116    addConstraint(ConstraintBase* cons);
117    int getNumOfCons() {return constraints.size();}
118    int getConsType() {return consType;}
119    vector<ConstraintBase*> getConstraints() {return constraints;}  
120
121  protected:
122
123    vector<ConstraintBase*> constraints;
124    int consType;
125 };
126
45   #endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines