deterministicrank.cpp
1 /********************************************************************************
2  * FARSA Genetic Algorithm Library *
3  * Copyright (C) 2007-2009 Gianluca Massera <emmegian@yahoo.it> *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the Free Software *
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA *
18  ********************************************************************************/
19 
20 #include "gaconfig.h"
21 #include "core/genome.h"
22 #include "selections/deterministicrank.h"
23 #include "configurationparameters.h"
24 
25 namespace farsa {
26 
28  : Selection() {
29  nTruncation = 1;
30 }
31 
33  //--- nothing to do
34 }
35 
37  return genome()->at( idNext++ % nTruncation );
38 }
39 
42  idNext = 0;
43 }
44 
45 void DeterministicRank::setTruncation( int nTruncation ) {
46  this->nTruncation = nTruncation;
47 }
48 
50  return nTruncation;
51 }
52 
53 void DeterministicRank::configure( ConfigurationParameters& params, QString prefix ) {
54  nTruncation = params.getValue( prefix + QString( "nTruncation" ) ).toInt();
55 }
56 
57 void DeterministicRank::save( ConfigurationParameters& params, QString prefix ) {
58  params.createParameter( prefix, QString("type"), "DeterministicRank" );
59  params.createParameter( prefix, QString("nTruncation"), QString("%1").arg( nTruncation ) );
60 }
61 
62 void DeterministicRank::describe( QString type ) {
63  Descriptor d = addTypeDescription( type, "Selects the individual with a deterministic round-robin" );
64  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" );
65 }
66 
67 } // end namespace farsa