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

📄 history.htm

📁 遗传算法GPE_release_v1.0.tar
💻 HTM
📖 第 1 页 / 共 2 页
字号:
<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns="http://www.w3.org/TR/REC-html40">

<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 IGraphicHistory 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">
	<div align="center">
		<p style="margin-top: 0; margin-bottom: 0">&nbsp;</p>
		<p style="margin-top: 0; margin-bottom: 0" align="left">
		<font face="Arial">The IGraphicHistory <i>Base Class</i> extends the 
		IHistory <i>Base Class</i>.&nbsp; The IHistory class represents an 
		<b>IIndividual</b> in an <b>IEnvironment</b>.&nbsp; The IIndividual's actions are stored 
		in the IGraphicHistory and fitness is then calculated from this.&nbsp; The 
        IGraphicHistory class creates a graphical representation of the 
		IIndividual's performance in an IEnvrionment.&nbsp; Each history class 
		will be unique to the individual problem.&nbsp; That is, each history 
		class will have different sets of methods depending on the functions of 
		the individual.&nbsp; For example, the Ant measures fitness as the 
		amount of food it gathered and has four moves that it can make, 
		specifically up, down, left, and right on the grid.</font></p>
		<p align="left"><font face="Arial">The first method is the 
		IGraphicHistory get and set methods.&nbsp; The parameters vary on the needs of 
		the individual problem.&nbsp; In the Artificial Ant's case, the 
		IEnvironment and the Ant grid are needed for the history.&nbsp; First, AntHistory ensures that the 
        IEnvironment name and the Ant grid are not 
		null.&nbsp; If they are valid, an AntHistory is created.&nbsp; </font></p>
		<table border="0" width="90%" id="table1">
			<tr>
				<td>
				<p style="margin-top: 0; margin-bottom: 0">
				<font face="Courier New" size="2">public AntHistory( string 
				environmentName, Grid grid ) {<br>
&nbsp;&nbsp;&nbsp; //check for null args<br>
&nbsp;&nbsp;&nbsp; if( environmentName == null ) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; throw new ArgumentNullException( &quot;environmentName&quot;, 
				&quot;The environment name passed</font><p style="margin-top: 0; margin-bottom: 0">
				<font face="Courier New" size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
				to AntHistory.constructor was null.&quot; );<br>
&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; if( grid == null ) {<br>
&nbsp;&nbsp;&nbsp; throw new ArgumentNullException( &quot;grid&quot;, &quot;The grid passed to 
				AntHistory.constructor</font><p style="margin-top: 0; margin-bottom: 0">
				<font face="Courier New" size="2">&nbsp;&nbsp;&nbsp; was null.&quot; 
				);<br>
&nbsp;&nbsp;&nbsp; }<br>
				<br>
&nbsp;&nbsp;&nbsp; m_EnvironmentName = environmentName;<br>
&nbsp;&nbsp;&nbsp; m_Grid = grid;<br>
				}<br>
&nbsp;</font></td>
			</tr>
		</table>
	</div>
	<h4 class="dtH4"><font face="Arial"><span style="font-weight: 400">The raw 
	fitness method returns the fitness of the specified individual in the 
	specified environment.&nbsp; Fitness measures vary for each problem and,&nbsp;for the Artificial Ant, is the amount of food collected.</span></font></h4>
	<div align="center">
		<table border="0" width="90%" id="table2">
			<tr>
				<td><font face="Courier New" size="2">public decimal RawFitness 
				{<br>
&nbsp;&nbsp;&nbsp; get {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return m_FoodFound;<br>
&nbsp;&nbsp;&nbsp; }<br>
				}</font></td>
			</tr>
		</table>
	</div>
	<h4 class="dtH4"><font face="Arial"><span style="font-weight: 400">The 
	environment method retrieves the name of the IEnvironment the IIndividual is 
	being tested in.&nbsp; </span></font></h4>
	<div align="center">
		<table border="0" width="90%" id="table3">
			<tr>
				<td><font face="Courier New" size="2">public string 
				EnvironmentName {<br>
&nbsp;&nbsp;&nbsp; get {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return m_EnvironmentName;<br>
&nbsp;&nbsp;&nbsp; }<br>
				}<br>
				private string m_EnvironmentName;</font></td>
			</tr>
		</table>
	</div>
	<p class="dtH4"><font face="Arial">Next, a property should be defined to get 
	and set the fitness measure of the  <span style="font-weight: 400">
    IIndividual</span>.&nbsp; In the Ant's case it is 
	the amount of food collected.</font></p>
	<div align="center">
		<table border="0" width="90%" id="table4">
			<tr>
				<td><font face="Courier New" size="2">public int FoodFound {<br>
&nbsp;&nbsp;&nbsp; get {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return m_FoodFound;<br>
&nbsp;&nbsp;&nbsp; }<br>
&nbsp;&nbsp;&nbsp; set {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; m_FoodFound = value;<br>
&nbsp;&nbsp;&nbsp; }<br>
				}<br>
				private int m_FoodFound;</font></td>
			</tr>
		</table>
		<p align="left"><font face="Arial">The history class should also 
		maintain a list of actions performed by the  <span style="font-weight: 400">
        IIndividual </span>in the 
		IEnvironment.&nbsp; For the Artificial Ant, this would be a collection of 
		the moves the Ant made in the IEnvironment.</font></p>
		<div align="center">
			<table border="0" width="90%" id="table5">
				<tr>
					<td><font face="Courier New" size="2">public ArrayList Moves 
					{<br>
&nbsp;&nbsp;&nbsp; get {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return m_Moves;<br>
&nbsp;&nbsp;&nbsp; }<br>
					}<br>
					private ArrayList m_Moves = new ArrayList();<br>
					private Direction[] m_FinishedMoves;</font></td>
				</tr>
			</table>
			<p align="left"><font face="Arial">Any problem-specific variables 
			should also be defined.&nbsp; This would include the environment 
			grid and a bitmap image to draw on for the Artificial Ant.</font></p>
			<div align="center">
				<table border="0" width="90%" id="table6">
					<tr>
						<td><font face="Courier New" size="2">private int 
						m_MovesIndex = -1;<br>
						private Grid m_Grid;<br>
						private Bitmap m_bmp;<br>
						private SmartPoint m_Position;<br>
						private int m_CellDim;</font></td>
					</tr>
				</table>
				<p align="left"><font face="Arial">The DrawFrame method handles 
				the graphical portion of the history.&nbsp; This method draws a 
				graphical representation of the  <span style="font-weight: 400">
                IIndividual's </span>actions on the 
				Graphics object one frame at a time.</font></p>
				<div align="center">
					<table border="0" width="90%" id="table7">
						<tr>
							<td>
							<p style="margin-top: 0; margin-bottom: 0">public 
							bool DrawFrame( Graphics g ) {<br>
&nbsp;&nbsp;&nbsp; //if just starting, set up graphics stuff<br>
&nbsp;&nbsp;&nbsp; if( m_MovesIndex == -1 ) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //initialize state<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; m_Position = new SmartPoint( 
							m_Grid.Width, m_Grid.Height, 
							m_Grid.InitialAntPosition.X,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
							</p>
							<p style="margin-top: 0; margin-bottom: 0">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
							m_Grid.InitialAntPosition.Y );<br>
							<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //create square bitmap<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int maxGridSize = (int) Math.Max( 
							m_Grid.Width, m_Grid.Height );<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int dim = (int) Math.Min( 
							g.ClipBounds.Width, g.ClipBounds.Height );<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; m_CellDim = (dim - 2)/maxGridSize;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; m_bmp = new Bitmap( dim, dim );<br>
							<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //draw grid<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; using( Graphics gBmp = 
							Graphics.FromImage( m_bmp ) ) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
							gBmp.FillRectangle( Brushes.White, 0, 0, dim, dim );<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
							gBmp.DrawRectangle( Pens.Black, 0, 0, dim - 1, dim - 
							1 );<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for( int x = 
							0; x &lt; m_Grid.Width; ++x ) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 

⌨️ 快捷键说明

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