ConicBundle
PSCPrimal.hxx
Go to the documentation of this file.
1 
2 
3 #ifndef CONICBUNDLE_PSCPRIMAL_HXX
4 #define CONICBUNDLE_PSCPRIMAL_HXX
5 
13 //------------------------------------------------------------
14 
15 #include <map>
16 #include "CBout.hxx"
17 #include "PSCOracle.hxx"
18 #include "SparseCoeffmatMatrix.hxx"
19 
20 //------------------------------------------------------------
21 
22 namespace ConicBundle {
23 
27 
46  class PSCPrimal: public PrimalData
47  {
48 
49  public:
51  virtual ~PSCPrimal(){}
52 
54  virtual PrimalData* clone_primal_data() const =0;
55 
57  virtual int assign_Gram_matrix(const CH_Matrix_Classes::Matrix& P)=0;
58 
60  virtual int aggregate_primal_data(const PrimalData& pd,double factor=1.)=0;
61 
63  virtual int aggregate_Gram_matrix(const CH_Matrix_Classes::Matrix& P,double factor=1.)=0;
64 
66  virtual int scale_primal_data(double factor)=0;
67 
69  virtual int primal_ip(CH_Matrix_Classes::Real& value,
70  const SparseCoeffmatMatrix& A,
71  CH_Matrix_Classes::Integer column) const =0;
72  };
73 
74 
75 
82  {
83  private:
84 
85  public:
89  DensePSCPrimal(const DensePSCPrimal& symmat,double factor=1.) : PSCPrimal(), CH_Matrix_Classes::Symmatrix(symmat,factor) {}
91  DensePSCPrimal(const CH_Matrix_Classes::Symmatrix& symmat,double factor=1.) : PSCPrimal(), CH_Matrix_Classes::Symmatrix(symmat,factor) {}
96  { init(symmat); return *this; }
97 
99  virtual PrimalData* clone_primal_data() const
100  { return new DensePSCPrimal(*this); }
101 
102 
105  { CH_Matrix_Classes::rankadd(P,*this); return 0; }
106 
108  virtual int aggregate_primal_data(const PrimalData& it,double factor=1.)
109  {
110  const DensePSCPrimal* pd=dynamic_cast<const DensePSCPrimal*>(&it);
111  assert(pd!=0);
112  CH_Matrix_Classes::xbpeya(*this,*pd,factor,1.);
113  return 0;
114  }
115 
117  virtual int aggregate_Gram_matrix(const CH_Matrix_Classes::Matrix& P,double factor=1.)
118  { CH_Matrix_Classes::rankadd(P,*this,factor,1.); return 0; }
119 
121  virtual int scale_primal_data(double factor)
122  { assert(factor>=0.); *this *= factor; return 0;}
123 
125  virtual int primal_ip(CH_Matrix_Classes::Real& value,
126  const SparseCoeffmatMatrix& A,
127  CH_Matrix_Classes::Integer column) const
128  {
129  if ((column<0)||(column>=A.coldim())||(A.blockdim().dim()!=1)||(A.blockdim()(0)!=rowdim()))
130  return 1;
131  const SparseCoeffmatVector* block=A.block(0);
132  if (block==0){
133  value=0.;
134  }
135  else {
136  SparseCoeffmatVector::const_iterator it=block->find(column);
137  if (it==block->end())
138  value=0.;
139  else
140  value=it->second->ip(*this);
141  }
142  return 0;
143  }
144 
145  };
146 
147 
154  {
155  public:
157  SparsePSCPrimal(const CH_Matrix_Classes::Sparsesym& sps,double factor=1.) : PSCPrimal(), CH_Matrix_Classes::Sparsesym(sps,factor) {}
159  SparsePSCPrimal(const SparsePSCPrimal& pr,double factor=1.) : PSCPrimal(), CH_Matrix_Classes::Sparsesym(pr,factor) {}
160  ~SparsePSCPrimal(){}
163  { init(sdp); return *this; }
164 
167  { return new SparsePSCPrimal(*this); }
168 
171  { CH_Matrix_Classes::support_rankadd(P,*this); return 0; }
172 
174  int aggregate_primal_data(const PrimalData& it,double factor=1.)
175  {
176  const SparsePSCPrimal* pd=dynamic_cast<const SparsePSCPrimal*>(&it);
177  assert(pd!=0);
178  this->support_xbpeya(*pd,factor,1.);
179  return 0;
180  }
181 
183  int aggregate_Gram_matrix(const CH_Matrix_Classes::Matrix& P,double factor=1.)
184  { CH_Matrix_Classes::support_rankadd(P,*this,factor,1.); return 0; }
185 
187  virtual int scale_primal_data(double factor)
188  { assert(factor>=0.); *this *= factor; return 0;}
189 
191  virtual int primal_ip(CH_Matrix_Classes::Real& value,
192  const SparseCoeffmatMatrix& A,
193  CH_Matrix_Classes::Integer column) const
194  {
195  if ((column<0)||(column>=A.coldim())||(A.blockdim().dim()!=1)||(A.blockdim()(0)!=rowdim()))
196  return 1;
197  const SparseCoeffmatVector* block=A.block(0);
198  if (block==0)
199  value=0.;
200  else {
201  SparseCoeffmatVector::const_iterator it=block->find(column);
202  if (it==block->end())
203  value=0.;
204  else {
205  if (it->second->support_in(*this)==0){
206  return 1;
207  }
208  value=it->second->ip(*this);
209  }
210  }
211  return 0;
212  }
213  };
214 
215 
222  {
223  protected:
225 
226  public:
228  GramSparsePSCPrimal(const CH_Matrix_Classes::Sparsesym& sps,double factor=1.) : PSCPrimal(), CH_Matrix_Classes::Sparsesym(sps,factor) {}
230  GramSparsePSCPrimal(const GramSparsePSCPrimal& pr,double factor=1.) :
231  PSCPrimal(),
232  CH_Matrix_Classes::Sparsesym(pr,factor),
233  gramblock(pr.gramblock,std::sqrt(factor)) {assert(factor>=0.);}
238  { init(sdp); gramblock.init(0,0,0.); return *this; }
241  { init(sdp); gramblock=sdp.gramblock; return *this; }
242 
244  const CH_Matrix_Classes::Matrix& get_grammatrix() const { return gramblock; }
245 
248  { return new GramSparsePSCPrimal(*this); }
249 
252  { gramblock=P; CH_Matrix_Classes::support_rankadd(CH_Matrix_Classes::Matrix(gramblock.rowdim(),1,0.),*this,0.); return 0; }
253 
260  int aggregate_primal_data(const PrimalData& it,double factor=1.)
261  {
262  assert(factor>=0.);
263  const GramSparsePSCPrimal* pd=dynamic_cast<const GramSparsePSCPrimal*>(&it);
264  if (pd!=0){
265  this->support_xbpeya(*pd,factor,1.);
266  if (pd->gramblock.dim()!=0)
268  return 0;
269  }
270  const SparsePSCPrimal* ps=dynamic_cast<const SparsePSCPrimal*>(&it);
271  if (ps!=0){
272  this->support_xbpeya(*ps,factor,1.);
273  return 0;
274  }
275  return 1;
276  }
277 
286  int aggregate_Gram_matrix(const CH_Matrix_Classes::Matrix& P,double factor=1.)
287  {
288  if (gramblock.dim()!=0) {
289  CH_Matrix_Classes::support_rankadd(gramblock,*this);
290  gramblock.init(0,0,0.);
291  }
292  CH_Matrix_Classes::support_rankadd(P,*this,factor,1.);
293  return 0;
294  }
295 
297  virtual int scale_primal_data(double factor)
298  { assert(factor>=0.); *this *= factor; gramblock*=std::sqrt(factor); return 0;}
299 
301  virtual int primal_ip(CH_Matrix_Classes::Real& value,
302  const SparseCoeffmatMatrix& A,
303  CH_Matrix_Classes::Integer column) const
304  {
305  if ((column<0)||(column>=A.coldim())||(A.blockdim().dim()!=1)||(A.blockdim()(0)!=rowdim()))
306  return 1;
307  const SparseCoeffmatVector* block=A.block(0);
308  if (block==0){
309  value=0.;
310  }
311  else {
312  SparseCoeffmatVector::const_iterator it=block->find(column);
313  if (it==block->end())
314  value=0.;
315  else {
316  if (it->second->support_in(*this)==0){
317  return 1;
318  }
319  value=it->second->ip(*this);
320  if (gramblock.dim()>0)
321  value+=it->second->gramip(gramblock);
322  }
323  }
324  return 0;
325  }
326  };
327 
339  class BlockPSCPrimal: public PSCPrimal
340  {
341  private:
343  std::map<CH_Matrix_Classes::Integer,PSCPrimal*> primal;
344  public:
346  BlockPSCPrimal(const BlockPSCPrimal& pr,double factor=1.);
349  BlockPSCPrimal(const CH_Matrix_Classes::Indexmatrix& Xd,const std::map<CH_Matrix_Classes::Integer,PSCPrimal*>& pr,double factor=1.);
351  ~BlockPSCPrimal();
352 
354  virtual PrimalData* clone_primal_data() const;
355 
361  virtual int assign_Gram_matrix(const CH_Matrix_Classes::Matrix& P);
362 
365  virtual int aggregate_primal_data(const PrimalData& it,double factor=1.);
366 
372  virtual int aggregate_Gram_matrix(const CH_Matrix_Classes::Matrix& P,double factor=1.);
373 
375  CH_Matrix_Classes::Integer get_nblocks() const {return Xdim.dim();}
379  PSCPrimal* block(CH_Matrix_Classes::Integer i) const;
380 
382  virtual int scale_primal_data(double factor);
383 
385  virtual int primal_ip(CH_Matrix_Classes::Real& value,
386  const SparseCoeffmatMatrix& A,
387  CH_Matrix_Classes::Integer column) const;
388 
389  };
390 
392 
393 }
394 
395 
396 #endif
397 
int Integer
all integer numbers in calculations and indexing are of this type
Definition: matop.hxx:40
PrimalData * clone_primal_data() const
returns a newly generated identical Object
Definition: PSCPrimal.hxx:166
PrimalData * clone_primal_data() const
returns a newly generated identical Object
Definition: PSCPrimal.hxx:247
int aggregate_Gram_matrix(const CH_Matrix_Classes::Matrix &P, double factor=1.)
add factor*P*P^T on the support to this
Definition: PSCPrimal.hxx:183
SparsePSCPrimal & operator=(const CH_Matrix_Classes::Sparsesym &sdp)
assigns this Sparsesym, only the same support will be used in all Gram operations ...
Definition: PSCPrimal.hxx:162
Integer rowdim() const
returns the row dimension
Definition: matrix.hxx:215
double Real
all real numbers in calculations are of this type
Definition: matop.hxx:50
int assign_Gram_matrix(const CH_Matrix_Classes::Matrix &P)
for each element aij in the support set aij=<P.row(i),P.row(j)>
Definition: PSCPrimal.hxx:170
virtual int aggregate_Gram_matrix(const CH_Matrix_Classes::Matrix &P, double factor=1.)=0
add factor*P*P^T to this
SparsePSCPrimal(const SparsePSCPrimal &pr, double factor=1.)
copy constructor, only the same support will be used in all Gram operations
Definition: PSCPrimal.hxx:159
const DensePSCPrimal & operator=(const CH_Matrix_Classes::Symmatrix &symmat)
assigns a symmetric matrix
Definition: PSCPrimal.hxx:95
Matrix class for integral values of type Integer
Definition: indexmat.hxx:195
Matrix & init(const Matrix &A, Real d=1., int atrans=0)
initialize to *this=A*d where A may be transposed
Definition: matrix.hxx:1035
void dim(Integer &_nr, Integer &_nc) const
returns the number of rows in _nr and the number of columns in _nc
Definition: matrix.hxx:209
GramSparsePSCPrimal(const GramSparsePSCPrimal &pr, double factor=1.)
copy constructor
Definition: PSCPrimal.hxx:230
virtual int aggregate_primal_data(const PrimalData &pd, double factor=1.)=0
add factor*pd to this
const CH_Matrix_Classes::Matrix & get_grammatrix() const
returns the matrix giving rise to the Gram matrix
Definition: PSCPrimal.hxx:244
Header declaring the classes ConicBundle::PSCOracle and ConicBundle::PSCBundleParameters (needed for ...
GramSparsePSCPrimal(const CH_Matrix_Classes::Sparsesym &sps, double factor=1.)
initialize to the given sparse symmetric matrix, the gram part is zero
Definition: PSCPrimal.hxx:228
Matrix class of symmetric matrices with real values of type Real
Definition: symmat.hxx:43
SparsePSCPrimal(const CH_Matrix_Classes::Sparsesym &sps, double factor=1.)
copy constructor from a CH_Matrix_Classes::Sparssym, only the support of this matrix will be used in ...
Definition: PSCPrimal.hxx:157
const CH_Matrix_Classes::Indexmatrix & blockdim() const
returns a column vector with row i giving the order of block i
Definition: SparseCoeffmatMatrix.hxx:117
virtual int scale_primal_data(double factor)
multiply/scale *this with a nonnegative factor
Definition: PSCPrimal.hxx:297
conic bundle method solver for sum of convex functions. See the ConicBundle_Manual for a quick introd...
Definition: CBSolver.hxx:22
DensePSCPrimal(CH_Matrix_Classes::Integer n)
direct size initialization to a zero matrix
Definition: PSCPrimal.hxx:93
DensePSCPrimal(const DensePSCPrimal &symmat, double factor=1.)
copy constructor
Definition: PSCPrimal.hxx:89
int aggregate_primal_data(const PrimalData &it, double factor=1.)
if it is a SparseSDPRimal, add factor*it to this on the support of this
Definition: PSCPrimal.hxx:174
represents an PSCPrimal as the sum of a Gram matrix and a sparse symmetric matrix ...
Definition: PSCPrimal.hxx:221
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
DensePSCPrimal()
initialize to a symmetric matrix of size 0
Definition: PSCPrimal.hxx:87
virtual int aggregate_primal_data(const PrimalData &it, double factor=1.)
add factor*it to this (it must also be a DensePSCPrimal)
Definition: PSCPrimal.hxx:108
int aggregate_primal_data(const PrimalData &it, double factor=1.)
if it is a GramSparsePSCPrimal or SparseSDPRimal, add factor*it to this on only the support of this s...
Definition: PSCPrimal.hxx:260
CH_Matrix_Classes::Indexmatrix Xdim
stores the sizes of the block
Definition: PSCPrimal.hxx:342
GramSparsePSCPrimal & operator=(const GramSparsePSCPrimal &sdp)
copy the information
Definition: PSCPrimal.hxx:240
Symmatrix & rankadd(const Matrix &A, Symmatrix &C, Real alpha=1., Real beta=0., int trans=0)
returns C=beta*C+alpha* A*A^T, where A may be transposed. If beta==0. then C is initiliazed to the co...
std::map< CH_Matrix_Classes::Integer, PSCPrimal * > primal
holds the PSCPrimal of blcok i if there is one
Definition: PSCPrimal.hxx:343
Header declaring the output class CBout.
virtual int scale_primal_data(double factor)
multiply/scale *this with a nonnegative factor
Definition: PSCPrimal.hxx:121
virtual int scale_primal_data(double factor)
multiply/scale *this with a nonnegative factor
Definition: PSCPrimal.hxx:187
virtual int primal_ip(CH_Matrix_Classes::Real &value, const SparseCoeffmatMatrix &A, CH_Matrix_Classes::Integer column) const =0
if compatible evaluate value=ip(*this,A.column[i])
Matrix Classes and Linear Algebra. See Matrix Classes (namespace CH_Matrix_Classes) for a quick intro...
Definition: PSCOracle.hxx:20
Sparsesym & support_rankadd(const Matrix &A, Sparsesym &C, Real alpha=1., Real beta=0., int trans=0)
returns C=beta*C+alpha*AA^T (or A^TA), but only on the current support of C
virtual int primal_ip(CH_Matrix_Classes::Real &value, const SparseCoeffmatMatrix &A, CH_Matrix_Classes::Integer column) const
if compatible evaluate value=ip(*this,A.column[i])
Definition: PSCPrimal.hxx:301
Matrix class of symmetric matrices with real values of type Real
Definition: sparssym.hxx:89
implements a general purpose dense symmetric PSCPrimal based on CH_Matrix_Classes::Symmatrix ...
Definition: PSCPrimal.hxx:81
Matrix class for real values of type Real
Definition: matrix.hxx:74
virtual int aggregate_Gram_matrix(const CH_Matrix_Classes::Matrix &P, double factor=1.)
add factor*P*P^T to this
Definition: PSCPrimal.hxx:117
implements a sparse symmetric PSCPrimal collecting data only on a sparse, prespecified support; it is...
Definition: PSCPrimal.hxx:153
virtual int primal_ip(CH_Matrix_Classes::Real &value, const SparseCoeffmatMatrix &A, CH_Matrix_Classes::Integer column) const
if compatible evaluate value=ip(*this,A.column[i])
Definition: PSCPrimal.hxx:125
virtual PrimalData * clone_primal_data() const =0
returns a newly generated identical Object
virtual int primal_ip(CH_Matrix_Classes::Real &value, const SparseCoeffmatMatrix &A, CH_Matrix_Classes::Integer column) const
if compatible evaluate value=ip(*this,A.column[i])
Definition: PSCPrimal.hxx:191
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 ...
int aggregate_Gram_matrix(const CH_Matrix_Classes::Matrix &P, double factor=1.)
add factor*P*P^T to this, collecting all available information only in the sparse part...
Definition: PSCPrimal.hxx:286
In Lagrangean relaxation an approximate primal solution can be generated by supplying primal informat...
Definition: CBSolver.hxx:151
Header declaring the classes ConicBundle::SparseCoeffmatMatrix (needed for ConicBundle::PSCAffineFunc...
CH_Matrix_Classes::Integer blockdim(CH_Matrix_Classes::Integer i) const
returns the size of block i
Definition: PSCPrimal.hxx:377
CH_Matrix_Classes::Integer coldim() const
returns the number of columns (i.e. of blockdiagonal matrices)
Definition: SparseCoeffmatMatrix.hxx:121
virtual int scale_primal_data(double factor)=0
multiply/scale *this with a nonnegative factor
Indexmatrix & xbpeya(Indexmatrix &x, const Indexmatrix &y, Integer alpha=1, Integer beta=0, int ytrans=0)
returns x= alpha*y+beta*x, where y may be transposed (ytrans=1); if beta==0. then x is initialized to...
GramSparsePSCPrimal & operator=(const CH_Matrix_Classes::Sparsesym &sdp)
assign the sparse symmetric matrix to this and set the gram part to zero
Definition: PSCPrimal.hxx:237
int assign_Gram_matrix(const CH_Matrix_Classes::Matrix &P)
Set the grammatrix part to and set all values on the sparse support to zero (but keep this support e...
Definition: PSCPrimal.hxx:251
virtual int assign_Gram_matrix(const CH_Matrix_Classes::Matrix &P)
assign P*P^T to this
Definition: PSCPrimal.hxx:104
void dim(Integer &_nr, Integer &_nc) const
returns the number of rows in _nr and the number of columns in _nc
Definition: indexmat.hxx:315
double sqrt(int a)
return sqrt for int a
Definition: mymath.hxx:121
CH_Matrix_Classes::Matrix gramblock
the gram matrix part is gramblock*transpose(grampblock)
Definition: PSCPrimal.hxx:224
virtual PrimalData * clone_primal_data() const
returns a newly generated identical Object, see PrimalData::clone_primal_data()
Definition: PSCPrimal.hxx:99
virtual int assign_Gram_matrix(const CH_Matrix_Classes::Matrix &P)=0
intialize the primal corresponding to the (positive semidefinite) Gram matrix P*P^T ...
implements a block diagonal PSCPrimal consisting of several PSCPrimal blocks
Definition: PSCPrimal.hxx:339
PSCPrimal is the corresponding positive semidefinite object for PSCOracle like PrimalMatrix for a Mat...
Definition: PSCPrimal.hxx:46
CH_Matrix_Classes::Integer get_nblocks() const
returns the number of blocks
Definition: PSCPrimal.hxx:375
DensePSCPrimal(const CH_Matrix_Classes::Symmatrix &symmat, double factor=1.)
copy constructor from a CH_Matrix_Classes::Symmatrix
Definition: PSCPrimal.hxx:91