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

📄 population.htm

📁 遗传算法GPE_release_v1.0.tar
💻 HTM
📖 第 1 页 / 共 2 页
字号:
          CodeCompileUnit cuu = </font></font><font SIZE="2" face="Courier New">
          new</font><font SIZE="2"><font face="Courier New"> CodeCompileUnit();</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">//get Individuals</p>
          </font><font SIZE="2">
          <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp; 
          ICollection individuals = Values;</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">//add base class 
          namespace</p>
          </font><font SIZE="2">
          <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp; 
          CodeNamespace namespaces = </font></font>
          <font SIZE="2" face="Courier New">new</font><font SIZE="2"><font face="Courier New"> 
          CodeNamespace( BaseClass.Namespace );</font></p>
          <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp; 
          cuu.Namespaces.Add( namespaces );</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">//add code for each 
          Individual in Population</p>
          </font><font SIZE="2">
          <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp; 
          StringCollection namesCollection = </font></font>
          <font SIZE="2" face="Courier New">new</font><font SIZE="2"><font face="Courier New"> 
          StringCollection();</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( 
          IndividualInfo individual in</font><font SIZE="2"><font face="Courier New"> 
          individuals ) {</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">( 
          includeTested || individual.Generation == Generation ) {</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; 
          namesCollection.Add( individual.Name );</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; 
          namespaces.Types.Add( individual.GenerateCodeDomClass() );</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">&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">//if the output 
          directory does not exist, create it</p>
          <p style="margin-top: 0; margin-bottom: 0">&nbsp;&nbsp;&nbsp; if</font><font SIZE="2"><font face="Courier New">( 
          !Directory.Exists( outputDirectory ) ) {</font></p>
          <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
          Directory.CreateDirectory( outputDirectory );</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">//path to the code 
          file = output directory, </p>
          </font><font SIZE="2">
          <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp; 
          m_CodeFile = outputDirectory </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">//plus ending slash if 
          not already there, </p>
          </font><font SIZE="2">
          <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
          + (outputDirectory[outputDirectory.Length - 1] == 
          Path.DirectorySeparatorChar ?</font></p>
          <p style="margin-top: 0; margin-bottom: 0">
          <font SIZE="2" face="Courier">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
          </font><font face="Courier New">&nbsp;&quot;&quot; : &quot;&quot; + 
          Path.DirectorySeparatorChar) </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">//plus file name</p>
          </font><font SIZE="2">
          <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
          + CodeFile;</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">//get a code type 
          provider for C#</p>
          <p style="margin-top: 0; margin-bottom: 0">&nbsp;&nbsp;&nbsp; using( 
          CodeDomProvider codeProvider = new</font><font SIZE="2"><font face="Courier New"> 
          CSharpCodeProvider() ) {</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">&nbsp;&nbsp;&nbsp; 
          //create the output file and output the Population code in it</p>
          <p style="margin-top: 0; margin-bottom: 0">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
          using( FileStream fs = new FileStream( CodeFile, FileMode.Create,</font></p>
          <p style="margin-top: 0; margin-bottom: 0">
          <font SIZE="2" face="Courier New">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
          FileAccess.Write,</font><font SIZE="2"><font face="Courier New"> 
          FileShare.None ) )</font></p>
          <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp;
          </font><font SIZE="2" face="Courier New">&nbsp;&nbsp;&nbsp; </font>
          </font><font SIZE="2" face="Courier New">using( StreamWriter sw = new</font><font SIZE="2"><font face="Courier New"> 
          StreamWriter( fs ) )</font></p>
          <p style="margin-top: 0; margin-bottom: 0">
          <font SIZE="2" face="Courier New">&nbsp;&nbsp;&nbsp; </font>
          <font face="Courier New">&nbsp;&nbsp;&nbsp; </font></font>
          <font SIZE="2" face="Courier New">using( IndentedTextWriter outputFile 
          = new IndentedTextWriter( sw, &quot; &quot; ) ) {</font></p>
          <font SIZE="2">
          <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
          </font><font SIZE="2" face="Courier New">&nbsp;&nbsp;&nbsp; </font>
          <font face="Courier New">ICodeGenerator codeGenerator = 
          codeProvider.CreateGenerator();</font></p>
          <p style="margin-top: 0; margin-bottom: 0">
          <font SIZE="2" face="Courier New">&nbsp;&nbsp;&nbsp; </font>
          <font face="Courier New">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
          codeGenerator.GenerateCodeFromCompileUnit( cuu, outputFile, </font>
          </font><font SIZE="2" face="Courier New">new</font></p>
          <p style="margin-top: 0; margin-bottom: 0">
          <font SIZE="2" face="Courier New">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
          </font><font SIZE="2"><font face="Courier New">CodeGeneratorOptions()&nbsp;&nbsp;&nbsp;&nbsp; 
          );</font></p>
          <p style="margin-top: 0; margin-bottom: 0">
          <font SIZE="2" face="Courier New">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
          </font><font face="Courier New">}</font></p>
          <p style="margin-top: 0; margin-bottom: 0">
          <font SIZE="2" face="Courier New">&nbsp;&nbsp;&nbsp; </font>
          <font face="Courier New">}</font></p>
          <p style="margin-top: 0; margin-bottom: 0">
          <font SIZE="2" face="Courier New">&nbsp;&nbsp;&nbsp; </font></font>
          <font SIZE="2" face="Courier New">//return names</p>
          </font><font SIZE="2">
          <p style="margin-top: 0; margin-bottom: 0">
          <font SIZE="2" face="Courier New">&nbsp;&nbsp;&nbsp; </font></font>
          <font SIZE="2" face="Courier New">string[] names = new string</font><font SIZE="2"><font face="Courier New">[namesCollection.Count];</font></p>
          <p style="margin-top: 0; margin-bottom: 0">
          <font SIZE="2" face="Courier New">&nbsp;&nbsp;&nbsp; </font>
          <font face="Courier New">namesCollection.CopyTo( names, 0 );</font></p>
          <p style="margin-top: 0; margin-bottom: 0">
          <font SIZE="2" face="Courier New">&nbsp;&nbsp;&nbsp; </font></font>
          <font SIZE="2" face="Courier New">return</font><font SIZE="2"><font face="Courier New"> 
          names;</font></p>
          <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">} 
          //end GenerateCodeFile method definition</font></font></td>
        </tr>
      </table>
      </center>
  </div>
  <p class="dtH4"><font face="Arial">The OnValidate override ensures that 
  IndividualInfos being added have the same <i>Base</i> <i>Class </i>type.</font></p>
	<div align="center">
      <center>
      <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="90%" id="AutoNumber6">
        <tr>
          <td width="100%"><font SIZE="2">
          <p style="margin-top: 0; margin-bottom: 0"></font>
          <font SIZE="2" face="Courier New">protected override void OnValidate( 
          object key, object value</font><font SIZE="2"><font face="Courier New"> 
          ) {</font></p>
          <p style="margin-top: 0; margin-bottom: 0">
          <font SIZE="2" face="Courier New">&nbsp;&nbsp;&nbsp; </font></font>
          <font SIZE="2" face="Courier New">base.OnValidate( key, value</font><font SIZE="2"><font face="Courier New"> 
          );</font></p>
          <p style="margin-top: 0; margin-bottom: 0">
          <font SIZE="2" face="Courier New">&nbsp;&nbsp;&nbsp; </font>
          <font face="Courier New">Type baseClass = ((IndividualInfo) </font>
          </font><font SIZE="2" face="Courier New">value</font><font SIZE="2"><font face="Courier New">).BaseClass;</font></p>
          <p style="margin-top: 0; margin-bottom: 0">
          <font SIZE="2" face="Courier New">&nbsp;&nbsp;&nbsp; </font></font>
          <font SIZE="2" face="Courier New">if</font><font SIZE="2"><font face="Courier New">( 
          Empty ) {</font></p>
          <p style="margin-top: 0; margin-bottom: 0">
          <font SIZE="2" face="Courier New">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
          </font><font face="Courier New">m_BaseClass = baseClass;</font></p>
          <p style="margin-top: 0; margin-bottom: 0">
          <font SIZE="2" face="Courier New">&nbsp;&nbsp;&nbsp; </font>
          <font face="Courier New">}</font></p>
          <p style="margin-top: 0; margin-bottom: 0">
          <font SIZE="2" face="Courier New">&nbsp;&nbsp;&nbsp; </font></font>
          <font SIZE="2" face="Courier New">else if</font><font SIZE="2"><font face="Courier New">( 
          m_BaseClass != baseClass ) {</font></p>
          <p style="margin-top: 0; margin-bottom: 0">
          <font SIZE="2" face="Courier New">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
          </font></font><font SIZE="2" face="Courier New">throw new 
          ArgumentException( &quot;The value for an IndividualInfo item added to the</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;Population had a 
          different BaseClass Type.&quot;, &quot;value&quot; );</font></p>
          <p style="margin-top: 0; margin-bottom: 0">
          <font SIZE="2" face="Courier New">&nbsp;&nbsp;&nbsp; </font>
          <font face="Courier New">}</font></p>
          <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">}</font></font></td>
        </tr>
      </table>
      </center>
  </div>
  <h4 class="dtH4">&nbsp;</h4>
	<h4 class="dtH4"><font face="Arial">See Also</font></h4>
  <p><font face="Arial"><a href="../GPE.htm">GPEngine</a> |
  <a href="../ProblemSpace/Individual.htm">IIndividual</a> |
  <a href="IndividualInfo.htm">IndividualInfo</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 + -