亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? chrome.cpp

?? 一個GP遺傳編程的源程序
?? CPP
?? 第 1 頁 / 共 2 頁
字號:
					{
						vnum=atoi(s+1);
						if (vnum>=0 && vnum <= CONSTARRAYSIZE)
						{
							s[0]='\0';              // found a valid function with variable number appended.  Keep function name.
						}
						else
				vnum=0;
					}
				}
				func=FindFunc(scratch);
				if (func<0)
					rval=LOAD_BADFUNC;
				else
				{
					SETNODE(buf[ip],func,vnum);
					ip++;
		    rval=LOAD_OK;
					// get the arguments
		    args=funclist[func]->argnum;
					while(args>0 && rval==LOAD_OK)
		    {
						rval=SubLoad(istr,buf);
						args--;
					}
//                                      if (rval == LOAD_TOOFEW)
//                      ;               // restore the token for the error message
				}
			}
		}
	}
	return rval;
}


//**************************************************************************

int Chrome::FindFunc(char* funcname)            // find a function index by name, or return -1
{
	int rval=-1;
	int i;
	for (i=0;i<funccount && rval<0;i++)
		if (strcmpi(funcname,funclist[i]->name)==0)
			rval=i;
	return rval;
}

Chrome::~Chrome()
{
		delete[] expr;
	delete nfitness;
}

//**************************************************************************
//// Generic Problem Functions /////////////////////////////////////

Problem::Problem()
// Set up the tables
// You add the primitive functions in your subclass constructor

{
	int i;

	funclist = new Function*[FUNCARRAYSIZE];
		funcbag = new CSelector(EStraight,256);
	varlist = new retval[CONSTARRAYSIZE];
	constlist = new retval[CONSTARRAYSIZE];
	funccount = 0;
	// set up constant table (not implemented)
	for (i=0;i<CONSTARRAYSIZE;i++) constlist[i]=i-(CONSTARRAYSIZE/2);
}

Problem::~Problem()
{
	int i;
	delete[] constlist;
	delete[] varlist;

	for (i=0;i<funccount;i++) delete funclist[i];
    delete funcbag;
	delete[] funclist;
}

FitnessValue* Problem::GetFitnessObj()
{
	FitnessValue* fv = new FitnessValue;
	if (fv==NULL) NoMoreMem();		// Out of memory?
	fv->fvalue=0;
    // fv has to be deleted by the Chrome Object
    return fv;
}

CSelector* Problem::getfuncbag()         // update the function selector and return its pointer
{
	int i;
	funcbag->reset();
	for (i=0;i<funccount;i++)
		funcbag->add(funclist[i]->weight/(2+funclist[i]->argnum),i);
	return funcbag;
}

float Problem::fitness(Chrome* chrome)
// This is just a stub.  You must add your own virtual fitness function

{
	float f=0;
	// clear variables if required
	// call the installed fitness function
	chrome->nfitness->fvalue = f;
	return f;
}



//**************************************************************************
//// Pop Functions /////////////////////////////////////////////////

Pop::Pop(Problem* prob,ChromeParams* par,UINT size)
// set up a population for a particular problem
// Creates <size> new Chromes
// evaluates the first Chrome.  The rest will be evaluated in the first
// Size-1 calls to generate

{
	UINT i;
		CSelector* fbag = prob->getfuncbag();
	isAborted=FALSE;
	problem = prob;
	gencount = 0;
	start=time(NULL);
		BestMember=0;
	BestFitness=NULL;

	params=par;
	par->funccount = prob->funccount;
	if (par->params[pMaxExpr] > EXPRLEN)
		par->params[pMaxExpr]=EXPRLEN;

	popsize=size;
	pop = new Chrome*[size];
	if (pop==NULL) NoMoreMem();		// Out of memory?
	for (i=0;i<size;i++)
	{
		pop[i]=new Chrome(params,fbag,prob,prob->getfuncs(),prob->getconsts());
		if (pop[i]==NULL) NoMoreMem();		// Out of memory?
	}
	// now eval 1 guy
	initeval=TRUE;
	nexteval=1;
	Fitness(pop[0]);
	InsertMember(0,pop[0],TRUE);
}

float Pop::Fitness(Chrome* chrome)
// uses the problem to evalue the fitness of member X
// performs setup on the Chrome
// updates the BestMember and returns the fitness value

{
	chrome->SetupEval();
	return problem->fitness(chrome);
}


void Pop::InsertMember(int slot,Chrome* NewChrome,int nodelete)
// uses the problem to evalue the fitness of member X
// performs setup on the Chrome
// updates the BestMember and returns the fitness value

{
	UINT endpop;


	if (!nodelete)
		 {
	// replace the chrome in this slot
	    delete pop[slot];
		pop[slot]=NewChrome;
	 }
	 // Update Best Member
		if (BestFitness==NULL)
		{
			BestMember=slot;
			BestFitness=NewChrome->nfitness;
	}
	else if(NewChrome->nfitness->IsBetter(BestFitness))
	{
		BestMember=slot;
		BestFitness=NewChrome->nfitness;
	}
	else if(slot==BestMember)
	{
		endpop = (initeval? nexteval : popsize);
		BestMember=0;
		BestFitness=pop[0]->nfitness;
		UINT i;
		for (i=1;i<endpop;i++)
		{
			if (pop[i]->nfitness->IsBetter(BestFitness))
			{
				BestMember = i;
				BestFitness=pop[i]->nfitness;
			}
		}

	}
	NewChrome->birth=gencount;
}


Pop::Pop(Problem* prob,ChromeParams* par)
// set up just the core of a population;; let a subclass allocate the members
{
	isAborted=FALSE;
	problem = prob;
	gencount = 0;
	params=par;
	popsize=0;
	pop=NULL;
		BestMember=-1;
		BestFitness=prob->GetFitnessObj();    // allocates FitnessValue object on heap
	   
	BestFitness->fvalue=1-10000000000000;
	// BestFitness->fvalue=1-MAXFLOAT;
}


Pop::~Pop()
{
		int i;
		for (i=0;i<popsize;i++) delete pop[i];
	delete[] pop;
}

Chrome* Pop::best()
{
	return pop[BestMember];
}

enum {docross,domutate,doanneal,docrossanneal,docopy};

Chrome* Pop::selectParent(int target)
{                                                                               // target identifies selection region in pop
// select one parent. Return pointer to selected parent
	int region, ts, offset, i;
	Chrome* best;
	Chrome* trial;

	region = params->params[pMateRadius];
	ts = params->params[pTournSize];
	// Only tournament selection is implemented in GPQUICK.
	// Add your own methods to taste
	if (params->params[pSelectMethod] == ETournament)
	{
		if (region == 0 || region > popsize)
			region = popsize;
		offset=popsize+target-region/2;
		best=pop[(rnd(region)+offset)%popsize];
	for (i=1;i<ts;i++)
		{
			trial=pop[(rnd(region)+offset)%popsize];
			if (trial->nfitness->IsBetter(best->nfitness))
				best=trial;
		}
	}
    return best;
}

Chrome* Pop::generate()
// generate a single new chrome.  Return fitness.
// This implements a one processor, steady stage GA
// Its reproductive operators are Copy, Subtree Crossover, and Node Mutation
// It uses tournament selection to select parents
// It selects in a one dimensional local region
// It uses global tournament anti-selection to select a member for replacement

// Virtual - add your own GA here if desired

{
	int target;
	int i,region,ts,offset;
	int newchrome = FALSE;
	int prob,wheel;
	int dowhat;

	Chrome* best;
	Chrome* secondbest;
    Chrome* trial;
	


	gencount++;

  if (initeval)                 // still on initial evaluations?
							// don't generate. Finish evaluating initial pop.
	{
	  Fitness(pop[nexteval]);
      InsertMember(nexteval,pop[nexteval],TRUE);
	  target=nexteval;
	  nexteval++;
	  if (nexteval>=popsize)
		initeval=FALSE;
  }
  else
  {
	// decide what to do - Cross, Mutate, Copy
		prob=rnd(params->params[pCrossWt]+params->params[pMuteWt]+params->params[pCopyWt]+params->params[pAnnealMuteWt]+params->params[pAnnealCrossWt]);
	wheel=params->params[pCrossWt];
	if (prob<wheel)
		dowhat=docross;
	else if (prob<(wheel += params->params[pMuteWt]))
		dowhat=domutate;
	else if (prob<(wheel += params->params[pCopyWt]))
		dowhat=docopy;
	else if (prob<(wheel += params->params[pAnnealMuteWt]))
	dowhat=doanneal;
	else
		dowhat=docrossanneal;
	   
	// Perform reproduction
	switch (dowhat)
	{
	case docross:
	target=GetTarget();                     // Find a member to replace
		best=selectParent(target);
		secondbest=selectParent(target);
		trial=best->CrossTree(secondbest);
		newchrome = TRUE;
		break;
	case domutate:
		target=GetTarget();                     // Find a member to replace
	    best=selectParent(target);
		trial = best->Copy();
				prob=rnd(params->params[pMuteNodeWt]+params->params[pMuteConstWt]+params->params[pMuteShrinkWt]);
				wheel=params->params[pMuteNodeWt];
		if (prob<wheel)
	    trial->Mutate();
				else if (prob<(wheel += params->params[pMuteConstWt]))
			trial->MutateC();
		else 
			trial->MutateShrink();
		newchrome = TRUE;
		break;
	case doanneal:
		target=GetAnnealTarget();
		trial = pop[target]->Copy();
				prob=rnd(params->params[pMuteNodeWt]+params->params[pMuteConstWt]+params->params[pMuteShrinkWt]);
		wheel=params->params[pMuteNodeWt];
		if (prob<wheel)
	    trial->Mutate();
		else if (prob<(wheel += params->params[pMuteConstWt]))
			trial->MutateC();
		else 
			trial->MutateShrink();
	Fitness(trial);
		// test whether mutated chome is fitter
				if (trial->nfitness->IsBetter(pop[target]->nfitness))
		{
		InsertMember(target,trial);
			newchrome = TRUE;
		}
		else
			delete trial;
		break;
    case docrossanneal:
		target=GetAnnealTarget();
		best=selectParent(target);
		trial=pop[target]->CrossTree(best);
		Fitness(trial);
		// test whether chome is fitter
		if (trial->nfitness->IsBetter(pop[target]->nfitness))
		{
		InsertMember(target,trial);
			newchrome = TRUE;
		}
		else
			delete trial;
		break;

	case docopy:
		target=GetTarget();                     // Find a member to replace
	    best=selectParent(target);
		trial=best->Copy();
		newchrome = (params->params[pRepeatEval]? TRUE: FALSE);
	}

    // Update the pop array
	if ((dowhat!=doanneal) && (dowhat!=docrossanneal))
    {

		// fitness?
		if (newchrome)
		{
			Fitness(trial);
	}
	InsertMember(target,trial);
	}
  }     // if not initeval

	return pop[target];
}

Chrome* Pop::go_until(time_t max_time, int maxevals, float maxfitness)
// generate until time max_time, evals maxevals, or fitness maxfitness
// Do this to run the GA in a bigger event loop

{
	//int done = FALSE;
	int didevals = 0;
	Chrome* lastchrome;

	lastchrome=generate();
	didevals++;
		//while(maxevals == 0 || didevals<maxevals)
		while ((max_time == 0 || time(NULL) < max_time) &&
			(maxevals == 0 || didevals<maxevals) &&
			( lastchrome->nfitness->fvalue < maxfitness)
			&&!Aborted())
		{
				lastchrome = generate();
				didevals++;
	}
	return lastchrome;
}

int Pop::GetTarget()
// Tournament anti-selection for replacement.  Usually size 1 (random selection) or 2
// Will select a target that is too old, even if more fit.
{
	int target = rnd(popsize);
	int i,winner;
		if (params->params[pKillTourn]>1 && gencount- pop[target]->birth < params->params[pMaxAge])
	// pick a target to replace
	for (i=1;i<params->params[pKillTourn];i++)
	{
		winner=rnd(popsize);
		if (gencount - pop[winner]->birth > params->params[pMaxAge])
		{
			i=1000;
			target = winner;
		} else if (pop[target]->nfitness->IsBetter(pop[winner]->nfitness))
			target = winner;
	}
	return target;
}


int Pop::GetAnnealTarget()
{                                                                               // target identifies selection region in pop
// select one parent. Return pointer to selected parent
	int ts, i;
    int best,trial;

	ts = params->params[pTournSize];
	// Only tournament selection is implemented in GPQUICK.
	// Add your own methods to taste
	if (params->params[pSelectMethod] == ETournament)
	{
		best=rnd(popsize);
	for (i=1;i<ts;i++)
		{
			trial=rnd(popsize);
			if (pop[trial]->nfitness->IsBetter(pop[best]->nfitness))
				best=trial;
		}
	}
    return best;
}

//************************************************************************
//////////////////////ChromeParams methods

ChromeParams::ChromeParams()
//Set default parameters here in the constructor
{
	varcount = 0;
	funccount = 0;

	int x;
	for (x=0;x<PARAM_COUNT;x++)
		params[x]=0;

		params[pMaxExpr] = 50;         // Maximum expression size in nodes
		params[pInitExpr] = 6;          // Maximum initial expression depth
		params[pMuteRate] = 100;        // Node Mutation rate per 1000
		params[pCrossSelf] = 1;         // enable cross with self
		params[pUnRestrictWt] = 70;        // any point crossover out of 100
		params[pCrossWt] = 100;       // Crossover weight
		params[pMuteWt] = 30;        // overall Mutation weight
		params[pAnnealCrossWt] = 0;   // Crossover Annealing Weight
		params[pAnnealMuteWt] = 0;   // Mutate Annealing weight
		params[pCopyWt] = 10;        // Copy weight
		params[pMuteNodeWt] = 100;   // Node Mutate weight
		params[pMuteConstWt] = 100;    // MutateC weight
		params[pMuteShrinkWt] = 100;   // MutateShrink weight
		params[pSelectMethod] = ETournament;  // Selection method = Tournament
		params[pTournSize] = 7;         // Tournament size
		params[pMateRadius] = 500;       // Mating radius
		params[pGaussRegion] = 0;         // Guassian mate selection 0 disable 1 enable
		params[pRepeatEval] = 0;         // Repeat eval on copy? 0 no 1 yes
		params[pKillTourn] = 2;         // Size of "Kill Tournament" for replacement
		params[pMaxAge] = 2000;      // Maximum age before replaced even if better
		params[pParsimony] = 0;         // Parsimony factor
		params[pFitnessCases] = 20;        // # fitness cases
}


ChromeParams::~ChromeParams()
{
}

//************************************************************************


?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
4438成人网| 成人av午夜影院| 91精品国产入口| 奇米色一区二区| 欧美xxxx在线观看| 国产宾馆实践打屁股91| 国产精品免费久久久久| 91美女在线观看| 亚洲国产综合在线| 日韩欧美国产综合一区| 国产精品亚洲午夜一区二区三区 | 久久综合色综合88| 国产在线不卡视频| 国产精品国产自产拍在线| 色哟哟一区二区| 丝袜a∨在线一区二区三区不卡| 3751色影院一区二区三区| 九九精品一区二区| 国产精品青草综合久久久久99| 91啪亚洲精品| 日本特黄久久久高潮| 国产欧美一区在线| 在线一区二区视频| 精品午夜一区二区三区在线观看| 国产亚洲一区二区三区在线观看 | 中文字幕一区二区三区在线不卡| 9i看片成人免费高清| 天涯成人国产亚洲精品一区av| 欧美一区二区视频网站| 国产精品91xxx| 一二三区精品视频| 国产亚洲欧洲997久久综合| 日本不卡视频在线| 18成人在线视频| 日韩免费高清av| 色综合天天视频在线观看 | 亚洲精品乱码久久久久久日本蜜臀| 欧美亚洲丝袜传媒另类| 国产精品一区在线观看你懂的| 一区二区三区免费在线观看| 精品国产乱码久久| 欧美色图一区二区三区| 成人国产精品视频| 美国一区二区三区在线播放| 亚洲激情图片qvod| 国产蜜臀av在线一区二区三区| 欧美日韩成人综合| 91丨九色porny丨蝌蚪| 精品一区二区在线视频| 亚洲一区二区美女| 国产精品私人自拍| 精品人在线二区三区| 91精品国产黑色紧身裤美女| 99精品久久久久久| 国产一区二区三区免费| 日韩激情一二三区| 一区二区三区四区蜜桃| 国产精品国产三级国产aⅴ入口| 日韩视频一区在线观看| 欧美影视一区在线| 色偷偷一区二区三区| 成人性生交大片免费看中文| 美女视频黄久久| 热久久一区二区| 日日摸夜夜添夜夜添精品视频| 亚洲精品成人a在线观看| 中文字幕亚洲电影| 中文字幕不卡三区| 欧美国产精品一区二区三区| 久久久国产精品午夜一区ai换脸| 欧美一区二区三区四区高清| 欧美日韩国产首页| 欧美三级电影精品| 欧美精品一二三区| 欧美顶级少妇做爰| 欧美久久久久久久久中文字幕| 日本精品一区二区三区四区的功能| 岛国精品在线播放| www.欧美色图| 99精品在线观看视频| 99re视频精品| 91久久精品一区二区三区| 99精品黄色片免费大全| 99国产精品一区| 91免费精品国自产拍在线不卡| 97久久超碰国产精品| 色婷婷一区二区| 欧美日韩久久久久久| 欧美日韩国产在线观看| 3d动漫精品啪啪| 欧美精品一区二区三区蜜桃视频| 久久日韩粉嫩一区二区三区| 国产日韩欧美高清在线| 中文字幕在线一区| 一个色妞综合视频在线观看| 日韩精品欧美精品| 狠狠色丁香婷婷综合久久片| 国产精品一区二区久久精品爱涩| 成人听书哪个软件好| 色婷婷亚洲综合| 欧美一卡二卡在线| 国产亚洲一区二区在线观看| 国产精品黄色在线观看| 亚洲高清一区二区三区| 老色鬼精品视频在线观看播放| 国产成人午夜精品影院观看视频| 91在线免费视频观看| 欧美色图片你懂的| 精品成人a区在线观看| 国产女人18毛片水真多成人如厕| 看国产成人h片视频| 激情图片小说一区| 91香蕉视频mp4| 91精品国产综合久久精品图片| 久久亚洲免费视频| 一区二区三区中文在线| 免费人成黄页网站在线一区二区| 国产成人在线网站| 欧美性生活一区| 国产色产综合产在线视频| 亚洲一区二区三区中文字幕 | 精品福利av导航| 亚洲免费伊人电影| 日本午夜精品一区二区三区电影| 国产超碰在线一区| 欧美一区二区三区小说| 国产精品久久久久久久久动漫| 日韩激情视频网站| 色综合中文字幕国产 | 91尤物视频在线观看| 91精品久久久久久久91蜜桃 | 亚洲欧美日韩电影| 精品一区二区三区久久| 色婷婷亚洲综合| 国产拍欧美日韩视频二区| 日本色综合中文字幕| 99re66热这里只有精品3直播 | 99r国产精品| 久久综合九色综合欧美亚洲| 亚洲综合色成人| 国产xxx精品视频大全| 91精品国产综合久久久久久久久久| 亚洲丝袜另类动漫二区| 激情综合色丁香一区二区| 国产精品免费免费| 麻豆高清免费国产一区| 欧美三级在线播放| 亚洲婷婷综合色高清在线| 国产精品一区二区在线播放| 欧美一卡二卡三卡| 亚洲福利一二三区| 色婷婷综合久色| 国产精品乱码妇女bbbb| 韩国av一区二区| 欧美哺乳videos| 日本中文一区二区三区| 在线观看日产精品| 亚洲精品第一国产综合野| 99这里只有久久精品视频| 国产亚洲短视频| 国产精品一品视频| 久久网这里都是精品| 国内久久婷婷综合| 精品成人免费观看| 狠狠色丁香婷婷综合| 精品欧美一区二区三区精品久久| 久久综合综合久久综合| 7777精品伊人久久久大香线蕉 | 一区二区三区在线观看欧美| 成人黄色在线视频| 国产精品全国免费观看高清| 成人一级黄色片| 中文字幕一区二区三区四区 | 老司机午夜精品| 日韩视频一区二区在线观看| 蜜桃av噜噜一区二区三区小说| 欧美一区二区美女| 精品午夜久久福利影院| 精品国产1区2区3区| 国产老肥熟一区二区三区| 久久久精品中文字幕麻豆发布| 国产乱码精品一区二区三 | 亚洲精品国产第一综合99久久| 色www精品视频在线观看| 亚洲激情网站免费观看| 欧美日韩国产另类不卡| 人人狠狠综合久久亚洲| 久久伊99综合婷婷久久伊| 成人免费视频视频在线观看免费 | 6080yy午夜一二三区久久| 日韩激情中文字幕| 久久久久久久久久电影| www.av精品| 婷婷综合久久一区二区三区| 精品人在线二区三区| 成人激情免费网站| 视频一区视频二区中文| 欧美一级一区二区| 高清在线不卡av| 亚洲综合色成人|