📄 api.html
字号:
</p><pre>extern char gaErrMsg[];void <b>GAReportErrors</b>(GABoolean flag);void <b>GASetErrorStream</b>(ostream&);</pre></blockquote><br><br><br><br><a name="ga_base"><big><strong>GAGeneticAlgorithm</strong></big></a><br><hr><blockquote>This is an abstract class that cannot be instantiated. Each genetic algorithm, when instantiated, will have default operators defined for it. See the documentation for the specific genetic algorithm type for details.<p>The base genetic algorithm class keeps track of evolution statistics such as number of mutations, number of crossovers, number of evaluations, best/mean/worst in each generation, and initial/current population statistics. It also defines the terminator, a member function that specifies the stopping criterion for the algorithm.</p><p>You can maximize or minimize by calling the appropriate member function. If you derive your own genetic algorithm, remember that users of your algorithm may need either type of optimization.</p><p>Statistics can be written to file each generation or periodically by specifying a flush frequency. Generational scores can be recorded each generation or less frequently by specifying a score frequency.</p><p>Parameters such as generations-to-completion, crossover probability and mutation probability can be set by member functions, command-line, or from file.</p><p>The <b>evolve</b> member function first calls <b>initialize</b> then calls the <b>step</b> member function until the <b>done</b> member function returns gaTrue. It calls the <b>flushScores</b> member as needed when the evolution is complete. If you evolve the genetic algorithm without using the <b>evolve</b> member function, be sure to call <b>initialize</b> before stepping through the evolution. You can use the <b>step</b> member function to evolve a single generation. You should call <b>flushScores</b> when the evolution is finished so that any buffered scores are flushed.</p><p>The names of the individual parameter member functions correspond to the #defined string names. You may set the parameters on a genetic algorithm one at a time (for example, using the <b>nGenerations</b> member function), using a parameter list (for example, using the <b>parameters</b> member function with a GAParameterList), by parsing the command line (for example, using the <b>parameters</b> member function with <i>argc</i> and <i>argv</i>), by name-value pairs (for example, using the <b>set</b> member function with a parameter name and value), or by reading a stream or file (for example, using the <b>parameters</b> member with a filename or stream).</p><i>see also: <a href="#ga_parameters">GAParameterList</a></i><br><i>see also: <a href="#ga_statistics">GAStatistics</a></i><br><i>see also: <a href="#ga_completion">Terminators</a></i><br></blockquote><big><strong>class hierarchy</strong></big><br><blockquote><pre>class GAGeneticAlgorithm : public GAID</pre></blockquote><big><strong>typedefs and constants</strong></big><br><blockquote><pre>GABoolean (*<b>GAGeneticAlgorithm::Terminator</b>)(GAGeneticAlgorithm &) enum { <b>MINIMIZE</b> = -1, <b>MAXIMIZE</b> = 1 };</pre></blockquote><big><strong>member function index</strong></big><br><blockquote><pre>static GAParameterList& <b>registerDefaultParameters</b>(GAParameterList&); void * <b>userData</b>() void * <b>userData</b>(void *) void <b>initialize</b>(unsigned int seed=0) void <b>evolve</b>(unsigned int seed=0) void <b>step</b>() GABoolean <b>done</b>()GAGeneticAlgorithm::Terminator <b>terminator</b>()GAGeneticAlgorithm::Terminator <b>terminator</b>(GAGeneticAlgorithm::Terminator) const GAStatistics & <b>statistics</b>() const float <b>convergence</b>() const int <b>generation</b>() const void <b>flushScores</b>() int <b>minimaxi</b>() const int <b>minimaxi</b>(int) int <b>minimize</b>() int <b>maximize</b>() int <b>nGenerations</b>() const int <b>nGenerations</b>(unsigned int) int <b>nConvergence</b>() const int <b>nConvergence</b>(unsigned int) float <b>pConvergence</b>() const float <b>pConvergence</b>(float) float <b>pMutation</b>() const float <b>pMutation</b>(float) float <b>pCrossover</b>() const float <b>pCrossover</b>(float) GAGenome::SexualCrossover <b>crossover</b>(GAGenome::SexualCrossover func); GAGenome::SexualCrossover <b>sexual</b>() const; GAGenome::AsexualCrossover <b>crossover</b>(GAGenome::AsexualCrossover func); GAGenome::AsexualCrossover <b>asexual</b>() const; const GAPopulation & <b>population</b>() const const GAPopulation & <b>population</b>(const GAPopulation&) int <b>populationSize</b>() const int <b>populationSize</b>(unsigned int n) int <b>nBestGenomes</b>() const int <b>nBestGenomes</b>(unsigned int n) GAScalingScheme & <b>scaling</b>() const GAScalingScheme & <b>scaling</b>(const GAScalingScheme&) GASelectionScheme & <b>selector</b>() const GASelectionScheme & <b>selector</b>(const GASelectionScheme& s) void <b>objectiveFunction</b>(GAGenome::Evaluator) void <b>objectiveData</b>(const GAEvalData&) int <b>scoreFrequency</b>() const int <b>scoreFrequency</b>(unsigned int frequency) int <b>flushFrequency</b>() const int <b>flushFrequency</b>(unsigned int frequency) char* <b>scoreFilename</b>() const char* <b>scoreFilename</b>(const char *filename) int <b>selectScores</b>() const int <b>selectScores</b>(GAStatistics::ScoreID which) GABoolean <b>recordDiversity</b>() const GABoolean <b>recordDiversity</b>(GABoolean flag) const GAParameterList & <b>parameters</b>() const GAParameterList & <b>parameters</b>(const GAParameterList &) const GAParameterList & <b>parameters</b>(int& argc, char** argv, GABoolean flag = <i>gaFalse</i>) const GAParameterList & <b>parameters</b>(const char* filename, GABoolean flag = <i>gaFalse</i>); const GAParameterList & <b>parameters</b>(istream&, GABoolean flag = <i>gaFalse</i>); int <b>set</b>(const char* s, int v) int <b>set</b>(const char* s, unsigned int v) int <b>set</b>(const char* s, char v) int <b>set</b>(const char* s, const char* v) int <b>set</b>(const char* s, const void* v) int <b>set</b>(const char* s, double v); int <b>write</b>(const char* filename) int <b>write</b>(ostream&) int <b>read</b>(const char* filename) int <b>read</b>(ostream&)</pre></blockquote><big><strong>member function descriptions</strong></big><br><blockquote><dl><dt><b>convergence</b><dd>Returns the current convergence. The convergence is defined as the ratio of the Nth previous best-of-generation score to the current best-of-generation score.<dt><b>crossover</b><dd>Specify the mating method to use for evolution. This can be changed during the course of an evolution. This genetic algorithm uses only sexual crossover.<dt><b>done</b><dd>Returns gaTrue if the termination criteria have been met, returns gaFalse otherwise. This function simply calls the completion function that was specified using the <b>terminator</b> member function.<dt><b>evolve</b><dd>Initialize the genetic algorithm then evolve it until the termination criteria have been satisfied. This function first calls <b>initialize</b> then calls the <b>step</b> member function until the <b>done</b> member function returns gaTrue. It calls the <b>flushScores</b> member as needed when the evolution is complete. You may pass a seed to evolve if you want to specify your own random seed.<dt><b>flushFrequency</b><dd>Use this member function to specify how often the scores should be flushed to disk. A value of 0 means do not write to disk. A value of 100 means to flush the scores every 100 generations.<dt><b>flushScores</b><dd>Force the genetic algorithm to flush its generational data to disk. If you have specified a flushFrequency of 0 or specified a scoreFilename of nil then calling this function has no effect.<dt><b>generation</b><dd>Returns the current generation.<dt><b>initialize</b><dd>Initialize the genetic algorithm. If you specify a seed, this function calls GARandomSeed with that value. If you do not specify a seed, GAlib will choose one for you as described in the <a href="#random">random functions</a> section. It then initializes the population and does the first population evaluation.<dt><b>nBestGenomes</b><dd>Specify how many 'best' genomes to record. For example, if you specify 10, the genetic algorithm will keep the 10 best genomes that it ever encounters. Beware that if you specify a large number here the algorithm will slow down because it must compare the best of each generation with its current list of best individuals. The default is 1.<dt><b>nConvergence</b><dd>Set/Get the number of generations used for the convergence test.<dt><b>nGenerations</b><dd>Set/Get the number of generations.<dt><b>objectiveData</b><dd>Set the objective data member on all individuals used by the genetic algorithm. This can be changed during the course of an evolution.<dt><b>objectiveFunction</b><dd>Set the objective function on all individuals used by the genetic algorithm. This can be changed during the course of an evolution.<dt><b>parameters</b><dd>Returns a reference to a parameter list containing the current values of the genetic algorithm parameters.<dt><b>parameters</b>(GAParameterList&)<dd>Set the parameters for the genetic algorithm. To use this member function you must create a parameter list (an array of name-value pairs) then pass it to the genetic algorithm. <dt><b>parameters</b>(int& argc, char** argv, GABoolean flag = <i>gaFalse</i>)<dd>Set the parameters for the genetic algorithm. Use this member function to let the genetic algorithm parse your command line for arguments that GAlib understands. This method decrements argc and moves the pointers in argv appropriately to remove from the list the arguments that it understands. If you pass gaTrue as the third argument then the method will complain about any command-line arguments that are not recognized by this genetic algorithm.<dt><b>parameters</b>(char* filename, GABoolean flag = <i>gaFalse</i>)<dt><b>parameters</b>(istream&, GABoolean flag = <i>gaFalse</i>)<dd>Set the parameters for the genetic algorithm. This version of the parameters member function will parse the specified file or stream for parameters that the genetic algorithm understands. If you pass gaTrue as the second argument then the method will complain about any parameters that are not recognized by this genetic algorithm.<dt><b>pConvergence</b><dd>Set/Get the convergence percentage. The convergence is defined as the ratio of the <i>N</i>th previous best-of-generation score to the current best-of-generation score. <i>N</i> is defined by the <b>nConvergence</b> member function.<dt><b>pCrossover</b><dd>Set/Get the crossover probability.<dt><b>pMutation</b><dd>Set/Get the mutation probability.<dt><b>population</b><dd>Set/Get the population. Returns a reference to the current population.<dt><b>populationSize</b><dd>Set/Get the population size. This can be changed during the course of an evolution.<dt><b>recordDiversity</b><dd>Convenience function for specifying whether or not to calculate diversity. Since diversity calculations require comparison of each individual with every other, recording this statistic can be expensive. The default is gaFalse (diversity is not recorded).<dt><b>registerDefaultParameters</b><dd>Each genetic algorithm defines this member function to declare the parameters that work with it. Pass a parameter list to this function and this function will configure the list with the default parameter list and values for the genetic algorithm class from which you called it. This is a statically defined function, so invoke it using the class name of the genetic algorithm whose parameters you want to use, for example, GASimpleGA::registerDefaultParameters(list). The default parameters for the base genetic algorithm class are: <ul> <li>flushFrequency <li>minimaxi <li>nBestGenomes <li>nGenerations <li>nConvergence <li>pConvergence <li>pCrossover <li>pMutation <li>populationSize <li>recordDiversity <li>scoreFilename <li>scoreFrequency <li>selectScores </ul><dt><b>scaling</b><dd>Set/Get the scaling scheme. The specified scaling scheme must be derived from the <a href="#scaling">GAScalingScheme</a> class. This can be changed during the course of an evolution.<dt><b>scoreFilename</b><dd>Specify the name of the file to which the scores should be recorded.<dt><b>scoreFrequency</b><dd>Specify how often the generational scores should be recorded. The default depends on the type of genetic algorithm that you are using. You can record mean, max, min, stddev, and diversity for every n generations.<dt><b>selector</b><dd>Set/Get the selection scheme for the genetic algorithm. The selector is used to pick individuals from a population before mating and mutation occur. This can be changed during the course of an evolution.<dt><b>selectScores</b><dd>This function is used to specify which scores should be saved to disk. The argument is the logical OR of the following values: Mean, Maximum, Minimum, Deviation, Diversity (all defined in the scope of the GAStatistics object). To record all of the scores, pass GAStatistics::AllScores. When written to file, the format is as follows:<pre>generation TAB mean TAB max TAB min TAB deviation TAB diversity NEWLINE</pre><dt><b>set</b><dd>Set individual parameters for the genetic algorithm. The first argument should be the full- or short-name of the parameter you wish to set. The second argument is the value to which you would like to set the parameter.<dt><b>statistics</b><dd>Returns a reference to the statistics object in the genetic algorithm. The statistics object maintains information such as best, worst, mean, and standard deviation, and diversity of each generation as well as a separate population with the best individuals ever encountered by the genetic algorithm.<dt><b>step</b><dd>Evolve the genetic algorithm for one generation.<dt><b>terminator</b><dd>Set/Get the termination function. The genetic algorithm is complete when the completion function returns gaTrue. The function must have the proper <a href="#signatures">signature</a>.<dt><b>userData</b><dd>Set/Get the userData member of the genetic algorithm. This member is a generic pointer to any information that needs to be stored with the genetic algorithm.</dl></blockquote><br><br><br><br><a name="ga_non_overlapping"><big><strong>GASimpleGA</strong></big> (non-overlapping populations)</a><br><hr><blockquote>This genetic algorithm is the 'simple' genetic algorithm that Goldberg describes in his book. It uses non-overlapping populations. When you create a simple genetic algorithm, you must specify either an individual or a population of individuals. The new genetic algorithm will clone the individual(s) that you specify to make its own population. You can change most of the genetic algorithm behaviors after creation and during the course of the evolution.<p>The simple genetic algorithm creates an initial population by cloning the individual or population you pass when you create it. Each generation the algorithm creates an entirely new population of individuals by selecting from the previous population then mating to produce the new offspring for the new population. This process continues until the stopping criteria are met (determined by the terminator).</p>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -