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

📄 api.html

📁 麻省理工开发的免费遗传算法类库GAlib,很好用
💻 HTML
📖 第 1 页 / 共 5 页
字号:
<html><head><title>GAlib: programming interface</title><!-- by matthew wall                           all rights reserved --><!-- Copyright (c) 1995-1996 Massachusetts Institute of Technology --><!-- Copyright (c) 1996-1999 Matthew Wall                          --></head><body bgcolor="efefef" text="000000"><strong>Programming interface for <a href="GAlib.html">GAlib</a> classes</strong><br><i>version 2.4</i><p>This document describes the programming interface for the library.  The section for each class contains a description of the object's purpose followed by the creator signature and member functions.  There are also sections for library constants, typedefs, and function signatures.</p><p>see also: <i><a href="Overview.html">library overview</a>, <a href="ClassHierarchy.html">class hierarchy</a>, <a href="Extensions.html">customization</a></i></p><br><big><strong>Table of contents</strong></big><br><hr><table border=0 cellspacing=0 cellpadding=6><tr valign=baseline><td width="50%"><ul>  <p>  <strong>General library information</strong><br>  <li><a href="#typedefs">typedefs and enumerations</a>  <li><a href="#signatures">function prototypes</a>  <li><a href="#constants">globals and default values</a>  <li><a href="#random">random number functions</a>  <li><a href="#errors">error handling</a>       </p>       <p>       <strong>Genetic Algorithm</strong><br>  <li><a href="#ga_base">GA base class</a>  <li><a href="#ga_overlapping">GA with overlapping populations (steady-state)</a>  <li><a href="#ga_non_overlapping">GA with non-overlapping populations (simple)</a>  <li><a href="#ga_incremental">GA with 1 or 2 children per generation (incremental)</a>  <li><a href="#ga_deme">GA with parallel, migrating populations (deme)</a>       </p>       <p>  <li><a href="#defparms">parameters and command-line options</a>  <li><a href="#parameters">parameter list object</a>  <li><a href="#statistics">statistics object</a>  <li><a href="#completion">completion functions</a>  <li><a href="#replacement">replacement schemes</a>       </p>       <p>       <strong>Population, Scaling, and Selection</strong><br>  <li><a href="#pop">population</a>  <li><a href="#selection">selection schemes</a>  <li><a href="#scaling">fitness scaling schemes</a>       </p></ul></td><td width=6></td><td width="50%"><ul>  <p>  <strong>Genomes</strong><br>  <li><a href="#genome_base">genome base class</a>  <li><a href="#genome_1dbinstr">1D binary string genome</a>  <li><a href="#genome_2dbinstr">2D binary string genome</a>  <li><a href="#genome_3dbinstr">3D binary string genome</a>  <li><a href="#genome_bin2dec">binary-to-decimal genome</a>  <li><a href="#genome_1darray">1D array genome</a>  <li><a href="#genome_1darrayallele">1D array genome with alleles</a>  <li><a href="#genome_2darray">2D array genome</a>  <li><a href="#genome_2darrayallele">2D array genome with alleles</a>  <li><a href="#genome_3darray">3D array genome</a>  <li><a href="#genome_3darrayallele">3D array genome with alleles</a>  <li><a href="#genome_string">string genome</a>  <li><a href="#genome_real">real number genome</a>  <li><a href="#genome_list">list genome</a>  <li><a href="#genome_tree">tree genome</a>       </p>       <p>  <li><a href="#phenotype_b2d">binary-to-decimal phenotype</a>  <li><a href="#alleleset">allele set</a>  <li><a href="#evaldata">evaluation data</a>       </p>       <p>       <strong>Data Structures</strong><br>  <li><a href="#binstr">binary string</a>  <li><a href="#array">array</a>  <li><a href="#tree">tree</a>  <li><a href="#list">list</a>       </p></ul></td></tr></table><br><br><br><br><a name="typedefs"><big><strong>Global Typedefs and Enumerations</strong></big></a><br><hr><blockquote><pre>typedef float <b>GAProbability, GAProb</b>typedef enum  <b>_GABoolean</b> {gaFalse, gaTrue} <b>GABoolean</b>, <b>GABool</b>typedef enum  <b>_GAStatus</b> {gaSuccess, gaFailure} <b>GAStatus</b>typedef unsigned char <b>GABit</b></pre></blockquote><br><br><br><br><a name="signatures"><big><strong>Function Prototypes</strong></big></a><br><hr><blockquote><pre>GABoolean (*<b>GAGeneticAlgorithm::Terminator</b>)(GAGeneticAlgorithm &amp; ga)GAGenome&amp; (*<b>GAIncrementalGA::ReplacementFunction</b>)(GAGenome &amp;, GAPopulation &amp;)     void (*<b>GAPopulation::Initializer</b>)(GAPopulation &amp;)     void (*<b>GAPopulation::Evaluator</b>)(GAPopulation &amp;)     void (*<b>GAGenome::Initializer</b>)(GAGenome &amp;)    float (*<b>GAGenome::Evaluator</b>)(GAGenome &amp;)      int (*<b>GAGenome::Mutator</b>)(GAGenome &amp;, float)    float (*<b>GAGenome::Comparator</b>)(const GAGenome &amp;, const GAGenome&amp;)      int (*<b>GAGenome::SexualCrossover</b>)(const GAGenome&amp;, const GAGenome&amp;, GAGenome*, GAGenome*)      int (*<b>GAGenome::AsexualCrossover</b>)(const GAGenome&amp;, GAGenome*)      int (*<b>GABinaryEncoder</b>)(float&amp; value, GABit* bits,       			       unsigned int nbits, float min, float max)      int (*<b>GABinaryDecoder</b>)(float&amp; value, const GABit* bits,       			       unsigned int nbits, float min, float max)</pre></blockquote><br><br><br><a name="defparms"><big><strong>Parameter Names and Command-Line Options</strong></big></a><br><hr><blockquote><pre>#define name        full name                   short name  default valuegaNminimaxi         minimaxi                    mm          int   gaDefMiniMaxi        = 1gaNnGenerations     number_of_generations       ngen        int   gaDefNumGen          = 250gaNpConvergence     convergence_percentage      pconv       float gaDefPConv           = 0.99gaNnConvergence     generations_to_convergence  nconv       int   gaDefNConv           = 20gaNpCrossover       crossover_probability       pcross      float gaDefPCross          = 0.9gaNpMutation        mutation_probability        pmut        float gaDefPMut            = 0.01gaNpopulationSize   population_size             popsize     int   gaDefPopSize         = 30gaNnPopulations     number_of_populations       npop        int   gaDefNPop            = 10gaNpReplacement     replacement_percentage      prepl       float gaDefPRepl           = 0.25gaNnReplacement     replacement_number          nrepl       int   gaDefNRepl           = 5gaNnBestGenomes     number_of_best              nbest       int   gaDefNumBestGenomes  = 1gaNscoreFrequency   score_frequency             sfreq       int   gaDefScoreFrequency1 = 1gaNflushFrequency   flush_frequency             ffreq       int   gaDefFlushFrequency  = 0gaNscoreFilename    score_filename              sfile       char* gaDefScoreFilename   = "generations.dat"gaNselectScores     select_scores               sscores     int   gaDefSelectScores    = GAStatistics::MaximumgaNelitism          elitism                     el          GABoolean gaDefElitism     = gaTruegaNnOffspring       number_of_offspring         noffspr     int   gaDefNumOff          = 2gaNrecordDiversity  record_diversity            recdiv      GABoolean gaDefDivFlag     = gaFalsegaNpMigration       migration_percentage        pmig        float gaDefPMig            = 0.1gaNnMigration       migration_number            nmig        int   gaDefNMig            = 5</pre><p>Parameters may be specified using the full name strings (for example in parameter files), short name strings (for example on the command line), or explicit member functions (such as those of the genetic algorithm objects).  All of the #defined names are simply the full names declared as #defined strings; you can use either the string (e.g. number_of_generations) or the #defined name (e.g. gaNnGenerations), but if you use the #defined name then the compiler will be able to catch your spelling mistakes.</p><p>When you specify GAlib arguments on the command line, they must be in name-value pairs.  You can use either the long or short name.  For example, if my program is called <i>optimizer</i>, the command line for running the program with a population size of 150, mutation rate of 10%, and score filename of evolve.txt would be:<pre>optimizer popsize 150 pmut 0.1 sfile evolve.txt</pre></p></blockquote><br><br><br><br><a name="constants"><big><strong>Global Variables and Global Constants</strong></big></a><br><hr><blockquote><pre>char* gaErrMsg;    // globally defined pointer to current error message</pre><pre>int  gaDefScoreFrequency1 = 1;   // for non-overlapping populationsint  gaDefScoreFrequency2 = 100; // for overlapping populationsfloat gaDefLinearScalingMultiplier   = 1.2;float gaDefSigmaTruncationMultiplier = 2.0;float gaDefPowerScalingFactor        = 1.0005;float gaDefSharingCutoff             = 1.0;</pre></blockquote><br><br><br><br><a name="random"><big><strong>Random Number Functions</strong></big></a><br><hr><blockquote>GAlib includes the following functions for generating random numbers:<pre>     void <b>GARandomSeed</b>(unsigned s = <i>0</i>)      int <b>GARandomInt</b>()      int <b>GARandomInt</b>(int low, int high)   double <b>GARandomDouble</b>()   double <b>GARandomDouble</b>(double low, double high)    float <b>GARandomFloat</b>()    float <b>GARandomFloat</b>(float low, float high)      int <b>GARandomBit</b>()GABoolean <b>GAFlipCoin</b>(float p)      int <b>GAGaussianInt</b>(int stddev)    float <b>GAGaussianFloat</b>(float stddev)   double <b>GAGaussianDouble</b>(double stddev)   double <b>GAUnitGaussian</b>()</pre><p>If you call it with no argument, the GARandomSeed function uses the current time multiplied by the process ID (on systems that have PIDs) as the seed for a psuedo-random number generator.  On systems with no process IDs it uses only the time.  You can specify your own random seed if you like by passing a value to this function.  Once a seed has been specified, subsequent calls to GARandomSeed with the same value have no effect.  Subsequent calls to GARandomSeed with a different value will re-initialize the random number generator using the new value.</p><p>The functions that take low and high as argument return a random number from low to high, <i>inclusive</i>.  The functions that take no arguments return a value in the interval [0,1].  GAFlipCoin returns a boolean value based on a biased coin toss.  If you give it a value of 1 it will return a 1, if you give it a value of 0.75 it will return a 1 with a 75% chance. </p><p>The GARandomBit function is the most efficient way to do unbiased coin tosses.  It uses the random bit generator described in <a href="http://nr.harvard.edu/nr/bookc.html">Numerical Recipes in C</a>.</p><p>The Gaussian functions return a random number from a Gaussian distribution with deviation that you specify.  The GAUnitGaussian function returns a number from a unit Gaussian distribution with mean 0 and deviation of 1.</p><p>GAlib uses a single random number generator for the entire library.  You may not change the random number generator on the fly - it can be changed only when GAlib is compiled.  See the config.h and random.h header files for details.  By default, GAlib uses the <i>ran2</i> generator described in <a href="http://nr.harvard.edu/nr/bookc.html">Numerical Recipes in C</a>.</p></blockquote><br><br><br><br><a name="errors"><big><strong>Error Handling</strong></big></a><br><hr><blockquote>Exceptions are not used in GAlib version 2.x.  However, some GAlib functions return a status value to indicate whether or not their operation was successful.  If a function returns an error status, it posts its error message on the global GAlib error pointer, a global string called gaErrMsg.<p>By default, GAlib error messages are sent immediately to the error stream.  You can disable the immediate printing of error messages by passing gaFalse to the ::GAReportErrors function.  Passing a value of gaTrue enables the behavior.</p><p>If you would like to redirect the error messages to a different stream, use the ::GASetErrorStream function to assign a new stream.  The default stream is the system standard error stream, cerr.</p><p>Here are the error control functions and variables:

⌨️ 快捷键说明

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