dignea  1.0.0
Diverse Instance Generator with Novelty Search and Evolutionary Algorithms
UniformAllMutation.h
Go to the documentation of this file.
1 
12 #ifndef DIGNEA_UNIFORMALLMUTATION_H
13 #define DIGNEA_UNIFORMALLMUTATION_H
14 
15 #include <dignea/core/Mutation.h>
16 #include <dignea/utilities/random/PseudoRandom.h>
17 
23 template <class S>
24 class UniformAllMutation : public Mutation<S> {
25  public:
26  UniformAllMutation() = default;
27 
28  virtual ~UniformAllMutation() = default;
29 
30  void run(S &ind, const double &probability, Problem<S> *) override;
31 
32  std::string getName() const override { return "Uniform All Mutation"; };
33 };
34 
45 template <class S>
46 void UniformAllMutation<S>::run(S &ind, const double &probability,
47  Problem<S> *problem) {
48  for (int i = 0; i < ind.getNumberOfVars(); i++) {
49  if (PseudoRandom::randDouble() < probability) {
50  auto var = PseudoRandom::randDouble(problem->getLowerLimit(i),
51  problem->getUpperLimit(i));
52  ind.setVarAt(i, var);
53  }
54  }
55 }
56 
57 #endif // DIGNEA_UNIFORMALLMUTATION_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 double randDouble()
Generates a random double value between 0.0 and 1.0.
Definition: PseudoRandom.cpp:31
Uniform All Mutation Operator.
Definition: UniformAllMutation.h:24
void run(S &ind, const double &probability, Problem< S > *) override
Mutates each variable in the individual with a random probability lower than the probability paramete...
Definition: UniformAllMutation.h:46