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

📄 ga_utility.c

📁 关于遗传算法的一些见地。特别是关于简单遗传程序设计的实现。
💻 C
📖 第 1 页 / 共 2 页
字号:
/**********************************************************************  ga_utility.c **********************************************************************  ga_utility - High-level genetic algorithm routines.  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:     High-level GA functions and convenience functions.  To do:	Population/entity iterator functions.		On-line and off-line performance summaries. **********************************************************************/#include "gaul.h"/**********************************************************************  ga_diagnostics()  synopsis:	Display diagnostics message.  parameters:	none  return:	none  last updated:	17 Feb 2005 **********************************************************************/void ga_diagnostics(void)  {  int	num_pops;	/* Number of populations defined, or -1 for no table. */  printf("=== GA utility library =======================================\n");  printf("Version:                     %s\n", GA_VERSION_STRING);  printf("Build date:                  %s\n", GA_BUILD_DATE_STRING);  printf("Compilation machine characteristics:\n%s\n", GA_UNAME_STRING);  printf("--- Constants ------------------------------------------------\n");  printf("GA_DEBUG:                    %d\n", GA_DEBUG);  printf("GA_BOLTZMANN_FACTOR:         %e\n", GA_BOLTZMANN_FACTOR);  printf("GA_MIN_FITNESS:              %e\n", GA_MIN_FITNESS);  printf("BYTEBITS:                    %d\n", BYTEBITS);  printf("--- Defaults -------------------------------------------------\n");  printf("GA_DEFAULT_CROSSOVER_RATIO:  %f\n", GA_DEFAULT_CROSSOVER_RATIO);  printf("GA_DEFAULT_MUTATION_RATIO:   %f\n", GA_DEFAULT_MUTATION_RATIO);  printf("GA_DEFAULT_MIGRATION_RATIO:  %f\n", GA_DEFAULT_MIGRATION_RATIO);  printf("GA_DEFAULT_ALLELE_MUTATION_PROB: %f\n", GA_DEFAULT_ALLELE_MUTATION_PROB);  printf("--- Data structures ------------------------------------------\n");  printf("structure                    sizeof\n");  printf("population                   %lu\n", (unsigned long) sizeof(population));  printf("entity                       %lu\n", (unsigned long) sizeof(entity));  printf("byte                         %lu\n", (unsigned long) sizeof(byte));  printf("--- Current variables ----------------------------------------\n");  num_pops = ga_get_num_populations();  if (num_pops==-1)    {    printf("Population table:            undefined\n");    }  else    {    printf("Population table:            defined\n");    printf("Size:                        %d\n", num_pops);    }  printf("==============================================================\n");  return;  }/**********************************************************************  ga_get_major_version()  synopsis:	Return major version number.  parameters:	none  return:	none  last updated:	06 Apr 2003 **********************************************************************/int ga_get_major_version( void )  {  return GA_MAJOR_VERSION;  }/**********************************************************************  ga_get_minor_version()  synopsis:	Return major version number.  parameters:	none  return:	none  last updated:	06 Apr 2003 **********************************************************************/int ga_get_minor_version( void )  {  return GA_MINOR_VERSION;  }/**********************************************************************  ga_get_patch_version()  synopsis:	Return patch level (version) number.  parameters:	none  return:	none  last updated:	06 Apr 2003 **********************************************************************/int ga_get_patch_version( void )  {  return GA_PATCH_VERSION;  }/**********************************************************************  ga_genesis_integer()  synopsis:	High-level function to create a new population and		perform the basic setup (i.e. initial seeding) required		for further optimisation and manipulation.		Assumes the use of integer chromosomes is desired.		Integer-valued chromsomes.  parameters:  return:	population, or NULL on failure.  last updated:	17 Feb 2005 **********************************************************************/population *ga_genesis_integer(	const int		population_size,			const int		num_chromo,			const int		len_chromo,			GAgeneration_hook	generation_hook,			GAiteration_hook	iteration_hook,			GAdata_destructor	data_destructor,			GAdata_ref_incrementor	data_ref_incrementor,			GAevaluate		evaluate,			GAseed			seed,			GAadapt			adapt,			GAselect_one		select_one,			GAselect_two		select_two,			GAmutate		mutate,			GAcrossover		crossover,			GAreplace		replace,			vpointer		userdata )  {  population	*pop;	/* The new population structure. */  plog(LOG_VERBOSE, "Genesis is beginning!");/* * Initialise OpenMP code. */  ga_init_openmp();/* * Allocate and initialise a new population. * This call also sets this as the active population. */  if ( !(pop = ga_population_new( population_size, num_chromo, len_chromo )) )    return NULL;/* * Assign population's user data. */  pop->data = userdata;/* * Define some callback functions. */  pop->generation_hook = generation_hook;  pop->iteration_hook = iteration_hook;  pop->data_destructor = data_destructor;  pop->data_ref_incrementor = data_ref_incrementor;  pop->chromosome_constructor = ga_chromosome_integer_allocate;  pop->chromosome_destructor = ga_chromosome_integer_deallocate;  pop->chromosome_replicate = ga_chromosome_integer_replicate;  pop->chromosome_to_bytes = ga_chromosome_integer_to_bytes;  pop->chromosome_from_bytes = ga_chromosome_integer_from_bytes;  pop->chromosome_to_string = ga_chromosome_integer_to_string;  pop->evaluate = evaluate;  pop->seed = seed;  pop->adapt = adapt;  pop->select_one = select_one;  pop->select_two = select_two;  pop->mutate = mutate;  pop->crossover = crossover;  pop->replace = replace;/* * Seed the population. */#if 0  if (seed==NULL)    {    plog(LOG_VERBOSE, "Entity seed function not defined.  Genesis can not occur.  Continuing anyway.");    }  else    {    ga_population_seed(pop);    plog(LOG_VERBOSE, "Genesis has occured!");    }#endif  return pop;  }/**********************************************************************  ga_genesis() and ga_genesis_int()  *** DEPRECATED FUNCTIONS! ***  synopsis:	High-level function to create a new population and		perform the basic setup (i.e. initial seeding) required		for further optimisation and manipulation.		Assumes the use of integer chromosomes is desired.		This currently only exists for compatibility with		older versions of GAUL.		Integer-valued chromsomes.  parameters:  return:	population, or NULL on failure.  last updated:	25 Mar 2004 **********************************************************************/#ifndef COMPILE_DEPRECATED_FUNCTIONSpopulation *ga_genesis(	const int		population_size,			const int		num_chromo,			const int		len_chromo,			GAgeneration_hook	generation_hook,			GAiteration_hook	iteration_hook,			GAdata_destructor	data_destructor,			GAdata_ref_incrementor	data_ref_incrementor,			GAevaluate		evaluate,			GAseed			seed,			GAadapt			adapt,			GAselect_one		select_one,			GAselect_two		select_two,			GAmutate		mutate,			GAcrossover		crossover,			GAreplace		replace,			vpointer		userdata )  {  plog(LOG_FIXME, "Use of ga_genesis() is deprecated.  Modify code to use ga_genesis_integer() instead.");  return ga_genesis_integer( population_size, num_chromo, len_chromo,                             generation_hook, iteration_hook,                             data_destructor, data_ref_incrementor,                             evaluate, seed, adapt,                             select_one, select_two, mutate, crossover, replace,                             userdata );  }population *ga_genesis_int(	const int		population_size,			const int		num_chromo,			const int		len_chromo,			GAgeneration_hook	generation_hook,			GAiteration_hook	iteration_hook,			GAdata_destructor	data_destructor,			GAdata_ref_incrementor	data_ref_incrementor,			GAevaluate		evaluate,			GAseed			seed,			GAadapt			adapt,			GAselect_one		select_one,			GAselect_two		select_two,			GAmutate		mutate,			GAcrossover		crossover,			GAreplace		replace,			vpointer		userdata )  {  plog(LOG_FIXME, "Use of ga_genesis_int() is deprecated.  Modify code to use ga_genesis_integer() instead.");  return ga_genesis_integer( population_size, num_chromo, len_chromo,                             generation_hook, iteration_hook,                             data_destructor, data_ref_incrementor,                             evaluate, seed, adapt,                             select_one, select_two, mutate, crossover, replace,                             userdata );  }#endif/**********************************************************************  ga_genesis_char()  synopsis:	High-level function to create a new population and		perform the basic setup (i.e. initial seeding) required		for further optimisation and manipulation.		Character-valued chromosomes.  parameters:  return:	population, or NULL on failure.  last updated:	17 Feb 2005 **********************************************************************/population *ga_genesis_char(	const int		population_size,			const int		num_chromo,			const int		len_chromo,			GAgeneration_hook	generation_hook,			GAiteration_hook	iteration_hook,			GAdata_destructor	data_destructor,			GAdata_ref_incrementor	data_ref_incrementor,			GAevaluate		evaluate,			GAseed			seed,			GAadapt			adapt,			GAselect_one		select_one,			GAselect_two		select_two,			GAmutate		mutate,			GAcrossover		crossover,			GAreplace		replace,			vpointer		userdata )  {  population	*pop;	/* The new population structure. */  plog(LOG_VERBOSE, "Genesis is beginning!");/* * Initialise OpenMP code. */  ga_init_openmp();/* * Allocate and initialise a new population. * This call also sets this as the active population. */  if ( !(pop = ga_population_new( population_size, num_chromo, len_chromo )) )    return NULL;/* * Assign population's user data. */  pop->data = userdata;/* * Define some callback functions. */  pop->generation_hook = generation_hook;  pop->iteration_hook = iteration_hook;  pop->data_destructor = data_destructor;  pop->data_ref_incrementor = data_ref_incrementor;  pop->chromosome_constructor = ga_chromosome_char_allocate;  pop->chromosome_destructor = ga_chromosome_char_deallocate;  pop->chromosome_replicate = ga_chromosome_char_replicate;  pop->chromosome_to_bytes = ga_chromosome_char_to_bytes;  pop->chromosome_from_bytes = ga_chromosome_char_from_bytes;  pop->chromosome_to_string = ga_chromosome_char_to_string;  pop->evaluate = evaluate;  pop->seed = seed;  pop->adapt = adapt;  pop->select_one = select_one;  pop->select_two = select_two;  pop->mutate = mutate;  pop->crossover = crossover;  pop->replace = replace;/* * Seed the population. */#if 0  if (seed==NULL)    {    plog(LOG_VERBOSE, "Entity seed function not defined.  Genesis can not occur.  Continuing anyway.");    }  else    {    ga_population_seed(pop);    plog(LOG_VERBOSE, "Genesis has occured!");    }#endif  return pop;  }/**********************************************************************  ga_genesis_boolean()  synopsis:	High-level function to create a new population and		perform the basic setup (i.e. initial seeding) required		for further optimisation and manipulation.		Boolean-valued chromosomes.  parameters:  return:	population, or NULL on failure.  last updated:	17 Feb 2005 **********************************************************************/population *ga_genesis_boolean(	const int		population_size,			const int		num_chromo,			const int		len_chromo,			GAgeneration_hook	generation_hook,			GAiteration_hook	iteration_hook,			GAdata_destructor	data_destructor,

⌨️ 快捷键说明

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