GENEIAL  0.2=/
 All Classes Pages
SmoothPeakMutationOperation.h
1 #pragma once
2 
3 #include <geneial/core/operations/mutation/MultiValueChromosomeMutationOperation.h>
4 #include <geneial/core/population/builder/ContinousMultiValueChromosomeFactory.h>
5 #include <geneial/core/population/builder/ContinousMultiValueBuilderSettings.h>
6 #include <geneial/utility/Smoothing.h>
7 #include <geneial/utility/mixins/EnableMakeShared.h>
8 #include <geneial/core/population/Population.h>
9 
10 #include <cassert>
11 
12 geneial_private_namespace(geneial)
13 {
14 geneial_private_namespace(operation)
15 {
16 geneial_private_namespace(mutation)
17 {
18 using ::geneial::population::chromosome::ContinousMultiValueBuilderSettings;
19 using ::geneial::population::chromosome::ContinousMultiValueChromosomeFactory;
20 using ::geneial::population::Population;
21 using ::geneial::utility::EnableMakeShared;
22 
23 
24 geneial_export_namespace
25 {
26 
27 template<typename VALUE_TYPE, typename FITNESS_TYPE>
28 class SmoothPeakMutationOperation: public MultiValueChromosomeMutationOperation<VALUE_TYPE,FITNESS_TYPE>,
29  public EnableMakeShared<SmoothPeakMutationOperation<VALUE_TYPE,FITNESS_TYPE>>
30 {
31 
32 private:
33  unsigned int _maxLeftEps;
34 
35  unsigned int _maxRightEps;
36 
37  FITNESS_TYPE _maxElevation;
38 
39 protected:
40  SmoothPeakMutationOperation(
41  const unsigned int maxLeftEps,
42  const unsigned int maxRightEps,
43  const FITNESS_TYPE maxElevation,
44  const std::shared_ptr<const MultiValueMutationSettings> &settings,
45  const std::shared_ptr<const BaseChoosingOperation<FITNESS_TYPE>> &choosingOperation,
46  const std::shared_ptr<ContinousMultiValueChromosomeFactory<VALUE_TYPE, FITNESS_TYPE>> &builderFactory) :
47 
48  MultiValueChromosomeMutationOperation<VALUE_TYPE,FITNESS_TYPE>(
49  settings,
50  choosingOperation,
51  builderFactory
52  ),
53 
54  _maxLeftEps(maxLeftEps),
55  _maxRightEps(maxRightEps),
56  _maxElevation(maxElevation)
57  {
58  //TODO (bewo): Make some assertions regarding eps and builder here
59  }
60 public:
61 
62  virtual ~SmoothPeakMutationOperation()
63  {
64  }
65 
70  virtual typename Population<FITNESS_TYPE>::chromosome_container doMutate(
71  const typename Population<FITNESS_TYPE>::chromosome_container &mutants, BaseManager<FITNESS_TYPE> &manager) const override;
72 
73  FITNESS_TYPE getMaxElevation() const
74  {
75  return _maxElevation;
76  }
77 
78  unsigned int getMaxLeftEps() const
79  {
80  return _maxLeftEps;
81  }
82 
83  unsigned int getMaxRightEps() const
84  {
85  return _maxRightEps;
86  }
87 
88 
89  class Builder : public MultiValueChromosomeMutationOperation<VALUE_TYPE,FITNESS_TYPE>::Builder
90  {
91  protected:
92  unsigned int _maxLeftEps;
93 
94  unsigned int _maxRightEps;
95 
96  FITNESS_TYPE _maxElevation;
97  public:
98 
99  const constexpr static unsigned int DEFAULT_MAX_LEFT_EPS = 2;
100 
101  const constexpr static unsigned int DEFAULT_MAX_RIGHT_EPS = 2;
102 
103  const constexpr static FITNESS_TYPE DEFAULT_MAX_ELEVATION = 5;
104 
105  Builder(const std::shared_ptr<ContinousMultiValueChromosomeFactory<VALUE_TYPE, FITNESS_TYPE>> &builderFactory) :
106  MultiValueChromosomeMutationOperation<VALUE_TYPE, FITNESS_TYPE>::Builder(builderFactory),
107  _maxLeftEps(DEFAULT_MAX_LEFT_EPS),
108  _maxRightEps(DEFAULT_MAX_RIGHT_EPS),
109  _maxElevation(DEFAULT_MAX_ELEVATION)
110  {
111  }
112 
113  Builder(const std::shared_ptr<MultiValueMutationSettings> &settings,
114  const std::shared_ptr<BaseChoosingOperation<FITNESS_TYPE>> &choosingOperation,
115  const std::shared_ptr<ContinousMultiValueChromosomeFactory<VALUE_TYPE, FITNESS_TYPE>> &builderFactory) :
116  MultiValueChromosomeMutationOperation<VALUE_TYPE, FITNESS_TYPE>::Builder(settings, choosingOperation,
117  builderFactory),
118  _maxLeftEps(DEFAULT_MAX_LEFT_EPS),
119  _maxRightEps(DEFAULT_MAX_RIGHT_EPS),
120  _maxElevation(DEFAULT_MAX_ELEVATION)
121  {
122  }
123 
124  Builder& setMaxElevation(FITNESS_TYPE maxElevation)
125  {
126  _maxElevation = maxElevation;
127  return *this;
128  }
129 
130  Builder& setMaxLeftEps(unsigned int maxLeftEps)
131  {
132  _maxLeftEps = maxLeftEps;
133  return *this;
134  }
135 
136  Builder& setMaxRightEps(unsigned int maxRightEps)
137  {
138  _maxRightEps = maxRightEps;
139  return *this;
140  }
141 
142  virtual typename BaseMutationOperation<FITNESS_TYPE>::ptr create() override
143  {
144  return std::move
145  (
146  SmoothPeakMutationOperation<VALUE_TYPE,FITNESS_TYPE>::makeShared(
147  this->_maxLeftEps,
148  this->_maxRightEps,
149  this->_maxElevation,
150  this->_settings,
151  this->_choosingOperation,
152  std::dynamic_pointer_cast<ContinousMultiValueChromosomeFactory<VALUE_TYPE, FITNESS_TYPE>>(this->_builderFactory)
153  )
154  );
155  }
156 
157  };
158 
159 
160 
161 };
162 //class
163 
164 } /* geneial_export_namespace */
165 } /* private namespace mutation */
166 } /* private namespace operation */
167 } /* private namespace geneial */
168 
169 #include <geneial/core/operations/mutation/SmoothPeakMutationOperation.hpp>
170