LinearConstraint.hh 2.8 KB
Newer Older
David Bommes's avatar
David Bommes committed
1 2
//=============================================================================
//
3
//  CLASS LinearConstraint
David Bommes's avatar
David Bommes committed
4 5 6 7 8 9 10 11 12 13
//
//=============================================================================


#ifndef COMISO_LINEARCONSTRAINT_HH
#define COMISO_LINEARCONSTRAINT_HH


//== INCLUDES =================================================================

Jan Möbius's avatar
Jan Möbius committed
14
#include <CoMISo/Config/CoMISoDefines.hh>
David Bommes's avatar
David Bommes committed
15
#include "NConstraintInterface.hh"
David Bommes's avatar
David Bommes committed
16 17
#include <Eigen/StdVector>

David Bommes's avatar
David Bommes committed
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34

//== FORWARDDECLARATIONS ======================================================

//== NAMESPACES ===============================================================

namespace COMISO {

//== CLASS DEFINITION =========================================================

	      

/** \class NProblemGmmInterface NProblemGmmInterface.hh <ACG/.../NPRoblemGmmInterface.hh>

    Brief Description.
  
    A more elaborate description follows.
*/
Jan Möbius's avatar
Jan Möbius committed
35
class COMISODLLEXPORT LinearConstraint : public NConstraintInterface
David Bommes's avatar
David Bommes committed
36 37 38
{
public:

David Bommes's avatar
David Bommes committed
39
  // sparse vector type
Jan Möbius's avatar
Jan Möbius committed
40
  typedef NConstraintInterface::SVectorNC SVectorNC;
David Bommes's avatar
David Bommes committed
41 42 43 44 45

  // different types of constraints
//  enum ConstraintType {NC_EQUAL, NC_LESS_EQUAL, NC_GREATER_EQUAL};

  /// Default constructor
Jan Möbius's avatar
Jan Möbius committed
46
  LinearConstraint(const ConstraintType _type = NC_EQUAL);
David Bommes's avatar
David Bommes committed
47

48
  // linear equation of the form -> coeffs_^T *x  + b_=_type= 0
Jan Möbius's avatar
Jan Möbius committed
49
  LinearConstraint(const SVectorNC& _coeffs, const double _b, const ConstraintType _type = NC_EQUAL);
David Bommes's avatar
David Bommes committed
50 51

  /// Destructor
David Bommes's avatar
David Bommes committed
52
  virtual ~LinearConstraint();
David Bommes's avatar
David Bommes committed
53

Jan Möbius's avatar
Jan Möbius committed
54
  virtual int n_unknowns();
David Bommes's avatar
David Bommes committed
55

David Bommes's avatar
David Bommes committed
56
  // resize coefficient vector = #unknowns
David Bommes's avatar
David Bommes committed
57
  // maintain all values in range
David Bommes's avatar
David Bommes committed
58 59
  void  resize(const unsigned int _n);

David Bommes's avatar
David Bommes committed
60 61 62
  // clear to zero constraint 0 =_type 0
  void  clear();

David Bommes's avatar
David Bommes committed
63 64 65 66 67
  const SVectorNC& coeffs() const;
        SVectorNC& coeffs();

  const double&    b() const;
        double&    b();
68

Jan Möbius's avatar
Jan Möbius committed
69 70 71
  virtual double eval_constraint ( const double* _x );
  
  virtual void eval_gradient( const double* _x, SVectorNC& _g      );
David Bommes's avatar
David Bommes committed
72

Jan Möbius's avatar
Jan Möbius committed
73
  virtual void eval_hessian    ( const double* _x, SMatrixNC& _h      );
David Bommes's avatar
David Bommes committed
74

75 76 77
  virtual bool   is_linear()         const { return true;}
  virtual bool   constant_gradient() const { return true;}
  virtual bool   constant_hessian () const { return true;}
David Bommes's avatar
David Bommes committed
78

David Bommes's avatar
David Bommes committed
79 80 81 82 83 84
  // inherited from base
//  virtual ConstraintType  constraint_type (                                      ) { return type_; }

private:

  // linear equation of the form -> coeffs_^T * x + b_
David Bommes's avatar
David Bommes committed
85
  SVectorNC coeffs_;
David Bommes's avatar
David Bommes committed
86 87 88 89 90 91 92
  double    b_;
};


//=============================================================================
} // namespace COMISO
//=============================================================================
David Bommes's avatar
David Bommes committed
93 94 95
// support std vectors
EIGEN_DEFINE_STL_VECTOR_SPECIALIZATION(COMISO::LinearConstraint);
//=============================================================================
David Bommes's avatar
David Bommes committed
96 97 98
#endif // ACG_LINEARCONSTRAINT_HH defined
//=============================================================================