NDOSolver / FiOracle
Interfaces and Solvers for NonDifferentiable Optimization
Loading...
Searching...
No Matches
Volume.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------------*/
2/*--------------------------- File Volume.h --------------------------------*/
3/*--------------------------------------------------------------------------*/
25/*--------------------------------------------------------------------------*/
26/*-------------------- DEFINITIONS & IMPLEMENTATION ------------------------*/
27/*--------------------------------------------------------------------------*/
28
29#ifndef __Volume
30 #define __Volume /* self-identification: #endif at the end of the file */
31
32/*--------------------------------------------------------------------------*/
33/*------------------------------- MACROS ----------------------------------*/
34/*--------------------------------------------------------------------------*/
35
36#define LOG_VOL 0
37
38/* If LOG_VOL > 0, the Volume class produces a log of its activities on the
39 ostream object and at the "level of verbosity" set with the method
40 SetVOLLog() [see below]. */
41
42#if( LOG_VOL )
43 #define VOLLOG( l , x ) if( VOLLLvl > l ) *VOLLog << x
44 #define VOLLOG2( l , c , x ) if( ( VOLLLvl > l ) && c ) *VOLLog << x
45#else
46 #define VOLLOG( l , x )
47 #define VOLLOG2( l , c , x )
48#endif
49
50/*--------------------------------------------------------------------------*/
51/*------------------------------ INCLUDES ----------------------------------*/
52/*--------------------------------------------------------------------------*/
53
54#include "Deflection.h"
55#include <algorithm>
56
57/*--------------------------------------------------------------------------*/
58/*----------------------------- NAMESPACE ----------------------------------*/
59/*--------------------------------------------------------------------------*/
60
61namespace NDO_di_unipi_it
62{
63
64/*--------------------------------------------------------------------------*/
65/*--------------------------- GENERAL NOTES --------------------------------*/
66/*--------------------------------------------------------------------------*/
83class Volume : public Deflection
84{
85
86/*--------------------------------------------------------------------------*/
87/*----------------------- PUBLIC PART OF THE CLASS -------------------------*/
88/*--------------------------------------------------------------------------*/
89
90 public:
91
92/*--------------------------------------------------------------------------*/
93/*--------------------- PUBLIC METHODS OF THE CLASS ------------------------*/
94/*--------------------------------------------------------------------------*/
95/*---------------------------- CONSTRUCTOR ---------------------------------*/
96/*--------------------------------------------------------------------------*/
118 Volume( SubGrad *slvr , std::istream *iStrm = 0 ) : Deflection( slvr )
119 {
120 DfltdSfInpt( iStrm , tauInit , HpNum( 1 ) );
121 DfltdSfInpt( iStrm , tauMin , HpNum( 1e-4 ) );
122 DfltdSfInpt( iStrm , tauFactor , HpNum( 0.5 ) );
123 DfltdSfInpt( iStrm , tauIter , Index( 100 ) );
124 DfltdSfInpt( iStrm , m , HpNum( 0.1 ) );
125 }
126
127/*--------------------------------------------------------------------------*/
128/*-------------------------- OTHER INITIALIZATIONS -------------------------*/
129/*--------------------------------------------------------------------------*/
130
131 inline void SetVOLLog( ostream *outs = 0 , const char lvl = 0 );
132
133/*--------------------------------------------------------------------------*/
134
135 void Format( void )
136 {
138 alpha = lastvalue = Inf< HpNum >(); // deflection coefficient is unknown
139 tau = tauInit;
140 }
141
142/*--------------------------------------------------------------------------*/
143/*-------------------- METHODS FOR DEFLECTION COMPUTATION ------------------*/
144/*--------------------------------------------------------------------------*/
145
146 inline void NewDEF( void );
147
148/*--------------------------------------------------------------------------*/
149/*---------------------- METHODS FOR READING RESULTS -----------------------*/
150/*--------------------------------------------------------------------------*/
151
152 inline HpNum GetDFLCoeff( void );
153
154 inline bool DoSS( void );
155
156 inline HpNum Delta( void );
157
158/*--------------------------------------------------------------------------*/
159/*--------------------- PRIVATE PART OF THE CLASS --------------------------*/
160/*--------------------------------------------------------------------------*/
161
162 private:
163
164/*--------------------------------------------------------------------------*/
165/*--------------------------- PRIVATE METHODS ------------------------------*/
166/*--------------------------------------------------------------------------*/
167
168 inline void Solve( void );
169
170/*--------------------------------------------------------------------------*/
171/*----------------------- PRIVATE DATA STRUCTURES -------------------------*/
172/*--------------------------------------------------------------------------*/
173
174 HpNum tauInit; // initial tau
175 HpNum tauMin; // the minimum value of tau
176 HpNum tauFactor; // the decreasing factor
177 Index tauIter; // the number of iterations after a decrease
178 HpNum m; // descent parameter
179
180 HpNum tau; // the safeguarded parameter tau
181 HpNum lastvalue; // last function value Fi()
182 HpNum alpha; // deflection coefficient
183
184/*--------------------------------------------------------------------------*/
185/*--------------------------------------------------------------------------*/
186
187 }; // end( class Volume )
188
189/*--------------------------------------------------------------------------*/
190/*------------------- inline methods implementation ------------------------*/
191/*--------------------------------------------------------------------------*/
192
193inline void Volume::SetVOLLog( ostream *outs , const char lvl )
194{
195 Deflection::SetVOLLog( outs , lvl );
196
197 #if( LOG_VOL )
198 if( VOLLLvl > 1 )
199 *VOLLog << std::endl << "Volume: tau = " << tauInit << " in ["<< tauMin
200 << " , -] with ( " << tauFactor << " , " << tauIter << " ) ~ m = "
201 << m << std::endl;
202 #endif
203 }
204
205/*--------------------------------------------------------------------------*/
206
207inline void Volume::NewDEF( void )
208{
209 // change tau if needed - - - - - - - - - - - - - - - - - - - - - - - - - - -
210 //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
211
212 if( Solver->NrIter() <= 1 ) {
213 alpha = 1;
214 return;
215 }
216
217 HpNum FiRec = Solver->ReadBestFiVal();
218
219 // tau should be decreased if after tauIter iterations Fi() is decreased
220 // less than 1% - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
221 //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
222
223 if( ! ( Solver->NrIter() % tauIter ) )
224 if( tau > tauMin ) {
225 cHpNum x = ( lastvalue - FiRec ) / ABS( FiRec );
226 lastvalue = FiRec;
227 if( x <= 0.01 ) {
228 tau *= tauFactor;
229 if( tau < tauMin )
230 tau = tauMin;
231 }
232 }
233
234 // solve a quadratic problem and get the deflection coefficient - - - - - - -
235 //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
236
237 Solve();
238
239 } // end( Volume::NewDEF )
240
241/*--------------------------------------------------------------------------*/
242
244{
245 return( alpha );
246 }
247
248/*--------------------------------------------------------------------------*/
249
250inline bool Volume::DoSS( void )
251{
252 bool serious;
253 HpNum Delta;
254 Solver->GetPar( NDOSolver::kEpsLin , Delta );
255 Delta *= m * std::max( 1.0 , ABS( Solver->ReadBestFiVal() ) );
256
257 // if there is an improvement of Fi(), a SS occurs; otherwise, a NS occurs
258 if( ( Solver->ReadFiVal() - ReadFVal() ) >= Delta )
259 serious = true;
260 else
261 serious = false;
262
263 return( serious );
264
265 } // end( Volume::DoSS )
266
267/*--------------------------------------------------------------------------*/
268
269inline HpNum Volume::Delta( void )
270{
271 HpNum EpsLin;
272 Solver->GetPar( NDOSolver::kEpsLin , EpsLin );
273 return( m * EpsLin * std::max( 1.0 , ABS( Solver->ReadBestFiVal() ) ) );
274 }
275
276/*--------------------------------------------------------------------------*/
277
278inline void Volume::Solve( void )
279{
280 HpNum GiNorm = GetGiNorm();
281 HpNum DNorm = GetDNorm();
282 HpNum GixD = GetdGk();
283 HpNum Sigma = GetSigma();
284 HpNum Epsilon = GetEpsilon();
285
286 // compute the proximity parameter - - - - - - - - - - - - - - - - - - - -
287 //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
288
289 HpNum proximity = GetStepsize() == Inf< HpNum >() ? 1 : GetStepsize();
290
291 // solving the cutting plane model - - - - - - - - - - - - - - - - - - - - -
292 //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
293
294 HpNum den = proximity * ( GiNorm + DNorm - 2.0 * GixD );
295
296 if( den <= 1e-8 )
297 alpha = 1;
298 else
299 alpha = ( Epsilon - Sigma - proximity * ( GixD - DNorm ) ) / den;
300
301 // tau should be projected over [0,1] - - - - - - - - - - - - - - - - - - -
302 //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
303
304 if( alpha > 1 )
305 alpha = std::min( tau , 1.0 );
306 else
307 if( alpha < 1e-8 )
308 alpha = tau / 10;
309
310 } // end ( void Solve )
311
312/*--------------------------------------------------------------------------*/
313/*--------------------------------------------------------------------------*/
314
315}; // end( namespace NDO_di_unipi_it )
316
317/*--------------------------------------------------------------------------*/
318/*--------------------------------------------------------------------------*/
319
320#endif /* Volume.h included */
321
322/*--------------------------------------------------------------------------*/
323/*------------------------- End File Volume.h ------------------------------*/
324/*--------------------------------------------------------------------------*/
Definition Deflection.h:63
char VOLLLvl
the "level of verbosity"
Definition Deflection.h:237
std::ostream * VOLLog
the output stream object
Definition Deflection.h:235
virtual void SetVOLLog(std::ostream *outs=0, const char lvl=0)
Definition Deflection.h:106
SubGrad * Solver
(pointer to) the SubGrad solver
Definition Deflection.h:233
virtual void Format(void)
Definition Deflection.h:117
Index NrIter(void) const
Definition NDOSlver.h:667
Definition SubGrad.h:148
HpNum ReadFiVal(cIndex wFi=Inf< Index >())
void GetPar(const int wp, int &value)
Definition SubGrad.h:825
HpNum ReadBestFiVal(cIndex wFi=Inf< Index >())
Definition Volume.h:84
Volume(SubGrad *slvr, std::istream *iStrm=0)
Definition Volume.h:118
bool DoSS(void)
Definition Volume.h:250
HpNum GetDFLCoeff(void)
Definition Volume.h:243
void NewDEF(void)
Definition Volume.h:207
HpNum Delta(void)
Definition Volume.h:269
void Format(void)
Definition Volume.h:135
const HpNum cHpNum
a read-only HpNum
Definition OPTtypes.h:102
double HpNum
"finer" floating point numbers
Definition OPTtypes.h:98
unsigned int Index
Index in a vector ( >= 0 )
Definition OPTtypes.h:60
static constexpr T Inf(void) noexcept
Inf< T >() = infinity value for T.
Definition OPTUtils.h:357
void DfltdSfInpt(istream *iStrm, T &Param, const T Dflt, const char cmntc='#')
Definition OPTUtils.h:392
Definition Bundle.h:68