📄 individual.htm
字号:
<h4 style="margin:0in;margin-bottom:.0001pt">
<span style="font-family: Arial; font-weight: normal">Next, any state
clearing that needs to be done after testing is complete is done. In the
case of the Artificial Ant, nothing needs to be done to the Ant when testing
is complete. </span></h4>
<h4 style="margin:0in;margin-bottom:.0001pt">
<span style="font-family: Arial; font-weight: normal">
</span></h4>
<div align="center">
<table border="0" width="90%" id="table4">
<tr>
<td>
<h4 style="margin:0in;margin-bottom:.0001pt">
<span style="font-family: Courier New; font-weight: normal">
<font size="2">public void TestTeardown() {</font></span></h4>
<h4 style="margin:0in;margin-bottom:.0001pt">
<font face="Courier" size="2"> </font>
<span style="font-family: Courier New; font-weight: normal">
<font size="2">//no state clearing needed</font></span></h4>
<h4 style="margin:0in;margin-bottom:.0001pt">
<span style="font-family: Courier New; font-weight: normal">
<font size="2">}</font></span></h4>
</td>
</tr>
</table>
</div>
<h4 style="margin:0in;margin-bottom:.0001pt">
<span style="font-family: Courier New; font-weight: normal"> </span></h4>
<h4 style="margin:0in;margin-bottom:.0001pt">
<span style="font-family: Arial; font-weight: normal">Next a method is
defined to determine when the IIndividual is finished testing. This can
occur when fitness is maximized, such as when the Ant collects all of the
available food. It can also occur when the program completes a certain
number of iterations as defined by the IEnvironment. This is necessary as
maximum fitness is not always achieved. </span></h4>
<h4 style="margin:0in;margin-bottom:.0001pt">
<span style="font-family: Arial; font-weight: normal"> </span><span style="font-family: Courier New; font-weight: normal">
</span></h4>
<div align="center">
<table border="0" width="90%" id="table5">
<tr>
<td>
<h4 style="margin:0in;margin-bottom:.0001pt">
<span style="font-family: Courier New; font-weight: normal">
<font size="2">public bool FinishedTesting() {</font></span></h4>
<h4 style="margin:0in;margin-bottom:.0001pt">
<font face="Courier New" size="2"> </font>
<span style="font-family: Courier New; font-weight: normal">
<font size="2">return m_Environment.AllFoodCollected ||
m_StepCount > m_Environment.StepLimit;</font></span></h4>
<h4 style="margin:0in;margin-bottom:.0001pt">
<span style="font-family: Courier New; font-weight: normal">
<font size="2">}</font></span></h4>
</td>
</tr>
</table>
</div>
<h4><span style="font-family:Arial;font-weight:normal">Finally, any
problem-specific methods are defined. These methods define what the
IIndividual can do. These are the methods that will get mutated and/or
recombined by the </span><span style="font-family:Arial;">GPEngine</span><span style="font-family:Arial;font-weight:normal"> in order to find fitter solutions. In the artificial
Ant example, the </span><span style="font-family:Arial;font-weight:normal">
IIndividual </span><span style="font-family:Arial;font-weight:normal">contains definitions for turning left and right,
moving forward, and determining if food is in front of the Ant. </span></h4>
<h4 style="margin:0in;margin-bottom:.0001pt">
<span style="font-family:"Courier New";
font-weight:normal"> </span></h4>
<div align="center">
<table border="0" width="90%" id="table6">
<tr>
<td>
<h4 style="margin:0in;margin-bottom:.0001pt">
<span style="font-family:"Courier New";
font-weight:normal"><font size="2">public void TurnLeft() {</font></span></h4>
<h4 style="margin:0in;margin-bottom:.0001pt">
<font face="Courier New" size="2"> </font>
<span style="font-family:"Courier New";
font-weight:normal"><font size="2">++m_StepCount;</font></span></h4>
<h4 style="margin:0in;margin-bottom:.0001pt">
<font face="Courier New" size="2"> </font>
<span style="font-family:"Courier New";
font-weight:normal"><font size="2">m_Facing = (Direction) ((((int) m_Facing) +
5)%4);</font></span></h4>
<h4 style="margin:0in;margin-bottom:.0001pt">
<span style="font-family:"Courier New";
font-weight:normal"><font size="2">}</font></span></h4>
<h4 style="margin:0in;margin-bottom:.0001pt">
<span style="font-family:"Courier New";
font-weight:normal"><font size="2"> </font></span></h4>
<h4 style="margin:0in;margin-bottom:.0001pt">
<span style="font-family:"Courier New";
font-weight:normal"><font size="2">public void TurnRight() {</font></span></h4>
<h4 style="margin:0in;margin-bottom:.0001pt">
<font face="Courier New" size="2"> </font>
<span style="font-family:"Courier New";
font-weight:normal"><font size="2">++m_StepCount;</font></span></h4>
<h4 style="margin:0in;margin-bottom:.0001pt">
<font face="Courier New" size="2"> </font>
<span style="font-family:"Courier New";
font-weight:normal"><font size="2">m_Facing = (Direction) ((((int) m_Facing) +
1)%4);</font></span></h4>
<h4 style="margin:0in;margin-bottom:.0001pt">
<span style="font-family:"Courier New";
font-weight:normal"><font size="2">}</font></span></h4>
<h4 style="margin:0in;margin-bottom:.0001pt">
<span style="font-family:"Courier New";
font-weight:normal"><font size="2"> </font></span></h4>
<h4 style="margin:0in;margin-bottom:.0001pt">
<span style="font-family:"Courier New";
font-weight:normal"><font size="2">public void MoveForward() {</font></span></h4>
<h4 style="margin:0in;margin-bottom:.0001pt">
<font face="Courier New" size="2"> </font>
<span style="font-family:"Courier New";
font-weight:normal"><font size="2">++m_StepCount;</font></span></h4>
<h4 style="margin:0in;margin-bottom:.0001pt">
<font face="Courier New" size="2"> </font>
<span style="font-family:"Courier New";
font-weight:normal"><font size="2">m_Environment.Move( m_Facing );</font></span></h4>
<h4 style="margin:0in;margin-bottom:.0001pt">
<span style="font-family:"Courier New";
font-weight:normal"><font size="2">}</font></span></h4>
<h4 style="margin:0in;margin-bottom:.0001pt">
<span style="font-family:"Courier New";
font-weight:normal"><font size="2"> </font></span></h4>
<h4 style="margin:0in;margin-bottom:.0001pt">
<span style="font-family:"Courier New";
font-weight:normal"><font size="2">public bool IsFoodAhead() {</font></span></h4>
<h4 style="margin:0in;margin-bottom:.0001pt">
<span style="font-family:"Courier New";
font-weight:normal"><font size="2">return m_Environment.Peek( m_Facing ) == 1;</font></span></h4>
<h4 style="margin:0in;margin-bottom:.0001pt">
<span style="font-family:"Courier New";
font-weight:normal"><font size="2">}</font></span></h4>
</td>
</tr>
</table>
</div>
<h4 class="dtH4"><font face="Arial">See Also</font></h4>
<p><font face="Arial">
<a href="../../../GPproject/GeneticProgrammingEngine/ProblemSpace/IEnvironment.htm">
IEnvironment</a> |
<a href="../../../GPproject/GeneticProgrammingEngine/ProblemSpace/IIndividual.htm">
IIndividual</a> |
<a href="../../../GPproject/GeneticProgrammingEngine/GPEngine.htm">GPEngine</a></font></p>
<hr>
<div id="footer">
<font face="Arial">
<a href="http://www.opensource.org/" target="_top">
<img style="padding-bottom: 5px" src="http://opensource.org/trademarks/open_source_button.png" align="left" border="0"></a>
This software licensed under the
<a href="http://opensource.org/licenses/afl-2.1.php" target="_top">Academic
Free License version 2.1</a>. (<a href="../../afl-2.1.txt">Plain
text</a>)</font></div>
</div>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -