dignea  1.0.0
Diverse Instance Generator with Novelty Search and Evolutionary Algorithms
UniformOneMutation.h
Go to the documentation of this file.
1 
12 #ifndef DIGNEA_UNIFORMONEMUTATION_H
13 #define DIGNEA_UNIFORMONEMUTATION_H
14 
15 #include <dignea/core/Mutation.h>
16 #include <dignea/utilities/random/PseudoRandom.h>
17 
23 template <class S>
24 class UniformOneMutation : public Mutation<S> {
25  public:
26  UniformOneMutation() = default;
27 
28  virtual ~UniformOneMutation() = default;
29 
30  void run(S &ind, const double &probability, Problem<S> *) override;
31 
32  std::string getName() const override { return "Uniform One Mutation"; };
33 };
34 
45 template <class S>
46 void UniformOneMutation<S>::run(S &ind, const double &probability,
47  Problem<S> *problem) {
48  if (PseudoRandom::randDouble() < probability) {
49  int varIndex = PseudoRandom::randInt(0, ind.getNumberOfVars() - 1);
50  auto varNewValue = PseudoRandom::randDouble(
51  problem->getLowerLimit(varIndex), problem->getUpperLimit(varIndex));
52  ind.setVarAt(varIndex, varNewValue);
53  }
54 }
55 
56 #endif // DIGNEA_UNIFORMONEMUTATION_H
Abstract Mutation interface.
Definition: Mutation.h:21
Class to represent a Problem in the tool. It includes the basic information for a problem a few metho...
Definition: Problem.h:29
virtual float getLowerLimit(const int i) const =0
Returns the lower bound to the problem at dimension i. This method must be implemented in the subclas...
virtual float getUpperLimit(const int i) const =0
Returns the upper bound to the problem at dimension i. This method must be implemented in the subclas...
static int randInt(int minBound, int maxBound)
Returns a random integer int the range [minBound, maxBound].
Definition: PseudoRandom.cpp:38
static double randDouble()
Generates a random double value between 0.0 and 1.0.
Definition: PseudoRandom.cpp:31
Uniform One Mutation.
Definition: UniformOneMutation.h:24
void run(S &ind, const double &probability, Problem< S > *) override
Performs the Uniform One Mutation Operator with a probability lower than the given parameter (probabi...
Definition: UniformOneMutation.h:46