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 );
112 if ( valuesList.size() > 0 ) {
115 foreach( QString avalue, valuesList ) {
119 rankv = params.
getValue( prefix + QString(
"rank" ) ).toDouble();
127 foreach(
double avalue,
fitnessv ) {
128 fitstring.append( QString(
"%1 ").arg(avalue) );
139 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" );
140 d.
describeString(
"data" ).
help(
"The bits composing the Genotype stored in a compressed string" );
141 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" );
162 unsigned char* newdata =
new unsigned char[
allocated];
192 bool allLessEq =
true;
193 bool oneLessStrictly =
false;
194 for(
int i=0; i<numObjToCompare; i++ ) {
199 oneLessStrictly =
true;
202 return (allLessEq && oneLessStrictly);
218 unsigned char mask = 0x80 >> (i&7);
219 return (
data[
id] & mask );
227 unsigned char mask = 0x80 >> (i&7);
237 unsigned char mask = 0x80 >> (i&7);
247 unsigned char mask = 0x80 >> (i&7);
262 for(
unsigned int i=0; i<
sizev; i++ ) {
263 ret += (
bit(i) == other->
bit(i) );
269 for(
unsigned int i=0; i<
sizev; i++ ) {
281 for(
unsigned int i=0; i<
sizev; i++ ) {
282 ret[i] = (
bit(i) ) ?
'1' :
'0';
288 int dim = qMin( (
int)
sizev, str.size() );
289 for(
int i=0; i<dim; i++ ) {
290 if ( str[i] ==
'1' ) {
300 temp.resize(
sizev );
301 for(
unsigned int i=0; i<
sizev; i++ ) {
302 temp[i] = (
bit(i) ) ?
'1' :
'0';
304 QByteArray temp2 = qCompress( temp, 9 );
305 return temp2.toBase64();
309 QByteArray temp2 = QByteArray::fromBase64( str.toAscii() );
310 QByteArray temp = qUncompress( temp2 );
311 if ( temp.isEmpty() ) {
314 int dim = qMin( (
int)
sizev, temp.size() );
315 for(
int i=0; i<dim; i++ ) {
316 if ( temp[i] ==
'1' ) {
326 if ( startPos >=
sizev )
return 0;
328 stopPos = qMin( stopPos,
sizev );
329 unsigned int len = stopPos - startPos;
330 unsigned int ret = 0;
331 for( ; startPos<stopPos; startPos++ ) {
333 if (
bit(startPos) ) {
334 ret += (
unsigned int)( pow( 2.0f, (
int)len ) );
341 if ( startPos >=
sizev ) return ;
343 stopPos = qMin( stopPos,
sizev );
344 for( ; stopPos!=startPos; stopPos-- ) {
345 if ( value%2 == 1 ) {