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:
35  QuadRow();
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 
50  QuadRow(const OsiRowCut &cut);
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_;
98  CoinPackedVector a_;
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 
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_;
120 };
121 }//End Bonmin namespace
122 #endif
std::pair< int, int > matIdx
Store the number of times entry is used and its index in the matrix.
Definition: BonQuadRow.hpp:22
CoinPackedVector a_
linear term in sparse storage.
Definition: BonQuadRow.hpp:98
double lb_
lower bound.
Definition: BonQuadRow.hpp:92
bool isLinear()
Says if the constraint is linear.
Definition: BonQuadRow.hpp:70
void internal_eval_grad(const double *x)
Does internal work to evaluate gradiant of this in x.
std::vector< AdjustableMat::iterator > Q_hessian_idx_
To have fast access to entries in full hessian of Q_.
Definition: BonQuadRow.hpp:117
TMat Q_
Quadratic term.
Definition: BonQuadRow.hpp:100
std::vector< gStore::iterator > a_grad_idx_
To have fast access to gradiant entries for a_.
Definition: BonQuadRow.hpp:111
std::vector< gStore::iterator > Q_col_grad_idx_
To have fast access to gradient entries for cols Q_.
Definition: BonQuadRow.hpp:115
void eval_grad(const int nnz, const double *x, bool new_x, double *values)
Evaluate gradiant of quadratic form.
void remove_from_hessian(AdjustableMat &H)
Remove row from a bigger hessian.
double eval_f(const double *x, bool new_x)
Evaluate quadratic form.
void add_to_hessian(AdjustableMat &H, bool offset)
Add row to a bigger hessian.
QuadRow()
Default constructor.
std::vector< gStore::iterator > Q_row_grad_idx_
To have fast access to gradient entries for rows Q_.
Definition: BonQuadRow.hpp:113
Stores a quadratic row of the form l &lt; c + ax + x^T Q x &lt; u.
Definition: BonQuadRow.hpp:32
QuadRow & operator=(const QuadRow &rhs)
Assignment operator.
std::pair< int, int > matEntry
Store column and row of the entry.
Definition: BonQuadRow.hpp:20
int nnz_grad()
Get number of non-zeroes in the gradiant.
void gradiant_struct(const int nnz, int *indices, bool offset)
Get structure of gradiant.
void initialize()
Initialize once quadratic form is know.
bool grad_evaled_
Flag indicating if gradiant has been evaluated.
Definition: BonQuadRow.hpp:119
void eval_hessian(double lambda, double *values)
Return hessian value (i.e.
std::map< int, std::pair< double, double > > gStore
Definition: BonQuadRow.hpp:106
std::map< matEntry, matIdx > AdjustableMat
Definition: BonQuadRow.hpp:26
double c_
Constant term.
Definition: BonQuadRow.hpp:96
int nnz_hessian()
number of non-zeroes in hessian.
Definition: BonQuadRow.hpp:66
void print()
Print quadratic constraint.
double ub_
upper bound.
Definition: BonQuadRow.hpp:94