[avida-cvs] avida CVS commits: /current/source/main environment.cc organism.cc phenotype.cc phenotype.hh reaction_result.cc reaction_result.hh

bckirkup avida-cvs at alife.org
Tue Jun 24 22:56:40 PDT 2003


bckirkup		Tue Jun 24 14:56:40 2003 EDT

  Modified files:              
    /avida/current/source/main	environment.cc organism.cc phenotype.cc 
                              	phenotype.hh reaction_result.cc 
                              	reaction_result.hh 
  Log:
  Lethal Reactions = done.  Resource Detection = 1/2 way there.
  
-------------- next part --------------
Index: avida/current/source/main/environment.cc
diff -u avida/current/source/main/environment.cc:1.12 avida/current/source/main/environment.cc:1.13
--- avida/current/source/main/environment.cc:1.12	Wed Jun 18 17:41:59 2003
+++ avida/current/source/main/environment.cc	Tue Jun 24 14:56:39 2003
@@ -8,6 +8,7 @@
 #include "../cpu/hardware_method.hh"
 #include "environment.hh"
 
+#include "../tools/random.hh"
 #include "../tools/string_util.hh"
 
 
@@ -779,12 +780,30 @@
       break;
     };
 
+	// Determine detection events
+	cResource * detected = cur_process->GetDetect();
+	const int detected_id = detected->GetID();
+	int real_amount = resource_count[detected_id];
+	//Arbitrary value for infinite resource
+	if (detected == NULL) result.Detect(detected_id, 1.0);
+	else
+	{
+		double estimated_amount =
+			g_random.GetRandNormal(real_amount, cur_process->GetDetectionError()*real_amount);
+		if (estimated_amount < cur_process->GetDetectionThreshold())
+			result.Detect(detected_id, 0.0);				
+		else result.Detect(detected_id, estimated_amount);
+	};
+
     // Determine byproducts
     cResource * product = cur_process->GetProduct();
-    if (product == NULL) continue;
-
-    int product_id = product->GetID();
+    if (product != NULL) 
+	{
+	int product_id = product->GetID();
     double product_size = consumed * cur_process->GetConversion();
     result.Produce(product_id, product_size);
+	};
+
+	result.Lethal(cur_process->GetLethal());
   }
 }
Index: avida/current/source/main/organism.cc
diff -u avida/current/source/main/organism.cc:1.23 avida/current/source/main/organism.cc:1.24
--- avida/current/source/main/organism.cc:1.23	Sat May 17 14:54:55 2003
+++ avida/current/source/main/organism.cc	Tue Jun 24 14:56:39 2003
@@ -94,8 +94,8 @@
 
   out_buf.Add(value);
   phenotype.TestOutput(in_buf, out_buf, resource_count, res_change);
-  
   pop_interface.UpdateResources(res_change);
+  if(phenotype.GetToDie() == 1) Die();	//Final Effect Lethal Reaction
 }
 
 
Index: avida/current/source/main/phenotype.cc
diff -u avida/current/source/main/phenotype.cc:1.33 avida/current/source/main/phenotype.cc:1.34
--- avida/current/source/main/phenotype.cc:1.33	Sun Jun  8 19:36:09 2003
+++ avida/current/source/main/phenotype.cc	Tue Jun 24 14:56:39 2003
@@ -25,6 +25,7 @@
   , last_task_count(environment.GetTaskLib().GetSize())
   , last_reaction_count(environment.GetReactionLib().GetSize())
   , last_inst_count(environment.GetInstSet().GetSize())
+  , sensed_resources(environment.GetResourceLib().GetSize())
 {
 }
 
@@ -52,7 +53,7 @@
   assert(time_used >= 0);
   assert(age >= 0);
   assert(child_copied_size >= 0);
-
+  assert(to_die == false);
   return true;
 }
 
@@ -91,6 +92,9 @@
   cur_task_count.SetAll(0);
   cur_reaction_count.SetAll(0);
   cur_inst_count.SetAll(0);
+  for (int j = 0; j < sensed_resources.GetSize(); j++)
+	      sensed_resources[j] =  parent_phenotype.sensed_resources[j];
+ 
 
   // Copy last values from parent
   last_merit_base     = parent_phenotype.last_merit_base;
@@ -120,6 +124,7 @@
   is_multi_thread = parent_phenotype.is_multi_thread;
   parent_true   = parent_phenotype.copy_true;
   parent_sex    = parent_phenotype.divide_sex;
+  to_die = false; 
 
   // Setup child info...
   copy_true          = false;
@@ -159,6 +164,7 @@
   cur_task_count.SetAll(0);
   cur_reaction_count.SetAll(0);
   cur_inst_count.SetAll(0);
+  sensed_resources.SetAll(0);
 
   // Copy last values from parent
   last_merit_base = _length;
@@ -186,6 +192,7 @@
   is_multi_thread = false;
   parent_true   = true;
   parent_sex    = false;
+  to_die = false;
 
   // Setup child info...
   copy_true         = false;
@@ -308,6 +315,7 @@
   cur_task_count.SetAll(0);
   cur_reaction_count.SetAll(0);
   cur_inst_count.SetAll(0);
+  sensed_resources.SetAll(-1.0);
 
   // Setup other miscellaneous values...
   num_divides++;
@@ -386,6 +394,14 @@
   for (int i = 0; i < res_in.GetSize(); i++) {
     res_change[i] = result.GetProduced(i) - result.GetConsumed(i);
   }
+
+  //Put in detected resources
+  for (int j = 0; j < res_in.GetSize(); j++)
+	  if(result.GetDetected(j) != -1.0)
+	      sensed_resources[j] = result.GetDetected(j);
+
+  //Kill any cells that did lethal reactions
+  to_die = result.GetLethal();
 
   return true;
 }
Index: avida/current/source/main/phenotype.hh
diff -u avida/current/source/main/phenotype.hh:1.35 avida/current/source/main/phenotype.hh:1.36
--- avida/current/source/main/phenotype.hh:1.35	Fri Jun  6 12:46:23 2003
+++ avida/current/source/main/phenotype.hh	Tue Jun 24 14:56:39 2003
@@ -54,14 +54,16 @@
   int gestation_time;    // CPU cycles to produce offspring (or be produced)
   int gestation_start;   // Total instructions executed at last divide.
   double fitness;        // Relative efective replication rate...
-  double div_type;	 // Type of the divide command used
+  double div_type;	     // Type of the divide command used
 
   // 2. These are "in progress" variables, updated as the organism operates
   double cur_bonus;               // Current Bonus
+  bool to_die;					  // Has executed a fatal reaction
   int cur_num_errors;             // Total instructions executed illeagally.
   tArray<int> cur_task_count;     // Total times each task was performed
   tArray<int> cur_reaction_count; // Total times each reaction was triggered.
   tArray<int> cur_inst_count;	  // Intruction exection counter
+  tArray<double> sensed_resources; // Resources of which the organism is explictly aware
 
   // 3. These mark the status of "in progess" variables at the last divide.
   double last_merit_base;         // Either constant or based on genome length.
@@ -157,6 +159,8 @@
 
   double GetCurBonus() const
     { assert(initialized == true); return cur_bonus; }
+  bool GetToDie() const
+    { assert(initialized == true); return to_die; }
   int GetCurNumErrors()const
     { assert(initialized == true); return cur_num_errors; }
   const tArray<int> & GetCurTaskCount() const
@@ -165,6 +169,9 @@
     { assert(initialized == true); return cur_reaction_count;}
   const tArray<int> & GetCurInstCount() const
     { assert(initialized == true); return cur_inst_count; }
+  
+  double GetSensedResource(int _in)
+  { assert(initialized == true); return sensed_resources[_in]; }
 
   double GetLastMeritBase() const
     { assert(initialized == true); return last_merit_base; }
Index: avida/current/source/main/reaction_result.cc
diff -u avida/current/source/main/reaction_result.cc:1.2 avida/current/source/main/reaction_result.cc:1.3
--- avida/current/source/main/reaction_result.cc:1.2	Sat May 17 02:48:10 2003
+++ avida/current/source/main/reaction_result.cc	Tue Jun 24 14:56:39 2003
@@ -13,11 +13,13 @@
 				 const int num_reactions)
   : resources_consumed(num_resources)
   , resources_produced(num_resources)
+  , resources_detected(num_resources)
   , tasks_done(num_tasks)
   , reactions_triggered(num_reactions)
   , bonus_add(0.0)
   , bonus_mult(1.0)
   , active_reaction(false)
+  , lethal(false)
 {
 }
 
@@ -43,8 +45,9 @@
   if (active_reaction == true) return;
 
   // To activate the reaction, we must initialize all counter settings.
-  resources_consumed.SetAll(0);
-  resources_produced.SetAll(0);
+  resources_consumed.SetAll(0.0);
+  resources_produced.SetAll(0.0);
+  resources_detected.SetAll(-1.0);
   tasks_done.SetAll(false);
   reactions_triggered.SetAll(false);
 
@@ -67,6 +70,18 @@
 }
 
 
+void cReactionResult::Detect(int id, double num)
+{
+  ActivateReaction();
+  resources_detected[id] += num;
+}
+
+void cReactionResult::Lethal(bool num)
+{
+ ActivateReaction();
+ lethal = true;
+}
+
 void cReactionResult::MarkTask(int id)
 {
   ActivateReaction();
@@ -106,6 +121,18 @@
 {
   if (GetActive() == false) return 0.0;
   return resources_produced[id];
+}
+
+double cReactionResult::GetDetected(int id)
+{
+  if (GetActive() == false) return 0.0;
+  return resources_detected[id];
+}
+
+bool cReactionResult::GetLethal()
+{
+  if (GetActive() == false) return false;
+  return lethal;
 }
 
 bool cReactionResult::ReactionTriggered(int id)
Index: avida/current/source/main/reaction_result.hh
diff -u avida/current/source/main/reaction_result.hh:1.1 avida/current/source/main/reaction_result.hh:1.2
--- avida/current/source/main/reaction_result.hh:1.1	Sat Oct 27 12:21:33 2001
+++ avida/current/source/main/reaction_result.hh	Tue Jun 24 14:56:39 2003
@@ -14,10 +14,13 @@
 private:
   tArray<double> resources_consumed;
   tArray<double> resources_produced;
+  tArray<double> resources_detected;  //Initialize to -1.0
   tArray<bool> tasks_done;
   tArray<bool> reactions_triggered;
   double bonus_add;
   double bonus_mult;
+  bool lethal;
+  
 
   bool active_reaction;
 
@@ -31,6 +34,8 @@
 
   void Consume(int id, double num);
   void Produce(int id, double num);
+  void Detect(int id, double num);
+  void Lethal(bool num);
   void MarkTask(int id);
   void MarkReaction(int id);
   void AddBonus(double value);
@@ -38,6 +43,8 @@
 
   double GetConsumed(int id);
   double GetProduced(int id);
+  double GetDetected(int id);
+  bool GetLethal();
   bool ReactionTriggered(int id);
   bool TaskDone(int id);
   double GetAddBonus();


More information about the Avida-cvs mailing list