📄 iprecode.htm
字号:
<td width="100%">
<font SIZE="2" face="Courier New">bool</font><font face="Courier New" SIZE="2">
CheckMethod( MethodInfo method );</font></td>
</tr>
</table>
</center>
</div>
<h4 class="dtH4"><font face="Arial"><span style="font-weight: 400">The
CheckMethod for an AP node is shown below. This is one method that would
be changed to handle methods with parameters and of different return values.
The method currently currently checks to make sure the method has no
parameters and that it is of either type <i>bool</i> or <i>void</i>. To
create a check for a different type, such as <i>int method()</i>, the return
type of int would have to be ensured. If the method requires parameters,
additional checks would have to be performed to make sure the mutated and/or
recombined code calls the method with the required number of arguments.</span></font></h4>
<div align="center">
<center>
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="90%" id="AutoNumber9">
<tr>
<td width="100%"><font SIZE="2">
<p style="margin-top: 0; margin-bottom: 0"></font>
<font SIZE="2" face="Courier New">public static bool</font><font SIZE="2"><font face="Courier New">
CheckMethod( MethodInfo method ) {</font></p>
<p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">
//check that method is not null</font></p>
<p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">
</font></font><font SIZE="2" face="Courier New">if( method == 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( "method", "The method 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">
ActionPerceptionNode.CheckMethod method 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">
//check that method takes no arguments</font></p>
<p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">
</font></font><font SIZE="2" face="Courier New">if(
method.GetParameters().Length != 0 ) return false</font><font SIZE="2"><font face="Courier New">;</font></p>
<p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">
//check return type</font></p>
<p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">
</font></font><font SIZE="2" face="Courier New">if( method.ReturnType !=
typeof(void) && method.ReturnType != typeof(bool) ) return false</font><font SIZE="2"><font face="Courier New">;</font></p>
<p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">
//everything check out</font></p>
<p style="margin-top: 0; margin-bottom: 0"></font>
<font SIZE="2" face="Courier New"> return true</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>
<p class="dtH4"><font face="Arial">The GenerateCodeDomStatements method
generates the </font><font face="CodeDom "> <b>CodeDom</b></font><font face="Arial"> statement represented by this node. </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" face="Courier New">
CodeStatementCollection GenerateCodeDomStatements();</font></td>
</tr>
</table>
</center>
</div>
<h4 class="dtH4"><font face="Arial"><span style="font-weight: 400">The
GenerateCodeDomStatements method for the AP tree is shown below. The
code generates the CodeDom statements for each of the for each node in the
tree. See CodeDom for more information.</span></font></h4>
<div align="center">
<center>
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="90%" id="AutoNumber10">
<tr>
<td width="100%"><font SIZE="2">
<p style="margin-top: 0; margin-bottom: 0"></font>
<font SIZE="2" face="Courier New">public</font><font SIZE="2"><font face="Courier New">
CodeStatementCollection GenerateCodeDomStatements() {</font></p>
<p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">
</font></font><font SIZE="2" face="Courier New">return new</font><font SIZE="2"><font face="Courier New">
CodeStatementCollection( GenerateCodeDomArray() );</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">
public CodeStatement[] GenerateCodeDomArray() {</font></p>
<p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">
</font></font><font SIZE="2" face="Courier New">//create array for child
statements</p>
</font><font SIZE="2">
<p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">
CodeStatement[] childStatements = </font></font>
<font SIZE="2" face="Courier New">new</font><font SIZE="2"><font face="Courier New">
CodeStatement[ Children.Count ];</font></p>
<p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">
</font></font></p>
<p style="margin-top: 0; margin-bottom: 0">
<font face="Courier New" SIZE="2"> //add child
statements to array</p>
<p style="margin-top: 0; margin-bottom: 0"> </font>
<font SIZE="2" face="Courier New">for( int</font><font SIZE="2"><font face="Courier New">
index = 0; index < childStatements.Length; ++index ) {</font></p>
<p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">
childStatements[ index ] = Children[ index ].GenerateCodeDomStatement();</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">//return array of
statements from children</p>
<p style="margin-top: 0; margin-bottom: 0"> return</font><font SIZE="2"><font face="Courier New">
childStatements;</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 Mutate method mutates within
IPrecodeTree by replacing the node at the specified point with the specified
method.</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" face="Courier New">void Mutate( int</font><font face="Courier New" SIZE="2">
point, MethodInfo method );</font></td>
</tr>
</table>
</center>
</div>
<h4 class="dtH4"><font face="Arial"><span style="font-weight: 400">The
Mutate method for the AP tree is shown below. It uses
the CheckMethod for the AP tree. The check method would have to be
redefined for different types of methods such as <i>int method()</i>.
CreateNode would also have to be defined to specify mutation and recombination
points and other necessary features for different return types.</span></font></h4>
<div align="center">
<center>
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="90%" id="AutoNumber11">
<tr>
<td width="100%"><font SIZE="2">
<p style="margin-top: 0; margin-bottom: 0"></font>
<font SIZE="2" face="Courier New">public void Mutate( int</font><font SIZE="2"><font face="Courier New">
point, MethodInfo method ) {</font></p>
<p style="margin-top: 0; margin-bottom: 0"></font>
<font face="Courier New" SIZE="2"> //check that method
is 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( method == 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
ArgumentNullException( "method", "The method 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.Mutate
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 method is valid</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">(
!CheckMethod( method ) ) {</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
ArgumentException( "The method passed to ActionPerceptionTree.Mutate
method</font></p>
<p style="margin-top: 0; margin-bottom: 0">
<font face="Courier New" SIZE="2">
</font><font SIZE="2"><font face="Courier New"> could not be used
to create a node.", "method" );</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 mutation point is 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">(
MutationPoints == 0 && point == 0 ) {</font></p>
<p style="margin-top: 0; margin-bottom: 0">
<font face="Courier New" SIZE="2">
</font><font face="Courier New">Children.Add(
ActionPerceptionNode.CreateNode( method ) );</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>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -