[Avida-cvs] [avida-svn] r1009 - in branches/coopcomm/source: actions classification main

beckma24 at myxo.css.msu.edu beckma24 at myxo.css.msu.edu
Thu Sep 28 14:12:34 PDT 2006


Author: beckma24
Date: 2006-09-28 17:12:34 -0400 (Thu, 28 Sep 2006)
New Revision: 1009

Modified:
   branches/coopcomm/source/actions/PopulationActions.cc
   branches/coopcomm/source/actions/PrintActions.cc
   branches/coopcomm/source/actions/SaveLoadActions.cc
   branches/coopcomm/source/classification/cClassificationManager.cc
   branches/coopcomm/source/classification/cClassificationManager.h
   branches/coopcomm/source/main/cOrganism.cc
   branches/coopcomm/source/main/cOrganism.h
Log:
Added SaveLastSentTo action

Modified: branches/coopcomm/source/actions/PopulationActions.cc
===================================================================
--- branches/coopcomm/source/actions/PopulationActions.cc	2006-09-27 21:02:30 UTC (rev 1008)
+++ branches/coopcomm/source/actions/PopulationActions.cc	2006-09-28 21:12:34 UTC (rev 1009)
@@ -1210,9 +1210,7 @@
   
   void Process(cAvidaContext& ctx)
   {
-    std::cerr<<baseStation<<endl;
     m_world->GetPopulation().AddBaseStation(baseStation);
-    std::cerr<<baseStation<<endl;
   }
 };
 

Modified: branches/coopcomm/source/actions/PrintActions.cc
===================================================================
--- branches/coopcomm/source/actions/PrintActions.cc	2006-09-27 21:02:30 UTC (rev 1008)
+++ branches/coopcomm/source/actions/PrintActions.cc	2006-09-28 21:12:34 UTC (rev 1009)
@@ -73,6 +73,7 @@
 STATS_OUT_FILE(PrintMessageDataPerUpdate, message.dat);
 STATS_OUT_FILE(PrintMessageSnapshot, msg_snapshot.dat);
 
+
 #define POP_OUT_FILE(METHOD, DEFAULT)                                                     /*  1 */ \
 class cAction ## METHOD : public cAction {                                                /*  2 */ \
 private:                                                                                  /*  3 */ \

Modified: branches/coopcomm/source/actions/SaveLoadActions.cc
===================================================================
--- branches/coopcomm/source/actions/SaveLoadActions.cc	2006-09-27 21:02:30 UTC (rev 1008)
+++ branches/coopcomm/source/actions/SaveLoadActions.cc	2006-09-28 21:12:34 UTC (rev 1009)
@@ -303,6 +303,36 @@
   }
 };
 
+/**
+Written by Ben Beckmann
+
+Writes a file containing the cell ID of the last organisms every organism has sent a message to.
+**/
+class cActionSaveLastCellSentTo : public cAction
+{
+private:
+  cString m_filename;
+  
+public:
+  cActionSaveLastCellSentTo(cWorld* world, const cString& args) : cAction(world, args), m_filename("")
+  {
+    cString largs(args);
+    if (largs.GetSize()) m_filename = largs.PopWord();
+  }
+  
+  static const cString GetDescription() { return "Arguments: [string fname='']"; }
+  
+  void Process(cAvidaContext& ctx)
+  {
+    cString filename(m_filename);
+    if (filename == "") filename.Set("lastSentTo-%d.pop", m_world->GetStats().GetUpdate());
+    m_world->GetClassificationManager().DumpLastSentToSummary(m_world->GetDataFileOFStream(filename));
+    m_world->GetDataFileManager().Remove(filename);
+  }
+};
+
+
+
 void RegisterSaveLoadActions(cActionLibrary* action_lib)
 {
   action_lib->Register<cActionSaveClone>("SaveClone");
@@ -316,6 +346,10 @@
   action_lib->Register<cActionSaveParasitePopulation>("SaveParasitePopulation");
   action_lib->Register<cActionSaveHistoricPopulation>("SaveHistoricPopulation");
   action_lib->Register<cActionSaveHistoricSexPopulation>("SaveHistoricSexPopulation");
+  action_lib->Register<cActionSaveLastCellSentTo>("SaveLastCellSentTo");
+  
+  //coopcomm
+  action_lib->Register<cActionSaveLastCellSentTo>("SaveLastSentTo");
 
   // @DMB - The following actions are DEPRECATED aliases - These will be removed in 2.7.
   action_lib->Register<cActionSaveClone>("save_clone");

Modified: branches/coopcomm/source/classification/cClassificationManager.cc
===================================================================
--- branches/coopcomm/source/classification/cClassificationManager.cc	2006-09-27 21:02:30 UTC (rev 1008)
+++ branches/coopcomm/source/classification/cClassificationManager.cc	2006-09-28 21:12:34 UTC (rev 1009)
@@ -700,6 +700,29 @@
   return true;
 }
 
+/**
+Written by Ben Beckmann
+
+Writes out pairs (sender cell ID, last cell sent to ID)
+**/
+#include "cPopulation.h"
+#include "cPopulationCell.h"
+bool cClassificationManager::DumpLastSentToSummary(ofstream& fp)
+{
+  fp << "# 1: Cell ID of sender\n # 2: Cell ID of receiver\n";
+  for (int i = 0; i < (m_world->GetConfig().WORLD_X.Get() * m_world->GetConfig().WORLD_Y.Get()); i++) {
+    cOrganism* org = m_world->GetPopulation().GetCell(i).GetOrganism();
+    if(org != NULL)
+      fp << i << " " << org->getLastSent() <<endl;
+    else
+      fp << i << " -3\n";
+  }
+  
+  return true;
+}
+
+
+
 void cClassificationManager::DumpDetailHeading (ofstream& fp)
 {
   fp << "#filetype genotype_data" << endl

Modified: branches/coopcomm/source/classification/cClassificationManager.h
===================================================================
--- branches/coopcomm/source/classification/cClassificationManager.h	2006-09-27 21:02:30 UTC (rev 1008)
+++ branches/coopcomm/source/classification/cClassificationManager.h	2006-09-28 21:12:34 UTC (rev 1009)
@@ -186,6 +186,9 @@
   bool SaveClone(std::ofstream& fp);
   bool LoadClone(std::ifstream & fp);
   bool OK();  
+  
+  // coopcomm output
+  bool DumpLastSentToSummary(std::ofstream& fp);
 };
 
 

Modified: branches/coopcomm/source/main/cOrganism.cc
===================================================================
--- branches/coopcomm/source/main/cOrganism.cc	2006-09-27 21:02:30 UTC (rev 1008)
+++ branches/coopcomm/source/main/cOrganism.cc	2006-09-28 21:12:34 UTC (rev 1009)
@@ -57,6 +57,7 @@
   , received_messages(RECEIVED_MESSAGES_SIZE)
   , is_running(false)
   , m_retrieve_pos(0)
+  , last_cell_sent_to(-1)
 {
   // Initialization of structures...
   m_hardware = m_world->GetHardwareManager().Create(this);
@@ -542,6 +543,8 @@
   assert(m_interface);
   m_world->GetStats().IncSent();
   if(m_interface->SendMessage(msg)) {
+  
+    last_cell_sent_to = msg.GetReceiver()->GetCellID();
     // Stat-tracking.
     m_world->GetStats().SentMessage(msg);
 
@@ -605,6 +608,7 @@
     inserted_msg.first->second.SetReceiver(NULL);
     return true;
   } else {
+    last_cell_sent_to = -2; //no organism received sent message
     return false;
   }
 }

Modified: branches/coopcomm/source/main/cOrganism.h
===================================================================
--- branches/coopcomm/source/main/cOrganism.h	2006-09-27 21:02:30 UTC (rev 1008)
+++ branches/coopcomm/source/main/cOrganism.h	2006-09-28 21:12:34 UTC (rev 1009)
@@ -148,6 +148,7 @@
   t_message_list::size_type m_retrieve_pos; //!< Index of the message that will be returned on next RetrieveMessage().
   t_sorted_messages m_sorted_recv_messages; //!< Sorted map of received messages.
   t_sorted_messages m_sorted_sent_messages; //!< Sorted map of sent messages.
+  int last_cell_sent_to;
   
   cOrganism(); // @not_implemented
   cOrganism(const cOrganism&); // @not_implemented
@@ -307,6 +308,8 @@
   void GetPosition(int& x, int& y) { assert(m_interface); m_interface->GetPosition(x, y); }
   //! Returns the facing of this organism.
   int GetFacing() { assert(m_interface); return m_interface->GetFacing(); }
+  //!
+  int getLastSent(){ return last_cell_sent_to; }
 };
 
 




More information about the Avida-cvs mailing list