ConicBundle
BundleTerminator.hxx
Go to the documentation of this file.
1 
2 
3 #ifndef CONICBUNDLE_BUNDLETERMINATOR_HXX
4 #define CONICBUNDLE_BUNDLETERMINATOR_HXX
5 
6 
15 #include "matrix.hxx"
16 #include "clock.hxx"
17 #include "CBSolver.hxx"
18 #include "CBout.hxx"
19 
20 namespace ConicBundle {
21 
26 
30 {
31 public:
33  virtual ~BundleTerminatorData(); //implemented in BundleTerminator.cxx
34 
36  virtual CH_Matrix_Classes::Integer get_cntobjeval() const =0;
38  virtual CH_Matrix_Classes::Integer get_sumrecomp() const =0;
40  virtual CH_Matrix_Classes::Integer get_suminnerit() const =0;
42  virtual CH_Matrix_Classes::Integer get_sumqpfails() const =0;
44  virtual CH_Matrix_Classes::Real get_center_objval() const =0;
46  virtual CH_Matrix_Classes::Real get_cand_objval() const =0;
48  virtual CH_Matrix_Classes::Real get_modelval() const =0;
50  virtual CH_Matrix_Classes::Real get_aggr_dnormsqr() const =0;
62  virtual CH_Matrix_Classes::Real get_term_corr() const =0;
63 
64 };
65 
67 
68 class BundleSolver;
69 class NBundleSolver;
70 
77  class BundleTerminator: public CBout
78 {
79  friend class BundleSolver;
80  friend class NBundleSolver;
81 
82 protected:
87 
92 
95 
98 
101 
104 
107 
110 
113 
114 
131  {
132  terminated=0;
133  if (clockp)
134  terminated|=2*(clockp->time()>=timelimit);
135  if (recomplimit>=0)
136  terminated|=4*(recomplimit<=sb->get_sumrecomp());
137  if (qpfailslimit>=0)
138  terminated|=8*(qpfailslimit<=sb->get_sumqpfails());
139  if (modelfailslimit>=0)
140  terminated|=16*(modelfailslimit<=sb->get_summodelfails());
141  if (augvalfailslimit>=0)
142  terminated|=32*(augvalfailslimit<=sb->get_sumaugvalfails());
143  if (objevallimit>=0)
144  terminated|=64*(objevallimit<=sb->get_cntobjeval());
145  if (oraclefailslimit>=0)
146  terminated|=128*(oraclefailslimit<=sb->get_sumoraclefails());
147  if ((sb->get_suminnerit()<10)&&(sb->get_aggr_dnormsqr()>0.1)) return terminated;
148  if ((aggregate_dnormsqr>0)&&(sb->get_aggr_dnormsqr()>aggregate_dnormsqr)) return terminated;
149  CH_Matrix_Classes::Real center_objval=sb->get_center_objval();
150  terminated|=(center_objval-sb->get_modelval()<=
151  termeps*(CH_Matrix_Classes::abs(center_objval)+1.)*sb->get_term_corr());
152  return terminated;
153  }
154 
155 public:
157  virtual void set_defaults()
158  {
159  termeps=1e-5;clockp=0;timelimit.set_infinity(true);
160  recomplimit=100;qpfailslimit=100;modelfailslimit=100;
161  augvalfailslimit=10;oraclefailslimit=10;objevallimit=-1;
162  aggregate_dnormsqr=-1.;
163  }
164 
166  virtual void clear()
167  { terminated=0; }
168 
170  BundleTerminator(const CBout* cb=0,int incr=-1):CBout(cb,incr)
171  { /*save_function=0;*/ set_defaults(); clear(); }
172 
174  virtual ~BundleTerminator(); //implemented in bundleterminator.cxx
175 
178  {if (teps>0.) termeps=teps;}
180  virtual CH_Matrix_Classes::Real get_termeps() const {return termeps;}
182  virtual void set_aggr_dnormsqr(CH_Matrix_Classes::Real sg){aggregate_dnormsqr=sg;}
184  virtual CH_Matrix_Classes::Real get_aggr_dnormsqr() const {return aggregate_dnormsqr;}
187  {clockp=cp;timelimit=tl;}
189  virtual CH_Tools::Microseconds get_timelimit() const {return timelimit;}
191  virtual void set_recomplimit(CH_Matrix_Classes::Integer rl){recomplimit=rl;}
193  virtual CH_Matrix_Classes::Integer get_recomplimit() const {return recomplimit;}
195  virtual void set_qpfailslimit(CH_Matrix_Classes::Integer ql){qpfailslimit=ql;}
197  virtual CH_Matrix_Classes::Integer get_qpfailslimit() const {return qpfailslimit;}
199  virtual void set_modelfailslimit(CH_Matrix_Classes::Integer ml){modelfailslimit=ml;}
201  virtual CH_Matrix_Classes::Integer get_modelfailslimit() const {return modelfailslimit;}
203  virtual void set_augvalfailslimit(CH_Matrix_Classes::Integer al){augvalfailslimit=al;}
205  virtual CH_Matrix_Classes::Integer get_augvalfailslimit() const {return augvalfailslimit;}
207  virtual void set_objevallimit(CH_Matrix_Classes::Integer ol){objevallimit=ol;}
209  virtual CH_Matrix_Classes::Integer get_objevallimit() const {return objevallimit;}
211  virtual void set_oraclefailslimit(CH_Matrix_Classes::Integer ol){oraclefailslimit=ol;}
213  virtual CH_Matrix_Classes::Integer get_oraclefailslimit() const {return oraclefailslimit;}
214 
216  virtual int get_terminated() const {return terminated;}
218  virtual void clear_terminated() {terminated=0;}
219 
221  virtual void print_status(std::ostream& o) const
222  {
223  o<<"termination status: "<<terminated;
224  if (terminated==0) { o<<" (not terminated)"<<std::endl; return;}
225  if (terminated & 1){ o<<", relative precision criterion satisfied"; }
226  if (terminated & 2){ o<<", timelimit exceeded"; }
227  if (terminated & 4){ o<<", function reevaluation limit exceeded";}
228  if (terminated & 8){ o<<", limit of QP failures exceeded";}
229  if (terminated & 16){ o<<", limit of model failures exceeded";}
230  if (terminated & 32){ o<<", limit of augmented model failures exceeded";}
231  if (terminated & 64){ o<<", limit of calls to evaluation oracle exceeded";}
232  if (terminated & 128){ o<<", limit of failed oracle calls exceeded";}
233  o<<std::endl;
234  }
235 
237  virtual std::ostream& save(std::ostream& o) const
238  {
239  o.precision(20);
240  o<<termeps<<"\n"<<timelimit<<"\n"<<recomplimit<<"\n"<<qpfailslimit<<"\n"<<modelfailslimit<<"\n"<<augvalfailslimit<<"\n"<<objevallimit<<"\n"<<oraclefailslimit<<"\n"<<aggregate_dnormsqr<<"\n"<<terminated<<"\n";
241  return o;
242  }
243 
245  virtual std::istream& restore(std::istream& in)
246  {
247  in>>termeps;
248  in>>timelimit;
249  in>>recomplimit;
250  in>>qpfailslimit;
251  in>>modelfailslimit;
252  in>>augvalfailslimit;
253  in>>objevallimit;
254  in>>oraclefailslimit;
255  in>>aggregate_dnormsqr;
256  in>>terminated;
257  return in;
258  }
259 };
260 
262 
263 }
264 
265 #endif
266 
virtual CH_Tools::Microseconds get_timelimit() const
returns the timelimit value
Definition: BundleTerminator.hxx:189
int Integer
all integer numbers in calculations and indexing are of this type
Definition: matop.hxx:40
virtual void set_termeps(CH_Matrix_Classes::Real teps)
set the termination precision (>0!)
Definition: BundleTerminator.hxx:177
virtual std::ostream & save(std::ostream &o) const
output current parameter settings
Definition: BundleTerminator.hxx:237
Header declaring the classes CH_Matrix_Classes::Realrange and CH_Matrix_Classes::Matrix having Real e...
CH_Matrix_Classes::Real aggregate_dnormsqr
if the value is positive, do not terminate due to sufficient precision as long as the squared dual no...
Definition: BundleTerminator.hxx:86
virtual CH_Matrix_Classes::Integer get_sumaugvalfails() const =0
returns the number of times, the augmented model value could not be increased over all descent and nu...
virtual CH_Matrix_Classes::Integer get_objevallimit() const
returns the current value of this parameter
Definition: BundleTerminator.hxx:209
virtual int get_terminated() const
return the termination code returned in the last call to check_termination()
Definition: BundleTerminator.hxx:216
double Real
all real numbers in calculations are of this type
Definition: matop.hxx:50
CH_Matrix_Classes::Integer objevallimit
upper limit on number returned in BundleTerminatorData::get_cntobjeval, <0 if no limit ...
Definition: BundleTerminator.hxx:106
virtual void set_aggr_dnormsqr(CH_Matrix_Classes::Real sg)
set an upper bound for the dual norm squared of the aggregate at termination (or <=0 if no such bound...
Definition: BundleTerminator.hxx:182
virtual CH_Matrix_Classes::Real get_term_corr() const =0
returns a correction factor for the termination criterion if the quadratic term is big (the proximal ...
virtual CH_Matrix_Classes::Real get_aggr_dnormsqr() const
returns the current bound for the dual norm squared of the aggregate
Definition: BundleTerminator.hxx:184
CH_Tools::Microseconds timelimit
if clockp is not Null then this gives the upper time limit in Microseconds
Definition: BundleTerminator.hxx:91
BundleTerminator(const CBout *cb=0, int incr=-1)
calls set_defaults() and clear()
Definition: BundleTerminator.hxx:170
virtual void set_timelimit(const CH_Tools::Clock *cp, CH_Tools::Microseconds tl)
set cp==0 for no timelimit, otherwise specify clock and microseconds
Definition: BundleTerminator.hxx:186
virtual CH_Matrix_Classes::Integer get_qpfailslimit() const
returns the current value of this parameter
Definition: BundleTerminator.hxx:197
virtual void set_recomplimit(CH_Matrix_Classes::Integer rl)
set upper bound on the value returned by BundleTerminatorData::get_sumrecomp, <0 if no limit ...
Definition: BundleTerminator.hxx:191
virtual void set_modelfailslimit(CH_Matrix_Classes::Integer ml)
set upper bound on the value returned by BundleTerminatorData::get_summodelfails, <0 if no limit ...
Definition: BundleTerminator.hxx:199
virtual CH_Matrix_Classes::Real get_center_objval() const =0
returns the upper bound on the function value in the current center of stability
virtual CH_Matrix_Classes::Integer get_oraclefailslimit() const
returns the current value of this parameter
Definition: BundleTerminator.hxx:213
virtual void print_status(std::ostream &o) const
output an explanation string for the current termination code
Definition: BundleTerminator.hxx:221
allows measuring time difference to its initialization time in Microseconds
Definition: clock.hxx:282
virtual void clear()
resets terminated
Definition: BundleTerminator.hxx:166
CH_Matrix_Classes::Integer recomplimit
upper limit on number returned in BundleTerminatorData::get_sumrecomp, <0 if no limit ...
Definition: BundleTerminator.hxx:94
conic bundle method solver for sum of convex functions. See the ConicBundle_Manual for a quick introd...
Definition: CBSolver.hxx:22
virtual CH_Matrix_Classes::Integer get_suminnerit() const =0
returns the number of descent and null steps
base class for uniform use of WARNINGS and ERRORS (at some point in time)
Definition: CBout.hxx:30
virtual CH_Matrix_Classes::Integer get_sumqpfails() const =0
returns the number of times, the call to a quadratic subproblem failed
virtual CH_Matrix_Classes::Integer get_summodelfails() const =0
returns the number of failed callls to model evaluations
extra long integer number for expressing and computing time measurements in microseconds.
Definition: clock.hxx:46
virtual CH_Matrix_Classes::Integer get_recomplimit() const
returns the current value of this parameter
Definition: BundleTerminator.hxx:193
virtual CH_Matrix_Classes::Integer get_augvalfails() const =0
returns the number of times, the augmented model value could not be increased since the last descent ...
This is the internal bundle solver managing descent/null steps with inner updates for approximating t...
Definition: BundleSolver.hxx:103
Header declaring the classes ConicBundle::CBSolver, ConicBundle::FunctionOracle and ConicBundle::Prim...
virtual void set_oraclefailslimit(CH_Matrix_Classes::Integer ol)
set upper bound on the value returned by BundleTerminatorData::get_sumoraclefails, <0 if no limit
Definition: BundleTerminator.hxx:211
virtual CH_Matrix_Classes::Integer get_sumrecomp() const =0
returns the number of reevalutions in center points (if their function value violates the most recent...
Header declaring the output class CBout.
virtual CH_Matrix_Classes::Real get_termeps() const
returns the current termination precision
Definition: BundleTerminator.hxx:180
Microseconds time() const
return time elapsed since last call to start() in Microseconds (possibly adding an optional offset) ...
Definition: clock.hxx:318
CH_Matrix_Classes::Integer qpfailslimit
upper limit on number returned in BundleTerminatorData::get_sumqpfails, <0 if no limit ...
Definition: BundleTerminator.hxx:97
const CH_Tools::Clock * clockp
if a computation time criterion is set, this pointer is also set and points at the clock to be used ...
Definition: BundleTerminator.hxx:89
virtual CH_Matrix_Classes::Integer get_modelfailslimit() const
returns the current value of this parameter
Definition: BundleTerminator.hxx:201
CH_Matrix_Classes::Integer augvalfailslimit
upper limit on number returned in BundleTerminatorData::get_sumaugvalfails, <0 if no limit ...
Definition: BundleTerminator.hxx:103
basic class implementing termination criteria for BundleSolver, may also serve as base class for othe...
Definition: BundleTerminator.hxx:77
virtual CH_Matrix_Classes::Real get_modelval() const =0
returns the model value in the current candidate
virtual void set_augvalfailslimit(CH_Matrix_Classes::Integer al)
set upper bound on the value returned by BundleTerminatorData::get_sumaugvalfails(), <0 if no limit
Definition: BundleTerminator.hxx:203
virtual void set_qpfailslimit(CH_Matrix_Classes::Integer ql)
set upper bound on the value returned by BundleTerminatorData::get_sumqpfails, <0 if no limit ...
Definition: BundleTerminator.hxx:195
virtual CH_Matrix_Classes::Integer get_augvalfailslimit() const
returns the current value of this parameter
Definition: BundleTerminator.hxx:205
virtual CH_Matrix_Classes::Integer get_sumoraclefails() const =0
returns the number of times, the oracle returend some error code over all descent and null steps ...
virtual CH_Matrix_Classes::Real get_aggr_dnormsqr() const =0
returns the norm of the aggregate subgradient squared (for the norm dual to quadratic augmented term)...
abstract interface for BundleTerminator providing the data needed for deciding on termination ...
Definition: BundleTerminator.hxx:29
virtual void set_objevallimit(CH_Matrix_Classes::Integer ol)
set upper bound on the value returned by BundleTerminatorData::get_cntobjeval, <0 if no limit ...
Definition: BundleTerminator.hxx:207
virtual int check_termination(BundleTerminatorData *sb)
computes and returns a termination code for the BundleTerminationData passed to this ...
Definition: BundleTerminator.hxx:130
virtual CH_Matrix_Classes::Integer get_cntobjeval() const =0
returns the number of calls to the oracle, i.e., to BundleProblem::eval_function() ...
CH_Matrix_Classes::Integer modelfailslimit
upper limit on number returned in BundleTerminatorData::get_summodelfails, <0 if no limit ...
Definition: BundleTerminator.hxx:100
virtual CH_Matrix_Classes::Real get_cand_objval() const =0
returns the upper bound on the function value in the current candidate
int terminated
result of last call to check_termination
Definition: BundleTerminator.hxx:112
virtual void set_defaults()
sets the default parameter values
Definition: BundleTerminator.hxx:157
CH_Matrix_Classes::Real termeps
termination precision
Definition: BundleTerminator.hxx:84
double abs(double d)
absolute value of a double
Definition: mymath.hxx:25
Header declaring and (inline) implementing the classes CH_Tools::Microseconds and CH_Tools::Clock as ...
void set_infinity(bool infty)
use true to regard value as infinity
Definition: clock.hxx:164
virtual void clear_terminated()
reset the termination code to zero (this does not remove the reason for the termination; for this...
Definition: BundleTerminator.hxx:218
virtual std::istream & restore(std::istream &in)
input new parameter settings, the clock must be set in addition!
Definition: BundleTerminator.hxx:245
virtual CH_Matrix_Classes::Integer get_oraclefails() const =0
returns the number of times, the oracle returend some error code since the last descent step ...
CH_Matrix_Classes::Integer oraclefailslimit
upper limit on number returned in BundleTerminatorData::get_sumoraclefails, <0 if no limit ...
Definition: BundleTerminator.hxx:109