Bonmin  1.8.8
BonQuadRow.hpp
Go to the documentation of this file.
1 // All Rights Reserved.
3 // This code is published under the Eclipse Public License.
4 //
5 // Authors :
6 // Pierre Bonami, International Business Machines Corporation
7 //
8 // Date : 10/06/2007
9 
10 #ifndef BonQuadRow_H
11 #define BonQuadRow_H
12 
13 #include "CoinPackedVector.hpp"
14 #include "BonTMatrix.hpp"
15 #include "BonQuadCut.hpp"
16 
17 namespace Bonmin{
18 
20  typedef std::pair<int, int> matEntry;
22  typedef std::pair<int, int> matIdx;
23 #if HAS_HASH_MAP
24  typedef std::has_map<matEntry, matIdx, std::hash< matEntry> > AdjustableMat;
25 #else
26  typedef std::map<matEntry, matIdx> AdjustableMat;
27 #endif
28 
32 class QuadRow {
33  public:
36 
38  QuadRow(const QuadRow & other);
39 
41  QuadRow& operator=(const QuadRow& rhs);
42 
44  QuadRow(const QuadCut &cut);
45 
47  QuadRow& operator=(const QuadCut & rhs);
48 
51 
53  QuadRow& operator=(const OsiRowCut & rhs);
54 
56  double eval_f(const double *x, bool new_x);
57 
59  int nnz_grad();
61  void gradiant_struct(const int nnz, int * indices, bool offset);
63  void eval_grad(const int nnz, const double * x, bool new_x, double * values);
64 
66  int nnz_hessian(){
67  return Q_.nnz_;}
68 
70  bool isLinear(){
71  return Q_.nnz_ == 0;}
72 
74  void eval_hessian(double lambda, double * values);
75 
77  void add_to_hessian(AdjustableMat &H, bool offset);
78 
82 void print();
83 
84  private:
86  void initialize();
87 
89  void internal_eval_grad(const double *x);
90 
92  double lb_;
94  double ub_;
96  double c_;
100  TMat Q_;
101 
102 
103 #if HAS_HASH_MAP
104  typedef std::has_map<int, std::pair<double, double >, std::hash<int> > gStore;
105 #else
106  typedef std::map<int, std::pair<double, double> > gStore;
107 #endif
108 
109  gStore g_;
111  std::vector<gStore::iterator> a_grad_idx_;
113  std::vector<gStore::iterator> Q_row_grad_idx_;
115  std::vector<gStore::iterator> Q_col_grad_idx_;
117  std::vector<AdjustableMat::iterator> Q_hessian_idx_;
119  bool grad_evaled_;
120 };
121 }//End Bonmin namespace
122 #endif
Stores a quadratic row of the form l < c + ax + x^T Q x < u.
Definition: BonQuadRow.hpp:32
QuadRow(const OsiRowCut &cut)
Constructor from a linear cut.
void print()
Print quadratic constraint.
QuadRow & operator=(const OsiRowCut &rhs)
Assignment form a linear &cut.
double eval_f(const double *x, bool new_x)
Evaluate quadratic form.
QuadRow()
Default constructor.
void gradiant_struct(const int nnz, int *indices, bool offset)
Get structure of gradiant.
bool isLinear()
Says if the constraint is linear.
Definition: BonQuadRow.hpp:70
QuadRow(const QuadCut &cut)
Constructor from a quadratic cut.
QuadRow & operator=(const QuadRow &rhs)
Assignment operator.
void add_to_hessian(AdjustableMat &H, bool offset)
Add row to a bigger hessian.
int nnz_grad()
Get number of non-zeroes in the gradiant.
QuadRow(const QuadRow &other)
Copy constructor.
void eval_grad(const int nnz, const double *x, bool new_x, double *values)
Evaluate gradiant of quadratic form.
int nnz_hessian()
number of non-zeroes in hessian.
Definition: BonQuadRow.hpp:66
void remove_from_hessian(AdjustableMat &H)
Remove row from a bigger hessian.
QuadRow & operator=(const QuadCut &rhs)
Assignment form a quadrattic &cut.
void eval_hessian(double lambda, double *values)
Return hessian value (i.e.
(C) Copyright International Business Machines Corporation 2007
std::map< matEntry, matIdx > AdjustableMat
Definition: BonQuadRow.hpp:26
std::pair< int, int > matEntry
Store column and row of the entry.
Definition: BonQuadRow.hpp:20
std::pair< int, int > matIdx
Store the number of times entry is used and its index in the matrix.
Definition: BonQuadRow.hpp:22