string expressionFromChromosome(const Chromosome& candidate) { string expression = ""; int numBlocks = candidate.size() / 4; for (int index = 0; index < numBlocks; ++index) { string bits = ""; for (int loc = 0; loc < 4; ++loc) { bits += (candidate[4*index + loc] == true ? '1' : '0'); } if ('?' != convertFromBits(bits)) expression += convertFromBits(bits); } return expression; }
void Chromosome_Length_test::testBuildChromosome() { unsigned int nDim = 3; unsigned int aPrecision = 6; std::vector<double> domain; for(unsigned i=0; i<2*nDim; ++i) { domain.push_back(2*i+i); } Chromosome_Length chrom_length(aPrecision, nDim, domain); chrom_length.buildChromosome(); Chromosome chrom = chrom_length.getChromosome(); std:: cout<< "the total length of the chromosome = "<< chrom.size()<< std::endl; }
void Fitness_test::testFitness() { unsigned int aPrecision = 4; std::vector<double> adomain; adomain.push_back(1.0); adomain.push_back(2.0); adomain.push_back(3.0); adomain.push_back(6.0); adomain.push_back(8.0); adomain.push_back(16.0); std::vector<unsigned int> length; unsigned int aNDIM = 3; Chromosome_Length chrom(aPrecision, aNDIM, adomain); chrom.buildChromosome(); length = chrom.getLength(); Chromosome achromosome = chrom.getChromosome(); for(unsigned int i=0; i<achromosome.size(); i++) { if(i%2==0) { achromosome[i]=true; } else achromosome[i]=false; } Function afunction; Fittness_value<Function> fitness(length, aNDIM, adomain, afunction); double result; result = fitness.computeValue(achromosome); std:: cout << "the final value is = " << result << std::endl; }