[Avida-SVN] r2897 - in development/source: cpu main
connel42 at myxo.css.msu.edu
connel42 at myxo.css.msu.edu
Thu Oct 30 12:24:04 PDT 2008
Author: connel42
Date: 2008-10-30 15:24:03 -0400 (Thu, 30 Oct 2008)
New Revision: 2897
Modified:
development/source/cpu/cHardwareCPU.cc
development/source/main/cAvidaConfig.h
development/source/main/cDeme.cc
development/source/main/cDeme.h
development/source/main/cPhenotype.cc
development/source/main/cPhenotype.h
development/source/main/cPopulation.cc
Log:
Moved all energy-related values to doubles (some were ints). Added energy sharing/donating stat variables to the phenotype
Modified: development/source/cpu/cHardwareCPU.cc
===================================================================
--- development/source/cpu/cHardwareCPU.cc 2008-10-29 15:19:26 UTC (rev 2896)
+++ development/source/cpu/cHardwareCPU.cc 2008-10-30 19:24:03 UTC (rev 2897)
@@ -221,6 +221,7 @@
tInstLibEntry<tMethod>("donate-facing", &cHardwareCPU::Inst_DonateFacing, nInstFlag::STALL),
tInstLibEntry<tMethod>("receive-donated-energy", &cHardwareCPU::Inst_ReceiveDonatedEnergy, nInstFlag::STALL),
tInstLibEntry<tMethod>("donate-energy", &cHardwareCPU::Inst_DonateEnergy, nInstFlag::STALL),
+ tInstLibEntry<tMethod>("request-energy", &cHardwareCPU::Inst_RequestEnergy, nInstFlag::STALL),
tInstLibEntry<tMethod>("IObuf-add1", &cHardwareCPU::Inst_IOBufAdd1, nInstFlag::STALL),
tInstLibEntry<tMethod>("IObuf-add0", &cHardwareCPU::Inst_IOBufAdd0, nInstFlag::STALL),
@@ -3399,6 +3400,7 @@
//place energy into receiver's incoming energy buffer
to_org->GetPhenotype().ReceiveDonatedEnergy(energy_given);
to_org->GetPhenotype().IncreaseEnergyReceived(energy_given);
+ GetOrganism()->GetOrgInterface().GetDeme()->IncEnergyDonationsMade();
//if we are using the push energy method, pass the new energy into the receiver's energy store and recalculate merit
if(m_world->GetConfig().ENERGY_SHARING_METHOD.Get() == 1) {
@@ -3951,6 +3953,7 @@
//Note: could get fancier about fraction of energy to send
DoEnergyDonatePercent(receiver, m_world->GetConfig().MERIT_GIVEN.Get());
organism->GetPhenotype().IncDonates();
+ GetOrganism()->GetOrgInterface().GetDeme()->IncEnergyDonationsMade();
return true;
@@ -3970,6 +3973,7 @@
// Could set the data field of the message to be the multiplier
organism->BroadcastMessage(ctx, msg);
+ GetOrganism()->GetOrgInterface().GetDeme()->IncEnergyRequestsMade();
return true;
Modified: development/source/main/cAvidaConfig.h
===================================================================
--- development/source/main/cAvidaConfig.h 2008-10-29 15:19:26 UTC (rev 2896)
+++ development/source/main/cAvidaConfig.h 2008-10-30 19:24:03 UTC (rev 2897)
@@ -479,14 +479,14 @@
CONFIG_ADD_GROUP(ENERGY_GROUP, "Energy Settings");
CONFIG_ADD_VAR(ENERGY_ENABLED, bool, 0, "Enable Energy Model. 0/1 (off/on)");
- CONFIG_ADD_VAR(ENERGY_GIVEN_ON_INJECT, int, 0, "Energy given to organism upon injection.");
- CONFIG_ADD_VAR(ENERGY_GIVEN_AT_BIRTH, int, 0, "Energy given to offspring upon birth.");
+ CONFIG_ADD_VAR(ENERGY_GIVEN_ON_INJECT, double, 0.0, "Energy given to organism upon injection.");
+ CONFIG_ADD_VAR(ENERGY_GIVEN_AT_BIRTH, double, 0.0, "Energy given to offspring upon birth.");
CONFIG_ADD_VAR(FRAC_PARENT_ENERGY_GIVEN_TO_ORG_AT_BIRTH, double, 0.5, "Fraction of parent's energy given to offspring organism.");
CONFIG_ADD_VAR(FRAC_PARENT_ENERGY_GIVEN_TO_DEME_AT_BIRTH, double, 0.5, "Fraction of parent's energy given to offspring deme.");
CONFIG_ADD_VAR(FRAC_ENERGY_DECAY_AT_ORG_BIRTH, double, 0.0, "Fraction of energy lost due to decay during organism reproduction.");
CONFIG_ADD_VAR(FRAC_ENERGY_DECAY_AT_DEME_BIRTH, double, 0.0, "Fraction of energy lost due to decay during deme reproduction.");
CONFIG_ADD_VAR(NUM_INST_EXC_BEFORE_0_ENERGY, int, 0, "Number of instructions executed before energy is exhausted.");
- CONFIG_ADD_VAR(ENERGY_CAP, int, -1, "Maximum amount of energy that can be stored in an organism. -1 means the cap is set to Max Int"); // TODO - is this done?
+ CONFIG_ADD_VAR(ENERGY_CAP, double, -1.0, "Maximum amount of energy that can be stored in an organism. -1 means the cap is set to Max Int"); // TODO - is this done?
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.");
Modified: development/source/main/cDeme.cc
===================================================================
--- development/source/main/cDeme.cc 2008-10-29 15:19:26 UTC (rev 2896)
+++ development/source/main/cDeme.cc 2008-10-30 19:24:03 UTC (rev 2897)
@@ -73,6 +73,9 @@
last_org_task_exe_count.SetAll(0);
last_org_reaction_count.ResizeClear(num_reactions);
last_org_reaction_count.SetAll(0);
+
+ energy_requests_made = 0;
+ energy_donations_made = 0;
// If width is negative, set it to the full number of cells.
width = in_width;
Modified: development/source/main/cDeme.h
===================================================================
--- development/source/main/cDeme.h 2008-10-29 15:19:26 UTC (rev 2896)
+++ development/source/main/cDeme.h 2008-10-30 19:24:03 UTC (rev 2897)
@@ -65,7 +65,7 @@
int birth_count_perslot;
int _age; //!< Age of this deme, in updates.
int generation; //!< Generation of this deme
- double total_org_energy; //! total amount of energy in organisms in this deme
+ double total_org_energy; //! amount of energy in organisms in this deme
int time_used; //!< number of cpu cycles this deme has used
int gestation_time; // Time used during last generation
double cur_normalized_time_used; // normalized by merit and number of orgs
@@ -83,6 +83,8 @@
unsigned int consecutiveSuccessfulEventPeriods;
int sleeping_count; //!< Number of organisms currently sleeping
cDoubleSum energyUsage;
+ unsigned int energy_requests_made;
+ unsigned int energy_donations_made;
tArray<int> cur_task_exe_count;
tArray<int> cur_reaction_count;
@@ -299,7 +301,10 @@
unsigned int GetMessageSuccessfullySent() { return MSG_SuccessfullySent; }
unsigned int GetMessageDropped() { return MSG_dropped; }
unsigned int GetMessageSendFailed() { return MSG_sendFailed; }
-
+
+ // --- Energy sharing stats --- //
+ void IncEnergyRequestsMade() { energy_requests_made++; }
+ void IncEnergyDonationsMade() { energy_donations_made++; }
// --- Pheromones --- //
void AddPheromone(int absolute_cell_id, double value);
Modified: development/source/main/cPhenotype.cc
===================================================================
--- development/source/main/cPhenotype.cc 2008-10-29 15:19:26 UTC (rev 2896)
+++ development/source/main/cPhenotype.cc 2008-10-30 19:24:03 UTC (rev 2897)
@@ -274,7 +274,7 @@
else
executionRatio = parent_phenotype.executionRatio;
- energy_store = min(energy_store, (double) m_world->GetConfig().ENERGY_CAP.Get());
+ energy_store = min(energy_store, m_world->GetConfig().ENERGY_CAP.Get());
energy_tobe_applied = 0.0;
energy_testament = 0.0;
energy_received_buffer = 0.0;
@@ -1220,7 +1220,7 @@
}
void cPhenotype::SetEnergy(const double value) {
- energy_store = max(0.0, min(value, (double) m_world->GetConfig().ENERGY_CAP.Get()));
+ energy_store = max(0.0, min(value, m_world->GetConfig().ENERGY_CAP.Get()));
}
void cPhenotype::DoubleEnergyUsage() {
@@ -1272,6 +1272,14 @@
void cPhenotype::ApplyDonatedEnergy() {
+ double energy_cap = m_world->GetConfig().ENERGY_CAP.Get();
+
+ if((energy_store + energy_received_buffer) >= energy_cap) {
+ IncreaseEnergyApplied(energy_cap - energy_store);
+ } else {
+ IncreaseEnergyApplied(energy_received_buffer);
+ }
+
SetEnergy(energy_store + energy_received_buffer);
energy_received_buffer = 0.0;
} //End AppplyDonatedEnergy()
@@ -1290,7 +1298,7 @@
double energy_given_at_birth = m_world->GetConfig().ENERGY_GIVEN_AT_BIRTH.Get();
double frac_parent_energy_given_at_birth = m_world->GetConfig().FRAC_PARENT_ENERGY_GIVEN_TO_ORG_AT_BIRTH.Get();
double frac_energy_decay_at_birth = m_world->GetConfig().FRAC_ENERGY_DECAY_AT_ORG_BIRTH.Get();
- double energy_cap = (double) m_world->GetConfig().ENERGY_CAP.Get();
+ double energy_cap = m_world->GetConfig().ENERGY_CAP.Get();
// apply energy if APPLY_ENERGY_METHOD is set to "on divide" (0)
if(m_world->GetConfig().APPLY_ENERGY_METHOD.Get() == 0) {
Modified: development/source/main/cPhenotype.h
===================================================================
--- development/source/main/cPhenotype.h 2008-10-29 15:19:26 UTC (rev 2896)
+++ development/source/main/cPhenotype.h 2008-10-30 19:24:03 UTC (rev 2897)
@@ -113,6 +113,7 @@
double energy_received_buffer; // Energy received through donation, but not yet applied to energy store
double total_energy_donated; // Tota amount of energy that has been donated
double total_energy_received; // Total amount of energy received through donations
+ double total_energy_applied; // Total amount of received energy applied to energy store
int cur_num_errors; // Total instructions executed illeagally.
int cur_num_donates; // Number of donations so far
tArray<int> cur_task_count; // Total times each task was performed
@@ -429,6 +430,7 @@
void SetToDelete() { to_delete = true; }
void IncreaseEnergyDonated(double amount) { assert(amount >=0); total_energy_donated += amount; }
void IncreaseEnergyReceived(double amount) { assert(amount >=0); total_energy_received += amount; }
+ void IncreaseEnergyApplied(double amount) { assert(amount >=0); total_energy_applied += amount; }
void SetIsDonorCur() { is_donor_cur = true; }
void SetIsDonorRand() { SetIsDonorCur(); is_donor_rand = true; }
Modified: development/source/main/cPopulation.cc
===================================================================
--- development/source/main/cPopulation.cc 2008-10-29 15:19:26 UTC (rev 2896)
+++ development/source/main/cPopulation.cc 2008-10-30 19:24:03 UTC (rev 2897)
@@ -92,7 +92,7 @@
const int geometry = world->GetConfig().WORLD_GEOMETRY.Get();
if(m_world->GetConfig().ENERGY_CAP.Get() == -1) {
- m_world->GetConfig().ENERGY_CAP.Set(INT_MAX);
+ m_world->GetConfig().ENERGY_CAP.Set(std::numeric_limits<double>::max());
}
if(m_world->GetConfig().LOG_SLEEP_TIMES.Get() == 1) {
More information about the Avida-cvs
mailing list