////////////////////////////////////////////////////////////////////// // // Constraints.h: interface of the Constaints class. // // Written By: Matthias Wacker // ////////////////////////////////////////////////////////////////////// #ifndef _CONSTRAINTS_H_ #define _CONSTRAINTS_H_ #include "core/optimization/blackbox/Definitions_core_opt.h" namespace opt=OPTIMIZATION; /*! class Abstract base class for all constraints. */ class Constraints { public: typedef OPTIMIZATION::matrix_type matrix_type; /*! default constructor */ Constraints(); /*! Constructor. \param numOfParameters \param numOfConstraints */ Constraints(unsigned int numOfParameters, unsigned int numOfConstraints); /* Copy constructor \param con the constraint to copy */ Constraints(const Constraints &con); /*! Destructor. */ virtual ~Constraints(); /*! get Number of Parameters \return the number of parameters */ inline unsigned int getNumOfParameters(){return m_numOfParameters;}; /*! get Number of Constraints \return the number of Constraints */ inline unsigned int getNumOfConstraints(){return m_numOfConstraints;}; /*! do the constraints provide analytic gradient computation? \return true if they do */ inline bool hasAnalyticGradient(){return m_hasAnalyticGradient;}; /*! get the analytic gradient \param x =^ position \return matrix_type =[gradConstraint(i,j)]_{i,j=(0,0)}^{(m_numOfParameters,m_numOfConstraints)} where (i,j) indicates the i-th component of the j-th Constraint */ virtual const matrix_type getAnalyticGradient(const matrix_type &x); /*! do the constraints provide analytic hessian computation? \return true if they do */ inline bool hasAnalyticHessian(){return m_hasAnalyticHessian;}; /*! get the analytic hessian(s) \param x =^ position \return matrix_type =[hessianConstraint(i,j)]_{i,j=(0,0)}^{(m_numOfParameters, m_numOfParameters * m_numOfConstraints)} where (i,j) indicates the (i,[j%m_numOfConstraints])-th component of the Hessian of the ground(j/m_numOfConstraints)-th Constraint where gound means cuttung the number after '.' example: 2 dimensional parameters 3 constraints return= [H_1(i,j), H_2(i,j), H_3(i,j)], where H_v are matrices of 2x2: [h_1_1,1 h_1_1,2 h_2_1,1 h_2_1,2 h_3_1,1 h_3_1,2 h_1_2,1 h_1_2,2 h_2_2,1 h_2_2,2 h_3_2,1 h_3_2,2 ] */ virtual const matrix_type getAnalyticHessian(const matrix_type & x); /*! weight handling: setWeightVector Set a weight vector for normalization of the constraint ranges. The value of the i-th constraint, gets multiplied with the i-th value of the weight vector. The weights have te be non-negative, but can be 0 to disable the i-th constraint The default is [1,1, ... , 1] what weights the constraints equally. \param weight \returns true, if everything went fine */ bool setWeightVector(const matrix_type weights); /*! get the weight vector */ inline matrix_type getWeightVector(){return m_weights;}; /*! Initialization for the cost function */ virtual void init() = 0; /*! evaluate the constraints \param x =^ position \return matrix_type containing the i-th constraint result in the i-th component */ virtual matrix_type evaluate(const matrix_type & x) = 0; /*! set an x0 for 1dim line search \param x0 affine part of affine linear parameter space */ bool setX0(const matrix_type &x0); /*! set an h0 for 1dim line search \param h0 linear part of affine linear parameter space */ bool setH0(const matrix_type &H0); /*! evaluate 1dimension sub function fsub(lambda) = f(x0 + lambda * h0) \param lambda */ matrix_type evaluateSub(double lambda); protected: /*! number of parameters */ unsigned int m_numOfParameters; /*! number of constraints */ unsigned int m_numOfConstraints; /*! has analytic gradient ? */ bool m_hasAnalyticGradient; /*! has analytic hessian ? */ bool m_hasAnalyticHessian; /*! internal weight vector */ matrix_type m_weights; /*! x_0 */ matrix_type m_x_0; /*! direction h_0 */ matrix_type m_h_0; }; #endif