📄 cgp.h
字号:
// cgp.c
// Julian F. Miller (c)
// Dept. of Electronics, University of York
// IMPORTANT: program outputs are arranged most significant on the left
#define MAX_NUM_ROWS 10
#define MAX_NUM_COLS 1000
#define MAX_NUM_INPUTS 10
#define MAX_NUM_OUTPUTS 256
#define MAX_NUM_PRODUCTS 1024
#define MAX_NUM_NODES MAX_NUM_ROWS*MAX_NUM_COLS
#define MAX_NUM_GENES_PER_NODE 4#define MAX_NUM_GENES MAX_NUM_GENES_PER_NODE*MAX_NUM_NODES#define MAX_OUTPUT_SIZE MAX_NUM_INPUTS+MAX_NUM_NODES+MAX_NUM_OUTPUTS
#define MAX_NUM_RUNS 200
#define MAX_NUM_CHROMOSOMES 1000
#define MAX_NUM_LETTERS 100
#define MAX_NUM_FUNCTIONS 20
#define MAXNUM 4294967295
#define INITIALISE
//these are all read from the .par file and never change after that
int population_size;
double per_cent_mutate;
double per_cent_crossover;
int num_generations;
int num_runs_total;
int num_rows;
int num_cols;
int levels_back;
int progress_report;
int report_interval;
unsigned global_seed;
int ea_type;
int mu;
int elitism;
int save_best_chrom;
int run_from_chrom;
int make_efficient;
int expected_min_gates;
// global constants calculated in get_parameters
int num_functions;
int num_genes;
int num_nodes, num_genes_per_node;
int number[MAX_NUM_FUNCTIONS];
char node_types[MAX_NUM_FUNCTIONS][20];
int allowed_functions[MAX_NUM_FUNCTIONS];
// global constants read from .plu file
int num_inputs,num_outputs,num_products;
unsigned long plu_inputs[MAX_NUM_PRODUCTS][MAX_NUM_INPUTS];
unsigned long plu_outputs[MAX_NUM_PRODUCTS][MAX_NUM_INPUTS];
//calculated global constants in read_plu()
int num_tests,end_count,num_bits,bit_width;
// stores the outputs of all gates (inc. primary inputs )
// initialised in read_plu() reset in invhamming()
unsigned long output[MAX_OUTPUT_SIZE];
// macros
#define pow2(x) (1<<x) // returns 2 to power x (x>=0)
#define getbit(decimal,nthbit) ((decimal>>nthbit) & 01) // gets nth bit
// function prototypes
void validate_command_line(int argc, char* argv[], char parfile[], char plufile[]);
void get_parameters(char parfile[],char plufile[]);
void write_cgp_info(char command[],char plufile[]);
unsigned int invhamming(unsigned long a,int addr);
int newrand(int range);
void read_plu(char plufile[]);
void fprint_a_chromosome(int* chromosome, char name[]);
void print_a_chromosome(int* chromosome);
void fprint_active_genes(int* chromosome,char name[30]);
int get_num_nodes_active(int* chromosome);
void read_from_chrom(int** chromosomes);
void get_gene_limits(int column, int* limit_min, int* limit);
int get_connection_gene(int limit_min, int limit);
int get_function_gene(void);
int get_output_gene(void);
unsigned node_type(unsigned long in[MAX_NUM_GENES_PER_NODE],
unsigned code);
int fitness(int* chromosome);
void insertion_sort(int Fit[], int** chromosomes);
void sort_chromosomes_by_fitness(int** chromosomes);
void initialise(int** chromosomes);
int get_best_chromosome(int** chromosomes,
int* best_chromosome);
int is_not_output_gene(int gene);
int is_function_gene(int gene, int locus);
int get_num_mutant(int num_genes, double per_cent_mutate);
int get_num_children(int num_genes, double per_cent_crossover);
void mutate(int* chromosome, int num_mutations);
void recombine(int* parent_chromosome1,
int* parent_chromosome2,
int* child_chromosome,
int crossover_point);
void get_candidates(int* candidate1, int* candidate2);
int get_tournament_winner(int** chromosomes);
void select_new_pop(int** chromosomes,
int** new_chromosomes);
void generate_new_pop_ga(int** chromosomes,
int* best_chromosome,
int elitism);
void generate_new_pop_es(int** chromosomes,
int* best_chromosome);
void generate_new_pop_es_mu_plus_lambda(int** chromosomes, int *best_chromosome, int mu);
void generate_new_pop_es_mu_comma_lambda(int** chromosomes, int* best_chromosome, int mu);
int** create_2dchromosome_space(void);
int* create_chromosome_space(void);
void free_chromosomes(int** chromosomes);
int EA(int* best_gen, int* num_nodes_active, int run,
char prog[MAX_NUM_LETTERS], char stat[MAX_NUM_LETTERS]);
void run_EA(int num_runs_total);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -