📄 individualinfo.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 IndividualInfos</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">The
IndividualInfo holds information about an </span>IIndividual<span style="font-weight: 400">.
This information includes the individual's generation number, its individual
number (to uniquely identify it within a generation), the type of its <i>Base
Class</i>, the </span>Precode<span style="font-weight: 400"> tree that makes
it up, and its parents (or null if in the first generation). This is
what makes up a </span>Population<span style="font-weight: 400">. </span>
</font></h4>
<p class="dtH4"><font face="Arial">The generationNumber and individualNumber
must be greater than or equal to 0. The individualNumber is the
number of this individual in its generation. The baseClass and Precode
tree must not be null. The individual's name is made up of the <i>Base
Class </i>name, generation number, and individual number. For example,
individual 39 of generation 3 of the AntIndividual base class would be named
AntIndividual_Generation3_Number39. </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</font></font><font SIZE="2" face="Courier New"> IndividualInfo(
int generationNumber, int individualNumber, Type baseClass,</font></p>
<p style="margin-top: 0; margin-bottom: 0">
<font face="Courier New" size="2"> IPrecodeTree precodeTree,
string</font><font SIZE="2"><font face="Courier New">[] parents ) {</font></p>
<p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">
</font></font><font SIZE="2" face="Courier New">//check that numbers
are non-negative</p>
<p style="margin-top: 0; margin-bottom: 0"> if</font><font SIZE="2"><font face="Courier New">(
generationNumber < 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( "generationNumber", generationNumber,
"The</font></p>
<p style="margin-top: 0; margin-bottom: 0">
<font face="Courier New" SIZE="2">
</font><font SIZE="2"><font face="Courier New"> generation number
passed to IndividualInfo.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">
</font></font><font SIZE="2" face="Courier New">if</font><font SIZE="2"><font face="Courier New">(
individualNumber < 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( "individualNumber", individualNumber,
"The</font></p>
<p style="margin-top: 0; margin-bottom: 0">
<font face="Courier New" SIZE="2">
</font><font SIZE="2"><font face="Courier New"> individual number
passed to IndividualInfo.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">
</font></font><font SIZE="2" face="Courier New">//check for null
arguments</p>
</font><font SIZE="2">
<p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">
</font></font><font SIZE="2" face="Courier New">if( baseClass == 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( "baseClass", "The base class type passed to</font></p>
<p style="margin-top: 0; margin-bottom: 0">
<font face="Courier New" SIZE="2">
</font><font SIZE="2"><font face="Courier New"> IndividualInfo.constructor
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"><font face="Courier New">
</font></font><font SIZE="2" face="Courier New">if( precodeTree ==
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( "precodeTree", "The precode tree passed to</font></p>
<p style="margin-top: 0; margin-bottom: 0">
<font face="Courier New" SIZE="2">
</font><font SIZE="2"><font face="Courier New"> IndividualInfo.constructor
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">//assign given values</p>
</font><font SIZE="2">
<p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">
m_Generation = generationNumber;</font></p>
<p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">
m_Number = individualNumber;</font></p>
<p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">
m_BaseClass = baseClass;</font></p>
<p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">
m_PrecodeTree = precodeTree;</font></p>
<p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">
m_Parents = (parents != </font></font>
<font SIZE="2" face="Courier New">null && parents.Length > 0 ? </font>
</p>
<p style="margin-top: 0; margin-bottom: 0">
<font face="Courier New" SIZE="2"> new
ReadOnlyStringCollection( parents ) : </font></p>
<p style="margin-top: 0; margin-bottom: 0">
<font face="Courier New" SIZE="2"> new
ReadOnlyStringCollection( new string</font><font SIZE="2"><font face="Courier New">[0]
));</font></p>
<p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">
m_Name = String.Format( "{0}_Generation{1}_Number{2}", BaseClass.Name,</font></p>
<p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">
Generation.ToString(), Number.ToString() );</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 Name method gets the name of the
individual as described above.</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>
<font SIZE="2" face="Courier New">public string</font><font SIZE="2"><font face="Courier New">
Name {</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">return</font><font SIZE="2"><font face="Courier New">
m_Name;</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 readonly string m_Name;</font></td>
</tr>
</table>
</center>
</div>
<p class="dtH4"><font face="Arial">The Generation method gets the Generation
of the individual.</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>
<font SIZE="2" face="Courier New">public int</font><font SIZE="2"><font face="Courier New">
Generation {</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">return</font><font SIZE="2"><font face="Courier New">
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -