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


#ifndef COMISO_LINEARCONSTRAINT_HH
#define COMISO_LINEARCONSTRAINT_HH


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

David Bommes's avatar
David Bommes committed
14
#include "NConstraintInterface.hh"
David Bommes's avatar
David Bommes committed
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31

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

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

namespace COMISO {

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

	      

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

    Brief Description.
  
    A more elaborate description follows.
*/
David Bommes's avatar
David Bommes committed
32
class LinearConstraint : public NConstraintInterface
David Bommes's avatar
David Bommes committed
33
34
35
36
37
38
39
40
41
42
{
public:

  // use c-arrays as vectors for gmm
  typedef gmm::array1D_reference<double*> VectorPT;

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

  /// Default constructor
David Bommes's avatar
David Bommes committed
43
  LinearConstraint(const ConstraintType _type = NC_EQUAL) : NConstraintInterface(_type)
David Bommes's avatar
David Bommes committed
44
45
  {}

46
  // linear equation of the form -> coeffs_^T *x  + b_=_type= 0
David Bommes's avatar
David Bommes committed
47
  LinearConstraint(const SVectorNC& _coeffs, const double _b, const ConstraintType _type = NC_EQUAL) : NConstraintInterface(_type)
David Bommes's avatar
David Bommes committed
48
  {
David Bommes's avatar
David Bommes committed
49
    coeffs_ = _coeffs;
David Bommes's avatar
David Bommes committed
50
51
52
53
54
55
56
57
    b_ = _b;
  }

  /// Destructor
  ~LinearConstraint() {}

  virtual int n_unknowns()
  {
David Bommes's avatar
David Bommes committed
58
    return coeffs_.innerSize();
David Bommes's avatar
David Bommes committed
59
60
  }

61
62
63
  SVectorNC& coeffs() { return coeffs_;}
  double&    b()      { return b_;}

David Bommes's avatar
David Bommes committed
64
65
  virtual double eval_constraint ( const double* _x )
  {
David Bommes's avatar
David Bommes committed
66
67
68
69
70
71
72
    double v = b_;

    SVectorNC::InnerIterator c_it(coeffs_);
    for(; c_it; ++c_it)
      v += c_it.value()*_x[c_it.index()];

    return v;
David Bommes's avatar
David Bommes committed
73
74
  }

David Bommes's avatar
David Bommes committed
75
  virtual void eval_gradient( const double* _x, SVectorNC& _g      )
David Bommes's avatar
David Bommes committed
76
  {
David Bommes's avatar
David Bommes committed
77
    _g = coeffs_;
David Bommes's avatar
David Bommes committed
78
79
  }

David Bommes's avatar
David Bommes committed
80
  virtual void eval_hessian    ( const double* _x, SMatrixNC& _h      )
David Bommes's avatar
David Bommes committed
81
  {
David Bommes's avatar
David Bommes committed
82
83
    _h.clear();
    _h.resize(coeffs_.innerSize(), coeffs_.innerSize());
David Bommes's avatar
David Bommes committed
84
85
86
87
88
89
90
91
  }

  // 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
92
  SVectorNC coeffs_;
David Bommes's avatar
David Bommes committed
93
94
95
96
97
98
99
100
101
102
  double    b_;
};


//=============================================================================
} // namespace COMISO
//=============================================================================
#endif // ACG_LINEARCONSTRAINT_HH defined
//=============================================================================