⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 brack.cc

📁 标准的GP源代码,由Andy Singleton维护
💻 CC
📖 第 1 页 / 共 2 页
字号:
// brack.cc   File to demonstrate evolution of cfg, build with GPQUICK-2.1// W. Langdon cs.ucl.ac.uk 24 Sep 1995 $Revision: 1.29 $//                     based upon list.cc Revision: 1.86//#define DEBUG //Modifications (in reverse order)//WBL 15 Apr 97  Tidy to keep DEC Alpha cxx compiler quiet//WBL 25 Nov 95  Restore cpu_penalty for start of run as before (cf r1.19)//WBL 21 Nov 95  Restrict problem specific primitives (ifmatch and ifopen)//               and ARG1 and Set_Aux1 to rpb//WBL 21 Nov 95  BUGFIX ensure Memory_Errors is cleared//WBL 20 Nov 95  BUGFIX ensure adf1 has no arguments//               Add third adf//WBL 20 Nov 95  BUGFIX ensure cpu penalty is applied to 1st sol as well//WBL 19 Nov 95  Implment TIMINGS in ifmatch, ifopen, ifempty//               Remove cpu penalty (before solution found)//WBL 19 Nov 95  Try including ifmatch and ifopen, recode -5,-13,-31,-43 as//               71,103,137,167//WBL 19 Nov 95  BUGFIX Use sol_found when calculating cpu penalty//               Restore ADD, SUB, ifeq, iflte, makenull, empty//                 and remove ifmatch, ifempty, ifopen//WBL  8 Nov 95  Replace ADD and SUB by ifmatch//WBL  8 Nov 95  Replace bracket codes 1,2,3,4 with 5,13,31,43//WBL 4,6 Nov 95  BUGFIX allow loading of saved population which contains a//               solution by ensuring update_population_fitness does not crash//               when called before the whole population's fitness is known//WBL 31 Oct 95  Ok now go back to plain read/write but//               two adfs, no caches, no by ref.//               Use stack.cc primitives (but replace write_aux by set_aux and//               call ...aux1 rather than ...aux//               Remove forwhile loops//WBL 23 Oct 95  Convert to using stack primitives.//WBL 20 Oct 95  Add 2 more adfs, Allow some adfs to read input symbol directly//WBL 18 Oct 95  Display test_seed//WBL 17 Oct 95  Take number of tests run into account when setting cpu penalty//WBL 15 Oct 95  Add IsBranch//               Restore using cpu as pareto penalty//WBL  6 Oct 95  Now use for karp too//               Give adf1 a simple argument//               Disable static_check//WBL 29 Sep 95  BUGFIX ensure mem_used is always set (Nb various parts of//               myfitnessvalue are not cleared at the start of fitness testing//WBL 27 Sep 95  Set Memory_Errors//requires MULTREE to be defined#include <assert.h>#include "pch.h"#include "chrome.h"#include "primitiv.h"#ifdef TRACE_RUN#include "trace.h"#endif#ifdef TIMINGS#include "time.h"#endif#include "Primitives.h"#include "gp.h"#include "test.h"#ifdef KARP2#include "stack_prim.h"#endif#ifdef KARP#ifdef KARP2#define version "karp2. $Revision: 1.29 $"#else#define version "karp. $Revision: 1.29 $"#endif#else#define version "brack. $Revision: 1.29 $"#endifextern char scratch[100];#ifdef FASTEVAL	extern evalnode* IpGlobal;	extern Chrome* ChromeGlobal;#endifextern Pop*  ThisPop;extern test* ThisTest;const int tree_arg_num[last_op+1] = {1};const BOOL tree_return_value[last_op+1] =                        {TRUE};int num_sol_found = 0;//used to report solution to each test phase foundBOOL sol_found = FALSE;//used to report 1st total solution found                       //Once found there are no thresholds on mem or cpu usageBOOL current_phase_reported = FALSE;//Used by gen_gens                       //should be in dumpfile but ignore this for time being //**************************************************************************void write_problem_params(){cout<<store_limit<<"["<<Array_bot<<".."<<Array_top<<"] ";cout<<mem_penalty_bot<<" "<<cpu_penalty_bot<<endl;}// Define your FitnessValue classvoid myfitnessvalue::write(ostream& fout){	{char buf[80]; sprintf(buf,"%4d",int(fvalue));	 fout << buf;}#ifdef PARETO        scoretype total = 0;	fout << " {";	for (int i=first_op; i <= last_op; i++)		{ total += hits[i];		  char buf[80]; sprintf(buf,"%4d",hits[i]);		  fout << buf << ",";	        }	fout << "[";	for (i=0; i < NUM_OTHERS; i++)		{ char buf[80]; sprintf(buf,"%4d",hits[i+last_op+1]);		  fout << buf;		  if (i < NUM_OTHERS-1 ) fout << ",";	        }	fout << "]}= " << total;#endif	fout << " mem " << int(mem_used);	fout <<","<<Memory_errors();#ifdef MINC_ADF	fout << " adf1ver " << adf1;#endif#ifdef TIMINGS	fout << " cpu " << cpu_time;#endif	fout << " tests " << Ntests_run;	fout << " seed " << test_seed;#ifdef TRACE_RUN	fout << " (";	int notrun[NUM_TREES];	missed(this, notrun);	for (i=0; i < NUM_TREES; i++)		{ char buf[80]; 		  sprintf(buf,"%4d", ok(i)); fout << buf;		  {if(Tree_OK(this,i))			   fout<<"K"; else fout<<"-";}		  sprintf(buf,"%-4d",nak(i)); fout << buf;		  sprintf(buf,"%-4d",notrun[i]); fout << buf;		  	        }	fout << ")";#endif}//end myfitnessvalue::writevoid cache_init(){}void cache_stats_init(){}void cache_stats(){}//**************************************************************************///////////////////////// PROBLEM definition#ifndef KARP2OPDEF(Adf1Eval)     {return calleval (0, adf1);}OPDEF(Adf2Eval)     {return calleval (1, adf2);}OPDEF(Adf3Eval)     {return calleval (0, adf3);}#endif /*KARP2*/OPDEF(ifmatchEval){//if matching brackets dothis else dothat	retval r1 = EVAL;	switch(r1){	case  5: case 13: case 31: case 43: //opening bracket#ifdef TIMINGS		ThisTimmer->opt_time(IP);#endif		retval r2 = EVAL;		if((r1== 5&&r2== 71)||                   (r1==13&&r2==103)||                   (r1==31&&r2==137)||                   (r1==43&&r2==167)   ) { //matching closing bracket#ifdef TIMINGS		ThisTimmer->opt_time(IP);#endif			retval r3 = EVAL;			IP++;           // Jump the expression			TRAVERSE();			IP--;           // back up one (since EVAL increments)			return r3;		}		else {			IP++;           // Jump the expression			TRAVERSE();			IP--;           // back up one (since EVAL increments)#ifdef TIMINGS		ThisTimmer->opt_time(IP);#endif			return EVAL;		}	default:		IP++;           // Jump the 2nd arg		TRAVERSE();		IP--;           // back up one (since EVAL increments)		IP++;           // Jump the 3rd arg		TRAVERSE();		IP--;           // back up one (since EVAL increments)#ifdef TIMINGS		ThisTimmer->opt_time(IP);#endif		return EVAL;	}}#ifdef KARP2OPDEF(ifemptyEval){//if stack is empty dothis else dothat	retval r1 = emptyEval();	if(r1==0){#ifdef TIMINGS		ThisTimmer->opt_time(IP);#endif			retval r3 = EVAL;			IP++;           // Jump the expression			TRAVERSE();			IP--;           // back up one (since EVAL increments)			return r3;		}		else {			IP++;           // Jump the expression			TRAVERSE();			IP--;           // back up one (since EVAL increments)#ifdef TIMINGS		ThisTimmer->opt_time(IP);#endif			return EVAL;		}}#endif /*KARP2*/OPDEF(ifopenEval){//if open bracket dothis else dothat	retval r1 = EVAL;	switch(r1){	case  5: case 13: case 31: case 43: //opening bracket#ifdef TIMINGS		ThisTimmer->opt_time(IP);#endif		retval r3 = EVAL;		IP++;           // Jump the expression		TRAVERSE();		IP--;           // back up one (since EVAL increments)		return r3;	default:		IP++;           // Jump the 2nd arg		TRAVERSE();		IP--;           // back up one (since EVAL increments)#ifdef TIMINGS		ThisTimmer->opt_time(IP);#endif		return EVAL;	}}OPDEF(AEval)    {return   5;}OPDEF(A_Eval)   {return  71;}OPDEF(BEval)    {return  13;}OPDEF(B_Eval)   {return 103;}OPDEF(CEval)    {return  31;}OPDEF(C_Eval)   {return 137;}OPDEF(DEval)    {return  43;}OPDEF(D_Eval)   {return 167;}int Adf1_Insert_funcnum = -1;int Adf1_Delete_funcnum = -1;int Adf1_Locate_funcnum = -1;int Adf1_Printlist_funcnum = -1;int ifeq_funcnum = -1;int iflte_funcnum = -1;int ifopen_funcnum = -1;int ifmatch_funcnum = -1;int ifempty_funcnum = -1;gp::gp():i0_funcnum(0),         for_funcnum(0),	 down_funcnum(0),	 while_funcnum(0),	 forwhile_funcnum(0), 	 arg1_funcnum(0),	 arg2_funcnum(0),	 ARG1_funcnum(0),	 ARG2_funcnum(0),	 FUNC_funcnum(0), 	 print_funcnum(0){//cout<<"gp::gp"<<endl;//debug	ProbVersion = version;	assert ( NUM_TREES >= NUM_OPERATIONS );	AddF(new ConstFunc(0));    // REQUIRED as function 0	// Add some standard primitives	AddFall(new AddFunc(100));	AddFall(new SubFunc(100));#ifdef KARP	AddF1(rpb,new Function(4,0,100,ifmatchEval,"ifmatch"));        ifmatch_funcnum=funccount-1;#endif        AddFall(new Function(2,0,100,Prog2Eval,"PROG2"));	AddFall(new IflteFunc(100));        iflte_funcnum=funccount-1;	AddFall(new Function(4,0,100,IfeqEval,"Ifeq"));        ifeq_funcnum=funccount-1;#ifndef KARP	AddFall(new Function(0,0,100,NegoneEval,"-1"));#else	AddF1(rpb,new Function(3,0,100,ifopenEval,"ifopen"));        ifopen_funcnum=funccount-1;//	AddFall(new Function(2,0,100,ifemptyEval,"ifempty"));//	ifempty_funcnum=funccount-1;#endif	AddFall(new Function(0,0,100,zeroEval,"0"));	AddFall(new Function(0,0,100,oneEval,"1"));#ifdef KARP//	AddFall(new Function(0,0,100,AEval,   "5"));//	AddFall(new Function(0,0,100,A_Eval, "-5?"));//	AddFall(new Function(0,0,100,BEval,  "13"));//	AddFall(new Function(0,0,100,B_Eval,"-13?"));//	AddFall(new Function(0,0,100,CEval,  "31"));//	AddFall(new Function(0,0,100,C_Eval,"-31?"));//	AddFall(new Function(0,0,100,DEval,  "43"));//	AddFall(new Function(0,0,100,D_Eval,"-43?"));#endif	AddFall(new Function(0,0,100,MaxEval,"max"));//	AddFall(new Function(0,0,100,BotEval,"bot"));//	AddFall(new Function(0,0,100,BotEval,"bot"));//	AddFall(new Function(0,0,100,TopEval,"top"));#ifdef KARP2	AddFall(new Function(0,0,100,Aux1Eval,"aux1"));	AddFall(new Function(0,0,100,ARG1Eval,"ARG1"));	new stack_prim(100); //delete when prog aborts	AddFall(new Function(0,0,100,makenullEval,"Makenull"));	AddFall(new Function(0,0,100,emptyEval,   "Empty"));	AddFall(new Function(0,0,100,topEval,     "Top"));	AddFall(new Function(0,0,100,popEval,     "Pop"));	AddFall(new Function(1,0,100,pushEval,    "Push"));//	AddF4(adf1,adf2,adf3,adf4, new Function(0,0,100,Arg1Eval,"arg1"));//        arg1_funcnum=funccount-1;//        AddF1(adf2,new Function(0,0,100,Arg2Eval,"arg2"));//        arg2_funcnum=funccount-1;//	AddF3(rpb,adf1,adf3, new Function(1,0,100,readEval,"read"));//	AddF3(rpb,adf1,adf3, new Function(2,0,100,writeEval,"write"));//	AddF3(rpb,adf1,adf3, new Function(2,0,100,swapEval,"swap"));	AddFall(new Function(1,0,100,set_Aux1Eval,"Set_Aux1"));//	AddF3(rpb,adf1,adf3, new Function(1,0,100,Adf2Eval,"adf2"));//	AddF3(rpb,adf1,adf3, new Function(1,0,100,Adf4Eval,"adf4"));//	AddF1(rpb,           new Function(1,0,100,Adf1Eval,"adf1"));//	AddF2(rpb,adf1,      new Function(1,0,100,Adf3Eval,"adf3"));////	AddF4(Insert,Locate,Delete,Printlist,//              new Function(3,0,100,ForEval,"for"));//        for_funcnum=funccount-1;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -