t-selectOne.cpp

00001 // -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
00002 
00003 //-----------------------------------------------------------------------------
00004 // t-selectOne.cpp
00005 //   This program test the breeder object
00006 // (c) GeNeura Team, 1998 
00007 /* 
00008     This program is free software; you can redistribute it and/or modify
00009     it under the terms of the GNU General Public License as published by
00010     the Free Software Foundation; either version 2 of the License, or
00011     (at your option) any later version.
00012 
00013     This program is distributed in the hope that it will be useful,
00014     but WITHOUT ANY WARRANTY; without even the implied warranty of
00015     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016     GNU General Public License for more details.
00017 
00018     You should have received a copy of the GNU General Public License
00019     along with this program; if not, write to the Free Software
00020     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021 
00022     Contact: todos@geneura.ugr.es, http://geneura.ugr.es
00023             
00024 */
00025 //-----------------------------------------------------------------------------
00026 
00027 #ifndef __GNUG__
00028 // to avoid long name warnings
00029 #pragma warning(disable:4786)
00030 #endif // __GNUG__
00031 
00032 #include <ga/eoBin.h>  // eoBin, eoPop, eoBreeder
00033 #include <eoPop.h>
00034 #include <ga/eoBitOp.h>
00035 
00036 #include <eoUniformSelect.h>
00037 #include <eoStochTournament.h>
00038 #include <eoDetTournament.h>
00039 
00040 
00041 //-----------------------------------------------------------------------------
00042 
00043 typedef eoBin<float> Chrom;
00044 
00045 #include "binary_value.h"
00046 
00047 //-----------------------------------------------------------------------------
00048 
00049 main()
00050 {
00051   const unsigned POP_SIZE = 8, CHROM_SIZE = 4;
00052   unsigned i;
00053 
00054   eoBinRandom<Chrom> random;
00055   eoPop<Chrom> pop; 
00056 
00057   // Create the population
00058   for (i = 0; i < POP_SIZE; ++i) {
00059     Chrom chrom(CHROM_SIZE);
00060     random(chrom);
00061     BinaryValue()(chrom);
00062     pop.push_back(chrom);
00063   }
00064   
00065   // print population
00066   std::cout << "population:" << std::endl;
00067   for (i = 0; i < pop.size(); ++i)
00068     std::cout << pop[i] << " " << pop[i].fitness() << std::endl;
00069 
00070   // Declare 1-selectors
00071   eoUniformSelect<Chrom> uSelect;
00072 
00073   Chrom aChrom;
00074   aChrom = uSelect( pop );
00075   std::cout << "Uniform Select " << aChrom << " " << aChrom.fitness() << std::endl;
00076 
00077   eoStochTournament<Chrom> sSelect(0.7);
00078   aChrom = sSelect( pop );
00079   std::cout << "Stochastic Tournament " << aChrom << " " << aChrom.fitness() << std::endl;
00080 
00081   eoDetTournament<Chrom> dSelect(3);
00082   aChrom = dSelect( pop );
00083   std::cout << "Deterministic Tournament " << aChrom << " " << aChrom.fitness() << std::endl;
00084 
00085   return 0;
00086 }
00087 
00088 //-----------------------------------------------------------------------------

Generated on Thu Oct 19 05:06:44 2006 for EO by  doxygen 1.3.9.1