ConicBundle
SparseCoeffmatMatrix.hxx
Go to the documentation of this file.
1 
2 
3 #ifndef CONICBUNDLE_SPARSECOEFFMATMATRIX_HXX
4 #define CONICBUNDLE_SPARSECOEFFMATMATRIX_HXX
5 
13 #include "Coeffmat.hxx"
14 
15 namespace ConicBundle {
16 
17  class PSCPrimal;
18 
22 
24  typedef std::vector<CoeffmatPointer> CoeffmatVector;
26  typedef std::map<CH_Matrix_Classes::Integer,CoeffmatPointer> SparseCoeffmatVector;
27 
50  class SparseCoeffmatMatrix : virtual public CBout
51 {
52 public:
54  typedef std::map<CH_Matrix_Classes::Integer,SparseCoeffmatVector> SCMcolrep;
55 
56 private:
60 
62  typedef std::vector<SparseCoeffmatVector> SCMblockrep;
64  SCMblockrep blockrep;
65 
66 
67  mutable SCMcolrep* colrep;
68 
69 
71  void form_colrep() const;
72 
73 
74 public:
77 
79  void clear();
80 
82  int init(const CH_Matrix_Classes::Indexmatrix& block_dim,
84  const CH_Matrix_Classes::Indexmatrix* block_ind=0,
85  const CH_Matrix_Classes::Indexmatrix* col_ind=0,
86  const CoeffmatVector* coeff_vec=0);
87 
90  int incr=-1):
91  CBout(cb,incr),col_dim(0),blockrep(),colrep(0)
92  {clear();}
93 
96  int incr=-1):
97  CBout(cb,incr),col_dim(0),blockrep(),colrep(0)
98  { *this=S; }
99 
100 
103  CH_Matrix_Classes::Integer in_col_dim,
104  const CH_Matrix_Classes::Indexmatrix* block_ind=0,
105  const CH_Matrix_Classes::Indexmatrix* col_ind=0,
106  const CoeffmatVector* coeff_vec=0,
107  const CBout* cb=0,
108  int incr=-1):
109  CBout(cb,incr),col_dim(0),blockrep(),colrep(0)
110  { init(in_block_dim,in_col_dim,block_ind,col_ind,coeff_vec); }
111 
114 
115 
123  CH_Matrix_Classes::Integer rowdim() const {return block_dim.rowdim();}
126  {form_colrep(); return CH_Matrix_Classes::Integer(colrep->size()); }
127 
130 
133  {CoeffmatPointer cmp(cm); return set(i,j,cmp);}
134 
137 
139  const SparseCoeffmatVector* block(CH_Matrix_Classes::Integer i) const;
141  const SparseCoeffmatVector* column(CH_Matrix_Classes::Integer i) const;
142 
143 
148  int append_blocks(const SparseCoeffmatMatrix& append_mat,
149  const CH_Matrix_Classes::Indexmatrix* blocks=0,
150  const CH_Matrix_Classes::Indexmatrix* cols=0);
151 
156  int append_columns(const SparseCoeffmatMatrix& append_mat,
157  const CH_Matrix_Classes::Indexmatrix* blocks=0,
158  const CH_Matrix_Classes::Indexmatrix* cols=0);
159 
161  int reassign_blocks(const CH_Matrix_Classes::Indexmatrix& map_to_old);
163  int reassign_columns(const CH_Matrix_Classes::Indexmatrix& map_to_old);
164 
166  int delete_blocks(const CH_Matrix_Classes::Indexmatrix& delete_indices, CH_Matrix_Classes::Indexmatrix* map_to_old=0);
168  int delete_columns(const CH_Matrix_Classes::Indexmatrix& delete_indices, CH_Matrix_Classes::Indexmatrix* map_to_old=0);
169 
171  const SCMcolrep* get_colrep() const
172  { form_colrep(); return colrep;}
173 
176  { return dense_cnt(i);}
177 
179  bool operator==(const SparseCoeffmatMatrix& mat) const;
180 
182  bool operator!=(const SparseCoeffmatMatrix& mat) const
183  {return !(*this==mat);}
184 
187 
190 
192  int primal_ip(CH_Matrix_Classes::Matrix& ipvec,const PSCPrimal* primal,const CH_Matrix_Classes::Indexmatrix* ind=0) const;
193 
195  int primal_ip(CH_Matrix_Classes::Real& value,const PSCPrimal* primal,CH_Matrix_Classes::Integer j) const;
196 
199 
200 
201 };
202 
203 
205 }
206 
207 #endif
208 
int Integer
all integer numbers in calculations and indexing are of this type
Definition: matop.hxx:40
Header declaring the classes ConicBundle::Coeffmat, ConicBundle::CoeffmatPointer, ConicBundle::Coeffm...
void form_colrep() const
rebuilds the column representation from the block representation (if needed)
double Real
all real numbers in calculations are of this type
Definition: matop.hxx:50
const SCMcolrep * get_colrep() const
returns the column representation of the matrix
Definition: SparseCoeffmatMatrix.hxx:171
bool operator==(const SparseCoeffmatMatrix &mat) const
useful for testing purposes; true iff both have the same size and both have the same pointers in the ...
CoeffmatPointer operator()(CH_Matrix_Classes::Integer i, CH_Matrix_Classes::Integer j) const
returns the CoeffmatPointer of block i in column j (blockdiagonal matrix j) (may be empty) ...
defines a base class for coefficient matrices in semidefinite programming, in particular for use with...
Definition: Coeffmat.hxx:125
int delete_blocks(const CH_Matrix_Classes::Indexmatrix &delete_indices, CH_Matrix_Classes::Indexmatrix *map_to_old=0)
generates a map_to_old by deleting the specified indices and calls reassign_blocks; this map_to_old w...
Matrix class for integral values of type Integer
Definition: indexmat.hxx:195
int reassign_columns(const CH_Matrix_Classes::Indexmatrix &map_to_old)
afterwards the new column i is the previous column map_to_old(i); no multiple appearances are allowed...
int delete_columns(const CH_Matrix_Classes::Indexmatrix &delete_indices, CH_Matrix_Classes::Indexmatrix *map_to_old=0)
generates a map_to_old by deleting the specified indices and calls reassign_columns; this map_to_old ...
int init(const CH_Matrix_Classes::Indexmatrix &block_dim, CH_Matrix_Classes::Integer col_dim, const CH_Matrix_Classes::Indexmatrix *block_ind=0, const CH_Matrix_Classes::Indexmatrix *col_ind=0, const CoeffmatVector *coeff_vec=0)
first calls clear() and then it sets the new values (if one of block_ind, col_ind, or coeff_vec is !=NULL, all must be !=NULL and of the same size)
int primal_ip(CH_Matrix_Classes::Matrix &ipvec, const PSCPrimal *primal, const CH_Matrix_Classes::Indexmatrix *ind=0) const
computes the inner products of (selected) columns (which represent block diagonal symmetric matrices)...
Matrix class of symmetric matrices with real values of type Real
Definition: symmat.hxx:43
SparseCoeffmatMatrix(const SparseCoeffmatMatrix &S, const CBout *cb=0, int incr=-1)
set the output and call clear()
Definition: SparseCoeffmatMatrix.hxx:95
const CH_Matrix_Classes::Indexmatrix & blockdim() const
returns a column vector with row i giving the order of block i
Definition: SparseCoeffmatMatrix.hxx:117
conic bundle method solver for sum of convex functions. See the ConicBundle_Manual for a quick introd...
Definition: CBSolver.hxx:22
const SparseCoeffmatVector * column(CH_Matrix_Classes::Integer i) const
returns NULL if the column is empty and a pointer to a Vector of CoeffmatPointers otherwise ...
base class for uniform use of WARNINGS and ERRORS (at some point in time)
Definition: CBout.hxx:30
stores/organizes the CoeffmatPointer pointers to Coeffmat matrices with the purpose of describing the...
Definition: SparseCoeffmatMatrix.hxx:50
std::map< CH_Matrix_Classes::Integer, CoeffmatPointer > SparseCoeffmatVector
this is used to extract a row/block or a column from a SparseCoeffmatMatrix
Definition: SparseCoeffmatMatrix.hxx:26
std::vector< SparseCoeffmatVector > SCMblockrep
each row/block is likely to have at least one nonzero entry, therefore the block representation uses ...
Definition: SparseCoeffmatMatrix.hxx:62
int reassign_blocks(const CH_Matrix_Classes::Indexmatrix &map_to_old)
afterwards the new block i is the previous block map_to_old(i); no multiple appearances are allowed...
SparseCoeffmatMatrix(const CH_Matrix_Classes::Indexmatrix &in_block_dim, CH_Matrix_Classes::Integer in_col_dim, const CH_Matrix_Classes::Indexmatrix *block_ind=0, const CH_Matrix_Classes::Indexmatrix *col_ind=0, const CoeffmatVector *coeff_vec=0, const CBout *cb=0, int incr=-1)
set the output and call init() for the given sparse information
Definition: SparseCoeffmatMatrix.hxx:102
int append_columns(const SparseCoeffmatMatrix &append_mat, const CH_Matrix_Classes::Indexmatrix *blocks=0, const CH_Matrix_Classes::Indexmatrix *cols=0)
append append_mat (or its submatrix given by blocks and/or cols) to the right
SCMcolrep * colrep
this column representation is only formed on demand and deleted on changes
Definition: SparseCoeffmatMatrix.hxx:67
CH_Matrix_Classes::Integer nzcoldim() const
returns the number of columns with nonzero coefficient matrices
Definition: SparseCoeffmatMatrix.hxx:125
SparseCoeffmatMatrix & operator=(const SparseCoeffmatMatrix &)
copy
~SparseCoeffmatMatrix()
calls clear() and exits
Matrix class for real values of type Real
Definition: matrix.hxx:74
SCMblockrep blockrep
this is the basic block representation, it holds for each row/block a sparse representation of the ro...
Definition: SparseCoeffmatMatrix.hxx:64
std::vector< CoeffmatPointer > CoeffmatVector
convenient for initializing SparseCoeffmatMatrix via the sparse (block_i,column_i,Coeffmat_i), i=1,...,nz (nonzeros) format with Indexmatrix,Indexmatrix,CoeffmatVector
Definition: SparseCoeffmatMatrix.hxx:17
SparseCoeffmatMatrix(const CBout *cb=0, int incr=-1)
set the output and call clear()
Definition: SparseCoeffmatMatrix.hxx:89
CH_Matrix_Classes::Integer rowdim() const
returns the number of blocks
Definition: SparseCoeffmatMatrix.hxx:123
CH_Matrix_Classes::Indexmatrix dense_cnt
number of dense matrices per block
Definition: SparseCoeffmatMatrix.hxx:59
CH_Matrix_Classes::Integer get_dense_cnt(CH_Matrix_Classes::Integer i) const
returns the number of dense matrices in block i
Definition: SparseCoeffmatMatrix.hxx:175
int append_blocks(const SparseCoeffmatMatrix &append_mat, const CH_Matrix_Classes::Indexmatrix *blocks=0, const CH_Matrix_Classes::Indexmatrix *cols=0)
append append_mat (or its submatrix given by blocks and/or cols) below
pointer class for Coeffmat for deleting objects on the heap if Coefmat::use_cnt is reduced to zero an...
Definition: Coeffmat.hxx:264
Integer rowdim() const
returns the row dimension
Definition: indexmat.hxx:321
const SparseCoeffmatVector * block(CH_Matrix_Classes::Integer i) const
returns NULL if the block is empty and a pointer to a Vector of CoeffmatPointers otherwise ...
void clear()
clears all (empty 0 times 0 matrix)
int project(CH_Matrix_Classes::Symmatrix &S, const CH_Matrix_Classes::Matrix &P, const CH_Matrix_Classes::Integer j) const
computes S=P^T*A.column(j)*P
CH_Matrix_Classes::Integer coldim() const
returns the number of columns (i.e. of blockdiagonal matrices)
Definition: SparseCoeffmatMatrix.hxx:121
int Gram_ip(CH_Matrix_Classes::Matrix &ipvec, const CH_Matrix_Classes::Matrix &P, const CH_Matrix_Classes::Matrix *Lam=0, const CH_Matrix_Classes::Indexmatrix *ind=0) const
computes the inner products of (selected) columns (which represent block diagonal symmetric matrices)...
std::map< CH_Matrix_Classes::Integer, SparseCoeffmatVector > SCMcolrep
this will be used for a (lazy) column representation of the matrix
Definition: SparseCoeffmatMatrix.hxx:54
CH_Matrix_Classes::Integer col_dim
number of columns in the SparseCoeffmatMatrix
Definition: SparseCoeffmatMatrix.hxx:58
bool operator!=(const SparseCoeffmatMatrix &mat) const
useful for testing purposes; false iff both have the same size and both have the same pointers in the...
Definition: SparseCoeffmatMatrix.hxx:182
CH_Matrix_Classes::Indexmatrix block_dim
column vector holding for each row the dimension of the block
Definition: SparseCoeffmatMatrix.hxx:57
PSCPrimal is the corresponding positive semidefinite object for PSCOracle like PrimalMatrix for a Mat...
Definition: PSCPrimal.hxx:46