/*! * \brief Initialize ES individual with initial strategy parameter. * \param outIndividual Individual to initialize. * \param ioContext Evolution context. * * Size of ES individual is given by integer vector "es.init.vectorsize". Initial strategy * parameter value of ES pair is given by parameter "es.init.strategy". Initial value of ES pair * is given using random numbers following a Gaussian distribution of zero mean and standard * deviation equal to initial strategy parameter value. */ void GA::InitQRESVecOp::initIndividual(Beagle::Individual& outIndividual, Context& ioContext) { Beagle_StackTraceBeginM(); #ifndef BEAGLE_NDEBUG if(mESVectorSize->getWrappedValue() == 0) { std::string lMessage = "GA::InitQRESVecOp::initIndividual: "; lMessage += "ES vector size parameter is zero; "; lMessage += "could not initialize the individuals!"; throw Beagle_RunTimeExceptionM(lMessage); } #endif // BEAGLE_NDEBUG const Factory& lFactory = ioContext.getSystem().getFactory(); GA::ESVector::Alloc::Handle lESVectorAlloc = castHandleT<GA::ESVector::Alloc>(lFactory.getConceptAllocator("Genotype")); GA::ESVector::Handle lESVector = castHandleT<GA::ESVector>(lESVectorAlloc->allocate()); lESVector->resize(mESVectorSize->getWrappedValue()); outIndividual.clear(); outIndividual.push_back(lESVector); Vector lQRValues(mESVectorSize->getWrappedValue()+1); QuasiRandom::Handle lQRComponent = castHandleT<QuasiRandom>(ioContext.getSystem().getComponent("QuasiRandom")); lQRComponent->getUniformVector(lQRValues); Beagle_AssertM((mESVectorSize->getWrappedValue()+1) == lQRValues.size()); const double lInitStrategy = mInitStrategyValue->getWrappedValue(); for(unsigned int j=0; j<lESVector->size(); ++j) { const double lMaxVal = j<mMaxValue->size() ? (*mMaxValue)[j] : mMaxValue->back(); const double lMinVal = j<mMinValue->size() ? (*mMinValue)[j] : mMinValue->back(); (*lESVector)[j].mValue = (lQRValues[j] * lInitStrategy); if((*lESVector)[j].mValue > lMaxVal) (*lESVector)[j].mValue = lMaxVal; if((*lESVector)[j].mValue < lMinVal) (*lESVector)[j].mValue = lMinVal; (*lESVector)[j].mStrategy = lInitStrategy; } Beagle_LogDebugM( ioContext.getSystem().getLogger(), "initialization", "Beagle::GA::InitQRESVecOp", "ES vector is initialized as" ); Beagle_LogObjectDebugM( ioContext.getSystem().getLogger(), "initialization", "Beagle::GA::InitQRESVecOp", *lESVector ); Beagle_StackTraceEndM("void GA::InitQRESVecOp::initIndividual(Beagle::Individual& outIndividual, Context& ioContext)"); }
/*! * \brief Initialize real-valued individual with derandomized Gaussian values. * \param outIndividual Individual to initialize. * \param ioContext Evolution context. */ void FltVec::InitGaussianQROp::initIndividual(Beagle::Individual& outIndividual, Context& ioContext) { Beagle_StackTraceBeginM(); #ifndef BEAGLE_NDEBUG if(mFloatVectorSize->getWrappedValue() == 0) { string lMessage = "FltVec::InitGaussianQROp::initIndividual: "; lMessage += "float vector size parameter is zero; "; lMessage += "could not initialize the individuals!"; throw Beagle_RunTimeExceptionM(lMessage); } #endif // BEAGLE_NDEBUG const Factory& lFactory = ioContext.getSystem().getFactory(); FltVec::FloatVector::Alloc::Handle lVectorAlloc = castHandleT<FltVec::FloatVector::Alloc>(lFactory.getConceptAllocator("Genotype")); FltVec::FloatVector::Handle lVector = castHandleT<FltVec::FloatVector>(lVectorAlloc->allocate()); lVector->resize(mFloatVectorSize->getWrappedValue()); outIndividual.clear(); outIndividual.push_back(lVector); QuasiRandom::Handle lQRComponent = castHandleT<QuasiRandom>(ioContext.getSystem().getComponent("QuasiRandom")); Vector lQRValues(lVector->size()); lQRComponent->getGaussianVector(lQRValues); Beagle_AssertM(mFloatVectorSize->getWrappedValue() == lQRValues.size()); for(unsigned int j=0; j<lVector->size(); ++j) { const double lMaxVal = j<mMaxInitValue->size() ? (*mMaxInitValue)[j] : mMaxInitValue->back(); const double lMinVal = j<mMinInitValue->size() ? (*mMinInitValue)[j] : mMinInitValue->back(); const double lIncVal = j<mIncValue->size() ? (*mIncValue)[j] : mIncValue->back(); const double lMean = j<mMean->size() ? (*mMean)[j] : mMean->back(); const double lStdev = j<mStdev->size() ? (*mStdev)[j] : mStdev->back(); (*lVector)[j] = (lQRValues[j] * lStdev) + lMean; if((*lVector)[j] > lMaxVal) (*lVector)[j] = lMaxVal; if((*lVector)[j] < lMinVal) (*lVector)[j] = lMinVal; if(std::fabs(lIncVal)>1e-12) { (*lVector)[j] = lIncVal * round((*lVector)[j] / lIncVal); if((*lVector)[j] > lMaxVal) (*lVector)[j] -= lIncVal; if((*lVector)[j] < lMinVal) (*lVector)[j] += lIncVal; } } Beagle_LogDebugM( ioContext.getSystem().getLogger(), *lVector ); Beagle_StackTraceEndM(); }
/*! * \brief Initialize real-valued GA individual with numbers uniformly distributed in a given range. * \param outIndividual Individual to initialize. * \param ioContext Evolution context. */ void GA::InitFltVecOp::initIndividual(Beagle::Individual& outIndividual, Context& ioContext) { Beagle_StackTraceBeginM(); #ifndef BEAGLE_NDEBUG if(mFloatVectorSize->getWrappedValue() == 0) { string lMessage = "GA::InitFltVecOp::initIndividual: "; lMessage += "float vector size parameter is zero; "; lMessage += "could not initialize the individuals!"; throw Beagle_RunTimeExceptionM(lMessage); } #endif // BEAGLE_NDEBUG const Factory& lFactory = ioContext.getSystem().getFactory(); GA::FloatVector::Alloc::Handle lFloatVectorAlloc = castHandleT<GA::FloatVector::Alloc>(lFactory.getConceptAllocator("Genotype")); GA::FloatVector::Handle lFloatVector = castHandleT<GA::FloatVector>(lFloatVectorAlloc->allocate()); lFloatVector->resize(mFloatVectorSize->getWrappedValue()); outIndividual.clear(); outIndividual.push_back(lFloatVector); for(unsigned int j=0; j<lFloatVector->size(); ++j) { const double lMaxVal = j<mMaxInitValue->size() ? (*mMaxInitValue)[j] : mMaxInitValue->back(); const double lMinVal = j<mMinInitValue->size() ? (*mMinInitValue)[j] : mMinInitValue->back(); const double lIncVal = j<mIncValue->size() ? (*mIncValue)[j] : mIncValue->back(); (*lFloatVector)[j] = ioContext.getSystem().getRandomizer().rollUniform(lMinVal,lMaxVal); if(std::fabs(lIncVal)>1e-12) { (*lFloatVector)[j] = lIncVal * round((*lFloatVector)[j] / lIncVal); if((*lFloatVector)[j] > lMaxVal) (*lFloatVector)[j] = lMaxVal; if((*lFloatVector)[j] < lMinVal) (*lFloatVector)[j] = lMinVal; } } Beagle_LogDebugM( ioContext.getSystem().getLogger(), "initialization", "Beagle::GA::InitFltVecOp", string("Float vector initialized as") ); Beagle_LogObjectDebugM( ioContext.getSystem().getLogger(), "initialization", "Beagle::GA::InitFltVecOp", *lFloatVector ); Beagle_StackTraceEndM("void GA::InitFltVecOp::initIndividual(Beagle::Individual& outIndividual, Context& ioContext)"); }
/*! * \brief Initialize integer-valued GA individual with numbers uniformly distributed in a given range. * \param outIndividual Individual to initialize. * \param ioContext Evolution context. */ void GA::InitIntVecOp::initIndividual(Beagle::Individual& outIndividual, Context& ioContext) { Beagle_StackTraceBeginM(); #ifndef BEAGLE_NDEBUG if(mIntVectorSize->getWrappedValue() == 0) { string lMessage = "GA::InitIntVecOp::initIndividual: "; lMessage += "integer vector size parameter is zero; "; lMessage += "could not initialize the individuals!"; throw Beagle_RunTimeExceptionM(lMessage); } #endif // BEAGLE_NDEBUG const Factory& lFactory = ioContext.getSystem().getFactory(); GA::IntegerVector::Alloc::Handle lIntegerVectorAlloc = castHandleT<GA::IntegerVector::Alloc>(lFactory.getConceptAllocator("Genotype")); GA::IntegerVector::Handle lIntegerVector = castHandleT<GA::IntegerVector>(lIntegerVectorAlloc->allocate()); lIntegerVector->resize(mIntVectorSize->getWrappedValue()); outIndividual.clear(); outIndividual.push_back(lIntegerVector); for(unsigned int j=0; j<lIntegerVector->size(); ++j) { const int lMaxVal = j<mMaxInitValue->size() ? (*mMaxInitValue)[j] : mMaxInitValue->back(); const int lMinVal = j<mMinInitValue->size() ? (*mMinInitValue)[j] : mMinInitValue->back(); Beagle_AssertM(lMaxVal >= lMinVal); const int lRandVal = (int)ioContext.getSystem().getRandomizer().rollInteger(0,lMaxVal-lMinVal); (*lIntegerVector)[j] = (lRandVal+lMinVal); } Beagle_LogDebugM( ioContext.getSystem().getLogger(), "initialization", "Beagle::GA::InitIntVecOp", "Integer vector initialized as" ); Beagle_LogObjectDebugM( ioContext.getSystem().getLogger(), "initialization", "Beagle::GA::InitIntVecOp", *lIntegerVector ); Beagle_StackTraceEndM("void GA::InitIntVecOp::initIndividual(Beagle::Individual& outIndividual, Context& ioContext)"); }