[Avida-cvs] [avida-svn] r912 - development/documentation

brysonda at myxo.css.msu.edu brysonda at myxo.css.msu.edu
Wed Aug 30 19:21:25 PDT 2006


Author: brysonda
Date: 2006-08-30 22:21:25 -0400 (Wed, 30 Aug 2006)
New Revision: 912

Modified:
   development/documentation/code_task.html
Log:
Update Task Implementation Checklist documentation.

Modified: development/documentation/code_task.html
===================================================================
--- development/documentation/code_task.html	2006-08-31 02:01:54 UTC (rev 911)
+++ development/documentation/code_task.html	2006-08-31 02:21:25 UTC (rev 912)
@@ -1,111 +1,128 @@
 <html>
-<title>Environmant Task Implementation Checklist</title>
-<body
- bgcolor="#FFFFFF"
- text="#000000"
- link="#0000AA"
- alink="#0000FF"
- vlink="#000044">
+<head>
+  <title>Avida : Environment Task Implementation Checklist</title>
+</head>
+<body>
 
-<h2 align=center>Environment Task Implementation Checklist</h2>
+<div style="float: right">
+Revised 2006-08-30 DMB
+</div>
 
+<p><a href="index.html">Return to the Index</a></p>
+<hr />
+
+<div align="center">
+<h1>Environment Task Implementation Checklist</h1>
+</div>
+
 <p>
 This document discusses how to implement your own tasks to use as triggers
 for reactions in the environment.
+</p>
 
-<h3>1. Build the prototype of the method that will be used to test the new task</h3>
 
-<p>
-    For this step, you will be editing the task library found in the files
-    tasks.cc and tasks.hh in the directory source/main/.  Start by adding
-    the prototype of your new test function to the cTaskLib class in the
-    header (tasks.hh) file.  The data that will be tested is all stored within
-    the library, so this function takes no inputs and outputs a double that
-    represents the "quality" with which the task is performed.  This is a
-    number between 0 and 1 that determines the fraction of the bonus that
-    should be received.  For tasks that are either successful or not, this
-    will only return 0.0 or 1.0.
+<p>&nbsp;</p>
+<h2>1. Build the prototype of the method that will be used to test the new task</h2>
 
 <p>
-    For example, if we were going to create a task that tests if the
-    organisms could double one of their inputs, we might call that task
-    "times2".  We would then add the line to this file:
-
+For this step, you will be editing the task library found in the files
+<kbd>cTaskLib.cc</kbd> and <kbd>cTaskLib.h</kbd> in the directory
+<kbd>source/main/</kbd>.  Start by adding the prototype of your new test
+function to the cTaskLib class in the header file.  The data that will be
+tested is all stored within task context that is passed into this function.
+This function will output a double that represents the <em>quality</em> with
+which the task is performed.  This is a number between 0 and 1 that
+determines the fraction of the bonus that should be received.  For tasks that
+are either successful or not, this will only return 0.0 or 1.0.
+</p>
+<p>
+For example, if we were going to create a task that tests if the organisms
+could double one of their inputs, we might call that task 'times2'.  We would
+then add the line to this file:
+</p>
 <pre>
-   void <font color="#008800">Task_Times2</font>();
+double <font color="#008800">Task_Times2</font>(<span style="color: #880000">cTaskContext</span>* <span style="color: #000088">ctx</span>) const;
 </pre>
 
 <p>
-    If possible, place it near other tasks of the same type.  In this case,
-    I choose to place it directly after Task_Echo(), since this is also an
-    easy task for the organisms to perform.
+If possible, place it near other tasks of the same type.  In this case,
+I choose to place it directly after Task_Echo(), since this is also an
+easy task for the organisms to perform.
+</p>
 
-<h3>2. Build the body of the method that will be used to test the new task</h3>
 
+<p>&nbsp;</p>
+<h2>2. Build the body of the method that will be used to test the new task</h2>
+
 <p>
-    We next go into the code (tasks.cc) file, and add the body of our new
-    method.  We search for cTaskLib::Task_Echo(), since our new prototype
-    followed this method in the header file, and place the body of our
-    function immediately after it.
+We next go into the code (<kbd>cTaskLib.cc</kbd>) file, and add the body of our
+new method.  We search for cTaskLib::Task_Echo(), since our new prototype
+followed this method in the header file, and place the body of our function
+immediately after it.
+</p>
 
 <pre>
-   <font color="#880000">double</font> <font color="#880000">cTaskLib</font>::<font color="#008800">Task_Times2</font>() const
-   {
-     const <font color="#880000">int</font> <font color="#000088">test_output</font> = <font color="#000088">output_buffer</font>[0];
-     for (<font color="#880000">int</font> <font color="#000088">i</font> = 0; <font color="#000088">i</font> < <font color="#000088">input_buffer</font>.<font color="#008800">GetNumStored</font>(); <font color="#000088">i</font>++) {
-       if (2 * <font color="#000088">input_buffer</font>[i] == <font color="#000088">test_output</font>) {
-         return 1.0;
-       }
-     }
-     return 0.0;
-   }
+double <font color="#880000">cTaskLib</font>::<font color="#008800">Task_Times2</font>(<span style="color: #880000">cTaskContext</span>* <span style="color: #000088">ctx</span>) const
+{
+  const <font color="#880000">int</font> <font color="#000088">test_output</font> = <span style="color: #000088">ctx</span>-&gt;<font color="#000088">output_buffer</font>[0];
+  for (<font color="#880000">int</font> <font color="#000088">i</font> = 0; <font color="#000088">i</font> &lt; <span style="color: #000088">ctx</span>-&gt;<font color="#000088">input_buffer</font>.<font color="#008800">GetNumStored</font>(); <font color="#000088">i</font>++) {
+    if (2 * <span style="color: #000088">ctx</span>-&gt;<font color="#000088">input_buffer</font>[i] == <font color="#000088">test_output</font>) {
+      return 1.0;
+    }
+  }
+  return 0.0;
+}
 </pre>
-    
 
 <p>
-    The most recent output is always placed at the beginning of the output
-    buffer, so we store it in the variable
-    <font color="#000088">test_output</font> to compare it against all of the
-    different inputs.  We then have a for-loop that goes from 1 to the number
-    of inputs stored in the input buffer.  Inside the body of the loop, we
-    test for each input if twice that input is equal to the output.  If so,
-    then the task was successful and we return a 1.0.  If all of the tests
-    fail and we exit the loop, then we return a 0.0.
-
+The most recent output is always placed at the beginning of the output
+buffer, so we store it in the variable
+<font color="#000088">test_output</font> to compare it against all of the
+different inputs.  We then have a for-loop that goes from 0 to the number
+of inputs stored in the input buffer.  Inside the body of the loop, we
+test for each input if twice that input is equal to the output.  If so,
+then the task was successful and we return a 1.0.  If all of the tests
+fail and we exit the loop, then we return a 0.0.
+</p>
 <p>
-    These test methods should be carefully written so that they run as fast
-    as possible.  In particular, if a task requires that an output be
-    compared to multiple inputs at a time (i.e., the tasks Add or Subtract),
-    then this can become combinartoically explosive.  For the moment, we
-    keep control on this problem by only allowing three different inputs
-    in the input buffer, but in the future this number may need to become
-    higher.
+These test methods should be carefully written so that they run as fast
+as possible.  In particular, if a task requires that an output be
+compared to multiple inputs at a time (i.e., the tasks Add or Subtract),
+then this can become combinartoically explosive.  For the moment, we
+keep control on this problem by only allowing three different inputs
+in the input buffer, but in the future this number may need to become
+higher.
+</p>
 
-<h3>3. Attach our new method to the name of its trigger</h3>
 
-    This next step is also done in the code file, inside the
-    <font color="#880000">cTaskLib</font>::<font color="#008800">AddTask</font>()
-    method.  Again, we want this to be in the same place, so we locate the
-    task "echo" that its supposed to follow, and add in the new line.
+<p>&nbsp;</p>
+<h2>3. Attach our new method to the name of its trigger</h2>
 
+<p>
+This next step is also done in the code file, inside the
+<font color="#880000">cTaskLib</font>::<font color="#008800">AddTask</font>()
+method.  Again, we want this to be in the same place, so we locate the
+task 'echo' that its supposed to follow, and add in the new line.
+</p>
+
 <pre>
-   else if (<font color="#000088">name</font> == "times2") <font color="#008800">NewTask</font>(<font color="#000088">name</font>, "Times2", &<font color="#880000">cTaskLib</font>::<font color="#008800">Task_Times2</font>);
+else if (<font color="#000088">name</font> == &quot;times2&quot;)
+  <font color="#008800">NewTask</font>(<font color="#000088">name</font>, &quot;Times2&quot;, &amp;<font color="#880000">cTaskLib</font>::<font color="#008800">Task_Times2</font>);
 </pre>    
 
 <p>
-    This line will attach the name to the description "Times2" (which could
-    have been a little more detailed, but should be 40 characters or less)
-    as well as to the function that should be called when that name is
-    listed as a trigger to a reaction.
-
+This line will attach the name to the description &quot;Times2&quot; (which
+could have been a little more detailed, but should be 40 characters or less)
+as well as the function that should be called when that name is listed as a
+trigger to a reaction.
+</p>
 <p>
-    You are now ready to use your task!
+You are now ready to use your task!
+</p>
+    
 
-<h3>4. Some advanced features...</h3>
+<hr />
+<p><a href="index.html">Return to the Index</a></p>
 
-    [ This section to be written soon! ]
-    
-<br><hr>
-Project hosted by:<br>
-<a href="http://sourceforge.net"><img src="http://sourceforge.net/sflogo.php?group_id=46761&type=2" width="125" height="37" border="0" alt="SourceForge.net"/></a>
-    
\ No newline at end of file
+</body>
+</html>




More information about the Avida-cvs mailing list