📄 iprecode.htm
字号:
<font face="Courier New">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">//check the available
methods</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">(
availableMethods.Empty ) {</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">
ArgumentException( "The collection of methods 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 empty.", "availableMethods" );</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">foreach(
MethodInfo method in</font><font SIZE="2"><font face="Courier New">
availableMethods ) {</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">(
!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</font><font face="Courier New" SIZE="2">
ArgumentException( String.Format( "The collection of methods 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 contained a method, '{0}', that </font>
<font face="Courier New" size="2">
</font><font face="Courier New">cannot be used to create a node.",
method.Name ), "availableMethods" );</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 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">return</font><font SIZE="2"><font face="Courier New">
GenerateRandomTree( 1, r, availableMethods, maxDepth, maxWidth + 1 );</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" size="2"> </font></font></p>
<p style="margin-top: 0; margin-bottom: 0"> </p>
<p style="margin-top: 0; margin-bottom: 0">
<font SIZE="2" face="Courier New">private static
ActionPerceptionTree GenerateRandomTree( int</font><font face="Courier New" SIZE="2">
currentDepth, </font></p>
<font SIZE="2">
<p style="margin-top: 0; margin-bottom: 0"><font face="Courier New">
Random r, ReadOnlyMethodInfoCollection availableMethods, </font></font>
<font SIZE="2" face="Courier New">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">//create new tree and
fill with 'width' number of elements</p>
</font><font SIZE="2">
<p style="margin-top: 0; margin-bottom: 0">
<font face="Courier New" size="2"> </font>
<font face="Courier New">ActionPerceptionTree newTree = </font></font>
<font SIZE="2" face="Courier New">new</font><font SIZE="2"><font face="Courier New">
ActionPerceptionTree();</font></p>
<p style="margin-top: 0; margin-bottom: 0">
<font face="Courier New" size="2"> </font></font>
<font SIZE="2" face="Courier New">int</font><font SIZE="2"><font face="Courier New">
width = r.Next( 1, maxWidth );</font></p>
<p style="margin-top: 0; margin-bottom: 0">
<font face="Courier New" size="2"> </font>
<font face="Courier New">PerceptionNode p;</font></p>
<p style="margin-top: 0; margin-bottom: 0">
<font face="Courier New" size="2"> </font></font>
<font SIZE="2" face="Courier New">for( int</font><font SIZE="2"><font face="Courier New">
index = 0; index < width; ++index ) {</font></p>
<p style="margin-top: 0; margin-bottom: 0">
<font face="Courier New" size="2">
</font></font><font SIZE="2" face="Courier New">//add
random node</p>
</font><font SIZE="2">
<p style="margin-top: 0; margin-bottom: 0">
<font face="Courier New" size="2">
</font><font face="Courier New">newTree.Children.Add( </font></p>
<p style="margin-top: 0; margin-bottom: 0">
<font face="Courier New" size="2">
</font>
<font face="Courier New">ActionPerceptionNode.CreateNode(
availableMethods[r.Next( 0,</font></p>
<p style="margin-top: 0; margin-bottom: 0">
<font face="Courier New" size="2">
</font><font face="Courier New"> availableMethods.Count )]) </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
this is not the final depth, and if this added node is a perception
node, </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">//
generate trees for it at the next depth level</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(
currentDepth < maxDepth&&(p = newTree.Children[index] as PerceptionNode)
!= null){ </font></p>
<p style="margin-top: 0; margin-bottom: 0">
<font face="Courier New" size="2"> //treeChoice
determines which subtrees to generate:</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">// 0 =
true tree, 1 = false tree, 2 = both trees, 3 = neither tree</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">int</font><font SIZE="2"><font face="Courier New">
treeChoice = r.Next( 0, 4 );</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">(
treeChoice == 0 || treeChoice == 2 ) {</font></p>
<p style="margin-top: 0; margin-bottom: 0">
<font face="Courier New" size="2">
</font><font face="Courier New">p.TrueTree.Children.AddRange( </font>
</p>
<p style="margin-top: 0; margin-bottom: 0">
<font face="Courier New" size="2">
</font><font face="Courier New"> GenerateRandomTree( currentDepth
+ 1, r, availableMethods, maxDepth, maxWidth</font></p>
<p style="margin-top: 0; margin-bottom: 0">
<font face="Courier New" size="2">
</font><font face="Courier New"> ).Children</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 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">(
treeChoice == 1 || treeChoice == 2 ) {</font></p>
<p style="margin-top: 0; margin-bottom: 0">
<font face="Courier New" size="2">
</font><font face="Courier New">p.FalseTree.Children.AddRange( </font>
</p>
<p style="margin-top: 0; margin-bottom: 0">
<font face="Courier New" size="2"> </font>
<font face="Courier New" size="2">
</font><font face="Courier New">GenerateRandomTree( currentDepth + 1, r,
availableMethods, maxDepth, maxWidth</font></p>
<p style="margin-top: 0; margin-bottom: 0">
<font face="Courier New" size="2">
</font><font face="Courier New"> ).Children</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 face="Courier New">}</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 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">return</font><font SIZE="2"><font face="Courier New">
newTree;</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 CheckMethod method verifies that the
given method can be used in this implementation of IPrecodeTree.</font></p>
<div align="center">
<center>
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="90%" id="AutoNumber4">
<tr>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -