Esempio n. 1
0
		bool initialize(StateP state)
		{		
			voidP lBound = state->getGenotypes()[0]->getParameterValue(state, "lbound");
			lbound = *((double*) lBound.get());

			voidP uBound = state->getGenotypes()[0]->getParameterValue(state, "ubound");
			ubound = *((double*) uBound.get());

			voidP dimension_ = state->getGenotypes()[0]->getParameterValue(state, "dimension");
			dimension = *((uint*) dimension_.get());

			voidP dup_ = getParameterValue(state, "dup");
			dup = *((uint*) dup_.get());
			if( *((int*) dup_.get()) <= 0 ) {
				ECF_LOG(state, 1, "Error: opt-IA requires parameter 'dup' to be an integer greater than 0");
				throw "";}

			voidP c_ = getParameterValue(state, "c");
			c = *((double*) c_.get());
			if( c <= 0 ) {
				ECF_LOG(state, 1, "Error: opt-IA requires parameter 'c' to be a double greater than 0");
				throw "";}

			voidP tauB_ = getParameterValue(state, "tauB");
			tauB = *((double*) tauB_.get());
			if( tauB < 0 ) {
				ECF_LOG(state, 1, "Error: opt-IA requires parameter 'tauB' to be a nonnegative double value");
				throw "";}

			voidP elitism_ = getParameterValue(state, "elitism");
			elitism = *((string*) elitism_.get());
			if( elitism != "true" && elitism != "false"  ) {
				ECF_LOG(state, 1,  "Error: opt-IA requires parameter 'elitism' to be either 'true' or 'false'");
				throw "";}


			// algorithm accepts a single FloatingPoint Genotype
			FloatingPointP flp (new FloatingPoint::FloatingPoint);
			if(state->getGenotypes()[0]->getName() != flp->getName()) {
				ECF_LOG_ERROR(state, "Error: opt-IA algorithm accepts only a FloatingPoint genotype!");
				throw ("");}

			// algorithm adds another FloatingPoint genotype (age)
			FloatingPointP flpoint[2];
			for(uint iGen = 1; iGen < 2; iGen++) {
				flpoint[iGen] = (FloatingPointP) new FloatingPoint::FloatingPoint;
				state->setGenotype(flpoint[iGen]);

				flpoint[iGen]->setParameterValue(state, "dimension", (voidP) new uint(1));					

				// initial value of age parameter should be (or as close as possible to) 0				
				flpoint[iGen]->setParameterValue(state, "lbound", (voidP) new double(0));
				flpoint[iGen]->setParameterValue(state, "ubound", (voidP) new double(0.01));
				
			}
			ECF_LOG(state, 1, "opt-IA algorithm: added 1 FloatingPoint genotype (antibody age)");
			
            return true;
		}
bool ArtificialBeeColony::initialize(StateP state)
{
	// initialize all operators
	selFitOp->initialize(state);
	selFitOp->setSelPressure(2);
	selBestOp->initialize(state);
	selWorstOp->initialize(state);
	selRandomOp->initialize(state);

	voidP sptr = state->getRegistry()->getEntry("population.size");
	uint size = *((uint*) sptr.get());
	probability_.resize(size);

	// this algorithm accepts a single FloatingPoint Genotype
	FloatingPointP flp (new FloatingPoint::FloatingPoint);
	if(state->getGenotypes()[0]->getName() != flp->getName()) {
		ECF_LOG_ERROR(state, "Error: ABC algorithm accepts only a single FloatingPoint genotype!");
		throw ("");
	}

	voidP limitp = getParameterValue(state, "limit");
	limit_ = *((uint*) limitp.get());

	voidP lBound = state->getGenotypes()[0]->getParameterValue(state, "lbound");
	lbound_ = *((double*) lBound.get());
	voidP uBound = state->getGenotypes()[0]->getParameterValue(state, "ubound");
	ubound_ = *((double*) uBound.get());

	// batch run check
	if(isTrialAdded_)
		return true;

	FloatingPointP flpoint[2];
	for(uint iGen = 1; iGen < 2; iGen++) {

		flpoint[iGen] = (FloatingPointP) new FloatingPoint::FloatingPoint;
		state->setGenotype(flpoint[iGen]);

		flpoint[iGen]->setParameterValue(state, "dimension", (voidP) new uint(1));					

		// initial value of trial parameter should be (as close as possible to) 0				
		flpoint[iGen]->setParameterValue(state, "lbound", (voidP) new double(0));
		flpoint[iGen]->setParameterValue(state, "ubound", (voidP) new double(0.01));
	}
	ECF_LOG(state, 1, "ABC algorithm: added 1 FloatingPoint genotype (trial)");

	// mark adding of trial genotype
	isTrialAdded_ = true;

    return true;
}
Esempio n. 3
0
bool Individual::initialize(StateP state)
{
	state_ = state;
	this->clear();

	// copy genotypes from State
	for(uint i = 0; i < state->getGenotypes().size(); i++) {
		this->push_back(static_cast<GenotypeP> (state->getGenotypes()[i]->copy()));
		(*this)[i]->setGenotypeId(i);
	}

	// init genotypes
	for(uint i = 0; i < this->size(); i++)
		(*this)[i]->initialize(state);

	return true;
}
bool DifferentialEvolution::initialize(StateP state)
{	
	selRandomOp->initialize(state);
	donor_vector.clear();

	// read parameters, check defined genotype (only a single FloatingPoint is allowed)
	voidP F = getParameterValue(state, "F");
	Fconst_ = *((double*) F.get());
	voidP CR = getParameterValue(state, "CR");
	CR_ = *((double*) CR.get());
	FloatingPointP flp (new FloatingPoint::FloatingPoint);
	if(state->getGenotypes()[0]->getName() != flp->getName() || state->getGenotypes().size() != 1) {
		state->getLogger()->log(1, "Error: DE algorithm accepts only a single FloatingPoint genotype!");
		throw ("");
	}

	return true;
}
        bool initialize(StateP state)
		{		
			// initialize all operators
			selFitOp->initialize(state);
			selBestOp->initialize(state);
			selRandomOp->initialize(state);
			
			voidP limit_ = getParameterValue(state, "limit");
			limit = *((uint*) limit_.get());

			voidP lBound = state->getGenotypes()[0]->getParameterValue(state, "lbound");
			lbound = *((double*) lBound.get());
			voidP uBound = state->getGenotypes()[0]->getParameterValue(state, "ubound");
			ubound = *((double*) uBound.get());

		// algorithm accepts a single FloatingPoint Genotype
			FloatingPointP flp (new FloatingPoint::FloatingPoint);
			if(state->getGenotypes()[0]->getName() != flp->getName()) {
				ECF_LOG_ERROR(state, "Error: ABC algorithm accepts only a FloatingPoint genotype!");
				throw ("");
			}

			FloatingPointP flpoint[2];
			for(uint iGen = 1; iGen < 2; iGen++) {

				flpoint[iGen] = (FloatingPointP) new FloatingPoint::FloatingPoint;
				state->setGenotype(flpoint[iGen]);

				flpoint[iGen]->setParameterValue(state, "dimension", (voidP) new uint(1));					

				// initial value of trial parameter should be (as close as possible to) 0				
				flpoint[iGen]->setParameterValue(state, "lbound", (voidP) new double(0));
				flpoint[iGen]->setParameterValue(state, "ubound", (voidP) new double(0.01));
				
			}
			ECF_LOG(state, 1, "ABC algorithm: added 1 FloatingPoint genotype (trial)");
 
            return true;
        }
bool PSOInheritance::initialize(StateP state)
{
	// initialize all operators
	selBestOp->initialize(state);

	voidP weightType = getParameterValue(state, "weightType");
	m_weightType = *((InertiaWeightType*) weightType.get());

	voidP weight = getParameterValue(state, "weight");
	m_weight = *((double*) weight.get());

	voidP maxV = getParameterValue(state, "maxVelocity");
	m_maxV = *((double*) maxV.get());

	// test if inertia weight type is time variant and if so, check if max iterations specified
	if(m_weightType == TIME_VARIANT) {
		if(state->getRegistry()->isModified("term.maxgen")) {
			// read maxgen parameter
			m_maxIter = *(boost::static_pointer_cast<int>( state->getRegistry()->getEntry("term.maxgen") ));
		}
		else {
			ECF_LOG_ERROR(state, "Error: term.maxgen has to be specified in order to use time variant inertia eight in PSO algorithm");
			throw("");
		}
	}

	// algorithm accepts a single FloatingPoint Genotype
	FloatingPointP flp (new FloatingPoint::FloatingPoint);
	if(state->getGenotypes()[0]->getName() != flp->getName()) {
		ECF_LOG_ERROR(state, "Error: PSO algorithm accepts only a single FloatingPoint genotype!");
		throw ("");
	}

	voidP sptr = state->getGenotypes()[0]->getParameterValue(state, "dimension");
	uint numDimension = *((uint*) sptr.get());

	voidP bounded = getParameterValue(state, "bounded");
	bounded_ = *((bool*) bounded.get());

	sptr = state->getGenotypes()[0]->getParameterValue(state, "lbound");
	lbound_ = *((double*) sptr.get());

	sptr = state->getGenotypes()[0]->getParameterValue(state, "ubound");
	ubound_ = *((double*) sptr.get());

	// batch run check
	if(areGenotypesAdded_)
		return true;

	FloatingPointP flpoint[4];
	for(uint iGen = 1; iGen < 4; iGen++) {

		flpoint[iGen] = (FloatingPointP) new FloatingPoint::FloatingPoint;
		state->setGenotype(flpoint[iGen]);

		if(iGen == 3)
			flpoint[iGen]->setParameterValue(state, "dimension", (voidP) new uint(1));
		else
			flpoint[iGen]->setParameterValue(state, "dimension", (voidP) new uint(numDimension));

		// other parameters are proprietary (ignored by the algorithm)
		flpoint[iGen]->setParameterValue(state, "lbound", (voidP) new double(0));
		flpoint[iGen]->setParameterValue(state, "ubound", (voidP) new double(1));
	}
	ECF_LOG(state, 1, "PSO algorithm: added 3 FloatingPoint genotypes (particle velocity, best-so-far postition, best-so-far fitness value)");

	// mark adding of genotypes
	areGenotypesAdded_ = true;

	return true;
}