[Avida-SVN] r1106 - in development: documentation source/main

goingssh at myxo.css.msu.edu goingssh at myxo.css.msu.edu
Wed Nov 29 21:22:56 PST 2006


Author: goingssh
Date: 2006-11-30 00:22:48 -0500 (Thu, 30 Nov 2006)
New Revision: 1106

Modified:
   development/documentation/environment.html
   development/source/main/cEnvironment.cc
   development/source/main/cEnvironment.h
   development/source/main/cOrganism.cc
   development/source/main/cOrganism.h
   development/source/main/cReactionRequisite.h
   development/source/main/cTaskContext.h
   development/source/main/cTaskLib.cc
Log:
Added new requisite for tasks that allows them to be checked only when an org divides, or only on an IO (this is the default and how it works now), or on both.  Updated the environment documentation file to explain how this requisite works.



Modified: development/documentation/environment.html
===================================================================
--- development/documentation/environment.html	2006-11-29 14:57:15 UTC (rev 1105)
+++ development/documentation/environment.html	2006-11-30 05:22:48 UTC (rev 1106)
@@ -544,6 +544,16 @@
   </td>
   <td>INT_MAX</td>
 </tr>
+<tr>
+  <td class="resall">divide_only</td>
+  <td>
+    This command decides when a task will be checked, if the value is 0 the task
+    will only be checked when an organism executes an IO.  If the value is 1 the task
+    will only be checked when the organism divides.  If the value is 2 the task will be
+    checked at both times.
+  </td>
+  <td>0</td>
+</tr>
 </table>
 <p>&nbsp;</p>
 </div>

Modified: development/source/main/cEnvironment.cc
===================================================================
--- development/source/main/cEnvironment.cc	2006-11-29 14:57:15 UTC (rev 1105)
+++ development/source/main/cEnvironment.cc	2006-11-30 05:22:48 UTC (rev 1106)
@@ -245,6 +245,10 @@
       if (!AssertInputInt(var_value, "max_count", var_type)) return false;
       new_requisite->SetMaxTaskCount(var_value.AsInt());
     }
+	else if (var_name == "divide_only") {
+		if (!AssertInputInt(var_value, "divide_only", var_type)) return false;
+		new_requisite->SetDivideOnly(var_value.AsInt());
+	}
     else {
       cerr << "Error: Unknown requisite variable '" << var_name
       << "' in reaction '" << reaction->GetName() << "'" << endl;
@@ -769,14 +773,16 @@
     const double task_quality = m_tasklib.TestOutput(&taskctx);
     const int task_id = cur_task->GetID();
     const int task_cnt = task_count[task_id];
+	const bool on_divide = taskctx.GetOnDivide();
     
     // If this task wasn't performed, move on to the next one.
     if (task_quality == 0.0) continue;
     
     // Examine requisites on this reaction
-    if (TestRequisites(cur_reaction->GetRequisites(), task_cnt, reaction_count) == false) {
+    if (TestRequisites(cur_reaction->GetRequisites(), task_cnt, reaction_count, on_divide) == false) {
       continue;
     }
+
     
     // Mark this task as performed...
     result.MarkTask(task_id, task_quality);
@@ -793,13 +799,19 @@
 
 
 bool cEnvironment::TestRequisites(const tList<cReactionRequisite>& req_list,
-                                  int task_count, const tArray<int>& reaction_count) const
+                                  int task_count, const tArray<int>& reaction_count, const bool on_divide) const
 {
   const int num_reqs = req_list.GetSize();
-  
+
   // If there are no requisites, there is nothing to meet!
-  if (num_reqs == 0) return true;
-  
+  // (unless this is a check upon dividing, in which case we want the default to be to not check the task
+  // and only if the requisite has been added to check it
+  if (num_reqs == 0) {
+	  if (on_divide)
+		  return false;
+	  else
+		return true;
+  }
   tLWConstListIterator<cReactionRequisite> req_it(req_list);
   for (int i = 0; i < num_reqs; i++) {
     // See if this requisite batch can be satisfied.
@@ -831,8 +843,14 @@
     // Have all task counts been met?
     if (task_count < cur_req->GetMinTaskCount()) continue;
     
-    // Have all reactions been met?
+    // Have divide task reqs been met?
+    // If div_type is 0 we only check on IO, if 1 we only check on divide,
+    // if 2 we check always
     if (task_count >= cur_req->GetMaxTaskCount()) continue;
+
+	int div_type = cur_req->GetDivideOnly();
+	if (div_type == 1 && on_divide == false) continue;
+	if (div_type == 0 && on_divide) continue;
     
     return true;
   }

Modified: development/source/main/cEnvironment.h
===================================================================
--- development/source/main/cEnvironment.h	2006-11-29 14:57:15 UTC (rev 1105)
+++ development/source/main/cEnvironment.h	2006-11-30 05:22:48 UTC (rev 1106)
@@ -73,7 +73,7 @@
 
   bool LoadSetActive(cString desc);
 
-  bool TestRequisites(const tList<cReactionRequisite>& req_list, int task_count, const tArray<int>& reaction_count) const;
+  bool TestRequisites(const tList<cReactionRequisite>& req_list, int task_count, const tArray<int>& reaction_count, const bool on_divide = false) const;
   void DoProcesses(cAvidaContext& ctx, const tList<cReactionProcess>& process_list, const tArray<double>& resource_count,
                    const double task_quality, const int task_count, cReactionResult& result) const;
 

Modified: development/source/main/cOrganism.cc
===================================================================
--- development/source/main/cOrganism.cc	2006-11-29 14:57:15 UTC (rev 1105)
+++ development/source/main/cOrganism.cc	2006-11-30 05:22:48 UTC (rev 1106)
@@ -155,7 +155,7 @@
   phenotype.TestInput(input_buf, output_buf);
 }
 
-void cOrganism::DoOutput(cAvidaContext& ctx, const int value)
+void cOrganism::DoOutput(cAvidaContext& ctx, const int value, const bool on_divide)
 {
   assert(m_interface);
   const tArray<double> & resource_count = m_interface->GetResources();
@@ -198,7 +198,7 @@
   tBuffer<int>* received_messages_point = &received_messages;
   if (!m_world->GetConfig().SAVE_RECEIVED.Get())
 	  received_messages_point = NULL;
-  cTaskContext taskctx(input_buf, output_buf, other_input_list, other_output_list, net_valid, 0, received_messages_point);
+  cTaskContext taskctx(input_buf, output_buf, other_input_list, other_output_list, net_valid, 0, on_divide, received_messages_point);
   phenotype.TestOutput(ctx, taskctx, send_buf, receive_buf, resource_count, res_change, insts_triggered);
   m_interface->UpdateResources(res_change);
 
@@ -498,6 +498,11 @@
 bool cOrganism::ActivateDivide(cAvidaContext& ctx)
 {
   assert(m_interface);
+  // Test tasks one last time before actually dividing, pass true so 
+  // know that should only test "divide" tasks here
+  // Sending last output just for lack of better idea at the moment
+  DoOutput(ctx, output_buf[0], true);
+
   // Activate the child!  (Keep Last: may kill this organism!)
   return m_interface->Divide(ctx, this, child_genome);
 }

Modified: development/source/main/cOrganism.h
===================================================================
--- development/source/main/cOrganism.h	2006-11-29 14:57:15 UTC (rev 1105)
+++ development/source/main/cOrganism.h	2006-11-30 05:22:48 UTC (rev 1106)
@@ -164,7 +164,7 @@
   
   // Input & Output Testing
   void DoInput(const int value);
-  void DoOutput(cAvidaContext& ctx, const int value);
+  void DoOutput(cAvidaContext& ctx, const int value, const bool on_divide = false);
 
   // Message stuff
   void SendMessage(cOrgMessage & mess);

Modified: development/source/main/cReactionRequisite.h
===================================================================
--- development/source/main/cReactionRequisite.h	2006-11-29 14:57:15 UTC (rev 1105)
+++ development/source/main/cReactionRequisite.h	2006-11-30 05:22:48 UTC (rev 1106)
@@ -24,19 +24,21 @@
   tList<cReaction> prior_noreaction_list;
   int min_task_count;
   int max_task_count;
+  int divide_only;
 
 
   cReactionRequisite(const cReactionRequisite&); // @not_implemented
   cReactionRequisite& operator=(const cReactionRequisite&);
 
 public:
-  cReactionRequisite() : min_task_count(0) , max_task_count(INT_MAX) { ; }
+  cReactionRequisite() : min_task_count(0) , max_task_count(INT_MAX), divide_only(0) { ; }
   ~cReactionRequisite() { ; }
 
   const tList<cReaction>& GetReactions() const { return prior_reaction_list; }
   const tList<cReaction>& GetNoReactions() const { return prior_noreaction_list; }
   int GetMinTaskCount() const { return min_task_count; }
   int GetMaxTaskCount() const { return max_task_count; }
+  int GetDivideOnly() const { return divide_only; }
 
   void AddReaction(cReaction* in_reaction) {
     prior_reaction_list.PushRear(in_reaction);
@@ -46,6 +48,7 @@
   }
   void SetMinTaskCount(int min) { min_task_count = min; }
   void SetMaxTaskCount(int max) { max_task_count = max; }
+  void SetDivideOnly(int div) { divide_only = div; }
 
   /*
   added to satisfy Boost.Python; the semantics are fairly useless --

Modified: development/source/main/cTaskContext.h
===================================================================
--- development/source/main/cTaskContext.h	2006-11-29 14:57:15 UTC (rev 1105)
+++ development/source/main/cTaskContext.h	2006-11-30 05:22:48 UTC (rev 1106)
@@ -32,20 +32,22 @@
   int net_completed;
   tBuffer<int>* received_messages;
   int logic_id;
+  bool on_divide;
   
   cTaskEntry* task_entry;
 
 public:
   cTaskContext(const tBuffer<int>& inputs, const tBuffer<int>& outputs, const tList<tBuffer<int> >& other_inputs,
                const tList<tBuffer<int> >& other_outputs, bool in_net_valid, int in_net_completed, 
-               tBuffer<int>* in_received_messages = NULL)
+			   bool in_on_divide = false, tBuffer<int>* in_received_messages = NULL)
     : input_buffer(inputs), output_buffer(outputs), other_input_buffers(other_inputs),
     other_output_buffers(other_outputs), net_valid(in_net_valid), net_completed(in_net_completed), 
-    received_messages(in_received_messages), logic_id(0), task_entry(NULL)
+	on_divide(in_on_divide), received_messages(in_received_messages), logic_id(0), task_entry(NULL)
   {
   }
   
   void SetTaskEntry(cTaskEntry* in_entry) { task_entry = in_entry; }
+  bool GetOnDivide() { return on_divide; }
 };
 
 

Modified: development/source/main/cTaskLib.cc
===================================================================
--- development/source/main/cTaskLib.cc	2006-11-29 14:57:15 UTC (rev 1105)
+++ development/source/main/cTaskLib.cc	2006-11-30 05:22:48 UTC (rev 1106)
@@ -1740,9 +1740,9 @@
 double cTaskLib::Task_MatchStr(cTaskContext* ctx) const
 {
 	tBuffer<int> temp_buf(ctx->output_buffer);
-	if (temp_buf[0] != 357913941) return 0;
+	//	if (temp_buf[0] != 357913941) return 0;
 
-	temp_buf.Pop(); // pop the signal value off of the buffer
+	//	temp_buf.Pop(); // pop the signal value off of the buffer
 
 	const cString& string_to_match = ctx->task_entry->GetArguments().GetString(0);
 	int string_index;




More information about the Avida-cvs mailing list