[Avida-SVN] r3586 - in branches/matt/InheritInstSet: Avida.xcodeproj source/cpu source/main

ruppmatt at myxo.css.msu.edu ruppmatt at myxo.css.msu.edu
Tue Jan 5 14:44:05 PST 2010


Author: ruppmatt
Date: 2010-01-05 17:44:03 -0500 (Tue, 05 Jan 2010)
New Revision: 3586

Modified:
   branches/matt/InheritInstSet/Avida.xcodeproj/project.pbxproj
   branches/matt/InheritInstSet/source/cpu/cHardwareBase.cc
   branches/matt/InheritInstSet/source/cpu/cHardwareCPU.cc
   branches/matt/InheritInstSet/source/cpu/cHardwareCPU.h
   branches/matt/InheritInstSet/source/cpu/cHardwareExperimental.cc
   branches/matt/InheritInstSet/source/cpu/cHardwareExperimental.h
   branches/matt/InheritInstSet/source/cpu/cHardwareGX.cc
   branches/matt/InheritInstSet/source/cpu/cHardwareGX.h
   branches/matt/InheritInstSet/source/cpu/cHardwareManager.cc
   branches/matt/InheritInstSet/source/cpu/cHardwareManager.h
   branches/matt/InheritInstSet/source/cpu/cHardwareSMT.cc
   branches/matt/InheritInstSet/source/cpu/cHardwareSMT.h
   branches/matt/InheritInstSet/source/cpu/cHardwareTransSMT.cc
   branches/matt/InheritInstSet/source/cpu/cHardwareTransSMT.h
   branches/matt/InheritInstSet/source/cpu/cInstSet.h
   branches/matt/InheritInstSet/source/main/cBirthChamber.cc
   branches/matt/InheritInstSet/source/main/cBirthChamber.h
   branches/matt/InheritInstSet/source/main/cInheritedInstSet.cc
   branches/matt/InheritInstSet/source/main/cInheritedInstSet.h
   branches/matt/InheritInstSet/source/main/cOrganism.cc
   branches/matt/InheritInstSet/source/main/cOrganism.h
Log:
Done with initial implementation of inherited instruction sets.  Memory management seems OK.

Modified: branches/matt/InheritInstSet/Avida.xcodeproj/project.pbxproj
===================================================================
--- branches/matt/InheritInstSet/Avida.xcodeproj/project.pbxproj	2010-01-05 20:47:29 UTC (rev 3585)
+++ branches/matt/InheritInstSet/Avida.xcodeproj/project.pbxproj	2010-01-05 22:44:03 UTC (rev 3586)
@@ -176,7 +176,6 @@
 		70DCAC9C097AF7C0002F8733 /* primitive.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70DCAC9B097AF7C0002F8733 /* primitive.cc */; };
 		B4480DDF10F3DE4E00FC179B /* cInheritedInstSet.cc in Sources */ = {isa = PBXBuildFile; fileRef = B4480DDE10F3DE4E00FC179B /* cInheritedInstSet.cc */; };
 		B4DA5DBE10F289170052C0A5 /* cInheritedInstSet.h in Headers */ = {isa = PBXBuildFile; fileRef = B4DA5DBC10F289170052C0A5 /* cInheritedInstSet.h */; };
-		B4DA5DBF10F289170052C0A5 /* cInheritedInstSet.cpp in Sources */ = {isa = PBXBuildFile; fileRef = B4DA5DBD10F289170052C0A5 /* cInheritedInstSet.cpp */; };
 		B4FA258A0C5EB65E0086D4B5 /* cPlasticPhenotype.cc in Sources */ = {isa = PBXBuildFile; fileRef = B4FA25810C5EB6510086D4B5 /* cPlasticPhenotype.cc */; };
 		B4FA25A90C5EB7880086D4B5 /* cPhenPlastGenotype.cc in Sources */ = {isa = PBXBuildFile; fileRef = B4FA259E0C5EB7600086D4B5 /* cPhenPlastGenotype.cc */; };
 		B516AF840C91E2D400023D53 /* cDemeCellEvent.cc in Sources */ = {isa = PBXBuildFile; fileRef = B516AF790C91E24600023D53 /* cDemeCellEvent.cc */; };
@@ -718,7 +717,6 @@
 		70FB86A908BFAFEC00BDF589 /* CMakeLists.txt */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text; path = CMakeLists.txt; sourceTree = "<group>"; };
 		B4480DDE10F3DE4E00FC179B /* cInheritedInstSet.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = cInheritedInstSet.cc; sourceTree = "<group>"; };
 		B4DA5DBC10F289170052C0A5 /* cInheritedInstSet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = cInheritedInstSet.h; sourceTree = "<group>"; };
-		B4DA5DBD10F289170052C0A5 /* cInheritedInstSet.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = cInheritedInstSet.cpp; path = source/main/cInheritedInstSet.cpp; sourceTree = SOURCE_ROOT; };
 		B4FA25800C5EB6510086D4B5 /* cPhenPlastGenotype.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cPhenPlastGenotype.h; sourceTree = "<group>"; };
 		B4FA25810C5EB6510086D4B5 /* cPlasticPhenotype.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = cPlasticPhenotype.cc; sourceTree = "<group>"; };
 		B4FA25820C5EB6510086D4B5 /* cPlasticPhenotype.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cPlasticPhenotype.h; sourceTree = "<group>"; };
@@ -1145,7 +1143,6 @@
 		DCC30F7C0762539D008F7A48 /* cpu */ = {
 			isa = PBXGroup;
 			children = (
-				B4DA5DBD10F289170052C0A5 /* cInheritedInstSet.cpp */,
 				705261050B87AF5C0007426F /* cInstLib.h */,
 				706C703E0B83FB95003174C1 /* tInstLibEntry.h */,
 				706C6FFE0B83F265003174C1 /* cInstSet.cc */,
@@ -1739,7 +1736,6 @@
 				B4FA258A0C5EB65E0086D4B5 /* cPlasticPhenotype.cc in Sources */,
 				B4FA25A90C5EB7880086D4B5 /* cPhenPlastGenotype.cc in Sources */,
 				B516AF840C91E2D400023D53 /* cDemeCellEvent.cc in Sources */,
-				B4DA5DBF10F289170052C0A5 /* cInheritedInstSet.cpp in Sources */,
 				B4480DDF10F3DE4E00FC179B /* cInheritedInstSet.cc in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;

Modified: branches/matt/InheritInstSet/source/cpu/cHardwareBase.cc
===================================================================
--- branches/matt/InheritInstSet/source/cpu/cHardwareBase.cc	2010-01-05 20:47:29 UTC (rev 3585)
+++ branches/matt/InheritInstSet/source/cpu/cHardwareBase.cc	2010-01-05 22:44:03 UTC (rev 3586)
@@ -47,10 +47,10 @@
 
 #include "functions.h"
 
-
 cHardwareBase::~cHardwareBase(){
-  if (m_inherited_instset)
+  if (m_inherited_instset){
     delete m_inst_set;
+  }
 }
 
 
@@ -382,6 +382,16 @@
 //    }
 //  }
   
+  //@MRR Inherited Instruction Set Mutations
+  if (m_inherited_instset){
+    double per_inst = m_world->GetConfig().EIS_MUT_RED_PERINST.Get();
+    double single_in_set = m_world->GetConfig().EIS_MUT_RED_PERSET.Get();
+    if (per_inst > 0)
+      static_cast<cInheritedInstSet*>(m_inst_set)->MutateAllInsts(per_inst);
+    if (single_in_set > 0)
+      static_cast<cInheritedInstSet*>(m_inst_set)->MutateSingleInst(single_in_set);
+  }
+  
   return totalMutations;
 }
 

Modified: branches/matt/InheritInstSet/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/matt/InheritInstSet/source/cpu/cHardwareCPU.cc	2010-01-05 20:47:29 UTC (rev 3585)
+++ branches/matt/InheritInstSet/source/cpu/cHardwareCPU.cc	2010-01-05 22:44:03 UTC (rev 3586)
@@ -399,8 +399,8 @@
   return new tInstLib<tMethod>(f_size, s_f_array, n_names, nop_mods, functions, error, def, null_inst);
 }
 
-cHardwareCPU::cHardwareCPU(cWorld* world, cOrganism* in_organism, cInstSet* in_m_inst_set)
-: cHardwareBase(world, in_organism, in_m_inst_set)
+cHardwareCPU::cHardwareCPU(cWorld* world, cOrganism* in_organism, cInstSet* in_m_inst_set, bool inherited_instset)
+: cHardwareBase(world, in_organism, in_m_inst_set, inherited_instset)
 {
   /* FIXME:  reorganize storage of m_functions.  -- kgn */
   m_functions = s_inst_slib->GetFunctions();

Modified: branches/matt/InheritInstSet/source/cpu/cHardwareCPU.h
===================================================================
--- branches/matt/InheritInstSet/source/cpu/cHardwareCPU.h	2010-01-05 20:47:29 UTC (rev 3585)
+++ branches/matt/InheritInstSet/source/cpu/cHardwareCPU.h	2010-01-05 22:44:03 UTC (rev 3586)
@@ -223,9 +223,9 @@
   cHardwareCPU& operator=(const cHardwareCPU&); // @not_implemented
 
 public:
-  cHardwareCPU(cWorld* world, cOrganism* in_organism, cInstSet* in_inst_set);
+  cHardwareCPU(cWorld* world, cOrganism* in_organism, cInstSet* in_inst_set, bool inherited_instset);
   explicit cHardwareCPU(const cHardwareCPU&);
-  ~cHardwareCPU() { ; }
+  virtual ~cHardwareCPU() { ; }
   static tInstLib<tMethod>* GetInstLib() { return s_inst_slib; }
   static cString GetDefaultInstFilename() { return "instset-classic.cfg"; }
 

Modified: branches/matt/InheritInstSet/source/cpu/cHardwareExperimental.cc
===================================================================
--- branches/matt/InheritInstSet/source/cpu/cHardwareExperimental.cc	2010-01-05 20:47:29 UTC (rev 3585)
+++ branches/matt/InheritInstSet/source/cpu/cHardwareExperimental.cc	2010-01-05 22:44:03 UTC (rev 3586)
@@ -143,8 +143,8 @@
   return new tInstLib<tMethod>(f_size, s_f_array, n_names, nop_mods, functions, error, def, null_inst);
 }
 
-cHardwareExperimental::cHardwareExperimental(cWorld* world, cOrganism* in_organism, cInstSet* in_m_inst_set)
-: cHardwareBase(world, in_organism, in_m_inst_set)
+cHardwareExperimental::cHardwareExperimental(cWorld* world, cOrganism* in_organism, cInstSet* in_m_inst_set, bool inherited_instset)
+: cHardwareBase(world, in_organism, in_m_inst_set, inherited_instset)
 {
   /* FIXME:  reorganize storage of m_functions.  -- kgn */
   m_functions = s_inst_slib->GetFunctions();

Modified: branches/matt/InheritInstSet/source/cpu/cHardwareExperimental.h
===================================================================
--- branches/matt/InheritInstSet/source/cpu/cHardwareExperimental.h	2010-01-05 20:47:29 UTC (rev 3585)
+++ branches/matt/InheritInstSet/source/cpu/cHardwareExperimental.h	2010-01-05 22:44:03 UTC (rev 3586)
@@ -193,9 +193,9 @@
   cHardwareExperimental& operator=(const cHardwareExperimental&); // @not_implemented
 
 public:
-  cHardwareExperimental(cWorld* world, cOrganism* in_organism, cInstSet* in_inst_set);
+  cHardwareExperimental(cWorld* world, cOrganism* in_organism, cInstSet* in_inst_set, bool inherited_instset);
   explicit cHardwareExperimental(const cHardwareExperimental&);
-  ~cHardwareExperimental() { ; }
+  virtual ~cHardwareExperimental() { ; }
   static tInstLib<cHardwareExperimental::tMethod>* GetInstLib() { return s_inst_slib; }
   static cString GetDefaultInstFilename() { return "instset-experimental.cfg"; }
 

Modified: branches/matt/InheritInstSet/source/cpu/cHardwareGX.cc
===================================================================
--- branches/matt/InheritInstSet/source/cpu/cHardwareGX.cc	2010-01-05 20:47:29 UTC (rev 3585)
+++ branches/matt/InheritInstSet/source/cpu/cHardwareGX.cc	2010-01-05 22:44:03 UTC (rev 3586)
@@ -312,8 +312,8 @@
 /*! Construct a cHardwareGX instance from the passed-in cOrganism.  This amounts to
 creating an initial cProgramid from in_organism's genome.
 */
-cHardwareGX::cHardwareGX(cWorld* world, cOrganism* in_organism, cInstSet* in_m_inst_set)
-: cHardwareBase(world, in_organism, in_m_inst_set)
+cHardwareGX::cHardwareGX(cWorld* world, cOrganism* in_organism, cInstSet* in_m_inst_set, bool inherited_instset)
+: cHardwareBase(world, in_organism, in_m_inst_set, inherited_instset)
 {
   m_last_unique_id_assigned = 0;
   m_functions = s_inst_slib->GetFunctions();

Modified: branches/matt/InheritInstSet/source/cpu/cHardwareGX.h
===================================================================
--- branches/matt/InheritInstSet/source/cpu/cHardwareGX.h	2010-01-05 20:47:29 UTC (rev 3585)
+++ branches/matt/InheritInstSet/source/cpu/cHardwareGX.h	2010-01-05 22:44:03 UTC (rev 3586)
@@ -303,7 +303,7 @@
 
 public:
   //! Main constructor for cHardwareGX; called from cHardwareManager for every organism.
-  cHardwareGX(cWorld* world, cOrganism* in_organism, cInstSet* in_inst_set);
+  cHardwareGX(cWorld* world, cOrganism* in_organism, cInstSet* in_inst_set, bool inherited_instset);
   virtual ~cHardwareGX(); //!< Destructor; removes all cProgramids.
     
   static tInstLib<tMethod>* GetInstLib() { return s_inst_slib; }

Modified: branches/matt/InheritInstSet/source/cpu/cHardwareManager.cc
===================================================================
--- branches/matt/InheritInstSet/source/cpu/cHardwareManager.cc	2010-01-05 20:47:29 UTC (rev 3585)
+++ branches/matt/InheritInstSet/source/cpu/cHardwareManager.cc	2010-01-05 22:44:03 UTC (rev 3586)
@@ -172,7 +172,7 @@
 }
                           
 
-cHardwareBase* cHardwareManager::Create(cOrganism* in_org, cOrganism* parent_org)
+cHardwareBase* cHardwareManager::Create(cOrganism* in_org, const cInstSet* parent_instset)
 {
   assert(in_org != NULL);
   
@@ -180,21 +180,21 @@
   assert(inst_id <= m_inst_sets.GetSize()-1 && m_inst_sets[inst_id] != NULL);
 
   cInstSet* this_instset = (!m_inherited_instset) ? m_inst_sets[inst_id] :
-              (parent_org == NULL) ? new cInheritedInstSet(m_inst_sets[inst_id], m_init_redundancy, m_allowed_redundancies) :
-                                     new cInheritedInstSet(static_cast<cInheritedInstSet*>(parent_org->GetHardware().GetInstSetPtr()));
+              (parent_instset == NULL) ? new cInheritedInstSet(m_inst_sets[inst_id], m_init_redundancy, m_allowed_redundancies) :
+                                     new cInheritedInstSet(parent_instset, m_allowed_redundancies);
   
   switch (m_type)
   {
     case HARDWARE_TYPE_CPU_ORIGINAL:
-      return new cHardwareCPU(m_world, in_org, this_instset);
+      return new cHardwareCPU(m_world, in_org, this_instset, m_inherited_instset);
     case HARDWARE_TYPE_CPU_SMT:
-      return new  cHardwareSMT(m_world, in_org, this_instset);
+      return new  cHardwareSMT(m_world, in_org, this_instset, m_inherited_instset);
     case HARDWARE_TYPE_CPU_TRANSSMT:
-      return  new cHardwareTransSMT(m_world, in_org, this_instset);
+      return  new cHardwareTransSMT(m_world, in_org, this_instset, m_inherited_instset);
     case HARDWARE_TYPE_CPU_EXPERIMENTAL:
-      return new cHardwareExperimental(m_world, in_org, this_instset);
+      return new cHardwareExperimental(m_world, in_org, this_instset, m_inherited_instset);
     case HARDWARE_TYPE_CPU_GX:
-      return new cHardwareGX(m_world, in_org, this_instset);
+      return new cHardwareGX(m_world, in_org, this_instset, m_inherited_instset);
     default:
       return NULL;
   }

Modified: branches/matt/InheritInstSet/source/cpu/cHardwareManager.h
===================================================================
--- branches/matt/InheritInstSet/source/cpu/cHardwareManager.h	2010-01-05 20:47:29 UTC (rev 3585)
+++ branches/matt/InheritInstSet/source/cpu/cHardwareManager.h	2010-01-05 22:44:03 UTC (rev 3586)
@@ -81,7 +81,7 @@
   cHardwareManager(cWorld* world);
   ~cHardwareManager() { for(int i = 0; i < m_inst_sets.GetSize(); i++) delete m_inst_sets[i]; }
   
-  cHardwareBase* Create(cOrganism* in_org, cOrganism* parent_org = NULL);
+  cHardwareBase* Create(cOrganism* in_org, const cInstSet* parent_instset = NULL);
   cTestCPU* CreateTestCPU() { return new cTestCPU(m_world /*, &m_testres*/); }
 
   const cInstSet& GetInstSet(int id=0) const { assert(id < m_inst_sets.GetSize()); return *(m_inst_sets[id]); }

Modified: branches/matt/InheritInstSet/source/cpu/cHardwareSMT.cc
===================================================================
--- branches/matt/InheritInstSet/source/cpu/cHardwareSMT.cc	2010-01-05 20:47:29 UTC (rev 3585)
+++ branches/matt/InheritInstSet/source/cpu/cHardwareSMT.cc	2010-01-05 22:44:03 UTC (rev 3586)
@@ -134,8 +134,8 @@
   return new tInstLib<tMethod>(f_size, s_f_array, n_names, nop_mods, functions, error, def, null_inst);
 }
 
-cHardwareSMT::cHardwareSMT(cWorld* world, cOrganism* in_organism, cInstSet* in_m_inst_set)
-: cHardwareBase(world, in_organism, in_m_inst_set), m_mem_array(1), m_mem_marks(1)
+cHardwareSMT::cHardwareSMT(cWorld* world, cOrganism* in_organism, cInstSet* in_m_inst_set, bool inherited_instset)
+: cHardwareBase(world, in_organism, in_m_inst_set, inherited_instset), m_mem_array(1), m_mem_marks(1)
 , m_mem_lbls(Pow(NUM_NOPS, MAX_MEMSPACE_LABEL) / MEM_LBLS_HASH_FACTOR)
 , m_thread_lbls(Pow(NUM_NOPS, MAX_THREAD_LABEL) / THREAD_LBLS_HASH_FACTOR)
 {

Modified: branches/matt/InheritInstSet/source/cpu/cHardwareSMT.h
===================================================================
--- branches/matt/InheritInstSet/source/cpu/cHardwareSMT.h	2010-01-05 20:47:29 UTC (rev 3585)
+++ branches/matt/InheritInstSet/source/cpu/cHardwareSMT.h	2010-01-05 22:44:03 UTC (rev 3586)
@@ -196,8 +196,8 @@
   cHardwareSMT& operator=(const cHardwareSMT&); // @not_implemented
   
 public:
-  cHardwareSMT(cWorld* world, cOrganism* in_organism, cInstSet* in_inst_set);
-  ~cHardwareSMT() { ; }
+  cHardwareSMT(cWorld* world, cOrganism* in_organism, cInstSet* in_inst_set, bool inherited_instset);
+  virtual ~cHardwareSMT() { ; }
   static cInstLib* GetInstLib() { return s_inst_slib; }
   static cString GetDefaultInstFilename() { return "instset-smt.cfg"; }
 	

Modified: branches/matt/InheritInstSet/source/cpu/cHardwareTransSMT.cc
===================================================================
--- branches/matt/InheritInstSet/source/cpu/cHardwareTransSMT.cc	2010-01-05 20:47:29 UTC (rev 3585)
+++ branches/matt/InheritInstSet/source/cpu/cHardwareTransSMT.cc	2010-01-05 22:44:03 UTC (rev 3586)
@@ -133,8 +133,8 @@
   return new tInstLib<tMethod>(f_size, s_f_array, n_names, nop_mods, functions, error, def, null_inst);
 }
 
-cHardwareTransSMT::cHardwareTransSMT(cWorld* world, cOrganism* in_organism, cInstSet* in_m_inst_set)
-: cHardwareBase(world, in_organism, in_m_inst_set), m_mem_array(1)
+cHardwareTransSMT::cHardwareTransSMT(cWorld* world, cOrganism* in_organism, cInstSet* in_m_inst_set, bool inherited_instset)
+: cHardwareBase(world, in_organism, in_m_inst_set, inherited_instset), m_mem_array(1)
 , m_mem_lbls(Pow(NUM_NOPS, MAX_MEMSPACE_LABEL) / MEM_LBLS_HASH_FACTOR)
 , m_thread_lbls(Pow(NUM_NOPS, MAX_THREAD_LABEL) / THREAD_LBLS_HASH_FACTOR)
 {

Modified: branches/matt/InheritInstSet/source/cpu/cHardwareTransSMT.h
===================================================================
--- branches/matt/InheritInstSet/source/cpu/cHardwareTransSMT.h	2010-01-05 20:47:29 UTC (rev 3585)
+++ branches/matt/InheritInstSet/source/cpu/cHardwareTransSMT.h	2010-01-05 22:44:03 UTC (rev 3586)
@@ -195,8 +195,8 @@
   cHardwareTransSMT& operator=(const cHardwareTransSMT&); // @not_implemented
   
 public:
-  cHardwareTransSMT(cWorld* world, cOrganism* in_organism, cInstSet* in_inst_set);
-  ~cHardwareTransSMT() { ; }
+  cHardwareTransSMT(cWorld* world, cOrganism* in_organism, cInstSet* in_inst_set, bool inherited_instset);
+  virtual ~cHardwareTransSMT() { ; }
   static cInstLib* GetInstLib() { return s_inst_slib; }
   static cString GetDefaultInstFilename() { return "instset-transsmt.cfg"; }
 	

Modified: branches/matt/InheritInstSet/source/cpu/cInstSet.h
===================================================================
--- branches/matt/InheritInstSet/source/cpu/cInstSet.h	2010-01-05 20:47:29 UTC (rev 3585)
+++ branches/matt/InheritInstSet/source/cpu/cInstSet.h	2010-01-05 22:44:03 UTC (rev 3586)
@@ -87,7 +87,8 @@
 public:
   inline cInstSet(cWorld* world, cInstLib* inst_lib) : m_world(world), m_inst_lib(inst_lib) { ; }
   inline cInstSet(const cInstSet& is);
-  inline ~cInstSet() { ; }
+  inline cInstSet(const cInstSet* is);
+  virtual ~cInstSet() { ; }
   
   inline bool operator==(const cInstSet& _in) const;
   inline cInstSet& operator=(const cInstSet& _in);
@@ -161,6 +162,13 @@
 {
 }
 
+inline cInstSet::cInstSet(const cInstSet* is)
+: m_world(is->m_world), m_inst_lib(is->m_inst_lib), m_lib_name_map(is->m_lib_name_map)
+,m_lib_nopmod_map(is->m_lib_nopmod_map), m_mutation_chart(is->m_mutation_chart)
+{
+}
+
+
 inline cInstSet& cInstSet::operator=(const cInstSet& _in)
 {
   m_inst_lib = _in.m_inst_lib;
@@ -170,6 +178,8 @@
   return *this;
 }
 
+
+
 //@MRR Instruction sets are equivalent if their mappings to function ids 
 // are identical.  Other properties are not considered.
 inline bool cInstSet::operator==(const cInstSet& _rhs) const{

Modified: branches/matt/InheritInstSet/source/main/cBirthChamber.cc
===================================================================
--- branches/matt/InheritInstSet/source/main/cBirthChamber.cc	2010-01-05 20:47:29 UTC (rev 3585)
+++ branches/matt/InheritInstSet/source/main/cBirthChamber.cc	2010-01-05 22:44:03 UTC (rev 3586)
@@ -36,6 +36,7 @@
 #include "cTools.h"
 #include "cWorld.h"
 #include "cStats.h"
+#include "cHardwareBase.h"
 
 cBirthChamber::cBirthChamber(cWorld* world) : m_world(world)
 {
@@ -154,7 +155,7 @@
   // This is asexual who doesn't need to wait in the birth chamber
   // just build the child and return.
   child_array.Resize(1);
-  child_array[0] = new cOrganism(m_world, ctx, child_genome, parent.GetInstSetID());
+  child_array[0] = new cOrganism(m_world, ctx, child_genome, parent.GetInstSetID(), &parent.GetHardware().GetInstSet());
   merit_array.Resize(1);
   
   if(m_world->GetConfig().ENERGY_ENABLED.Get() == 1) {
@@ -193,8 +194,8 @@
 {
   // Build both child organisms...
   child_array.Resize(2);
-  child_array[0] = new cOrganism(m_world, ctx, old_entry.genome,parent.GetInstSetID());
-  child_array[1] = new cOrganism(m_world, ctx, new_genome,parent.GetInstSetID());
+  child_array[0] = new cOrganism(m_world, ctx, old_entry.genome,parent.GetInstSetID(), &parent.GetHardware().GetInstSet());
+  child_array[1] = new cOrganism(m_world, ctx, new_genome,parent.GetInstSetID(), &parent.GetHardware().GetInstSet());
 
   // Setup the merits for both children...
   merit_array.Resize(2);
@@ -235,6 +236,8 @@
       size_wait_entry[child_length].merit = parent.GetPhenotype().GetMerit();
     }
     size_wait_entry[child_length].parent_genotype = parent_genotype;
+    size_wait_entry[child_length].parent_instset = new cInstSet(parent.GetHardware().GetInstSet());
+    size_wait_entry[child_length].parent_instset_id = parent.GetInstSetID();
     size_wait_entry[child_length].update_in = m_world->GetStats().GetUpdate();
     return NULL; 				
   }
@@ -264,6 +267,8 @@
       mate_select_wait_entry[mate_id].merit = parent.GetPhenotype().GetMerit();
     }
     mate_select_wait_entry[mate_id].parent_genotype = parent_genotype;
+    mate_select_wait_entry[mate_id].parent_instset =  new cInstSet(parent.GetHardware().GetInstSet());
+    mate_select_wait_entry[mate_id].parent_instset_id = parent.GetInstSetID();
     mate_select_wait_entry[mate_id].update_in = m_world->GetStats().GetUpdate();
     return NULL;
   }
@@ -292,6 +297,8 @@
       local_wait_entry[parent_id].merit = parent.GetPhenotype().GetMerit();
     }
     local_wait_entry[parent_id].parent_genotype = parent_genotype;
+    local_wait_entry[parent_id].parent_instset = new cInstSet(parent.GetHardware().GetInstSet());
+    local_wait_entry[parent_id].parent_instset_id = parent.GetInstSetID();
     local_wait_entry[parent_id].update_in = m_world->GetStats().GetUpdate();
     return NULL; 				
   }
@@ -324,6 +331,8 @@
     }
     deme_wait_entry[parent_deme].parent_genotype = parent_genotype;
     deme_wait_entry[parent_deme].update_in = m_world->GetStats().GetUpdate();
+    deme_wait_entry[parent_deme].parent_instset = new cInstSet(parent.GetHardware().GetInstSet());
+    deme_wait_entry[parent_deme].parent_instset_id = parent.GetInstSetID();
     return NULL; 				
   }
 
@@ -346,6 +355,8 @@
       global_wait_entry.merit = parent.GetPhenotype().GetMerit();
     }
     global_wait_entry.parent_genotype = parent_genotype;
+    global_wait_entry.parent_instset = new cInstSet(parent.GetHardware().GetInstSet());
+    global_wait_entry.parent_instset_id = parent.GetInstSetID();
     global_wait_entry.update_in = m_world->GetStats().GetUpdate();
     return NULL;
   }
@@ -629,8 +640,8 @@
 
   if (two_fold_cost == 0) {	// Build the two organisms.
     child_array.Resize(2);
-    child_array[0] = new cOrganism(m_world, ctx, genome0);
-    child_array[1] = new cOrganism(m_world, ctx, genome1);
+    child_array[0] = new cOrganism(m_world, ctx, genome0, old_entry->parent_instset_id, old_entry->parent_instset);
+    child_array[1] = new cOrganism(m_world, ctx, genome1, parent.GetInstSetID(), parent.GetHardware().GetInstSetPtr());
     
     if(m_world->GetConfig().ENERGY_ENABLED.Get() == 1) {
       child_array[0]->GetPhenotype().SetEnergy(meritOrEnergy0);
@@ -653,7 +664,7 @@
     merit_array.Resize(1);
 
     if (ctx.GetRandom().GetDouble() < 0.5) {
-      child_array[0] = new cOrganism(m_world, ctx, genome0);
+      child_array[0] = new cOrganism(m_world, ctx, genome0, old_entry->parent_instset_id, old_entry->parent_instset );
       if(m_world->GetConfig().ENERGY_ENABLED.Get() == 1) {
         child_array[0]->GetPhenotype().SetEnergy(meritOrEnergy0);
         meritOrEnergy0 = cMerit::EnergyToMerit(child_array[0]->GetPhenotype().GetStoredEnergy(), m_world);
@@ -664,7 +675,7 @@
       SetupGenotypeInfo(child_array[0], parent0_genotype, parent1_genotype);
     } 
     else {
-      child_array[0] = new cOrganism(m_world, ctx, genome1);
+      child_array[0] = new cOrganism(m_world, ctx, genome1, parent.GetInstSetID(), parent.GetHardware().GetInstSetPtr());
       if(m_world->GetConfig().ENERGY_ENABLED.Get() == 1) {
         child_array[0]->GetPhenotype().SetEnergy(meritOrEnergy1);
         meritOrEnergy1 = cMerit::EnergyToMerit(child_array[1]->GetPhenotype().GetStoredEnergy(), m_world);

Modified: branches/matt/InheritInstSet/source/main/cBirthChamber.h
===================================================================
--- branches/matt/InheritInstSet/source/main/cBirthChamber.h	2010-01-05 20:47:29 UTC (rev 3585)
+++ branches/matt/InheritInstSet/source/main/cBirthChamber.h	2010-01-05 22:44:03 UTC (rev 3586)
@@ -32,6 +32,9 @@
 #ifndef cMerit_h
 #include "cMerit.h"
 #endif
+#ifndef cInstSet_h
+#include "cInstSet.h"
+#endif
 
 /**
  * All genome-based organisms must go through the birth chamber, which will
@@ -48,6 +51,7 @@
 template <class T> class tArray;
 class cWorld;
 
+
 class cBirthChamber {
 private:
 
@@ -57,9 +61,12 @@
     double energy4Offspring;
     cMerit merit;
     cGenotype * parent_genotype;
+    cInstSet* parent_instset;  //@MRR for inheritence
+    int parent_instset_id;  //@MRR for inheriting global instset tags
     int update_in;  // Update entry was created; Set to -1 if entry is empty.
 
-    cBirthEntry() : parent_genotype(NULL), update_in(-1) { ; }
+    cBirthEntry() : parent_genotype(NULL), parent_instset(NULL), update_in(-1) { ; }
+    ~cBirthEntry() { if (parent_instset != NULL) delete parent_instset; }
   };
   
   cWorld* m_world;

Modified: branches/matt/InheritInstSet/source/main/cInheritedInstSet.cc
===================================================================
--- branches/matt/InheritInstSet/source/main/cInheritedInstSet.cc	2010-01-05 20:47:29 UTC (rev 3585)
+++ branches/matt/InheritInstSet/source/main/cInheritedInstSet.cc	2010-01-05 22:44:03 UTC (rev 3586)
@@ -20,6 +20,10 @@
 }
 
 
+cInheritedInstSet::cInheritedInstSet(const cInstSet* in, tArray< tArray<int> >& allowed_redundancies) : cInstSet(*in)
+{
+  m_allowed_redundancies = allowed_redundancies;
+}
 
 cInheritedInstSet::cInheritedInstSet(const cInstSet* in, int init_val, const tArray< tArray<int> >& allowed_redundancies) : cInstSet(*in)
 {
@@ -52,21 +56,6 @@
 
 
 
-void cInheritedInstSet::DoMutation(eIIS_MUT_TYPE type, double p)
-{
-  bool did_mutate = false;
-  if (type == PER_INST){
-    did_mutate = MutateAllInsts(p);
-  } else if (type == PER_INSTSET){
-    if (RandProceed(p))
-      did_mutate = MutateSingleInst();
-  }
-  if (did_mutate)
-    Sync();
-  return;
-}
-
-
 bool cInheritedInstSet::MutateAllInsts(double p)
 {
   bool did_mutate = false;
@@ -79,8 +68,10 @@
 }
 
 
-bool cInheritedInstSet::MutateSingleInst()
+bool cInheritedInstSet::MutateSingleInst(double p)
 {
+  if (RandProceed(p) > p)
+    return false;
   int id = m_world->GetRandom().GetUInt(0,m_lib_name_map.GetSize());
   m_lib_name_map[id].redundancy = GetRandomRedundancy(id);
   return true;

Modified: branches/matt/InheritInstSet/source/main/cInheritedInstSet.h
===================================================================
--- branches/matt/InheritInstSet/source/main/cInheritedInstSet.h	2010-01-05 20:47:29 UTC (rev 3585)
+++ branches/matt/InheritInstSet/source/main/cInheritedInstSet.h	2010-01-05 22:44:03 UTC (rev 3586)
@@ -12,7 +12,6 @@
 
 #include "tArray.h"
 #include "tList.h"
-#include "defs.h"
 
 #include "cInstSet.h"
 
@@ -30,9 +29,7 @@
     void InitRedByValue(int val);
     
   
-    bool MutateAllInsts(double p);
-    bool MutateSingleInst();
-  
+   
     inline int GetRandomRedundancy(int id);
     inline bool RandProceed(double p);
   
@@ -41,12 +38,15 @@
   
   
   public:
+    virtual ~cInheritedInstSet() {;}
     cInheritedInstSet(const cInheritedInstSet* in);
+    cInheritedInstSet(const cInstSet* in, tArray< tArray<int> >& allowed_redundancies);
     cInheritedInstSet(const cInstSet* in, int init_val, 
                       const tArray< tArray<int> >& allowed_redundancies);
     cInstSet* MakeInstSet();
     
-    void DoMutation(eIIS_MUT_TYPE type, double prob);
+    bool MutateAllInsts(double p);
+    bool MutateSingleInst(double p);
   
     void Sync();
   

Modified: branches/matt/InheritInstSet/source/main/cOrganism.cc
===================================================================
--- branches/matt/InheritInstSet/source/main/cOrganism.cc	2010-01-05 20:47:29 UTC (rev 3585)
+++ branches/matt/InheritInstSet/source/main/cOrganism.cc	2010-01-05 22:44:03 UTC (rev 3586)
@@ -49,7 +49,7 @@
 using namespace std;
 
 
-cOrganism::cOrganism(cWorld* world, cAvidaContext& ctx, const cGenome& in_genome, int inst_set_id)
+cOrganism::cOrganism(cWorld* world, cAvidaContext& ctx, const cGenome& in_genome, int inst_set_id, const cInstSet* inst_set)
   : m_world(world)
   , m_genotype(NULL)
   , m_phenotype(world)
@@ -74,7 +74,7 @@
   , m_msg(0)
 {
   // Initialization of structures...
-  m_hardware = m_world->GetHardwareManager().Create(this);
+  m_hardware = m_world->GetHardwareManager().Create(this, inst_set);
 //  m_cpu_stats.Setup();
 
   if (m_world->GetConfig().DEATH_METHOD.Get() > DEATH_METHOD_OFF) {

Modified: branches/matt/InheritInstSet/source/main/cOrganism.h
===================================================================
--- branches/matt/InheritInstSet/source/main/cOrganism.h	2010-01-05 20:47:29 UTC (rev 3585)
+++ branches/matt/InheritInstSet/source/main/cOrganism.h	2010-01-05 22:44:03 UTC (rev 3586)
@@ -83,9 +83,9 @@
 class cLineage;
 class cOrgSinkMessage;
 class cSaleItem;
+class cInstSet;
 
 
-
 class cOrganism
 {
 protected:
@@ -144,7 +144,7 @@
   cOrganism& operator=(const cOrganism&); // @not_implemented
   
 public:
-  cOrganism(cWorld* world, cAvidaContext& ctx, const cGenome& in_genome, int inst_set_id = 0);
+  cOrganism(cWorld* world, cAvidaContext& ctx, const cGenome& in_genome, int inst_set_id = 0, const cInstSet* instset = NULL);
   ~cOrganism();
 
   // --------  Accessor Methods  --------




More information about the Avida-cvs mailing list