BinaryTranscribe.cpp

Go to the documentation of this file.
00001 #include "BinaryTranscribe.h"
00002 #include "FatalException.h"
00003 
00004 namespace gplib
00005   {
00006     BinaryTranscribe::BinaryTranscribe(const ttranscribed &base,
00007         const ttranscribed &step, const tsizev &gene) :
00008       basevalues(base), stepsizes(step), genesizes(gene)
00009       {
00010         if ((basevalues.size() != stepsizes.size()) || (basevalues.size()
00011             != genesizes.size()))
00012           throw FatalException(
00013               "Basevalues, Stepsizes and Genesizes do not have equal length !");
00014       }
00015 
00016     BinaryTranscribe::~BinaryTranscribe()
00017       {
00018       }
00019 
00020     ttranscribed BinaryTranscribe::GetValues(const tpopmember &member)
00021       {
00022         unsigned int currentindex = 0;
00023         double currentvalue;
00024 
00025         ttranscribed ReturnValues(genesizes.size());
00026         //for each model parameter
00027         for (unsigned int i = 0; i < genesizes.size(); ++i)
00028           {
00029             currentvalue = 0;
00030             //scan the corresponding section of the genetic string
00031             for (unsigned int j = currentindex; j < currentindex + genesizes(i); ++j)
00032               {
00033                 currentvalue += member(j) * pow(2, j - currentindex); //calculate the numeric value from the bits
00034               }
00035             currentvalue *= stepsizes(i);
00036             currentvalue += basevalues(i);
00037             currentindex += genesizes(i);
00038             ReturnValues(i) = currentvalue; //store in the right component
00039           }
00040         return (ReturnValues);
00041       }
00042 
00043     BinaryTranscribe::BinaryTranscribe(const BinaryTranscribe &Old) :
00044       basevalues(Old.basevalues), stepsizes(Old.stepsizes), genesizes(
00045           Old.genesizes)
00046       {
00047         // The body is empty
00048       }
00049 
00050   }

Generated on Tue Nov 3 13:24:13 2009 for GPLIB++ by  doxygen 1.5.8