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

📄 generationhistory.htm

📁 遗传算法GPE_release_v1.0.tar
💻 HTM
📖 第 1 页 / 共 4 页
字号:
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp;
        </font></font><font SIZE="2" face="Courier New">//only 
        update if necessary</p>
        </font><font SIZE="2">
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp;
        </font></font><font SIZE="2" face="Courier New">if( 
        !UpdateProperties ) return</font><font SIZE="2"><font face="Courier New">;</font></p>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp;
        </font></font><font SIZE="2" face="Courier New">//check 
        that aggregator and normalizer are set</p>
        </font><font SIZE="2">
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp;
        </font></font><font SIZE="2" face="Courier New">if( 
        Aggregator == null</font><font SIZE="2"><font face="Courier New"> 
        ) {</font></p>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        </font></font><font SIZE="2" face="Courier New">
        throw new 
        InvalidOperationException( &quot;GenerationHistory cannot update fitness</font></p>
        <p style="margin-top: 0; margin-bottom: 0">
        <font face="Courier New" SIZE="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        </font><font SIZE="2"><font face="Courier New">&nbsp;statistics before 
        the Aggregator property has been set.&quot; );</font></p>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp; 
        }</font></p>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp;
        </font></font><font SIZE="2" face="Courier New">if( 
        Normalizer == null</font><font SIZE="2"><font face="Courier New"> 
        ) {</font></p>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        </font></font><font SIZE="2" face="Courier New">
        throw new 
        InvalidOperationException( &quot;GenerationHistory cannot update fitness</font></p>
        <p style="margin-top: 0; margin-bottom: 0">
        <font face="Courier New" SIZE="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        </font><font SIZE="2"><font face="Courier New">&nbsp;statistics before 
        the Normalizer property has been set.&quot; );</font></p>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp; 
        }</font></p>
        <p style="margin-top: 0; margin-bottom: 0">&nbsp;</p>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp;
        </font></font><font SIZE="2" face="Courier New">
        //aggregate</p>
        </font><font SIZE="2">
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp;
        </font></font><font SIZE="2" face="Courier New">
        decimal[] aggregatedFitnesses = new decimal</font><font SIZE="2"><font face="Courier New">[Count];</font></p>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp;
        </font></font><font SIZE="2" face="Courier New">int</font><font SIZE="2"><font face="Courier New"> 
        index = 0;</font></p>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp;
        </font></font><font SIZE="2" face="Courier New">
        foreach( HistoryInfo hi in this</font><font SIZE="2"><font face="Courier New"> 
        ) {</font></p>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        </font></font><font SIZE="2" face="Courier New">if</font><font SIZE="2"><font face="Courier New">( 
        hi.Histories.Empty ) {</font></p>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        </font></font><font SIZE="2" face="Courier New">
        throw new 
        InvalidOperationException( &quot;GenerationHistory cannot update fitness</font></p>
        <p style="margin-top: 0; margin-bottom: 0">
        <font face="Courier New" SIZE="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        </font><font SIZE="2"><font face="Courier New">statistics before 
        Histories have been filled for every individual.&quot; );</font></p>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
        }</font></p>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
        aggregatedFitnesses[index] = hi.AggregatedFitness = Aggregator( 
        hi.Histories );</font></p>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
        ++index;</font></p>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp; 
        }</font></p>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp;
        </font><font SIZE="2" face="Courier New">//set values to 
        opposite of calculated value</p>
        </font>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp; if( MaximizeFitness ) {</font></p>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
        m_BestFitness = decimal.MinValue;</font></p>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
        m_WorstFitness = decimal.MaxValue;</font></p>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp; 
        }</font></p>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp; else {</font></p>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
        m_BestFitness = decimal.MaxValue;</font></p>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
        m_WorstFitness = decimal.MinValue;</font></p>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp; 
        }</font></p>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp; 
        m_BestIndividual = null;</font></p>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp; 
        m_WorstIndividual = null;</font></p>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp;
        </font><font SIZE="2" face="Courier New">//use average 
        fitness as the sum while calculating</p>
        </font>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp; 
        m_AverageFitness = 0;</font></p>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp;
        </font><font SIZE="2" face="Courier New">//normalize and 
        update stats</p>
        </font>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp; 
        index = 0;</font></p>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp; decimal workingFitness;</font></p>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp; foreach( HistoryInfo hi in
        this ) {</font></p>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
        workingFitness = hi.NormalizedFitness = Normalizer( 
        aggregatedFitnesses[index],</font></p>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
        aggregatedFitnesses );</font></p>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
        m_AverageFitness += workingFitness;</font></p>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
        ++index;</font></p>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if( MaximizeFitness ) {</font></p>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        </font><font SIZE="2" face="Courier New">//maximize best 
        fitness</p>
        </font>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if( workingFitness &gt; m_BestFitness 
        ) {</font></p>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
        m_BestFitness = workingFitness;</font></p>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
        m_BestIndividual = hi;</font></p>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
        }</font></p>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if( workingFitness &lt; 
        m_WorstFitness ) {</font></p>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
        m_WorstFitness = workingFitness;</font></p>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
        m_WorstIndividual = hi;</font></p>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
        }</font></p>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
        }</font></p>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else {</font></p>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        </font><font SIZE="2" face="Courier New">//minimize best 
        fitness</p>
        </font>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if( workingFitness &lt; m_BestFitness 
        ) {</font></p>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
        m_BestFitness = workingFitness;</font></p>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
        m_BestIndividual = hi;</font></p>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
        }</font></p>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if( workingFitness &gt; 
        m_WorstFitness ) {</font></p>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
        m_WorstFitness = workingFitness;</font></p>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
        m_WorstIndividual = hi;</font></p>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
        }</font></p>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
        }</font></p>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp; 
        }</font></p>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp; 
        m_AverageFitness = m_AverageFitness/Count;</font></p>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp; 
        UpdateProperties = false;</font></p>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">}</font></font></td>
      </tr>
    </table>
    </center>
  </div>
	<p class="dtH4"><font face="Arial"><span style="font-weight: 400">The 
    Contains method determines whether the collection contains the specified 
    individual.</span></font></p>
  <div align="center">
    <center>
    <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="90%" id="AutoNumber20">
      <tr>
        <td width="100%"><font SIZE="2">
        <p style="margin-top: 0; margin-bottom: 0"></font>
        <font SIZE="2" face="Courier New">public bool 
        Contains( string</font><font SIZE="2"><font face="Courier New"> 
        key ) {</font></p>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp;
        </font></font><font SIZE="2" face="Courier New">return</font><font SIZE="2"><font face="Courier New"> 
        InnerDictionary.Contains( key );</font></p>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">}</font></font></td>
      </tr>
    </table>
    </center>
  </div>
	<p class="dtH4"><font face="Arial"><span style="font-weight: 400">The CopyTo 
    method copies the HistoryInfo objects to a one dimensional array.</span></font></p>
  <div align="center">
    <center>
    <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="90%" id="AutoNumber21">
      <tr>
        <td width="100%"><font SIZE="2">
        <p style="margin-top: 0; margin-bottom: 0"></font>
        <font SIZE="2" face="Courier New">public void CopyTo( 
        HistoryInfo[] destination, int</font><font SIZE="2"><font face="Courier New"> 
        index ) {</font></p>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp; 
        InnerDictionary.CopyTo( destination, index );</font></p>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">}</font></font></td>
      </tr>
    </table>
    </center>
  </div>
	<p class="dtH4">&nbsp;</p>
	<h4 class="dtH4"><font face="Arial">See Also</font></h4>
  <p><font face="Arial"><a href="EngineOptions.htm">EngineOptions</a> |
  <a href="../ProblemSpace/Individual.htm">IIndividual</a> | </font></p>
  <hr>
  <div id="footer">
    <font face="Arial">
    <a href="http://www.opensource.org/" target="_top">
    <img style="padding-bottom: 5px" src="http://opensource.org/trademarks/open_source_button.png" align="left" border="0"></a> 
    This software licensed under the
    <a href="http://opensource.org/licenses/afl-2.1.php" target="_top">Academic 
    Free License version 2.1</a>. (<a href="../../afl-2.1.txt">Plain 
    text</a>)</font></div>
</div>

</body>

</html>

⌨️ 快捷键说明

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