📄 gaul.h
字号:
/********************************************************************** gaul.h ********************************************************************** gaul - Genetic Algorithm Utility Library. Copyright ©2000-2005, Stewart Adcock <stewart@linux-domain.com> All rights reserved. The latest version of this program should be available at: http://gaul.sourceforge.net/ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. Alternatively, if your project is incompatible with the GPL, I will probably agree to requests for permission to use the terms of any other license. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY WHATSOEVER. A full copy of the GNU General Public License should be in the file "COPYING" provided with this distribution; if not, see: http://www.gnu.org/ ********************************************************************** Synopsis: Public header file for GAUL. This file should be included by any code that will be linking to libgaul. **********************************************************************/#ifndef GAUL_H_INCLUDED#define GAUL_H_INCLUDED/********************************************************************** * Include requisite headers. **********************************************************************/#include "gaul/gaul_util.h" /* General header containing commonly used convenience definitions. This also includes a platform- specific configuration file. *//* * Portable programming utilities. */#include "gaul/compatibility.h" /* For portability stuff. */#include "gaul/linkedlist.h" /* For linked lists. */#include "gaul/log_util.h" /* For logging facilities. */#include "gaul/memory_util.h" /* Memory handling. */#include "gaul/random_util.h" /* For PRNGs. */#include "gaul/table_util.h" /* Handling unique integer ids. *//********************************************************************** * Forward declarations. **********************************************************************//* The entity datatype stores single individuals. */typedef struct entity_t entity;/* The population datatype stores single populations. */typedef struct population_t population;/********************************************************************** * Enumerated types, used to define varients of the GA algorithms. **********************************************************************//* * Evolutionary mode. */typedef enum ga_scheme_type_t { GA_SCHEME_DARWIN = 0, GA_SCHEME_LAMARCK_PARENTS = 1, GA_SCHEME_LAMARCK_CHILDREN = 2, GA_SCHEME_LAMARCK_ALL = 3, GA_SCHEME_BALDWIN_PARENTS = 4, GA_SCHEME_BALDWIN_CHILDREN = 8, GA_SCHEME_BALDWIN_ALL = 12 } ga_scheme_type;/* * Elitism mode. */typedef enum ga_elitism_type_t { GA_ELITISM_UNKNOWN = 0, GA_ELITISM_NULL = 0, GA_ELITISM_PARENTS_SURVIVE = 1, GA_ELITISM_ONE_PARENT_SURVIVES = 2, GA_ELITISM_PARENTS_DIE = 3, GA_ELITISM_RESCORE_PARENTS = 4 } ga_elitism_type;/* * Stategies available with Differential Evolution implementation. */typedef enum de_strategy_t { GA_DE_STRATEGY_UNKNOWN = 0, GA_DE_STRATEGY_BEST = 1, GA_DE_STRATEGY_RAND = 2, GA_DE_STRATEGY_RANDTOBEST = 3 } ga_de_strategy_type;typedef enum de_crossover_t { GA_DE_CROSSOVER_UNKNOWN = 0, GA_DE_CROSSOVER_BINOMIAL = 1, GA_DE_CROSSOVER_EXPONENTIAL = 2 } ga_de_crossover_type;/********************************************************************** * Callback function typedefs. **********************************************************************//* * Analysis and termination. *//* GAgeneration_hook is called at the beginning of each generation by * all evolutionary functions. */typedef boolean (*GAgeneration_hook)(const int generation, population *pop);/* GAiteration_hook is called at the beginning of each iteration by * all non-evolutionary functions. */typedef boolean (*GAiteration_hook)(const int iteration, entity *entity);/* * Phenome (A general purpose data cache) handling. *//* GAdata_destructor is used to deallocate phenomic data. */typedef void (*GAdata_destructor)(vpointer data);/* GAdata_ref_incrementor is used for reference counting of phenomic data. */typedef void (*GAdata_ref_incrementor)(vpointer data);/* * Genome handling. *//* GAchromosome_constructor is used to allocate single chromosomes. */typedef boolean (*GAchromosome_constructor)(population *pop, entity *entity);/* GAchromosome_destructor is used to deallocate single chromosomes. */typedef void (*GAchromosome_destructor)(population *pop, entity *entity);/* GAchromosome_replicate is used to clone single chromosomes. */typedef void (*GAchromosome_replicate)(const population *pop, entity *parent, entity *child, const int chromosomeid);/* GAchromosome_to_bytes is used to pack genomic data into a * contiguous block of memory. */typedef unsigned int (*GAchromosome_to_bytes)(const population *pop, entity *joe, byte **bytes, unsigned int *max_bytes);/* GAchromosome_from_bytes is used to unpack genomic data from a * contiguous block of memory. */typedef void (*GAchromosome_from_bytes)(const population *pop, entity *joe, byte *bytes);/* GAchromosome_to_string is used to generate a human readable * representation of genomic data. */typedef char *(*GAchromosome_to_string)(const population *pop, const entity *joe, char *text, size_t *textlen);/* * GA operations. * * FIXME: Adaptation prototype should match the mutation prototype so that * the adaptation local optimisation algorithms may be used as mutation * operators. *//* GAevaluate determines the fitness of an entity. */typedef boolean (*GAevaluate)(population *pop, entity *entity);/* GAseed initialises the genomic contents of an entity. */typedef boolean (*GAseed)(population *pop, entity *adam);/* GAadapt optimises/performs learning for an entity. */typedef entity *(*GAadapt)(population *pop, entity *child);/* GAselect_one selects a single entity from the population. */typedef boolean (*GAselect_one)(population *pop, entity **mother);/* GAselect_two selects a pair of entities from the population. */typedef boolean (*GAselect_two)(population *pop, entity **mother, entity **father);/* GAmutate introduces a mutation into an entity. */typedef void (*GAmutate)(population *pop, entity *mother, entity *daughter);/* GAcrossover produces two new sets of chromosomes from two parent sets. */typedef void (*GAcrossover)(population *pop, entity *mother, entity *father, entity *daughter, entity *son);/* GAreplace inserts a new entity into the population. */typedef void (*GAreplace)(population *pop, entity *child);/* GArank Compare two entities and return 1, 0, or -1, if alpha should rank higher, * they should have equal rank, or beta should rank higher. */typedef int (*GArank)(population *alphapop, entity *alpha, population *betapop, entity *beta);/* * Alternative heuristic search function operations. * * GAtabu_accept - Tabu-search tabu+aspiration criteria. * GAsa_accept - Simulated Annealing acceptance criteria. * GAmutate_allele - Mutate a single, specified, allele. * GAto_double - Map chromosomal data to double-precision float array. * GAfrom_double - Map chromosomal data from double-precision float array. * GAgradient - Return array of gradients. * GAscan_chromosome - Produce next permutation of genome. * GAcompare - Compare two entities and return distance. */typedef boolean (*GAtabu_accept)(population *pop, entity *putative, entity *tabu);typedef boolean (*GAsa_accept)(population *pop, entity *current, entity *trial);typedef boolean (*GAmutate_allele)(population *pop, entity *parent, entity *child, const int chromosomeid, const int alleleid);typedef boolean (*GAto_double)(population *pop, entity *entity, double *darray);typedef boolean (*GAfrom_double)(population *pop, entity *entity, double *darray);typedef double (*GAgradient)(population *pop, entity *entity, double *darray, double *varray);typedef boolean (*GAscan_chromosome)(population *pop, entity *entity, int enumeration_num);typedef double (*GAcompare)(population *pop, entity *alpha, entity *beta);/********************************************************************** * Public prototypes. **********************************************************************//* * Functions located in ga_core.c:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -