NDOSolver / FiOracle
Interfaces and Solvers for NonDifferentiable Optimization
Loading...
Searching...
No Matches
FiOracle.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------*/
2/*--------------------------- File FiOracle.h ------------------------------*/
3/*--------------------------------------------------------------------------*/
17/*--------------------------------------------------------------------------*/
18/*----------------------------- DEFINITIONS --------------------------------*/
19/*--------------------------------------------------------------------------*/
20
21#ifndef _FiOracle
22 #define _FiOracle /* self-identification: #endif at the end of the file */
23
24/*--------------------------------------------------------------------------*/
25/*------------------------------ INCLUDES ----------------------------------*/
26/*--------------------------------------------------------------------------*/
27
28#include "OPTtypes.h"
29
30/*--------------------------------------------------------------------------*/
31/*------------------------ NAMESPACE and USINGS ----------------------------*/
32/*--------------------------------------------------------------------------*/
38namespace NDO_di_unipi_it
39{
40 using namespace OPTtypes_di_unipi_it;
41
42/*--------------------------------------------------------------------------*/
43/*--------------------------- CLASS NDOSolver ------------------------------*/
44/*--------------------------------------------------------------------------*/
53class NDOSolver;
54
55/*--------------------------------------------------------------------------*/
56/*------------------------- CLASS NDOException -----------------------------*/
57/*--------------------------------------------------------------------------*/
66 class NDOException : public exception {
67 public:
68 NDOException( const char *const msg = 0 ) { errmsg = msg; }
69
70 const char* what( void ) const throw() { return( errmsg ); }
71
72 private:
73 const char *errmsg;
74 };
75
76/*--------------------------------------------------------------------------*/
77/*--------------------------- CLASS FiOracle -------------------------------*/
78/*--------------------------------------------------------------------------*/
79/*--------------------------- GENERAL NOTES --------------------------------*/
80/*--------------------------------------------------------------------------*/
231{
232
233/*--------------------------------------------------------------------------*/
234/*----------------------- PUBLIC PART OF THE CLASS -------------------------*/
235/*--------------------------------------------------------------------------*/
236
237 public:
238
239/*--------------------------------------------------------------------------*/
240/*---------------------------- PUBLIC TYPES --------------------------------*/
241/*--------------------------------------------------------------------------*/
248 enum FiStatus { kFiNorm = 0,
249 kFiError ,
250 kFiChgd ,
251 kFiStop ,
252 kFiCont
253 };
254
256/*--------------------- PUBLIC METHODS OF THE CLASS ------------------------*/
257/*--------------------------------------------------------------------------*/
258/*---------------------------- CONSTRUCTOR ---------------------------------*/
259/*--------------------------------------------------------------------------*/
267 FiOracle( void )
268 {
269 Slvr = 0;
270
271 NumVar = MaxName = LamBDim = 0;
272 Lambda = 0;
273 LamBase = 0;
274 LHasChgd = true; // NewGi() has clearly never be called yet
275
276 FiLog = 0;
277 FiLLvl = 0;
278
279 Fit = 0;
280 }
281
283/*-------------------------- OTHER INITIALIZATIONS -------------------------*/
284/*--------------------------------------------------------------------------*/
294 virtual void SetNDOSolver( NDOSolver *NwSlvr = 0 )
295 {
296 Slvr = NwSlvr;
297 }
298
299/*--------------------------------------------------------------------------*/
300
307 virtual void SetFiLog( ostream *outs = 0 , const char lvl = 0 )
308 {
309 if( ( FiLog = outs ) )
310 FiLLvl = lvl;
311 else
312 FiLLvl = 0;
313 }
314
315/*--------------------------------------------------------------------------*/
316
327 virtual void SetFiTime( const bool TimeIt = true )
328 {
329 if( TimeIt )
330 if( Fit )
331 Fit->ReSet();
332 else
333 Fit = new OPTtimers();
334 else {
335 delete Fit;
336 Fit = 0;
337 }
338 }
339
340/*--------------------------------------------------------------------------*/
341
384 virtual void SetMaxName( cIndex MxNme = 0 )
385 {
386 MaxName = MxNme;
387 }
388
390/*-------------- METHODS FOR READING THE DATA OF THE PROBLEM ---------------*/
391/*--------------------------------------------------------------------------*/
402 virtual Index GetNumVar( void ) const
403 {
404 return( NumVar );
405 }
406
407/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
424 virtual Index GetMaxNumVar( void ) const
425 {
426 return( GetNumVar() );
427 }
428
429/*--------------------------------------------------------------------------*/
448 virtual Index GetNrFi( void ) const
449 {
450 return( 1 );
451 }
452
453/*--------------------------------------------------------------------------*/
454
458 virtual Index MaxNConst( void ) {
459 return( 0 );
460 }
461
462/*--------------------------------------------------------------------------*/
474 virtual bool IsFiContinuous( cIndex NrFi = Inf< Index >() )
475 {
476 return( true );
477 }
478
479/*--------------------------------------------------------------------------*/
491 virtual bool IsFiConvex( cIndex NrFi = Inf< Index >() )
492 {
493 return( true );
494 }
495
496/*--------------------------------------------------------------------------*/
510 virtual bool HasGi( cIndex NrFi = Inf< Index >() )
511 {
512 return( true );
513 }
514
515/*--------------------------------------------------------------------------*/
536 virtual bool IsGiContinuous( cIndex NrFi )
537 {
538 return( false );
539 }
540
541/*--------------------------------------------------------------------------*/
557 virtual bool HasH( cIndex NrFi )
558 {
559 return( false );
560 }
561
562/*--------------------------------------------------------------------------*/
584 virtual bool IsHContinuous( cIndex NrFi )
585 {
586 return( false );
587 }
588
589/*--------------------------------------------------------------------------*/
594 virtual Index GetMaxName( void ) const
595 {
596 return( MaxName );
597 }
598
599/*--------------------------------------------------------------------------*/
619 virtual HpNum GetMinusInfinity( void )
620 {
621 return( - Inf< HpNum >() );
622 }
623
624/*--------------------------------------------------------------------------*/
651 virtual Index GetMaxNZ( cIndex wFi = Inf< Index >() ) const
652 {
653 return( GetMaxNumVar() );
654 }
655
656/*--------------------------------------------------------------------------*/
684 virtual Index GetMaxCNZ( cIndex wFi = Inf< Index >() ) const
685 {
686 return( GetMaxNumVar() );
687 }
688
689/*--------------------------------------------------------------------------*/
706 virtual bool GetUC( cIndex i )
707 {
708 return( true );
709 }
710
711/*--------------------------------------------------------------------------*/
729 virtual LMNum GetUB( cIndex i )
730 {
731 return( Inf< LMNum >() );
732 }
733
734/*--------------------------------------------------------------------------*/
759 virtual LMNum GetBndEps( void )
760 {
761 return( 0 );
762 }
763
764/*--------------------------------------------------------------------------*/
779
780 {
781 return( Inf< HpNum >() );
782 }
783
784/*--------------------------------------------------------------------------*/
882 virtual Index GetBNC( cIndex wFi )
883 {
884 return( 0 );
885 }
886
887/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
892 virtual Index GetBNR( cIndex wFi )
893 {
894 return( 0 );
895 }
896
897/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
901 virtual Index GetBNZ( cIndex wFi )
902 {
903 return( 0 );
904 }
905
906/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
952 virtual void GetBDesc( cIndex wFi , int *Bbeg , int *Bind , double *Bval ,
953 double *lhs , double *rhs , double *cst ,
954 double *lbd , double *ubd )
955 {
956 throw( NDOException( "GetBDesc: this component is not easy" ) );
957 }
958
959/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
966 virtual Index GetANZ( cIndex wFi , cIndex strt = 0 ,
967 Index stp = Inf< Index >() )
968 {
969 return( 0 );
970 }
971
972/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
978 virtual void GetADesc( cIndex wFi , int *Abeg , int *Aind , double *Aval ,
979 cIndex strt = 0 , Index stp = Inf< Index >() )
980 {
981 throw( NDOException( "GetADesc: this component is not easy" ) );
982 }
983
988 virtual NDOSolver *GetNDOSolver( void )
989 {
990 return( Slvr );
991 }
992
994/*---------------------- METHODS FOR SETTING LAMBDA ------------------------*/
995/*--------------------------------------------------------------------------*/
1017 virtual void SetLambda( cLMRow Lmbd = 0 )
1018 {
1019 Lambda = Lmbd;
1020 LHasChgd = true;
1021 }
1022
1023/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
1067 virtual void SetLamBase( cIndex_Set LmbdB = 0 , cIndex LmbdBD = 0 )
1068 {
1069 LamBase = LmbdB;
1070 LamBDim = LamBase ? LmbdBD : NumVar;
1071 }
1072
1073/*--------------------------------------------------------------------------*/
1157 virtual bool SetPrecision( HpNum Eps )
1158 {
1159 return( false );
1160 }
1161
1163/*----------------------- METHODS FOR COMPUTING Fi() -----------------------*/
1164/*--------------------------------------------------------------------------*/
1168 virtual HpNum Fi( cIndex wFi = Inf< Index >() ) = 0;
1169
1221/*------------- METHODS FOR READING SUBGRADIENTS / CONSTRAINTS -------------*/
1222/*--------------------------------------------------------------------------*/
1253/*--------------------------------------------------------------------------*/
1308 virtual bool NewGi( cIndex wFi = Inf< Index >() )
1309 {
1310 return( LHasChgd );
1311 }
1312
1313/*--------------------------------------------------------------------------*/
1314
1315 virtual Index GetGi( SgRow SubG , cIndex_Set &SGBse ,
1316 cIndex Name = Inf< Index >() ,
1317 cIndex strt = 0 , Index stp = Inf< Index >() ) = 0;
1318
1393/*--------------------------------------------------------------------------*/
1457 virtual HpNum GetVal( cIndex Name = Inf< Index >() )
1458 {
1459 if( Name < MaxName )
1460 throw( NDOException( "GetVal: past information is not recorded" ) );
1461
1462 return( 0 );
1463 }
1464
1465/*--------------------------------------------------------------------------*/
1466
1467 virtual void SetGiName( cIndex Name ) {}
1468
1532/*--------------------------------------------------------------------------!!
1533
1534 virtual void GetH( ... )
1535
1536 < We must decide exactly the signature of GetH(), whether or not we need
1537 something like "NewH()", whether or not we need "SetHName()", etc.
1538 In particular, we must decide a reasonable format for the Hessians.
1539 The best would be an abstract C++ matrix class which can hold different
1540 types of matrices (diagonal, banded, sparse, dense, ...). One may use
1541 some existing C++ library for that; however, being this an abstract
1542 interface it would be better to have it depend on the smallest possible
1543 number of other libraries (possibly none); if we do use some, it should
1544 be a "very light" library, i.e., not one such that compiling it is
1545 very complicated, since many of the solvers would not actually use it.
1546 In other words, I don't think that lapack++ is the right one.
1547
1548 However, I don't have a clear opinion on that. Suggestions? */
1549
1551/*-------------------- METHODS FOR READING OTHER RESULTS -------------------*/
1552/*--------------------------------------------------------------------------*/
1602 {
1603 return( - Inf< HpNum >() );
1604 }
1605
1606/*--------------------------------------------------------------------------*/
1699 {
1700 return( kFiNorm );
1701 }
1702
1703/*--------------------------------------------------------------------------*/
1718 void FiTime( double &t_us , double &t_ss )
1719 {
1720 t_us = t_ss = 0;
1721 if( Fit ) Fit->Read( t_us , t_ss );
1722 }
1723
1724/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
1728 double FiTime( void )
1729 {
1730 return( Fit ? Fit->Read() : 0 );
1731 }
1732
1734/*------------- METHODS FOR ADDING / REMOVING / CHANGING DATA --------------*/
1735/*--------------------------------------------------------------------------*/
1739 virtual void Deleted( cIndex i = Inf< Index >() ) {}
1740
1758/*--------------------------------------------------------------------------*/
1759
1760 virtual void Aggregate( cHpRow Mlt , cIndex_Set NmSt , cIndex Dm ,
1761 cIndex NwNm ) {}
1762
1796/*------------------------------ DESTRUCTOR --------------------------------*/
1797/*--------------------------------------------------------------------------*/
1806 virtual ~FiOracle() { delete Fit; }
1807
1809/*-------------------- PROTECTED PART OF THE CLASS -------------------------*/
1810/*--------------------------------------------------------------------------*/
1811
1812 protected:
1813
1814/*--------------------------------------------------------------------------*/
1815/*----------------------- PROTECTED DATA STRUCTURES -----------------------*/
1816/*--------------------------------------------------------------------------*/
1830
1840 ostream *FiLog;
1841 char FiLLvl;
1842
1844
1846/*--------------------------------------------------------------------------*/
1847
1848 }; // end( class FiOracle )
1849
1850/*--------------------------------------------------------------------------*/
1851
1852 } // end( namespace NDO_di_unipi_it )
1853
1854/*--------------------------------------------------------------------------*/
1855/*--------------------------------------------------------------------------*/
1856
1857#endif /* FiOracle.h included */
1858
1859/*--------------------------------------------------------------------------*/
1860/*------------------------- End File FiOracle.h ----------------------------*/
1861/*--------------------------------------------------------------------------*/
Definition FiOracle.h:231
FiStatus
Definition FiOracle.h:248
virtual Index GetNrFi(void) const
Definition FiOracle.h:448
virtual bool GetUC(cIndex i)
Definition FiOracle.h:706
cIndex_Set LamBase
Definition FiOracle.h:1834
bool LHasChgd
Definition FiOracle.h:1837
virtual bool IsGiContinuous(cIndex NrFi)
Definition FiOracle.h:536
char FiLLvl
the "level of verbosity" of the log
Definition FiOracle.h:1841
Index MaxName
maximum name to be used in SetGiName()
Definition FiOracle.h:1829
virtual void Aggregate(cHpRow Mlt, cIndex_Set NmSt, cIndex Dm, cIndex NwNm)
Definition FiOracle.h:1760
virtual LMNum GetBndEps(void)
Definition FiOracle.h:759
virtual void SetGiName(cIndex Name)
Definition FiOracle.h:1467
virtual bool HasGi(cIndex NrFi=Inf< Index >())
Definition FiOracle.h:510
virtual void SetNDOSolver(NDOSolver *NwSlvr=0)
Definition FiOracle.h:294
virtual bool IsFiConvex(cIndex NrFi=Inf< Index >())
Definition FiOracle.h:491
ostream * FiLog
the output stream object for log purposes
Definition FiOracle.h:1840
virtual Index GetGi(SgRow SubG, cIndex_Set &SGBse, cIndex Name=Inf< Index >(), cIndex strt=0, Index stp=Inf< Index >())=0
double FiTime(void)
Definition FiOracle.h:1728
cLMRow Lambda
Definition FiOracle.h:1831
virtual ~FiOracle()
Definition FiOracle.h:1806
virtual HpNum GetMinusInfinity(void)
Definition FiOracle.h:619
virtual bool HasH(cIndex NrFi)
Definition FiOracle.h:557
NDOSolver * Slvr
Definition FiOracle.h:1825
virtual Index GetMaxNZ(cIndex wFi=Inf< Index >()) const
Definition FiOracle.h:651
Index LamBDim
length of LamBase[]
Definition FiOracle.h:1836
virtual LMNum GetUB(cIndex i)
Definition FiOracle.h:729
virtual bool SetPrecision(HpNum Eps)
Definition FiOracle.h:1157
virtual void SetMaxName(cIndex MxNme=0)
Definition FiOracle.h:384
virtual void SetLambda(cLMRow Lmbd=0)
Definition FiOracle.h:1017
virtual void Deleted(cIndex i=Inf< Index >())
Definition FiOracle.h:1739
virtual HpNum Fi(cIndex wFi=Inf< Index >())=0
virtual bool IsHContinuous(cIndex NrFi)
Definition FiOracle.h:584
virtual void SetFiLog(ostream *outs=0, const char lvl=0)
Definition FiOracle.h:307
virtual FiStatus GetFiStatus(Index wFi=Inf< Index >())
Definition FiOracle.h:1698
virtual Index MaxNConst(void)
Definition FiOracle.h:458
virtual Index GetMaxName(void) const
Definition FiOracle.h:594
virtual Index GetMaxCNZ(cIndex wFi=Inf< Index >()) const
Definition FiOracle.h:684
virtual HpNum GetGlobalLipschitz(cIndex wFi=Inf< Index >())
Definition FiOracle.h:778
virtual bool IsFiContinuous(cIndex NrFi=Inf< Index >())
Definition FiOracle.h:474
virtual HpNum GetLowerBound(cIndex wFi=Inf< Index >())
Definition FiOracle.h:1601
virtual void SetFiTime(const bool TimeIt=true)
Definition FiOracle.h:327
virtual void SetLamBase(cIndex_Set LmbdB=0, cIndex LmbdBD=0)
Definition FiOracle.h:1067
virtual HpNum GetVal(cIndex Name=Inf< Index >())
Definition FiOracle.h:1457
OPTtimers * Fit
OPTtimer for timing purposes.
Definition FiOracle.h:1843
virtual Index GetMaxNumVar(void) const
Definition FiOracle.h:424
FiOracle(void)
Definition FiOracle.h:267
void FiTime(double &t_us, double &t_ss)
Definition FiOracle.h:1718
virtual bool NewGi(cIndex wFi=Inf< Index >())
Definition FiOracle.h:1308
virtual Index GetNumVar(void) const
Definition FiOracle.h:402
Index NumVar
(current) number of variables if Fi()
Definition FiOracle.h:1828
Definition FiOracle.h:66
Definition NDOSlver.h:60
Definition OPTUtils.h:144
void ReSet(void)
reset the timer
Definition OPTUtils.h:214
double Read(void)
Definition OPTUtils.h:184
virtual Index GetBNZ(cIndex wFi)
Definition FiOracle.h:901
virtual Index GetBNR(cIndex wFi)
Definition FiOracle.h:892
virtual void GetADesc(cIndex wFi, int *Abeg, int *Aind, double *Aval, cIndex strt=0, Index stp=Inf< Index >())
Definition FiOracle.h:978
virtual Index GetANZ(cIndex wFi, cIndex strt=0, Index stp=Inf< Index >())
Definition FiOracle.h:966
virtual NDOSolver * GetNDOSolver(void)
Definition FiOracle.h:988
virtual void GetBDesc(cIndex wFi, int *Bbeg, int *Bind, double *Bval, double *lhs, double *rhs, double *cst, double *lbd, double *ubd)
Definition FiOracle.h:952
virtual Index GetBNC(cIndex wFi)
Definition FiOracle.h:882
double HpNum
"finer" floating point numbers
Definition OPTtypes.h:98
const Index cIndex
a read-only Index
Definition OPTtypes.h:64
cIndex * cIndex_Set
read-only array
Definition OPTtypes.h:65
unsigned int Index
Index in a vector ( >= 0 )
Definition OPTtypes.h:60
cHpNum * cHpRow
read-only array
Definition OPTtypes.h:103
SgNum * SgRow
a subgradient
Definition OPTtypes.h:112
double LMNum
a Lagrangean Multiplier
Definition OPTtypes.h:129
cLMNum * cLMRow
a read-only vector of LMs
Definition OPTtypes.h:134
static constexpr T Inf(void) noexcept
Inf< T >() = infinity value for T.
Definition OPTUtils.h:357
static constexpr T Eps(void) noexcept
Eps< T >() = "machine epsilon" for T.
Definition OPTUtils.h:367
Definition Bundle.h:68
Definition OPTtypes.h:41