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