⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 eval.cc

📁 用C++编写的遗传算法
💻 CC
字号:
// eval.cc/* -------------------------------------------------------------------gpc++ - The Genetic Programming KernelThis program is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 1, or (at your option)any later version.This program is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public Licensealong with this program; if not, write to the Free SoftwareFoundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.Copyright 1993, 1994 Adam P. Fraser and 1996, 1997 Thomas WeinbrennerFor comments, improvements, additions (or even money) contact:Thomas WeinbrennerGrauensteinstr. 2635789 LaimbachGermanyE-mail: thomasw@emk.e-technik.th-darmstadt.deWWW:    http://www.emk.e-technik.th-darmstadt/~thomasw  or (Address may be out of date)Adam Fraser, Postgraduate Section, Dept of Elec & Elec Eng,Maxwell Building, University Of Salford, Salford, M5 4WT, United Kingdom.E-mail: a.fraser@eee.salford.ac.ukTel:    (UK) 061 745 5000 x3633Fax:    (UK) 061 745 5999------------------------------------------------------------------- */#include "gp.h"// This function is called after a new generation has been created.// It is alsso called after each new generation has been evolved using// crossover, creation or reproduction, but only if steady state is// not used.  It loops throupgh the population and evaluates the// fitness of each genetic program.void GPPopulation::evaluate (){  // loop through whole population evaluating every GP  for (int n=0; n<containerSize(); n++)    {      GP* current=NthGP (n);#if GPINTERNALCHECK      if (!current)	GPExitSystem ("GPPopulation::evaluate", 		      "Member of population is NULL");#endif      // If the evaluation is still valid, don't evaluate it again      if (!current->fitnessValid)	{	  // Evaluate genetic program	  current->evaluate ();	  current->fitnessValid=1;	}    }}// Evaluation for a genetic program.  The user must provide for this// function!  We don't know how to do this.  The user should inherit// the GP class and rewrite this function.  He should then put the// result of the evaluation into the class variable stdFitness.void GP::evaluate (){  stdFitness=0.0;#if GPINTERNALCHECK  GPExitSystem ("GP::Evaluate", 		"Can't evaluate program, user must so this"); #endif}// Evaluation for a gene.  We don't define this function in the// kernel!  Anyway, we don't know how to evaluate a gene.  Another// reason is that the return value may be anything from int, double,// or a class variable.  We allow for maximum user freedom.#ifdef PURPOSELY_NOT_DEFINEDdouble GPGene::evaluate (){  GPExitSystem ("GPGene::Evaluate", 		"Can't evaluate gene, user must so this"); }#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -