Bonmin 1.8.9
Loading...
Searching...
No Matches
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
20namespace Bonmin {
21
22struct TMat{
23 int * iRow_;
24 int * jCol_;
25 double * value_;
26 int nnz_;
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
51
53 TMat& operator=(const TMat &rhs);
54
57
64
66
69
71 const RowS & nonEmptyRows() const {
72 return nonEmptyRows_;}
73
76
78 const RowS & nonEmptyCols() const {
79 return nonEmptyCols_;}
80
81 private:
83 struct TMatOrdering{
84 TMat * M_;
85 TMatOrdering(TMat *M):
86 M_(M){}
87 };
88
90 struct ColumnOrder : public TMatOrdering {
91 ColumnOrder(TMat *M):
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 {
106 RowOrder(TMat *M):
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
132
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
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
A small wrap around std::vector to give easy access to array for interfacing with fortran code.
Definition BonTypes.hpp:9
(C) Copyright International Business Machines Corporation 2007
void resizeAndCopyArray(X *&array, unsigned int oldSize, unsigned int newSize)
MatrixStorageType
int numNonEmptyRows()
Get number of non empty rows.
double * value_
TMat()
Default constructor.
void removeDuplicates()
Remove the duplicated entries.
TMat & operator=(const CoinPackedMatrix &M)
Assignment from a CoinPackedMatrix.
const vector< int > & orderByColumns()
Orders current matrix by columns.
TMat(const CoinPackedMatrix &M, MatrixStorageType T)
Construct from a CoinPackedMatrix.
void resizeOrdering(vector< int > &ordering, unsigned int newSize)
void make_upper_triangular(const MatrixStorageType &T)
void create(const CoinPackedMatrix &M)
Create the TMat from M.
void make_full_upper_triangular()
int numNonEmptyCols()
Get number of non empty cols.
vector< int > columnOrdering_
void freeSpace()
void resize(int nnz)
const RowS & nonEmptyCols() const
Get the list of non empty row.
vector< std::pair< int, int > > RowS
Storage for non empty rows.
TMat(const TMat &other)
Copy constructor.
void makeQuadUpperDiag()
Assuming that this is representing a quadratic form.
void make_lower_to_be_upper()
const RowS & nonEmptyRows() const
Get the list of non empty row.
const vector< int > & orderByRows()
Orders current matrix by rows.
vector< int > rowOrdering_
TMat & operator=(const TMat &rhs)
Assignment operator.