📄 iprecode.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">How to Write IPrecodeTree for Different Problems</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
IPrecodeTree represents the operations performed by an </span>IIndividual<span style="font-weight: 400">
before they are converted to actual computer code. The IPrecodeTree
gives the </span>GPEngine<span style="font-weight: 400"> access to the
implementation-specific genetic operations of mutation and recombination.
Precode classes provide an abstract tree representation of the code that will
be written to each IIndividual's Test method. The IPrecodeTree can be
seen as a tree containing nodes which contain lines of code. These nodes
can be mutated and recombined to form new nodes. See "Getting Started"
for more information on mutation and recombination. The
Action-Perception (AP) tree is currently the Precode tree defined. The
AP tree handles the <i>void Method()</i> and the <i>bool Method()</i>.
Future improvements include support for various methods such as <i>int
Method()</i>, <i>int Method( int )</i>, <i>int Method( int, int )</i>, etc.
</span></font></h4>
<p class="dtH4"><font face="Arial">The MutationPoints method gets the number
of mutation points in this instance. See "Getting Started" for more
information on mutation. </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">int
MutationPoints {</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></td>
</tr>
</table>
</center>
</div>
<h4 class="dtH4"> </h4>
<p><font face="Arial">The RecombinationPoints method gets the number of
recombination points in this instance. See "Getting Started" for more
information on recombination. </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">int
RecombinationPoints {</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></td>
</tr>
</table>
</center>
</div>
<h4 class="dtH4"> </h4>
<p class="dtH4"><font face="Arial">The GenerateRandomTree method, using the
specified methods, generates a random Precode tree within the depth and width
constraints specified in the <b>EngineOptions</b>. After verifying that
the random number and available methods are not null and that the maximum
depth and width are greater than zero, a random tree is generated with the
valid methods.</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">
IPrecodeTree GenerateRandomTree( Random r, ReadOnlyMethodInfoCollection
availableMethods, </font></font></p>
<p style="margin-top: 0; margin-bottom: 0"> <font SIZE="2" face="Courier New">
int maxDepth, int</font><font face="Courier New" SIZE="2">
maxWidth );</font></td>
</tr>
</table>
</center>
</div>
<h4 class="dtH4" style="margin-top: 0; margin-bottom: 0"> </h4>
<div align="center">
<center>
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="90%" id="AutoNumber8">
<tr>
<td width="100%"><font SIZE="2">
<p style="margin-top: 0; margin-bottom: 0"></font>
<font SIZE="2" face="Courier New">public
IPrecodeTree GenerateRandomTree( Random r, ReadOnlyMethodInfoCollection</font></p>
<p style="margin-top: 0; margin-bottom: 0">
<font face="Courier New" size="2"> </font><font SIZE="2" face="Courier New">
availableMethods, int
maxDepth, int</font><font SIZE="2"><font face="Courier New">
maxWidth ) {</font></p>
<p style="margin-top: 0; margin-bottom: 0">
<font face="Courier New" size="2"> </font></font><font SIZE="2" face="Courier New">//check
that random number and methods are not null</p>
</font><font SIZE="2">
<p style="margin-top: 0; margin-bottom: 0">
<font face="Courier New" size="2"> </font></font>
<font SIZE="2" face="Courier New">if(
r == null</font><font SIZE="2"><font face="Courier New">
) {</font></p>
<p style="margin-top: 0; margin-bottom: 0">
<font face="Courier New" size="2">
</font></font><font SIZE="2" face="Courier New">
throw new</font><font face="Courier New" SIZE="2">
ArgumentNullException( "r", "The random number 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"> ActionPerceptionTree.GenerateRandomTree
method was null." );</font></p>
<p style="margin-top: 0; margin-bottom: 0">
<font face="Courier New" size="2"> </font>
<font face="Courier New">}</font></p>
<p style="margin-top: 0; margin-bottom: 0">
<font face="Courier New" size="2"> </font></font>
<font SIZE="2" face="Courier New">if(
availableMethods == null</font><font SIZE="2"><font face="Courier New">
) {</font></p>
<p style="margin-top: 0; margin-bottom: 0">
<font face="Courier New" size="2">
</font></font><font SIZE="2" face="Courier New">
throw new</font><font face="Courier New" SIZE="2">
ArgumentNullException( "availableMethods", "The collection of methods
passed</font></p>
<p style="margin-top: 0; margin-bottom: 0">
<font face="Courier New" size="2"> </font>
<font SIZE="2"><font face="Courier New"> to
ActionPerceptionTree.GenerateRandomTree method was null." );</font></p>
<p style="margin-top: 0; margin-bottom: 0">
<font face="Courier New" size="2"> </font>
<font face="Courier New">}</font></p>
<p style="margin-top: 0; margin-bottom: 0">
<font face="Courier New" size="2"> </font></font>
<font SIZE="2" face="Courier New">//check that depth and
width are in range</p>
</font><font SIZE="2">
<p style="margin-top: 0; margin-bottom: 0">
<font face="Courier New" size="2"> </font></font>
<font SIZE="2" face="Courier New">if</font><font SIZE="2"><font face="Courier New">(
maxDepth <= 0 ) {</font></p>
<p style="margin-top: 0; margin-bottom: 0">
<font face="Courier New" size="2">
</font></font><font SIZE="2" face="Courier New">
throw new</font><font face="Courier New" SIZE="2">
ArgumentOutOfRangeException( "maxDepth", maxDepth, "The maximum depth
passed</font></p>
<p style="margin-top: 0; margin-bottom: 0">
<font face="Courier New" size="2"> </font>
<font face="Courier New" SIZE="2"> to
ActionPerceptionTree.GenerateRandomTree method was less than or </font>
</p>
<p style="margin-top: 0; margin-bottom: 0">
<font face="Courier New" size="2"> </font>
<font SIZE="2"><font face="Courier New">equal to zero.");</font></p>
<p style="margin-top: 0; margin-bottom: 0">
<font face="Courier New" size="2"> </font>
<font face="Courier New">}</font></p>
<p style="margin-top: 0; margin-bottom: 0">
<font face="Courier New" size="2"> </font></font>
<font SIZE="2" face="Courier New">if</font><font SIZE="2"><font face="Courier New">(
maxWidth <= 0 ) {</font></p>
<p style="margin-top: 0; margin-bottom: 0">
<font face="Courier New" size="2">
</font></font><font SIZE="2" face="Courier New">
throw new</font><font face="Courier New" SIZE="2">
ArgumentOutOfRangeException( "maxWidth", maxWidth, "The maximum width
passed</font></p>
<p style="margin-top: 0; margin-bottom: 0">
<font face="Courier New" size="2"> </font>
<font face="Courier New" SIZE="2"> to
ActionPerceptionTree.GenerateRandomTree method was less than or equal
</font></p>
<p style="margin-top: 0; margin-bottom: 0">
<font face="Courier New" size="2"> </font>
<font SIZE="2">
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -