[Avida-SVN] r2519 - in branches/jobScheduling/source: cpu main
beckma24 at myxo.css.msu.edu
beckma24 at myxo.css.msu.edu
Fri Apr 4 12:18:26 PDT 2008
Author: beckma24
Date: 2008-04-04 15:18:26 -0400 (Fri, 04 Apr 2008)
New Revision: 2519
Modified:
branches/jobScheduling/source/cpu/cHardwareCPU.cc
branches/jobScheduling/source/cpu/cHardwareCPU.h
branches/jobScheduling/source/cpu/cTestCPUInterface.cc
branches/jobScheduling/source/cpu/cTestCPUInterface.h
branches/jobScheduling/source/main/cAvidaConfig.h
branches/jobScheduling/source/main/cDemeCellEvent.cc
branches/jobScheduling/source/main/cOrgInterface.h
branches/jobScheduling/source/main/cOrganism.h
branches/jobScheduling/source/main/cPhenotype.h
branches/jobScheduling/source/main/cPopulationInterface.cc
branches/jobScheduling/source/main/cPopulationInterface.h
Log:
Added two more will and testament instuctions
Modified: branches/jobScheduling/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/jobScheduling/source/cpu/cHardwareCPU.cc 2008-04-04 14:15:59 UTC (rev 2518)
+++ branches/jobScheduling/source/cpu/cHardwareCPU.cc 2008-04-04 19:18:26 UTC (rev 2519)
@@ -357,7 +357,10 @@
tInstLibEntry<tMethod>("kazi5", &cHardwareCPU::Inst_Kazi5, nInstFlag::STALL),
tInstLibEntry<tMethod>("die", &cHardwareCPU::Inst_Die, nInstFlag::STALL),
tInstLibEntry<tMethod>("relinquishEnergyToFutureDeme", &cHardwareCPU::Inst_RelinquishEnergyToFutureDeme, nInstFlag::STALL),
+ tInstLibEntry<tMethod>("relinquishEnergyToNeighborOrganisms", &cHardwareCPU::Inst_RelinquishEnergyToNeighborOrganisms, nInstFlag::STALL),
+ tInstLibEntry<tMethod>("relinquishEnergyToOrganismsInDeme", &cHardwareCPU::Inst_RelinquishEnergyToOrganismsInDeme, nInstFlag::STALL),
+
// Sleep and time
tInstLibEntry<tMethod>("sleep", &cHardwareCPU::Inst_Sleep, nInstFlag::STALL),
tInstLibEntry<tMethod>("sleep1", &cHardwareCPU::Inst_Sleep, nInstFlag::STALL),
@@ -2718,14 +2721,54 @@
bool cHardwareCPU::Inst_RelinquishEnergyToFutureDeme(cAvidaContext& ctx)
{
- double stored_energy = organism->GetPhenotype().GetStoredEnergy();
+ double stored_energy = organism->GetPhenotype().GetStoredEnergy() * m_world->GetConfig().FRAC_ENERGY_RELINQUISH.Get();
// put stored energy into testament pool for offspring deme
- organism->GetOrgInterface().GetDeme()->IncreaseTotalEnergyTestament(stored_energy);
+ cDeme* deme = organism->GetOrgInterface().GetDeme();
+ if(deme == NULL)
+ return false; // in test CPU
+ deme->IncreaseTotalEnergyTestament(stored_energy);
organism->Die();
return true;
}
+bool cHardwareCPU::Inst_RelinquishEnergyToNeighborOrganisms(cAvidaContext& ctx)
+{
+ double stored_energy = organism->GetPhenotype().GetStoredEnergy() * m_world->GetConfig().FRAC_ENERGY_RELINQUISH.Get();
+ // put stored energy into toBeApplied energy pool of neighbor organisms
+ int numOcuppiedNeighbors(0);
+ int orginalFacing = organism->GetFacing();
+ for(int i = 0; i < organism->GetNeighborhoodSize(); i++) {
+ if(organism->IsNeighborCellOccupied()) {
+ // count neighboring organisms
+ numOcuppiedNeighbors++;
+ }
+ organism->Rotate(1);
+ }
+ assert(organism->GetFacing() == orginalFacing);
+ for(int i = 0; i < organism->GetNeighborhoodSize(); i++) {
+ if(organism->IsNeighborCellOccupied()) {
+ // give energy testament to neighboring organisms
+ organism->GetPhenotype().EnergyTestament(stored_energy/numOcuppiedNeighbors);
+ }
+ organism->Rotate(1);
+ }
+ assert(organism->GetFacing() == orginalFacing);
+
+ organism->Die();
+ return true;
+}
+
+bool cHardwareCPU::Inst_RelinquishEnergyToOrganismsInDeme(cAvidaContext& ctx) {
+ double stored_energy = organism->GetPhenotype().GetStoredEnergy() * m_world->GetConfig().FRAC_ENERGY_RELINQUISH.Get();
+ // put stored energy into toBeApplied energy pool of neighbor organisms
+
+ organism->DivideOrgTestamentAmongDeme(stored_energy);
+
+ organism->Die();
+ return true;
+}
+
// The inject instruction can be used instead of a divide command, paired
// with an allocate. Note that for an inject to work, one needs to have a
// broad range for sizes allowed to be allocated.
Modified: branches/jobScheduling/source/cpu/cHardwareCPU.h
===================================================================
--- branches/jobScheduling/source/cpu/cHardwareCPU.h 2008-04-04 14:15:59 UTC (rev 2518)
+++ branches/jobScheduling/source/cpu/cHardwareCPU.h 2008-04-04 19:18:26 UTC (rev 2519)
@@ -435,6 +435,8 @@
bool Inst_Kazi5(cAvidaContext& ctx);
bool Inst_Die(cAvidaContext& ctx);
bool Inst_RelinquishEnergyToFutureDeme(cAvidaContext& ctx);
+ bool Inst_RelinquishEnergyToNeighborOrganisms(cAvidaContext& ctx);
+ bool Inst_RelinquishEnergyToOrganismsInDeme(cAvidaContext& ctx);
// I/O and Sensory
bool Inst_TaskGet(cAvidaContext& ctx);
Modified: branches/jobScheduling/source/cpu/cTestCPUInterface.cc
===================================================================
--- branches/jobScheduling/source/cpu/cTestCPUInterface.cc 2008-04-04 14:15:59 UTC (rev 2518)
+++ branches/jobScheduling/source/cpu/cTestCPUInterface.cc 2008-04-04 19:18:26 UTC (rev 2519)
@@ -41,6 +41,10 @@
return NULL;
}
+bool cTestCPUInterface::IsNeighborCellOccupied() {
+ return false;
+}
+
int cTestCPUInterface::GetNumNeighbors()
{
return 0;
Modified: branches/jobScheduling/source/cpu/cTestCPUInterface.h
===================================================================
--- branches/jobScheduling/source/cpu/cTestCPUInterface.h 2008-04-04 14:15:59 UTC (rev 2518)
+++ branches/jobScheduling/source/cpu/cTestCPUInterface.h 2008-04-04 19:18:26 UTC (rev 2519)
@@ -56,6 +56,7 @@
bool Divide(cAvidaContext& ctx, cOrganism* parent, cGenome& child_genome);
cOrganism* GetNeighbor();
+ bool IsNeighborCellOccupied();
int GetNumNeighbors();
void Rotate(int direction = 1);
void Breakpoint() { ; }
@@ -82,6 +83,8 @@
bool SendMessage(cOrgMessage& msg) { return false; }
bool BcastAlarm(int jump_label) { return false; }
+
+ void DivideOrgTestamentAmongDeme(double value) {;}
};
Modified: branches/jobScheduling/source/main/cAvidaConfig.h
===================================================================
--- branches/jobScheduling/source/main/cAvidaConfig.h 2008-04-04 14:15:59 UTC (rev 2518)
+++ branches/jobScheduling/source/main/cAvidaConfig.h 2008-04-04 19:18:26 UTC (rev 2519)
@@ -470,6 +470,7 @@
CONFIG_ADD_VAR(APPLY_ENERGY_METHOD, int, 0, "When should rewarded energy be applied to current energy?\n0 = on divide\n1 = on completion of task\n2 = on sleep");
CONFIG_ADD_VAR(FRAC_ENERGY_TRANSFER, double, 0.0, "Fraction of replaced organism's energy take by new resident");
CONFIG_ADD_VAR(LOG_SLEEP_TIMES, bool, 0, "Log sleep start and end times. 0/1 (off/on)\nWARNING: may use lots of memory.");
+ CONFIG_ADD_VAR(FRAC_ENERGY_RELINQUISH, double, 1.0, "Fraction of organisms energy to relinquish");
CONFIG_ADD_GROUP(SECOND_PASS_GROUP, "Tracking metrics known after the running experiment previously");
CONFIG_ADD_VAR(TRACK_CCLADES, int, 0, "Enable tracking of coalescence clades");
Modified: branches/jobScheduling/source/main/cDemeCellEvent.cc
===================================================================
--- branches/jobScheduling/source/main/cDemeCellEvent.cc 2008-04-04 14:15:59 UTC (rev 2518)
+++ branches/jobScheduling/source/main/cDemeCellEvent.cc 2008-04-04 19:18:26 UTC (rev 2519)
@@ -72,4 +72,4 @@
assert(max_delay > min_delay);
m_delay = (m_delay % (max_delay - min_delay)) + min_delay;
-}
\ No newline at end of file
+}
Modified: branches/jobScheduling/source/main/cOrgInterface.h
===================================================================
--- branches/jobScheduling/source/main/cOrgInterface.h 2008-04-04 14:15:59 UTC (rev 2518)
+++ branches/jobScheduling/source/main/cOrgInterface.h 2008-04-04 19:18:26 UTC (rev 2519)
@@ -65,6 +65,7 @@
virtual bool Divide(cAvidaContext& ctx, cOrganism* parent, cGenome& child_genome) = 0;
virtual cOrganism* GetNeighbor() = 0;
+ virtual bool IsNeighborCellOccupied() = 0;
virtual int GetNumNeighbors() = 0;
virtual int GetFacing() = 0; //!< Returns the facing of this organism.
virtual void Rotate(int direction = 1) = 0;
@@ -91,6 +92,7 @@
virtual bool SendMessage(cOrgMessage& msg) = 0;
virtual bool BcastAlarm(int jump_jabel) = 0;
+ virtual void DivideOrgTestamentAmongDeme(double value) = 0;
};
Modified: branches/jobScheduling/source/main/cOrganism.h
===================================================================
--- branches/jobScheduling/source/main/cOrganism.h 2008-04-04 14:15:59 UTC (rev 2518)
+++ branches/jobScheduling/source/main/cOrganism.h 2008-04-04 19:18:26 UTC (rev 2519)
@@ -188,6 +188,7 @@
// -------- cOrgInterface Methods --------
cHardwareBase& GetHardware() { return *m_hardware; }
cOrganism* GetNeighbor() { return m_interface->GetNeighbor(); }
+ bool IsNeighborCellOccupied() { return m_interface->IsNeighborCellOccupied(); }
int GetNeighborhoodSize() { return m_interface->GetNumNeighbors(); }
int GetFacing() { assert(m_interface); return m_interface->GetFacing(); } // Returns the facing of this organism.
void Rotate(int direction) { m_interface->Rotate(direction); }
@@ -358,6 +359,8 @@
bool BcastAlarmMSG(cAvidaContext& ctx, int jump_label);
void moveIPtoAlarmLabel(int jump_label);
+
+ void DivideOrgTestamentAmongDeme(double value) { m_interface->DivideOrgTestamentAmongDeme(value); }
};
Modified: branches/jobScheduling/source/main/cPhenotype.h
===================================================================
--- branches/jobScheduling/source/main/cPhenotype.h 2008-04-04 14:15:59 UTC (rev 2518)
+++ branches/jobScheduling/source/main/cPhenotype.h 2008-04-04 19:18:26 UTC (rev 2519)
@@ -457,6 +457,7 @@
void HalfEnergyUsage();
void RefreshEnergy();
void ApplyToEnergyStore();
+ void EnergyTestament(double value) { energy_tobe_applied += value; } //! external energy given to organism
double ExtractParentEnergy();
bool operator<(const cPhenotype& rhs) const;
Modified: branches/jobScheduling/source/main/cPopulationInterface.cc
===================================================================
--- branches/jobScheduling/source/main/cPopulationInterface.cc 2008-04-04 14:15:59 UTC (rev 2518)
+++ branches/jobScheduling/source/main/cPopulationInterface.cc 2008-04-04 19:18:26 UTC (rev 2519)
@@ -69,6 +69,11 @@
return cell.ConnectionList().GetFirst()->GetOrganism();
}
+bool cPopulationInterface::IsNeighborCellOccupied() {
+ cPopulationCell & cell = m_world->GetPopulation().GetCell(m_cell_id);
+ return cell.IsOccupied();
+}
+
int cPopulationInterface::GetNumNeighbors()
{
cPopulationCell & cell = m_world->GetPopulation().GetCell(m_cell_id);
@@ -283,3 +288,14 @@
}
return true;
}
+
+void cPopulationInterface::DivideOrgTestamentAmongDeme(double value){
+ cDeme* deme = GetDeme();
+ for(int i = 0; i < deme->GetSize(); i++) {
+ cPopulationCell& cell = deme->GetCell(i);
+ if(cell.IsOccupied()) {
+ cOrganism* org = cell.GetOrganism();
+ org->GetPhenotype().EnergyTestament(value/deme->GetOrgCount());
+ }
+ }
+}
Modified: branches/jobScheduling/source/main/cPopulationInterface.h
===================================================================
--- branches/jobScheduling/source/main/cPopulationInterface.h 2008-04-04 14:15:59 UTC (rev 2518)
+++ branches/jobScheduling/source/main/cPopulationInterface.h 2008-04-04 19:18:26 UTC (rev 2519)
@@ -67,6 +67,7 @@
bool Divide(cAvidaContext& ctx, cOrganism* parent, cGenome& child_genome);
cOrganism* GetNeighbor();
+ bool IsNeighborCellOccupied();
int GetNumNeighbors();
int GetFacing(); // Returns the facing of this organism.
void Rotate(int direction = 1);
@@ -93,6 +94,8 @@
//! Send a message to the faced organism.
bool SendMessage(cOrgMessage& msg);
bool BcastAlarm(int jump_label);
+
+ void DivideOrgTestamentAmongDeme(double value);
};
More information about the Avida-cvs
mailing list