ConicBundle
QPKKTSolverComparison.hxx
Go to the documentation of this file.
1 
2 #ifndef CONICBUNDLE_QPKKTSOLVERCOMPARISON_HXX
3 #define CONICBUNDLE_QPKKTSOLVERCOMPARISON_HXX
4 
12 #include <string>
13 #include "QPKKTSolverObject.hxx"
14 #include "clock.hxx"
15 
16 namespace ConicBundle {
17 
18 
22 
23 
29  {
30  public:
44 
47  {
48  preptime=predtime=corrtime=0;
49  prepnmult=prednmult=corrnmult=0;
50  cond=-1.;
51  rank=-1;
52  Hviol=Aviol=Bviol=Cviol=sysviol=0.;
53  }
54 
57 
59  friend std::ostream& operator<<(std::ostream& out,const QPKKT_SolverStats& s);
60 
62  friend std::istream& operator>>(std::ostream& in,QPKKT_SolverStats& s);
63  };
64 
66  std::ostream& operator<<(std::ostream& out,const QPKKT_SolverStats& s);
67 
69  std::istream& operator>>(std::ostream& in,QPKKT_SolverStats& s);
70 
72 
73 
77 
82  {
83  public:
86  std::vector<QPKKT_SolverStats> sdata;
87 
90  { prec=mu=0.; }
91 
94 
97  CH_Matrix_Classes::Matrix& prepsecs,
98  CH_Matrix_Classes::Matrix& predsecs,
99  CH_Matrix_Classes::Matrix& corrsecs,
100  CH_Matrix_Classes::Indexmatrix& predcalls,
101  CH_Matrix_Classes::Indexmatrix& corrcalls,
105  {
106  CH_Matrix_Classes::Integer ind=muvals.coldim();
107  muvals.concat_right(mu);
108  assert(prepsecs.rowdim()==CH_Matrix_Classes::Integer(sdata.size()));
109  assert(predsecs.rowdim()==CH_Matrix_Classes::Integer(sdata.size()));
110  assert(corrsecs.rowdim()==CH_Matrix_Classes::Integer(sdata.size()));
111  assert(predcalls.rowdim()==CH_Matrix_Classes::Integer(sdata.size()));
112  assert(corrcalls.rowdim()==CH_Matrix_Classes::Integer(sdata.size()));
113  assert(cond.rowdim()==CH_Matrix_Classes::Integer(sdata.size()));
114  assert(pccols.rowdim()==CH_Matrix_Classes::Integer(sdata.size()));
115  assert(sysviol.rowdim()==CH_Matrix_Classes::Integer(sdata.size()));
116  prepsecs.enlarge_right(1,0.);
117  predsecs.enlarge_right(1,0.);
118  corrsecs.enlarge_right(1,0.);
124  for(CH_Matrix_Classes::Integer i=0;i<CH_Matrix_Classes::Integer(sdata.size());i++){
125  prepsecs(i,ind)+=sdata[unsigned(i)].preptime;
126  predsecs(i,ind)+=sdata[unsigned(i)].predtime;
127  corrsecs(i,ind)=sdata[unsigned(i)].corrtime;
128  predcalls(i,ind)=sdata[unsigned(i)].prednmult;
129  corrcalls(i,ind)=sdata[unsigned(i)].corrnmult;
130  cond(i,ind)=sdata[unsigned(i)].cond;
131  pccols(i,ind)=sdata[unsigned(i)].rank;
132  sysviol(i,ind)=sdata[unsigned(i)].sysviol;
133  }
134  return 0;
135  }
136 
139  CH_Matrix_Classes::Matrix& predsecs,
140  CH_Matrix_Classes::Matrix& corrsecs,
141  CH_Matrix_Classes::Indexmatrix& predcalls,
143  )
144  {
145  CH_Matrix_Classes::Integer ind=prepsecs.coldim()-1;
146  for(CH_Matrix_Classes::Integer i=0;i<CH_Matrix_Classes::Integer(sdata.size());i++){
147  prepsecs(i,ind)+=sdata[unsigned(i)].preptime;
148  predsecs(i,ind)+=sdata[unsigned(i)].predtime;
149  corrsecs(i,ind)+=sdata[unsigned(i)].corrtime;
150  predcalls(i,ind)+=sdata[unsigned(i)].prednmult;
151  corrcalls(i,ind)+=sdata[unsigned(i)].corrnmult;
152  }
153  return 0;
154  }
155 
157  friend std::ostream& operator<<(std::ostream& out,const QPKKT_KKTStats& k);
158 
160  friend std::istream& operator>>(std::ostream& in,QPKKT_KKTStats& k);
161 
162  };
163 
165  std::ostream& operator<<(std::ostream& out,const QPKKT_KKTStats& k);
166 
168  std::istream& operator>>(std::istream& in,QPKKT_KKTStats& k);
169 
171 
172 
176 
181  {
182  public:
189  std::vector<CH_Tools::Microseconds> inittime;
190  std::vector<QPKKT_KKTStats> kktdata;
191 
194  {Qdim=Vdim=Arowdim=Aeqdim=Bdim=Cdim=0; }
195 
198 
202  {
204  for (unsigned int i=0;i<kktdata.size();i++)
205  if ((lbmu<=kktdata[i].mu)&&(kktdata[i].mu<ubmu))
206  sumval++;
207  return sumval;
208  }
209 
215  CH_Matrix_Classes::Matrix& prepsecs,
216  CH_Matrix_Classes::Matrix& predsecs,
217  CH_Matrix_Classes::Matrix& corrsecs,
223  {
225  for (unsigned int i=0;i<kktdata.size();i++){
226  if ((lbmu<=kktdata[i].mu)&&(kktdata[i].mu<ubmu)){
227  kktdata[i].append_col(mu,prepsecs,predsecs,corrsecs,predcalls,corrcalls,cond,pccols,sysviol);
228  cnt++;
229  }
230  }
231  assert(dims.coldim()+cnt==mu.coldim());
232  CH_Matrix_Classes::Integer startcol=dims.coldim();
233  if (dims.coldim()==0)
234  dims.init(6,cnt,CH_Matrix_Classes::Integer(0));
235  else {
236  assert(dims.rowdim()==6);
238  }
239  for (CH_Matrix_Classes::Integer i=0;i<cnt;i++){
240  dims(0,startcol+i)=Qdim;
241  dims(1,startcol+i)=Vdim;
242  dims(2,startcol+i)=Arowdim;
243  dims(3,startcol+i)=Aeqdim;
244  dims(4,startcol+i)=Bdim;
245  dims(5,startcol+i)=Cdim;
246  }
247  return 0;
248  }
249 
252  CH_Matrix_Classes::Indexmatrix& iterations,
253  CH_Matrix_Classes::Matrix& lastmu,
254  CH_Matrix_Classes::Matrix& prepsecs,
255  CH_Matrix_Classes::Matrix& predsecs,
256  CH_Matrix_Classes::Matrix& corrsecs,
257  CH_Matrix_Classes::Indexmatrix& predcalls,
259  )
260  {
261  assert(dims.coldim()==iterations.coldim());
262  assert(dims.coldim()==lastmu.coldim());
263  assert(dims.coldim()==prepsecs.coldim());
264  assert(dims.coldim()==predsecs.coldim());
265  assert(dims.coldim()==corrsecs.coldim());
266  assert(dims.coldim()==predcalls.coldim());
267  assert(dims.coldim()==corrcalls.coldim());
269  if (dims.coldim()==0)
270  dims.init(6,1,CH_Matrix_Classes::Integer(0));
271  else {
272  assert(dims.rowdim()==6);
274  }
275  dims(0,ind)=Qdim;
276  dims(1,ind)=Vdim;
277  dims(2,ind)=Arowdim;
278  dims(3,ind)=Aeqdim;
279  dims(4,ind)=Bdim;
280  dims(5,ind)=Cdim;
281  iterations.concat_right(CH_Matrix_Classes::Integer(kktdata.size()));
282  lastmu.concat_right(kktdata[kktdata.size()-1].mu);
283  assert(inittime.size()==unsigned(prepsecs.rowdim()));
284  prepsecs.enlarge_right(1,0.);
285  for(unsigned int i=0;i<inittime.size();i++)
286  prepsecs(CH_Matrix_Classes::Integer(i),ind)+=inittime[i];
287  predsecs.enlarge_right(1,0.);
288  corrsecs.enlarge_right(1,0.);
289  predcalls.enlarge_right(1,0.);
290  corrcalls.enlarge_right(1,0.);
291  for (unsigned int i=0;i<kktdata.size();i++){
292  kktdata[i].add_col(prepsecs,predsecs,corrsecs,predcalls,corrcalls);
293  }
294  return 0;
295  }
296 
297 
299  friend std::ostream& operator<<(std::ostream& out,const QPKKT_ProbStats& p);
300 
302  friend std::istream& operator>>(std::istream& in,QPKKT_ProbStats& p);
303 };
304 
306  std::ostream& operator<<(std::ostream& out,const QPKKT_ProbStats& p);
307 
309  std::istream& operator>>(std::istream& in,QPKKT_ProbStats& p);
310 
312 
313 
314 
318 
328 {
329 private:
330  std::vector<QPKKTSolverObject*> solver;
331  std::vector<std::string> solvername;
332  std::vector<QPKKT_ProbStats> probdata;
333  std::vector<QPModelBlockObject*> model;
334 
342 
344 
349 
351  int violation(CH_Matrix_Classes::Matrix& violvec,const CH_Matrix_Classes::Matrix& solx,const CH_Matrix_Classes::Matrix& soly,QPModelBlockObject* inmodel,QPKKT_SolverStats& stats);
352 
353 public:
355  virtual void clear();
356 
357 
359  QPKKTSolverComparison(CBout* cb=0,int cbinc=-1);
360 
362  virtual ~QPKKTSolverComparison();
363 
365  virtual int add_solver(QPKKTSolverObject* solver,const char* name);
366 
368  virtual int QPinit_KKTdata(QPSolverProxObject* Hp,
369  QPModelBlockObject* model,
371  const CH_Matrix_Classes::Indexmatrix* eq_indices
372  );
373 
375  virtual int QPinit_KKTsystem(const CH_Matrix_Classes::Matrix& KKTdiagx,
376  const CH_Matrix_Classes::Matrix& KKTdiagy,
377  CH_Matrix_Classes::Real Hfactor,
379  QPSolverParameters* params);
380 
382  virtual int QPsolve_KKTsystem(CH_Matrix_Classes::Matrix& solx,
384  const CH_Matrix_Classes::Matrix& primalrhs,
385  const CH_Matrix_Classes::Matrix& dualrhs,
387  CH_Matrix_Classes::Real rhscorr,
389  QPSolverParameters* params);
390 
392  virtual CH_Matrix_Classes::Real QPget_blockH_norm();
393 
395  virtual CH_Matrix_Classes::Real QPget_blockA_norm();
396 
397  //------- for later statistical evaluation purposes
398 
400  std::vector<std::string>& get_solvernames()
401  {return solvername;}
402 
404  std::vector<QPKKT_ProbStats>& get_probdata()
405  {return probdata;}
406 
408  int get_mu_stats(CH_Matrix_Classes::Real lbmu,
412  CH_Matrix_Classes::Matrix& prepsecs,
413  CH_Matrix_Classes::Matrix& predsecs,
414  CH_Matrix_Classes::Matrix& corrsecs,
415  CH_Matrix_Classes::Indexmatrix& predcalls,
416  CH_Matrix_Classes::Indexmatrix& corrcalls,
420  );
421 
423  int get_prob_stats(CH_Matrix_Classes::Indexmatrix& dims,
424  CH_Matrix_Classes::Indexmatrix& iterations,
425  CH_Matrix_Classes::Matrix& lastmu,
426  CH_Matrix_Classes::Matrix& prepsecs,
427  CH_Matrix_Classes::Matrix& predsecs,
428  CH_Matrix_Classes::Matrix& corrsecs,
429  CH_Matrix_Classes::Indexmatrix& predcalls,
431  );
432 
434  friend std::ostream& operator<<(std::ostream& out,const QPKKTSolverComparison& q);
435 
437  friend std::istream& operator>>(std::istream& in,QPKKTSolverComparison& q);
438 };
439 
440 
442  std::ostream& operator<<(std::ostream& out,const QPKKTSolverComparison& q);
443 
445  std::istream& operator>>(std::istream& in,QPKKTSolverComparison& q);
446 
448 
449 
450 
451 }
452 
453 #endif
454 
Integer coldim() const
returns the column dimension
Definition: indexmat.hxx:324
int Integer
all integer numbers in calculations and indexing are of this type
Definition: matop.hxx:40
std::vector< QPKKT_ProbStats > & get_probdata()
returns the stored statistical data
Definition: QPKKTSolverComparison.hxx:404
CH_Tools::Clock clock
for taking the time
Definition: QPKKTSolverComparison.hxx:343
std::vector< QPKKT_SolverStats > sdata
one entry per solver
Definition: QPKKTSolverComparison.hxx:86
parameters for steering the termination criteria and solution method of the solver ...
Definition: QPSolverParameters.hxx:26
QPSolverProxObject * testHp
the proximal term/quadratic cost matrix; this points to external object
Definition: QPKKTSolverComparison.hxx:335
CH_Matrix_Classes::Matrix testdualrhs
stores the input rhs for the H block
Definition: QPKKTSolverComparison.hxx:341
const CH_Matrix_Classes::Sparsemat * testA
the constraint matrix; this points to external object
Definition: QPKKTSolverComparison.hxx:336
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
CH_Matrix_Classes::Real sysviol
norm of the residual of the entire KKT system
Definition: QPKKTSolverComparison.hxx:43
CH_Tools::Microseconds corrtime
time spent in solving the corrector
Definition: QPKKTSolverComparison.hxx:33
CH_Matrix_Classes::Integer Arowdim
rowdim of the constraints
Definition: QPKKTSolverComparison.hxx:185
CH_Matrix_Classes::Real Bviol
norm of the residual for the B block
Definition: QPKKTSolverComparison.hxx:41
CH_Matrix_Classes::Matrix insoly
stores the input solution of the A block (e.g. of predictor)
Definition: QPKKTSolverComparison.hxx:346
std::vector< QPKKTSolverObject * > solver
solvers add via add_solver()
Definition: QPKKTSolverComparison.hxx:330
Matrix class for integral values of type Integer
Definition: indexmat.hxx:195
~QPKKT_SolverStats()
destructor
Definition: QPKKTSolverComparison.hxx:56
CH_Matrix_Classes::Integer Qdim
the order of the H block (the quadratic/proximal term)
Definition: QPKKTSolverComparison.hxx:183
Matrix & concat_right(const Matrix &A, int Atrans=0)
concats matrix A (or its tranpose) to the right of *this, A or *this may be the 0x0 matrix initally...
CH_Matrix_Classes::Real cond
estimate of the condition number
Definition: QPKKTSolverComparison.hxx:37
Used for collecting statics in QPKKTSolverComparison: For each bundle subproblem there is a block QPK...
Definition: QPKKTSolverComparison.hxx:81
~QPKKT_ProbStats()
destructor
Definition: QPKKTSolverComparison.hxx:197
CH_Matrix_Classes::Real Cviol
norm of the residual for the C block
Definition: QPKKTSolverComparison.hxx:42
std::vector< std::string > & get_solvernames()
returns the names of the solvers
Definition: QPKKTSolverComparison.hxx:400
CH_Matrix_Classes::Integer rank
the rank used in the preconditioner
Definition: QPKKTSolverComparison.hxx:38
std::vector< CH_Tools::Microseconds > inittime
time spent in initializing the solver for a subproblem
Definition: QPKKTSolverComparison.hxx:189
std::vector< QPKKT_KKTStats > kktdata
one entry per KKT system
Definition: QPKKTSolverComparison.hxx:190
std::vector< QPModelBlockObject * > model
a seperate clone of the model for each solver in order to avoid side effects
Definition: QPKKTSolverComparison.hxx:333
allows measuring time difference to its initialization time in Microseconds
Definition: clock.hxx:282
CH_Matrix_Classes::Integer Bdim
number of vectors in the bundle
Definition: QPKKTSolverComparison.hxx:187
Used for collecting statics in QPKKTSolverComparison: For each bundle subproblem there is a block QPK...
Definition: QPKKTSolverComparison.hxx:180
Indexmatrix & enlarge_right(Integer addnc)
enlarge the matrix by addnc>=0 columns without intializaton of the new columns, returns *this (marked...
conic bundle method solver for sum of convex functions. See the ConicBundle_Manual for a quick introd...
Definition: CBSolver.hxx:22
int append_col(CH_Matrix_Classes::Matrix &muvals, CH_Matrix_Classes::Matrix &prepsecs, CH_Matrix_Classes::Matrix &predsecs, CH_Matrix_Classes::Matrix &corrsecs, CH_Matrix_Classes::Indexmatrix &predcalls, CH_Matrix_Classes::Indexmatrix &corrcalls, CH_Matrix_Classes::Matrix &cond, CH_Matrix_Classes::Indexmatrix &pccols, CH_Matrix_Classes::Matrix &sysviol)
appends the statsitics data of this KKT system as the last column of the repsective matrices ...
Definition: QPKKTSolverComparison.hxx:96
CH_Matrix_Classes::Real testHfactor
stores a factor for testHp, usually ==1. unless a second order cone variant is used ...
Definition: QPKKTSolverComparison.hxx:339
int get_prob_stats(CH_Matrix_Classes::Indexmatrix &dims, CH_Matrix_Classes::Indexmatrix &iterations, CH_Matrix_Classes::Matrix &lastmu, CH_Matrix_Classes::Matrix &prepsecs, CH_Matrix_Classes::Matrix &predsecs, CH_Matrix_Classes::Matrix &corrsecs, CH_Matrix_Classes::Indexmatrix &predcalls, CH_Matrix_Classes::Indexmatrix &corrcalls)
collects the cummulative values for each quadratic (bundle) subproblem. For each problem a new column...
Definition: QPKKTSolverComparison.hxx:251
base class for uniform use of WARNINGS and ERRORS (at some point in time)
Definition: CBout.hxx:30
extra long integer number for expressing and computing time measurements in microseconds.
Definition: clock.hxx:46
CH_Matrix_Classes::Integer corrnmult
matrix multiplications in solving the correcotr
Definition: QPKKTSolverComparison.hxx:36
CH_Matrix_Classes::Matrix testKKTdiagy
stores the input diagonal for the A block
Definition: QPKKTSolverComparison.hxx:338
Used for collecting statics in QPKKTSolverComparison: For each bundle subproblem there is a block QPK...
Definition: QPKKTSolverComparison.hxx:28
Indexmatrix & concat_right(const Indexmatrix &A)
concats matrix A to the right of *this, A or *this may be the 0x0 matrix initally, returns *this
QPKKT_ProbStats()
constructor
Definition: QPKKTSolverComparison.hxx:193
friend std::istream & operator>>(std::ostream &in, QPKKT_SolverStats &s)
(file-)input
CH_Matrix_Classes::Integer cnt_mu_cols(CH_Matrix_Classes::Real lbmu, CH_Matrix_Classes::Real ubmu)
for collecting the statistics for an interval of barrier parameter values, this first determines the ...
Definition: QPKKTSolverComparison.hxx:200
Matrix & enlarge_right(Integer addnc)
enlarge the matrix by addnc>=0 columns without intializaton of the new columns, returns *this (marked...
CH_Matrix_Classes::Matrix testprimalrhs
stores the input rhs for the A block
Definition: QPKKTSolverComparison.hxx:340
Header declaring the class ConicBundle::QPKKTSolverObject.
friend std::ostream & operator<<(std::ostream &out, const QPKKT_SolverStats &s)
(file-)output
QPKKT_KKTStats()
constructor
Definition: QPKKTSolverComparison.hxx:89
Indexmatrix & init(const Indexmatrix &A, Integer d=1)
initialize to *this=A*d
int add_col(CH_Matrix_Classes::Matrix &prepsecs, CH_Matrix_Classes::Matrix &predsecs, CH_Matrix_Classes::Matrix &corrsecs, CH_Matrix_Classes::Indexmatrix &predcalls, CH_Matrix_Classes::Indexmatrix &corrcalls)
adds the respecitve values of the solvers to last column. It is used for collecting cummlative data f...
Definition: QPKKTSolverComparison.hxx:138
QPKKT_SolverStats()
constructor
Definition: QPKKTSolverComparison.hxx:46
CH_Matrix_Classes::Integer prepnmult
matrix multiplications in setting up the system
Definition: QPKKTSolverComparison.hxx:34
Integer coldim() const
returns the column dimension
Definition: matrix.hxx:218
Matrix class for real values of type Real
Definition: matrix.hxx:74
int get_mu_stats(CH_Matrix_Classes::Real lbmu, CH_Matrix_Classes::Real ubmu, CH_Matrix_Classes::Indexmatrix &dims, CH_Matrix_Classes::Matrix &mu, CH_Matrix_Classes::Matrix &prepsecs, CH_Matrix_Classes::Matrix &predsecs, CH_Matrix_Classes::Matrix &corrsecs, CH_Matrix_Classes::Indexmatrix &predcalls, CH_Matrix_Classes::Indexmatrix &corrcalls, CH_Matrix_Classes::Matrix &cond, CH_Matrix_Classes::Indexmatrix &pccols, CH_Matrix_Classes::Matrix &sysviol)
collects the statistics for an interval of barrier parameter values by appending a column for each KK...
Definition: QPKKTSolverComparison.hxx:211
CH_Matrix_Classes::Real Hviol
norm of the residual for the H block
Definition: QPKKTSolverComparison.hxx:39
~QPKKT_KKTStats()
destructor
Definition: QPKKTSolverComparison.hxx:93
CH_Matrix_Classes::Matrix outsoly
stores the output solution of the A block (first solver)
Definition: QPKKTSolverComparison.hxx:348
CH_Matrix_Classes::Matrix testKKTdiagx
stores the input diagonal for the H block
Definition: QPKKTSolverComparison.hxx:337
CH_Matrix_Classes::Integer prednmult
matrix multiplications in solving the predictor
Definition: QPKKTSolverComparison.hxx:35
Matrix class of sparse matrices with real values of type Real
Definition: sparsmat.hxx:74
abstract interface for model blocks in the constrained QPSolver
Definition: QPModelBlockObject.hxx:89
CH_Tools::Microseconds preptime
time spent in setting up the system
Definition: QPKKTSolverComparison.hxx:31
CH_Matrix_Classes::Real mu
this is the (minimal) mu>0 value used in the calls
Definition: QPKKTSolverComparison.hxx:85
This is a pseudosolver designed for producing comparative statistics on the performance of mainly ite...
Definition: QPKKTSolverComparison.hxx:327
Integer rowdim() const
returns the row dimension
Definition: indexmat.hxx:321
CH_Matrix_Classes::Matrix insolx
stores the input solution of the H block (e.g. of predictor)
Definition: QPKKTSolverComparison.hxx:345
std::vector< std::string > solvername
name of the solver for output
Definition: QPKKTSolverComparison.hxx:331
std::vector< QPKKT_ProbStats > probdata
for each bundle subproblem there is a block QPKKT_ProbStats (stored here), which holds for each KKT s...
Definition: QPKKTSolverComparison.hxx:332
CH_Matrix_Classes::Integer Aeqdim
with this number of equations
Definition: QPKKTSolverComparison.hxx:186
Header declaring and (inline) implementing the classes CH_Tools::Microseconds and CH_Tools::Clock as ...
CH_Matrix_Classes::Matrix outsolx
stores the output solution of the H block (first solver)
Definition: QPKKTSolverComparison.hxx:347
CH_Tools::Microseconds predtime
time spent in solving the predictor
Definition: QPKKTSolverComparison.hxx:32
CH_Matrix_Classes::Integer Cdim
number of constraints in the model
Definition: QPKKTSolverComparison.hxx:188
abstract class for setting up and solving the primal dual KKT System within QPSolverBasicStructures ...
Definition: QPKKTSolverObject.hxx:101
CH_Matrix_Classes::Real prec
this is the (minimal) precision requirement in the calls
Definition: QPKKTSolverComparison.hxx:84
CH_Matrix_Classes::Integer Vdim
the low-rank rank of the H matrix
Definition: QPKKTSolverComparison.hxx:184
CH_Matrix_Classes::Real Aviol
norm of the residual for the A block
Definition: QPKKTSolverComparison.hxx:40
in order to pass a ConicBundle::BundleProxObject, see Quadratic Proximal Terms, to a custzomized QPSo...
Definition: QPSolverObject.hxx:55