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.toLatin1() );
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 ) {
123 rankv = params.
getValue( prefix + QString(
"rank" ) ).toDouble();
131 foreach(
double avalue,
fitnessv ) {
132 fitstring.append( QString(
"%1 ").arg(avalue) );
143 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" );
144 d.
describeString(
"data" ).
help(
"The bits composing the Genotype stored in a compressed string" );
145 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" );
166 unsigned char* newdata =
new unsigned char[
allocated];
196 bool allLessEq =
true;
197 bool oneLessStrictly =
false;
198 for(
int i=0; i<numObjToCompare; i++ ) {
203 oneLessStrictly =
true;
206 return (allLessEq && oneLessStrictly);
222 unsigned char mask = 0x80 >> (i&7);
223 return (
data[
id] & mask );
231 unsigned char mask = 0x80 >> (i&7);
241 unsigned char mask = 0x80 >> (i&7);
251 unsigned char mask = 0x80 >> (i&7);
266 for(
unsigned int i=0; i<
sizev; i++ ) {
267 ret += (
bit(i) == other->
bit(i) );
273 for(
unsigned int i=0; i<
sizev; i++ ) {
285 for(
unsigned int i=0; i<
sizev; i++ ) {
286 ret[i] = (
bit(i) ) ?
'1' :
'0';
292 int dim = qMin( (
int)
sizev, str.size() );
293 for(
int i=0; i<dim; i++ ) {
294 if ( str[i] ==
'1' ) {
304 temp.resize(
sizev );
305 for(
unsigned int i=0; i<
sizev; i++ ) {
306 temp[i] = (
bit(i) ) ?
'1' :
'0';
308 QByteArray temp2 = qCompress( temp, 9 );
309 return temp2.toBase64();
313 QByteArray temp2 = QByteArray::fromBase64( str.toLatin1() );
314 QByteArray temp = qUncompress( temp2 );
315 if ( temp.isEmpty() ) {
318 int dim = qMin( (
int)
sizev, temp.size() );
319 for(
int i=0; i<dim; i++ ) {
320 if ( temp[i] ==
'1' ) {
330 if ( startPos >=
sizev )
return 0;
332 stopPos = qMin( stopPos,
sizev );
333 unsigned int len = stopPos - startPos;
334 unsigned int ret = 0;
335 for( ; startPos<stopPos; startPos++ ) {
337 if (
bit(startPos) ) {
338 ret += (
unsigned int)( pow( 2.0f, (
int)len ) );
345 if ( startPos >=
sizev ) return ;
347 stopPos = qMin( stopPos,
sizev );
348 for( ; stopPos!=startPos; stopPos-- ) {
349 if ( value%2 == 1 ) {