GPLIB++
GrayTranscribe.cpp
Go to the documentation of this file.
1 #include "GrayTranscribe.h"
2 #include <cmath>
3 #include <boost/numeric/conversion/cast.hpp>
4 
5 namespace gplib
6  {
8  const ttranscribed &step, const tsizev &gene) :
9  BinaryTranscribe(base, step, gene)
10  {
11  }
12 
14  {
15  }
16 
18  {
19  unsigned int currentindex = 0;
20  unsigned int currentmaxindex = 0;
21  double currentvalue;
22  double exponent;
23 
24  ttranscribed ReturnValues(genesizes.size());
25  //for each model parameter
26  for (unsigned int i = 0; i < genesizes.size(); ++i)
27  {
28  currentvalue = 0;
29  //scan the corresponding section of the genetic string
30  currentmaxindex = currentindex + genesizes(i);
31  for (unsigned int j = currentindex; j < currentmaxindex; ++j)
32  {
33  exponent = 0.0;
34  for (unsigned int k = j; k < currentmaxindex; ++k)
35  {
36  exponent += member(k);
37  }
38  currentvalue += -1.0 * member(j) * std::pow(-1.0, exponent) * (std::pow(
39  2.0, boost::numeric_cast<int>(j - currentindex + 1)) - 1.0); //calculate the numeric value from the bits
40  }
41  currentvalue *= stepsizes(i);
42  currentvalue += basevalues(i);
43  currentindex += genesizes(i);
44  ReturnValues(i) = currentvalue; //store in the right component
45  }
46  return (ReturnValues);
47  }
48  }
BinaryTranscibe implements transcription for standard binary populations.
ublas::vector< double > ttranscribed
Definition: gentypes.h:21
GrayTranscribe(const ttranscribed &base, const ttranscribed &step, const tsizev &gene)
virtual ttranscribed GetValues(const tpopmember &member)
Re-Implements the function from BinaryTranscribe.
const ttranscribed stepsizes
The stepsize associated to a bit change for each parameter.
ublas::vector< bool > tpopmember
Definition: gentypes.h:22
const tsizev genesizes
The number of bits for each parameter.
ublas::vector< int > tsizev
Definition: gentypes.h:27
const ttranscribed basevalues
The minimum value for each parameter.