NDOSolver / FiOracle
Interfaces and Solvers for NonDifferentiable Optimization
Loading...
Searching...
No Matches
OSIMPSolver.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------*/
2/*------------------------- File OSIMPSolver.h -----------------------------*/
3/*--------------------------------------------------------------------------*/
23/*--------------------------------------------------------------------------*/
24/*----------------------------- DEFINITIONS --------------------------------*/
25/*--------------------------------------------------------------------------*/
26
27#ifndef __OSIMPSolver
28 #define __OSIMPSolver /* self-identification: #endif at the end of the file*/
29
30/*--------------------------------------------------------------------------*/
31/*-------------------------------- MACROS ----------------------------------*/
32/*--------------------------------------------------------------------------*/
33/* As the name implies, OSIMPSolver uses an object derived from
34 * OsiSolverInterface to solve the MP. Certain usage patterns cause the MP to
35 * be changed, and *after that* the previous optimal primal and dual solution
36 * to be accessed. Certain OsiSolvers graciously allow that, by keeping the
37 * previous solution even in face of changes until the MP is explicitly
38 * re-solved, while others are more strict and delete any previous solution
39 * as soon as anything changes in the MP.
40 *
41 * This macro, if set to 1, dictates that the OSIMPSolver object stores the
42 * solution information of the OsiSolver in its own data structures, so that
43 * it remains available even after changes in the MP. Doing so is safe, but
44 * it may be useless (and therefore better avoided for higher efficiency in
45 * both space and time) with certain OsiSolvers. */
46
47#define PRESERVE_OSI_SOLS 1
48
49/*--------------------------------------------------------------------------*/
50/*------------------------------ INCLUDES ----------------------------------*/
51/*--------------------------------------------------------------------------*/
52
53#include "MPSolver.h"
54
55#include "OsiSolverInterface.hpp"
56
57/*--------------------------------------------------------------------------*/
58/*------------------------------ NAMESPACE ---------------------------------*/
59/*--------------------------------------------------------------------------*/
60
61namespace NDO_di_unipi_it
62{
63
64/*--------------------------------------------------------------------------*/
65/*----------------------------- CLASSES ------------------------------------*/
66/*--------------------------------------------------------------------------*/
67/*--------------------------- GENERAL NOTES --------------------------------*/
68/*--------------------------------------------------------------------------*/
74class OSIMPSolver : public MPSolver
75{
76/*--------------------------------------------------------------------------*/
77/*----------------------- PUBLIC PART OF THE CLASS -------------------------*/
78/*--------------------------------------------------------------------------*/
79
80 public:
81
82/*--------------------------------------------------------------------------*/
83/*---------------------------- PUBLIC TYPES --------------------------------*/
84/*--------------------------------------------------------------------------*/
89
90 enum StabFun { unset = 0 , none , boxstep , quadratic };
91
92/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
105 enum OsiAlg { kAuto = 0 , kPrim , kDual , kNet , kBar , kSif , kCon };
106
107/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
116 enum OsiRed { rNo = 0 , rPrim , rDual , rBoth };
117
119/*--------------------- PUBLIC METHODS OF THE CLASS ------------------------*/
120/*--------------------------------------------------------------------------*/
121/*------------------------------ CONSTRUCTOR -------------------------------*/
122/*--------------------------------------------------------------------------*/
126 OSIMPSolver( std::istream *iStrm = nullptr );
127
129/*-------------------------- OTHER INITIALIZATIONS -------------------------*/
130/*--------------------------------------------------------------------------*/
134 void SetDim( cIndex MxBSz = 0 , FiOracle * Oracle = nullptr ,
135 const bool UsAvSt = false ) override;
136
137/*--------------------------------------------------------------------------*/
138
139 void Sett( cHpNum tt = 1 ) override;
140
141/*--------------------------------------------------------------------------*/
142
143 void SetPar( const int wp , cHpNum value ) override;
144
145/*--------------------------------------------------------------------------*/
146
147 void SetThreads( int nthreads ) override;
148
149/*--------------------------------------------------------------------------*/
150
152 cIndex wFi = Inf< Index >() ) override;
153
154/*--------------------------------------------------------------------------*/
169 void SetMPLog( ostream *outs = 0 , const char lvl = 0 ) override;
170
171/*--------------------------------------------------------------------------*/
175 void SetAlgo( const OsiAlg algo = kAuto , const OsiRed reduc = rNo );
176
178/*---------------------- OSIMPSolver-SPECIFIC METHODS ----------------------*/
179/*--------------------------------------------------------------------------*/
184
193 void SetOsi( OsiSolverInterface * osi = nullptr );
194
195/*--------------------------------------------------------------------------*/
197
198 OsiSolverInterface * GetOsi( void ) const { return( osiSlvr ); }
199
200/*--------------------------------------------------------------------------*/
202
211 void SetStabType( const StabFun sf = none );
212
214/*-------------------- METHODS FOR SOLVING THE PROBLEM ---------------------*/
215/*--------------------------------------------------------------------------*/
219 MPStatus SolveMP( void ) override;
220
222/*---------------------- METHODS FOR READING RESULTS -----------------------*/
223/*--------------------------------------------------------------------------*/
228
229 HpNum ReadDt( cHpNum tt = 1 ) override;
230
231 HpNum ReadSigma( cIndex wFi = Inf< Index >() ) override;
232
233 HpNum ReadDStart( cHpNum tt = 1 ) override;
234
235 cLMRow Readd( bool Fulld = false ) override;
236
237 void ReadZ( LMRow tz , cIndex_Set & I , Index & D ,
238 cIndex wFi = Inf< Index >() ) override;
239
241 const bool IncldCnst = true ) override;
242
243 HpNum ReadLBMult( cIndex wFi = Inf< Index >() ) override;
244
245 cHpRow ReadDualEasy( cIndex wFi ) override;
246
248
249 HpNum ReadGid( cIndex Nm = Inf< Index >() ) override;
250
251 void MakeLambda1( cHpRow Lmbd , HpRow Lmbd1 , cHpNum Tau ) override;
252
253 void SensitAnals( HpNum &lp , HpNum &cp ) override;
254
256/*-------------- METHODS FOR READING THE DATA OF THE PROBLEM ---------------*/
257/*--------------------------------------------------------------------------*/
261 Index BSize( cIndex wFi = Inf< Index >() ) override;
262
263 Index BCSize( cIndex wFi = Inf< Index >() ) override;
264
265 Index MaxName( cIndex wFi = Inf< Index >() ) override;
266
267 Index WComponent( cIndex i ) override;
268
269 bool IsSubG( cIndex i ) override;
270
271 Index NumNNVars( void ) override;
272
273 Index NumBxdVars( void ) override;
274
275 bool IsNN( cIndex i ) override;
276
277 void CheckIdentical( const bool Chk = true ) override;
278
279 cHpRow ReadLinErr( void ) override;
280
282
283 HpNum EpsilonD( void ) override;
284
285 bool FiBLambdaIsExact( cIndex wFi );
286
288/*------------- METHODS FOR ADDING / REMOVING / CHANGING DATA --------------*/
289/*--------------------------------------------------------------------------*/
293 SgRow GetItem( cIndex wFi = Inf< Index >() ) override;
294
295 void SetItemBse( cIndex_Set SGBse = nullptr , cIndex SGBDm = 0 ) override;
296
297 Index CheckSubG( cHpNum DFi , cHpNum Tau , HpNum & Ai , HpNum & ScPri )
298 override;
299
300 Index CheckCnst( HpNum & Ai , HpNum & ScPri , cHpRow CrrPnt ) override;
301
302 bool ChangesMPSol( void ) override;
303
304 void SetItem( cIndex Nm = Inf< Index >() ) override;
305
306 void SubstItem( cIndex Nm ) override;
307
308/*--------------------------------------------------------------------------*/
309
310 void RmvItem( cIndex i ) override;
311
312 void RmvItems( void ) override;
313
314/*--------------------------------------------------------------------------*/
315
316 void SetActvSt( cIndex_Set AVrs = nullptr , cIndex AVDm = 0 ) override;
317
318 void AddActvSt( cIndex_Set Addd , cIndex AdDm , cIndex_Set AVrs ) override;
319
320 void RmvActvSt( cIndex_Set Rmvd , cIndex RmDm , cIndex_Set AVrs ) override;
321
322/*--------------------------------------------------------------------------*/
323
324 void AddVars( cIndex NNwVrs ) override;
325
326 void RmvVars( cIndex_Set whch = nullptr , Index hwmny = 0 ) override;
327
328/*--------------------------------------------------------------------------*/
329
330 void ChgAlfa( cHpRow DeltaAlfa ) override;
331
332 void ChgAlfa( cHpRow NewAlfa , cIndex wFi ) override;
333
334 void ChgAlfa( cIndex i , cHpNum Ai ) override;
335
336/*--------------------------------------------------------------------------*/
337
338 void ChangeCurrPoint( cLMRow DLambda , cHpRow DFi ) override;
339
340 void ChangeCurrPoint( cHpNum Tau , cHpRow DFi ) override;
341
342/*--------------------------------------------------------------------------*/
343
344 void ChgSubG( cIndex strt , Index stp , cIndex wFi ) override;
345
346/*--------------------------------------------------------------------------*/
347
348 void ChgCosts( Index wFi , cLMRow Lambda ) override;
349
350/*--------------------------------------------------------------------------*/
375 void ChgRLHS( Index wFi ) override;
376
377/*--------------------------------------------------------------------------*/
402 void ChgLUBD( Index wFi ) override;
403
405/*------------------------------ DESTRUCTOR --------------------------------*/
406/*--------------------------------------------------------------------------*/
413 virtual ~OSIMPSolver();
414
416/*--------------------- PRIVATE PART OF THE CLASS --------------------------*/
417/*--------------------------------------------------------------------------*/
418
419 private:
420
421/*--------------------------------------------------------------------------*/
422/*-------------------------- PRIVATE METHODS -------------------------------*/
423/*--------------------------------------------------------------------------*/
424
425 void cleanup( void );
426
427/*--------------------------------------------------------------------------*/
428/* Update the prices after either t has changed or if the current point
429 has been changed. The last form changes the prices in tmpHP[], assumed to
430 hold the whole vector of cost coefficients of the master problem. */
431
432 void tUpdatePrices( cIndex strt = 0 , Index stp = Inf< Index >() );
433
434 void ptUpdatePrices( cIndex strt = 0 , Index stp = Inf< Index >() );
435
436 void ptUpdatePricesInPlace( void );
437
438/*--------------------------------------------------------------------------*/
439
440 void UpdateRhoCol( void );
441
442/*--------------------------------------------------------------------------*/
443/* Private method for handling the quadratic stabilization. */
444
445 void switchToQP( void );
446
447/*--------------------------------------------------------------------------*/
448// inline bool isactive( Index i );
449
450 void activate( Index i );
451
452 void deactivate( Index i );
453
454 void resizeHP( Index i );
455
456 void resizeI( Index i );
457
458/*--------------------------------------------------------------------------*/
459/* Placeholder method: it should do nothing, but depending on the value of
460 the macro CHECK_DS [see OSIMPSolver.C] some extra checking is done in
461 there for debugging purposes. */
462
463 void CheckDS( void );
464
465/*--------------------------------------------------------------------------*/
466
467 Index CheckBCopy( void );
468
469/*--------------------------------------------------------------------------*/
470/*----------------------- PRIVATE DATA STRUCTURES -------------------------*/
471/*--------------------------------------------------------------------------*/
472
473 OsiSolverInterface *osiSlvr;
475
477
479 bool first;
481 bool checkID;
484
487
488 double MaxTime;
489 double OptEps;
490 double FsbEps;
491
492 double * RhoCol;
493 int * RhoColBse;
507
509
513
516
521
533
535
537 int* tempI;
540
543
546
549
551
557 #if( PRESERVE_OSI_SOLS )
558 double * csol;
559 int csols;
560 double * rsol;
561 int rsols;
562 double * rcst;
563 #endif
564
565 CoinMessageHandler *derhand;
566
568
569/*--------------------------------------------------------------------------*/
570
571 }; // end( class OSIMPSolver )
572
573/*--------------------------------------------------------------------------*/
574/*--------------------------------------------------------------------------*/
575
576 } // end( namespace NDO_di_unipi_it )
577
578/*--------------------------------------------------------------------------*/
579/*--------------------------------------------------------------------------*/
580
581#endif /* __OSIMPSolver */
582
583/*--------------------------------------------------------------------------*/
584/*---------------------- End File OSIMPSolver.h ----------------------------*/
585/*--------------------------------------------------------------------------*/
Definition FiOracle.h:231
Definition MPSolver.h:121
MPStatus
Definition MPSolver.h:151
Definition OSIMPSolver.h:75
HpNum ReadDt(cHpNum tt=1) override
void RmvVars(cIndex_Set whch=nullptr, Index hwmny=0) override
HpNum ReadFiBLambda(cIndex wFi=Inf< Index >()) override
void SetStabType(const StabFun sf=none)
Sets the stabilizing term in the Master Problem.
Index_Set dict_slack
slack vocabulary
Definition OSIMPSolver.h:519
bool useactiveset
true if the active set are taken in account
Definition OSIMPSolver.h:478
double FsbEps
feasibility tolerance
Definition OSIMPSolver.h:490
double * RhoCol
entries of the column of rho
Definition OSIMPSolver.h:492
Index NumBxdVars(void) override
void SetItemBse(cIndex_Set SGBse=nullptr, cIndex SGBDm=0) override
Index NNVars
variables with >= 0 constraints
Definition OSIMPSolver.h:544
Index NewItemFi
the function component relative to new item
Definition OSIMPSolver.h:504
void ChgLUBD(Index wFi) override
void SetDim(cIndex MxBSz=0, FiOracle *Oracle=nullptr, const bool UsAvSt=false) override
Index tempI_size
size of tempI
Definition OSIMPSolver.h:539
void MakeLambda1(cHpRow Lmbd, HpRow Lmbd1, cHpNum Tau) override
void SensitAnals(HpNum &lp, HpNum &cp) override
bool ChangesMPSol(void) override
cIndex_Set Aset
active set structure
Definition OSIMPSolver.h:547
Index_Set comp_row
row vocabulary
Definition OSIMPSolver.h:517
Index tempHP_size
size of tempHP
Definition OSIMPSolver.h:538
Bool_Vec weasy
which Fi-component is easy
Definition OSIMPSolver.h:482
bool IsSubG(cIndex i) override
void AddVars(cIndex NNwVrs) override
StabFun
Public enum for handling the Bundle stabilization term [see below].
Definition OSIMPSolver.h:90
void ChgRLHS(Index wFi) override
double NewItemprice
price of the item
Definition OSIMPSolver.h:511
Index WComponent(cIndex i) override
cLMRow Readd(bool Fulld=false) override
SgRow NewItem
the new item
Definition OSIMPSolver.h:503
Index BSize(cIndex wFi=Inf< Index >()) override
returns the current number of items (of either type) in the bundle.
Index_Set dict_item
item vocabulary
Definition OSIMPSolver.h:518
cHpRow ReadReducedCostsEasy(cIndex wFi) override
returns the reduced costs of the variables of an easy component
void RmvActvSt(cIndex_Set Rmvd, cIndex RmDm, cIndex_Set AVrs) override
Index BCSize(cIndex wFi=Inf< Index >()) override
returns the current number of constraints in the bundle.
Index NrEasy
how many easy Fi-components are there
Definition OSIMPSolver.h:483
HpNum ReadLowerBound(cIndex wFi=Inf< Index >()) override
int csols
length of csol
Definition OSIMPSolver.h:559
Index_Set NConst
number of constraints (per component)
Definition OSIMPSolver.h:515
HpNum t
proximal parameter term
Definition OSIMPSolver.h:486
StabFun stab
tell the stabilization term adopted
Definition OSIMPSolver.h:485
OsiAlg algorithm
algorithm used in the solver
Definition OSIMPSolver.h:476
void ChangeCurrPoint(cLMRow DLambda, cHpRow DFi) override
double OptEps
optimality tolerance
Definition OSIMPSolver.h:489
bool first
Definition OSIMPSolver.h:479
void ChgSubG(cIndex strt, Index stp, cIndex wFi) override
void SetPar(const int wp, cHpNum value) override
cHpRow ReadDualEasy(cIndex wFi) override
returns the dual variables of the constraints of an easy component
HpNum ReadSigma(cIndex wFi=Inf< Index >()) override
LMRow Lower
lower bounds on the primal variable
Definition OSIMPSolver.h:542
HpRow LwrBnds
values of lower bounds for each component
Definition OSIMPSolver.h:550
OsiRed
Definition OSIMPSolver.h:116
double MaxTime
max running time for each call to SolveMP
Definition OSIMPSolver.h:488
Index_Set dict_stab
stabilization variables vocabulary
Definition OSIMPSolver.h:520
Index BxdVars
variables with >= 0 or <= UB constraints
Definition OSIMPSolver.h:545
Index item_maxname
maximum name among current items + 1
Definition OSIMPSolver.h:534
void SetThreads(int nthreads) override
SgRow GetItem(cIndex wFi=Inf< Index >()) override
Index MaxNZ
max dimension of the item
Definition OSIMPSolver.h:508
HpRow tempHP
temporary vector of HpNum
Definition OSIMPSolver.h:536
void RmvItem(cIndex i) override
int * tempI
temporary vector of ints
Definition OSIMPSolver.h:537
cHpRow ReadMult(cIndex_Set &I, Index &D, cIndex wFi=Inf< Index >(), const bool IncldCnst=true) override
void RmvItems(void) override
void Sett(cHpNum tt=1) override
void SetItem(cIndex Nm=Inf< Index >()) override
void SetMPLog(ostream *outs=0, const char lvl=0) override
void CheckIdentical(const bool Chk=true) override
OsiSolverInterface * GetOsi(void) const
gives back the current OsiSolverInterface
Definition OSIMPSolver.h:198
bool IsNN(cIndex i) override
double * csol
column (primal) solution
Definition OSIMPSolver.h:558
void SetOsi(OsiSolverInterface *osi=nullptr)
Provides OSIMPSolver with the actual OsiSolverInterface.
void SetAlgo(const OsiAlg algo=kAuto, const OsiRed reduc=rNo)
void ChgAlfa(cHpRow NewAlfa, cIndex wFi) override
Index NumNNVars(void) override
double * rcst
row reduced cost
Definition OSIMPSolver.h:562
void SetActvSt(cIndex_Set AVrs=nullptr, cIndex AVDm=0) override
MPStatus SolveMP(void) override
OsiSolverInterface * osiSlvr
pointer to the OsiSolver
Definition OSIMPSolver.h:473
Index NewItemBDm
dimension of new item
Definition OSIMPSolver.h:506
cHpRow ReadLinErr(void) override
HpNum ReadDStart(cHpNum tt=1) override
int rsols
length of rsol
Definition OSIMPSolver.h:561
FiOracle * FIO
pointer to the FiOracle
Definition OSIMPSolver.h:474
Index CheckSubG(cHpNum DFi, cHpNum Tau, HpNum &Ai, HpNum &ScPri) override
HpNum ReadGid(cIndex Nm=Inf< Index >()) override
HpNum EpsilonD(void) override
Index_Set comp_col
column vocabulary
Definition OSIMPSolver.h:532
void ChgAlfa(cHpRow DeltaAlfa) override
HpNum ReadLBMult(cIndex wFi=Inf< Index >()) override
Index Asetdim
size of active set
Definition OSIMPSolver.h:548
void SetLowerBound(cHpNum LwBnd=- Inf< HpNum >(), cIndex wFi=Inf< Index >()) override
void ChangeCurrPoint(cHpNum Tau, cHpRow DFi) override
void AddActvSt(cIndex_Set Addd, cIndex AdDm, cIndex_Set AVrs) override
void SubstItem(cIndex Nm) override
void ReadZ(LMRow tz, cIndex_Set &I, Index &D, cIndex wFi=Inf< Index >()) override
Index RhoColBDm
... and size
Definition OSIMPSolver.h:494
bool NewItemisSG
subgradient vs constraint
Definition OSIMPSolver.h:510
HpRow GiPerd
Definition OSIMPSolver.h:552
cIndex_Set NewItemBse
index vector of the new item
Definition OSIMPSolver.h:505
Index CheckCnst(HpNum &Ai, HpNum &ScPri, cHpRow CrrPnt) override
int * RhoColBse
... in sparse format: indices ...
Definition OSIMPSolver.h:493
double * rsol
row (dual) solution
Definition OSIMPSolver.h:560
OsiAlg
Definition OSIMPSolver.h:105
LMRow Upper
upper bounds on the primal variable
Definition OSIMPSolver.h:541
void ChgAlfa(cIndex i, cHpNum Ai) override
Index NRCall
number of calls to SolveMP procedure
Definition OSIMPSolver.h:567
double NewItemScPri
Gid product.
Definition OSIMPSolver.h:512
Index MaxName(cIndex wFi=Inf< Index >()) override
Index RhoColSgPos
position in RhoColBse of the "subgradient"
Definition OSIMPSolver.h:495
Index_Set wcomp
Definition OSIMPSolver.h:522
Index_Set NSubG
number of subgradients (per component)
Definition OSIMPSolver.h:514
void ChgCosts(Index wFi, cLMRow Lambda) override
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
Index * Index_Set
set (array) of indices
Definition OPTtypes.h:61
bool * Bool_Vec
vector of booleans
Definition OPTtypes.h:52
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
Definition Bundle.h:68