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

beckma24 at myxo.css.msu.edu beckma24 at myxo.css.msu.edu
Mon Mar 12 08:16:42 PDT 2007


Author: beckma24
Date: 2007-03-12 11:16:42 -0400 (Mon, 12 Mar 2007)
New Revision: 1397

Modified:
   branches/energy/Avida.xcodeproj/project.pbxproj
   branches/energy/source/cpu/cHardwareCPU.cc
   branches/energy/source/cpu/cHardwareCPU.h
   branches/energy/source/main/cAvidaConfig.h
   branches/energy/source/main/cPopulation.cc
Log:
Working energy model.

TODO:
- initial org. does not take NUM_INST_EXE_BEFORE_0_ENERGY into account.
- FIX_METABOLIC_RATE does nothing.
- Does not run correctly with ENERGY_ENABLED = false; moved some statement within a conditional when I was adding FIX_METABOLIC_RATE.

Modified: branches/energy/Avida.xcodeproj/project.pbxproj
===================================================================
--- branches/energy/Avida.xcodeproj/project.pbxproj	2007-03-11 20:04:27 UTC (rev 1396)
+++ branches/energy/Avida.xcodeproj/project.pbxproj	2007-03-12 15:16:42 UTC (rev 1397)
@@ -887,7 +887,7 @@
 		70DCAC77097AF730002F8733 /* key_chart */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text; path = key_chart; sourceTree = "<group>"; };
 		70DCAC78097AF730002F8733 /* viewer.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = viewer.cc; sourceTree = "<group>"; };
 		70DCAC9B097AF7C0002F8733 /* primitive.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = primitive.cc; sourceTree = "<group>"; };
-		70DCAD1C097AF7CC002F8733 /* avida-s */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = "avida-s"; sourceTree = BUILT_PRODUCTS_DIR; };
+		70DCAD1C097AF7CC002F8733 /* avida-s */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = "compiled.mach-o.executable"; path = "avida-s"; sourceTree = BUILT_PRODUCTS_DIR; };
 		70DCAD1F097AF81A002F8733 /* AvidaScript.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = AvidaScript.h; sourceTree = "<group>"; };
 		70DCAD20097AF81A002F8733 /* cLexer.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cLexer.h; sourceTree = "<group>"; };
 		70DCAD21097AF81A002F8733 /* cLexer.l */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.lex; path = cLexer.l; sourceTree = "<group>"; };

Modified: branches/energy/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/energy/source/cpu/cHardwareCPU.cc	2007-03-11 20:04:27 UTC (rev 1396)
+++ branches/energy/source/cpu/cHardwareCPU.cc	2007-03-12 15:16:42 UTC (rev 1397)
@@ -325,7 +325,9 @@
     tInstLibEntry<tMethod>("kazi",	&cHardwareCPU::Inst_Kazi),
     tInstLibEntry<tMethod>("kazi5", &cHardwareCPU::Inst_Kazi5),
     tInstLibEntry<tMethod>("die", &cHardwareCPU::Inst_Die),
-	    
+    
+    tInstLibEntry<tMethod>("sleep", &cHardwareCPU::Inst_Sleep),
+    
     // Placebo instructions
     tInstLibEntry<tMethod>("skip", &cHardwareCPU::Inst_Skip)
   };
@@ -351,6 +353,7 @@
 
 cHardwareCPU::cHardwareCPU(cWorld* world, cOrganism* in_organism, cInstSet* in_m_inst_set)
 : cHardwareBase(world, in_organism, in_m_inst_set)
+, sleep(0)
 {
   /* FIXME:  reorganize storage of m_functions.  -- kgn */
   m_functions = s_inst_slib->GetFunctions();
@@ -376,6 +379,7 @@
 , inst_ft_cost(hardware_cpu.inst_ft_cost)
 , inst_energy_cost(hardware_cpu.inst_energy_cost)
 #endif
+, sleep(0)
 {
 }
 
@@ -3600,6 +3604,12 @@
 return true; 
 }
 
+bool cHardwareCPU::Inst_Sleep(cAvidaContext& ctx) {
+  sleep++;
+  return true;
+}
+
+
 //// Placebo insts ////
 bool cHardwareCPU::Inst_Skip(cAvidaContext& ctx)
 {

Modified: branches/energy/source/cpu/cHardwareCPU.h
===================================================================
--- branches/energy/source/cpu/cHardwareCPU.h	2007-03-11 20:04:27 UTC (rev 1396)
+++ branches/energy/source/cpu/cHardwareCPU.h	2007-03-12 15:16:42 UTC (rev 1397)
@@ -144,6 +144,8 @@
   tArray<int> inst_ft_cost;
   tArray<int> inst_energy_cost;
 #endif
+
+  int sleep;
   
   
   bool SingleProcess_PayCosts(cAvidaContext& ctx, const cInstruction& cur_inst);
@@ -515,6 +517,7 @@
   bool Inst_HeadDivide0_01(cAvidaContext& ctx);
   bool Inst_HeadDivide0_001(cAvidaContext& ctx);
 
+  bool Inst_Sleep(cAvidaContext& ctx);
   //// Placebo ////
   bool Inst_Skip(cAvidaContext& ctx);
 };

Modified: branches/energy/source/main/cAvidaConfig.h
===================================================================
--- branches/energy/source/main/cAvidaConfig.h	2007-03-11 20:04:27 UTC (rev 1396)
+++ branches/energy/source/main/cAvidaConfig.h	2007-03-12 15:16:42 UTC (rev 1397)
@@ -321,13 +321,15 @@
   CONFIG_ADD_VAR(ANALYZE_OPTION_2, cString, "", "String variable accessible from analysis scripts");
   
   CONFIG_ADD_GROUP(ENERGY_GROUP, "Energy Settings");
-  CONFIG_ADD_VAR(ENERGY_ENABLED, bool, false, "Enable Energy Model");
+  CONFIG_ADD_VAR(ENERGY_ENABLED, bool, 0, "Enable Energy Model. 0/1 (off/on)");
   CONFIG_ADD_VAR(ENERGY_GIVEN_ON_INJECT, int, 0, "Energy given to organism upon injection.");
   CONFIG_ADD_VAR(FRAC_ENERGY_GIVEN, double, 0.5, "Fraction of energy given to offspring.");
   CONFIG_ADD_VAR(ENERGY_GIVEN_AT_BIRTH, int, 0, "Energy given to offspring upon birth.");
   CONFIG_ADD_VAR(NUM_INST_EXC_BEFORE_0_ENERGY, int, 0, "Number of instructions executed before energy is exhausted.");
-//  CONFIG_ADD_VAR(FIX_METABOLIC_RATE, bool, false, "When activated the metabolic rate of all orgiansims are equal"); // TODO - check for correctness
+  CONFIG_ADD_VAR(FIX_METABOLIC_RATE, bool, 0, "When activated the metabolic rate of all orgiansims are equal. 0/1 (off/on)"); // TODO - check for correctness
+  CONFIG_ADD_VAR(ENERGY_VERBOSE, bool, 0, "Print energy and merit values. 0/1 (off/on)");
 
+
 #endif
   
   void Load(const cString& filename, const bool& crash_if_not_found);

Modified: branches/energy/source/main/cPopulation.cc
===================================================================
--- branches/energy/source/main/cPopulation.cc	2007-03-11 20:04:27 UTC (rev 1396)
+++ branches/energy/source/main/cPopulation.cc	2007-03-12 15:16:42 UTC (rev 1397)
@@ -347,12 +347,13 @@
       
       parent_phenotype.ReduceEnergy(child_energy - init_energy_given);  // trying to avoid floating point error
 
-      if(m_world->GetConfig().FIX_METABOLIC_RATE.Get()) {
-        merit_array[i] = parent_phenotype.GetMerit();
-      } else {
+//      if(m_world->GetConfig().FIX_METABOLIC_RATE.Get()) {  //TODO check correctness
+//        merit_array[i] = parent_phenotype.GetMerit();
+//      } else {
         merit_array[i] = 100 * child_energy / (inst_2_exc);
-      }
-      cerr<<"child merit: "<<merit_array[i]<<endl<<"child energy: "<< child_energy <<endl;
+      //}
+      if(m_world->GetConfig().ENERGY_VERBOSE.Get())
+        cerr<<"child merit: "<<merit_array[i]<<endl<<"child energy: "<< child_energy <<endl;
     }
 
     child_array[i]->GetPhenotype().SetMerit(merit_array[i]);
@@ -368,11 +369,12 @@
   if(m_world->GetConfig().ENERGY_ENABLED.Get()) {
     parent_phenotype.ReduceEnergy(-1.0*init_energy_given);
     
-    if(!(m_world->GetConfig().FIX_METABOLIC_RATE.Get())) {
+//    if(!(m_world->GetConfig().FIX_METABOLIC_RATE.Get())) {
       cMerit parentMerit = cMerit(100 * parent_phenotype.GetStoredEnergy()/(inst_2_exc));
       parent_phenotype.SetMerit(parentMerit);
-    }
-    cerr<<"parent merit: "<<parent_phenotype.GetMerit()<<endl<<"parent energy: "<< parent_phenotype.GetStoredEnergy() <<endl;
+//    }
+    if(m_world->GetConfig().ENERGY_VERBOSE.Get())
+      cout<<"parent merit: "<<parent_phenotype.GetMerit()<<endl<<"parent energy: "<< parent_phenotype.GetStoredEnergy() <<endl;
   }
   
   // If we're not about to kill the parent, do some extra work on it.
@@ -2247,7 +2249,7 @@
   // BB - Don't need to fix metabolic rate here, only on birth
   phenotype.SetMerit( cMerit(new_genotype->GetTestMerit(ctx)) );
   
-  cerr<<"initial energy: " <<initial_energy<<endl<<"initial Merit: "<<phenotype.GetMerit().GetDouble()<<endl;
+  cerr<<"initial energy: " << phenotype.GetStoredEnergy() <<endl<<"initial Merit: "<<phenotype.GetMerit().GetDouble()<<endl;
   
   // @CAO are these really needed?
   phenotype.SetLinesCopied( new_genotype->GetTestCopiedSize(ctx) );




More information about the Avida-cvs mailing list