NDOSolver / FiOracle
Interfaces and Solvers for NonDifferentiable Optimization
Loading...
Searching...
No Matches
CutPlane.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------*/
2/*---------------------------- File CutPlane.h -----------------------------*/
3/*--------------------------------------------------------------------------*/
27/*--------------------------------------------------------------------------*/
28/*----------------------------- DEFINITIONS --------------------------------*/
29/*--------------------------------------------------------------------------*/
30
31#ifndef __CutPlane
32 #define __CutPlane /* self-identification: #endif at the end of the file */
33
34/*--------------------------------------------------------------------------*/
35/*-------------------------------- MACROS ----------------------------------*/
36/*--------------------------------------------------------------------------*/
37
38/*--------------------------------------------------------------------------*/
39/*------------------------------ INCLUDES ----------------------------------*/
40/*--------------------------------------------------------------------------*/
41
42#include "NDOSlver.h"
43
44#include "OsiSolverInterface.hpp"
45
46/*--------------------------------------------------------------------------*/
47/*----------------------------- NAMESPACE ----------------------------------*/
48/*--------------------------------------------------------------------------*/
49
50namespace NDO_di_unipi_it
51{
52
53/*--------------------------------------------------------------------------*/
54/*--------------------------- CLASS CutPlane -------------------------------*/
55/*--------------------------------------------------------------------------*/
56/*--------------------------- GENERAL NOTES --------------------------------*/
57/*--------------------------------------------------------------------------*/
80class CutPlane : public NDOSolver
81{
82
83/*--------------------------------------------------------------------------*/
84/*----------------------- PUBLIC PART OF THE CLASS -------------------------*/
85/*--------------------------------------------------------------------------*/
86
87 public:
88
89/*--------------------------------------------------------------------------*/
90/*--------------------------- PUBLIC METHODS -------------------------------*/
91/*--------------------------------------------------------------------------*/
92/*---------------------------- CONSTRUCTOR ---------------------------------*/
93/*--------------------------------------------------------------------------*/
97 CutPlane( std::istream *iStrm = 0 );
98
145/*-------------------------- OTHER INITIALIZATIONS -------------------------*/
146/*--------------------------------------------------------------------------*/
150 void SetOsiSolver( OsiSolverInterface* osi = 0 );
151
153
154/*--------------------------------------------------------------------------*/
155
156 void SetRadius( LMNum rad = Inf< LMNum >() );
157
165/*--------------------------------------------------------------------------*/
166
167 void SetFiOracle( FiOracle *Fi = 0 );
168
169/*--------------------------------------------------------------------------*/
170
171 void SetLambda( cLMRow tLambda = 0 );
172
173/*--------------------------------------------------------------------------*/
174
175 void KeepBestLambda( const bool KBL = true );
176
177/*--------------------------------------------------------------------------*/
178
179 void SetNDOLog( ostream *outs = 0 , const char lvl = 0 );
180
194/*-------------------- METHODS FOR SOLVING THE PROBLEM ---------------------*/
195/*--------------------------------------------------------------------------*/
200
201/*--------------------------------------------------------------------------*/
202
204
206/*---------------------- METHODS FOR READING RESULTS -----------------------*/
207/*--------------------------------------------------------------------------*/
208
210
211/*--------------------------------------------------------------------------*/
212
214
215/*--------------------------------------------------------------------------*/
216
218
219/*--------------------------------------------------------------------------*/
220
222
223/*--------------------------------------------------------------------------*/
224
225 bool IsOptimal( HpNum eps = 0 ) const;
226
227/*--------------------------------------------------------------------------*/
228
230
231/*--------------------------------------------------------------------------*/
232
234
236/*-------------- METHODS FOR READING THE DATA OF THE PROBLEM ---------------*/
237/*--------------------------------------------------------------------------*/
242/*------------- METHODS FOR ADDING / REMOVING / CHANGING DATA --------------*/
243/*--------------------------------------------------------------------------*/
247 void AddVariables( Index NNwVrs , cLMRow IVs = 0 );
248
249/*--------------------------------------------------------------------------*/
250
251 void RemoveVariables( cIndex_Set whch = 0 , Index hwmny = 0 );
252
253/*--------------------------------------------------------------------------*/
254
255 void ChgFiV( cIndex wFi = Inf< Index >() )
256 {
257 throw NDOException( "CutPlane::ChgFiV not implemented yet" );
258 }
259
260/*--------------------------------------------------------------------------*/
261
262 void ChgSbG( cIndex strt = 0 , Index stp = Inf< Index >() ,
263 cIndex wFi = Inf< Index >() )
264 {
265 throw NDOException( "CutPlane::ChgSbG not implemented yet" );
266 }
267
269/*------------------------------ DESTRUCTOR --------------------------------*/
270/*--------------------------------------------------------------------------*/
274 virtual ~CutPlane();
275
277
279/*-------------------- PROTECTED PART OF THE CLASS -------------------------*/
280/*--------------------------------------------------------------------------*/
281
282 protected:
283
284/*--------------------------------------------------------------------------*/
285/*---------------------- PROTECTED PART OF THE CLASS -----------------------*/
286/*--------------------------------------------------------------------------*/
287/*-------------------------- PROTECTED METHODS -----------------------------*/
288/*--------------------------------------------------------------------------*/
289
290/*--------------------------------------------------------------------------*/
291/*----------------------- PROTECTED DATA STRUCTURES -----------------------*/
292/*--------------------------------------------------------------------------*/
293
294
295 private:
296
297/*--------------------------------------------------------------------------*/
298/*--------------------- PRIVATE PART OF THE CLASS --------------------------*/
299/*--------------------------------------------------------------------------*/
300/*-------------------------- PRIVATE METHODS -------------------------------*/
301/*--------------------------------------------------------------------------*/
302
303 inline void FiAndGi( void );
304
305/* Solve Fi subproblem and retrieve corresponding subgradients.
306 The Fi problem is solved with the last Lambda found and if some
307 solution is atractive, corresponding sugradients is retrieved and
308 a new line is added in the RMP. The number of lines added depends
309 of the number of subproblems in the Oracle. */
310
311/*--------------------------------------------------------------------------*/
312
313 inline Index DelRMPRows( HpNum lim );
314
315// Delete RMP rows with slacks greater than lim.
316
317/*--------------------------------------------------------------------------*/
318
319 inline void OutRsts( void );
320
321// Function to output results when LOG >=1.
322
323/*--------------------------------------------------------------------------*/
324
325 inline void MemDealloc( void );
326
327// Function to free the allocated arrays.
328
329/*--------------------------------------------------------------------------*/
330/*----------------------- PRIVATE DATA STRUCTURES -------------------------*/
331/*--------------------------------------------------------------------------*/
332
333 // algorithmic parameters- - - - - - - - - - - - - - - - - - - - - - - - -
334
335 Index NumNames; // number of items (re)allocated each time
336
337 HpNum PurgeRows; // purge (delete) rows options
338 Index PurgeInvl; // how often the purge rows is done.
339
340 Index HeurSubGU; /* number of subgradients asked to the FiOracle
341 (every iteration) when the restricted master
342 problem is artificially feasible */
343 Index HeurSubGF; /* number of subgradients asked to the FiOracle
344 (every HeurInvl - next parameter) when the
345 restricted master problem is feasible */
346 Index HeurInvl; /* how often "extra" subgradients are asked by the
347 CutPlane (when the restricted master problem is
348 feasible) */
349
350 Index KpPrimals; // if == 0, do not care for primal information
351
352 Index PrintInvl; // how often do we print log information
353
354 // other stuff - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
355
356 Index MaxNumVar;
357 LMRow Lambda; // The current point
358 LMRow BestLambda; // The best point found so far
359 Index_Set Base; // Vector of the indices of nonzeroes in Lambda
360 Index BaseSize; // Size of Base
361 bool KpBstL; // If LmbdBst has to be kept
362 HpRow FiLambda; // Fi( Lambda ) of each component of Fi
363 HpRow BestFiLambda; // Fi( BestLambda ) of each component of Fi
364 HpNum AFiLambda; // Value of Fi( Lambda )
365 HpNum ABestFiLambda; // Best value of Fi found so far.
366 SgRow Gi; // SubGradient returned by the FiOracle
367
368 OsiSolverInterface *OsiS; // Instance of OsiSolverInterface.
369
370 HpNum AValueRMP; // Value of the approximation of Fi in the RMP
371 HpRow ValueRMP; // Optimal values of the RMP, for each component
372 Index RowsAdded; // Rows added to the RMP in the current iteration
373 Index MaxNRows; // Maximum number of rows of the RMP.
374 HpNum Gap; // Gap between FiLambda and ValueRMP
375 HpNum LowerBound; // Lower Bound over Fi
376 bool TrueLB; // true if LowerBound is a "true" lower bound
377 // rather than just the "minus infinity"
378 bool loptimal; // true if the solution found is optimal to the
379 // current master problem. When adding of
380 // variables is being used, note that the solution
381 // may not be optimal to the full problem.
382
383 // oracle solutions management related - - - - - - - - - - - - - - - - - -
384 // CutPlane is responsible to give a name to each of the primal solutions
385 // on which the subgradients are calculated. it is for him to "know" which
386 // names are being used and which are not. the following structures are
387 // relative to that management of names. also, each name that is being
388 // used has a corresponding row in the RMP. the primal solution
389 // associated with row i is kept in FullNames[ i ]
390
391 Index_Set EmptyNames; // Vector of Empty Gi names.
392 Index_Set FullNames; // Vector of Full Gi names.
393 Index_Set SubPNames; // Vector with Fi-components of subgradients
394
395 SIndex LastFull; // Pointer to the last Full name.
396 Index FirstEmpty; // Pointer to the first Empty name.
397 Index AllocNumber; // Number of allocations to RowNames.
398
399/*--------------------------------------------------------------------------*/
400
401 }; // end( class CutPlane )
402
403/*--------------------------------------------------------------------------*/
404/*------------------- inline methods implementation ------------------------*/
405/*--------------------------------------------------------------------------*/
406
407/*--------------------------------------------------------------------------*/
408
409}; //end( namespace( NDO_di_unipi_it ) )
410
411/*--------------------------------------------------------------------------*/
412/*--------------------------------------------------------------------------*/
413
414#endif /* CutPlane.h included */
415
416/*--------------------------------------------------------------------------*/
417/*------------------------ End File CutPlane.h -----------------------------*/
418/*--------------------------------------------------------------------------*/
Definition CutPlane.h:81
void SetRadius(LMNum rad=Inf< LMNum >())
void SetLambda(cLMRow tLambda=0)
void SetOsiSolver(OsiSolverInterface *osi=0)
Sets the OsiSolver to be used by CutPlane to solve the RMP.
virtual ~CutPlane()
Destructor. It must be virtual.
HpNum ReadFiVal(cIndex wFi=Inf< Index >())
void ChgSbG(cIndex strt=0, Index stp=Inf< Index >(), cIndex wFi=Inf< Index >())
Definition CutPlane.h:262
bool IsOptimal(HpNum eps=0) const
void RemoveVariables(cIndex_Set whch=0, Index hwmny=0)
HpNum ReadBestFiVal(cIndex wFi=Inf< Index >())
cHpRow ReadMult(cIndex_Set &I, Index &D, cIndex wFi=Inf< Index >())
void SetFiOracle(FiOracle *Fi=0)
CutPlane(std::istream *iStrm=0)
void SetNDOLog(ostream *outs=0, const char lvl=0)
HpNum ReadLBMult(cIndex wFi=Inf< Index >())
cLMRow ReadSol(cIndex_Set &I, Index &D)
! void ReSetAlg( unsigned char RstLvl = 0 ) {}
cLMRow ReadBestSol(cIndex_Set &I, Index &D)
void AddVariables(Index NNwVrs, cLMRow IVs=0)
void ChgFiV(cIndex wFi=Inf< Index >())
Definition CutPlane.h:255
Definition FiOracle.h:231
Definition FiOracle.h:66
Definition NDOSlver.h:60
NDOStatus
Definition NDOSlver.h:91
int SIndex
Definition OPTtypes.h:69
HpNum * HpRow
"finer" (fp) array
Definition OPTtypes.h:99
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
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
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
Definition Bundle.h:68