当前位置: 首页>>代码示例>>C++>>正文


C++ Population::GetSpecifiedTreeStrings方法代码示例

本文整理汇总了C++中Population::GetSpecifiedTreeStrings方法的典型用法代码示例。如果您正苦于以下问题:C++ Population::GetSpecifiedTreeStrings方法的具体用法?C++ Population::GetSpecifiedTreeStrings怎么用?C++ Population::GetSpecifiedTreeStrings使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Population的用法示例。


在下文中一共展示了Population::GetSpecifiedTreeStrings方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: DoMasterAMR

void DoMasterAMR(char *buf, int size, int who, int tag, thread_arg_t *targ)	{
	MasterGamlConfig *conf = targ->conf;
	Population *pop = targ->pop;
	int count, start_shield, which;
	char *tree_strings, *model_buf;
	double *models, score;

	assert(tag == TAG_SCORE);
	memcpy(&score, buf, sizeof(double));
	//delete [] buf;

	// print some messages
	debug_mpi("SYNCHRONOUS COMM (%d, AMR, %f)", who, pop->bestFitness);
	debug_mpi("\trecv: score %f", score);

	if (score > pop->bestFitness)	{
		SendMPIMessage(NULL, 0, who, TAG_TREE_STRINGS_REQUEST);
		debug_mpi("\tsent: TAG_TREE_STRINGS_REQUEST");
		RecvMPIMessage(&buf, &size, who, &tag, true);
		assert(tag == TAG_TREE_STRINGS);
		tree_strings = buf;
		debug_mpi("\trecv: %d tree strings", CountTreeStrings(tree_strings));

		RecvMPIMessage(&buf, &size, who, &tag, true);
		assert(tag == TAG_MODEL);
		models=(double*)buf;
		
		which = pop->total_size-1;
		pop->ReplaceSpecifiedIndividuals(1, &which, tree_strings, models);
		pop->CalcAverageFitness();
		debug_mpi("score sent: %f, score calced: %f", score, pop->IndivFitness(which));
		//assert(abs(score -  pop->IndivFitness(which))<.00001);
		}
	else	{
		which = (int)pop->cumfit[pop->total_size-1][0];
		pop->GetSpecifiedTreeStrings(&tree_strings, 1, &which);
		int model_size=pop->GetSpecifiedModels(&models, 1, &which);

		SendMPIMessage(tree_strings, strlen2(tree_strings)+2, who, TAG_TREE_STRINGS);
		debug_mpi("\tsent: %d tree strings", CountTreeStrings(tree_strings));

		model_buf = (char*)models;
		SendMPIMessage(model_buf, sizeof(double)*model_size, who, TAG_MODEL);
		debug_mpi("\tsent: %d models", 1);
		}
	delete [] tree_strings;
	delete [] models;
	}
开发者ID:rekepalli,项目名称:garli,代码行数:48,代码来源:threadfunc.cpp

示例2: RemoteSendBestTree

void RemoteSendBestTree(Population& pop){
	int *which=new int;
	char *tree_strings;
	double *models;
	
	pop.GetNBestIndivIndices(&which, 1);
	pop.GetSpecifiedTreeStrings(&tree_strings, 1, which);
	int size=strlen2(tree_strings)+2;
//	debug_mpi("about to send treestrings...");
	SendMPIMessage(tree_strings, size, 0, TAG_TREE_STRINGS);
	debug_mpi("\tsent ind %d, lnL %f", *which, pop.indiv[*which].Fitness());
//	debug_mpi("about to send modelstrings...");
	int model_size=pop.GetSpecifiedModels(&models, 1, which);
	SendMPIMessage((char*) models, sizeof(double)*model_size, 0, TAG_MODEL);
//	debug_mpi("about to send subdef...");
	char std[5];
	sprintf(std, "%d", pop.subtreeDefNumber);
	SendMPIMessage(std, strlen(std)+2, 0, TAG_SUBTREE_ITERATION);
	
	if(pop.subtreeDefNumber!=0){
		char stn[10];
		sprintf(stn, "%d", pop.subtreeNode);
		SendMPIMessage(stn, strlen(stn)+2, 0, TAG_SUBTREE_DEFINE);
		debug_mpi("\tvalid for subtree def %d, node %d", pop.subtreeDefNumber, pop.subtreeNode);
		}
	else
		debug_mpi("\tno defined subtree");
		
	//finally, send the score
	double score = pop.indiv[*which].Fitness();
	SendMPIMessage((char*)&score, sizeof(double), 0, TAG_SCORE);	
	
	delete which;
	delete [] tree_strings;
	delete [] models;
	}
开发者ID:rekepalli,项目名称:garli,代码行数:36,代码来源:mpifuncs.cpp

示例3: DoMasterSW


//.........这里部分代码省略.........
	
	double updateThresh=paraMan->updateThresh;
//DEBUG
//	if(paraMan->subtreeModeActive==false && (paraMan->needToSend[who]==true || ((scorediff > nonSubThresh && paraMan->beforeFirstSubtree==false) || (scorediff > startThresh && paraMan->beforeFirstSubtree==true) || remoteSubtreeDef>0))){
	if(paraMan->subtreeModeActive==false){
		if((paraMan->perturbModeActive==false && (scorediff > updateThresh || remoteSubtreeDef>0))/* || (paraMan->needToSend[who]==true)*/){
			debug_mpi("\tupdate thresh = %f, send indiv", updateThresh);
			//cases 5, 6 and 8
			*which = (int)pop->cumfit[pop->total_size-1][0];
			subtreeNum=0;
			send=true;
			}
		else debug_mpi("\tupdate thresh = %f", updateThresh);
		}
		
	else if(paraMan->subtreeModeActive==true){
		//cases 1-4
		if((scorediff > updateThresh) || (subtreesCurrent==false)/* || paraMan->perturb==true*/){
			//cases 2 and 4.  send the best accurate tree
			*which=pop->bestAccurateIndiv;	
			if(paraMan->remoteSubtreeAssign[who] != 0) subtreeNum=paraMan->remoteSubtreeAssign[who];
			else subtreeNum=paraMan->ChooseSubtree();
			debug_mpi("\tsend best accurate ind, %f (best=%f)", pop->indiv[*which].Fitness(), pop->bestFitness);
//			debug_mpi("\tperturb=%d, bestFit=%f, indFit=%f", paraMan->perturb, pop->bestFitness, pop->indiv[*which].Fitness());
			send=true;
			}
		else if(recalcSubtrees==true && subtreesCurrent==false){
			//case 3
			//if the new inaccurate tree that came in is better than what we have,
			//recalcuate the subtrees, and send the same tree back, but with a 
			//subtree asignment
			pop->StartSubtreeMode();
			debug_mpi("Recalculating subtrees");
			subtreeNum=paraMan->ChooseSubtree();
			send=true;
			}
		}

	if(paraMan->needToSend[who]){
		char pertbuf[5];
		int perttype = (pop->pertMan->pertType > 0 ? pop->pertMan->pertType : (int)(rnd.uniform() * 2 + 1));
		sprintf(pertbuf, "%d", perttype);
		SendMPIMessage(pertbuf, strlen(pertbuf)+2, who, TAG_PERTURB);
		debug_mpi("sending pertub message to %d, type %d", who, perttype);
		paraMan->needToSend[who]=false;
		}


	if(send==true){
		pop->GetSpecifiedTreeStrings(&out_tree_strings, 1, which);
		
		assert(*out_tree_strings == '(');
		int model_size=pop->GetSpecifiedModels(&out_models, 1, which);
		
		SendMPIMessage(out_tree_strings, strlen2(out_tree_strings)+2, who, TAG_TREE_STRINGS);
		SendMPIMessage((char*)out_models, sizeof(double)*model_size, who, TAG_MODEL);

/*		if(paraMan->needToSend[who]){
			char pertbuf[5];
			int perttype = (pop->pertMan->pertType > 0 ? pop->pertMan->pertType : (rnd.uniform() * 2 + 1));
			sprintf(pertbuf, "%d", subtreeNum);
			SendMPIMessage(NULL, 0, who, TAG_PERTURB);
			debug_mpi("sending pertub message to %d, type %d", who, perttype);
			paraMan->needToSend[who]=false;
			}
*/			
//		else{
			char stn[5];
			sprintf(stn, "%d", subtreeNum);
			SendMPIMessage(stn, strlen(stn)+2, who, TAG_SUBTREE_DEFINE);
			debug_mpi("\tsent ind %d, lnL %f", *which, pop->indiv[*which].Fitness());

			if(subtreeNum > 0){
				//if this node was already assigned a subtree, be sure to subtract the old one from the assigned array
				sprintf(stn, "%d", paraMan->subtreeDefNumber);
				debug_mpi("\tsubdef %d, node %d", paraMan->subtreeDefNumber, subtreeNum);
				SendMPIMessage(stn, strlen(stn)+2, who, TAG_SUBTREE_ITERATION);
				}
			
//			}
		paraMan->remoteSubtreeAssign[who]=subtreeNum;
		
		delete []out_models;
		delete []out_tree_strings;		
		}
#ifndef NDEBUG
	if(paraMan->subtreeModeActive && paraMan->subtreeDefNumber==remoteSubtreeDef){
        //DEBUG
        //if we think that this remote gave us a tree with accurate subtrees, check
        paraMan->CheckSubtreeAccuracy(pop->indiv[which[0]].treeStruct);
		}
#endif
	
	//the tree_strings that were passed in will be deleted back
	//where the initial call to RecvMPIMessage was made
	delete [] which;

	pop->CalcAverageFitness();
	return 0;
}
开发者ID:rekepalli,项目名称:garli,代码行数:101,代码来源:threadfunc.cpp


注:本文中的Population::GetSpecifiedTreeStrings方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。