00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "crossovers/onepoint.h"
00021 #include "core/genotype.h"
00022 #include "randomgenerator.h"
00023 #include "configurationparameters.h"
00024
00025 namespace farsa {
00026
00027 OnePoint::OnePoint() : Crossover() {
00028 }
00029
00030 OnePoint::~OnePoint() {
00031
00032 }
00033
00034 void OnePoint::crossover( Genotype* father, const Genotype* mother ) {
00035 int max = qMin( father->size(), mother->size() );
00036 int splitpoint = globalRNG->getInt( 0, max );
00037 for( int i=splitpoint; i<max; i++ ) {
00038 if ( father->bit(i) != mother->bit(i) ) {
00039 father->toggle(i);
00040 }
00041 }
00042 }
00043
00044 void OnePoint::configure( ConfigurationParameters& params, QString prefix ) {
00045 Q_UNUSED( params );
00046 Q_UNUSED( prefix );
00047
00048 }
00049
00050 void OnePoint::save( ConfigurationParameters& params, QString prefix ) {
00051 params.createParameter( prefix, QString("type"), "OnePoint" );
00052 }
00053
00054 void OnePoint::describe( QString type ) {
00055 addTypeDescription( type, "The one point crossover", "It randomly select one point where to split the two Genotypes, and create a new one combining the first part of one Genotype with the second part of the other one" );
00056 }
00057
00058 }