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

📄 individual.htm

📁 遗传算法GPE_release_v1.0.tar
💻 HTM
📖 第 1 页 / 共 2 页
字号:
<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 the Individual Class</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  </span></font>
  <span style="font-family:Arial">GPEngine</span><span lang="EN-GB" style="font-family:Arial"> </span><font face="Arial"><span style="font-weight: 400">derives potential solutions to problems from the  </span>IIndividual<span style="font-weight: 400"> <i>Base Class</i>.&nbsp; The 
	IIndividual class represents an individual as used by the  </span></font>
  <span style="font-family:Arial; font-weight:400">GPEngine</span><font face="Arial"><span style="font-weight: 400">.&nbsp; In the 
	Artificial Ant problem, an Ant is an example of an individual.&nbsp; The 
	IIndividual class defines all of the actions an IIndividual can take to 
	interact with its  </span>IEnvironment<span style="font-weight: 400">.&nbsp; Each 
  IIndividual has an IEnvironment to interact with.&nbsp;&nbsp; An IIndividual has methods 
	common to all problems as well as problem-specific methods.&nbsp; Common 
	methods include getting and setting the IEnvironment ; methods to initialize 
  the state of the IIndividual and, if necessary, reset the state of the 
  IIndividual after testing; and a method to determine if testing is complete.&nbsp; 
  Problem-specific methods are unique to each problem.&nbsp; In the case of the Artificial Ant, problem-specific 
	methods include moving forward, turning left and right, and determining if 
	food is in front of the Ant.</span></font></h4>
	<h4 class="dtH4"><font face="Arial"><span style="font-weight: 400">The first 
	methods to be defined are the IEnvironment get and set methods.&nbsp; The 
	example below is for the Artificial Ant.</span></font></h4>
	<div align="center">
		<table border="0" width="90%" id="table1">
			<tr>
				<td>
				<p style="margin-top: 0; margin-bottom: 0">
				<font face="Courier" size="2">public IEnvironment Environment {<br>
&nbsp;&nbsp;&nbsp; get {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return m_Environment;<br>
&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; set {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if( value == null ) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; throw new 
				ArgumentNullException( &quot;value&quot;, &quot;The value passed to</font></p>
				<p style="margin-top: 0; margin-bottom: 0">
				<font face="Courier" size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
				AntIndividual.Environment_set property was null.&quot; );<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; m_Environment = value as 
				AntEnvironment;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if( m_Environment == null ) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; throw new 
				ArgumentException( &quot;The value passed to 
				AndIndividual.Environment_set</font></p>
				<p style="margin-top: 0; margin-bottom: 0">
				<font face="Courier" size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
				property was not of type AntEnvironment.&quot;, &quot;value&quot; );<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; }<br>
				}<br>
				private AntEnvironment m_Environment;<br>
&nbsp;</font></td>
			</tr>
		</table>
	</div>
	<h4><span style="font-family:Arial;font-weight:normal">The Environment 
	method sets the IEnvironment in which the IIndividual will be tested.&nbsp; The 
	IEnvironment that is passed to this method should be verified that it is not 
	null and that it is of a compatible type for this IIndividual.&nbsp; If the 
    IEnvironment is of the proper type, the 
	 
	</span><span style="font-family:Arial;font-weight:normal">IEnvironment </span><span style="font-family:Arial;font-weight:normal">of this  </span><span style="font-family:Arial;font-weight:normal">
    IIndividual </span><span style="font-family:Arial;font-weight:normal">will be set.&nbsp; This method also returns the 
	 
	</span><span style="font-family:Arial;font-weight:normal">IEnvironment </span><span style="font-family:Arial;font-weight:normal">to callers of this method.</span></h4>
	<h4><span style="font-family:Arial;font-weight:normal">Next, any 
	problem-specific variables should be defined.&nbsp; </span>
	<span style="font-family: Arial; font-weight: normal">These variables 
	include any IIndividual states that need to be tracked.&nbsp; In the case of the 
	Artificial Ant, this includes variables to count how many steps were taken 
	and the current direction the Ant is facing.</span></h4>
	<div align="center">
		<table border="0" width="90%" id="table2">
			<tr>
				<td>
				<h4 style="margin-top: 0; margin-bottom: 0">
				<span style="font-family: Courier New; font-weight: normal">
				<font size="2">private int m_StepCount;</font></span></h4>
				<h4 style="margin-top: 0; margin-bottom: 0">
				<span style="font-family: Courier New; font-weight: normal">
				<font size="2">private Direction m_Facing;</font></span></h4>
				</td>
			</tr>
		</table>
	</div>
	<h4><span style="font-family: Arial; font-weight: normal">m_StepCount is 
	incremented for each step the Ant takes or if it turns left or right.&nbsp; This 
	is one condition used to test if the IIndividual is done being tested.&nbsp; When 
	the Ant has taken a certain number of steps (as defined by the IEnvironment), 
	testing stops.&nbsp; This prevents the program from entering an endless loop.&nbsp; m_Facing is used to track which way the Ant is facing.&nbsp; This is used to 
	determine which directions the Ant can move.</span></h4>
	<h4 style="margin:0in;margin-bottom:.0001pt">
	<span style="font-family: Arial; font-weight: normal">The next method to 
	define is the TestSetup in which any initial states of the individual are 
	set.&nbsp; For the Artificial Ant, the individual Ant starts out with a step 
	count of 0 (it hasn抰 yet moved) and facing to the right.</span></h4>
	<h4 style="margin:0in;margin-bottom:.0001pt">
	<span style="font-family: Arial; font-weight: normal">&nbsp;</span></h4>
	<div align="center">
		<table border="0" width="90%" id="table3">
			<tr>
				<td>
				<h4 style="margin:0in;margin-bottom:.0001pt">
				<span style="font-family: Courier New; font-weight: normal">
				<font size="2">public void TestSetup() {</font></span></h4>
				<h4 style="margin:0in;margin-bottom:.0001pt">
				<font face="Courier" size="2">&nbsp;&nbsp;&nbsp; </font>
				<span style="font-family: Courier New; font-weight: normal">
				<font size="2">//reset state</font></span></h4>
				<h4 style="margin:0in;margin-bottom:.0001pt">
				<font face="Courier" size="2">&nbsp;&nbsp;&nbsp; </font>
				<span style="font-family: Courier New; font-weight: normal">
				<font size="2">m_StepCount = 0;</font></span></h4>
				<h4 style="margin:0in;margin-bottom:.0001pt">
				<font face="Courier" size="2">&nbsp;&nbsp;&nbsp; </font>
				<span style="font-family: Courier New; font-weight: normal">
				<font size="2">m_Facing = Direction.Right;</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: Arial; font-weight: normal">&nbsp;</span></h4>

⌨️ 快捷键说明

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