ConicBundle
Coeffmat.hxx
Go to the documentation of this file.
1 
2 
3 #ifndef CONICBUNDLE_COEFFMAT_HXX
4 #define CONICBUNDLE_COEFFMAT_HXX
5 
13 #include <string>
14 #include <map>
15 #include "memarray.hxx"
16 #include "symmat.hxx"
17 #include "sparssym.hxx"
18 #include "CBout.hxx"
19 
20 
21 namespace ConicBundle {
22 
23 
27 
40  };
41 
43 
47 
53 {
54 protected:
56 public:
58  CoeffmatInfo(CH_Matrix_Classes::Real sf=1.):scalefactor(sf){}
60  virtual ~CoeffmatInfo(){}
61 
63  virtual CoeffmatInfo* clone() const {return new CoeffmatInfo(scalefactor);}
64 
68  void set_scalefactor(CH_Matrix_Classes::Real sf){scalefactor=sf;}
70  void multiply(CH_Matrix_Classes::Real sf){scalefactor*=sf;}
72  virtual std::ostream& print_id(std::ostream& out) const {return out<<"NoInfo";}
73 };
74 
76 
80 
84 class CMIName : public CoeffmatInfo
85 {
86 private:
87  std::string name;
88 public:
90  CMIName(std::string in_name,CH_Matrix_Classes::Real sf=1.):CoeffmatInfo(sf),name(in_name){}
92  ~CMIName(){}
94  CoeffmatInfo* clone() const {return new CMIName(name,scalefactor);}
96  std::ostream& print_id(std::ostream& out) const {return out<<name.c_str();}
97 };
98 
100 
104 
106 inline CoeffmatInfo* clone(const CoeffmatInfo* cip)
107 {return (cip==0)? 0: cip->clone();}
108 
109 
111 
115 
126 {
127 private:
128  friend class CoeffmatPointer;
133 protected:
136 public:
138  Coeffmat(bool del_by_CoeffmatPointer=true)
139  {CM_type=CM_unspec;infop=0;use_cnt=0;deletion_by_CoeffmatPointer=del_by_CoeffmatPointer;}
141  virtual ~Coeffmat(){delete infop;}
142 
145  {deletion_by_CoeffmatPointer=dbMP;}
147  virtual Coeffmattype get_type() const {return CM_type;}
149  virtual CoeffmatInfo* get_info() {return infop;}
151  virtual const CoeffmatInfo* get_info() const {return infop;}
153  virtual void set_info(CoeffmatInfo* cip) {delete infop; infop=cip;}
154 
155 
157  virtual Coeffmat* clone() const =0;
158 
160  virtual CH_Matrix_Classes::Integer dim() const =0;
161 
164 
166  virtual void make_symmatrix(CH_Matrix_Classes::Symmatrix& S) const =0;
167 
169  virtual CH_Matrix_Classes::Real norm(void) const =0;
170 
171 
173  virtual Coeffmat* subspace(const CH_Matrix_Classes::Matrix& P) const =0;
174 
176  virtual void multiply(CH_Matrix_Classes::Real d) =0;
177 
179  virtual CH_Matrix_Classes::Real ip(const CH_Matrix_Classes::Symmatrix& S) const =0;
180 
182  virtual CH_Matrix_Classes::Real gramip(const CH_Matrix_Classes::Matrix& P) const =0;
183 
185  virtual CH_Matrix_Classes::Real gramip(const CH_Matrix_Classes::Matrix& P,CH_Matrix_Classes::Integer start_row,const CH_Matrix_Classes::Matrix* Lam=0) const =0;
186 
188  virtual void addmeto(CH_Matrix_Classes::Symmatrix& S,CH_Matrix_Classes::Real d=1.) const =0;
189 
191  virtual void addprodto(CH_Matrix_Classes::Matrix& A,const CH_Matrix_Classes::Matrix& B,CH_Matrix_Classes::Real d=1.) const =0;
192 
194  virtual void addprodto(CH_Matrix_Classes::Matrix& A,const CH_Matrix_Classes::Sparsemat& B,CH_Matrix_Classes::Real d=1.) const =0;
195 
197  virtual void left_right_prod(const CH_Matrix_Classes::Matrix& P,const CH_Matrix_Classes::Matrix& Q,CH_Matrix_Classes::Matrix& R) const =0;
198 
200  virtual CH_Matrix_Classes::Integer prodvec_flops() const =0;
201 
203  virtual int dense() const =0;
204 
206  virtual int sparse() const =0;
207 
210 
212  virtual int support_in(const CH_Matrix_Classes::Sparsesym& A) const =0;
213 
215  virtual CH_Matrix_Classes::Real ip(const CH_Matrix_Classes::Sparsesym& A) const =0;
216 
218  virtual void project(CH_Matrix_Classes::Symmatrix& S,const CH_Matrix_Classes::Matrix& P) const=0;
219 
221  virtual void add_projection(CH_Matrix_Classes::Symmatrix& S,const CH_Matrix_Classes::Matrix& P,CH_Matrix_Classes::Real alpha=1.,CH_Matrix_Classes::Integer start_row=0) const =0;
222 
225  CH_Matrix_Classes::Real alpha=1.,CH_Matrix_Classes::Real beta=0.,int btrans=0) const =0;
226 
229  CH_Matrix_Classes::Real alpha=1.,CH_Matrix_Classes::Real beta=0.,int btrans=0) const =0;
230 
232  virtual int equal(const Coeffmat* p,double tol=1e-6) const =0;
233 
235  virtual std::ostream& display(std::ostream& o) const =0;
236 
238  virtual std::ostream& out(std::ostream& o) const =0;
239 
241  virtual std::istream& in(std::istream& i) =0;
242 
243 };
244 
246 
250 
253 Coeffmat* coeffmat_read(std::istream& in);
254 
256 
260 
265 private:
268 
269 public:
271  void init(Coeffmat* cfmp)
272  {
273  if ((coeffmatp)&&
274  ( --(coeffmatp->use_cnt)<=0)&&
275  (coeffmatp->deletion_by_CoeffmatPointer)){
276  assert(coeffmatp->use_cnt==0);
277  delete coeffmatp;
278  }
279  coeffmatp=cfmp;
280  if (coeffmatp)
281  coeffmatp->use_cnt++;
282  }
283 
285  CoeffmatPointer():coeffmatp(0)
286  {}
287 
289  CoeffmatPointer(Coeffmat* cfmp):coeffmatp(0)
290  {
291  init(cfmp);
292  }
293 
295  CoeffmatPointer(const CoeffmatPointer& mp):coeffmatp(0)
296  {
297  init(mp.coeffmatp);
298  }
299 
302  { init(0); }
303 
306  { init(mp.coeffmatp); return *this; }
307 
310  { init(cfmp); return *this; }
311 
313  bool operator==(const CoeffmatPointer& mp) const
314  { return coeffmatp==mp.coeffmatp; }
315 
317  bool operator==(const Coeffmat* cfmp) const
318  { return coeffmatp==cfmp; }
319 
321  bool operator!=(const CoeffmatPointer& mp) const
322  { return coeffmatp!=mp.coeffmatp; }
323 
325  bool operator!=(const Coeffmat* cfmp) const
326  { return coeffmatp!=cfmp; }
327 
329  bool operator<(const CoeffmatPointer& mp) const
330  { return coeffmatp<mp.coeffmatp; }
331 
333  bool operator<(const Coeffmat* cfmp) const
334  { return coeffmatp<cfmp; }
335 
337  bool operator>(const CoeffmatPointer& mp) const
338  { return coeffmatp>mp.coeffmatp; }
339 
341  bool operator>(const Coeffmat* cfmp) const
342  { return coeffmatp>cfmp; }
343 
346  {assert(coeffmatp); return *coeffmatp;}
347 
350  {assert(coeffmatp); return coeffmatp;}
351 
353  Coeffmat* ptr() const
354  {return coeffmatp;}
355 
356 };
357 
359 
360 
361 
362 }
363 
364 #endif
365 
void set_scalefactor(CH_Matrix_Classes::Real sf)
sets the scale factor
Definition: Coeffmat.hxx:68
int Integer
all integer numbers in calculations and indexing are of this type
Definition: matop.hxx:40
virtual Coeffmattype get_type() const
returns its Coeffmattype
Definition: Coeffmat.hxx:147
Coeffmat * operator->() const
returns the pointers (may not be called if empty)
Definition: Coeffmat.hxx:349
bool operator<(const Coeffmat *cfmp) const
compares the pointers
Definition: Coeffmat.hxx:333
double Real
all real numbers in calculations are of this type
Definition: matop.hxx:50
CoeffmatPointer & operator=(Coeffmat *cfmp)
calls init(cfmp), NULL is allowed
Definition: Coeffmat.hxx:309
for CMlowrankdd
Definition: Coeffmat.hxx:33
CoeffmatPointer()
default initialization to an empty pointer
Definition: Coeffmat.hxx:285
for CMsymdense
Definition: Coeffmat.hxx:31
allows to memorize the scalings applied to a Coeffmat and offers the basis for storing further user d...
Definition: Coeffmat.hxx:52
virtual CoeffmatInfo * clone() const
generates a new copy of itself on the heap
Definition: Coeffmat.hxx:63
Coeffmat * coeffmat_read(std::istream &in)
reads the next Coeffmat from in into an object on the heap and returns a pointer to it...
defines a base class for coefficient matrices in semidefinite programming, in particular for use with...
Definition: Coeffmat.hxx:125
Matrix class for integral values of type Integer
Definition: indexmat.hxx:195
bool operator!=(const CoeffmatPointer &mp) const
compares the pointers
Definition: Coeffmat.hxx:321
std::ostream & print_id(std::ostream &out) const
outputs the name
Definition: Coeffmat.hxx:96
CoeffmatPointer(const CoeffmatPointer &mp)
calls init(mp.coeffmatp)
Definition: Coeffmat.hxx:295
for CMsingleton
Definition: Coeffmat.hxx:38
virtual CoeffmatInfo * get_info()
returns the user information
Definition: Coeffmat.hxx:149
bool operator!=(const Coeffmat *cfmp) const
compares the pointers
Definition: Coeffmat.hxx:325
std::string name
well, this is the name
Definition: Coeffmat.hxx:87
Matrix class of symmetric matrices with real values of type Real
Definition: symmat.hxx:43
bool operator>(const CoeffmatPointer &mp) const
compares the pointers
Definition: Coeffmat.hxx:337
for CMgramdense
Definition: Coeffmat.hxx:36
for CMsymsparse
Definition: Coeffmat.hxx:32
Header declaring the class CH_Matrix_Classes::Symmatrix for symmetric matrices with Real elements...
CH_Matrix_Classes::Integer use_cnt
Each CoeffmatPointer pointing to his increase the use_cnt by one and it reduces it by one once it sto...
Definition: Coeffmat.hxx:130
CoeffmatPointer & operator=(const CoeffmatPointer &mp)
calls init(mp.coeffmatp)
Definition: Coeffmat.hxx:305
conic bundle method solver for sum of convex functions. See the ConicBundle_Manual for a quick introd...
Definition: CBSolver.hxx:22
CoeffmatPointer(Coeffmat *cfmp)
calls init() (cfmp==NULL is allowed)
Definition: Coeffmat.hxx:289
Coeffmat * coeffmatp
holds the pointer to Coeffmat, may be NULL == empty
Definition: Coeffmat.hxx:267
bool operator==(const Coeffmat *cfmp) const
compares the pointers
Definition: Coeffmat.hxx:317
Coeffmat(bool del_by_CoeffmatPointer=true)
default constructor; set del_by_CoeffmatPointer==true if a CoeffmatPointer reducing the use_cnt to ze...
Definition: Coeffmat.hxx:138
Coeffmattype CM_type
in order to enable type identification
Definition: Coeffmat.hxx:134
CMIName(std::string in_name, CH_Matrix_Classes::Real sf=1.)
initalize name and scale factor
Definition: Coeffmat.hxx:90
CoeffmatInfo * infop
allows the user to specify and output additional information
Definition: Coeffmat.hxx:135
void init(Coeffmat *cfmp)
initialize the Pointer to hold cfmp (==NULL is allowed for empty); for the coeffmat stored previously...
Definition: Coeffmat.hxx:271
extends CoeffmatInfo to store a name (e.g. of the constraint it represents)
Definition: Coeffmat.hxx:84
CoeffmatInfo * clone() const
generates a new copy of itself on the heap
Definition: Coeffmat.hxx:94
Header declaring the output class CBout.
Matrix class of symmetric matrices with real values of type Real
Definition: sparssym.hxx:89
any user defined constraint may use this
Definition: Coeffmat.hxx:30
bool deletion_by_CoeffmatPointer
set deletion_by_CoeffmatPointer==true if a CoeffmatPointer reducing the use_cnt to zero should delete...
Definition: Coeffmat.hxx:132
for CMlowranksd
Definition: Coeffmat.hxx:34
virtual void set_info(CoeffmatInfo *cip)
deletes the old and sets new user information
Definition: Coeffmat.hxx:153
void multiply(CH_Matrix_Classes::Real sf)
scales the scale factor
Definition: Coeffmat.hxx:70
~CoeffmatPointer()
calls init(0) first
Definition: Coeffmat.hxx:301
bool operator>(const Coeffmat *cfmp) const
compares the pointers
Definition: Coeffmat.hxx:341
for CMgramsparse
Definition: Coeffmat.hxx:37
Matrix class for real values of type Real
Definition: matrix.hxx:74
bool operator==(const CoeffmatPointer &mp) const
compares the pointers
Definition: Coeffmat.hxx:313
CoeffmatInfo(CH_Matrix_Classes::Real sf=1.)
default value is 1 for no scaling
Definition: Coeffmat.hxx:58
Matrix class of sparse matrices with real values of type Real
Definition: sparsmat.hxx:74
for CMlowrankss
Definition: Coeffmat.hxx:35
CH_Matrix_Classes::Real scalefactor
scaling value
Definition: Coeffmat.hxx:55
All derived classes share a common Memarray memory manager, which is generated with the first user an...
Definition: memarray.hxx:117
pointer class for Coeffmat for deleting objects on the heap if Coefmat::use_cnt is reduced to zero an...
Definition: Coeffmat.hxx:264
Header for simple memory management tools that support frequent allocation and deallocation of arrays...
bool operator<(const CoeffmatPointer &mp) const
compares the pointers
Definition: Coeffmat.hxx:329
Coeffmat * ptr() const
returns the pointer (may return NULL)
Definition: Coeffmat.hxx:353
CH_Matrix_Classes::Real get_scalefactor() const
returns the scale factor
Definition: Coeffmat.hxx:66
for CMgramsparse_withoutdiag
Definition: Coeffmat.hxx:39
virtual const CoeffmatInfo * get_info() const
returns the user information in const form
Definition: Coeffmat.hxx:151
virtual std::ostream & print_id(std::ostream &out) const
output a name if there is one for recognizing the type
Definition: Coeffmat.hxx:72
bool equal(const Matrix &A, const Matrix &B)
returns true if both matrices have the same size and the same elements
Definition: matrix.hxx:1433
Header declaring the class CH_Matrix_Classes::Sparsesym for sparse symmetric matrices with Real eleme...
Coeffmattype
for recognizing the type when writing and reading the problem
Definition: Coeffmat.hxx:29
Real ip(const Matrix &A, const Matrix &B)
returns the usual inner product of A and B, i.e., the sum of A(i,j)*B(i,j) over all i...
Definition: matrix.hxx:1165
void set_deletion_by_CoeffmatPointer(bool dbMP)
if set to true any CoeffmatPointer that reduces use_cnt to zero will delete this object ...
Definition: Coeffmat.hxx:144
Coeffmat & operator*() const
returns the object pointed to (may not be called if empty)
Definition: Coeffmat.hxx:345