[Avida-SVN] r2958 - in development/source: actions cpu main
mmcgill at myxo.css.msu.edu
mmcgill at myxo.css.msu.edu
Thu Nov 20 16:07:26 PST 2008
Author: mmcgill
Date: 2008-11-20 19:07:26 -0500 (Thu, 20 Nov 2008)
New Revision: 2958
Modified:
development/source/actions/PrintActions.cc
development/source/cpu/cHardwareCPU.cc
development/source/main/cOrgMessage.cc
development/source/main/cPopulation.cc
development/source/main/cStats.cc
development/source/main/cStats.h
Log:
* added PrintCurrentTaskCounts print task
* fixed problem in energy dontation instructions
* fixed bug where a deme is seeded twice in CompeteDemes and ReplicateDeme
Modified: development/source/actions/PrintActions.cc
===================================================================
--- development/source/actions/PrintActions.cc 2008-11-20 23:15:16 UTC (rev 2957)
+++ development/source/actions/PrintActions.cc 2008-11-21 00:07:26 UTC (rev 2958)
@@ -110,6 +110,7 @@
STATS_OUT_FILE(PrintDemeOrgTasksExeData, deme_org_tasks_exe.dat );
STATS_OUT_FILE(PrintDemeOrgReactionData, deme_org_reactions.dat );
STATS_OUT_FILE(PrintDemeCurrentTaskExeData, deme_cur_task_exe.dat );
+STATS_OUT_FILE(PrintCurrentTaskCounts, curr_task_counts.dat);
STATS_OUT_FILE(PrintGermlineData, germline.dat );
STATS_OUT_FILE(PrintPredicatedMessages, messages.dat );
STATS_OUT_FILE(PrintCellData, cell_data.dat );
@@ -2742,6 +2743,7 @@
action_lib->Register<cActionPrintDemeOrgTasksExeData>("PrintDemeOrgTasksExeData");
action_lib->Register<cActionPrintDemeOrgReactionData>("PrintDemeOrgReactionData");
action_lib->Register<cActionPrintDemeCurrentTaskExeData>("PrintDemeCurrentTaskExeData");
+ action_lib->Register<cActionPrintCurrentTaskCounts>("PrintCurrentTaskCounts");
action_lib->Register<cActionPrintPerDemeGenPerFounderData>("PrintPerDemeGenPerFounderData");
//Coalescence Clade Actions
Modified: development/source/cpu/cHardwareCPU.cc
===================================================================
--- development/source/cpu/cHardwareCPU.cc 2008-11-20 23:15:16 UTC (rev 2957)
+++ development/source/cpu/cHardwareCPU.cc 2008-11-21 00:07:26 UTC (rev 2958)
@@ -3557,6 +3557,9 @@
double energy_given = cur_energy * frac_energy_given;
//update energy store and merit of donor
+#ifdef DEBUG_ENERGY_DONATION
+ cout << " donating " << energy_given << " energy to organism " << to_org->GetID() << endl;
+#endif
organism->GetPhenotype().ReduceEnergy(energy_given);
organism->GetPhenotype().IncreaseEnergyDonated(energy_given);
double senderMerit = cMerit::EnergyToMerit(organism->GetPhenotype().GetStoredEnergy() * organism->GetPhenotype().GetEnergyUsageRatio(), m_world);
@@ -4085,14 +4088,25 @@
{
if(organism->GetCellID() < 0) {
return false;
- }
+ }
+#ifdef DEBUG_ENERGY_DONATION
+ cout << "organism " << organism->GetCellID() << " receiving donated energy (if any)" << endl;
+#endif
if(organism->GetPhenotype().GetEnergyInBufferAmount() > 0) {
+#ifdef DEBUG_ENERGY_DONATION
+ cout << " received " << organism->GetPhenotype().GetEnergyInBufferAmount() << endl;
+#endif
organism->GetPhenotype().ApplyDonatedEnergy();
organism->GetPhenotype().SetHasUsedDonatedEnergy();
double receiverMerit = cMerit::EnergyToMerit(organism->GetPhenotype().GetStoredEnergy() * organism->GetPhenotype().GetEnergyUsageRatio(), m_world);
organism->UpdateMerit(receiverMerit);
}
+#ifdef DEBUG_ENERGY_DONATION
+ else {
+ cout << " no energy to receive!" << endl;
+ }
+#endif
return true;
@@ -4104,21 +4118,50 @@
{
if(organism->GetCellID() < 0) {
return false;
- }
-
+ }
+#ifdef DEBUG_ENERGY_DONATION
+ cout << "organism " << organism->GetCellID() << " donating energy..." << endl;
+#endif
+
const cOrgMessage* msg = organism->RetrieveMessage();
if(msg == 0) {
+#ifdef DEBUG_ENERGY_DONATION
+ cout << " no energy requests" << endl;
+#endif
return false;
}
-
+
+ /* MJM - by this point, the pointer returned by GetSender() may no longer
+ * be any good. Instead, we should use the cell and organism ID of the
+ * message sender to get hold of the sender (if it still exists and hasn't moved)
+ */
+ /*
cOrganism* receiver = msg->GetSender();
// If the requestor no longer exists, should the donor still lose energy???
if( (receiver == NULL) || (receiver->IsDead()) ) {
return false;
}
+ */
+ cPopulationCell senderCell = m_world->GetPopulation().GetCell(msg->GetSenderCellID());
+ if (!senderCell.IsOccupied()) {
+#ifdef DEBUG_ENERGY_DONATION
+ cout << " requestor has died!" << endl;
+#endif
+ // the organism that made the request is gone, we can't donate...
+ return false;
+ }
+ cOrganism* energyReceiver = senderCell.GetOrganism();
+ if (energyReceiver->GetID() != msg->GetSenderOrgID()) {
+#ifdef DEBUG_ENERGY_DONATION
+ cout << " requestor has been replaced!" << endl;
+#endif
+ // some other organism has occupied this cell since the msg was sent,
+ // we can't donate...
+ return false;
+ }
- DoEnergyDonatePercent(receiver, m_world->GetConfig().ENERGY_SHARING_PCT.Get());
+ DoEnergyDonatePercent(energyReceiver, m_world->GetConfig().ENERGY_SHARING_PCT.Get());
organism->GetPhenotype().IncDonates();
organism->GetOrgInterface().GetDeme()->IncEnergyDonationsMade();
organism->GetPhenotype().SetIsEnergyDonor();
@@ -4201,11 +4244,14 @@
{
if(organism->GetCellID() < 0) {
return false;
- }
+ }
+#ifdef DEBUG_ENERGY_DONATION
+ cout << "organism " << organism->GetCellID() << " requesting energy!" << endl;
+#endif
//TODO: BDC: somehow use nop modifiers to pick a multiplier for the amount of energy to request
- cOrgMessage msg = cOrgMessage(organism);
+ cOrgMessage msg(organism);
// Could set the data field of the message to be the multiplier
organism->BroadcastMessage(ctx, msg);
Modified: development/source/main/cOrgMessage.cc
===================================================================
--- development/source/main/cOrgMessage.cc 2008-11-20 23:15:16 UTC (rev 2957)
+++ development/source/main/cOrgMessage.cc 2008-11-21 00:07:26 UTC (rev 2958)
@@ -41,7 +41,7 @@
m_receiverOrgID = recvr->GetID();
m_receiverCellID = recvr->GetCellID();
} else {
- m_receiverOrgID = 0;
- m_receiverCellID = 0; // should this be -1?
+ m_receiverOrgID = -1;
+ m_receiverCellID = -1;
}
-}
+}
\ No newline at end of file
Modified: development/source/main/cPopulation.cc
===================================================================
--- development/source/main/cPopulation.cc 2008-11-20 23:15:16 UTC (rev 2957)
+++ development/source/main/cPopulation.cc 2008-11-21 00:07:26 UTC (rev 2958)
@@ -70,6 +70,10 @@
#include <cmath>
#include <climits>
+/* MJM - required to build under Visual Studio 2005.
+ * Fixes error "'numeric_limits' is not a member of 'std'" */
+#include <limits>
+
using namespace std;
@@ -1166,7 +1170,7 @@
}
}
}
-
+
//re-inject demes with count of 1 back into self
for(int i = 0; i < (int)deme_counts.size(); i++) {
if(deme_counts[i] == 1)
@@ -1437,7 +1441,13 @@
// All done with the germline manipulation; seed each deme.
SeedDeme(source_deme, source_deme.GetGermline().GetLatest());
- SeedDeme(target_deme, target_deme.GetGermline().GetLatest());
+
+ /* MJM - source and target deme could be the same!
+ * Seeding the same deme twice probably shouldn't happen.
+ */
+ if (source_deme.GetDemeID() != target_deme.GetDemeID()) {
+ SeedDeme(target_deme, target_deme.GetGermline().GetLatest());
+ }
} else if(m_world->GetConfig().DEMES_USE_GERMLINE.Get() == 2) {
// @JEB -- New germlines using cGenotype
Modified: development/source/main/cStats.cc
===================================================================
--- development/source/main/cStats.cc 2008-11-20 23:15:16 UTC (rev 2957)
+++ development/source/main/cStats.cc 2008-11-21 00:07:26 UTC (rev 2958)
@@ -1771,6 +1771,23 @@
df.Endl();
}
+void cStats::PrintCurrentTaskCounts(const cString& filename) {
+ ofstream& fp = m_world->GetDataFileOFStream(filename);
+ fp << "Update " << m_world->GetStats().GetUpdate() << ":" << endl;
+ for (int y = 0; y < m_world->GetPopulation().GetWorldY(); y++) {
+ for (int x = 0; x < m_world->GetPopulation().GetWorldX(); x++) {
+ cPopulationCell& cell = m_world->GetPopulation().GetCell(y * m_world->GetPopulation().GetWorldX() + x);
+ if (cell.IsOccupied()) {
+ fp << cell.GetOrganism()->GetPhenotype().GetCurTaskCount()[0] << "\t";
+ } else {
+ fp << "---\t";
+ }
+ }
+ fp << endl;
+ }
+ fp << endl;
+}
+
void cStats::PrintDemeOrgReactionData(const cString& filename){
cDataFile& df = m_world->GetDataFile(filename);
df.WriteComment("Avida deme org reactions data");
Modified: development/source/main/cStats.h
===================================================================
--- development/source/main/cStats.h 2008-11-20 23:15:16 UTC (rev 2957)
+++ development/source/main/cStats.h 2008-11-21 00:07:26 UTC (rev 2958)
@@ -847,6 +847,7 @@
void PrintDemeOrgTasksExeData(const cString& filename);
void PrintDemeOrgReactionData(const cString& filename);
void PrintDemeCurrentTaskExeData(const cString& filename);
+ void PrintCurrentTaskCounts(const cString& filename);
void PrintPerDemeGenPerFounderData(const cString& filename);
void IncNumOccupiedDemes() { m_num_occupied_demes++; }
More information about the Avida-cvs
mailing list