123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209 |
- //////////////////////////////////////////////////////////////////////
- //
- // 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
|