📄 gp.h
字号:
/*======================================================================+| PGPC: Parallel Genetic Programming in C || (c) 1995 Genetic Algorithm Technology Corp. all rights reserved || written by David Andre |+======================================================================*//*======================================================================+| FILE: gp.h || DESCRIPTION: Parameters and structures for GP. || || REVISIONS: || Jan 24, 1995: Works as of today, no known bugs. || Jan 26, 1995: Added N Plus 2 Repro functionality || Mar 15, 1995: Adding Constrained Syntactic Structure.... || Mar 15, 1995: Adding Function Weights || Mar 21, 1995: Added Randomizer Options, control || Apr 1, 1995: Changing to better user interface.... |+======================================================================*//* gp.h *//***********************************************************************//* Definitions of some stuff to be used as tokens */#define ON 1#define OFF 0#define TRUE 1#define FALSE 0#define TOP_OF_TREE -37/***********************************************************************/#include "_prbname.xxx"/*#define INCXFILENAME #INCXFILE#include INCXFILENAME*/#include _PRB_H#if __STDC__ || defined(__cplusplus)#define P_(s) s#define ANSI_FUNC#else#define P_(s) ()#ifdef ANSI_FUNC#undef ANSI_FUNC#endif#endif#ifndef RAND#define RAND Randu_Rand /*rand*/ /*PM_Rand*/ /*rand*/ /*MyRand*/#endif#ifndef SRAND#define SRAND Randu_Srand /*srand*/ /*PM_Srand*/ /*srand*/ /*MySrand*/#endif#ifndef DRAND_MAX#define DRAND_MAX Randu_MaxRand() /*RAND_MAX*/ /*PM_MaxRand()*/ /*RAND_MAX*/ /*MyMaxRand*/#endif#ifndef GET_RAND#define GET_RAND GetRanduRand /*GetSystemSeed*/ /*GetMyRand*/ /*GetSeed*/#endif#ifndef FRAND#define FRAND Randu_Rand /*rand*/ /*MyRand*/#endif#ifndef FSRAND#define FSRAND Randu_Srand /*srand*/ /*MySrand*/#endif#ifndef FDRAND_MAX#define FDRAND_MAX Randu_MaxRand() /*RAND_MAX*/ /*MyMaxRand()*/#endif#ifndef FGET_RAND#define FGET_RAND GetRanduRand /*GetMyRand*/ /*GetSeed*/#endif#define _FIRST_ADF ((int) 0)#define _LAST_ADF ((int) MAX_NUM_ADFS-1)#define _FIRST_ADF_ARG ((int) MAX_NUM_ADFS)#define _LAST_ADF_ARG ((int) MAX_NUM_ADFS + MAX_NUM_ADF_ARGS - 1)#define _dmax(x,y) (((x)>(y))?(x):(y))#define _dmin(x,y) (((x)<(y))?(x):(y))#define _dabs(n) (((n)>0)?(n):(-(n)))#define PGPC_MAXFLOAT (1370000037275507027000000000000000000.0)#define PGPC_MAXINT 1073741354/*#ifndef __BORLANDC__ #define BOSS_NODE_SENDS_FIT_CASES 1#endif*/#ifndef RUN_END_CRITERION#define RUN_END_CRITERION 0.001#endif/********************************************************************//* VARIOUS USEFUL PROBLEM DESIGN MACROS*/#define _dmax(x,y) (((x)>(y))?(x):(y))#define _dmin(x,y) (((x)<(y))?(x):(y))#define _set_code(cd) (*pop).func_table[func_index].code = cd;#define _set_weight(wt) (*pop).func_table[func_index].weight = wt;#define _set_macro(x) (*pop).func_table[func_index].macro = x;#define _set_constant(x) (*pop).func_table[func_index].constant = x;#define _set_print_name(dn) sprintf((*pop).func_table[func_index].print_name, #dn);#define _set_arity(da) (*pop).func_table[func_index].arity = da;#define _declare_adf(dn,cd,wt) _set_code(cd);_set_weight(wt);_set_macro(1);\ _set_constant(0);_set_print_name(dn);\ _set_arity(MIN_NUM_ADF_ARGS);\ if (func_index >= MAX_NUM_ADFS )\ {\ gpi_SendError("Error! Cannot have another ADF without increasing MAX_NUM_ADFS\n");\ exit(6);\ }\ func_index++;#define _declare_arg(dn,cd,wt) if (func_index != MAX_NUM_ADFS)\ {\ gpi_SendError("Error! Did not declare enough ADFS");\ exit(6);\ }\ _set_code(cd); _set_weight(wt); _set_macro(0);\ _set_constant(0); _set_arity(0); _set_print_name(dn);\ if (func_index >= (MAX_NUM_ADFS + MAX_NUM_ADF_ARGS ) )\ {\ gpi_SendError("Error! Cannot have another ADF_ARG without increasing MAX_NUM_ADF_ARGS\n");\ exit(6);\ }\ func_index++;#define _declare_func(cd,da,dm,dw,dn) if (func_index < MAX_NUM_ADFS+MAX_NUM_ADF_ARGS)\ {\ gpi_SendError("Error! Did not declare enough ADFs or ADF args\n");\ exit(6);\ }\ _set_code(cd); _set_weight(dw); _set_macro(dm);\ _set_constant(0); _set_arity(da); _set_print_name(dn);\ func_index++;#define _declare_random(dw) _set_code(random_func); _set_weight(dw); _set_macro(0);\ _set_constant(1); _set_arity(0); _set_print_name("%%f");\ func_index++;\ if (func_index != TOTAL_NUMBER_OF_FUNCTIONS) \ {\ gpi_SendError("Error! Wrong number of functions in <prob>.h\n");\ gpi_SendError("Either TOTAL_NUMBER_OF_FUNCTIONS is wrong");\ gpi_SendError(" or some function is not declared!\n"); \ sprintf(str,"Total number declared:%d, TOTAL_NUMBER_OF_FUNCTIONS:%d\n",\ func_index,TOTAL_NUMBER_OF_FUNCTIONS); \ gpi_SendError(str);\ exit(5);\ }\ else {\ for (i=0;i<TOTAL_NUMBER_OF_FUNCTIONS;i++)\ { \ if ((*pop).func_table[i].arity == -999)\ {\ sprintf(str,"Function %d was not declared properly...\n",i);\ gpi_SendError(str);\ exit(1);\ }\ } \ }#define _init_make_function_table_vars int i,branchnum,func_index;#define _null_function_arities() for (i=0;i<TOTAL_NUMBER_OF_FUNCTIONS;i++) \ (*pop).func_table[i].arity = -999;#define _init_make_function_table (*pop).num_general_functions = TOTAL_NUMBER_OF_FUNCTIONS; \ func_index=0; _null_function_arities();#define _init_function_set_definitions branch_index = 0;#define _start_def_func_set_for_branch(brn) (*pop).num_functions[brn] = (*pop).num_general_functions;\ for (i=0;i<(*pop).num_general_functions;i++) \ (*pop).function_assignment[brn][i] = -1;#define _use_func(br_num,func) (*pop).function_assignment[br_num][GetFuncNumber(func,pop)] = (*pop).func_table[GetFuncNumber(func,pop)].arity;#define _use_adf(br_num,func,arity) (*pop).function_assignment[br_num][GetFuncNumber(func,pop)] = arity;#define _use_adf_num(br_num,funcnum,arity) (*pop).function_assignment[br_num][funcnum] = arity;#define _use_func_num(br_num,funcnum) (*pop).function_assignment[br_num][funcnum] = (*pop).func_table[funcnum].arity;#define _use_dummy_arg(br_num,func) (*pop).function_assignment[br_num][GetFuncNumber(func,pop)] = 0;#define _use_random(br_num) (*pop).function_assignment[br_num][TOTAL_NUMBER_OF_FUNCTIONS-1] = 0;#define _init_macro(br) (br->ind->index_ptr)++#if (SHORT_CIRCUIT_EVAL ==1)#define _SHORT_CIRC_CODE if (g_done_early) return(-1);#else#define _SHORT_CIRC_CODE#endif#define _start_def_func(fname) GTYPE fname P_((Branch *br)); \ GTYPE fname(Branch *br){ GTYPE largs[MAX_NUM_ARGS]; br->ind->index_ptr++; _SHORT_CIRC_CODE {#define _start_def_macro(fname) GTYPE fname P_((Branch *br)); \ GTYPE fname(Branch *br){br->ind->index_ptr++; _SHORT_CIRC_CODE {#define _eval_args() {int opcode;\ int dind_ea; \ opcode = br->tree[br->ind->index_ptr-1].opcode;\ for(dind_ea=0;dind_ea<_function_arity(opcode);dind_ea++)\ {\ largs[dind_ea] = _eval_subtree(br,ppop); }}#define _get_args(n) (largs[n])#define _end_def_func(fname) }}#define _end_def_macro(fname) }}/********************************************************************/#define FULL 1#define GROWTH 2#define RAMPED 3#define OP_DONE -1#define CROSSOVER 101#define MUTATION 102#define BRCREATE 103#define DECOMPRESS 104#define BRDUP 105#define BRDEL 106#define ARGDUP 107#define ARGDEL 108#define CROSSOVER_ON_NODES 111#define CROSSOVER_ON_LEAVES 112#define IPB_BRC 113#define COPY 190#define START_CREATION 561#define END_CREATION 562#define START_EVAL 563#define END_EVAL 564#define START_REPRO 565#define END_REPRO 566#define START_EVAL_DUDE 567#define END_EVAL_DUDE 568#define IN_CREATION 661#define IN_EVAL 662#define IN_REPRO 663#define ADF_TYPE_IPB 91#define ADF_TYPE_ADF 92#define UNDEFINED -999#define MAXNUMFUNCTIONS 256#define MAXNUMFORARANDOMCONSTANT 245#define NUM_OPS_TO_KEEP 51#ifndef GOOD_TOURNAMENT_SIZE#define GOOD_TOURNAMENT_SIZE 7#endif#define BAD_TOURNAMENT_SIZE 1#define SEARCH_LIMIT_FOR_CROSSOVER 250#define KLUDGE_MAX_NUM_FIT_CASES 256#define MAX_DEPTH_FOR_TREE 40#define MAX_ATTEMPTS 100#define MAX_NUM_EMIGRANTS_PER_GENERATION 1000#define NUM_EXTRA_SLOTS 1#define EMPTY -1#define ROOT TOTAL_NUMBER_OF_FUNCTIONS#define _max(x,y) ((x)>(y)?(x):(y))#define _min(x,y) ((x)>(y)?(y):(x))/* These must be defined for my data structure */#define _fv_map(n) (((int)(n) >= (TOTAL_NUMBER_OF_FUNCTIONS-1))?(TOTAL_NUMBER_OF_FUNCTIONS-1):((int)(n)))#define _function_arity(n) ((int) (br->function_vector[(int)(_fv_map((int)(n)))]))#define _function_is_macro(pop,n) (*pop).func_table[(int)_fv_map((n))].macro#define _function_code(pop,n) (*pop).func_table[(int)_fv_map((n))].code#define _function_is_constant(n) (((n) >= (TOTAL_NUMBER_OF_FUNCTIONS-1)) ? 1 :0)#define _function_is_adf(n) ((n)<MAX_NUM_ADFS)#define _function_is_dummy_arg(n) (((n)<(MAX_NUM_ADFS+MAX_NUM_ADF_ARGS)) && ((n) >= MAX_NUM_ADFS))#define _function_is_general(n) ((n)>=(MAX_NUM_ADFS+MAX_NUM_ADF_ARGS) && ((n)<(TOTAL_NUMBER_OF_FUNCTIONS-1)))#define _function_printname(n) gpop.func_table[(int)_fv_map((n))].print_name#define _eval_subtree(br,dpop) ((*(_function_code(dpop,((br)->tree[(br)->ind->index_ptr]).opcode)))(br))
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -