ga/src/selections/deterministicrank.cpp
00001 /******************************************************************************** 00002 * FARSA Genetic Algorithm Library * 00003 * Copyright (C) 2007-2009 Gianluca Massera <emmegian@yahoo.it> * 00004 * * 00005 * This program is free software; you can redistribute it and/or modify * 00006 * it under the terms of the GNU General Public License as published by * 00007 * the Free Software Foundation; either version 2 of the License, or * 00008 * (at your option) any later version. * 00009 * * 00010 * This program is distributed in the hope that it will be useful, * 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00013 * GNU General Public License for more details. * 00014 * * 00015 * You should have received a copy of the GNU General Public License * 00016 * along with this program; if not, write to the Free Software * 00017 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * 00018 ********************************************************************************/ 00019 00020 #include "gaconfig.h" 00021 #include "core/genome.h" 00022 #include "selections/deterministicrank.h" 00023 #include "configurationparameters.h" 00024 00025 namespace farsa { 00026 00027 DeterministicRank::DeterministicRank() 00028 : Selection() { 00029 nTruncation = 1; 00030 } 00031 00032 DeterministicRank::~DeterministicRank() { 00033 //--- nothing to do 00034 } 00035 00036 const Genotype* DeterministicRank::select() { 00037 return genome()->at( idNext++ % nTruncation ); 00038 } 00039 00040 void DeterministicRank::setGenome( const Genome* g ) { 00041 Selection::setGenome( g ); 00042 idNext = 0; 00043 } 00044 00045 void DeterministicRank::setTruncation( int nTruncation ) { 00046 this->nTruncation = nTruncation; 00047 } 00048 00049 int DeterministicRank::truncation() { 00050 return nTruncation; 00051 } 00052 00053 void DeterministicRank::configure( ConfigurationParameters& params, QString prefix ) { 00054 nTruncation = params.getValue( prefix + QString( "nTruncation" ) ).toInt(); 00055 } 00056 00057 void DeterministicRank::save( ConfigurationParameters& params, QString prefix ) { 00058 params.createParameter( prefix, QString("type"), "DeterministicRank" ); 00059 params.createParameter( prefix, QString("nTruncation"), QString("%1").arg( nTruncation ) ); 00060 } 00061 00062 void DeterministicRank::describe( QString type ) { 00063 Descriptor d = addTypeDescription( type, "Selects the individual with a deterministic round-robin" ); 00064 d.describeInt( "nTruncation" ).limits( 1, INT_MAX ).def( 20 ).help( "Only the first nTruncation individuals will be select for reproduce. The individuals will be sorted on their rank" ); 00065 } 00066 00067 } // end namespace farsa