本文整理汇总了C++中GAGenome::score方法的典型用法代码示例。如果您正苦于以下问题:C++ GAGenome::score方法的具体用法?C++ GAGenome::score怎么用?C++ GAGenome::score使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GAGenome
的用法示例。
在下文中一共展示了GAGenome::score方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
// Receive the bits from the specified task. Stuff the genome with the data.
// Returns a negative number if there was a transmission failure.
int
UnpackIndividual(GAGenome& g) {
GA1DBinaryStringGenome& genome = (GA1DBinaryStringGenome&)g;
int length = 0;
float score = 0.0;
static int nbits = 0;
static int* bits = 0;
int status = 0;
status = pvm_upkint(&length, 1, 1);
if(nbits < length){
nbits = length;
delete [] bits;
bits = new int [nbits];
}
status = pvm_upkint(bits, length, 1);
genome.length(length); // resize the genome
genome = bits; // stuff it with the bits
status = pvm_upkfloat(&score, 1, 1); // get the score from process
g.score(score); // set the score on the genome
return status;
}
示例2: while
void
GADCrowdingGA::step() {
if(pop->size() == 0) return;
GAGenome *child = pop->individual(0).clone();
GAList<int> indpool;
for (int i=0; i<pop->size(); i++)
indpool.insert(i);
do {
int *ip;
indpool.warp(GARandomInt(0,indpool.size()-1)); // select mom
ip=indpool.remove();
GAGenome *mom = &pop->individual(*ip);
delete ip;
indpool.warp(GARandomInt(0,indpool.size()-1)); // select dad
ip=indpool.remove();
GAGenome *dad = &pop->individual(*ip);
delete ip;
stats.numsel += 2; // create child
stats.numcro += (*scross)(*mom, *dad, child, 0);
stats.nummut += child->mutate(pMutation());
stats.numeval += 1;
double d1 = child->compare(*mom); // replace closest parent
double d2 = child->compare(*dad);
if (d1 < d2) {
if (minmax == MINIMIZE) {
if (child->score() < mom->score()) {
mom->copy(*child);
stats.numrep += 1;
}
}
else {
if (child->score() > mom->score()) {
mom->copy(*child);
stats.numrep += 1;
}
}
}
else {
if (minmax == MINIMIZE) {
if (child->score() < dad->score()) {
dad->copy(*child);
stats.numrep += 1;
}
}
else {
if (child->score() > dad->score()) {
dad->copy(*child);
stats.numrep += 1;
}
}
}
} while (indpool.size()>1);
pop->evaluate(gaTrue);
stats.update(*pop);
delete child;
}
示例3: GAPDEvaluator
//.........这里部分代码省略.........
{
cerr << "boost::thread exception: " << e.what() << std::endl;
return;
}
#else//USE_BOOST
errorCode = pthread_create(&backgroundThreads[tIndex], NULL, backgroundEvaluate, backgroundEvaluators[tIndex]);
if (errorCode!=0)
{
cerr << "pthread_create: Error #"<< errorCode << " (" << strerror(errorCode) << ")" << std::endl;
return;
}
#endif//USE_BOOST
assert(backgroundThreads[tIndex]);
indIndex++;
}
// Our cyclic thread index checks for the completion of a running thread
tIndex = ( tIndex+1 ) % numberOfThreadsToUse;
// A (possibly still running) thread exists...
if ( backgroundThreads[tIndex] != NULL )
{
assert( backgroundEvaluators[tIndex] != NULL );
// Check to see if it is finished
if ( backgroundEvaluators[tIndex]->finished() )
{
// The thread has finished. Gather some stats (if DEBUGging) and free the thread up for the next individual
completed++;
#if DEBUG
GAGenome* genome = backgroundEvaluators[tIndex]->individual( );
float score = genome->score( );
total += score;
cout << "Received results from individual #" << backgroundEvaluators[tIndex]->index( ) << " ( " << completed << " of " << pop.size( ) <<
" finished ): Score: " << genome->score( ) << " (" << total / (float)completed << " is average so far)" << std::endl;
if ( score > highestScoreSoFar )
{
cout << "Found new high score so far: ( " << score << " > " << highestScoreSoFar <<" )" << std::endl;
highestScoreSoFar = score;
}
#endif//DEBUG
#if USE_BOOST
delete backgroundThreads[tIndex];
#else//USE_BOOST
errorCode = pthread_join(backgroundThreads[tIndex], NULL);
assert(errorCode==0);
#endif//USE_BOOST
backgroundThreads[tIndex] = NULL;
}
else
{
// If it hasn't finished yet, give up some main() thread processor time to the background evaluators
#if USE_BOOST
boost::thread::yield();
#else//USE_BOOST
pthread_yield();
#endif//USE_BOOST
}
}
}