bpp-core
2.1.0
Main Page
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Friends
AbstractOptimizer.h
Go to the documentation of this file.
1
//
2
// File: AbstractOptimizer.h
3
// Created by: Julien Dutheil
4
// Created on: Mon Dec 22 12:18:09 2003
5
//
6
7
/*
8
Copyright or © or Copr. Bio++ Development Team, (November 17, 2004)
9
10
This software is a computer program whose purpose is to provide classes
11
for numerical calculus.
12
13
This software is governed by the CeCILL license under French law and
14
abiding by the rules of distribution of free software. You can use,
15
modify and/ or redistribute the software under the terms of the CeCILL
16
license as circulated by CEA, CNRS and INRIA at the following URL
17
"http://www.cecill.info".
18
19
As a counterpart to the access to the source code and rights to copy,
20
modify and redistribute granted by the license, users are provided only
21
with a limited warranty and the software's author, the holder of the
22
economic rights, and the successive licensors have only limited
23
liability.
24
25
In this respect, the user's attention is drawn to the risks associated
26
with loading, using, modifying and/or developing or reproducing the
27
software by the user in light of its specific status of free software,
28
that may mean that it is complicated to manipulate, and that also
29
therefore means that it is reserved for developers and experienced
30
professionals having in-depth computer knowledge. Users are therefore
31
encouraged to load and test the software's suitability as regards their
32
requirements in conditions enabling the security of their systems and/or
33
data to be ensured and, more generally, to use and operate it in the
34
same conditions as regards security.
35
36
The fact that you are presently reading this means that you have had
37
knowledge of the CeCILL license and that you accept its terms.
38
*/
39
40
#ifndef _ABSTRACTOPTIMIZER_H_
41
#define _ABSTRACTOPTIMIZER_H_
42
43
#include "
Optimizer.h
"
44
45
namespace
bpp
46
{
47
59
class
AbstractOptimizer
:
60
public
virtual
Optimizer
61
{
62
private
:
63
67
Function
*
function_
;
68
72
ParameterList
parameters_
;
73
77
OutputStream
*
messageHandler_
;
78
82
OutputStream
*
profiler_
;
83
94
std::string
constraintPolicy_
;
95
99
OptimizationStopCondition
*
stopCondition_
;
100
104
OptimizationStopCondition
*
defaultStopCondition_
;
105
111
unsigned
int
verbose_
;
112
116
bool
isInitialized_
;
117
118
time_t
startTime_
;
119
120
std::vector<OptimizationListener*>
listeners_
;
121
122
bool
updateParameters_
;
123
124
std::string
stepChar_
;
125
126
protected
:
127
131
unsigned
int
nbEvalMax_
;
132
136
unsigned
int
nbEval_
;
137
141
double
currentValue_
;
142
149
bool
tolIsReached_
;
150
151
public
:
152
AbstractOptimizer
(
Function
*
function
= 0);
153
154
AbstractOptimizer
(
const
AbstractOptimizer
& opt);
155
156
AbstractOptimizer
&
operator=
(
const
AbstractOptimizer
& opt);
157
158
virtual
~AbstractOptimizer
()
159
{
160
delete
stopCondition_
;
161
delete
defaultStopCondition_
;
162
}
163
164
public
:
165
176
void
init
(
const
ParameterList
& params)
throw
(
Exception
);
182
double
step
() throw (
Exception
);
188
double
optimize
() throw (Exception);
189
bool
isInitialized
()
const
{
return
isInitialized_
; }
190
const
ParameterList
&
getParameters
()
const
{
return
parameters_
; }
191
double
getParameterValue
(
const
std::string& name)
const
{
return
parameters_
.
getParameterValue
(name); }
192
void
setFunction
(
Function
*
function
)
193
{
194
function_
=
function
;
195
if
(
function
)
stopCondition_
->
init
();
196
}
197
const
Function
*
getFunction
()
const
{
return
function_
; }
198
Function
*
getFunction
() {
return
function_
; }
199
bool
hasFunction
()
const
{
return
function_
!= 0; }
200
double
getFunctionValue
()
const
throw (
NullPointerException
)
201
{
202
if
(!
function_
)
throw
NullPointerException(
"AbstractOptimizer::getFunctionValue. No function associated to this optimizer."
);
203
return
currentValue_
;
204
}
205
206
void
setMessageHandler
(
OutputStream
* mh) {
messageHandler_
= mh; }
207
OutputStream
*
getMessageHandler
()
const
{
return
messageHandler_
; }
208
void
setProfiler
(
OutputStream
* profiler) {
profiler_
= profiler; }
209
OutputStream
*
getProfiler
()
const
{
return
profiler_
; }
210
211
unsigned
int
getNumberOfEvaluations
()
const
{
return
nbEval_
; }
212
void
setStopCondition
(
const
OptimizationStopCondition
& stopCondition)
213
{
214
stopCondition_
=
dynamic_cast<
OptimizationStopCondition
*
>
(stopCondition.
clone
());
215
}
216
OptimizationStopCondition
*
getStopCondition
() {
return
stopCondition_
; }
217
const
OptimizationStopCondition
*
getStopCondition
()
const
{
return
stopCondition_
; }
218
OptimizationStopCondition
*
getDefaultStopCondition
() {
return
defaultStopCondition_
; }
219
const
OptimizationStopCondition
*
getDefaultStopCondition
()
const
{
return
defaultStopCondition_
; }
220
bool
isToleranceReached
()
const
{
return
tolIsReached_
; }
221
bool
isMaximumNumberOfEvaluationsReached
()
const
{
return
nbEval_
>=
nbEvalMax_
; }
222
void
setMaximumNumberOfEvaluations
(
unsigned
int
max) {
nbEvalMax_
= max; }
223
void
setVerbose
(
unsigned
int
v) {
verbose_
= v; }
224
unsigned
int
getVerbose
()
const
{
return
verbose_
; }
225
void
setConstraintPolicy
(
const
std::string& constraintPolicy) {
constraintPolicy_
= constraintPolicy; }
226
std::string
getConstraintPolicy
()
const
{
return
constraintPolicy_
; }
227
void
addOptimizationListener
(
OptimizationListener
* listener)
228
{
229
if
(listener)
230
listeners_
.push_back(listener);
231
}
243
void
updateParameters
(
bool
yn) {
updateParameters_
= yn; }
244
254
bool
updateParameters
()
const
{
return
updateParameters_
; }
255
261
void
setOptimizationProgressCharacter
(
const
std::string& c) {
stepChar_
= c; }
265
const
std::string&
getOptimizationProgressCharacter
()
const
{
return
stepChar_
; }
266
267
protected
:
268
274
virtual
void
doInit
(
const
ParameterList
& params)
throw
(
Exception
) = 0;
275
281
virtual
double
doStep
() throw (
Exception
) = 0;
282
292
void
autoParameter
();
293
297
void
ignoreConstraints
();
298
304
void
profile
(
double
v);
305
311
void
profile
(
unsigned
int
v);
312
318
void
profile
(const std::
string
& s);
319
325
void
profileln
(
double
v);
326
332
void
profileln
(
unsigned
int
v);
333
339
void
profileln
(const std::
string
& s);
340
347
void
printPoint
(const
ParameterList
& params,
double
value);
348
354
void
printMessage
(const std::
string
& message);
355
363
void
fireOptimizationInitializationPerformed
(const
OptimizationEvent
& event);
364
372
void
fireOptimizationStepPerformed
(const
OptimizationEvent
& event);
373
374
bool
listenerModifiesParameters
() const;
377
protected:
378
ParameterList
&
getParameters_
() {
return
parameters_
; }
379
Parameter
&
getParameter_
(
size_t
i) {
return
parameters_
[i]; }
380
Function
*
getFunction_
() {
return
function_
; }
381
void
setDefaultStopCondition_
(
OptimizationStopCondition
* osc)
382
{
383
defaultStopCondition_
= osc;
384
}
385
386
};
387
388
}
//end of namespace bpp.
389
390
#endif //_ABSTRACTOPTIMIZER_H_
391
Bpp
Numeric
Function
AbstractOptimizer.h
Generated on Thu Mar 14 2013 16:32:30 for bpp-core by
1.8.3.1-20130209