42 #include "../../App/ApplicationTools.h"
43 #include "../../Text/TextTools.h"
44 #include "../AutoParameter.h"
56 AbstractOptimizer::AbstractOptimizer(
Function*
function) :
62 stopCondition_(0), defaultStopCondition_(0),
63 verbose_(true), isInitialized_(false), startTime_(), listeners_(),
64 updateParameters_(false), stepChar_(
"*"),
65 nbEvalMax_(1000000), nbEval_(0),
66 currentValue_(0), tolIsReached_(false)
72 function_(opt.function_),
73 parameters_(opt.parameters_),
74 messageHandler_(opt.messageHandler_),
75 profiler_(opt.profiler_),
76 constraintPolicy_(opt.constraintPolicy_),
77 stopCondition_(0), defaultStopCondition_(0),
78 verbose_(opt.verbose_),
79 isInitialized_(opt.isInitialized_),
80 startTime_(opt.startTime_),
82 updateParameters_(opt.updateParameters_),
83 stepChar_(opt.stepChar_),
84 nbEvalMax_(opt.nbEvalMax_),
86 currentValue_(opt.currentValue_),
87 tolIsReached_(opt.tolIsReached_)
161 throw Exception(
"AbstractOptimizer::init. Optimizer currently has no function.");
219 throw Exception(
"AbstractOptimizer::optimize. Optimizer not initialized: call the 'init' method first!");
281 size_t ndim = params.
size();
284 for (
size_t j = 0; j < ndim; j++)
330 for (
unsigned int i = 0; i <
listeners_.size(); i++)
332 listeners_[i]->optimizationInitializationPerformed(event);
340 for (
unsigned int i = 0; i <
listeners_.size(); i++)
342 listeners_[i]->optimizationStepPerformed(event);
350 for (
unsigned int i = 0; i <
listeners_.size(); i++)
Partial implementation of the Optimizer interface.
void ignoreConstraints()
Remove the constraints of all the arguments.
Function * function_
The function to optimize.
std::vector< OptimizationListener * > listeners_
OptimizationStopCondition * stopCondition_
The stoping condition to use while optimizing.
void fireOptimizationInitializationPerformed(const OptimizationEvent &event)
Notify all listeners that optimizer initialization was performed.
void printPoint(const ParameterList ¶ms, double value)
Print parameters and corresponding function evaluation to profiler.
double step()
Basic implementation.
double optimize()
Basic implementation.
void printMessage(const std::string &message)
Give a message to print to the message handler.
bool listenerModifiesParameters() const
void profileln(double v)
Print to the profile if there is one and end line.
unsigned int nbEvalMax_
The maximum number of function evaluations allowed.
void fireOptimizationStepPerformed(const OptimizationEvent &event)
Notify all listeners that an optimization step was performed.
OutputStream * profiler_
The profiler.
unsigned int nbEval_
The current number of function evaluations achieved.
OptimizationStopCondition * defaultStopCondition_
The default stoping condition to use while optimizing.
AbstractOptimizer(Function *function=0)
void init(const ParameterList ¶ms)
Basic implementation.
OutputStream * messageHandler_
The message handler.
unsigned int verbose_
State of the verbose mode: > 0 = enabled.
std::string constraintPolicy_
The constraint policy.
bool isInitialized_
Check if the optimizer have been feeded with initial parameters values.
double currentValue_
The current value of the function.
bool tolIsReached_
Tell if the tolerance level has been reached.
virtual void doInit(const ParameterList ¶ms)=0
This function is called by the init() method and contains all calculations.
void profile(double v)
Print to the profile if there is one.
void autoParameter()
Build a list of AutoParameter instead of Parameter.
AbstractOptimizer & operator=(const AbstractOptimizer &opt)
ParameterList parameters_
The parameters that will be optimized.
virtual double doStep()=0
This function is called by the step() method and contains all calculations.
static std::string CONSTRAINTS_AUTO
static std::string CONSTRAINTS_IGNORE
virtual void setMessageHandler(OutputStream *mh)
Set the message handler for this AutoParameter.
Exception base class. Overload exception constructor (to control the exceptions mechanism)....
This is the function abstract class.
virtual double getValue() const =0
Get the value of the function at the current point.
virtual double f(const ParameterList ¶meters)
Get the value of the function according to a given set of parameters.
An event object which indicates that an optimization event occured.
Interface for otimization stop condition objet.
OptimizationStopCondition * clone() const =0
Create a copy of this object and send a pointer to it.
virtual bool isToleranceReached() const =0
Tell if the we reached the desired tolerance with a given new set of estimates.
virtual void setOptimizer(const Optimizer *optimizer)=0
Set the optimizer attached to this instance.
virtual void init()=0
Initialize the condition.
The parameter list object.
virtual bool matchParametersValues(const ParameterList ¶ms, std::vector< size_t > *updatedParameters=0)
Update the parameters from params.
virtual void setParameter(size_t index, const Parameter ¶m)
Change given parameter.
virtual const ParameterList & getParameters() const =0
Get all parameters available.
std::string toString(T t)
General template method to convert to a string.