[Avida-SVN] r1476 - in development/source: . actions cpu main

jclune at myxo.css.msu.edu jclune at myxo.css.msu.edu
Tue Apr 17 01:16:55 PDT 2007


Author: jclune
Date: 2007-04-17 04:16:55 -0400 (Tue, 17 Apr 2007)
New Revision: 1476

Modified:
   development/source/actions/EnvironmentActions.cc
   development/source/actions/PopulationActions.cc
   development/source/cpu/cHardwareCPU.cc
   development/source/defs.h
   development/source/main/cAvidaConfig.h
   development/source/main/cPhenotype.cc
   development/source/main/cPhenotype.h
   development/source/main/cPopulation.cc
Log:
In avida.cfg, when BASE_MERIT_METHOD is set to 6 (Merit prop. to num times MERIT_BONUS_INST is in genome), the merit is incremented by MERIT_BONUS_EFFECT if MERIT_BONUS_EFFECT is positive and decremented by MERIT_BONUS_EFFECT if it is negative. For positive values the counting starts at 1, for negative values it starts  at genome length. The event ToggleRewardInstruction toggles MERIT_BONUS_EFFECT from positive to negative. This creates an extremely simple
 counting-ones type of dynamic environment. 


Modified: development/source/actions/EnvironmentActions.cc
===================================================================
--- development/source/actions/EnvironmentActions.cc	2007-04-14 15:31:34 UTC (rev 1475)
+++ development/source/actions/EnvironmentActions.cc	2007-04-17 08:16:55 UTC (rev 1476)
@@ -384,4 +384,5 @@
   action_lib->Register<cActionSetReactionValue>("set_reaction_value");
   action_lib->Register<cActionSetReactionValueMult>("set_reaction_value_mult");
   action_lib->Register<cActionSetReactionInst>("set_reaction_inst");
+  
 }

Modified: development/source/actions/PopulationActions.cc
===================================================================
--- development/source/actions/PopulationActions.cc	2007-04-14 15:31:34 UTC (rev 1475)
+++ development/source/actions/PopulationActions.cc	2007-04-17 08:16:55 UTC (rev 1476)
@@ -438,7 +438,33 @@
   }
 };
 
+/*
+ In avida.cfg, when BASE_MERIT_METHOD is set to 6 (Merit prop. to num times MERIT_BONUS_INST is in genome), 
+ the merit is incremented by MERIT_BONUS_EFFECT if MERIT_BONUS_EFFECT is positive and decremented by
+ MERIT_BONUS_EFFECT if it is negative. For positive values the counting starts at 1, for negative values it starts
+ at genome length. This event toggles MERIT_BONUS_EFFECT from positive to negative. This creates an extremely simple
+ counting-ones type of dynamic environment.  
+*/
+class cActionToggleRewardInstruction : public cAction
+{
+private:
+  double m_killprob;
+public:
+  cActionToggleRewardInstruction(cWorld* world, const cString& args) : cAction(world, args), m_killprob(0.9)
+  {
+    //pass
+    //@JMC: m_killprob is meme that hitchiked when I used gabe's event as an example. need to clean it up. 
+  }
+  
+  static const cString GetDescription() { return "Arguments: [double probability=0.9]"; }
+  
+  void Process(cAvidaContext& ctx)
+  {
+    m_world->GetConfig().MERIT_BONUS_EFFECT.Set(-1* m_world->GetConfig().MERIT_BONUS_EFFECT.Get());
+  }
+};
 
+
 /*
  Randomly removes a certain proportion of the population.
  In principle, this event does the same thing as the KillProb action.
@@ -1293,6 +1319,7 @@
   action_lib->Register<cActionInjectParasitePair>("InjectParasitePair");
 
   action_lib->Register<cActionKillProb>("KillProb");
+  action_lib->Register<cActionToggleRewardInstruction>("ToggleRewardInstruction");
   action_lib->Register<cActionKillProb>("KillRate");
   action_lib->Register<cActionKillRectangle>("KillRectangle");
   action_lib->Register<cActionSerialTransfer>("SerialTransfer");

Modified: development/source/cpu/cHardwareCPU.cc
===================================================================
--- development/source/cpu/cHardwareCPU.cc	2007-04-14 15:31:34 UTC (rev 1475)
+++ development/source/cpu/cHardwareCPU.cc	2007-04-17 08:16:55 UTC (rev 1476)
@@ -286,7 +286,7 @@
     
     // High-level instructions
     tInstLibEntry<tMethod>("repro", &cHardwareCPU::Inst_Repro),
-    tInstLibEntry<tMethod>("repro-A", &cHardwareCPU::Inst_Repro),
+    tInstLibEntry<tMethod>("  ", &cHardwareCPU::Inst_Repro),
     tInstLibEntry<tMethod>("repro-B", &cHardwareCPU::Inst_Repro),
     tInstLibEntry<tMethod>("repro-C", &cHardwareCPU::Inst_Repro),
     tInstLibEntry<tMethod>("repro-D", &cHardwareCPU::Inst_Repro),

Modified: development/source/defs.h
===================================================================
--- development/source/defs.h	2007-04-14 15:31:34 UTC (rev 1475)
+++ development/source/defs.h	2007-04-17 08:16:55 UTC (rev 1476)
@@ -148,7 +148,8 @@
   BASE_MERIT_EXE_SIZE,
   BASE_MERIT_FULL_SIZE,
   BASE_MERIT_LEAST_SIZE,
-  BASE_MERIT_SQRT_LEAST_SIZE
+  BASE_MERIT_SQRT_LEAST_SIZE,
+  BASE_MERIT_NUM_BONUS_INST
 };
 
 typedef enum eVerbosity {

Modified: development/source/main/cAvidaConfig.h
===================================================================
--- development/source/main/cAvidaConfig.h	2007-04-14 15:31:34 UTC (rev 1475)
+++ development/source/main/cAvidaConfig.h	2007-04-17 08:16:55 UTC (rev 1476)
@@ -271,10 +271,12 @@
   CONFIG_ADD_GROUP(TIME_GROUP, "Time Slicing");
   CONFIG_ADD_VAR(AVE_TIME_SLICE, int, 30, "Ave number of insts per org per update");
   CONFIG_ADD_VAR(SLICING_METHOD, int, 1, "0 = CONSTANT: all organisms get default...\n1 = PROBABILISTIC: Run _prob_ proportional to merit.\n2 = INTEGRATED: Perfectly integrated deterministic.");
-  CONFIG_ADD_VAR(BASE_MERIT_METHOD, int, 4, "0 = Constant (merit independent of size)\n1 = Merit proportional to copied size\n2 = Merit prop. to executed size\n3 = Merit prop. to full size\n4 = Merit prop. to min of executed or copied size\n5 = Merit prop. to sqrt of the minimum size");
+  CONFIG_ADD_VAR(BASE_MERIT_METHOD, int, 4, "0 = Constant (merit independent of size)\n1 = Merit proportional to copied size\n2 = Merit prop. to executed size\n3 = Merit prop. to full size\n4 = Merit prop. to min of executed or copied size\n5 = Merit prop. to sqrt of the minimum size\n6 = Merit prop. to num times MERIT_BONUS_INST is in genome.");
   CONFIG_ADD_VAR(BASE_CONST_MERIT, int, 100, "Base merit when BASE_MERIT_METHOD set to 0");
   CONFIG_ADD_VAR(DEFAULT_BONUS, double, 1.0, "Initial bonus before any tasks");
   CONFIG_ADD_VAR(MERIT_DEFAULT_BONUS, int, 0, "Scale the merit of an offspring by the default bonus\nrather than the accumulated bonus of the parent?"); 
+  CONFIG_ADD_VAR(MERIT_BONUS_INST, int, 0, "in BASE_MERIT_METHOD 6, this sets which instruction counts (-1=none, 0= 1st in INST_SET.)"); 
+  CONFIG_ADD_VAR(MERIT_BONUS_EFFECT, int, 0, "in BASE_MERIT_METHOD 6, this sets how much merit is earned per INST (-1=penalty, 0= no effect.)"); 
   CONFIG_ADD_VAR(MAX_CPU_THREADS, int, 1, "Number of Threads a CPU can spawn");
   CONFIG_ADD_VAR(THREAD_SLICING_METHOD, int, 0, "Formula for and organism's thread slicing\n  (num_threads-1) * THREAD_SLICING_METHOD + 1\n0 = One thread executed per time slice.\n1 = All threads executed each time slice.\n");
   CONFIG_ADD_VAR(MAX_LABEL_EXE_SIZE, int, 1, "Max nops marked as executed when labels are used");

Modified: development/source/main/cPhenotype.cc
===================================================================
--- development/source/main/cPhenotype.cc	2007-04-14 15:31:34 UTC (rev 1475)
+++ development/source/main/cPhenotype.cc	2007-04-17 08:16:55 UTC (rev 1476)
@@ -846,6 +846,11 @@
     if (out_size > executed_size)    out_size = executed_size;
     out_size = (int) sqrt((double) out_size);
     break;
+  case BASE_MERIT_NUM_BONUS_INST:
+    if (m_world->GetConfig().MERIT_BONUS_EFFECT.Get()>0) {out_size = 1 + bonus_instruction_count;}
+    else if (m_world->GetConfig().MERIT_BONUS_EFFECT.Get()<0) {out_size = genome_length - (bonus_instruction_count -1);}
+    else {out_size = 1;}  //the extra 1 point in all these case is so the orgs are not jilted by the scheduler
+    break;   
   case BASE_MERIT_CONST:
   default:
     out_size = m_world->GetConfig().BASE_CONST_MERIT.Get();

Modified: development/source/main/cPhenotype.h
===================================================================
--- development/source/main/cPhenotype.h	2007-04-14 15:31:34 UTC (rev 1475)
+++ development/source/main/cPhenotype.h	2007-04-17 08:16:55 UTC (rev 1476)
@@ -91,6 +91,7 @@
   // 1. These are values calculated at the last divide (of self or offspring)
   cMerit merit;             // Relative speed of CPU
   int genome_length;        // Number of instructions in genome.
+  int bonus_instruction_count; // Number of times MERIT_BONUS_INT is in genome.
   int copied_size;          // Instructions copied into genome.
   int executed_size;        // Instructions executed from genome.
   int gestation_time;       // CPU cycles to produce offspring (or be produced),
@@ -227,6 +228,8 @@
   double GetDivType() const { assert(initialized == true); return div_type; }
 
   double GetCurBonus() const { assert(initialized == true); return cur_bonus; }
+  int    GetCurBonusInstCount() const { assert(bonus_instruction_count >= 0); return bonus_instruction_count; }
+
   double GetCurMeritBase() const { assert(initialized == true); return CalcSizeMerit(); }
   bool GetToDie() const { assert(initialized == true); return to_die; }
   bool GetToDelete() const { assert(initialized == true); return to_delete; }
@@ -244,6 +247,7 @@
 
   double GetLastMeritBase() const { assert(initialized == true); return last_merit_base; }
   double GetLastBonus() const { assert(initialized == true); return last_bonus; }
+
   const double GetLastMerit() const { assert(initialized == true); return last_merit_base*last_bonus; }
   int GetLastNumErrors() const { assert(initialized == true); return last_num_errors; }
   int GetLastNumDonates() const { assert(initialized == true); return last_num_donates; }
@@ -306,6 +310,7 @@
   void SetIsReceiver() { is_receiver = true; } 
   
   void SetCurBonus(double _bonus) { cur_bonus = _bonus; }
+  void SetCurBonusInstCount(int _num_bonus_inst) {bonus_instruction_count = _num_bonus_inst;}
 
   void IncCurInstCount(int _inst_num)  { assert(initialized == true); cur_inst_count[_inst_num]++; } 
   void DecCurInstCount(int _inst_num)  { assert(initialized == true); cur_inst_count[_inst_num]--; } 

Modified: development/source/main/cPopulation.cc
===================================================================
--- development/source/main/cPopulation.cc	2007-04-14 15:31:34 UTC (rev 1475)
+++ development/source/main/cPopulation.cc	2007-04-17 08:16:55 UTC (rev 1476)
@@ -475,6 +475,26 @@
   // Statistics...
   m_world->GetStats().RecordBirth(target_cell.GetID(), in_genotype->GetID(),
                                   in_organism->GetPhenotype().ParentTrue());
+                                  
+  //count how many times MERIT_BONUS_INST (rewarded instruction) is in the genome
+  //only relevant if merit is proportional to # times MERIT_BONUS_INST is in the genome
+  int rewarded_instruction = m_world->GetConfig().MERIT_BONUS_INST.Get();
+  int num_rewarded_instructions = 0;
+  int genome_length = in_organism->GetGenome().GetSize();
+
+  if(rewarded_instruction == -1){
+    //no key instruction, so no bonus 
+    in_organism->GetPhenotype().SetCurBonusInstCount(0);
+    }
+  else{
+    for(int i = 1; i <= genome_length; i++){
+      if(in_organism->GetGenome()[i-1].GetOp() == rewarded_instruction){
+          num_rewarded_instructions++;
+      }  
+    } 
+     in_organism->GetPhenotype().SetCurBonusInstCount(num_rewarded_instructions);
+  }
+  
 }
 
 void cPopulation::KillOrganism(cPopulationCell& in_cell)




More information about the Avida-cvs mailing list