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

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

?? antprob.cpp

?? wang xiao ping 版遺傳算法
?? 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精品国产高清一区二区三区 | 麻豆一区二区99久久久久| 亚洲永久精品国产| 亚洲国产精品人人做人人爽| 五月婷婷激情综合| 精品在线播放午夜| 国产91清纯白嫩初高中在线观看 | 久久久精品综合| 久久噜噜亚洲综合| 亚洲欧洲日产国产综合网| 综合电影一区二区三区| 精品蜜桃在线看| 免费成人在线观看| 美女mm1313爽爽久久久蜜臀| 日本视频中文字幕一区二区三区| 久久国产精品免费| 成人高清视频在线| 欧美视频第二页| 91精品国产欧美一区二区18| 国产性做久久久久久| 国产精品国产自产拍高清av| 午夜精品在线看| 国产美女娇喘av呻吟久久| 91日韩精品一区| 日韩女优制服丝袜电影| 国产精品色眯眯| 亚洲综合男人的天堂| 免费av成人在线| 91日韩在线专区| 国产精品久久久久久久久动漫| 一区二区理论电影在线观看| 国产成人av电影免费在线观看| 蜜臀av亚洲一区中文字幕| 国产一级精品在线| 在线视频一区二区三| 久久久午夜精品| 婷婷国产v国产偷v亚洲高清| 成人精品亚洲人成在线| 8v天堂国产在线一区二区| 中文字幕免费在线观看视频一区| 亚洲国产精品久久一线不卡| 大美女一区二区三区| 欧美一级电影网站| 亚洲曰韩产成在线| 成人免费毛片嘿嘿连载视频| 日韩欧美成人一区二区| 亚洲电影第三页| 日本高清成人免费播放| 中文子幕无线码一区tr| 日韩一区二区高清| 精品视频999| 在线观看成人小视频| 国产日韩欧美麻豆| 亚洲精品乱码久久久久久黑人| 日本va欧美va精品发布| 91久久精品一区二区三| 欧美激情一区二区三区四区| 青青青爽久久午夜综合久久午夜| 在线视频观看一区| 亚洲精品国产一区二区精华液| 国产v日产∨综合v精品视频| 欧美精品一区二区蜜臀亚洲| 国内久久婷婷综合| 精品国产乱码久久久久久影片| 日韩精彩视频在线观看| 日韩一区二区在线看| 日韩av午夜在线观看| 欧美视频完全免费看| 亚洲.国产.中文慕字在线| 久久aⅴ国产欧美74aaa| 欧美成人伊人久久综合网| 日韩电影免费在线观看网站| 欧美剧情电影在线观看完整版免费励志电影 | 日韩在线观看一区二区| 在线不卡免费欧美| 老汉av免费一区二区三区| 日韩欧美国产一二三区| 国产一区二区视频在线播放| 久久久久久久综合日本| 成年人国产精品| 亚洲免费在线看| 欧美日韩免费观看一区二区三区| 亚洲高清中文字幕| 91精品国产综合久久久久久久 | 亚洲色图第一区| 久久99精品国产麻豆婷婷洗澡| 1024亚洲合集| 日韩欧美123| 国产呦精品一区二区三区网站| 久久综合九色综合欧美98 | 日韩成人伦理电影在线观看| 日韩欧美一二三区| 成人综合在线观看| 亚洲国产va精品久久久不卡综合| 欧美电影免费观看完整版| 福利视频网站一区二区三区| 中文字幕一区二区三区在线观看| 欧美亚洲尤物久久| 麻豆精品一区二区三区| 国产精品污www在线观看| 在线观看日韩一区| 久久疯狂做爰流白浆xx| 亚洲免费观看高清完整版在线 | 亚洲欧美韩国综合色| 亚洲色图都市小说| 一区二区三区欧美久久| 国产成人亚洲综合色影视| 亚洲色大成网站www久久九九| 欧美色视频在线观看| 国产乱一区二区| 亚洲国产日韩在线一区模特| 欧美v亚洲v综合ⅴ国产v| 一本到不卡免费一区二区| 久久成人精品无人区| 亚洲激情五月婷婷| 久久亚洲精华国产精华液| 欧美午夜电影一区| 成人高清视频在线观看| 国产在线一区二区| 亚洲gay无套男同| 国产精品无码永久免费888| 日韩一级二级三级精品视频| 91久久精品一区二区三区| 国产精品18久久久久久久网站| 香蕉成人啪国产精品视频综合网| 国产精品毛片a∨一区二区三区| 欧美丝袜丝交足nylons图片| 国产精品国产三级国产aⅴ原创 | 欧美一区二区三区喷汁尤物| 成人性生交大片| 另类中文字幕网| 视频一区欧美精品| 亚洲一区二区黄色| 曰韩精品一区二区| 国产女同性恋一区二区| 日韩免费电影网站| 精品久久久久香蕉网| 69久久夜色精品国产69蝌蚪网| 91成人免费在线| 在线一区二区三区| 色天天综合色天天久久| 色综合天天狠狠| 色先锋资源久久综合| 91亚洲男人天堂| 色拍拍在线精品视频8848| 成人激情开心网| 欧美不卡123| 国产精品夜夜嗨| 亚洲大片精品永久免费| 欧美激情综合五月色丁香小说| 日韩精品专区在线| 精品免费一区二区三区| 久久九九99视频| 亚洲国产高清在线观看视频| 国产精品久久久久永久免费观看| 中文字幕不卡在线播放| 中文字幕综合网| 亚洲韩国一区二区三区| 日韩国产在线一| 国产一区二区三区免费| 国产精品一区三区| 99视频一区二区| 欧美日韩日日夜夜| 日韩欧美一级二级三级久久久| 日韩三级免费观看| 国产人成亚洲第一网站在线播放| 国产精品少妇自拍| 亚洲高清免费观看| 国产一区视频在线看| 91免费视频观看| 3d成人动漫网站| 看片网站欧美日韩| 欧美一级搡bbbb搡bbbb| 日韩欧美精品在线视频| 中文在线免费一区三区高中清不卡| 国产女主播在线一区二区| 亚洲精品乱码久久久久久久久 | 久久精品国产一区二区三区免费看 | 91影视在线播放| 欧美精品丝袜中出| 国产亚洲午夜高清国产拍精品| 中文字幕一区二区三区四区不卡| 不卡视频一二三四| 成人app软件下载大全免费| 欧美体内she精高潮| 欧美高清激情brazzers| 亚洲午夜一区二区| 国产亚洲精品精华液| 亚洲一级二级三级| 日韩三级av在线播放|