[Avida-SVN] r3291 - in branches/matt/CompeteInstSet/source: cpu main tools
ruppmatt at myxo.css.msu.edu
ruppmatt at myxo.css.msu.edu
Fri Jun 5 12:02:42 PDT 2009
Author: ruppmatt
Date: 2009-06-05 15:02:42 -0400 (Fri, 05 Jun 2009)
New Revision: 3291
Modified:
branches/matt/CompeteInstSet/source/cpu/cHardwareManager.cc
branches/matt/CompeteInstSet/source/cpu/cHardwareManager.h
branches/matt/CompeteInstSet/source/cpu/cInstLib.h
branches/matt/CompeteInstSet/source/cpu/cInstSet.h
branches/matt/CompeteInstSet/source/main/cBirthChamber.cc
branches/matt/CompeteInstSet/source/main/cOrganism.cc
branches/matt/CompeteInstSet/source/main/cOrganism.h
branches/matt/CompeteInstSet/source/tools/tArray.h
branches/matt/CompeteInstSet/source/tools/tDictionary.h
branches/matt/CompeteInstSet/source/tools/tHashTable.h
branches/matt/CompeteInstSet/source/tools/tSmartArray.h
Log:
Initial modifications to allow for multiple versions of the same instruction set to be loaded.
Modified: branches/matt/CompeteInstSet/source/cpu/cHardwareManager.cc
===================================================================
--- branches/matt/CompeteInstSet/source/cpu/cHardwareManager.cc 2009-06-05 15:35:34 UTC (rev 3290)
+++ branches/matt/CompeteInstSet/source/cpu/cHardwareManager.cc 2009-06-05 19:02:42 UTC (rev 3291)
@@ -33,6 +33,7 @@
#include "cInstSet.h"
#include "cWorld.h"
#include "cWorldDriver.h"
+#include "cOrganism.h"
#include "tDictionary.h"
cHardwareManager::cHardwareManager(cWorld* world)
@@ -45,23 +46,23 @@
switch (m_type)
{
case HARDWARE_TYPE_CPU_ORIGINAL:
- m_inst_set = new cInstSet(world, cHardwareCPU::GetInstLib());
+ m_inst_sets.Push(new cInstSet(world, cHardwareCPU::GetInstLib()));
default_filename = cHardwareCPU::GetDefaultInstFilename();
break;
case HARDWARE_TYPE_CPU_SMT:
- m_inst_set = new cInstSet(world, cHardwareSMT::GetInstLib());
+ m_inst_sets.Push(new cInstSet(world, cHardwareSMT::GetInstLib()));
default_filename = cHardwareSMT::GetDefaultInstFilename();
break;
case HARDWARE_TYPE_CPU_TRANSSMT:
- m_inst_set = new cInstSet(world, cHardwareTransSMT::GetInstLib());
+ m_inst_sets.Push(new cInstSet(world, cHardwareTransSMT::GetInstLib()));
default_filename = cHardwareTransSMT::GetDefaultInstFilename();
break;
case HARDWARE_TYPE_CPU_EXPERIMENTAL:
- m_inst_set = new cInstSet(world, cHardwareExperimental::GetInstLib());
+ m_inst_sets.Push(new cInstSet(world, cHardwareExperimental::GetInstLib()));
default_filename = cHardwareExperimental::GetDefaultInstFilename();
break;
case HARDWARE_TYPE_CPU_GX:
- m_inst_set = new cInstSet(world, cHardwareGX::GetInstLib());
+ m_inst_sets.Push(new cInstSet(world, cHardwareGX::GetInstLib()));
default_filename = cHardwareGX::GetDefaultInstFilename();
break;
default:
@@ -75,9 +76,9 @@
if (m_world->GetConfig().INST_SET_FORMAT.Get()) {
- m_inst_set->LoadFromConfig();
+ m_inst_sets.GetPos(0)->LoadFromConfig();
} else {
- m_inst_set->LoadFromLegacyFile(filename);
+ m_inst_sets.GetPos(0)->LoadFromLegacyFile(filename);
}
}
@@ -86,18 +87,19 @@
{
assert(in_org != NULL);
+ int inst_id = in_org->GetInstSetID();
switch (m_type)
{
case HARDWARE_TYPE_CPU_ORIGINAL:
- return new cHardwareCPU(m_world, in_org, m_inst_set);
+ return new cHardwareCPU(m_world, in_org, m_inst_sets.GetPos(inst_id));
case HARDWARE_TYPE_CPU_SMT:
- return new cHardwareSMT(m_world, in_org, m_inst_set);
+ return new cHardwareSMT(m_world, in_org, m_inst_sets.GetPos(inst_id));
case HARDWARE_TYPE_CPU_TRANSSMT:
- return new cHardwareTransSMT(m_world, in_org, m_inst_set);
+ return new cHardwareTransSMT(m_world, in_org, m_inst_sets.GetPos(inst_id));
case HARDWARE_TYPE_CPU_EXPERIMENTAL:
- return new cHardwareExperimental(m_world, in_org, m_inst_set);
+ return new cHardwareExperimental(m_world, in_org, m_inst_sets.GetPos(inst_id));
case HARDWARE_TYPE_CPU_GX:
- return new cHardwareGX(m_world, in_org, m_inst_set);
+ return new cHardwareGX(m_world, in_org, m_inst_sets.GetPos(inst_id));
default:
return NULL;
}
Modified: branches/matt/CompeteInstSet/source/cpu/cHardwareManager.h
===================================================================
--- branches/matt/CompeteInstSet/source/cpu/cHardwareManager.h 2009-06-05 15:35:34 UTC (rev 3290)
+++ branches/matt/CompeteInstSet/source/cpu/cHardwareManager.h 2009-06-05 19:02:42 UTC (rev 3291)
@@ -35,6 +35,10 @@
# endif
#endif
+#ifndef tList_h
+#include "tList.h"
+#endif
+
class cHardwareBase;
class cInstSet;
class cOrganism;
@@ -48,7 +52,7 @@
#endif
private:
cWorld* m_world;
- cInstSet* m_inst_set;
+ tList<cInstSet> m_inst_sets;
int m_type;
// cTestResources m_testres;
@@ -64,8 +68,8 @@
cHardwareBase* Create(cOrganism* in_org);
cTestCPU* CreateTestCPU() { return new cTestCPU(m_world /*, &m_testres*/); }
- const cInstSet& GetInstSet() const { return *m_inst_set; }
- cInstSet& GetInstSet() { return *m_inst_set; }
+ const cInstSet& GetInstSet(int id=0) const { return *m_inst_sets.GetPos(id); }
+ cInstSet& GetInstSet(int id=0) { return *m_inst_sets.GetPos(id); }
};
Modified: branches/matt/CompeteInstSet/source/cpu/cInstLib.h
===================================================================
--- branches/matt/CompeteInstSet/source/cpu/cInstLib.h 2009-06-05 15:35:34 UTC (rev 3290)
+++ branches/matt/CompeteInstSet/source/cpu/cInstLib.h 2009-06-05 19:02:42 UTC (rev 3291)
@@ -56,6 +56,8 @@
: m_size(size), m_inst_error(inst_error), m_inst_default(inst_default), m_inst_null(inst_null) { ; }
virtual ~cInstLib() { ; }
+ inline bool operator==(const cInstLib& _in) const;
+
inline int GetSize() const { return m_size; }
virtual const cInstLibEntry& Get(int i) const = 0;
@@ -91,5 +93,12 @@
return m_inst_error;
}
+inline bool cInstLib::operator==(const cInstLib& _in) const{
+ return (m_size == _in.m_size &&
+ m_namemap == _in.m_namemap &&
+ m_inst_error == _in.m_inst_error &&
+ m_inst_default == _in.m_inst_default &&
+ m_inst_null == _in.m_inst_null);
+}
#endif
Modified: branches/matt/CompeteInstSet/source/cpu/cInstSet.h
===================================================================
--- branches/matt/CompeteInstSet/source/cpu/cInstSet.h 2009-06-05 15:35:34 UTC (rev 3290)
+++ branches/matt/CompeteInstSet/source/cpu/cInstSet.h 2009-06-05 19:02:42 UTC (rev 3291)
@@ -88,7 +88,8 @@
inline cInstSet(cWorld* world, cInstLib* inst_lib) : m_world(world), m_inst_lib(inst_lib) { ; }
inline cInstSet(const cInstSet& is);
inline ~cInstSet() { ; }
-
+
+ inline bool operator==(const cInstSet& _in) const;
inline cInstSet& operator=(const cInstSet& _in);
bool OK() const;
@@ -169,6 +170,22 @@
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{
+ //Check to make sure we are referencing the same library and have the
+ //same number of instructions in each instruction set
+ if (m_inst_lib != _rhs.m_inst_lib ||
+ m_lib_name_map.GetSize() != _rhs.m_lib_name_map.GetSize() )
+ return false;
+
+ //Verify that the instruction sets have the same mapping
+ for (int i = 0; i < m_lib_name_map.GetSize(); i++)
+ if (m_lib_name_map[i].lib_fun_id != _rhs.m_lib_name_map[i].lib_fun_id)
+ return false;
+ return true;
+}
+
inline cInstruction cInstSet::GetInst(const cString & in_name) const
{
for (int i = 0; i < m_lib_name_map.GetSize(); i++) {
Modified: branches/matt/CompeteInstSet/source/main/cBirthChamber.cc
===================================================================
--- branches/matt/CompeteInstSet/source/main/cBirthChamber.cc 2009-06-05 15:35:34 UTC (rev 3290)
+++ branches/matt/CompeteInstSet/source/main/cBirthChamber.cc 2009-06-05 19:02:42 UTC (rev 3291)
@@ -154,7 +154,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);
+ child_array[0] = new cOrganism(m_world, ctx, child_genome, parent.GetInstSetID());
merit_array.Resize(1);
if(m_world->GetConfig().ENERGY_ENABLED.Get() == 1) {
@@ -193,8 +193,8 @@
{
// Build both child organisms...
child_array.Resize(2);
- child_array[0] = new cOrganism(m_world, ctx, old_entry.genome);
- child_array[1] = new cOrganism(m_world, ctx, new_genome);
+ 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());
// Setup the merits for both children...
merit_array.Resize(2);
@@ -521,7 +521,7 @@
bool cBirthChamber::SubmitOffspring(cAvidaContext& ctx,
const cGenome& child_genome,
cOrganism& parent,
- tArray<cOrganism*>& child_array,
+ tArray<cOrganism*>& child_array,
tArray<cMerit>& merit_array)
{
cPhenotype& parent_phenotype = parent.GetPhenotype();
Modified: branches/matt/CompeteInstSet/source/main/cOrganism.cc
===================================================================
--- branches/matt/CompeteInstSet/source/main/cOrganism.cc 2009-06-05 15:35:34 UTC (rev 3290)
+++ branches/matt/CompeteInstSet/source/main/cOrganism.cc 2009-06-05 19:02:42 UTC (rev 3291)
@@ -50,7 +50,7 @@
using namespace std;
-cOrganism::cOrganism(cWorld* world, cAvidaContext& ctx, const cGenome& in_genome)
+cOrganism::cOrganism(cWorld* world, cAvidaContext& ctx, const cGenome& in_genome, int inst_set_id)
: m_world(world)
, m_genotype(NULL)
, m_phenotype(world)
@@ -59,6 +59,7 @@
, m_interface(NULL)
, m_lineage_label(-1)
, m_lineage(NULL)
+ , m_inst_set_id(m_inst_set_id)
, m_input_pointer(0)
, m_input_buf(world->GetEnvironment().GetInputSize())
, m_output_buf(world->GetEnvironment().GetOutputSize())
Modified: branches/matt/CompeteInstSet/source/main/cOrganism.h
===================================================================
--- branches/matt/CompeteInstSet/source/main/cOrganism.h 2009-06-05 15:35:34 UTC (rev 3290)
+++ branches/matt/CompeteInstSet/source/main/cOrganism.h 2009-06-05 19:02:42 UTC (rev 3291)
@@ -101,6 +101,7 @@
int m_lineage_label; // a lineages tag; inherited unchanged in offspring
cLineage* m_lineage; // A lineage descriptor... (different from label)
int cclade_id; // @MRR Coalescence clade information (set in cPopulation)
+ int m_inst_set_id; // @MRR inst_set id
// Other stats
cCPUMemory m_child_genome; // Child genome, while under construction.
@@ -142,7 +143,7 @@
cOrganism& operator=(const cOrganism&); // @not_implemented
public:
- cOrganism(cWorld* world, cAvidaContext& ctx, const cGenome& in_genome);
+ cOrganism(cWorld* world, cAvidaContext& ctx, const cGenome& in_genome, int inst_set_id = 0);
~cOrganism();
// -------- Accessor Methods --------
@@ -169,6 +170,8 @@
void SetCCladeLabel( int in_label ) { cclade_id = in_label; }; //@MRR
int GetCCladeLabel() const { return cclade_id; }
+
+ int GetInstSetID() const { return m_inst_set_id; } //@MRR
int GetMaxExecuted() const { return m_max_executed; }
Modified: branches/matt/CompeteInstSet/source/tools/tArray.h
===================================================================
--- branches/matt/CompeteInstSet/source/tools/tArray.h 2009-06-05 15:35:34 UTC (rev 3290)
+++ branches/matt/CompeteInstSet/source/tools/tArray.h 2009-06-05 19:02:42 UTC (rev 3291)
@@ -74,6 +74,13 @@
for(int i = 0; i < m_size; i++) m_data[i] = rhs[i];
return *this;
}
+
+ bool operator==(const tArray& _rhs) const {
+ if (m_size != _rhs.m_size) return false;
+ for (int i = 0; i < m_size; i++)
+ if (m_data[i] != _rhs.m_data[i]) return false;
+ return true;
+ }
inline tArray operator+(const tArray& in_array) const {
tArray tmp(m_size + in_array.m_size);
Modified: branches/matt/CompeteInstSet/source/tools/tDictionary.h
===================================================================
--- branches/matt/CompeteInstSet/source/tools/tDictionary.h 2009-06-05 15:35:34 UTC (rev 3290)
+++ branches/matt/CompeteInstSet/source/tools/tDictionary.h 2009-06-05 19:02:42 UTC (rev 3291)
@@ -64,6 +64,8 @@
inline tDictionary() { ; }
inline tDictionary(int in_hash_size) : m_hash(in_hash_size) { ; }
+ inline bool operator==(const tDictionary<T>& _rhs) const {return m_hash == _rhs.m_hash;}
+
// The following methods just call the encapsulated tHashTable
inline bool OK() { return m_hash.OK(); }
inline int GetSize() { return m_hash.GetSize(); }
Modified: branches/matt/CompeteInstSet/source/tools/tHashTable.h
===================================================================
--- branches/matt/CompeteInstSet/source/tools/tHashTable.h 2009-06-05 15:35:34 UTC (rev 3290)
+++ branches/matt/CompeteInstSet/source/tools/tHashTable.h 2009-06-05 19:02:42 UTC (rev 3291)
@@ -407,6 +407,21 @@
}
+ //Equivalency-- all keys must have matching values
+ bool operator==(const tHashTable<HASH_TYPE,DATA_TYPE>& _rhs) const
+ {
+ if (GetSize() != _rhs.GetSize()) //Make sure they store the same number of entries
+ return false;
+ list_it.Reset();
+ while (list_it.Next() != NULL){ //See if every key has the same value in _rhs
+ DATA_TYPE value = list_it.Get()->data;
+ HASH_TYPE key = list_it.Get()->key;
+ DATA_TYPE rhs_value;
+ if (!_rhs.Find(key,rhs_value) || value != rhs_value)
+ return false;
+ }
+ return true;
+ }
template<class Archive>
void serialize(Archive & a, const unsigned int version){
Modified: branches/matt/CompeteInstSet/source/tools/tSmartArray.h
===================================================================
--- branches/matt/CompeteInstSet/source/tools/tSmartArray.h 2009-06-05 15:35:34 UTC (rev 3290)
+++ branches/matt/CompeteInstSet/source/tools/tSmartArray.h 2009-06-05 19:02:42 UTC (rev 3291)
@@ -66,6 +66,7 @@
for(int i = 0; i < m_active; i++) m_data[i] = rhs[i];
return *this;
}
+
tSmartArray& operator=(const tArray<T>& rhs)
{
if (m_active != rhs.GetSize()) Resize(rhs.GetSize());
@@ -73,6 +74,14 @@
return *this;
}
+ bool operator==(const tSmartArray<T>& rhs) const
+ {
+ if (m_active != rhs.GetSize()) return false;
+ for (int i = 0; i < m_active; i++)
+ if (m_data[i] != rhs[i]) return false;
+ return true;
+ }
+
bool Good() const { return (m_data != NULL); }
int GetSize() const { return m_active; }
More information about the Avida-cvs
mailing list