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

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

?? chrome.cpp

?? wang xiao ping 版遺傳算法
?? CPP
?? 第 1 頁 / 共 2 頁
字號:
// Copyright Andy Singleton, 1993,1994
// This code is released for non-commercial use only
// For questions or upgrades contact:
// Andy Singleton, Creation Mechanics Inc.
// PO Box 248, Peterborough, NH 03458
// Internet: p00396@psilink.com
// Compuserve 73313,757
// Phone: (603) 563-7757

// GPQUICK
// C++ prefix stack implementation
// Divides GP system into classes:
//    Chrome-Function  - representation of the genetic program
//    Pop - Runs the GA
//    Problem - fitness and primitive functions


#include "pch.h"
#include "chrome.h"

// Global variables
char scratch[100];

#ifdef FASTEVAL
	// Global evaluation variables.  Eliminates parameter passing
	// If you can get IpGlobal into a register, you will run near the speed
	// limit for S-expression evaluation
	Chrome * ChromeGlobal;                  // currently evaluating Chrome
	evalnode ExprGlobal[EXPRLEN];   // expression expanded to evalnodes
	evalnode * IpGlobal;            // Current instruction pointer
#endif


//**************************************************************************
//////////////////////////////////// Utility functions

void NoMoreMem()		// Out of memory exit
{
	cout << "\nOut of Memory.  Aborting Execution.\n";
	exit(1);
}

int min(int value1, int value2)
   {
	  return ( (value1 < value2) ? value1 : value2);
   };
int max(int value1, int value2)
   {
	  return ( (value1 > value2) ? value1 : value2);
   };

// Comment out if included in your implementation (e.g. Borland)
	// upper case string
char* strupr(char* s)
{
	int i=0;
	while (s[i])
		if (s[i]>='a' && s[i]<='z') s[i]=s[i]-32;
    i++;
	return s;
}

	// compare strings without case sensitivity
int strcmpi(char* s1, char* s2)         // only checks equality
{
	int mismatch=0;
	while (*s1 && *s2 && !mismatch)
	{
		if (*s1>='a' && *s1<='z' && *s2<='Z')
			mismatch = *s1-32 != *s2;               
		else if (*s1>='A' && *s1<='Z' && *s2>='a')
		mismatch = *s1+32 !=*s2;

		else
			mismatch = *s1!=*s2;
		s1++;s2++;
	}
	return mismatch || *s1 || *s2;
}


//**************************************************************************
//////////////Function member function (separated for use in a DLL)
char* Function::getprint(Chrome* chrome)
{
	// NUMBER has its own getprint to write the correct number
	// This is fancy footwork for other functions with operands
	// these are written as <name>_<operand number>
	if (varnum) sprintf(scratch,"%s_%-d",name,VARNUM(chrome->expr[chrome->ip]));
	return (varnum? scratch : name);
}



//**************************************************************************
/// Chrome functions ///////////////////////////////////////////

Chrome::Chrome(ChromeParams* p,CSelector* cf,Problem* pr,Function** f,retval* c,BOOL doinit) {
// initialize a expr using the functions in array f

	int depth = p->params[pInitExpr];
	funcbag=cf;
		params = p;
	probl = pr;
	funclist = f;
	constlist = c;
	MaxExpr=params->params[pMaxExpr];
	ExprBytes=MaxExpr*sizeof(node);
	expr=new node[MaxExpr];
    if (expr==NULL) NoMoreMem();		// Out of memory?
	ip=0;
	funccount = params->funccount;          // how many primitives?
	
	birth = 0;
	if (doinit)
	{
		// DO "ramped half and half from 2 to depth"
		if (depth > 0)
		{
						SubInit(1,rnd(depth-1)+1,rnd(2));       // go to some depth less than max, full or half full
		}
		else
			SETNODE(expr[ip],0,0);                                  // stick in a stub constant
	}
		nfitness  = probl->GetFitnessObj();
		// allocates a FitnessValue object;  GetFitnessObj  calls new
}

Chrome* Chrome::Copy()
{
	Chrome* nw=new Chrome(params,funcbag,probl,funclist,constlist,FALSE);
	if (nw==NULL) NoMoreMem();		// Out of memory?
	nw->Dup(this);
	return nw;
}

void Chrome::Dup(Chrome* source)                // make a copy nondestructively
{
	funcbag=source->funcbag;
	params=source->params;
	funclist=source->funclist;
	funccount=source->funccount;
		constlist=source->constlist;
	
		memcpy(expr,source->expr,ExprBytes);
	nfitness->Copy(source->nfitness);
	ip=0;
}

retval Chrome::evalAll() // eval the whole expression anew
{
#ifndef FASTEVAL
	ip=-1;
	return eval();
#else
	
	IP=ExprGlobal;
	//cout<<"FUNC="<< IP->op;
	return (IP->ef)();
#endif
}

void Chrome::SetupEval()
{
#ifdef FASTEVAL
		// expand stack into evalnodes in global eval stack
	int args;
	node* spp=expr;
	evalnode* ip=ExprGlobal;
	args=1;
	while (args > 0)
	{
		SETEVALNODE(ip,spp->op,spp->idx);
		args=args+PARGNUM(spp)-1;
		ip++;
		spp++;
	}
		// set global eval pointers
	ChromeGlobal=this;
#endif
}

void Chrome::SubInit(int argstogo,int depth,int isfull)     // Initialize a subtree half full
{
	int i;
	int maxargs,thisargs;
	maxargs = MaxExpr -(ip+argstogo);       // max number of args to add
	i=funcbag->roulette();

	// terminal required
	if (maxargs == 0 || depth == 0 )
		while (funclist[i]->argnum>0) i=funcbag->roulette();

	// node required
	else if (isfull || ip==0)
		if (maxargs > 5)
			while (funclist[i]->argnum == 0) i=funcbag->roulette();
		else                    // not enough room.  Take what you can get.
			while (funclist[i]->argnum>maxargs) i=funcbag->roulette();

	// terminal allowed 50% of the time
	else
		if (rnd(2))             // terminal required
			while (funclist[i]->argnum>0) i=funcbag->roulette();
		else            // node required
			if (maxargs > 5)
				while (funclist[i]->argnum == 0) i=funcbag->roulette();
			else                    // not enough room.  Take what you can get.
				while (funclist[i]->argnum>maxargs) i=funcbag->roulette();

	SETNODE(expr[ip],i,rnd(funclist[i]->varnum));
	ip++;
	thisargs=funclist[i]->argnum;
	argstogo += funclist[i]->argnum-1;

	for (i=0;i<thisargs;i++)
	{
		SubInit(argstogo,depth-1,isfull);
		argstogo--;
	}
}

void Chrome::Traverse() {             // skip the next expression
	int args = 1;
	while (args > 0)
	{
				 args=args+ARGNUM()-1;
				 ip++;
	}
}


void Chrome::TraverseGlobal() {             // skip the next expression
	int args = 1;
	while (args > 0)
	{
				 args=args+PARGNUM(IP)-1;
				 IP++;
	}
}

				// Write the next subexpression to a stream
				// pretty flag controls parentheses, indenting
				// PRETTY_NONE = no indenting, just a stream, with parens
				// PRETTY_NOPARENS = indented, one function per line, no parens
				// PRETTY_PARENS = indented, one function per line, parens
void Chrome::SubWrite(ostream& ostr,int pretty) {
	int args,i;
	ip++;
	args = ARGNUM();
	if (pretty)                                     // indent?
	{
		ostr<< '\r' << '\n';
		for (i=0;i<depth;i++){
				ostr << " : ";
		}
	}
	else
		ostr << ' ';
	if (args>0)
	{                               // write (FUNC args)
		if (pretty != PRETTY_NOPARENS)
			ostr << '(';
		ostr << funclist[FUNCNUM(expr[ip])]->getprint(this);
		depth++;
		while (args-- > 0) SubWrite(ostr,pretty);
		depth--;
		if (pretty != PRETTY_NOPARENS)
			ostr << ")";
	}
	else {                          // write an atom
		ostr << funclist[FUNCNUM(expr[ip])]->getprint(this);
	}
}

Chrome* Chrome::CrossTree(Chrome* mate)
// Return a new Chrome that is a cross with mate

{
		Chrome* newexpr = Copy();
	int thislen;        // total length of expression
	int thissubptr;     // pointer to subexpression
	int thissublen;
	int matelen;
	int matesubptr;
	int matesublen;
	thislen=SubLen(0);
	matelen=mate->SubLen(0);
	if (rnd(101)>params->params[pUnRestrictWt])
	{
		thissubptr=GetIntNode();
		matesubptr=mate->GetIntNode();
	}
	else
    {
		thissubptr=GetAnyNode();
		matesubptr=mate->GetAnyNode();
	}
	thissublen = SubLen(thissubptr);
	matesublen=mate->SubLen(matesubptr);

	if (thislen+matesublen-thissublen > MaxExpr){      // take smaller side of swap
		memcpy(newexpr->expr,mate->expr,matesubptr*sizeof(node));
		memcpy(&(newexpr->expr[matesubptr]),&(expr[thissubptr]),thissublen*sizeof(node));
		memcpy(&(newexpr->expr[matesubptr+thissublen]),&(mate->expr[matesubptr+matesublen]),(matelen-(matesubptr+matesublen))*sizeof(node));
	}
	else {
		memcpy(newexpr->expr,expr,thissubptr*sizeof(node));
		memcpy(&(newexpr->expr[thissubptr]),&(mate->expr[matesubptr]),matesublen*sizeof(node));
		memcpy(&(newexpr->expr[thissubptr+matesublen]),&(expr[thissubptr+thissublen]),(thislen-(thissubptr+thissublen))*sizeof(node));
	}
	return newexpr;
}

int Chrome::GetAnyNode()                // get a node for crossover
{
	return rnd(SubLen(0));
}

int Chrome::GetIntNode()                // get an internal node for crossover
{
	int rval;
	int l=SubLen(0);
	if (l>2)
	{
		rval=rnd(l);
		while (funclist[FUNCNUM(expr[rval])]->argnum <1)
			rval=rnd(l);
	}
	else
		rval=0;
	return rval;
}

				// Mutate the current Chrome
void Chrome::Mutate()                   // mutate nodes with rate r
{
		int end,i,args;
	int rate=params->params[pMuteRate];
	ip=0;
	Traverse();
	end=ip;
	ip=0;
	while (ip<end)
	{
		if (rnd(1024) < rate)
		{
			args=ARGNUM();
			i=funcbag->roulette();
			while (funclist[i]->argnum!=args) i=funcbag->roulette();
			SETNODE(expr[ip],i,rnd(funclist[i]->varnum));
		}
		ip++;
	}
}


void Chrome::MutateC()                  // jiggle constants with a random walk 
{
	int i,end,newconst;
	int oldconst;
	int radius=8;
	ip= 0;
	Traverse();
	end=ip;
	ip=0;
	while (ip<end)
	{
				if (FUNCNUM(expr[ip])==0)
		{
			oldconst=VARNUM(expr[ip]);
			newconst=oldconst;
			for (i=0;i<radius;i++)
				newconst+=rnd(2);
			newconst-=radius/2;
			newconst=min(CONSTARRAYSIZE-1,max(newconst,0));
			if ((constlist[oldconst]>100 && constlist[newconst]<0) || (constlist[oldconst]<-100 && constlist[newconst]>0))  // overrun?
		newconst=oldconst;
			SETNODE(expr[ip],0,newconst);
		}
	ip++;
    }
}


void Chrome::MutateShrink()             // shrink by promoting a subtree
{
	int tree,treelen,subtree,subtreelen,l;
	node *temp;
	int argnum;
	argnum=0;
	l=SubLen(0);
	if (l>argnum+1)
    {
		// node required
		temp = new node[MaxExpr];
		if (temp==NULL) NoMoreMem();		// Out of memory?
		tree=rnd(l);
		while (funclist[FUNCNUM(expr[tree])]->argnum == 0) tree=rnd(l);

		// now pick a subtree
		treelen=SubLen(tree);
		subtree=tree+rnd(treelen-1)+1;
	subtreelen=SubLen(subtree);

		memcpy(temp,expr,l*sizeof(node));               // save the old expr
		memcpy(expr+tree,temp+subtree,subtreelen*sizeof(node)); // add the subtree
		memcpy(expr+tree+subtreelen,temp+tree+treelen,sizeof(node)*(l-(tree+treelen)));         // add the rest
		delete[] temp;
    }
}

int Chrome::Load(istream& ifile,int issource)
// Load an expression from a stream
// issource should always be TRUE

{
	int x,tempop, tempidx;
	int rval=LOAD_OK;
	node* buf;

	if (!issource)
	{
		for(x=0;x<MaxExpr;x++)
		{
			ifile >> tempop;
			expr[x].op =(unsigned) tempop;
			ifile >> tempidx;
			expr[x].idx=(unsigned) tempidx;
		}
	}
	else            // load a Source file
	{
		ip=0;
		buf=new node[MaxExpr];
		if (buf==NULL) NoMoreMem();		// Out of memory?
		if ((rval=SubLoad(ifile,buf)) == LOAD_OK)
		{
			delete[] expr;
			expr=buf;
		} else
			delete[] buf;
	}
	return rval;
}

#define EATSPACE c=istr.peek();while(isspace(c)||c==':') {istr.get();c=istr.peek();}
#define GETTOK tp=0;c=istr.peek();while(c!=EOF && !isspace(c) && c!=':' && c!='(' && c!=')' &&tp<79) {scratch[tp++]=istr.get(); c=istr.peek();} scratch[tp]='\0'

int Chrome::SubLoad(istream& istr,node* buf)
// load a sub-expression from source format
// Return LOAD_OK or an error value
// text expression is in istr
// nodes go into buf

{
	int rval = LOAD_OK;
	char c;
//      char token[80];
	int tp;
	int func;
	int args;
	int vnum;
	char* s;
	scratch[0]='\0';
	EATSPACE;
	if (istr.peek()==')' || istr.peek()==EOF)
	{
		rval=LOAD_TOOFEW;                       // missing expression body
	}
	else if (ip>=MaxExpr)
	{
		rval=LOAD_TOOLONG;
	}
	else if (istr.peek()=='(')              // Get an expression and the close paren
	{
		istr >> c;
		rval = SubLoad(istr,buf);
		if (rval==LOAD_OK)
	{
			EATSPACE;
			istr >> c;
			if (c!=')')
				rval=LOAD_TOOMANY;
	}
	}
	else                            // Get an expression.  Return if you hit a close paren.
	{
		GETTOK;
		if (strlen(scratch)==0)
			rval=LOAD_TOOFEW;
		else
		{
			if (isdigit(scratch[0]) || scratch[0]=='-')     // it's a number.  Function 0
			{
				func=atoi(scratch);
				if (func>=0-CONSTARRAYSIZE/2 && func<CONSTARRAYSIZE/2)
				{
					SETNODE(buf[ip],0,func+CONSTARRAYSIZE/2);
					ip++;
					rval=LOAD_OK;
				}
				else rval=LOAD_BADCONST;
			}
			else       // look up a function name
			{
				vnum=0;
				if (strchr(scratch,'_')!=NULL)
				{
					// parse it to take off the variable number?
					// This is fancy footwork for functions with operands
					// Except for NUMBER (function 0) these functions are
					// written as <name>_operand
					s=strrchr(scratch,'_');
					if (strchr("0123456789",s[1]))  // it is an underscore followed by numbers

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
成人精品鲁一区一区二区| 日本网站在线观看一区二区三区 | 亚洲第一在线综合网站| 99国产精品99久久久久久| 中文字幕亚洲不卡| 91免费视频网址| 一区二区三区精密机械公司| 在线观看日韩毛片| 亚洲成av人片| 精品国产伦理网| 大胆亚洲人体视频| 亚洲精品伦理在线| 欧美久久久一区| 精品在线一区二区三区| 欧美激情一区三区| 色先锋久久av资源部| 亚洲成人激情av| 精品卡一卡二卡三卡四在线| 国产aⅴ综合色| 一区二区三区久久久| 欧美一区二区视频在线观看2022| 国产剧情av麻豆香蕉精品| 亚洲国产岛国毛片在线| 99re66热这里只有精品3直播| 亚洲午夜久久久久久久久电影院 | 婷婷开心久久网| 久久嫩草精品久久久精品| gogogo免费视频观看亚洲一| 亚洲制服丝袜在线| 亚洲精品一区二区三区影院| av爱爱亚洲一区| 免费观看成人鲁鲁鲁鲁鲁视频| 久久久国产午夜精品| 91国产免费看| 国产高清精品网站| 亚洲一区二区综合| 精品国产第一区二区三区观看体验| eeuss鲁一区二区三区| 日韩福利电影在线| 日韩伦理av电影| 日韩欧美国产成人一区二区| 色先锋aa成人| 国产在线视频不卡二| 亚洲综合色区另类av| 久久久亚洲高清| 777久久久精品| 色伊人久久综合中文字幕| 韩国成人精品a∨在线观看| 亚洲专区一二三| 亚洲国产成人一区二区三区| 日韩一区二区免费高清| 在线中文字幕不卡| 豆国产96在线|亚洲| 免费看欧美女人艹b| 一区二区成人在线| 18成人在线观看| 国产欧美日韩激情| 亚洲精品一线二线三线| 制服丝袜日韩国产| 在线亚洲精品福利网址导航| av电影在线观看一区| 国产一区二区免费在线| 日本成人中文字幕在线视频| 亚洲第一精品在线| 亚洲综合一区二区精品导航| 成人免费一区二区三区在线观看| 久久亚洲精精品中文字幕早川悠里| 91.com在线观看| 欧美美女直播网站| 欧洲av一区二区嗯嗯嗯啊| 91视频观看免费| 91视频免费看| 色噜噜狠狠色综合中国| 91视频免费播放| 色综合网色综合| 91美女片黄在线| 在线免费观看不卡av| 色综合欧美在线| 色先锋aa成人| 欧美私模裸体表演在线观看| 欧美亚洲一区二区在线观看| 欧美影院精品一区| 欧美三级日韩在线| 91精品国产一区二区| 欧美一区二区大片| 欧美精品一区二区三区在线播放 | 色综合一区二区| 色综合久久久网| 在线观看区一区二| 欧美美女黄视频| 日韩欧美一区二区在线视频| 亚洲精品一区二区三区影院| 久久久美女艺术照精彩视频福利播放| 久久综合九色综合97婷婷| 久久精品视频在线免费观看| 国产精品亲子伦对白| 中文字幕一区二区三区不卡| 亚洲三级视频在线观看| 亚洲国产欧美在线人成| 石原莉奈在线亚洲二区| 美女视频黄免费的久久| 国产精品综合在线视频| av电影在线观看不卡| 欧美三日本三级三级在线播放| 91精品中文字幕一区二区三区| 欧美tickle裸体挠脚心vk| 亚洲国产成人午夜在线一区 | 欧美专区亚洲专区| 欧美一区欧美二区| 国产欧美日韩一区二区三区在线观看| 中文字幕日韩一区| 日韩中文字幕av电影| 国产精品白丝av| 在线视频欧美精品| 精品国产第一区二区三区观看体验| 国产精品视频免费看| 午夜精品久久久久久| 国产在线精品免费av| 91老师国产黑色丝袜在线| 777精品伊人久久久久大香线蕉| 国产午夜精品久久久久久免费视| 亚洲欧美日韩国产手机在线| 香蕉加勒比综合久久| 国产一区二区成人久久免费影院| 91首页免费视频| 欧美精品一区二区在线观看| 亚洲精品老司机| 国产一区二区免费看| 在线观看日韩电影| 国产女人18水真多18精品一级做| 一区二区欧美精品| 国产成人免费在线| 欧美日韩一区二区三区四区| 2020国产成人综合网| 亚洲国产成人av好男人在线观看| 久久国产福利国产秒拍| 色婷婷av久久久久久久| 久久久久久久国产精品影院| 一级日本不卡的影视| 丰满亚洲少妇av| 日韩一区二区三区四区| 尤物av一区二区| 成人涩涩免费视频| 日韩欧美国产一区在线观看| 亚洲精品中文在线影院| 成人综合在线视频| 欧美一级二级三级蜜桃| 一区二区久久久| 91丝袜高跟美女视频| 国产网红主播福利一区二区| 秋霞影院一区二区| 91国偷自产一区二区三区成为亚洲经典 | 日韩欧美的一区二区| 亚洲高清免费视频| 色狠狠综合天天综合综合| 国产精品全国免费观看高清 | 欧美天堂一区二区三区| 亚洲欧美在线aaa| 成人午夜电影网站| 久久久不卡网国产精品二区| 精品系列免费在线观看| 日韩视频在线一区二区| 日韩精品国产欧美| 欧美肥妇bbw| 亚洲成人777| 这里只有精品99re| 日本女人一区二区三区| 欧美精品视频www在线观看| 亚洲国产综合91精品麻豆| 91免费国产在线观看| 亚洲精品日韩综合观看成人91| 91视频在线观看| 亚洲最色的网站| 欧美调教femdomvk| 天堂蜜桃91精品| 日韩午夜激情av| 久草中文综合在线| 日本一二三不卡| eeuss鲁片一区二区三区| 国产精品久久午夜夜伦鲁鲁| 不卡在线视频中文字幕| 亚洲欧美区自拍先锋| 欧美视频在线不卡| 日韩国产欧美视频| 精品动漫一区二区三区在线观看| 国产一区高清在线| 中文字幕一区二区三区不卡| 91九色02白丝porn| 日韩黄色免费电影| 26uuu精品一区二区三区四区在线| 国产一区日韩二区欧美三区| 中文字幕欧美日本乱码一线二线 | 久久精品免费观看| 久久青草欧美一区二区三区| 波多野结衣在线aⅴ中文字幕不卡| 国产精品成人一区二区艾草| 欧美日韩美女一区二区| 麻豆成人综合网| 国产精品久久久久久久久动漫| 欧美最猛性xxxxx直播|