[Avida-SVN] r3315 - in branches/matt/CompeteInstSet/source: cpu main
ruppmatt at myxo.css.msu.edu
ruppmatt at myxo.css.msu.edu
Thu Jun 11 13:31:23 PDT 2009
Author: ruppmatt
Date: 2009-06-11 16:31:23 -0400 (Thu, 11 Jun 2009)
New Revision: 3315
Modified:
branches/matt/CompeteInstSet/source/cpu/cHardwareBase.h
branches/matt/CompeteInstSet/source/cpu/cHardwareManager.cc
branches/matt/CompeteInstSet/source/main/cPopulationCell.h
Log:
Bug fixes for hot-swapping instruction sets during the course of an experiment.
Modified: branches/matt/CompeteInstSet/source/cpu/cHardwareBase.h
===================================================================
--- branches/matt/CompeteInstSet/source/cpu/cHardwareBase.h 2009-06-11 19:17:25 UTC (rev 3314)
+++ branches/matt/CompeteInstSet/source/cpu/cHardwareBase.h 2009-06-11 20:31:23 UTC (rev 3315)
@@ -102,7 +102,7 @@
// -------- Organism ---------
cOrganism* GetOrganism() { return organism; }
const cInstSet& GetInstSet() { return *m_inst_set; }
- cInstSet* GetInstSetPtr() { return m_inst_set; }
+ void SetInstSet(cInstSet* _in) {m_inst_set = _in; }
// -------- Core Functionality --------
Modified: branches/matt/CompeteInstSet/source/cpu/cHardwareManager.cc
===================================================================
--- branches/matt/CompeteInstSet/source/cpu/cHardwareManager.cc 2009-06-11 19:17:25 UTC (rev 3314)
+++ branches/matt/CompeteInstSet/source/cpu/cHardwareManager.cc 2009-06-11 20:31:23 UTC (rev 3315)
@@ -111,18 +111,20 @@
if (m_inst_sets[id] != NULL){ //Old instruction set exists, migrate hardware and delete it
int sz = m_world->GetPopulation().GetSize();
for (int k = 0; k < sz; k++){ //Go through every organism and see if it's using the depricated instruction set
- cInstSet* old = (m_world->GetPopulation().GetCell(k).IsOccupied()) ? m_world->GetPopulation().GetCell(k).GetHardware()->GetInstSetPtr() : NULL;
- if (old != NULL && old == m_inst_sets[id])
- old = new_inst_set; //replace it if necessary
+ if (m_world->GetPopulation().GetCell(k).IsOccupied())
+ m_world->GetPopulation().GetCell(k).GetHardware()->SetInstSet(new_inst_set);
}
+ cerr << "Deprecating instruction set " << m_inst_sets[id] << " using id " << id << endl;
delete m_inst_sets[id];
}
m_inst_sets[id] = new_inst_set;
+ cerr << "Adding instruction set " << new_inst_set << " using id " << id << endl;
} else{ //If we have to resize the array to accomodate the ID
m_inst_sets.Resize(id+1, NULL);
if (m_inst_sets.GetSize() > 1) //Update our stats object if more than one inst set is added. Initial size is set in cStats constructor.
m_world->GetStats().GetInstSetCounts().Resize(id+1,0);
m_inst_sets[id] = new_inst_set;
+ cerr << "Created instruction set " << new_inst_set << " using id " << id << endl;
}
} else{ //Our instruction set is incompatible
m_world->GetDriver().RaiseFatalException(1, "Additional instruction set addition is incompatible.");
Modified: branches/matt/CompeteInstSet/source/main/cPopulationCell.h
===================================================================
--- branches/matt/CompeteInstSet/source/main/cPopulationCell.h 2009-06-11 19:17:25 UTC (rev 3314)
+++ branches/matt/CompeteInstSet/source/main/cPopulationCell.h 2009-06-11 20:31:23 UTC (rev 3315)
@@ -82,7 +82,7 @@
void Rotate(cPopulationCell& new_facing);
inline cOrganism* GetOrganism() const { return m_organism; }
- inline cHardwareBase* GetHardware() const { return m_hardware; }
+ inline cHardwareBase* GetHardware() const { return m_hardware; }
inline tList<cPopulationCell>& ConnectionList() { return m_connections; }
inline cPopulationCell& GetCellFaced() { return *(m_connections.GetFirst()); }
int GetFacing(); // Returns the facing of this cell.
More information about the Avida-cvs
mailing list