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

📄 iprecode.htm

📁 遗传算法GPE_release_v1.0.tar
💻 HTM
📖 第 1 页 / 共 4 页
字号:
        <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.&nbsp; This is one method that would 
  be changed to handle methods with parameters and of different return values.&nbsp; 
  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>.&nbsp; To 
  create a check for a different type, such as <i>int method()</i>, the return 
  type of int would have to be ensured.&nbsp; 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">&nbsp;&nbsp;&nbsp; 
        //check that method is not null</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">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">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        </font></font><font SIZE="2" face="Courier New">throw new 
        ArgumentNullException( &quot;method&quot;, &quot;The method passed to</font></p>
        <p style="margin-top: 0; margin-bottom: 0">
        <font face="Courier New" SIZE="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        </font><font SIZE="2"><font face="Courier New">
        ActionPerceptionNode.CheckMethod method was null.&quot; );</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; 
        //check that method takes no arguments</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">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">&nbsp;&nbsp;&nbsp; 
        //check return type</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">if( method.ReturnType != 
        typeof(void) &amp;&amp; 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">&nbsp;&nbsp;&nbsp; 
        //everything check out</font></p>
        <p style="margin-top: 0; margin-bottom: 0"></font>
        <font SIZE="2" face="Courier New">&nbsp;&nbsp;&nbsp; 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.&nbsp; The 
  code generates the CodeDom statements for each of the for each node in the 
  tree.&nbsp; 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">&nbsp;&nbsp;&nbsp;
        </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">&nbsp;</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">&nbsp;&nbsp;&nbsp;
        </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">&nbsp;&nbsp;&nbsp; 
        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">&nbsp;&nbsp;&nbsp;
        </font></font></p>
        <p style="margin-top: 0; margin-bottom: 0">
        <font face="Courier New" SIZE="2">&nbsp;&nbsp;&nbsp; //add child 
        statements to array</p>
        <p style="margin-top: 0; margin-bottom: 0">&nbsp;&nbsp;&nbsp; </font>
        <font SIZE="2" face="Courier New">for( int</font><font SIZE="2"><font face="Courier New"> 
        index = 0; index &lt; childStatements.Length; ++index ) {</font></p>
        <p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
        childStatements[ index ] = Children[ index ].GenerateCodeDomStatement();</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">//return array of 
        statements from children</p>
        <p style="margin-top: 0; margin-bottom: 0">&nbsp;&nbsp;&nbsp; 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.&nbsp; It uses 
  the CheckMethod for the AP tree.&nbsp; The check method would have to be 
  redefined for different types of methods such as <i>int method()</i>.&nbsp; 
  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">&nbsp;&nbsp;&nbsp; //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">&nbsp;&nbsp;&nbsp; </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">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        </font></font><font SIZE="2" face="Courier New">throw new 
        ArgumentNullException( &quot;method&quot;, &quot;The method passed to</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;ActionPerceptionTree.Mutate 
        method was null.&quot; );</font></p>
        <p style="margin-top: 0; margin-bottom: 0">
        <font face="Courier New" SIZE="2">&nbsp;&nbsp;&nbsp; </font>
        <font face="Courier New">}</font></p>
        <p style="margin-top: 0; margin-bottom: 0">
        <font face="Courier New" SIZE="2">&nbsp;&nbsp;&nbsp; </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">&nbsp;&nbsp;&nbsp; </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">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        </font></font><font SIZE="2" face="Courier New">throw new 
        ArgumentException( &quot;The method passed to ActionPerceptionTree.Mutate 
        method</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;could not be used 
        to create a node.&quot;, &quot;method&quot; );</font></p>
        <p style="margin-top: 0; margin-bottom: 0">
        <font face="Courier New" SIZE="2">&nbsp;&nbsp;&nbsp; </font>
        <font face="Courier New">}</font></p>
        <p style="margin-top: 0; margin-bottom: 0">
        <font face="Courier New" SIZE="2">&nbsp;&nbsp;&nbsp; </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">&nbsp;&nbsp;&nbsp; </font></font>
        <font SIZE="2" face="Courier New">if</font><font SIZE="2"><font face="Courier New">( 
        MutationPoints == 0 &amp;&amp; point == 0 ) {</font></p>
        <p style="margin-top: 0; margin-bottom: 0">
        <font face="Courier New" SIZE="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        </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">&nbsp;&nbsp;&nbsp; </font>
        <font face="Courier New">}</font></p>
        <p style="margin-top: 0; margin-bottom: 0">
        <font face="Courier New" SIZE="2">&nbsp;&nbsp;&nbsp; </font></font>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -