[Avida-cvs] [Avida2-svn] r200 - in trunk: documentation/content/using source/cpu source/event source/main

dule@myxo.css.msu.edu dule at myxo.css.msu.edu
Fri Jun 10 10:42:45 PDT 2005


Author: dule
Date: 2005-06-10 13:42:45 -0400 (Fri, 10 Jun 2005)
New Revision: 200

Modified:
   trunk/documentation/content/using/events.html
   trunk/documentation/content/using/genesis.html
   trunk/documentation/content/using/inst_set.html
   trunk/source/cpu/hardware_cpu.cc
   trunk/source/cpu/hardware_cpu.hh
   trunk/source/event/cPopulation.events
   trunk/source/main/config.cc
   trunk/source/main/config.hh
   trunk/source/main/environment.cc
   trunk/source/main/environment.hh
   trunk/source/main/reaction.cc
   trunk/source/main/reaction.hh
Log:

Added a new instrucion, 'die' which kills the organisms when executed, 
with a probability set in genesis by DIE_PROB variable. 

Also added an event to set the instruction triggered by a reaction, 
set_reaction_inst. 

See .html documentation for more info. 



Modified: trunk/documentation/content/using/events.html
===================================================================
--- trunk/documentation/content/using/events.html	2005-06-10 14:24:16 UTC (rev 199)
+++ trunk/documentation/content/using/events.html	2005-06-10 17:42:45 UTC (rev 200)
@@ -197,6 +197,7 @@
       <A HREF="#set_resource">set_resource</A><br>
       <A HREF="#set_reaction_value">set_reaction_value</A><br>
       <A HREF="#set_reaction_value_mult">set_reaction_value_mult</A><br>
+      <A HREF="#set_reaction_inst">set_reaction_inst</A><br>
       <A HREF="#sever_grid_col">sever_grid_col</A><br>
       <A HREF="#task_snapshot">task_snapshot</A><br>
       <A HREF="#test_dom">test_dom</A><br>
@@ -828,6 +829,11 @@
 <li><b><A NAME="set_reaction_value_mult">set_reaction_value_mult</A></b> [<font color="#008800">reaction_name</font>] [<font color="#008800">value_mult</font>] <br> 
     Multiply the reaction value ("bonus") by the <b>value_mult</b>. <b>reaction_name</b> must 
     already exist in the environment file. <b>value_mult</b> can be negative. 
+<br>
+<li><b><A NAME="set_reaction_inst">set_reaction_inst</A></b> [<font color="#008800">reaction_name</font>] 
+    [<font color="#008800">inst_name</font>] <br> 
+    Set the instruction triggered by this reaction. <b>reaction_name</b> must
+    already exist in the environment file. <b>inst_name</b> must be in the instruction set. 
 </menu>
 
 <p>

Modified: trunk/documentation/content/using/genesis.html
===================================================================
--- trunk/documentation/content/using/genesis.html	2005-06-10 14:24:16 UTC (rev 199)
+++ trunk/documentation/content/using/genesis.html	2005-06-10 17:42:45 UTC (rev 200)
@@ -164,6 +164,9 @@
 <tr><td valign=top><b><tt>REQUIRED_REACTION</tt></b>
     <td>Allows the user to set the ID number for a reaction that <i>must</i> 
         occur for a divide to be successful.  At -1, no reactions are required.
+<tr><td valign=top><b><tt>DIE_PROB</tt></b>
+    <td>Determines the probability of organism dieing when 'die' instruction is
+	executed. Set to 0 by default, making the instruction neutral. 
 </table>
 
 <h3>Mutations</h3>
@@ -429,4 +432,4 @@
 <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
+    

Modified: trunk/documentation/content/using/inst_set.html
===================================================================
--- trunk/documentation/content/using/inst_set.html	2005-06-10 14:24:16 UTC (rev 199)
+++ trunk/documentation/content/using/inst_set.html	2005-06-10 17:42:45 UTC (rev 200)
@@ -252,6 +252,10 @@
 no recombination here, but each genome must wait in the birth chamber until 
 another one arrives before they are both placed into the population. 
 
+<p>
+<b><tt>die</tt></b><br>
+When executed, kills the organism, with the probability set by DIE_PROB in genesis. 
+
 <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>

Modified: trunk/source/cpu/hardware_cpu.cc
===================================================================
--- trunk/source/cpu/hardware_cpu.cc	2005-06-10 14:24:16 UTC (rev 199)
+++ trunk/source/cpu/hardware_cpu.cc	2005-06-10 17:42:45 UTC (rev 200)
@@ -322,6 +322,7 @@
 
     // Suicide
     cInstEntryCPU("kazi",	&cHardwareCPU::Inst_Kazi),
+    cInstEntryCPU("die",	&cHardwareCPU::Inst_Die),
 
 
 
@@ -2651,6 +2652,13 @@
 	}
 }
 
+bool cHardwareCPU::Inst_Die()
+{
+   const double die_prob = cConfig::GetDieProb();
+   if(g_random.GetDouble() < die_prob) { organism->Die(); }
+   return true; 
+}
+
 // The inject instruction can be used instead of a divide command, paired
 // with an allocate.  Note that for an inject to work, one needs to have a
 // broad range for sizes allowed to be allocated.

Modified: trunk/source/cpu/hardware_cpu.hh
===================================================================
--- trunk/source/cpu/hardware_cpu.hh	2005-06-10 14:24:16 UTC (rev 199)
+++ trunk/source/cpu/hardware_cpu.hh	2005-06-10 17:42:45 UTC (rev 200)
@@ -369,6 +369,7 @@
   bool Inst_InjectThread();
   bool Inst_Repro();
   bool Inst_Kazi();
+  bool Inst_Die();
 
   // I/O and Sensory
   bool Inst_TaskGet();

Modified: trunk/source/event/cPopulation.events
===================================================================
--- trunk/source/event/cPopulation.events	2005-06-10 14:24:16 UTC (rev 199)
+++ trunk/source/event/cPopulation.events	2005-06-10 17:42:45 UTC (rev 200)
@@ -2134,3 +2134,14 @@
 double value_mult
 :body:
 population->GetEnvironment().SetReactionValueMult(reaction_name, value_mult);
+
+set_reaction_inst
+:descr:
+/**
+* Change the instruction triggered by the task **/
+:args:
+cString reaction_name
+cString inst_name
+:body:
+population->GetEnvironment().SetReactionInst(reaction_name, inst_name);
+

Modified: trunk/source/main/config.cc
===================================================================
--- trunk/source/main/config.cc	2005-06-10 14:24:16 UTC (rev 199)
+++ trunk/source/main/config.cc	2005-06-10 17:42:45 UTC (rev 200)
@@ -116,6 +116,7 @@
 bool cConfig::log_lineages;
 int cConfig::debug_level;
 int cConfig::view_mode;
+double cConfig::die_prob;
 
 void cConfig::InitGroupList(){
   // Start with the Architecture variables...
@@ -208,8 +209,11 @@
 		 "Task ID required for successful divide.");
   div_group->Add(required_reaction, "-1", "REQUIRED_REACTION",
 		 "Reaction ID required for successful divide.");
+  div_group->Add(die_prob, "0", "DIE_PROB",
+		 "probability of death when 'die' instruction is executed"); 
 
 
+
   // Mutations Group
   cConfigGroup * muts_group = new cConfigGroup("Mutations");
   group_list.PushRear(muts_group);
@@ -258,9 +262,8 @@
   rev_group->Add(sterilize_pos, "0.0", "STERILIZE_BENEFICIAL",
 		 "");
   rev_group->Add(fail_implicit, "0", "FAIL_IMPLICIT",
-		 "Should copies that failed *not* due to mutations\nbe eliminated?");
+               "Should copies that failed *not* due to mutations\nbe eliminated?");
 
-
   // Time slicing group
   cConfigGroup * time_group = new cConfigGroup("Time Slicing");
   group_list.PushRear(time_group);

Modified: trunk/source/main/config.hh
===================================================================
--- trunk/source/main/config.hh	2005-06-10 14:24:16 UTC (rev 199)
+++ trunk/source/main/config.hh	2005-06-10 17:42:45 UTC (rev 200)
@@ -293,6 +293,9 @@
   // Viewer
   static int view_mode;
 
+  // Death
+  static double die_prob; 
+
   // Other functions...
   static void ProcessConfiguration(int argc, char* argv[], cGenesis & genesis);
 public:
@@ -428,7 +431,9 @@
 
   static int GetViewMode() { return view_mode; }
 
+  static double GetDieProb() { return die_prob; }
 
+
   // ``Set''
   static void SetInstFilename(const cString & in_name)
     { inst_filename = in_name; }

Modified: trunk/source/main/environment.cc
===================================================================
--- trunk/source/main/environment.cc	2005-06-10 14:24:16 UTC (rev 199)
+++ trunk/source/main/environment.cc	2005-06-10 17:42:45 UTC (rev 200)
@@ -949,3 +949,11 @@
   return true;
 }
 
+bool cEnvironment::SetReactionInst(const cString & name, cString inst_name)
+{
+  cReaction * found_reaction = reaction_lib.GetReaction(name);
+  if (found_reaction == NULL) return false;
+  found_reaction->ModifyInst( inst_set.GetInst(inst_name).GetOp() );
+  return true;
+}
+

Modified: trunk/source/main/environment.hh
===================================================================
--- trunk/source/main/environment.hh	2005-06-10 14:24:16 UTC (rev 199)
+++ trunk/source/main/environment.hh	2005-06-10 17:42:45 UTC (rev 200)
@@ -134,6 +134,7 @@
   double GetReactionValue(int & reaction_id);
   bool SetReactionValue(const cString & name, double value);
   bool SetReactionValueMult(const cString & name, double value_mult);
+  bool SetReactionInst(const cString & name, cString inst_name);
 };
 
 #endif

Modified: trunk/source/main/reaction.cc
===================================================================
--- trunk/source/main/reaction.cc	2005-06-10 14:24:16 UTC (rev 199)
+++ trunk/source/main/reaction.cc	2005-06-10 17:42:45 UTC (rev 200)
@@ -65,6 +65,14 @@
   return true;
 }
 
+bool cReaction::ModifyInst(int inst_id, int process_num) 
+{
+  if (process_num >= process_list.GetSize() || process_num < 0) return false;
+  process_list.GetPos(process_num)->SetInstID(inst_id);
+  return true;
+}
+
+
 double cReaction::GetValue(int process_num)
 { 
   if (process_num >= process_list.GetSize() || process_num < 0) return false;

Modified: trunk/source/main/reaction.hh
===================================================================
--- trunk/source/main/reaction.hh	2005-06-10 14:24:16 UTC (rev 199)
+++ trunk/source/main/reaction.hh	2005-06-10 17:42:45 UTC (rev 200)
@@ -50,6 +50,9 @@
   bool ModifyValue(double new_value, int process_num=0);
   bool MultiplyValue(double value_mult, int process_num=0); 
 
+  // This method will modify the instruction triggered by this process
+  bool ModifyInst(int inst_id, int process_num=0); 
+
   double GetValue(int process_num=0);
 
 };




More information about the Avida-cvs mailing list