cse891

 

New Task

Page history last edited by Charles Ofria 2 yrs ago

Adding a New Task to Avida

 

Adding a new task is very similar to adding a new instruction in Avida. For this example, were going to add a task called "times2" which an organism will satisfy if they multiple an input by two and return the result.

 

Step 1: Declare the method for the new task.

 

Open the file "source/main/cTaskLib.h" and go to line 99 where the task declarations start. Add a declaration for our new task:

 

double Task_Times2(cTaskContext& ctx) const;

 

Each task test takes in a context (including information on the environment and inputs that the organism had access to) and returns a value between zero and one which indicates how well the organism has performed the task. In most cases the return value will just be 0.0 or 1.0.

 

Step 2: Write the body of our new method.

 

Go to line 483 in "source/main/cTaskLib.cc" and add in our new method.

 

double cTaskLib::Task_Times2(cTaskContext& ctx) const

{

const int test_output = ctx.GetOutputBuffer()[0];

for (int i = 0; i < ctx.GetInputBuffer().GetNumStored(); i++) {

if (test_output == ctx.GetInputBuffer()[i] * 2) return 1.0;

}

return 0.0;

}

 

Step 3: Link this test to the new task we're defining.

 

Go to line 72 in this same file and add:

 

else if (name == "times2") NewTask(name, "Mult by 2", &cTaskLib::Task_Times2);

 

Step 4: Compile and test it!

 

  • Go into your "build/" directory and type "make" to recompile.
  • Go into "build/work/" and modify the environment to reward this new task.
  • Write an organism of your own to test this task.
  • Do an Avida run to see if the organisms will evolve the new task.
  • When you have an organism that performs the task, trace it to see how it works.

Comments (0)

You don't have permission to comment on this page.