📄 population.htm
字号:
<html>
<head>
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Genetic Programming FAQ</title>
</head>
<body>
<div id="nsbanner">
<table cellSpacing="0" cellPadding="0" width="100%" border="0">
<tr>
<td>
<div id="bannerrow1">
<table class="bannerparthead" cellSpacing="0">
<tr id="hdr">
<td class="runninghead" style="font-size: 70%">
<font face="Arial"><a class="show" id="design_toggle" title="Show or hide design notes" href="../../index.html"><img src="../../Images/Icons/G.png" width="14" height="14" border="0" align="middle"/></a> Genetic Programming Engine FAQ</font></td>
</tr>
</table>
</div>
<div id="TitleRow">
<h1 class="dtH1" style="font-size: 85%; left: 5px; position: relative">
<font face="Arial">Creating the .CS Files for Individuals in a Population</font></h1>
</div>
</td>
<td vAlign="top" align="right">
<font face="Arial">
<img src="../../Images/Icons/GP_blue.png" width="191" height="39"></font></td>
</tr>
</table>
</div>
<div id="nstext">
<h4 class="dtH4"><font face="Arial"><span style="font-weight: 400">A
population represents a collection of individual programs to be tested by the
</span>GPEngine<span style="font-weight: 400">. It is a collection of
</span>IndividualInfos<span style="font-weight: 400"> or individuals before
they are compiled. The Population class is responsible for generating
the .CS code files for individuals in a population. Populations are
identified by their generation number with 0 being the first generation.</span></font></h4>
<p class="dtH4"><font face="Arial">The Population method initializes a new
instance of the Population class with the specified generation number.</font></p>
<div align="center">
<center>
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="90%" id="AutoNumber1">
<tr>
<td width="100%"><font SIZE="2">
<p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">
public Population( int generation ) {</font></p>
<p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">
Generation = generation;</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">The Generation method gets and sets the the
number of the generation this Population represents. Valid values are
integers greater than or equal to 0.</font></p>
<div align="center">
<center>
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="90%" id="AutoNumber2">
<tr>
<td width="100%"><font SIZE="2">
<p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">
public int Generation {</font></p>
<p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">
get {</font></p>
<p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">
return m_Generation;</font></p>
<p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">
}</font></p>
<p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">
set {</font></p>
<p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">
if( value < 0 ) {</font></p>
<p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">
</font></font><font SIZE="2" face="Courier New">throw new
ArgumentOutOfRangeException( "value", value, "The generation number
passed</font></p>
<p style="margin-top: 0; margin-bottom: 0"><font SIZE="2">
<font face="Courier New">
to Population.constructor was less than zero" );</font></p>
<p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">
}</font></p>
<p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">
m_Generation = value;</font></p>
<p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">
}</font></p>
<p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">}</font></p>
<p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">
private int m_Generation;</font></font></td>
</tr>
</table>
</center>
</div>
<p class="dtH4"><font face="Arial">The BaseClass method gets the type of the
IIndividual's <i>Base Class</i> in the Population. </font></p>
<div align="center">
<center>
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="90%" id="AutoNumber3">
<tr>
<td width="100%"><font SIZE="2">
<p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">
public Type BaseClass {</font></p>
<p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">
get {</font></p>
<p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">
return m_BaseClass;</font></p>
<p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">
}</font></p>
<p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">}</font></p>
<p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">
private Type m_BaseClass;</font></font></td>
</tr>
</table>
</center>
</div>
<p class="dtH4"><font face="Arial">The CodeFile method gets the name of the
generated code file before GenerateCodeFile (see below) is called and the full
path to the file after GenerateCodeFile is called. </font></p>
<div align="center">
<center>
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="90%" id="AutoNumber4">
<tr>
<td width="100%"><font SIZE="2">
<p style="margin-top: 0; margin-bottom: 0"></font>
<font SIZE="2" face="Courier New">public string</font><font SIZE="2"><font face="Courier New">
CodeFile {</font></p>
<p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">
</font></font><font SIZE="2" face="Courier New">get</font><font SIZE="2"><font face="Courier New">
{</font></p>
<p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">
</font></font><font SIZE="2" face="Courier New">if( m_CodeFile == null</font><font SIZE="2"><font face="Courier New">
) {</font></p>
<p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">
m_CodeFile = String.Format( "{0}_Generation{1}.cs", BaseClass.Name,
Generation );</font></p>
<p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">
}</font></p>
<p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">
</font></font><font SIZE="2" face="Courier New">return</font><font SIZE="2"><font face="Courier New">
m_CodeFile;</font></p>
<p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">
}</font></p>
<p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">}</font></p>
<p style="margin-top: 0; margin-bottom: 0"></font>
<font SIZE="2" face="Courier New">private string m_CodeFile;</font></td>
</tr>
</table>
</center>
</div>
<p class="dtH4"><font face="Arial">The GenerateCodeFile method creates the .CS
files that represent individuals. The IPrecodeTree of each
IndividualInfo in the Population is converted into computer code. This
is then saved in a file in the directory specified by the <i>OutputDirectory
</i>parameter. The file is named by the <b>IIndividual</b> <i>Base Class</i>
name plus the number of the current generation. If <i>includeTested </i>
is set to true, code for previously tested individuals is regenerated.
</font></p>
<div align="center">
<center>
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="90%" id="AutoNumber5">
<tr>
<td width="100%"><font SIZE="2">
<p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">
public</font></font><font SIZE="2" face="Courier New"> string[]
GenerateCodeFile( string outputDirectory, bool</font><font SIZE="2"><font face="Courier New">
includeTested ) {</font></p>
<p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">
</font></font><font SIZE="2" face="Courier New">//check that there are
individuals to generate code for</p>
<p style="margin-top: 0; margin-bottom: 0"> if</font><font SIZE="2"><font face="Courier New">(
Empty ) {</font></p>
<p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">
</font></font><font SIZE="2" face="Courier New">throw new
InvalidOperationException( "Population.GenerateCodeFile Cannot
generate</font></p>
<p style="margin-top: 0; margin-bottom: 0">
<font SIZE="2" face="Courier">
</font><font face="Courier New" SIZE="2"> code</font><font SIZE="2"><font face="Courier New">
for empty Population." );</font></p>
<p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">
}</font></p>
<p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">
</font></font><font SIZE="2" face="Courier New">//check output
directory</p>
<p style="margin-top: 0; margin-bottom: 0"> if(
outputDirectory == null</font><font SIZE="2"><font face="Courier New">
) {</font></p>
<p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">
</font></font><font SIZE="2" face="Courier New">throw new
ArgumentNullException( "outputDirectory", "The output directory passed</font></p>
<p style="margin-top: 0; margin-bottom: 0">
<font SIZE="2" face="Courier">
</font><font face="Courier New" SIZE="2"> to</font><font SIZE="2"><font face="Courier New">
Population.GenerateCodeFile was null." );</font></p>
<p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">
}</font></p>
<p style="margin-top: 0; margin-bottom: 0"> </p>
<p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">
</font></font><font SIZE="2" face="Courier New">//create a code
compile unit to generate the code</p>
</font><font SIZE="2">
<p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -