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

📄 api.html

📁 这是一个面向对象的GA遗传算法库GAlib: A C++ Library of Genetic Algorithm Components)
💻 HTML
📖 第 1 页 / 共 5 页
字号:
const GAPopulation&amp; <b>population</b>(unsigned int i) constconst GAPopulation&amp; <b>population</b>(int i, const GAPopulation&amp;)                int <b>populationSize</b>(unsigned int i) const                int <b>populationSize</b>(int i, unsigned int n)                int <b>nReplacement</b>(unsigned int i) const                int <b>nReplacement</b>(int i, unsigned int n)                int <b>nMigration</b>() const                int <b>nMigration</b>(unsigned int i)                int <b>nPopulations</b>() const                int <b>nPopulations</b>(unsigned int i)const GAStatistics&amp; <b>statistics</b>() constconst GAStatistics&amp; <b>statistics</b>(unsigned int i) const</pre></blockquote><big><strong>member function descriptions</strong></big><br><blockquote><dl>  <dt><b>nMigration</b>  <dd>Specify the number of individuals to migrate each generation.  Each population will migrate this many of its best individuals to the next population (the stepping-stone migration model).  The individuals replace the worst individuals in the receiving population.  <dt><b>nReplacement</b>  <dd>Specify a number of individuals to replace each generation.  When you specify a number of individuals to replace, the pReplacement value is set to 0.  The first argument specifies which population should be modified.  Use GADemeGA::ALL to apply to all populations.        <dt><b>operator++</b>  <dd>The increment operator evolves the genetic algorithm's population by one generation by calling the <b>step</b> member function.         <dt><b>pReplacement</b>  <dd>Specify a percentage of the population to replace each generation.  When you specify a replacement percentage, the nReplacement value is set to 0.  The first argument specifies which population should be modified.  Use GADemeGA::ALL to apply to all populations.  <dt><b>registerDefaultParameters</b>  <dd>This function adds parameters to the specified list that are of interest to this genetic algorithm.  The default parameters for the deme genetic algorithm are the parameters for the base genetic algorithm class plus the following:       <ul>	 <li>nMigration	 <li>nPopulations       </ul></dl></blockquote><br><br><br><br><a name="completion"><big><strong>Terminators</strong></big></a><br><hr><blockquote>Completion functions are used to determine whether or not a genetic algorithm is finished.  The <b>done</b> member function simply calls the completion function to determine whether or not the genetic algorithm should continue.  The predefined completion functions use generation and convergence to determine whether or not the genetic algorithm is finished.<p>The completion function returns gaTrue when the genetic algorithm should finish, and gaFalse when the genetic algorithm should continue.</p><p>In this context, convergence refers to the the similarity of the objective scores, <i>not</i> similarity of underlying genetic structure.  The built-in convergence measures use the best-of-generation scores to determine whether or not the genetic algorithm has plateaued. </p><pre>GABoolean <b>GAGeneticAlgorithm::TerminateUponGeneration</b>(GAGeneticAlgorithm &amp;)GABoolean <b>GAGeneticAlgorithm::TerminateUponConvergence</b>(GAGeneticAlgorithm &amp;)GABoolean <b>GAGeneticAlgorithm::TerminateUponPopConvergence</b>(GAGeneticAlgorithm &amp;)</pre><dl>  <p>  <dt><b>TerminateUponGeneration</b>  <dd>This function compares the current generation to the specified number of generations.  If the current generation is less than the requested number of generations, it returns gaFalse.  Otherwise, it returns gaTrue.       </p>       <p>  <dt><b>TerminateUponConvergence</b>  <dd>This function compares the current convergence to the specified convergence value.  If the current convergence is less than the requested convergence, it returns gaFalse.  Otherwise, it returns gaTrue.        </p>       <p>       Convergence is a number between 0 and 1.  A convergence of 1 means that the nth previous best-of-generation is equal to the current best-of-generation.  When you use convergence as a stopping criterion you <i>must</i> specify the convergence percentage and you <i>may</i> specify the number of previous generations against which to compare.  The genetic algorithm will always run at least this many generations.       </p>       <p>  <dt><b>TerminateUponPopConvergence</b>  <dd>This function compares the population average to the score of the best individual in the population.  If the population average is within <i>pConvergence</i> of the best individual's score, it returns gaTrue.  Otherwise, it returns gaFalse.       </p>       </dl><p>For details about how to write your own termination function, see the <a href="Extensions.html">customizations</a> page.</p></blockquote><br><br><br><br><a name="replacement"><big><strong>Replacement Schemes</strong></big></a><br><hr><blockquote>The replacement scheme is used by the incremental genetic algorithm to determine how a new individual should be inserted into a population.  Valid replacement schemes include:<blockquote><pre>GAIncrementalGA::RANDOMGAIncrementalGA::BESTGAIncrementalGA::WORSTGAIncrementalGA::CUSTOMGAIncrementalGA::CROWDINGGAIncrementalGA::PARENT</pre></blockquote><p>In general, replace worst produces the best results.  Replace parent is useful for basic speciation, and custom replacement can be used when you want to do your own type of speciation.</p><p>If you specify CUSTOM or CROWDING replacement then you must also specify a replacement function.  The replacement function takes as arguments an individual and the population into which the individual should be placed.  It returns a reference to the genome that the individual should replace.  If the individual should not be inserted into the population, the function should return a reference to the individual.</p><p>Any replacement function must have the following function prototype:<pre>typedef GAGenome&amp; (*<b>GAIncrementalGA::ReplacementFunction</b>)(GAGenome &amp;, GAPopulation &amp;);</pre>The first argument is the genome that will be inserted into the population, the second argument is the population into which the genome should be inserted.  The function should return a reference to the genome that will be replaced.  If no replacement occurs, the function should return a reference to the original genome.</p><p>For details about how to write your own replacement function, see the <a href="Extensions.html">customizations</a> page.</p></blockquote><br><br><br><br><a name="evaldata"><big><strong>GAEvalData</strong></big></a><br><hr><blockquote>The evaluation data object is a generic base class for genome- and/or population-specific data.  Whereas the userData member of the genome is shared by all genomes in a population, the evalData member is unique to each genome.  The base class defines the copy/clone interface for the evaluation data object.  Your derived classes should use this mechanism.  Any derived class <i>must</i> define a <b>clone</b> and <b>copy</b> member function.  These will be called by the base class when the evaluation data is cloned/copied by the genomes/populations.</blockquote><big><strong>class hierarchy</strong></big><br><blockquote><pre>class GAEvalData : public GAID</pre></blockquote><big><strong>constructors</strong></big><br><blockquote><pre>GAEvalData()GAEvalData(const GAEvalData&amp;) </pre></blockquote><big><strong>member functions</strong></big><br><blockquote><pre>GAEvalData* <b>clone</b>() const       void <b>copy</b>(const GAEvalData&amp;)</pre></blockquote><br><br><br><br><a name="genome_base"><big><strong>GAGenome</strong></big></a><br><hr><blockquote>The genome is a virtual base class and cannot be instantiated.  It defines a number of constants and function prototypes specific to the genome and its derived classes.<p>The dimension is used to specify which dimension is being referred to in multi-dimensional genomes.  The <b>clone</b> method specifies whether to clone the entire genome (a new genome with contents identical to the original will be created) or just the attributes of the genome (a new genome with identical characteristics will be created).  In both cases the caller is responsible for deleting the memory allocated by the <b>clone</b> member function.  The resize constants are used when specifying a resizable genome's resize behavior.</p><p>The genetic operators for genomes are functions that take generic genomes as their arguments.  This makes it possible to define new behaviors for existing genome classes without deriving a new class.  The genetic operators are defined with the following prototypes:</p><p>Instructions for deriving your own genome class are in the <a href="Extensions.html">customization</a> page.</p></blockquote><big><strong>class hierarchy</strong></big><br><blockquote><pre>class GAGenome : public GAID</pre></blockquote><big><strong>typedefs and constants</strong></big><br><blockquote><pre>enum GAGenome::Dimension { <b>LENGTH</b>, <b>WIDTH</b>, <b>HEIGHT</b>, <b>DEPTH</b> }enum GAGenome::CloneMethod { <b>CONTENTS</b>, <b>ATTRIBUTES</b> }enum { <b>FIXED_SIZE</b> = -1, <b>ANY_SIZE</b> = -10 }</pre><pre>    float (*<b>GAGenome::Evaluator</b>)(GAGenome &amp;)     void (*<b>GAGenome::Initializer</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*);</pre></blockquote><big><strong>member function index</strong></big><br><blockquote><pre>              virtual void <b>copy</b>(const GAGenome &amp; c)        virtual GAGenome * <b>clone</b>(CloneMethod flag = <i>CONTENTS</i>)                     float <b>score</b>(GABoolean flag = <i>gaFalse</i>)                     float <b>score</b>(float s)                       int <b>nevals</b>()                     float <b>evaluate</b>(GABoolean flag = <i>gaFalse</i>)       GAGenome::Evaluator <b>evaluator</b>() const       GAGenome::Evaluator <b>evaluator</b>(GAGenome::Evaluator func)                      void <b>initialize</b>()       GAGenomeInitializer <b>initializer</b>() const       GAGenomeInitializer <b>initializer</b>(GAGenome::Initializer func)                       int <b>mutate</b>(float pmutation)         GAGenome::Mutator <b>mutator</b>() const         GAGenome::Mutator <b>mutator</b>(GAGenome::Mutator func)                     float <b>compare</b>(const GAGenome&amp; g) const      GAGenome::Comparator <b>comparator</b>() const       GAGenome::Comparator <b>comparator</b>(GAGenome::Comparator c) GAGenome::SexualCrossover <b>crossover</b>(GAGenome::SexualCrossover func) GAGenome::SexualCrossover <b>sexual</b>()GAGenome::AsexualCrossover <b>crossover</b>(GAGenome::AsexualCrossover func)GAGenome::AsexualCrossover <b>asexual</b>()      GAGeneticAlgorithm * <b>geneticAlgorithm</b>() const      GAGeneticAlgorithm * <b>geneticAlgorithm</b>(GAGeneticAlgorithm &amp;)                    void * <b>userData</b>() const                    void * <b>userData</b>(void * data)              GAEvalData * <b>evalData</b>() const              GAEvalData * <b>evalData</b>(void * data)               virtual int <b>read</b>(istream &amp;)               virtual int <b>write</b>(ostream &amp;) const               virtual int <b>equal</b>(const GAGenome &amp;) const               virtual int <b>notequal</b>(const GAGenome &amp;) const</pre>These operators call the corresponding virtual members so that they will work on <i>any</i> properly derived genome class.<pre>              friend int <b>operator==</b>(const GAGenome&amp;, const GAGenome&amp;)              friend int <b>operator!=</b>(const GAGenome&amp;, const GAGenome&amp;)        friend ostream &amp; <b>operator&lt;&lt;</b>(ostream&amp;, const GAGenome&amp;)        friend istream &amp; <b>operator&gt;&gt;</b>(istream&amp;, GAGenome&amp;)</pre></blockquote><big><strong>member function descriptions</strong></big><br><blockquote><dl><dt><b>clone</b><dd>This method allocates space for a new genome whereas the copy method uses the space of the genome to which it belongs.  <dt><b>compare</b><dd>Compare two genomes.  The comparison can be genotype- or phenotype-based.  The comparison returns a value greater than or equal to 0.  0 means the two genomes are identical (no diversity).  The exact meaning of the comparison is up to you.<dt><b>comparator</b><dd>Set/Get the comparison method.  The comparator must have the correct <a href="#signatures">signature</a>.

⌨️ 快捷键说明

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