[Avida-cvs] [avida-svn] r1007 - in branches/coopcomm: source/cpu source/main source/tools support/config

dknoester at myxo.css.msu.edu dknoester at myxo.css.msu.edu
Wed Sep 27 13:31:04 PDT 2006


Author: dknoester
Date: 2006-09-27 16:31:04 -0400 (Wed, 27 Sep 2006)
New Revision: 1007

Modified:
   branches/coopcomm/source/cpu/cTestCPUInterface.h
   branches/coopcomm/source/main/cAvidaConfig.h
   branches/coopcomm/source/main/cOrgInterface.h
   branches/coopcomm/source/main/cOrgMessage.h
   branches/coopcomm/source/main/cOrganism.h
   branches/coopcomm/source/main/cPopulationCell.cc
   branches/coopcomm/source/main/cPopulationCell.h
   branches/coopcomm/source/main/cPopulationInterface.cc
   branches/coopcomm/source/main/cPopulationInterface.h
   branches/coopcomm/source/main/cStats.h
   branches/coopcomm/source/tools/cDataFile.cc
   branches/coopcomm/source/tools/cDataFile.h
   branches/coopcomm/support/config/avida.cfg
Log:
Two things here:
First, cOrgMessage is now completely unsigned, as per discussions with McKinley.  This does not affect the operation of the CPUs (which are signed, internally), but it does affect things like mean value of data fields, etc.

Second, there's a new configuration option that sets the probability that inserting an organism into a cell will reset the cell's ID.



Modified: branches/coopcomm/source/cpu/cTestCPUInterface.h
===================================================================
--- branches/coopcomm/source/cpu/cTestCPUInterface.h	2006-09-27 19:08:29 UTC (rev 1006)
+++ branches/coopcomm/source/cpu/cTestCPUInterface.h	2006-09-27 20:31:04 UTC (rev 1007)
@@ -56,7 +56,7 @@
   bool TestOnDivide() { return false; }
 
   bool SendMessage(cOrgMessage& mess) { return false; }
-  int GetRandomCellID() { return 0; }
+  unsigned int GetRandomCellID() { return 0; }
   void GetPosition(int& x, int& y) { }
   int GetFacing() { return 0; }
 };

Modified: branches/coopcomm/source/main/cAvidaConfig.h
===================================================================
--- branches/coopcomm/source/main/cAvidaConfig.h	2006-09-27 19:08:29 UTC (rev 1006)
+++ branches/coopcomm/source/main/cAvidaConfig.h	2006-09-27 20:31:04 UTC (rev 1007)
@@ -276,6 +276,10 @@
   CONFIG_ADD_VAR(BUY_PRICE, int, 0, "price offered by organisms attempting to buy");
   CONFIG_ADD_VAR(SELL_PRICE, int, 0, "price offered by organisms attempting to sell");
 
+  // Coop-comm
+  CONFIG_ADD_GROUP(COOP_COMM_GROUP, "Cooperative Communications Group");
+  CONFIG_ADD_VAR(CELL_ID_RESET_PROB, double, 0.0, "Probability that a cell's random ID will be reset when an organism is inserted.");
+  
 #endif
   
   void Load(const cString& filename);

Modified: branches/coopcomm/source/main/cOrgInterface.h
===================================================================
--- branches/coopcomm/source/main/cOrgInterface.h	2006-09-27 19:08:29 UTC (rev 1006)
+++ branches/coopcomm/source/main/cOrgInterface.h	2006-09-27 20:31:04 UTC (rev 1007)
@@ -56,7 +56,7 @@
   virtual bool TestOnDivide() = 0;
 
   virtual bool SendMessage(cOrgMessage& msg) = 0; //!< Sends a message to the organism that is currently faced.
-  virtual int GetRandomCellID() = 0; //!< Returns the random cell ID for the cell in which this organism lives.
+  virtual unsigned int GetRandomCellID() = 0; //!< Returns the random cell ID for the cell in which this organism lives.
   virtual void GetPosition(int& x, int& y) = 0; //!< Retrieves the position (x,y) coordinates of this organism.
   virtual int GetFacing() = 0; //!< Returns the facing of this organism.
 };

Modified: branches/coopcomm/source/main/cOrgMessage.h
===================================================================
--- branches/coopcomm/source/main/cOrgMessage.h	2006-09-27 19:08:29 UTC (rev 1006)
+++ branches/coopcomm/source/main/cOrgMessage.h	2006-09-27 20:31:04 UTC (rev 1007)
@@ -20,8 +20,8 @@
 private:
   cOrganism* m_pSender;
   cOrganism* m_pReceiver;
-  int m_data;
-  int m_label;
+  unsigned int m_data;
+  unsigned int m_label;
   
   cOrgMessage() : m_pSender(NULL), m_pReceiver(NULL), m_data(0), m_label(0) { }
   
@@ -44,11 +44,11 @@
   cOrganism* GetReceiver() { return m_pReceiver; }
   void SetReceiver(cOrganism* recvr) { m_pReceiver = recvr; }
   
-  int GetData() const { return m_data; }
-  int GetLabel() const { return m_label; }
+  unsigned int GetData() const { return m_data; }
+  unsigned int GetLabel() const { return m_label; }
 
-  void SetData(int data) { m_data = data; }
-  void SetLabel(int label) { m_label = label; }
+  void SetData(unsigned int data) { m_data = data; }
+  void SetLabel(unsigned int label) { m_label = label; }
 };
 
 

Modified: branches/coopcomm/source/main/cOrganism.h
===================================================================
--- branches/coopcomm/source/main/cOrganism.h	2006-09-27 19:08:29 UTC (rev 1006)
+++ branches/coopcomm/source/main/cOrganism.h	2006-09-27 20:31:04 UTC (rev 1007)
@@ -84,7 +84,7 @@
   // case, only ONE of each unique data field is kept, and it is the most recently
   // received.  This may change in future versions.
   typedef std::vector<cOrgMessage> t_message_list; //!< Container for cOrgMessages.
-  typedef std::map<int, cOrgMessage> t_sorted_messages; //!< A sorted container for cOrgMessages.
+  typedef std::map<unsigned int, cOrgMessage> t_sorted_messages; //!< A sorted container for cOrgMessages.
   
 protected:
   cWorld* m_world;
@@ -294,7 +294,7 @@
   //!< Called when this organism attempts to move a received message into its CPU.
   const cOrgMessage* RetrieveMessage();
   //! Returns the random cell ID for the cell in which this organism lives.
-  int GetRandomCellID() const { assert(m_interface); return m_interface->GetRandomCellID(); }
+  unsigned int GetRandomCellID() const { assert(m_interface); return m_interface->GetRandomCellID(); }
   //! Returns the list of all messsages received by this organism.
   t_message_list& GetReceivedMessages() { return m_received_messages; }
   //! Returns the list of all messages sent by this organism.

Modified: branches/coopcomm/source/main/cPopulationCell.cc
===================================================================
--- branches/coopcomm/source/main/cPopulationCell.cc	2006-09-27 19:08:29 UTC (rev 1006)
+++ branches/coopcomm/source/main/cPopulationCell.cc	2006-09-27 20:31:04 UTC (rev 1007)
@@ -70,7 +70,7 @@
   cell_id = in_id;
   m_x = x;
   m_y = y;
-  m_rand_id = m_world->GetRandom().GetUInt(INT_MAX);
+  m_rand_id = m_world->GetRandom().GetUInt(UINT_MAX);
   s_rand_ids.insert(std::make_pair(m_rand_id, this));
   
   if (mutation_rates == NULL)
@@ -113,6 +113,9 @@
   return input_array[id];
 }
 
+
+/*!
+*/
 void cPopulationCell::InsertOrganism(cOrganism & new_org)
 {
   assert(&new_org != NULL);
@@ -125,6 +128,12 @@
 
   // Adjust the organism's attributes to match this cell.
   organism->GetOrgInterface().SetCellID(cell_id);
+  
+  // Now, depending on configuration, possibly reset this cell's random ID.
+  double reset_id = m_world->GetConfig().CELL_ID_RESET_PROB.Get();
+  if(reset_id > 0.0 && m_world->GetRandom().P(reset_id)) {
+    ResetRandomID();
+  }
 }
 
 cOrganism * cPopulationCell::RemoveOrganism()
@@ -148,7 +157,7 @@
 /*! Returns the current maximum random cell ID.  If there is no current maximum,
 0 is returned.
 */
-int cPopulationCell::GetMaxRandomCellID()
+unsigned int cPopulationCell::GetMaxRandomCellID()
 {
   if(s_rand_ids.size()==0) return 0;
   
@@ -201,6 +210,6 @@
 void cPopulationCell::ResetRandomID()
 {
   s_rand_ids.erase(m_rand_id);
-  m_rand_id = m_world->GetRandom().GetUInt(INT_MAX);
+  m_rand_id = m_world->GetRandom().GetUInt(UINT_MAX);
   s_rand_ids.insert(std::make_pair(m_rand_id, this));
 }

Modified: branches/coopcomm/source/main/cPopulationCell.h
===================================================================
--- branches/coopcomm/source/main/cPopulationCell.h	2006-09-27 19:08:29 UTC (rev 1006)
+++ branches/coopcomm/source/main/cPopulationCell.h	2006-09-27 20:31:04 UTC (rev 1007)
@@ -33,7 +33,7 @@
 {
 public:
   friend class cPopulation;
-  typedef std::map<int,cPopulationCell*> t_id_map;
+  typedef std::map<unsigned int,cPopulationCell*> t_id_map;
   
 private:
   cWorld* m_world;
@@ -46,7 +46,7 @@
   int cell_id;           // Unique id for position of cell in population.
   int organism_count;    // Total number of orgs to ever inhabit this cell.
 
-  int m_rand_id; //!< Random identifier for this cell.
+  unsigned int m_rand_id; //!< Random identifier for this cell.
   static t_id_map s_rand_ids; //!< Container for m_rand_id -> cell* mappings.
   
   int m_x; //!< The x-coordinate of the position of this cell in the environment.
@@ -80,15 +80,15 @@
   bool OK();
   
   //! Returns the random ID for this cell.
-  int GetRandomCellID() const { return m_rand_id; }
+  unsigned int GetRandomCellID() const { return m_rand_id; }
   //!< Retrieves the position (x,y) coordinates of this cell.
   void GetPosition(int& x, int& y) { x = m_x; y = m_y; }
   //!< Returns the facing of this cell.
   int GetFacing();
   //! Returns a boolean representing whether or not the given ID belongs to a cell.
-  static int IsRandomCellID(int id) { return s_rand_ids.find(id)!=s_rand_ids.end(); }
+  static unsigned int IsRandomCellID(unsigned int id) { return s_rand_ids.find(id)!=s_rand_ids.end(); }
   //! Returns the current maximum random cell ID.
-  static int GetMaxRandomCellID();
+  static unsigned int GetMaxRandomCellID();
   //! Reset this cell's random ID.
   void ResetRandomID();  
 };

Modified: branches/coopcomm/source/main/cPopulationInterface.cc
===================================================================
--- branches/coopcomm/source/main/cPopulationInterface.cc	2006-09-27 19:08:29 UTC (rev 1006)
+++ branches/coopcomm/source/main/cPopulationInterface.cc	2006-09-27 20:31:04 UTC (rev 1007)
@@ -216,7 +216,7 @@
 }
 
 
-int cPopulationInterface::GetRandomCellID()
+unsigned int cPopulationInterface::GetRandomCellID()
 {
 	cPopulationCell& cell = m_world->GetPopulation().GetCell(m_cell_id);
 	assert(cell.IsOccupied());

Modified: branches/coopcomm/source/main/cPopulationInterface.h
===================================================================
--- branches/coopcomm/source/main/cPopulationInterface.h	2006-09-27 19:08:29 UTC (rev 1006)
+++ branches/coopcomm/source/main/cPopulationInterface.h	2006-09-27 20:31:04 UTC (rev 1007)
@@ -66,7 +66,7 @@
   //!< Sends a message to the organism that is currently faced.
   bool SendMessage(cOrgMessage& msg);
   //!< Returns the random cell ID for the cell in which this organism lives.
-  int GetRandomCellID();
+  unsigned int GetRandomCellID();
   //!< Retrieves the position (x,y) coordinates of this organism.
   void GetPosition(int& x, int& y);
   //!< Returns the facing of this organism.

Modified: branches/coopcomm/source/main/cStats.h
===================================================================
--- branches/coopcomm/source/main/cStats.h	2006-09-27 19:08:29 UTC (rev 1006)
+++ branches/coopcomm/source/main/cStats.h	2006-09-27 20:31:04 UTC (rev 1007)
@@ -243,14 +243,14 @@
   int num_own_used;
 
   // Stats for coop-comm.
-  int m_count_org_died; //!< Count of the number of organisms that died.
-  int m_count_msgs; //!< Count of the number of messages sent.
+  unsigned int m_count_org_died; //!< Count of the number of organisms that died.
+  unsigned int m_count_msgs; //!< Count of the number of messages sent.
   cDoubleSum m_msg_data; //!< Sum of all message data fields.
-  int m_max_id; //!< The maximum ID in the population.
-  int m_data_is_id; //!< Count of messages where the data field carries an ID.
-  int m_data_is_sender; //!< Count of messages where the data field carries the sender's ID.
-  int m_data_is_id_and_grt_sender; //!< Count of messages where the data field carries an ID, and is greater than the sender's ID.
-  int m_data_is_leader; //!< Count of messages where the data field is the leader's ID.
+  unsigned int m_max_id; //!< The maximum ID in the population.
+  unsigned int m_data_is_id; //!< Count of messages where the data field carries an ID.
+  unsigned int m_data_is_sender; //!< Count of messages where the data field carries the sender's ID.
+  unsigned int m_data_is_id_and_grt_sender; //!< Count of messages where the data field carries an ID, and is greater than the sender's ID.
+  unsigned int m_data_is_leader; //!< Count of messages where the data field is the leader's ID.
   cDoubleSum m_data_is_id_not_sender; //!< Sum of message data fields where the data field is an ID that is not the sender's ID.
   std::set<int> m_cell_sent_leader; //!< Set of all cells that sent a message carrying the leader's ID.
   

Modified: branches/coopcomm/source/tools/cDataFile.cc
===================================================================
--- branches/coopcomm/source/tools/cDataFile.cc	2006-09-27 19:08:29 UTC (rev 1006)
+++ branches/coopcomm/source/tools/cDataFile.cc	2006-09-27 20:31:04 UTC (rev 1007)
@@ -48,6 +48,16 @@
 }
 
 
+void cDataFile::Write(unsigned int i, const char* desc)
+{
+  if (!m_descr_written) {
+    m_data += cStringUtil::Stringf("%i ", i);
+    WriteColumnDesc(desc);
+  } else
+    m_fp << i << " ";  
+}
+
+
 void cDataFile::Write(const char* data_str, const char* descr)
 {
   if (!m_descr_written) {

Modified: branches/coopcomm/source/tools/cDataFile.h
===================================================================
--- branches/coopcomm/source/tools/cDataFile.h	2006-09-27 19:08:29 UTC (rev 1006)
+++ branches/coopcomm/source/tools/cDataFile.h	2006-09-27 20:31:04 UTC (rev 1007)
@@ -92,9 +92,11 @@
 
   void Write(double x, const char* descr);
   void Write(int i, const char* descr);
+  void Write(unsigned int i, const char* desc);
   void Write(const char* data_str, const char* descr);
   inline void WriteAnonymous(double x) { m_fp << x << " "; }
   inline void WriteAnonymous(int i) { m_fp << i << " "; }
+  inline void WriteAnonymous(unsigned int i) { m_fp << i << " "; }
   inline void WriteAnonymous(const char* data_str) { m_fp << data_str << " "; }
   void WriteBlockElement(double x, int element, int x_size);
   void WriteBlockElement(int i, int element, int x_size);

Modified: branches/coopcomm/support/config/avida.cfg
===================================================================
--- branches/coopcomm/support/config/avida.cfg	2006-09-27 19:08:29 UTC (rev 1006)
+++ branches/coopcomm/support/config/avida.cfg	2006-09-27 20:31:04 UTC (rev 1007)
@@ -204,3 +204,8 @@
 SAVE_RECEIVED 0  # Enable storage of all inputs bought from other orgs
 BUY_PRICE 0      # price offered by organisms attempting to buy
 SELL_PRICE 0     # price offered by organisms attempting to sell
+
+### COOP_COMM_GROUP ###
+# Cooperative communication parameters
+CELL_ID_RESET_PROB 0.0 # Probability that a cell's random ID will change on
+                       # organism insertion.




More information about the Avida-cvs mailing list