这是linux下的进化计算的源代码。 === === === === === === === === === === === ===== check latest news at http:

源代码在线查看: t-eobin.cpp

软件大小: 1452 K
上传用户: dragoncircle
关键词: latest linux check http
下载地址: 免注册下载 普通下载 VIP

相关代码

				/* -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-								    t-eobin.cpp				      This program tests the the binary cromosomes and several genetic operators				    (c) GeNeura Team, 1999								    This program is free software; you can redistribute it and/or modify				    it under the terms of the GNU General Public License as published by				    the Free Software Foundation; either version 2 of the License, or				    (at your option) any later version.								    This program is distributed in the hope that it will be useful,				    but WITHOUT ANY WARRANTY; without even the implied warranty of				    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the				    GNU General Public License for more details.								    You should have received a copy of the GNU General Public License				    along with this program; if not, write to the Free Software				    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA								    Contact: todos@geneura.ugr.es, http://geneura.ugr.es								*/				//-----------------------------------------------------------------------------				#ifdef HAVE_CONFIG_H				#include 				#endif								#include    // std::cout				#include 								#include          // general EO				#include 	      // bitstring representation & operators				#include 				#include "binary_value.h"								//-----------------------------------------------------------------------------								typedef eoBit Chrom;								//-----------------------------------------------------------------------------								void main_function()				{				  const unsigned SIZE = 8;				  unsigned i, j;				  eoBooleanGenerator gen;								  Chrom chrom(SIZE), chrom2;				  chrom.fitness(binary_value(chrom)); chrom2.fitness(binary_value(chrom2));								  std::cout 				  chrom[0] = chrom[SIZE - 1] = true; chrom.fitness(binary_value(chrom));				  std::cout 				  chrom[0] = chrom[SIZE - 1] = false; chrom.fitness(binary_value(chrom));				  std::cout 				  chrom[0] = chrom[SIZE - 1] = true; chrom.fitness(binary_value(chrom));								  std::cout 								  std::cout 				       								  std::ostringstream os;				  os 				  std::istringstream is(os.str());				  is >> chrom2; chrom.fitness(binary_value(chrom2));								  std::cout 				  std::cout 								  std::fill(chrom.begin(), chrom.end(), false);				  std::cout 				       								  eoInitFixedLength				      random(chrom.size(), gen);								  random(chrom); chrom.fitness(binary_value(chrom));				  std::cout 								  eoOneBitFlip bitflip;				  bitflip(chrom); chrom.fitness(binary_value(chrom));				  std::cout 								  eoBitMutation mutation(0.5);				  mutation(chrom); chrom.fitness(binary_value(chrom));				  std::cout 								  eoBitInversion inversion;				  inversion(chrom); chrom.fitness(binary_value(chrom));				  std::cout 								  eoBitNext next;				  next(chrom); chrom.fitness(binary_value(chrom));				  std::cout 								  eoBitPrev prev;				  prev(chrom); chrom.fitness(binary_value(chrom));				  std::cout 								  std::fill(chrom.begin(), chrom.end(), false); chrom.fitness(binary_value(chrom));				  std::fill(chrom2.begin(), chrom2.end(), true); chrom2.fitness(binary_value(chrom2));				  std::cout 				       				       								  eo1PtBitXover xover;				  std::fill(chrom.begin(), chrom.end(), false);				  std::fill(chrom2.begin(), chrom2.end(), true);				  xover(chrom, chrom2);				  chrom.fitness(binary_value(chrom)); chrom2.fitness(binary_value(chrom2));				  std::cout 								  for (i = 1; i < SIZE; i++)				    {				      eoNPtsBitXover nxover(i);				      std::fill(chrom.begin(), chrom.end(), false);				      std::fill(chrom2.begin(), chrom2.end(), true);				      nxover(chrom, chrom2);				      chrom.fitness(binary_value(chrom)); chrom2.fitness(binary_value(chrom2));				      std::cout 					   				    }								  for (i = 1; i < SIZE / 2; i++)				    for (j = 1; j < SIZE / 2; j++)				      {					eoBitGxOver gxover(i, j);					std::fill(chrom.begin(), chrom.end(), false);					std::fill(chrom2.begin(), chrom2.end(), true);					gxover(chrom, chrom2);					chrom.fitness(binary_value(chrom)); chrom2.fitness(binary_value(chrom2));					std::cout  					      				      }								    // test SGA algorithm				    eoGenContinue continuator1(50);				    eoFitContinue continuator2(65535.f);								    eoCombinedContinue continuator(continuator1, continuator2);								    eoCheckPoint checkpoint(continuator);								    eoStdoutMonitor monitor;								    checkpoint.add(monitor);								    eoSecondMomentStats stats;								    monitor.add(stats);				    checkpoint.add(stats);								    eoProportionalSelect select;				    eoEvalFuncPtr  eval(binary_value);								    eoSGA sga(select, xover, 0.8f, bitflip, 0.1f, eval, checkpoint);								    eoInitFixedLength init(16, gen);				    eoPop pop(100, init);								    apply(eval, pop);								    sga(pop);								    pop.sort();								    std::cout 								    std::cout 								  /*								    Commented this out, waiting for a definite decision what to do with the mOp's								    // Check multiOps				    eoMultiMonOp mOp( &next );				    mOp.adOp( &bitflip );				    std::cout 				    mOp( chrom );				    std::cout 								    eoBinGxOver gxover(2, 4);				    eoMultiBinOp mbOp( &gxover );				    mOp.adOp( &bitflip );				    std::cout 				    mbOp( chrom, chrom2 );				    std::cout 				  */				}								//-----------------------------------------------------------------------------				// For MSVC memory lead detection				#ifdef _MSC_VER				#include 				#endif								int main()				{				#ifdef _MSC_VER				  //  rng.reseed(42);				    int flag = _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF);				     flag |= _CRTDBG_LEAK_CHECK_DF;				    _CrtSetDbgFlag(flag);				//   _CrtSetBreakAlloc(100);				#endif								    try				    {				        main_function();				    }				    catch(std::exception& e)				    {				        std::cout 				    }								}							

相关资源