GeneticAlgoithm
Implementation of the genetic algorithm
IFigureOfMerit.cxx
1 #include "IFigureOfMerit.h"
2 
3 #include "IModel.h"
4 
6 {
8 }
9 
11 {
12 }
13 
14 /**
15  * The default behavior is to apply a threshold on the score.
16  *
17  * Derived classes can override this method if the default behaviour is not adequate.
18  *
19  * @param score The score of the model to be tested.
20  * @return true if the score can be accepted.
21  */
22 bool IFigureOfMerit::accept(double score) const
23 {
24  return isBetterThan(score, m_acceptThreshold);
25 }
26 
27 /**
28  * This is an overloaded function.
29  * The default behavior is to apply a threshold on the score.
30  *
31  * Derived classes can override this method if the decision is not based solely on the score.
32  *
33  * @param model The model to be tested.
34  * @return true if the model can be accepted.
35  */
36 bool IFigureOfMerit::accept(IModel *model) const
37 {
38  return accept(model->getScore());
39 }
40 
41 /**
42  * The default behavior is: higher score is better.
43  *
44  * Derived classes can override this method if the default behaviour is not adequate.
45  *
46  * @param scoreToTest The score of the model to be tested.
47  * @param referenceScore The score of the model to compare to.
48  * @return true if scoreToTest is better than referenceScore, false otherwise.
49  */
50 bool IFigureOfMerit::isBetterThan(double scoreToTest, double referenceScore) const
51 {
52  return scoreToTest > referenceScore;
53 }
54 
55 /**
56  * This is an overloaded function.
57  * The default behavior is: higher score is better.
58  *
59  * Derived classes can override this method if the comparison is not based solely on the score.
60  *
61  * @param modelToTest The model to be tested.
62  * @param referenceModel The model to compare to.
63  * @return true if modelToTest is better than referenceModel, false otherwise.
64  */
65 bool IFigureOfMerit::isBetterThan(IModel *modelToTest, IModel *referenceModel) const
66 {
67  return isBetterThan(modelToTest->getScore(), referenceModel->getScore());
68 }
69 
70 /**
71  * @param threshold score threshold to accept a model as a final answer.
72  */
73 void IFigureOfMerit::setAcceptThreshold(double threshold)
74 {
75  m_acceptThreshold = threshold;
76 }
77 
78 /**
79  * @return the score threshold to accept a model as a final answer.
80  */
82 {
83  return m_acceptThreshold;
84 }
virtual ~IFigureOfMerit()
virtual bool accept(IModel *model) const
void setAcceptThreshold(double acceptThreshold)
virtual bool isBetterThan(IModel *scoreToTest, IModel *referenceModel) const
double getAcceptThreshold() const
double getScore() const
Definition: IModel.cxx:16
double m_acceptThreshold
Stores the score threshold to accept a model as a final answer.
Abstract class describing the interface for a model.
Definition: IModel.h:13