NDOSolver / FiOracle
Interfaces and Solvers for NonDifferentiable Optimization
Loading...
Searching...
No Matches
MPSolver.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------*/
2/*--------------------------- File MPSolver.h ------------------------------*/
3/*--------------------------------------------------------------------------*/
18/*--------------------------------------------------------------------------*/
19/*----------------------------- DEFINITIONS --------------------------------*/
20/*--------------------------------------------------------------------------*/
21
22#ifndef __MPSolver
23 #define __MPSolver /* self-identification: #endif at the end of the file */
24
25/*--------------------------------------------------------------------------*/
26/*-------------------------------- MACROS ----------------------------------*/
27/*--------------------------------------------------------------------------*/
28
29/*--------------------------------------------------------------------------*/
30/*------------------------------ INCLUDES ----------------------------------*/
31/*--------------------------------------------------------------------------*/
32
33#include "FiOracle.h"
34
35/*--------------------------------------------------------------------------*/
36/*----------------------------- NAMESPACE ----------------------------------*/
37/*--------------------------------------------------------------------------*/
38
39namespace NDO_di_unipi_it
40{
41
42/*--------------------------------------------------------------------------*/
43/*----------------------------- CONSTANTS ----------------------------------*/
44/*--------------------------------------------------------------------------*/
45
46/*--------------------------------------------------------------------------*/
47/*--------------------------- CLASS MPSolver -------------------------------*/
48/*--------------------------------------------------------------------------*/
49/*--------------------------- GENERAL NOTES --------------------------------*/
50/*--------------------------------------------------------------------------*/
121{
122
123/*--------------------------------------------------------------------------*/
124/*----------------------- PUBLIC PART OF THE CLASS -------------------------*/
125/*--------------------------------------------------------------------------*/
126
127 public:
128
129/*--------------------------------------------------------------------------*/
130/*---------------------------- PUBLIC TYPES --------------------------------*/
131/*--------------------------------------------------------------------------*/
142 enum MPParam { kMaxTme = 0 ,
143 kOptEps , kFsbEps , // kZero ,
144 kLastMPParam
145 };
146
147/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
151 enum MPStatus { kOK = 0 ,
152 kUnbndd , kUnfsbl ,
153 kStppd , kError
154 };
155
157/*--------------------------- PUBLIC METHODS -------------------------------*/
158/*--------------------------------------------------------------------------*/
159/*---------------------------- CONSTRUCTOR ---------------------------------*/
160/*--------------------------------------------------------------------------*/
168 MPSolver( void ) : MaxBSize( 0 ) , MaxSGLen( 0 ) , CrrSGLen( 0 ) ,
169 NrFi( 1 ) , MPLog( nullptr ) , MPLLvl( 0 ) , MPt( nullptr ) {}
170
172/*-------------------------- OTHER INITIALIZATIONS -------------------------*/
173/*--------------------------------------------------------------------------*/
278 virtual void SetDim( cIndex MxBSz = 0 , FiOracle *Oracle = nullptr ,
279 const bool UsAvSt = false )
280 {
281 MaxBSize = MxBSz;
282
283 if( Oracle ) {
284 MaxSGLen = Oracle->GetMaxNumVar();
285 CrrSGLen = Oracle->GetNumVar();
286 NrFi = Oracle->GetNrFi();
287 }
288 }
289
290/*--------------------------------------------------------------------------*/
294 virtual void Sett( cHpNum tt = 1 ) = 0;
295
296/*--------------------------------------------------------------------------*/
336 virtual void SetPar( const int wp , cHpNum value ) = 0;
337
338/*--------------------------------------------------------------------------*/
343 virtual void SetThreads( int nthreads ) {}
344
386 virtual void SetLowerBound( cHpNum LwBnd = - Inf< HpNum >() ,
387 cIndex wFi = Inf< Index >() ) = 0;
388
389/*--------------------------------------------------------------------------*/
396 virtual void CheckIdentical( const bool Chk = true ) {
397 // the derived class may ignore the setting of CheckIdentical(), that's
398 // why a default implementation doing nothing is provided
399 }
400
401/*--------------------------------------------------------------------------*/
408 virtual void SetMPLog( std::ostream *outs = 0 , const char lvl = 0 ) {
409 if( ( MPLog = outs ) )
410 MPLLvl = lvl;
411 else
412 MPLLvl = 0;
413 }
414
415/*--------------------------------------------------------------------------*/
426 virtual void SetMPTime( const bool TimeIt = true ) {
427 if( TimeIt )
428 if( MPt )
429 MPt->ReSet();
430 else
431 MPt = new OPTtimers();
432 else
433 delete MPt;
434 }
435
437/*-------------------- METHODS FOR SOLVING THE PROBLEM ---------------------*/
438/*--------------------------------------------------------------------------*/
492 virtual MPStatus SolveMP( void ) = 0;
493
495/*---------------------- METHODS FOR READING RESULTS -----------------------*/
496/*--------------------------------------------------------------------------*/
549 virtual HpNum ReadFiBLambda( cIndex wFi = Inf< Index >() ) = 0;
550
551/*--------------------------------------------------------------------------*/
555 virtual HpNum ReadDt( cHpNum tt = 1 ) = 0;
556
557/*--------------------------------------------------------------------------*/
605 virtual HpNum ReadSigma( cIndex wFi = Inf< Index >() ) = 0;
606
607/*--------------------------------------------------------------------------*/
611 virtual HpNum ReadDStart( cHpNum tt = 1 ) = 0;
612
613/*--------------------------------------------------------------------------*/
632 virtual cLMRow Readd( bool Fulld = false ) = 0;
633
634/*--------------------------------------------------------------------------*/
682 virtual void ReadZ( LMRow tz , cIndex_Set &I , Index &D ,
683 cIndex wFi = Inf< Index >() ) = 0;
684
685/*--------------------------------------------------------------------------*/
740 virtual cHpRow ReadMult( cIndex_Set &I , Index &D ,
741 cIndex wFi = Inf< Index >() ,
742 const bool IncldCnst = true ) = 0;
743
744/*--------------------------------------------------------------------------*/
748 virtual HpNum ReadLBMult( cIndex wFi = Inf< Index >() ) = 0;
749
750/*--------------------------------------------------------------------------*/
752
776 virtual cHpRow ReadDualEasy( cIndex wFi ) { return( nullptr ); }
777
778/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
780
804 virtual cHpRow ReadReducedCostsEasy( cIndex wFi ) { return( nullptr ); }
805
806/*--------------------------------------------------------------------------*/
813 virtual HpNum ReadGid( cIndex Nm = Inf< Index >() ) = 0;
814
815/*--------------------------------------------------------------------------*/
833 virtual void MakeLambda1( cHpRow Lmbd , HpRow Lmbd1 , cHpNum Tau ) = 0;
834
835/*--------------------------------------------------------------------------*/
843 virtual void SensitAnals( HpNum &lp , HpNum &cp ) = 0;
844
845/*--------------------------------------------------------------------------*/
860 void MPTime( double &t_us , double &t_ss ) {
861 t_us = t_ss = 0;
862 if( MPt ) MPt->Read( t_us , t_ss );
863 }
864
865/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
880 double MPTime( void ) { return( MPt ? MPt->Read() : 0 ); }
881
883/*-------------- METHODS FOR READING THE DATA OF THE PROBLEM ---------------*/
884/*--------------------------------------------------------------------------*/
889
890 Index GetMaxBSize( void ) { return( MaxBSize ); }
891
892/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
894
895 Index GetMaxSGLen( void ) { return( MaxSGLen ); }
896
897/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
899
900 Index GetCrrSGLen( void ) { return( CrrSGLen ); }
901
902/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
904
905 Index GetNrFi( void ) { return( NrFi ); }
906
907/*--------------------------------------------------------------------------*/
909
910 virtual Index BSize( cIndex wFi = Inf< Index >() ) = 0;
911
912/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
914
915 virtual Index BCSize( cIndex wFi = Inf< Index >() ) = 0;
916
917/*--------------------------------------------------------------------------*/
922 virtual Index MaxName( cIndex wFi = Inf< Index >() ) = 0;
923
924/*--------------------------------------------------------------------------*/
932 virtual Index WComponent( cIndex i ) = 0;
933
934/*--------------------------------------------------------------------------*/
940 virtual bool IsSubG( cIndex i ) = 0;
941
942/*--------------------------------------------------------------------------*/
947 virtual Index NumNNVars( void ) { return( 0 ); }
948
949/*--------------------------------------------------------------------------*/
956 virtual Index NumBxdVars( void ) { return( 0 ); }
957
958/*--------------------------------------------------------------------------*/
963 virtual bool IsNN( cIndex i ) { return( false ); }
964
965/*--------------------------------------------------------------------------*/
969 virtual cHpRow ReadLinErr( void ) = 0;
970
971/*--------------------------------------------------------------------------*/
978 virtual HpNum ReadLowerBound( cIndex wFi = Inf< Index >() ) = 0;
979
980/*--------------------------------------------------------------------------*/
981/* Writes in Gi[] the description of the item with "name" Nm. It is an error
982 if there is no item with that name in the MP. The format of the returned
983 vector depends on what is returned in GB. If GB == 0, then the vector in
984 Gi[] is "dense". Otherwise, the vector in Gi[] is "sparse", GB[] contains
985 the read-only vector of indices of the nonzero elements (ordered in
986 increasing sense and Inf< Index >()-terminated), and the number of these is
987 returned by the method. That is, if GB != 0 and NNZGi is the value returned
988 by the method, then the "true" Gi is
989
990 Gi[ j ] = / Gi[ i ] if GB[ i ] == j for some 0 <= i < NNZGi
991 \ 0 otherwise. */
992
993// virtual Index ReadGi( cIndex Nm , SgRow Gi , cIndex_Set &GB ) = 0;
994
995/*--------------------------------------------------------------------------*/
999 virtual HpNum EpsilonD( void ) = 0;
1000
1002/*------------- METHODS FOR ADDING / REMOVING / CHANGING DATA --------------*/
1003/*--------------------------------------------------------------------------*/
1027 virtual SgRow GetItem( cIndex wFi = Inf< Index >() ) = 0;
1028
1029/*--------------------------------------------------------------------------*/
1053 virtual void SetItemBse( cIndex_Set SGBse = 0 , cIndex SGBDm = 0 ) = 0;
1054
1055/*--------------------------------------------------------------------------*/
1112 virtual Index CheckSubG( cHpNum DFi , cHpNum Tau , HpNum &Ai ,
1113 HpNum &ScPri ) = 0;
1114
1115/*--------------------------------------------------------------------------*/
1176 virtual Index CheckCnst( HpNum &Ai , HpNum &ScPri , cHpRow CrrPnt ) = 0;
1177
1178/*--------------------------------------------------------------------------*/
1189 virtual bool ChangesMPSol( void ) = 0;
1190
1191/*--------------------------------------------------------------------------*/
1202 virtual void SetItem( cIndex Nm = Inf< Index >() ) = 0;
1203
1204/*--------------------------------------------------------------------------*/
1216 virtual void SubstItem( cIndex Nm ) = 0;
1217
1218/*--------------------------------------------------------------------------*/
1223 virtual void RmvItem( cIndex i ) = 0;
1224
1225/*--------------------------------------------------------------------------*/
1233 virtual void RmvItems( void ) = 0;
1234
1235/*--------------------------------------------------------------------------*/
1283 virtual void SetActvSt( cIndex_Set AVrs = 0 , cIndex AVDm = 0 ) = 0;
1284
1285/*--------------------------------------------------------------------------*/
1316 virtual void AddActvSt( cIndex_Set Addd , cIndex AdDm ,
1317 cIndex_Set AVrs ) = 0;
1318
1319/*--------------------------------------------------------------------------*/
1341 virtual void RmvActvSt( cIndex_Set Rmvd , cIndex RmDm ,
1342 cIndex_Set AVrs ) = 0;
1343
1344/*--------------------------------------------------------------------------*/
1385 virtual void AddVars( cIndex NNwVrs ) = 0;
1386
1387/*--------------------------------------------------------------------------*/
1415 virtual void RmvVars( cIndex_Set whch = 0 , Index hwmny = 0 ) = 0;
1416
1417/*--------------------------------------------------------------------------*/
1428 virtual void ChgAlfa( cHpRow DeltaAlfa ) = 0;
1429
1430/*--------------------------------------------------------------------------*/
1443 virtual void ChgAlfa( cHpRow NewAlfa , cIndex wFi ) = 0;
1444
1445/*--------------------------------------------------------------------------*/
1449 virtual void ChgAlfa( cIndex i , cHpNum Ai ) = 0;
1450
1451/*--------------------------------------------------------------------------*/
1517 virtual void ChangeCurrPoint( cLMRow DLambda , cHpRow DFi ) = 0;
1518
1519/*--------------------------------------------------------------------------*/
1526 virtual void ChangeCurrPoint( cHpNum Tau , cHpRow DFi ) = 0;
1527
1528/*--------------------------------------------------------------------------*/
1543 virtual void ChgSubG( cIndex strt , Index stp , cIndex wFi ) = 0;
1544
1545/*--------------------------------------------------------------------------*/
1563 virtual void ChgCosts( Index wFi , cLMRow Lambda ) {
1564 throw( std::logic_error( "ChgCosts not implemented" ) );
1565 }
1566
1567/*--------------------------------------------------------------------------*/
1580 virtual void ChgRLHS( Index wFi ) {
1581 throw( std::logic_error( "ChgCosts not implemented" ) );
1582 }
1583
1584/*--------------------------------------------------------------------------*/
1597 virtual void ChgLUBD( Index wFi ) {
1598 throw( std::logic_error( "ChgCosts not implemented" ) );
1599 }
1600
1602/*------------------------------ DESTRUCTOR --------------------------------*/
1603/*--------------------------------------------------------------------------*/
1608
1609 virtual ~MPSolver() { delete MPt; }
1610
1612/*-------------------- PROTECTED PART OF THE CLASS -------------------------*/
1613/*--------------------------------------------------------------------------*/
1614
1615 protected:
1616
1617/*--------------------------------------------------------------------------*/
1618/*----------------------- PROTECTED DATA STRUCTURES -----------------------*/
1619/*--------------------------------------------------------------------------*/
1620
1621 Index MaxBSize; // max Bundle size
1622 Index MaxSGLen; // max items length
1623 Index CrrSGLen; // current items length
1624 Index NrFi; // number of components of Fi
1625
1626 std::ostream *MPLog; // the output stream object
1627 char MPLLvl; // the "level of verbosity"
1628
1629 OPTtimers *MPt; // total time
1630
1631/*--------------------------------------------------------------------------*/
1632
1633 }; // end( class MPSolver )
1634
1635/*--------------------------------------------------------------------------*/
1636
1637 } // end( namespace NDO_di_unipi_it )
1638
1639/*--------------------------------------------------------------------------*/
1640/*--------------------------------------------------------------------------*/
1641
1642#endif /* MPSolver.h included */
1643
1644/*--------------------------------------------------------------------------*/
1645/*------------------------ End File MPSolver.h -----------------------------*/
1646/*--------------------------------------------------------------------------*/
Definition FiOracle.h:231
Definition MPSolver.h:121
virtual void RmvItems(void)=0
virtual void AddVars(cIndex NNwVrs)=0
virtual MPStatus SolveMP(void)=0
virtual HpNum ReadLBMult(cIndex wFi=Inf< Index >())=0
virtual void ChgAlfa(cHpRow NewAlfa, cIndex wFi)=0
virtual ~MPSolver()
destructor: deletes the timer. it is virtual, as it must be
Definition MPSolver.h:1609
virtual HpNum ReadFiBLambda(cIndex wFi=Inf< Index >())=0
virtual HpNum ReadSigma(cIndex wFi=Inf< Index >())=0
virtual HpNum ReadDt(cHpNum tt=1)=0
virtual cHpRow ReadLinErr(void)=0
virtual void MakeLambda1(cHpRow Lmbd, HpRow Lmbd1, cHpNum Tau)=0
virtual Index WComponent(cIndex i)=0
virtual void ChgAlfa(cIndex i, cHpNum Ai)=0
virtual void ChangeCurrPoint(cHpNum Tau, cHpRow DFi)=0
virtual HpNum EpsilonD(void)=0
MPSolver(void)
Definition MPSolver.h:168
virtual cHpRow ReadDualEasy(cIndex wFi)
returns the dual variables of the constraints of an easy component
Definition MPSolver.h:776
MPParam
Definition MPSolver.h:142
virtual cLMRow Readd(bool Fulld=false)=0
virtual void SetDim(cIndex MxBSz=0, FiOracle *Oracle=nullptr, const bool UsAvSt=false)
Definition MPSolver.h:278
virtual void ChgAlfa(cHpRow DeltaAlfa)=0
double MPTime(void)
Definition MPSolver.h:880
virtual void ChgSubG(cIndex strt, Index stp, cIndex wFi)=0
virtual HpNum ReadLowerBound(cIndex wFi=Inf< Index >())=0
virtual void AddActvSt(cIndex_Set Addd, cIndex AdDm, cIndex_Set AVrs)=0
virtual cHpRow ReadMult(cIndex_Set &I, Index &D, cIndex wFi=Inf< Index >(), const bool IncldCnst=true)=0
virtual void RmvActvSt(cIndex_Set Rmvd, cIndex RmDm, cIndex_Set AVrs)=0
virtual void ChgLUBD(Index wFi)
Definition MPSolver.h:1597
Index GetCrrSGLen(void)
returns the current subgradient length
Definition MPSolver.h:900
virtual void SetItemBse(cIndex_Set SGBse=0, cIndex SGBDm=0)=0
virtual void ChangeCurrPoint(cLMRow DLambda, cHpRow DFi)=0
virtual Index MaxName(cIndex wFi=Inf< Index >())=0
virtual void SetActvSt(cIndex_Set AVrs=0, cIndex AVDm=0)=0
virtual Index BCSize(cIndex wFi=Inf< Index >())=0
returns the current number of constraints in the bundle.
virtual void SubstItem(cIndex Nm)=0
void MPTime(double &t_us, double &t_ss)
Definition MPSolver.h:860
virtual HpNum ReadGid(cIndex Nm=Inf< Index >())=0
Index GetNrFi(void)
returns the number of components of Fi()
Definition MPSolver.h:905
virtual HpNum ReadDStart(cHpNum tt=1)=0
virtual Index CheckCnst(HpNum &Ai, HpNum &ScPri, cHpRow CrrPnt)=0
virtual Index BSize(cIndex wFi=Inf< Index >())=0
returns the current number of items (of either type) in the bundle.
Index GetMaxBSize(void)
returns the maximum bundle size
Definition MPSolver.h:890
virtual Index NumNNVars(void)
Definition MPSolver.h:947
virtual void Sett(cHpNum tt=1)=0
Index GetMaxSGLen(void)
returns the maximum subgradient length
Definition MPSolver.h:895
virtual SgRow GetItem(cIndex wFi=Inf< Index >())=0
virtual bool IsNN(cIndex i)
Definition MPSolver.h:963
virtual void RmvVars(cIndex_Set whch=0, Index hwmny=0)=0
virtual void ReadZ(LMRow tz, cIndex_Set &I, Index &D, cIndex wFi=Inf< Index >())=0
MPStatus
Definition MPSolver.h:151
virtual void SensitAnals(HpNum &lp, HpNum &cp)=0
virtual void SetItem(cIndex Nm=Inf< Index >())=0
virtual void ChgCosts(Index wFi, cLMRow Lambda)
Definition MPSolver.h:1563
virtual bool IsSubG(cIndex i)=0
virtual void ChgRLHS(Index wFi)
Definition MPSolver.h:1580
virtual cHpRow ReadReducedCostsEasy(cIndex wFi)
returns the reduced costs of the variables of an easy component
Definition MPSolver.h:804
virtual bool ChangesMPSol(void)=0
virtual Index NumBxdVars(void)
Definition MPSolver.h:956
virtual void RmvItem(cIndex i)=0
virtual Index CheckSubG(cHpNum DFi, cHpNum Tau, HpNum &Ai, HpNum &ScPri)=0
Definition OPTUtils.h:144
void ReSet(void)
reset the timer
Definition OPTUtils.h:214
double Read(void)
Definition OPTUtils.h:184
HpNum * HpRow
"finer" (fp) array
Definition OPTtypes.h:99
const HpNum cHpNum
a read-only HpNum
Definition OPTtypes.h:102
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
LMNum * LMRow
a vector of Lagrangean Multipliers
Definition OPTtypes.h:130
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
virtual void SetPar(const int wp, cHpNum value)=0
virtual void CheckIdentical(const bool Chk=true)
Definition MPSolver.h:396
virtual void SetLowerBound(cHpNum LwBnd=- Inf< HpNum >(), cIndex wFi=Inf< Index >())=0
virtual void SetMPTime(const bool TimeIt=true)
Definition MPSolver.h:426
virtual void SetThreads(int nthreads)
Definition MPSolver.h:343
virtual void SetMPLog(std::ostream *outs=0, const char lvl=0)
Definition MPSolver.h:408
Definition Bundle.h:68