/* * 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/src/TermMaxGenOp.cpp * \brief Source code of class TermMaxGenOp. * \author Christian Gagne * \author Marc Parizeau * $Revision: 1.9 $ * $Date: 2005/10/04 16:25:10 $ */ #include "beagle/Beagle.hpp" using namespace Beagle; /*! * \brief Construct a termination check operator based on a maximum generation value. * \param inName Name of the operator. */ TermMaxGenOp::TermMaxGenOp(Beagle::string inName) : TerminationOp(inName) { } /*! * \brief Initialize the maximum generation termination operator. * \param ioSystem System to use to initialize the operator. */ void TermMaxGenOp::initialize(System& ioSystem) { Beagle_StackTraceBeginM(); if(ioSystem.getRegister().isRegistered("ec.term.maxgen")) { mMaxGeneration = castHandleT(ioSystem.getRegister().getEntry("ec.term.maxgen")); } else { mMaxGeneration = new UInt(50); string lLongDescrip = "Maximum number of generations for the evolution. "; lLongDescrip += "A zero value means that there is no generation limit."; Register::Description lDescription( "Max generation term criterion", "UInt", "50", lLongDescrip ); ioSystem.getRegister().addEntry("ec.term.maxgen", mMaxGeneration, lDescription); } Beagle_StackTraceEndM("void TermMaxGenOp::initialize(System& ioSystem)"); } /*! * \brief Check if the maximum number of generation is reached. * \param inDeme Actual deme of the evolution. * \param ioContext Actual evolution context. * \return True if the ending criterion is reached, false if not. */ bool TermMaxGenOp::terminate(const Deme& inDeme, Context& ioContext) { Beagle_StackTraceBeginM(); if(mMaxGeneration->getWrappedValue() == 0) return false; if(ioContext.getGeneration() > mMaxGeneration->getWrappedValue()) { Beagle_LogInfoM( ioContext.getSystem().getLogger(), "termination", "Beagle::TermMaxGenOp", string("Maximum number of generations (") + uint2str(mMaxGeneration->getWrappedValue()) + string(") termination criterion overpassed") ); Beagle_LogDetailedM( ioContext.getSystem().getLogger(), "termination", "Beagle::TermMaxGenOp", string("Actual generation number is: ")+uint2str(ioContext.getGeneration()) ); return true; } if((ioContext.getGeneration() == mMaxGeneration->getWrappedValue()) && (ioContext.getDemeIndex() == (ioContext.getVivarium().size()-1))) { Beagle_LogInfoM( ioContext.getSystem().getLogger(), "termination", "Beagle::TermMaxGenOp", string("Maximum number of generations (") + uint2str(mMaxGeneration->getWrappedValue()) + string(") termination criterion reached") ); return true; } Beagle_LogTraceM( ioContext.getSystem().getLogger(), "termination", "Beagle::TermMaxGenOp", string("Maximum number of generations (") + uint2str(mMaxGeneration->getWrappedValue()) + string(") termination criterion not reached ") ); return false; Beagle_StackTraceEndM("bool TermMaxGenOp::terminate(const Deme& inDeme, Context& ioContext)"); }