Completed eoInitPermutation: CTor now has a "isOneIndexed" parameter to assign 1..Indi_size as genotype values instead of 0..Indi_size

This commit is contained in:
tlegrand 2008-02-15 12:50:58 +00:00
commit 259dad2820

View file

@ -158,21 +158,24 @@ class eoInitPermutation: public eoInit<EOT>
typedef typename EOT::AtomType AtomType; typedef typename EOT::AtomType AtomType;
eoInitPermutation(unsigned _chromSize) eoInitPermutation(unsigned _chromSize, bool _isOneIndexed=true)
: chromSize(_chromSize){} : chromSize(_chromSize), isOneIndexed(_isOneIndexed){}
virtual void operator()(EOT& chrom) virtual void operator()(EOT& chrom)
{ {
chrom.resize(chromSize); chrom.resize(chromSize);
for(unsigned idx=0;idx <chrom.size();idx++) for(unsigned idx=0;idx <chrom.size();idx++)
if(isOneIndexed)
chrom[idx]=idx+1; chrom[idx]=idx+1;
else
chrom[idx]=idx;
std::random_shuffle(chrom.begin(), chrom.end(),gen); std::random_shuffle(chrom.begin(), chrom.end(),gen);
chrom.invalidate(); chrom.invalidate();
} }
private : private :
unsigned chromSize; unsigned chromSize;
bool isOneIndexed;
UF_random_generator<unsigned int> gen; UF_random_generator<unsigned int> gen;
}; };