LinearConstraintHandlerPenalty.hh 3.13 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
//=============================================================================
//
//  CLASS LinearConstraintHandlerElimination
//
//=============================================================================


#ifndef COMISO_LINEARCONSTRAINTHANDLERPENALTY_HH
#define COMISO_LINEARCONSTRAINTHANDLERPENALTY_HH


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

#include <CoMISo/Config/CoMISoDefines.hh>
#include <iostream>
16
DISABLE_BANNED_COMPLIANCE
17
#include <gmm/gmm.h>
18
ENABLE_BANNED_COMPLIANCE
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
//== FORWARDDECLARATIONS ======================================================

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

namespace COMISO {

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



	      
/** \class LinearConstraintHandler LinearConstraintHandler.hh <ACG/.../LinearConstraintHandler.hh>

    Brief Description.
  
    A more elaborate description follows.
*/


class COMISODLLEXPORT LinearConstraintHandlerPenalty
{
public:
   
  typedef gmm::col_matrix< gmm::wsvector< double> > CMatrix;
  typedef gmm::row_matrix< gmm::wsvector< double> > RMatrix;

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

  /// Constructor
  LinearConstraintHandlerPenalty();

  // initialize Constructor
  template<class MatrixT, class VectorT>
  LinearConstraintHandlerPenalty( const MatrixT& _C, const VectorT& _c);
 
  /// Destructor
  ~LinearConstraintHandlerPenalty();

  // penalty weight
  double& penalty();

  // number of variables
  int n();

  // number of linearly independent constraints (n-n_reduced)
  int n_constraints();

  // initialize new constraints
  template<class MatrixT, class VectorT>
  void initialize( const MatrixT& _C, const VectorT& _c);

  // initialize new constraints rhs only
  void initialize( const std::vector<double>& _c);
  void initialize( double* _c);

  // transform energy
  double add_penalty_f( double* _x, const double _f);

  // transform gradient
  void add_penalty_gradient( const std::vector<double>& _x, std::vector<double>& _g);
  void add_penalty_gradient( double* _x, double* _g);

  // transform hessian
  void add_penalty_hessian( RMatrix& _H);

private:
  // penalty weight
  double penalty_;
  
  // Linear Constraints C_*x_ = b_
  RMatrix             C_;
  std::vector<double> b_;

  // precomputed penalty terms
  RMatrix penalty_H_;
  std::vector<double> penalty_grad_b_;

  // temp vector
  std::vector<double> temp_;

  // number of variables
  int n_;
  // number of constraints (linear independent)
  int m_;
};

//=============================================================================
} // namespace COMISO
//=============================================================================
#if defined(INCLUDE_TEMPLATES) && !defined(ACG_LINEARCONSTRAINTHANDLERPENALTY_C)
#define ACG_LINEARCONSTRAINTHANDLERPENALTY_TEMPLATES
#include "LinearConstraintHandlerPenaltyT.cc"
#endif
//=============================================================================
#endif // ACG_LINEARCONSTRAINTHANDLERPENALTY_HH defined
//=============================================================================