/*!
 *  \brief Register the parameters of the constrained GP tree "grow" intialization operator.
 *  \param ioSystem System of the evolution.
 */
void GP::InitGrowOp::registerParams(Beagle::System& ioSystem)
{
	Beagle_StackTraceBeginM();
	GP::InitializationOp::registerParams(ioSystem);
	{
		Register::Description lDescription(
		    "Flag for whether the 'grow' method works as defined by Koza",
		    "Bool",
		    "0",
		    "Set this flag if you wish to initialize individuals using the 'grow' method as defined by Koza in GPI (and as used in GPII, GPIII, and probably GPIV---although it is not made entirely clear).  If this flag is set to true then individuals are grown with a minimum depth of 2.  If this flag is set to false then the minimum depth of individuals is paired to the register variable 'gp.init.mindepth'.  Irrespective of this flag, maximum depth of individuals will range according to the values of 'gp.init.mindepth' and 'gp.init.maxdepth'; note that if you wish to entirely replicate Koza's method then mindepth and maxdepth should be set to the same value."
		);
		mKozaGrow = castHandleT<Bool>
		            (ioSystem.getRegister().insertEntry("gp.init.kozagrow", new Bool(false), lDescription));
	}

	Beagle_StackTraceEndM("void GP::InitGrowOp::registerParams(Beagle::System&)");
}
/*!
 *  \brief Register the parameters of the constrained GP tree swap mutation operator.
 *  \param ioSystem System of the evolution.
 */
void STGP::MutationSwapConstrainedOp::registerParams(Beagle::System& ioSystem)
{
	Beagle_StackTraceBeginM();
	MutationSwapOp::registerParams(ioSystem);
	std::ostringstream lOSS;
	lOSS << "Maximum number of attempts to modify a GP tree in a genetic ";
	lOSS << "operation. As there is topological constraints on GP trees (i.e. tree ";
	lOSS << "depth limit), it is often necessary to try a genetic operation several times.";
	Register::Description lDescription(
	    "Max number of attempts",
	    "UInt",
	    "2",
	    lOSS.str()
	);
	mNumberAttempts = castHandleT<UInt>(
	                      ioSystem.getRegister().insertEntry("gp.try", new UInt(2), lDescription));
	Beagle_StackTraceEndM();
}
/*!
 *  \brief Register the parameters of this operator.
 *  \param ioSystem System used to initialize the operator.
 */
void GP::TermMaxHitsOp::registerParams(Beagle::System& ioSystem)
{
	Beagle_StackTraceBeginM();
	TerminationOp::registerParams(ioSystem);
	std::ostringstream lOSS;
	lOSS << "Number of hits required in an individual ";
	lOSS << "in order for the evolution process to terminate. ";
	lOSS << "If 0, termination criteria is ignored.";
	Register::Description lDescription(
	    "Max hits term criterion",
	    "UInt",
	    uint2str(mMaxHitsDefault),
	    lOSS.str()
	);
	mMaxHits = castHandleT<UInt>(
	               ioSystem.getRegister().insertEntry("gp.term.maxhits", new UInt(mMaxHitsDefault), lDescription));
	Beagle_StackTraceEndM("void GP::TermMaxHitsOp::registerParams(Beagle::System&)");
}
/*!
 *  \brief Read a primitive super set from a XML subtree.
 *  \param inIter XML iterator used to read the super set from.
 *  \param ioSystem Evolutionary system.
 *  \throw Beagle::IOException If size atribute not present.
 */
void GP::PrimitiveSuperSet::readWithSystem(PACC::XML::ConstIterator inIter, Beagle::System& ioSystem)
{
	Beagle_StackTraceBeginM();
	if((inIter->getType()!=PACC::XML::eData) || (inIter->getValue()!="GP-PrimitiveSuperSet"))
		throw Beagle_IOExceptionNodeM(*inIter, "tag <GP-PrimitiveSuperSet> expected!");
	const Factory& lFactory = ioSystem.getFactory();
	Context::Alloc::Handle lContextAlloc =
	    castHandleT<Context::Alloc>(lFactory.getConceptAllocator("Context"));
	GP::Context::Handle lGPContext =
	    castHandleT<GP::Context>(lContextAlloc->allocate());
	lGPContext->setSystemHandle(System::Handle(&ioSystem));
	GP::PrimitiveSet::Alloc::Handle lPrimitSetsAlloc =
		castHandleT<GP::PrimitiveSet::Alloc>(lFactory.getConceptAllocator("GP-PrimitiveSet"));
	mPrimitSets.clear();
	for(PACC::XML::ConstIterator lChild=inIter->getFirstChild(); lChild; ++lChild) {
		if((lChild->getType()==PACC::XML::eData) && (lChild->getValue()=="GP-PrimitiveSet")) {
			GP::PrimitiveSet::Handle lPrimitSet =
				castHandleT<GP::PrimitiveSet>(lPrimitSetsAlloc->allocate());
			lPrimitSet->readWithContext(lChild, *lGPContext);
			mPrimitSets.push_back(lPrimitSet);
		}
	}
	Beagle_StackTraceEndM("void GP::PrimitiveSuperSet::readWithSystem(PACC::XML::ConstIterator inIter, Beagle::System& ioSystem)");
}
/*!
 *  \brief Register the parameters of this operator.
 *  \param ioSystem System of the evolution.
 */
void GP::MutationSwapSubtreeOp::registerParams(Beagle::System& ioSystem)
{
	Beagle_StackTraceBeginM();

	{
		std::ostringstream lOSS;
		lOSS << "Swap subtree mutation probability for an individual. ";
		lOSS << "A swap subtree mutation consists to swap two subtrees of a tree in an ";
		lOSS << "individual.";
		Register::Description lProbaDescription(
		    "Swap subtree mutation prob.",
		    "Double",
		    "0.0",
		    lOSS.str()
		);
		mMutationProba = castHandleT<Double>(
		                     ioSystem.getRegister().insertEntry(mMutationPbName, new Double(0.0f), lProbaDescription));
	}
	Beagle::MutationOp::registerParams(ioSystem);
	{
		std::ostringstream lOSS;
		lOSS << "Probability that a swap subtree is internal ";
		lOSS << "(the mutation occurs between three points, where the 2nd point is in the ";
		lOSS << "1st point's subtree, and the 3rd point is in the 2nd point's subtree) vs ";
		lOSS << "being external (the mutation occurs between two points, ";
		lOSS << "where both points are not within the other's subtree). ";
		lOSS << "Value of 1.0 means that the swap subtrees mutations are all internal ";
		lOSS << "while value of 0.0 means that swap subtrees mutations are all external.";
		Register::Description lDescription(
		    "Swap subtree mut. distrib. prob.",
		    "Float",
		    "0.5",
		    lOSS.str()
		);
		mDistributionProba = castHandleT<Float>(
		                         ioSystem.getRegister().insertEntry(mDistribPbName, new Float(0.5f), lDescription));
	}
	{
		Register::Description lDescription(
		    "Maximum tree depth",
		    "UInt",
		    "17",
		    "Maximum allowed depth for the trees."
		);
		mMaxTreeDepth = castHandleT<UInt>(
		                    ioSystem.getRegister().insertEntry("gp.tree.maxdepth", new UInt(17), lDescription));
	}
	{
		std::ostringstream lOSS;
		lOSS << "Maximum number of attempts to modify a GP tree in a genetic ";
		lOSS << "operation. As there is topological constraints on GP trees (i.e. tree ";
		lOSS << "depth limit), it is often necessary to try a genetic operation several times.";
		Register::Description lDescription(
		    "Max number of attempts",
		    "UInt",
		    "2",
		    lOSS.str()
		);
		mNumberAttempts = castHandleT<UInt>(
		                      ioSystem.getRegister().insertEntry("gp.try", new UInt(2), lDescription));
	}
	Beagle_StackTraceEndM();
}
Example #6
0
/*!
 * \brief Initialize this MPICommunication component.
 * \param ioSystem System reference.
 */
void HPC::MPICommunication::init(Beagle::System& ioSystem)
{
	Beagle_StackTraceBeginM();
	void* lValue;
	if(!MPI::COMM_WORLD.Get_attr( MPI::TAG_UB, &lValue ))
		throw RunTimeException("HPC::MPICommunication::init(Beagle::System&) the MPI::TAG_UB couldn't be retrieve.",__FILE__,__LINE__);
	mTagUpperBound = *(int*)lValue;

	unsigned int lSize = MPI::COMM_WORLD.Get_size();
	mNodeRank = new UInt(MPI::COMM_WORLD.Get_rank());
	int lRank = (*mNodeRank);
	UIntArray::Handle lPopulationSize = castHandleT<UIntArray>(ioSystem.getRegister().getEntry("ec.pop.size"));

	unsigned int lNbEvolvers = (*mNbEvolvers);
	int lNbEvaluators = lSize - lNbEvolvers - 1;

	Beagle_ValidateParameterM( lNbEvolvers <= lPopulationSize->size() && lNbEvolvers > 0,
					"hpc.evolver.nb",
					"The number of evolver must between 1 and the number of deme");

	Beagle_ValidateParameterM( lNbEvolvers <= lNbEvaluators  &&  lNbEvaluators > 0,
					"Number of nodes.",
					"There is not enough node for each evolver node to have at least one evaluator node each.");

	mTopology["Supervisor"] = new IntArray;
	mTopology["Any"] = new IntArray;
	mTopology["Parent"] = new IntArray;
	mTopology["Sibling"] = new IntArray;
	mTopology["Child"] = new IntArray;

	mTopology["Supervisor"]->push_back(0);
	mTopology["Any"]->push_back(MPI::ANY_SOURCE);

	mTypesMap["Supervisor"] = 1;
	mTypesMap["Evolver"] = lNbEvolvers;
	mTypesMap["Evaluator"] = lSize - lNbEvolvers - 1;

	if( lRank == 0 ){
		mNodeType = "Supervisor";
		for(int i = 0; i < lPopulationSize->size(); ++i){
			mTopology["Child"]->push_back((i % lNbEvolvers) + 1);
		}
	}
	else if( lRank <= lNbEvolvers){
		mNodeType = "Evolver";
		mTopology["Parent"]->push_back(0);
		int i = lRank + 1;
		for(;  i <= lNbEvolvers; ++i)
			mTopology["Sibling"]->push_back(i);
		for(i = 1; i < lRank; ++i)
			mTopology["Sibling"]->push_back(i);

		for(int j = lRank + lNbEvolvers; j < lSize; j += lNbEvolvers){
			mTopology["Child"]->push_back(j);
		}

		UIntArray::Handle lNewPopulationSize = new UIntArray;
		for(unsigned int k =  lRank - 1; k < lPopulationSize->size(); k += lNbEvolvers){
			lNewPopulationSize->push_back( (*lPopulationSize)[k] );
		}
		(*lPopulationSize) = (*lNewPopulationSize);
	}
	else{
		mNodeType = "Evaluator";
		UIntArray::Handle lNewPopulationSize = new UIntArray;

		if(lRank % lNbEvolvers != 0 ){
			mTopology["Parent"]->push_back(lRank % lNbEvolvers);
		} else {
			mTopology["Parent"]->push_back(lNbEvolvers);
		}
		for(unsigned int i = (*mTopology["Parent"])[0] - 1; i < lPopulationSize->size(); i+= lNbEvolvers){
			lNewPopulationSize->push_back( (*lPopulationSize)[i] );
		}
		(*lPopulationSize) = (*lNewPopulationSize);
	}

	Beagle_HPC_StackTraceEndM("void HPC::MPICommunication::init(System& ioSystem)");
}
Example #7
0
/*!
 *  \brief Register the parameters of the generic GP intialization operator.
 *  \param ioSystem System of the evolution.
 */
void GP::InitializationOp::registerParams(Beagle::System& ioSystem)
{
	Beagle_StackTraceBeginM();
	Beagle::InitializationOp::registerParams(ioSystem);
	{
		Register::Description lDescription(
		    "Maximum initial tree depth",
		    "UInt",
		    "5",
		    "Maximum depth for newly initialized trees."
		);
		mMaxTreeDepth = castHandleT<UInt>(
		                    ioSystem.getRegister().insertEntry("gp.init.maxdepth", new UInt(5), lDescription));
	}
	{
		Register::Description lDescription(
		    "Minimum initial tree depth",
		    "UInt",
		    "2",
		    "Minimum depth for newly initialized trees."
		);
		mMinTreeDepth = castHandleT<UInt>(
		                    ioSystem.getRegister().insertEntry("gp.init.mindepth", new UInt(2), lDescription));
	}
	{
		std::ostringstream lOSS;
		lOSS << "Maximum number of GP tree in newly initialized individuals. More than one tree ";
		lOSS << "is usually useful with ADFs (and other ADx).";
		Register::Description lDescription(
		    "Maximum number of trees",
		    "UInt",
		    "1",
		    lOSS.str()
		);
		mMaxNumberTrees = castHandleT<UInt>(
		                      ioSystem.getRegister().insertEntry("gp.init.maxtree", new UInt(1), lDescription));
	}
	{
		std::ostringstream lOSS;
		lOSS << "Minimum number of GP tree in newly initialized individuals. More than one tree ";
		lOSS << "is usually useful with ADFs (and other ADx).";
		Register::Description lDescription(
		    "Minimum number of trees",
		    "UInt",
		    "1",
		    lOSS.str()
		);
		mMinNumberTrees = castHandleT<UInt>(
		                      ioSystem.getRegister().insertEntry("gp.init.mintree", new UInt(1), lDescription));
	}
	{
		std::ostringstream lOSS;
		lOSS << "Maximum number of arguments in GP tree.  The first element in the array "
		<< "specifies the maximum number of arguments in the first tree of an individual, "
		<< "the second element specifies the second tree and so on.  If there are more "
		<< "trees in an individual than elements in the array then the last element is "
		<< "recycled.  Tree arguments are usually useful with ADFs (and similar).";
		Register::Description lDescription(
		    "Max. number of tree arguments",
		    "UIntArray",
		    "0/2",
		    lOSS.str()
		);
		mMaxTreeArgs = new UIntArray;
		mMaxTreeArgs->push_back(0);
		mMaxTreeArgs->push_back(2);
		mMaxTreeArgs = castHandleT<UIntArray>(
		                   ioSystem.getRegister().insertEntry("gp.tree.maxargs", mMaxTreeArgs, lDescription));
	}
	{
		std::ostringstream lOSS;
		lOSS << "Minimum number of arguments in GP tree.  The first element in the array "
		<< "specifies the minimum number of arguments in the first tree of an individual, "
		<< "the second element specifies the second tree and so on.  If there are more "
		<< "trees in an individual than elements in the array then the last element is "
		<< "recycled.  Tree arguments are usually useful with ADFs (and similar).";
		Register::Description lDescription(
		    "Min. number of tree arguments",
		    "UIntArray",
		    "0/2",
		    lOSS.str()
		);
		mMinTreeArgs = new UIntArray;
		mMinTreeArgs->push_back(0);
		mMinTreeArgs->push_back(2);
		mMinTreeArgs = castHandleT<UIntArray>(
		                   ioSystem.getRegister().insertEntry("gp.tree.minargs", mMinTreeArgs, lDescription));
	}
	Beagle_StackTraceEndM();
}
Example #8
0
/*!
 *  \brief Register parameters of the MilestoneWrite operator.
 *  \param ioSystem Reference to the system.
 */
void Master::MilestoneWriteOp::registerParams(Beagle::System& ioSystem)
{
	Beagle_StackTraceBeginM();

	Beagle::MilestoneWriteOp::registerParams(ioSystem);
	{
		Register::Description lDescription(
		    "Application name",
		    "String",
		    std::string("'")+mDefaultAppName+std::string("'"),
		    "Name of the application, as registered in the server."
		);
		mAppName = castHandleT<Beagle::String>(
		               ioSystem.getRegister().insertEntry("db.app.name", new Beagle::String(mDefaultAppName), lDescription));
	}
	{
		Register::Description lDescription(
		    "IP server address",
		    "String",
		    "127.0.0.1",
		    "IP address of the master-slave server."
		);
		mServerIP = castHandleT<Beagle::String>(
		                ioSystem.getRegister().insertEntry("db.server.ip", new Beagle::String("127.0.0.1"), lDescription));
	}
	{
		Register::Description lDescription(
		    "IP server port",
		    "UInt",
		    "9123",
		    "IP port of the master-slave server."
		);
		mServerPort = castHandleT<UInt>(
		                  ioSystem.getRegister().insertEntry("db.server.port", new UInt(9123), lDescription));
	}
	{
		Register::Description lDescription(
		    "Compression level",
		    "UInt",
		    "3",
		    "Evolver communication compression."
		);
		mCompressionLevel = castHandleT<UInt>(
		                        ioSystem.getRegister().insertEntry("db.evolver.compression", new UInt(0), lDescription));
	}
#ifdef BEAGLE_HAVE_LIBZ
	{
		std::ostringstream lOSS;
		lOSS << "If true, this flag indicates that milestones will be ";
		lOSS << "compressed with gzip. Otherwise, each milestone are kept plain text.";
		Register::Description lDescription(
		    "Milestone compression flag",
		    "Bool",
		    "1",
		    lOSS.str()
		);
		mCompressMilestone = castHandleT<Bool>(
		                         ioSystem.getRegister().insertEntry("ms.write.compress", new Bool(true), lDescription));
	}
#endif // BEAGLE_HAVE_LIBZ

	Beagle_StackTraceEndM();
}