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

📄 initfullop.cpp

📁 非常好的进化算法EC 实现平台 可以实现多种算法 GA GP
💻 CPP
字号:
/* *  Open BEAGLE *  Copyright (C) 2001-2005 by Christian Gagne and Marc Parizeau * *  This library is free software; you can redistribute it and/or *  modify it under the terms of the GNU Lesser General Public *  License as published by the Free Software Foundation; either *  version 2.1 of the License, or (at your option) any later version. * *  This library 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 *  Lesser General Public License for more details. * *  You should have received a copy of the GNU Lesser General Public *  License along with this library; if not, write to the Free Software *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA * *  Contact: *  Laboratoire de Vision et Systemes Numeriques *  Departement de genie electrique et de genie informatique *  Universite Laval, Quebec, Canada, G1K 7P4 *  http://vision.gel.ulaval.ca * *//*! *  \file   beagle/GP/src/InitFullOp.cpp *  \brief  Source code of class GP::InitFullOp. *  \author Christian Gagne *  \author Marc Parizeau *  $Revision: 1.20 $ *  $Date: 2005/10/04 16:25:10 $ */#include "beagle/GP.hpp"#include <sstream>using namespace Beagle;/*! *  \brief Construct a GP "full" intialization operator. *  \param inReproProbaName Reproduction probability parameter name used in register.  *  \param inName Name of the operator. */GP::InitFullOp::InitFullOp(Beagle::string inReproProbaName, Beagle::string inName) :  Beagle::GP::InitializationOp(inReproProbaName, inName){ }/*! *  \brief Initialize a GP sub-tree of a specified depth using the "full" approach. *  \param ioTree Tree containing the sub-tree to initialize. *  \param inSubTreeDepth Depth of the sub-tree to initialize. *  \param ioContext Evolutionary context. *  \return Generated sub-tree size. */unsigned int GP::InitFullOp::initSubTreeFull(GP::Tree& ioTree,                                             unsigned int inSubTreeDepth,                                             GP::Context& ioContext) const{  Beagle_StackTraceBeginM();  Beagle_AssertM(inSubTreeDepth>0);  GP::PrimitiveSet& lPrimitSet = ioTree.getPrimitiveSet(ioContext);  GP::Primitive::Handle lPrimit = NULL;  if(inSubTreeDepth == 1) {    lPrimit = lPrimitSet.select(GP::Primitive::eTerminal, ioContext);    if(!lPrimit) {      string lMessage = "There is no leaf (primitive without argument) in the ";      lMessage += uint2ordinal(ioTree.getPrimitiveSetIndex()+1);      lMessage += " primitive set!";      throw Beagle_RunTimeExceptionM(lMessage);    }    lPrimit = lPrimit->giveReference(GP::Primitive::eTerminal, ioContext);  }  else {    lPrimit = lPrimitSet.select(GP::Primitive::eBranch, ioContext);    if(!lPrimit) {      string lMessage = "There is no branch (primitive with arguments) in the ";      lMessage += uint2ordinal(ioTree.getPrimitiveSetIndex()+1);      lMessage += " primitive set!";      throw Beagle_RunTimeExceptionM(lMessage);    }    lPrimit = lPrimit->giveReference(GP::Primitive::eBranch, ioContext);  }  unsigned int lNodeIndex = ioTree.size();  ioTree.push_back(GP::Node(lPrimit,0));  unsigned int lSubTreeSize = 1;  for(unsigned int i=0; i<ioTree[lNodeIndex].mPrimitive->getNumberArguments(); i++) {    lSubTreeSize += initSubTreeFull(ioTree, inSubTreeDepth-1, ioContext);  }  ioTree[lNodeIndex].mSubTreeSize = lSubTreeSize;  return lSubTreeSize;  Beagle_StackTraceEndM("unsigned int GP::InitFullOp::initSubTreeFull(GP::Tree& ioTree, unsigned int inSubTreeDepth, GP::Context& ioContext) const");}/*! *  \brief Initialize a tree. *  \param outTree Tree to initialize. *  \param inMinDepth Minimum depth to make tree. *  \param inMaxDepth Maximum depth to make tree. *  \param ioContext Evolution context. */unsigned int GP::InitFullOp::initTree(GP::Tree& outTree,                                      unsigned int inMinDepth,                                      unsigned int inMaxDepth,                                      GP::Context &ioContext) const{  Beagle_StackTraceBeginM();  Beagle_AssertM(inMaxDepth >= inMinDepth);  Beagle_AssertM(inMinDepth > 0);  const unsigned int lDepth =     ioContext.getSystem().getRandomizer().rollInteger(inMinDepth, inMaxDepth);  Beagle_LogVerboseM(    ioContext.getSystem().getLogger(),    "initialization", "Beagle::GP::InitFullOp",    string("Using the \'full\' method (with depth ")+    uint2str(lDepth)+string(") to initialize the ")+    uint2ordinal(ioContext.getGenotypeIndex()+1)+string(" tree.")  );  Beagle_AssertM(lDepth>0);  outTree.resize(0);  ioContext.emptyCallStack();  return initSubTreeFull(outTree, lDepth, ioContext);  Beagle_StackTraceEndM("unsigned int GP::InitFullOp::initTree(GP::Tree& outTree, unsigned int inMinDepth, unsigned int inMaxDepth, GP::Context &ioContext) const");}

⌨️ 快捷键说明

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