--- trunk/OOPSE/libmdtools/Constraint.hpp 2004/01/28 20:40:26 995 +++ trunk/OOPSE/libmdtools/Constraint.hpp 2004/02/03 20:43:08 1010 @@ -1,18 +1,19 @@ #ifndef _CONSTRAINT_H_ #define _CONSTRAINT_H_ +#include #include -#include "NLModel.hpp" +#include "SymMatrix.hpp" #define ERROR_CONSTRAINT 10 using namespace std; -typedef enum ConsType {simpleBound = 1, linearEqu = 2, linearInequ = 4, - nonlinearEqu = 8, nonlinearInequ =16}; +typedef enum {simpleBound = 1, linearEqu = 2, linearInequ = 4, + nonlinearEqu = 8, nonlinearInequ =16} ConsType; -typedef enum BoundType{upper, lower, equ}; +typedef enum {btUpper, btLower, btEqu} BoundType; /** * Abstract class of constraint for nonlinear optimization problem @@ -25,7 +26,7 @@ class ConstraintBase{ virtual void setDim(int dim); bool isDimSet(); - int getConsType() { return consType}; + int getConsType() { return consType;} virtual double calcResidual(vector& x) = 0; virtual vector calcConsGrad(vector& x) = 0; virtual SymMatrix calcConsHessian(vector& x) = 0; @@ -41,87 +42,4 @@ class ConstraintBase{ }; -/** - * Simple Bound Constraint for nonlinear optimization problem - * boundType is used to identify whether it is upper bound or lower bound - */ -class SimpleBoundCons : public ConstraintBase{ - public: - - SimpleBoundCons(int theIndex, double b, bool flag); - SimpleBoundCons(int dim, int theIndex, double b, bool flag); - - virtual double calcResidual(vector& x); - virtual vector calcConsGrad(vector& x); - virtual SymMatrix calcConsHessian(vector& x); - - protected: - - int index; -}; - -/** - * Linear Constraint for nonlinear optimization problem - * boundType is used to identify whether it is linear equation constraint or linear inequality - * constraint. If it is inear inequality constraint - */ - -class LinearCons : public ConstraintBase{ - - public: - - LinearCons(vector& theIndex, vector& , double b, BoundType bType); - LinearCons(int dim, vector& theIndex, vector& , double b, BoundType bType); - virtual double calcResidual(vector& x); - virtual vector calcConsGrad(vector& x); - virtual SymMatrix calcConsHessian(vector& x); - - protected: - - vector index; - vector coeff; -}; - -/** - * Linear Constraint for nonlinear optimization problem - * boundType is used to identify whether it is linear equality constraint or linear inequality - * constraint - */ - - -class NonlinearCons : public ConstraintBase{ - - public: - NonLinearCons(vector& theIndex, NLModel* theModel , double b, BoundType bType); - NonLinearCons(int dim, vector& theIndex, NLModel* theModel , double b, BoundType bType); - - void setDim(int dim); - - virtual double calcResidual(vector& x); - virtual vector calcConsGrad(vector& x); - virtual SymMatrix calcConsHessian(vector& x); - - protected: - - vector index; - NLModel* model; - -}; - -class ConstraintList{ - public: - ConstraintList(); - ~ConstraintList(); - - addConstraint(ConstraintBase* cons); - int getNumOfCons() {return constraints.size();} - int getConsType() {return consType;} - vector getConstraints() {return constraints;} - - protected: - - vector constraints; - int consType; -}; - #endif