OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
IndependentBitMutation.h
Go to the documentation of this file.
1 #include "boost/smart_ptr.hpp"
2 #include "Util/CmdArguments.h"
3 
5 template <class T> struct IndependentBitMutation
6 {
7  void mutate(boost::shared_ptr<T> ind, CmdArguments_t args) {
8 
9  const double probability =
10  args->getArg<double>("gene-mutation-probability", 0.5);
11 
12  for(size_t i = 0; i < ind->genes_m.size(); i++) {
13  double rval = static_cast<double>(rand() / (RAND_MAX + 1.0));
14  if(rval < probability) {
15  ind->new_gene(i);
16  }
17  }
18  }
19 };
boost::shared_ptr< CmdArguments > CmdArguments_t
Definition: CmdArguments.h:169
Mutate each gene with probability p.
void mutate(boost::shared_ptr< T > ind, CmdArguments_t args)