[Avida-SVN] r3169 - in development/source: cpu main
connel42 at myxo.css.msu.edu
connel42 at myxo.css.msu.edu
Fri Feb 27 08:54:29 PST 2009
Author: connel42
Date: 2009-02-27 11:54:29 -0500 (Fri, 27 Feb 2009)
New Revision: 3169
Modified:
development/source/cpu/cHardwareCPU.cc
development/source/cpu/cHardwareCPU.h
development/source/main/cPopulation.cc
development/source/main/cPopulation.h
Log:
Additional energy sharing instructions and print action. Will be branching in the future.
Modified: development/source/cpu/cHardwareCPU.cc
===================================================================
--- development/source/cpu/cHardwareCPU.cc 2009-02-26 22:53:17 UTC (rev 3168)
+++ development/source/cpu/cHardwareCPU.cc 2009-02-27 16:54:29 UTC (rev 3169)
@@ -431,6 +431,11 @@
tInstLibEntry<tMethod>("if-energy-not-in-buffer", &cHardwareCPU::Inst_IfEnergyNotInBuffer, nInstFlag::STALL),
tInstLibEntry<tMethod>("get-energy-level", &cHardwareCPU::Inst_GetEnergyLevel, nInstFlag::STALL),
tInstLibEntry<tMethod>("get-faced-energy-level", &cHardwareCPU::Inst_GetFacedEnergyLevel, nInstFlag::STALL),
+ tInstLibEntry<tMethod>("if-faced-request-on", &cHardwareCPU::Inst_IfFacedEnergyRequestOn, nInstFlag::STALL),
+ tInstLibEntry<tMethod>("if-faced-request-off", &cHardwareCPU::Inst_IfFacedEnergyRequestOff, nInstFlag::STALL),
+ tInstLibEntry<tMethod>("get-energy-request-status", &cHardwareCPU::Inst_GetEnergyRequestStatus, nInstFlag::STALL),
+ tInstLibEntry<tMethod>("get-faced-energy-request-status", &cHardwareCPU::Inst_GetFacedEnergyRequestStatus, nInstFlag::STALL),
+
// Sleep and time
tInstLibEntry<tMethod>("sleep", &cHardwareCPU::Inst_Sleep, nInstFlag::STALL),
@@ -5778,6 +5783,93 @@
} //End Inst_GetFacedEnergyLevel()
+bool cHardwareCPU::Inst_IfFacedEnergyRequestOn(cAvidaContext& ctx) {
+
+ if(m_organism->GetCellID() < 0) {
+ return false;
+ }
+
+ cOrganism * neighbor = m_organism->GetNeighbor();
+
+ if( (neighbor == NULL) || (neighbor->IsDead()) ) {
+ return false;
+ }
+
+ if(neighbor->GetPhenotype().IsEnergyRequestor() == false) {
+ IP().Advance();
+ }
+
+ return true;
+
+} //End Inst_IfFacedEnergyRequestOn()
+
+bool cHardwareCPU::Inst_IfFacedEnergyRequestOff(cAvidaContext& ctx) {
+
+ if(m_organism->GetCellID() < 0) {
+ return false;
+ }
+
+ cOrganism * neighbor = m_organism->GetNeighbor();
+
+ if( (neighbor == NULL) || (neighbor->IsDead()) ) {
+ return false;
+ }
+
+ if(neighbor->GetPhenotype().IsEnergyRequestor() == true) {
+ IP().Advance();
+ }
+
+ return true;
+
+} //End Inst_IfFacedEnergyRequestOff()
+
+
+bool cHardwareCPU::Inst_GetEnergyRequestStatus(cAvidaContext& ctx) {
+
+ if(m_organism->GetCellID() < 0) {
+ return false;
+ }
+
+ const int reg = FindModifiedRegister(REG_BX);
+ int status = 0;
+
+ if(m_organism->GetPhenotype().IsEnergyRequestor() == true) {
+ status = 1;
+ }
+
+ GetRegister(reg) = status;
+
+ return true;
+
+} //End Inst_GetEnergyRequestStatus()
+
+
+bool cHardwareCPU::Inst_GetFacedEnergyRequestStatus(cAvidaContext& ctx) {
+
+ if(m_organism->GetCellID() < 0) {
+ return false;
+ }
+
+ cOrganism * neighbor = m_organism->GetNeighbor();
+
+ if( (neighbor == NULL) || (neighbor->IsDead()) ) {
+ return false;
+ }
+
+ const int reg = FindModifiedRegister(REG_BX);
+ int status = 0;
+
+ if(neighbor->GetPhenotype().IsEnergyRequestor() == true) {
+ status = 1;
+ }
+
+ GetRegister(reg) = status;
+
+ return true;
+
+} //End Inst_GetFacedEnergyRequestStatus()
+
+
bool cHardwareCPU::Inst_Sleep(cAvidaContext& ctx) {
cPopulation& pop = m_world->GetPopulation();
int cellID = m_organism->GetCellID();
Modified: development/source/cpu/cHardwareCPU.h
===================================================================
--- development/source/cpu/cHardwareCPU.h 2009-02-26 22:53:17 UTC (rev 3168)
+++ development/source/cpu/cHardwareCPU.h 2009-02-27 16:54:29 UTC (rev 3169)
@@ -647,6 +647,12 @@
bool Inst_IfEnergyNotInBuffer(cAvidaContext& ctx);
bool Inst_GetEnergyLevel(cAvidaContext& ctx);
bool Inst_GetFacedEnergyLevel(cAvidaContext& ctx);
+ bool Inst_IfFacedEnergyRequestOn(cAvidaContext& ctx);
+ bool Inst_IfFacedEnergyRequestOff(cAvidaContext& ctx);
+ bool Inst_GetEnergyRequestStatus(cAvidaContext& ctx);
+ bool Inst_GetFacedEnergyRequestStatus(cAvidaContext& ctx);
+
+
bool Inst_Sleep(cAvidaContext& ctx);
bool Inst_GetUpdate(cAvidaContext& ctx);
Modified: development/source/main/cPopulation.cc
===================================================================
--- development/source/main/cPopulation.cc 2009-02-26 22:53:17 UTC (rev 3168)
+++ development/source/main/cPopulation.cc 2009-02-27 16:54:29 UTC (rev 3169)
@@ -2681,7 +2681,9 @@
} //End PrintDemeEnergySharingStats()
-// Print some stats about the distribution of energy among organisms in a deme
+// Print some stats about the distribution of energy among the cells in a deme
+// If a cell is occupied, the amount returned is that of the organism in that cell
+// If a cell is not occupied, the amount returned is the amount of energy resource in the cell
void cPopulation::PrintDemeEnergyDistributionStats() {
const int num_demes = deme_array.GetSize();
cStats& stats = m_world->GetStats();
@@ -2694,7 +2696,7 @@
cDoubleSum overall_stddev;
cDataFile & df_dist = m_world->GetDataFile("deme_energy_distribution.dat");
- comment.Set("Average distribution of energy among organisms in each of %d %d x %d demes", num_demes, m_world->GetConfig().WORLD_X.Get(), m_world->GetConfig().WORLD_Y.Get()/num_demes);
+ comment.Set("Average distribution of energy among cells in each of %d %d x %d demes", num_demes, m_world->GetConfig().WORLD_X.Get(), m_world->GetConfig().WORLD_Y.Get()/num_demes);
df_dist.WriteComment(comment);
df_dist.WriteTimeStamp();
df_dist.Write(stats.GetUpdate(), "Update");
@@ -2706,11 +2708,9 @@
int cur_cell = cur_deme.GetCellID(i);
if (cell_array[cur_cell].IsOccupied() == false) {
- //TODO: BDC: Get energy of cell and add that instead
deme_energy_distribution.Add(cur_deme.GetCellEnergy(cur_cell));
continue;
}
- //TODO: add 0 for this deme
deme_energy_distribution.Add(GetCell(cur_cell).GetOrganism()->GetPhenotype().GetStoredEnergy());
}
@@ -2731,6 +2731,56 @@
} //End PrintDemeEnergyDistributionStats()
+// Print some stats about the distribution of energy among the organism in a deme
+// If a cell is occupied, the amount returned is that of the organism in that cell
+// If a cell is not occupied, 0 energy is returned for that cell.
+void cPopulation::PrintDemeOrganismEnergyDistributionStats() {
+ const int num_demes = deme_array.GetSize();
+ cStats& stats = m_world->GetStats();
+ cString comment;
+
+ cDoubleSum deme_energy_distribution;
+
+ cDoubleSum overall_average;
+ cDoubleSum overall_variance;
+ cDoubleSum overall_stddev;
+
+ cDataFile & df_dist = m_world->GetDataFile("deme_org_energy_distribution.dat");
+ comment.Set("Average distribution of energy among organisms in each of %d %d x %d demes", num_demes, m_world->GetConfig().WORLD_X.Get(), m_world->GetConfig().WORLD_Y.Get()/num_demes);
+ df_dist.WriteComment(comment);
+ df_dist.WriteTimeStamp();
+ df_dist.Write(stats.GetUpdate(), "Update");
+
+ for (int deme_id = 0; deme_id < num_demes; deme_id++) {
+ const cDeme & cur_deme = deme_array[deme_id];
+
+ for (int i = 0; i < cur_deme.GetSize(); i++) {
+
+ int cur_cell = cur_deme.GetCellID(i);
+ if (cell_array[cur_cell].IsOccupied() == false) {
+ deme_energy_distribution.Add(0);
+ continue;
+ }
+
+ deme_energy_distribution.Add(GetCell(cur_cell).GetOrganism()->GetPhenotype().GetStoredEnergy());
+ }
+
+ overall_average.Add(deme_energy_distribution.Average());
+ overall_variance.Add(deme_energy_distribution.Variance());
+ overall_stddev.Add(deme_energy_distribution.StdDeviation());
+ deme_energy_distribution.Clear();
+
+ }
+
+ df_dist.Write(overall_average.Average(), "Average of Average Energy Level");
+ df_dist.Write(overall_variance.Average(), "Average of Energy Level Variance");
+ df_dist.Write(overall_stddev.Average(), "Average of Energy Level Standard Deviations");
+
+ df_dist.Endl();
+
+} //End PrintDemeOrganismEnergyDistributionStats()
+
+
void cPopulation::PrintDemeDonor() {
cStats& stats = m_world->GetStats();
const int num_demes = deme_array.GetSize();
Modified: development/source/main/cPopulation.h
===================================================================
--- development/source/main/cPopulation.h 2009-02-26 22:53:17 UTC (rev 3168)
+++ development/source/main/cPopulation.h 2009-02-27 16:54:29 UTC (rev 3169)
@@ -231,6 +231,7 @@
void PrintDemeTestamentStats(const cString& filename);
void PrintDemeEnergySharingStats();
void PrintDemeEnergyDistributionStats();
+ void PrintDemeOrganismEnergyDistributionStats();
void PrintDemeDonor();
void PrintDemeFitness();
void PrintDemeGestationTime();
More information about the Avida-cvs
mailing list