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

📄 chrome.h

📁 标准的GP源代码,由Andy Singleton维护
💻 H
📖 第 1 页 / 共 2 页
字号:
// Chrome.h   version to support stack.cc, from GPQUICK-2.1// W.Langdon cs.ucl.ac.uk $Revision: 1.72 $//Modifications (reverse order):// WBL 13 Feb 1997  Add pTournOff// WBL 17 Dec 1996  Add pGenerational, GENERATIONAL and newpop// WBL 16 Dec 1996  Make GatherPstats support tree depth info// WBL 14 Dec 1996  Add pMaxDepth// WBL 14 Jun 1996  Boost EXPRLEN from 1000 to 4500 (for 42 tree S.Wales)// WBL  8 Apr 1996  Add MutateSubTree// WBL 15 Mar 1996  Add hashcode, Chrome::same and DisplayDupStats// WBL  9 Mar 1996  Add FitnessValue::Load and Save for GEN_MEM// WBL 28 Feb 1996  Add Depth and crossfile// WBL 23 Oct 1995  Remove NUM_TREES, PARETO, TRACE, MULTREE, retval to prob.h//                  And BOOL to pch.h// WBL 20 Oct 1995  Increase NUM_TREES to 5 (for 2 more adfs)// WBL 15 Oct 1995  Restore PARETO// WBL 22 Sep 1995  Remove PARETO and set NUM_TREES to 3// WBL 30 Jun 1995  Add ability to dump and restore whole population// WBL 20 Jun 1995  Add ProbLTStat// WBL  1 May 1995  Add DisplayLPstats and GatherPstats// WBL  6 May 1995  Pack Chrome tighter, remove fields which are the same inall// WBL  4 May 1995  Add pStoreFit.//                  Add FitnessValue::update_rank, remove unused arg of Copy//                  cf 23 March 1995// WBL  2 May 1995  Add pDirCrossWt// WBL  1 May 1995  Add DisplayPstats// WBL 26 Apr 1995  Reduce size of population by removing idx from node//                  and evalnode (in the latter boost op from unsigned char to//                  int, as it takes no more space and might be faster)// WBL 18 Apr 1995  Decrement NUM_TREES (for adf2 tree removal)// WBL 17 Apr 1995  Add optional last_tree argument to chrome::write//                  Add pMaxTreeExpr// WBL  8 Apr 1995  Increase NUM_TREES to 16 (for 4 local adfs) etc// WBL  7 Apr 1995  Increase NUM_TREES to 12 (for list and two adfs)// WBL 23 Mar 1995  Move pElitist tests into chrome.cxx// WBL 23 Mar 1995  Add Optional Chrome* parameters to GetFitnessObj and Copy// WBL 15 Mar 1995  Add pElitist// WBL 12 Mar 1995  add pTournComp and pNicheSize// WBL 26 Feb 1995  Update definition of Bestof and Worstof// WBL 19 Feb 1995  Add def PARETO and use it to remove BestMember etc// WBL 13 Feb 1995  Add pTracePareto// WBL 31 Jan 1995  make strcmpi accessible by test.cc// WBL 25 Jan 1995  Increase NUM_TREES to 10 (for list)// WBL 29 Nov 1994  Implment pnames and re-order chromeParams, add Load(char*)// WBL 15 Oct 1994  Add support for loading populations// WBL  8 Sep 1994  Add static_check// WBL 25 Aug 1994  Make CSelector different for each tree, remove funcbag//                  from chrome (use problem pointer instead)// WBL 24 Aug 1994  Add Bestof and Worstof to Problem. Add select_candidates// WBL 22 Aug 1994  remove (to problem files) hits and write_hits()//                  add Problem::NewChrome// WBL 15 Aug 1994  Add hits and write_hits()//                  Initialise xtree to -1 rather than 0// WBL  6 Jul 1994  Add pPopWidth and pDemeWidth// WBL  6 Jul 1994  Put NUM_TREES to 6 (for adf1)// WBL 30 Jun 1994  Add pTraceStatic+pTraceDynamic+pTraceDStats// WBL 28 Jun 1994  Supply default for go_until tree param// WBL 21 Jun 1994  Put back NUM_TREES to 5. Add parameter to generate()//                  go_until() and CrossTree()// WBL 21 Jun 1994  Increase NUM_TREES from 5 to 7 (for two adfs)// WBL 16 Jun 1994  Add PopSeed and pTestSeed, pTrace. Add TRACE// WBL 14 Jun 1994  Add Save and Load to ChromeParams (based on GPCPlus3.0//                  gpv.cc). Add pGenerateLimit//                  Add DisplayDStats() and Write()// WBL 16 May 1994  Add DisplayStats() to Pop, Fix MULTREE bug// 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#ifndef _CHROME_H#define _CHROME_H#include "selector.h"#include "prob.h"// Support for multiple trees within one individual in pop WBL// Only tested with FASTEVAL so far#define MULTREE// keep and print genelogical trace info#define TRACE// Define this if you do multiple evals, one Chrome at a time// It speeds up the EVAL calls significantly// Penalties are:  Time to expand the chrome once before evaluations//                 Uses globals, so only one Chrome at a time#define FASTEVAL	class Problem;	class Chrome;        typedef Chrome* PtrChrome;        class FitnessValue;#ifdef FASTEVAL		// evaluation code with global pointers	typedef retval (*EVALFUNC)();#else		// evaluation code with pointer passing	typedef retval (*EVALFUNC)(Chrome*);#endif	// One byte instruction node, 8 bits function indextypedef struct {unsigned char op;} node;  // node type	// eval node with pointers for direct function callstypedef struct {EVALFUNC ef; int op;} evalnode;  // node type	// Grab the function index#define FUNCNUM(c) (c.op)	// argument count for the current function#define ARGNUM() (funclist[FUNCNUM(expr[ip])]->argnum)#define PARGNUM(ip) (funclist[ip->op]->argnum)	// Grab the operand#define VARNUM(c) (0)#define PVARNUM(ip) (0)	// Build a node "c"#define SETNODE(c,o,v) c.op=o#define SETEVALNODE(ip,o,v) ip->op=o;ip->ef=funclist[o]->evalfunc	// Function evaluation stuff	// These macros may change internal form for faster evaluation.	// Arguments will be removed.  Use them.#ifdef FASTEVAL		//Define an EVALFUNC with no arguments#define OPDEF(Op) retval Op()		//Get a pointer to the chrome being evaluated#define CHROMEP ChromeGlobal		//current instruction pointer#define IP IpGlobal		// get its argument#define GETIDX (0)		// traverse an unused argument in an eval#define TRAVERSE() CHROMEP->TraverseGlobal()		//Evaluate the next expression#define EVAL ((++IP)->ef)()#else		//Define an EVALFUNC#define OPDEF(Op) retval Op(Chrome* curchrome)		//Get a pointer to the chrome being evaluated#define CHROMEP curchrome		//current instruction pointer#define IP CHROMEP->ip		// get its argument#define GETIDX (CHROMEP->expr[IP].idx)		// traverse an unused argument in an eval#define TRAVERSE() CHROMEP->Traverse()		//Evaluate the next expression#define EVAL CHROMEP->eval()#endif		//function and memory arrays#define FUNCARRAYSIZE 100#define CONSTARRAYSIZE 256// cut numeric overflows.  Bound returns to 10^15#define BIGFLOAT ( (retval) 1.0e15 )#define SMALLFLOAT ( (retval) 1.0e-15 )#define BOUNDF(f) (f==0? f : (f>0 ?((f)>BIGFLOAT ? BIGFLOAT : ((f)<SMALLFLOAT? SMALLFLOAT : (f))) : ((f)<-BIGFLOAT ? -BIGFLOAT : ((f)>-SMALLFLOAT? -SMALLFLOAT : (f))) ))// Compatibility stuff#define UINT unsigned intextern ofstream& crossfile;// All primitives in a problem are subclasses of this FUNCTION objectclass Function {public:	int serial;             // serial number in universal function list (not implemented)	char name[30];                  // Function name	int argnum;             // number of arguments	int varnum;                             // number of variables in variable table of opcode	int weight;             // selection frequency relative to other functions	Function() {};	Function(const int a,const int v,const int w,const EVALFUNC e,const char* n)		{argnum=a;varnum=v;weight=w;evalfunc=e;strcpy(name,n);}; 	virtual char* getprint(Chrome* st);       // Printed name may differ	char* getname() {return name;};	EVALFUNC evalfunc;                      // pointer to evaluation code.  Not a virtual for speed reasons#ifndef FASTEVAL	retval eval(Chrome* st) {return (evalfunc)(st);};       // active ingredient#else	retval eval() {return (evalfunc)();};#endif};//******************* Parametersenum {pPopSize,         // population sizepGenerateLimit,         // Terminate GP if no solutionpPopSeed,         // Seed for Pop etc.pTestSeed,         // Seed for application to generate testspTrace,         // display trace infopMaxExpr,          // Maximum expression size in nodespMaxTreeExpr,      // Soft initial maximum tree size in nodespInitExpr,           // Maximum initial expression depthpMaxDepth,           // Maximum expression depthpMuteRate,          // Node mutation rate per 1000pCrossSelf,         // Allow self crossover?pUnRestrictWt,         // any point crossover per 100pCrossWt,         // Crossover weight on generatepMuteWt,         // overall Mutation weight on generatepMuteNodeWt,         // Normal-Mutation weight on generatepMuteConstWt,         // C-Mutation weight on generatepMuteShrinkWt,         // Shrink-Mutation weight on generatepMuteSubTreeWt,        // Koza subtree replacement Mutation weight on generatepAnnealMuteWt,                 // Mut. Annealing weightpAnnealCrossWt,         // Crossover Annealing weightpCopyWt,         // Copy weight on generatepDirCrossWt,         // Directed Crossover weight (given Crossover)pSeeds,              // Number of seeds in initial poppMuteSeedWt,         // Chance of mutating seeds (except 1st)pSelectMethod,         // can be tournament, ranked, proportionalpGenerational,         // 0 => steady statepTournSize,         // tournament size 2-10pTournComp,         // If select or kill cant choose, compare remaining                    // winners with upto PTournComp in rest of poppTournOff,          // num generates after which pTournSize is reduced to 1pNicheSize,         // 0 => no niches otherwise in same niche if identicalpElitist,           // <>0 keep best. Only for pareto so farpPopWidth,      // if !=0 treat pop as being torroid with this as widthpDemeWidth,     // if !=0 treat deme as being rectangle. nb area =pMateRadiuspMateRadius,         // mating radius.  0 for panmicticpGaussRegion,         // 0 for flat selection in region, 1 for gaussianpRepeatEval,         // repeat evaluation on copy?  For sampled evalspKillTourn,         // number for anti-tournament <=10pMaxAge,         // age to start killing off a good guypParsimony,pFitnessCases,     // number of fitness casespStoreFit,         //1=>use storefitness LIST:2=>across runs memory chargingpCPU,              //problem dependantPARAM_COUNT }; // total number of parametersenum {pDumpfile1,        // basic name of dumpfile, can include pathpDumpfile2,        // basic name of dumpfile, both 1 & 2 NULL => dont use

⌨️ 快捷键说明

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