[Avida-SVN] r1342 - in branches/energy: Avida.xcodeproj source/cpu source/main

beckma24 at myxo.css.msu.edu beckma24 at myxo.css.msu.edu
Tue Feb 20 06:38:01 PST 2007


Author: beckma24
Date: 2007-02-20 09:38:00 -0500 (Tue, 20 Feb 2007)
New Revision: 1342

Modified:
   branches/energy/Avida.xcodeproj/project.pbxproj
   branches/energy/source/cpu/cHardwareCPU.cc
   branches/energy/source/cpu/cHardwareCPU.h
   branches/energy/source/cpu/cHardwareManager.cc
   branches/energy/source/cpu/cInstSet.cc
   branches/energy/source/cpu/cInstSet.h
   branches/energy/source/main/cAvidaConfig.h
   branches/energy/source/main/cEnvironment.cc
   branches/energy/source/main/cPhenotype.cc
   branches/energy/source/main/cPhenotype.h
   branches/energy/source/main/cReactionResult.cc
   branches/energy/source/main/cReactionResult.h
   branches/energy/source/main/nReaction.h
Log:
Added variables for energy, however, merit is not yet adjusted.

Modified: branches/energy/Avida.xcodeproj/project.pbxproj
===================================================================
--- branches/energy/Avida.xcodeproj/project.pbxproj	2007-02-20 13:36:25 UTC (rev 1341)
+++ branches/energy/Avida.xcodeproj/project.pbxproj	2007-02-20 14:38:00 UTC (rev 1342)
@@ -384,6 +384,23 @@
 		};
 /* End PBXBuildRule section */
 
+/* Begin PBXBuildStyle section */
+		B500F94E0B8A8F72001CFA19 /* Development */ = {
+			isa = PBXBuildStyle;
+			buildSettings = {
+				COPY_PHASE_STRIP = NO;
+			};
+			name = Development;
+		};
+		B500F94F0B8A8F72001CFA19 /* Deployment */ = {
+			isa = PBXBuildStyle;
+			buildSettings = {
+				COPY_PHASE_STRIP = YES;
+			};
+			name = Deployment;
+		};
+/* End PBXBuildStyle section */
+
 /* Begin PBXContainerItemProxy section */
 		70DCF67509D4E10500924128 /* PBXContainerItemProxy */ = {
 			isa = PBXContainerItemProxy;
@@ -1847,6 +1864,12 @@
 		DCC30C4D0762532C008F7A48 /* Project object */ = {
 			isa = PBXProject;
 			buildConfigurationList = 702442D70859E0B00059BD9B /* Build configuration list for PBXProject "Avida" */;
+			buildSettings = {
+			};
+			buildStyles = (
+				B500F94E0B8A8F72001CFA19 /* Development */,
+				B500F94F0B8A8F72001CFA19 /* Deployment */,
+			);
 			hasScannedForEncodings = 0;
 			mainGroup = DCC30C490762532C008F7A48;
 			productRefGroup = DCC3164E07626CF3008F7A48 /* Products */;

Modified: branches/energy/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/energy/source/cpu/cHardwareCPU.cc	2007-02-20 13:36:25 UTC (rev 1341)
+++ branches/energy/source/cpu/cHardwareCPU.cc	2007-02-20 14:38:00 UTC (rev 1342)
@@ -374,6 +374,7 @@
 #if INSTRUCTION_COSTS
 , inst_cost(hardware_cpu.inst_cost)
 , inst_ft_cost(hardware_cpu.inst_ft_cost)
+, inst_energy_cost(hardware_cpu.inst_energy_cost)
 #endif
 {
 }
@@ -403,6 +404,7 @@
   for (int i = 0; i < num_inst_cost; i++) {
     inst_cost[i] = m_inst_set->GetCost(cInstruction(i));
     inst_ft_cost[i] = m_inst_set->GetFTCost(cInstruction(i));
+    inst_energy_cost[i] = m_inst_set->GetEnergyCost(cInstruction(i));
   }
 #endif 
   
@@ -516,6 +518,16 @@
 #if INSTRUCTION_COSTS
   assert(cur_inst.GetOp() < inst_cost.GetSize());
   
+  // check energy first
+  if(m_inst_set->GetEnergyCost(cur_inst) > 0) {
+    //TODO:
+    if(enough energy) {
+      subtract energy used from current energy.
+    } else
+      return false;  // not enough energy
+  }
+  
+  
   // If first time cost hasn't been paid off...
   if ( inst_ft_cost[cur_inst.GetOp()] > 0 ) {
     inst_ft_cost[cur_inst.GetOp()]--;       // dec cost

Modified: branches/energy/source/cpu/cHardwareCPU.h
===================================================================
--- branches/energy/source/cpu/cHardwareCPU.h	2007-02-20 13:36:25 UTC (rev 1341)
+++ branches/energy/source/cpu/cHardwareCPU.h	2007-02-20 14:38:00 UTC (rev 1342)
@@ -142,6 +142,7 @@
 #if INSTRUCTION_COSTS
   tArray<int> inst_cost;
   tArray<int> inst_ft_cost;
+  tArray<int> inst_energy_cost;
 #endif
   
   

Modified: branches/energy/source/cpu/cHardwareManager.cc
===================================================================
--- branches/energy/source/cpu/cHardwareManager.cc	2007-02-20 13:36:25 UTC (rev 1341)
+++ branches/energy/source/cpu/cHardwareManager.cc	2007-02-20 14:38:00 UTC (rev 1342)
@@ -84,6 +84,7 @@
     int redundancy = cur_line.PopWord().AsInt();
     int cost = cur_line.PopWord().AsInt();
     int ft_cost = cur_line.PopWord().AsInt();
+    int energy_cost = cur_line.PopWord().AsInt();
     double prob_fail = cur_line.PopWord().AsDouble();
     int addl_time_cost = cur_line.PopWord().AsInt();
 
@@ -108,9 +109,9 @@
     }
     
     if (inst_lib[inst_idx].IsNop()) {
-      m_inst_set->AddNop(inst_idx, redundancy, ft_cost, cost, prob_fail, addl_time_cost);
+      m_inst_set->AddNop(inst_idx, redundancy, ft_cost, cost, energy_cost, prob_fail, addl_time_cost);
     } else {
-      m_inst_set->AddInst(inst_idx, redundancy, ft_cost, cost, prob_fail, addl_time_cost);
+      m_inst_set->AddInst(inst_idx, redundancy, ft_cost, cost, energy_cost, prob_fail, addl_time_cost);
     }
   }
 }

Modified: branches/energy/source/cpu/cInstSet.cc
===================================================================
--- branches/energy/source/cpu/cInstSet.cc	2007-02-20 13:36:25 UTC (rev 1341)
+++ branches/energy/source/cpu/cInstSet.cc	2007-02-20 14:38:00 UTC (rev 1342)
@@ -58,7 +58,7 @@
   return cInstruction(inst_op);
 }
 
-int cInstSet::AddInst(int lib_fun_id, int redundancy, int ft_cost, int cost, double prob_fail, int addl_time_cost)
+int cInstSet::AddInst(int lib_fun_id, int redundancy, int ft_cost, int cost, int energy_cost, double prob_fail, int addl_time_cost)
 {
   const int inst_id = m_lib_name_map.GetSize();
 
@@ -72,6 +72,7 @@
   m_lib_name_map[inst_id].redundancy = redundancy;
   m_lib_name_map[inst_id].cost = cost;
   m_lib_name_map[inst_id].ft_cost = ft_cost;
+  m_lib_name_map[inst_id].energy_cost = energy_cost;
   m_lib_name_map[inst_id].prob_fail = prob_fail;
   m_lib_name_map[inst_id].addl_time_cost = addl_time_cost;
 
@@ -84,12 +85,12 @@
   return inst_id;
 }
 
-int cInstSet::AddNop(int lib_nopmod_id, int redundancy, int ft_cost, int cost, double prob_fail, int addl_time_cost)
+int cInstSet::AddNop(int lib_nopmod_id, int redundancy, int ft_cost, int cost, int energy_cost, double prob_fail, int addl_time_cost)
 {
   // Assert nops are at the _beginning_ of an inst_set.
   assert(m_lib_name_map.GetSize() == m_lib_nopmod_map.GetSize());
 
-  const int inst_id = AddInst(lib_nopmod_id, redundancy, ft_cost, cost, prob_fail, addl_time_cost);
+  const int inst_id = AddInst(lib_nopmod_id, redundancy, ft_cost, cost, int energy_cost, prob_fail, addl_time_cost);
 
   m_lib_nopmod_map.Resize(inst_id + 1);
   m_lib_nopmod_map[inst_id] = lib_nopmod_id;

Modified: branches/energy/source/cpu/cInstSet.h
===================================================================
--- branches/energy/source/cpu/cInstSet.h	2007-02-20 13:36:25 UTC (rev 1341)
+++ branches/energy/source/cpu/cInstSet.h	2007-02-20 14:38:00 UTC (rev 1342)
@@ -65,6 +65,7 @@
     int redundancy;           // Weight in instruction set (not impl.)
     int cost;                 // additional time spent to exectute inst.
     int ft_cost;              // time spent first time exec (in add to cost)
+    int energy_cost;          // energy required to execute.
     double prob_fail;         // probability of failing to execute inst
     int addl_time_cost;       // additional time added to age for executing instruction
   };
@@ -93,6 +94,7 @@
   const cString& GetName(const cInstruction& inst) const { return GetName(inst.GetOp()); }
   int GetCost(const cInstruction& inst) const { return m_lib_name_map[inst.GetOp()].cost; }
   int GetFTCost(const cInstruction& inst) const { return m_lib_name_map[inst.GetOp()].ft_cost; }
+  int GetEnergyCost(const cInstruction& inst) const { return m_lib_name_map[inst.GetOp()].energy_cost; }
   int GetAddlTimeCost(const cInstruction& inst) const { return m_lib_name_map[inst.GetOp()].addl_time_cost; }
   double GetProbFail(const cInstruction& inst) const { return m_lib_name_map[inst.GetOp()].prob_fail; }
   int GetRedundancy(const cInstruction& inst) const { return m_lib_name_map[inst.GetOp()].redundancy; }

Modified: branches/energy/source/main/cAvidaConfig.h
===================================================================
--- branches/energy/source/main/cAvidaConfig.h	2007-02-20 13:36:25 UTC (rev 1341)
+++ branches/energy/source/main/cAvidaConfig.h	2007-02-20 14:38:00 UTC (rev 1342)
@@ -235,7 +235,10 @@
   CONFIG_ADD_VAR(IMMUNITY_TASK, int, -1, "Task providing immunity from the required task.");
   CONFIG_ADD_VAR(REQUIRED_REACTION, int, -1, "Reaction ID required for successful divide.");
   CONFIG_ADD_VAR(REQUIRED_BONUS, int, 0, "The bonus that an organism must accumulate to divide."); 
+  CONFIG_ADD_VAR(FRAC_ENERGY_GIVEN, int, 0.5, "Fraction of energy given to offspring."); 
+  CONFIG_ADD_VAR(INITITAL_ENERGY_GIVEN, int, -1, "Initial energy given to offspring.\n-1 = energy model off"); 
  
+ 
   CONFIG_ADD_GROUP(MUTATION_GROUP, "Mutations");
   CONFIG_ADD_VAR(POINT_MUT_PROB, double, 0.0, "Mutation rate (per-location per update)");
   CONFIG_ADD_VAR(COPY_MUT_PROB, double, 0.0075, "Mutation rate (per copy)");

Modified: branches/energy/source/main/cEnvironment.cc
===================================================================
--- branches/energy/source/main/cEnvironment.cc	2007-02-20 13:36:25 UTC (rev 1341)
+++ branches/energy/source/main/cEnvironment.cc	2007-02-20 14:38:00 UTC (rev 1342)
@@ -155,6 +155,7 @@
       else if (var_value=="mult") new_process->SetType(nReaction::PROCTYPE_MULT);
       else if (var_value=="pow") new_process->SetType(nReaction::PROCTYPE_POW);
       else if (var_value=="lin") new_process->SetType(nReaction::PROCTYPE_LIN);
+      else if (var_value=="energy") new_process->SetType(nReaction::PROCTYPE_ENERGY);
       else {
         cerr << "Unknown reaction process type '" << var_value
         << "' found in '" << reaction->GetName() << "'." << endl;
@@ -972,6 +973,10 @@
       case nReaction::PROCTYPE_LIN:
         result.AddBonus( bonus * task_count);
         break;
+      case nReaction::PROCTYPE_ENERGY:
+        result.AddEnergy( bonus * task_count);
+        break;
+        
       default:
         assert(false);  // Should not get here!
         break;

Modified: branches/energy/source/main/cPhenotype.cc
===================================================================
--- branches/energy/source/main/cPhenotype.cc	2007-02-20 13:36:25 UTC (rev 1341)
+++ branches/energy/source/main/cPhenotype.cc	2007-02-20 14:38:00 UTC (rev 1342)
@@ -289,6 +289,12 @@
     merit = cur_merit_base * cur_bonus;
   }
   
+  double init_energy_give = m_world->GetConfig().INITITAL_ENERGY_GIVEN.Get()
+  if(init_energy_give >= 0.0) {  
+    // adjust energy and merit
+    energy_store = cur_energy + init_energy_give;
+  }
+  
   genome_length   = _length;
   (void) copied_size;          // Unchanged
   (void) executed_size;        // Unchanged
@@ -299,6 +305,7 @@
   // Lock in cur values as last values.
   last_merit_base     = cur_merit_base;
   last_bonus          = cur_bonus;
+  last_energy         = cur_energy;
   last_num_errors     = cur_num_errors;
   last_num_donates    = cur_num_donates;
   last_task_count     = cur_task_count;
@@ -309,6 +316,7 @@
 
   // Reset cur values.
   cur_bonus       = m_world->GetConfig().DEFAULT_BONUS.Get();
+  cur_energy      = 0.0;
   cur_num_errors  = 0;
   cur_num_donates  = 0;
   cur_task_count.SetAll(0);
@@ -589,7 +597,10 @@
   // Update the merit bonus
   cur_bonus *= result.GetMultBonus();
   cur_bonus += result.GetAddBonus();
-
+  
+  // Update the energy bonus
+  cur_energy += result.GetAddEnergy()
+  
   // Denote consumed resources...
   for (int i = 0; i < res_in.GetSize(); i++) {
     res_change[i] = result.GetProduced(i) - result.GetConsumed(i);

Modified: branches/energy/source/main/cPhenotype.h
===================================================================
--- branches/energy/source/main/cPhenotype.h	2007-02-20 13:36:25 UTC (rev 1341)
+++ branches/energy/source/main/cPhenotype.h	2007-02-20 14:38:00 UTC (rev 1342)
@@ -87,6 +87,7 @@
 
   // 1. These are values calculated at the last divide (of self or offspring)
   cMerit merit;             // Relative speed of CPU
+  double energy_store;      // Amount of energy.  Determines relative speed of CPU when turned on.
   int genome_length;        // Number of instructions in genome.
   int copied_size;          // Instructions copied into genome.
   int executed_size;        // Instructions executed from genome.
@@ -98,6 +99,7 @@
 
   // 2. These are "in progress" variables, updated as the organism operates
   double cur_bonus;               // Current Bonus
+  double cur_energy;              // Current energy bonus
   int cur_num_errors;             // Total instructions executed illeagally.
   int cur_num_donates;            // Number of donations so far
   tArray<int> cur_task_count;     // Total times each task was performed
@@ -112,6 +114,7 @@
   // 3. These mark the status of "in progess" variables at the last divide.
   double last_merit_base;         // Either constant or based on genome length.
   double last_bonus;
+  double last_energy;
   int last_num_errors;
   int last_num_donates;
   tArray<int> last_task_count;

Modified: branches/energy/source/main/cReactionResult.cc
===================================================================
--- branches/energy/source/main/cReactionResult.cc	2007-02-20 13:36:25 UTC (rev 1341)
+++ branches/energy/source/main/cReactionResult.cc	2007-02-20 14:38:00 UTC (rev 1342)
@@ -35,6 +35,7 @@
   , tasks_done(num_tasks)
   , tasks_quality(num_tasks)
   , reactions_triggered(num_reactions)
+  , energy_add(0.0)
   , bonus_add(0.0)
   , bonus_mult(1.0)
   , insts_triggered(0)
@@ -102,7 +103,13 @@
   reactions_triggered[id] = true;
 }
 
+void cReactionResult::AddEnergy(double value)
+{
+  ActivateReaction();
+  energy_add += value;
+}
 
+
 void cReactionResult::AddBonus(double value)
 {
   ActivateReaction();

Modified: branches/energy/source/main/cReactionResult.h
===================================================================
--- branches/energy/source/main/cReactionResult.h	2007-02-20 13:36:25 UTC (rev 1341)
+++ branches/energy/source/main/cReactionResult.h	2007-02-20 14:38:00 UTC (rev 1342)
@@ -38,6 +38,7 @@
   tArray<bool> tasks_done;
   tArray<double> tasks_quality;
   tArray<bool> reactions_triggered;
+  double energy_add;
   double bonus_add;
   double bonus_mult;
   tArray<int> insts_triggered;
@@ -65,6 +66,7 @@
   void MarkTask(int id, const double quality=1);
 
   void MarkReaction(int id);
+  void AddEnergy(double value);
   void AddBonus(double value);
   void MultBonus(double value);
   void AddInst(int id);
@@ -79,6 +81,7 @@
   bool ReactionTriggered(int id);
   bool TaskDone(int id);
   double TaskQuality(int id);
+  double GetAddEnergy() { return energy_add; }
   double GetAddBonus() { return bonus_add; }
   double GetMultBonus() { return bonus_mult; }
   tArray<int>& GetInstArray() { return insts_triggered; }

Modified: branches/energy/source/main/nReaction.h
===================================================================
--- branches/energy/source/main/nReaction.h	2007-02-20 13:36:25 UTC (rev 1341)
+++ branches/energy/source/main/nReaction.h	2007-02-20 14:38:00 UTC (rev 1342)
@@ -30,7 +30,8 @@
     PROCTYPE_ADD = 0,
     PROCTYPE_MULT,
     PROCTYPE_POW,
-    PROCTYPE_LIN
+    PROCTYPE_LIN,
+    PROCTYPE_ENERGY
   };
 }
 




More information about the Avida-cvs mailing list