20 #include "core/genotype.h"
21 #include "randomgenerator.h"
24 #include "configurationparameters.h"
31 allocated = (
unsigned int)( (size+1)/8 ) + 1;
49 for(
unsigned int i=0; i<
sizev; i++ ) {
50 if ( str[i] ==
'1' ) {
57 QByteArray temp2 = QByteArray::fromBase64( str.toAscii() );
58 QByteArray temp = qUncompress( temp2 );
63 for(
unsigned int i=0; i<
sizev; i++ ) {
64 if ( temp[i] ==
'1' ) {
101 int newsize = params.
getValue( prefix + QString(
"bitsize" ) ).toInt();
102 Q_ASSERT_X( newsize > 0,
103 "Genotype::configure",
104 "The bitsize must be present in the config file and its value must be greater than zero" );
106 QString zipdata = params.
getValue( prefix + QString(
"data" ) );
107 if ( !zipdata.isNull() ) {
110 QStringList valuesList = params.
getValue( prefix + QString(
"fitness" ) )
111 .split( QRegExp(
"\\s+"), QString::SkipEmptyParts );
113 foreach( QString avalue, valuesList ) {
116 rankv = params.
getValue( prefix + QString(
"rank" ) ).toDouble();
124 foreach(
double avalue,
fitnessv ) {
125 fitstring.append( QString(
"%1 ").arg(avalue) );
136 d.
describeReal(
"fitness" ).
props(
IsList ).
help(
"The fitness of the Genotype",
"The fitness of a Genotype support multi objective fitness; if you specify a vector of values they are considered different objectives of the fitness" );
137 d.
describeString(
"data" ).
help(
"The bits composing the Genotype stored in a compressed string" );
138 d.
describeReal(
"rank" ).
help(
"The rank indicate who is more fitted that others and how much; the values are dependent on the kind of GeneticAlgo used" );
159 unsigned char* newdata =
new unsigned char[
allocated];
189 bool allLessEq =
true;
190 bool oneLessStrictly =
false;
191 for(
int i=0; i<numObjToCompare; i++ ) {
196 oneLessStrictly =
true;
199 return (allLessEq && oneLessStrictly);
215 unsigned char mask = 0x80 >> (i&7);
216 return (
data[
id] & mask );
224 unsigned char mask = 0x80 >> (i&7);
234 unsigned char mask = 0x80 >> (i&7);
244 unsigned char mask = 0x80 >> (i&7);
259 for(
unsigned int i=0; i<
sizev; i++ ) {
260 ret += (
bit(i) == other->
bit(i) );
266 for(
unsigned int i=0; i<
sizev; i++ ) {
278 for(
unsigned int i=0; i<
sizev; i++ ) {
279 ret[i] = (
bit(i) ) ?
'1' :
'0';
285 int dim = qMin( (
int)
sizev, str.size() );
286 for(
int i=0; i<dim; i++ ) {
287 if ( str[i] ==
'1' ) {
297 temp.resize(
sizev );
298 for(
unsigned int i=0; i<
sizev; i++ ) {
299 temp[i] = (
bit(i) ) ?
'1' :
'0';
301 QByteArray temp2 = qCompress( temp, 9 );
302 return temp2.toBase64();
306 QByteArray temp2 = QByteArray::fromBase64( str.toAscii() );
307 QByteArray temp = qUncompress( temp2 );
308 if ( temp.isEmpty() ) {
311 int dim = qMin( (
int)
sizev, temp.size() );
312 for(
int i=0; i<dim; i++ ) {
313 if ( temp[i] ==
'1' ) {
323 if ( startPos >=
sizev )
return 0;
325 stopPos = qMin( stopPos,
sizev );
326 unsigned int len = stopPos - startPos;
327 unsigned int ret = 0;
328 for( ; startPos<stopPos; startPos++ ) {
330 if (
bit(startPos) ) {
331 ret += (
unsigned int)( pow( 2.0f, (
int)len ) );
338 if ( startPos >=
sizev ) return ;
340 stopPos = qMin( stopPos,
sizev );
341 for( ; stopPos!=startPos; stopPos-- ) {
342 if ( value%2 == 1 ) {