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

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

?? antprob.cpp

?? 一個GP遺傳編程的源程序
?? CPP
字號:
// 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
// sample GP problem file
// Compatible with problem DLL's for the GP-GIM professional GP system
// ANTPROB Artificial Ant traversing a trail of food
// Implementation by Georg Fuellen
// Includes main function
// This problem requires the file SANTAFE.TRL or equivalent 32x32 ascii trail file

// The ARTIFICIAL ANT problem was originally created by Jefferson and Collins et al
// as part of their experiments in evolution using a 64K processor CM2.
// They created the "Santa Fe Trail" and used a binary string GA to evolve
// a finite automata that could traverse the trail.
// John Koza adapted this problem to genetic programming and reported his
// results at the A-LIFE II conference.  This problem attempts to be a
// faithful reproduction of Koza's experiment.  For more information, see
// the Koza article in A-LIFE II or the Koza "GENETIC PROGRAMMING" book.
// The artificial ant problem is a popular benchmark of the
// GA learning mechanism.
// The artificial ant problem is a fairly easy problem because the trail
// never changes.  This is another reason it makes for a convenient experiment.
// You can make it harder, however, by designing trails with less food.
// For real extra credit, try moving the trail around between evals.

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

extern char scratch[100];
#ifdef FASTEVAL
	extern evalnode* IpGlobal;
	extern Chrome* ChromeGlobal;
#endif


//**************************************************************************
// Define your Problem class

class AntProb : public Problem {
public:
	AntProb(ChromeParams* p);               // initialize functions, parameters, and data
	float fitness(Chrome* chrome);  // Driving ingredient - GP fitness function
};


//**************************************************************************
// static variables that make up the evaluation environment
// Build your environment here as statics
// where the evaluation functions can get to the data
#define Grid_Horizontal 32
#define Grid_Vertical  32


unsigned char Grid[Grid_Horizontal][Grid_Vertical];
unsigned char LoadedGrid[Grid_Horizontal][Grid_Vertical];
#define START_ENERGY 600;
int energy=START_ENERGY;
int direction=0;
int xx=0; //position of the ant
int yy=0;

//**************************************************************************
// Data handling functions

retval FoodAhead()
{
	retval rval=0;
	switch(direction)
	{
		
		case 0:           /* is food on the right ?? */
			rval=( ( xx < Grid_Horizontal-1 ) && ( Grid[xx+1][yy] == '8' ) );
	    break;
		case 1:        /* is food up  ?? */
			rval=( ( yy > 0 ) && ( Grid[xx][yy-1] == '8' ) );
		break;
		case 2:    /* is food on the left ?? */
			rval=( ( xx > 0 ) && ( Grid[xx-1][yy] == '8' ) );
		break;
		case 3:  /* is food down ?? */
			rval=( ( yy < Grid_Vertical-1 ) && ( Grid[xx][yy+1] == '8' ) );
		break;
	}
    return rval;
}

int Reset()
{
	energy=START_ENERGY;
	direction=0;
    xx=0;
	yy=0; //position of the ant
    return 0;
}

int CopyGrid()
{
	int i,j;

	for (i=0; i<Grid_Horizontal; i++)
	{
		for (j=0; j<Grid_Vertical; j++)
		{
			Grid[i][j]=LoadedGrid[i][j];
		}
	}

	return 0;
}

// Load a GRID_HORIZONTAL column by GRID_VERTICAL row trail (usually 32x32)
// '8' marks the food pieces
BOOL LoadFromFile(char* filename = "santafe.trl")
{
	int i,j;
	char ch;
    int rval=TRUE;
	ifstream inf(filename);
	if (!inf)
	{
		 cerr<<"cannot open"<<filename;
		 rval=FALSE;
	}
    else {
		for (i=0; i<Grid_Vertical; i++)
		{
			for (j=0; j<Grid_Horizontal; j++)
			{
				inf.get(ch); while (ch =='\n' || ch == '\r') inf.get(ch);
				LoadedGrid[j][i]=ch;
			}
		}
    }
	CopyGrid();
	return rval;
    
}

//**************************************************************************
//////////////////////////  Problem specific functions

// Use the OPDEF,EVAL,IP and CURCHROME defines
// and the code will recompile for different eval methods


OPDEF(IfFoodEval)
{
		  retval rval;
		  if (FoodAhead())
		  {
					 rval=EVAL;
					 IP++;           // Jump the second expression
					 TRAVERSE();
					 IP--;           // And back up one (since EVAL increments)
		  }
		  else {
					 IP++;
					 TRAVERSE();    // Jump the first expression
					 IP--;                                   // Back up for EVAL
					 rval=EVAL;
		  }
		  return rval;
}

class IfFoodAhead : public Function {       
public:
	IfFoodAhead() {strcpy(name,"IFFOODAHEAD");argnum=2;varnum=0;weight=100;
	evalfunc=IfFoodEval;};

};
				//
OPDEF(Progn3) {return (EVAL + EVAL + EVAL);}

				//
OPDEF(Left)
{
	retval rval;
	rval=0;
	if ( energy != 0 )
	{
		direction = ( direction + 1 ) % 4;
		energy--;
    }
	return rval;

}

				// 
OPDEF(Right) 
{
	retval rval;
	rval=0;
	if ( energy != 0 )
	{
		direction = ( direction + 3 ) % 4;
		energy--;
    }
	return rval;

}
				//
OPDEF(Move)
{
	retval rval=0;
	if ( energy == 0 ) {
		rval=0;
	}
    else {
	switch ( direction )
	{
		case 0:  //right
			{
				if ( xx < Grid_Horizontal-1 ) xx++;
			break;
			} 
		case 1:  //up
			{
				if ( yy > 0) yy--;
			break;
			} 
		case 2: //left
			{
				if ( xx > 0) xx--;
			break;
			} 
		case 3: //down
		{
				if ( yy < Grid_Vertical-1) yy++;
			break;
		} 
	}
    }
	energy--;
	if ( Grid[xx][yy] == '8' )      /* Note spaces will not be seen as they == 2 */
	{
		Grid[xx][yy] = '+';          /* Eats Food */
		rval = 1;
	}
	else {
		{if (((Grid[xx][yy])=='+')||(Grid[xx][yy]=='*'))
		{Grid[xx][yy] = '*';}
		else {Grid[xx][yy]= '-';}}
		rval= 0;
	}
    return rval;
}


//**************************************************************************
///////////////////////// PROBLEM definition


AntProb::AntProb(ChromeParams* p) : Problem()
{
	AddF(new ConstFunc(0));                         // Required for GPQUICK, but zero weight

	// Problem specific functions
	AddF(new Function(2,0,100,IfFoodEval,"IfFoodAhead"));
	AddF(new Function(3,0,150,Progn3,"Prog3"));
	AddF(new Function(0,0,100,Left,"Left"));
	AddF(new Function(0,0,100,Right,"Right"));
	AddF(new Function(0,0,100,Move,"Move"));

	// Set some parameters
    p->params[pRepeatEval]=0;                   // no need to repeat, same case each time
	p->params[pMuteConstWt]=0;                      // no constants
    // Get to Koza type parameters
    p->params[pMuteWt]=15;                              // less mutation
	p->params[pAnnealMuteWt]=15;                    // disable annealing
	p->params[pAnnealCrossWt] = 0;

	// If you need to load problem specific data for evaluation
	// Or load an environment (a map, a scenario)
	// Do it here
	LoadFromFile("santafe.trl");
}

float AntProb::fitness(Chrome* chrome)
{

	int x,y,stop;
	float f = 0;
	CopyGrid();
	Reset();
	retval answer=0;
	while ( energy > 0 )
	{
		answer+= chrome->evalAll();
	}
	f=answer;
	chrome->nfitness->fvalue=f;
	return f;
}



//**************************************************************************
///////////////////////////////  MAIN

//int main(int, char **)
int EvolveAnt()
// Run with a population of size 2000
// Run for 80,000 evals, or until it finds the answer
// DOS version will exit on keyboard hit
// Every 5 seconds or 1000 evals, print the best answer so far

{
	ChromeParams* params = new ChromeParams();
	Problem* prob=new AntProb(params);
	Pop* pop;

    cout << "\nGPQUICK Artificial Ant Problem\n";

	rndomize();
	pop = new Pop(prob,params,2000);                // population of size 2000

	int done = 0;

	// Do for 80,000 iterations, or until we find the right answer
	//while (pop->gencount<20000l && !done)  // Portable version - not interruptible
	while (pop->gencount<25000l && !done && !kbhit())  // kbhit IS NOT PORTABLE (Borland specific)
	{
		// go for 5 seconds, 1000 evals, or until we get a right answer
		pop->go_until(time(NULL)+5,1000,89);

		// Display the best so far
		cout << "\n\nAfter " << pop->gencount << " generates, #food found = " << pop->BestFitness->fvalue << "\n";
		pop->pop[pop->BestMember]->write(PRETTY_NONE,cout);
		cout.flush();
		
		done = (pop->BestFitness->fvalue >=89);
	}


	// Display the best
	ofstream of("RESULT.TXT",ios::out | ios::app);
	cout << "\n\nFINAL RESULTS...";
	cout << "\nAfter " << pop->gencount << " generates, #food found = " << pop->BestFitness->fvalue << "\n";
	pop->pop[pop->BestMember]->write(PRETTY_NONE,cout);
	cout.flush();
			cout<<"****";pop->pop[pop->BestMember]->SetupEval();
    
			int x,y,stop;
			float f = 0;

	    // Get the track of the best ant
			CopyGrid();
			Reset();
			retval answer=0;
			while ( energy > 0 )
			{
				answer+= pop->pop[pop->BestMember]->evalAll();
			}

	    // Show the track
			f=answer;
			cout << '\n';
			of << '\n';
				for (y=0; y<Grid_Vertical; y++)
				{
					for (x=0; x<Grid_Horizontal; x++)
					{
						cout<<Grid[x][y];
			of<<Grid[x][y];
					}
					cout<<"\n";
		    of<<"\n";
				}

		of<< "\nLegend: (8)=Uneaten Food (+)=Eaten food (-)=Tracks (*)=Multiple Tracks";

			cout<<"\nFitness="<<f << " After " << pop->gencount << " generates";
			of<<"\nFitness="<<f << " After " << pop->gencount << " generates";

			cout<<"\n";pop->pop[pop->BestMember]->write(PRETTY_NONE,cout);
			of<<"\n";pop->pop[pop->BestMember]->write(PRETTY_NONE,of);

			cout << "\nResult in RESULT.TXT";

			of.close();
	delete pop;
	delete prob;
	delete params;
	return done? 1 : 0;
}

int main(int, char **)
{
	int i;
	BOOL done=FALSE;
	// remove comments to collect statistics
//      for (i=0;i<100 && !done;i++)
//    {
		EvolveAnt();
//              done=kbhit();
//      }
	return done? 0 : 1;
}
	

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
播五月开心婷婷综合| 国产精品电影院| 欧美日韩国产首页在线观看| 91麻豆高清视频| 91老司机福利 在线| 丁香婷婷综合色啪| 成人性视频免费网站| 国产不卡在线视频| 波多野结衣中文字幕一区 | 狠狠色狠狠色综合| 久久精品国产免费| 国产精品一区免费在线观看| 国产一区在线不卡| 国产成人在线视频网址| 国产成人精品三级| 成人av网站在线观看| 91蜜桃网址入口| 色综合咪咪久久| 欧美中文字幕一区二区三区亚洲| 欧美视频一区二区| 337p亚洲精品色噜噜噜| 日韩一区二区三区观看| 精品久久久久久久久久久久久久久| 亚洲精品一区二区精华| 中日韩av电影| 一区二区三区日本| 天堂成人国产精品一区| 九九热在线视频观看这里只有精品| 国产剧情一区二区| 91小视频在线| 7777女厕盗摄久久久| 日韩女优av电影在线观看| 国产调教视频一区| 亚洲男人电影天堂| 日本亚洲最大的色成网站www| 黄色日韩网站视频| 91亚洲永久精品| 7777精品伊人久久久大香线蕉完整版 | 国内精品视频一区二区三区八戒| 国产盗摄精品一区二区三区在线| 色综合久久中文综合久久牛| 91精品国产综合久久精品麻豆| 精品欧美乱码久久久久久| 国产精品嫩草影院com| 性欧美大战久久久久久久久| 国产在线不卡视频| 91国偷自产一区二区开放时间 | 波多野洁衣一区| 欧美色爱综合网| 久久久久国产精品麻豆ai换脸| 国产精品久久看| 午夜精品国产更新| 成人av在线电影| 欧美日韩国产首页| 国产精品久久影院| 美女久久久精品| 色琪琪一区二区三区亚洲区| 欧美精品一区二区三| 亚洲精品国产无套在线观| 日韩电影免费在线看| av中文字幕一区| 日韩精品中文字幕在线一区| 亚洲女与黑人做爰| 国产乱人伦偷精品视频免下载| 欧洲精品在线观看| 久久精品日产第一区二区三区高清版| 亚洲自拍偷拍综合| 大尺度一区二区| 精品日韩一区二区三区免费视频| 亚洲一区二区三区精品在线| 国产精品中文有码| 日韩欧美一二三四区| 亚洲国产人成综合网站| www.欧美.com| 久久久久久久久久久电影| 午夜精品一区二区三区电影天堂| 99国产精品久久久久久久久久久| 日韩三级电影网址| 丝袜诱惑制服诱惑色一区在线观看| 成人激情开心网| 久久精品视频一区二区三区| 久久99精品国产| 5月丁香婷婷综合| 夜夜嗨av一区二区三区四季av | 7777精品伊人久久久大香线蕉完整版| 国产精品久久久久久久久免费丝袜| 免费xxxx性欧美18vr| 在线视频国产一区| 国产精品美女久久久久久| 国产一区二区视频在线| 日韩精品专区在线影院观看| 午夜久久久影院| 精品视频在线看| 亚洲一区二区视频在线观看| 91免费版在线| 亚洲欧美成aⅴ人在线观看| 99久久精品一区| 亚洲天堂久久久久久久| eeuss鲁片一区二区三区在线观看| 国产亚洲人成网站| 国产精品99久久久| 国产丝袜欧美中文另类| 国产精品一区二区三区四区| 欧美精品一区二区在线观看| 国内精品久久久久影院一蜜桃| 日韩美女主播在线视频一区二区三区| 免费观看成人av| 日韩一区二区视频| 毛片一区二区三区| 久久先锋影音av| 国产大陆精品国产| 18成人在线视频| 在线精品视频免费观看| 午夜精彩视频在线观看不卡| 欧美精品乱人伦久久久久久| 日韩电影免费在线看| 精品久久久久久久久久久久久久久久久 | 亚洲美女免费视频| 欧美色偷偷大香| 免费成人av在线| 国产日韩av一区| 99视频精品免费视频| 亚洲精品成a人| 欧美人xxxx| 欧美日韩一级大片网址| 首页欧美精品中文字幕| 日韩三级在线免费观看| 国产麻豆91精品| 日韩一区有码在线| 欧美日韩精品一区二区天天拍小说| 婷婷六月综合亚洲| 久久综合久久鬼色| 成人av电影在线观看| 洋洋av久久久久久久一区| 欧美一二区视频| 成人午夜av在线| 亚洲成人一区二区在线观看| 精品国产一区二区三区av性色| 国产黄色精品视频| 伊人夜夜躁av伊人久久| 欧美精品777| 国产福利91精品一区| 一区二区三区四区精品在线视频 | 一区二区日韩av| 91精品视频网| 国产不卡视频在线播放| 亚洲午夜av在线| 久久香蕉国产线看观看99| 色综合天天综合色综合av| 免费成人av在线播放| 国产精品另类一区| 欧美日韩精品欧美日韩精品| 韩国理伦片一区二区三区在线播放| 中文字幕制服丝袜成人av| 欧美一区二区三区在线观看| 国产99精品国产| 视频在线观看91| 中文无字幕一区二区三区| 欧美日韩国产三级| youjizz久久| 久久av资源网| 一区二区三区**美女毛片| 欧美大片在线观看一区二区| 日本道色综合久久| 国产一区激情在线| 亚洲va国产va欧美va观看| 中文字幕巨乱亚洲| 日韩欧美一区在线观看| 色天天综合色天天久久| 国产成人免费在线视频| 午夜精品福利在线| **网站欧美大片在线观看| 精品国产自在久精品国产| 色狠狠色噜噜噜综合网| 懂色一区二区三区免费观看| 久久精品国产成人一区二区三区 | 中文字幕精品一区二区精品绿巨人| 欧美电影影音先锋| 91视频在线看| 国产成人精品免费看| 久久精品国产免费看久久精品| 亚洲一区二区三区在线播放| 国产精品二三区| 久久久久99精品一区| 91精品在线一区二区| 91黄色免费观看| 丁香六月综合激情| 国产一区二区三区免费观看| 日本伊人精品一区二区三区观看方式| 樱桃国产成人精品视频| 国产精品国产成人国产三级| 国产欧美日韩在线观看| 精品欧美乱码久久久久久 | 尤物av一区二区| 亚洲天堂福利av| 国产精品美女久久久久高潮| 久久久久久久久久看片| 久久综合色8888| 欧美精品一区在线观看| 26uuu色噜噜精品一区|