Bonmin  1.8.8
BonTMatrix.hpp
Go to the documentation of this file.
1 // (C) Copyright International Business Machines Corporation 2007
2 // 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 BonTMatrix_H
11 #define BonTMatrix_H
12 
13 #include "CoinPackedMatrix.hpp"
14 #include "BonArraysHelpers.hpp"
15 #include <vector>
16 #include <list>
17 #include <algorithm>
18 #include "BonQuadCut.hpp"
19 
20 namespace Bonmin {
21 
22 struct TMat{
23  int * iRow_;
24  int * jCol_;
25  double * value_;
26  int nnz_;
27  int capacity_;
28 
29 
33 
35  TMat(): iRow_(NULL), jCol_(NULL), value_(NULL), nnz_(0),
36  capacity_(0)
37  {}
38 
39 
40  void freeSpace(){
41  delete [] iRow_;
42  delete [] jCol_;
43  delete [] value_;
44  }
45 
47  TMat(const TMat &other);
48 
50  TMat(const CoinPackedMatrix &M, MatrixStorageType T);
51 
53  TMat& operator=(const TMat &rhs);
54 
56  TMat & operator=(const CoinPackedMatrix &M);
57 
58  void resize(int nnz){
62  nnz_ = nnz;
63  }
64 
65  ~TMat();
66 
68  int numNonEmptyRows();
69 
71  const RowS & nonEmptyRows() const {
72  return nonEmptyRows_;}
73 
75  int numNonEmptyCols();
76 
78  const RowS & nonEmptyCols() const {
79  return nonEmptyCols_;}
80 
81  private:
83  struct TMatOrdering{
84  TMat * M_;
86  M_(M){}
87  };
88 
90  struct ColumnOrder : public TMatOrdering {
92  TMatOrdering(M){}
93 
94  bool operator()(const int& i, const int& j){
95  if (M_->jCol_[i] < M_->jCol_[j])
96  return true;
97  if (M_->jCol_[i] == M_->jCol_[j] && M_->iRow_[i] < M_->iRow_[j])
98  return true;
99  return false;
100  }
101  };
102 
103 
105  struct RowOrder : public TMatOrdering {
107  TMatOrdering(M){}
108  bool operator()(const int& i, const int& j){
109  if (M_->iRow_[i]< M_->iRow_[j])
110  return true;
111  if (M_->iRow_[i] == M_->iRow_[j] && M_->jCol_[i] < M_->jCol_[j])
112  return true;
113  return false;
114  }
115  };
116  public:
120  std::sort(columnOrdering_.begin(), columnOrdering_.end(),ColumnOrder(this));
121  return columnOrdering_;
122  }
126  std::sort(rowOrdering_.begin(), rowOrdering_.end(), RowOrder(this));
127  return rowOrdering_;
128  }
129 
131  void removeDuplicates();
132 
135  void makeQuadUpperDiag();
136 
137  void resizeOrdering(vector<int> &ordering, unsigned int newSize){
138  size_t oldSize = ordering.size();
139  ordering.resize(newSize);
140  for(size_t i = oldSize ; i < newSize ; i++)
141  ordering[i] = static_cast<int>(i);
142  }
143 
145  void create(const CoinPackedMatrix &M);
146 
148 
150 
152 
153  void make_lower_to_be_upper();
154 
156 
157  // Stores non empty rows for computing jacobian structure
159 
160  // Stores non empty cols for computing jacobian structure
162  };
163 
164 }//Ends Bonmin namespace
165 
166 #endif
167 
void make_lower_to_be_upper()
int numNonEmptyCols()
Get number of non empty cols.
void make_upper_triangular(const MatrixStorageType &T)
void resize(int nnz)
Definition: BonTMatrix.hpp:58
A small wrap around std::vector to give easy access to array for interfacing with fortran code...
Definition: BonTypes.hpp:9
vector< int > rowOrdering_
Definition: BonTMatrix.hpp:149
RowS nonEmptyCols_
Definition: BonTMatrix.hpp:161
bool operator()(const int &i, const int &j)
Definition: BonTMatrix.hpp:94
TMat & operator=(const TMat &rhs)
Assignment operator.
const vector< int > & orderByColumns()
Orders current matrix by columns.
Definition: BonTMatrix.hpp:118
TMat()
Default constructor.
Definition: BonTMatrix.hpp:35
MatrixStorageType
Definition: BonQuadCut.hpp:22
const vector< int > & orderByRows()
Orders current matrix by rows.
Definition: BonTMatrix.hpp:124
void makeQuadUpperDiag()
Assuming that this is representing a quadratic form.
RowS nonEmptyRows_
Definition: BonTMatrix.hpp:158
void make_full_upper_triangular()
void resizeOrdering(vector< int > &ordering, unsigned int newSize)
Definition: BonTMatrix.hpp:137
double * value_
Definition: BonTMatrix.hpp:25
const RowS & nonEmptyCols() const
Get the list of non empty row.
Definition: BonTMatrix.hpp:78
Structure for ordering matrix by columns.
Definition: BonTMatrix.hpp:105
bool operator()(const int &i, const int &j)
Definition: BonTMatrix.hpp:108
vector< int > columnOrdering_
Definition: BonTMatrix.hpp:147
Structure for ordering matrix by columns.
Definition: BonTMatrix.hpp:90
const RowS & nonEmptyRows() const
Get the list of non empty row.
Definition: BonTMatrix.hpp:71
vector< std::pair< int, int > > RowS
Storage for non empty rows.
Definition: BonTMatrix.hpp:32
void freeSpace()
Definition: BonTMatrix.hpp:40
void removeDuplicates()
Remove the duplicated entries.
void resizeAndCopyArray(X *&array, unsigned int oldSize, unsigned int newSize)
Structure for ordering matrix.
Definition: BonTMatrix.hpp:83
void create(const CoinPackedMatrix &M)
Create the TMat from M.
int numNonEmptyRows()
Get number of non empty rows.