[Avida-SVN] r2123 - in branches/energy/source: actions cpu drivers main

beckma24 at myxo.css.msu.edu beckma24 at myxo.css.msu.edu
Wed Oct 3 18:42:34 PDT 2007


Author: beckma24
Date: 2007-10-03 21:42:29 -0400 (Wed, 03 Oct 2007)
New Revision: 2123

Modified:
   branches/energy/source/actions/PrintActions.cc
   branches/energy/source/cpu/cHardwareCPU.cc
   branches/energy/source/cpu/cHardwareCPU.h
   branches/energy/source/drivers/cDefaultRunDriver.cc
   branches/energy/source/main/cDeme.cc
   branches/energy/source/main/cDeme.h
   branches/energy/source/main/cPopulationCell.cc
   branches/energy/source/main/cPopulationCell.h
   branches/energy/source/main/cStats.cc
   branches/energy/source/main/cStats.h
Log:
Added instruction that blocks neighbors from sending messages during the same update, similar to carrier sense.  Also, added print action PrintMsgSentBlockedDump that dumps the infromation about which cells are blocked, and where messages were sent from/to.

Modified: branches/energy/source/actions/PrintActions.cc
===================================================================
--- branches/energy/source/actions/PrintActions.cc	2007-10-03 16:19:14 UTC (rev 2122)
+++ branches/energy/source/actions/PrintActions.cc	2007-10-04 01:42:29 UTC (rev 2123)
@@ -94,6 +94,7 @@
 STATS_OUT_FILE(PrintSleepData,              sleep.dat           );
 STATS_OUT_FILE(PrintMessageData,            message.dat         );
 STATS_OUT_FILE(PrintPredSatFracDump,        pred_sat_frac_dump.dat);
+STATS_OUT_FILE(PrintMsgSentBlockedDump,     msg_sent_block_dump.dat);
 
 #define POP_OUT_FILE(METHOD, DEFAULT)                                                     /*  1 */ \
 class cAction ## METHOD : public cAction {                                                /*  2 */ \
@@ -2633,6 +2634,7 @@
   action_lib->Register<cActionPrintSenseExeData>("PrintSenseExeData");
   action_lib->Register<cActionPrintSleepData>("PrintSleepData");
   action_lib->Register<cActionPrintMessageData>("PrintMessageData");
+  action_lib->Register<cActionPrintMsgSentBlockedDump>("PrintMsgSentBlockedDump");
 
 
   // Population Out Files

Modified: branches/energy/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/energy/source/cpu/cHardwareCPU.cc	2007-10-03 16:19:14 UTC (rev 2122)
+++ branches/energy/source/cpu/cHardwareCPU.cc	2007-10-04 01:42:29 UTC (rev 2123)
@@ -370,10 +370,11 @@
 
     // Messaging
     tInstLibEntry<tMethod>("send-msg", &cHardwareCPU::Inst_SendMessage),
+    tInstLibEntry<tMethod>("send-msg-block-neighbors", &cHardwareCPU::Inst_SendMessage_BlockNeighbors),
     tInstLibEntry<tMethod>("retrieve-msg", &cHardwareCPU::Inst_RetrieveMessage),
         
     // Placebo instructions
-    tInstLibEntry<tMethod>("skip", &cHardwareCPU::Inst_Skip),
+//    tInstLibEntry<tMethod>("skip", &cHardwareCPU::Inst_Skip),
 
     // Must always be the last instruction in the array
     tInstLibEntry<tMethod>("NULL", &cHardwareCPU::Inst_Nop, 0, "True no-operation instruction: does nothing"),
@@ -4494,6 +4495,33 @@
   return organism->SendMessage(ctx, msg);
 }
 
+bool cHardwareCPU::Inst_SendMessage_BlockNeighbors(cAvidaContext& ctx) {
+  cPopulation& pop = m_world->GetPopulation();
+  int cell_id = organism->GetCellID();
+  cPopulationCell& sending_cell = pop.GetCell(cell_id);
+  
+  if(!sending_cell.SendingIsBlocked() && !sending_cell.SendingIsPaused()) {
+    // block neighbors in connection list and track
+    int oldFacing = sending_cell.GetFacing();
+    for(int i = 0; i < organism->GetNeighborhoodSize(); i++) {
+      cPopulationCell* neighbor = sending_cell.ConnectionList().GetPos(i);
+      neighbor->BlockSending();
+      pop.GetDeme(sending_cell.GetDemeID()).InsertInBlockedList(neighbor->GetID(), neighbor);
+    }
+    int newFacing = sending_cell.GetFacing();
+    assert(oldFacing == newFacing);
+    
+    // send message
+    Inst_SendMessage(ctx);
+    
+    // pause self
+    sending_cell.PauseSending();
+    pop.GetDeme(sending_cell.GetDemeID()).InsertInPausedList(cell_id, &sending_cell);
+    return true;
+  }
+  return false;
+}
+
 /*! This method /attempts/ to retrieve a message -- It may not be possible, as in
 the case of an empty receive buffer.
 

Modified: branches/energy/source/cpu/cHardwareCPU.h
===================================================================
--- branches/energy/source/cpu/cHardwareCPU.h	2007-10-03 16:19:14 UTC (rev 2122)
+++ branches/energy/source/cpu/cHardwareCPU.h	2007-10-04 01:42:29 UTC (rev 2123)
@@ -561,6 +561,7 @@
 
   //// Messaging ////
   bool Inst_SendMessage(cAvidaContext& ctx);
+  bool Inst_SendMessage_BlockNeighbors(cAvidaContext& ctx);
   bool Inst_RetrieveMessage(cAvidaContext& ctx);
   
   //// Placebo ////

Modified: branches/energy/source/drivers/cDefaultRunDriver.cc
===================================================================
--- branches/energy/source/drivers/cDefaultRunDriver.cc	2007-10-03 16:19:14 UTC (rev 2122)
+++ branches/energy/source/drivers/cDefaultRunDriver.cc	2007-10-04 01:42:29 UTC (rev 2123)
@@ -76,6 +76,11 @@
     m_world->GetEvents(ctx);
     if (m_done == true) break;
     
+    // Clear deme TDMA
+    for(int i=0; i<population.GetNumDemes(); ++i) {
+      population.GetDeme(i).SetupUpdate();
+    }
+    
     // Increment the Update.
     stats.IncCurrentUpdate();
     

Modified: branches/energy/source/main/cDeme.cc
===================================================================
--- branches/energy/source/main/cDeme.cc	2007-10-03 16:19:14 UTC (rev 2122)
+++ branches/energy/source/main/cDeme.cc	2007-10-04 01:42:29 UTC (rev 2123)
@@ -23,7 +23,7 @@
 
 #include "cDeme.h"
 #include "cPopulation.h"
-#include "cPopulationCell.h"
+//#include "cPopulationCell.h"
 #include "cResource.h"
 #include "cStats.h"
 #include "cWorld.h"
@@ -97,6 +97,7 @@
       event.DeactivateEvent();  //event over
     }
   }
+  
   ++_age;
 }
 
@@ -115,6 +116,20 @@
   }
 }
 
+void cDeme::SetupUpdate() {
+  //remove sending block from all blocked cells in deme
+  for(map<int, cPopulationCell*>::iterator iter = cells_blocked_from_sending.begin(); iter != cells_blocked_from_sending.end(); iter++) {
+    (*iter).second->UnblockSending();
+  }
+  cells_blocked_from_sending.clear();
+
+  //remove sending pause from all paused cells in deme
+  for(map<int, cPopulationCell*>::iterator iter = cells_paused_from_sending.begin(); iter != cells_paused_from_sending.end(); iter++) {
+    (*iter).second->UnpauseSending();
+  }
+  cells_paused_from_sending.clear();
+}
+
 /*! Replacing this deme's germline has the effect of changing the deme's lineage.
 There's still some work to do here; the lineage labels of the Genomes in the germline
 are all messed up.

Modified: branches/energy/source/main/cDeme.h
===================================================================
--- branches/energy/source/main/cDeme.h	2007-10-03 16:19:14 UTC (rev 2122)
+++ branches/energy/source/main/cDeme.h	2007-10-04 01:42:29 UTC (rev 2123)
@@ -28,6 +28,7 @@
 #include "cGermline.h"
 #include "tArray.h"
 #include "cOrgMessagePredicate.h"
+#include "cPopulationCell.h"
 #include "cResourceCount.h"
 #include "cStringList.h"
 
@@ -58,6 +59,9 @@
   tArray<cDemeCellEvent> cell_events;
   tArray<cOrgMessagePredicate*> message_pred_list;
   
+  std::map<int, cPopulationCell*> cells_blocked_from_sending;
+  std::map<int, cPopulationCell*> cells_paused_from_sending;
+  
 public:
   cDeme() : width(0), birth_count(0), org_count(0), _age(0), deme_resource_count(0) { ; }
   ~cDeme() { ; }
@@ -95,6 +99,8 @@
   // -= Update support =-
   //! Called once, at the end of every update.
   void ProcessUpdate();
+  //! Called once, at the begining of every update.
+  void SetupUpdate();
   /*! Returns the age of this deme, updates.  Age is defined as the number of 
     updates since the last time Reset() was called. */
   int GetAge() const { return _age; }
@@ -117,6 +123,9 @@
   bool PredicatePreviouslySatisfied(int pred_id) { return message_pred_list[pred_id]->PreviouslySatisfied(); }
   cString GetPredicateName(int pred_id) { return message_pred_list[pred_id]->GetName(); }
   void PrintPredicate(int pred_id, std::ostream& out) { message_pred_list[pred_id]->Print(out); }
+  
+  void InsertInBlockedList(int cell_id, cPopulationCell* cell) { cells_blocked_from_sending[cell_id] = cell; }
+  void InsertInPausedList(int cell_id, cPopulationCell* cell) { cells_paused_from_sending[cell_id] = cell; }
 };
 
 #endif

Modified: branches/energy/source/main/cPopulationCell.cc
===================================================================
--- branches/energy/source/main/cPopulationCell.cc	2007-10-03 16:19:14 UTC (rev 2122)
+++ branches/energy/source/main/cPopulationCell.cc	2007-10-04 01:42:29 UTC (rev 2123)
@@ -46,6 +46,8 @@
   , m_deme_id(in_cell.m_deme_id)
   , m_organism_count(in_cell.m_organism_count)
   , m_cell_data(in_cell.m_cell_data)
+  , m_blocked_from_sending(in_cell.m_blocked_from_sending)
+  , m_sending_paused(in_cell.m_sending_paused)
 {
   // Copy the mutation rates into a new structure
   m_mut_rates = new cMutationRates(*in_cell.m_mut_rates);
@@ -66,7 +68,9 @@
   m_deme_id = in_cell.m_deme_id;
   m_organism_count = in_cell.m_organism_count;
   m_cell_data = in_cell.m_cell_data;
-
+  m_blocked_from_sending = in_cell.m_blocked_from_sending;
+  m_sending_paused = in_cell.m_sending_paused;
+  
   // Copy the mutation rates, constructing the structure as necessary
   if (m_mut_rates == NULL)
     m_mut_rates = new cMutationRates(*in_cell.m_mut_rates);

Modified: branches/energy/source/main/cPopulationCell.h
===================================================================
--- branches/energy/source/main/cPopulationCell.h	2007-10-03 16:19:14 UTC (rev 2122)
+++ branches/energy/source/main/cPopulationCell.h	2007-10-04 01:42:29 UTC (rev 2123)
@@ -65,13 +65,16 @@
   int m_x; //!< The x-coordinate of the position of this cell in the environment.
   int m_y; //!< The y-coordinate of the position of this cell in the environment.
 
-  
+  bool m_blocked_from_sending;
+  bool m_sending_paused;
+    
   void InsertOrganism(cOrganism* new_org);
   cOrganism* RemoveOrganism();
 
   
 public:
-  cPopulationCell() : m_world(NULL), m_organism(NULL), m_hardware(NULL), m_mut_rates(NULL), m_organism_count(0) { ; }
+  cPopulationCell() : m_world(NULL), m_organism(NULL), m_hardware(NULL), m_mut_rates(NULL), 
+                      m_organism_count(0), m_blocked_from_sending(false), m_sending_paused(false) { ; }
   cPopulationCell(const cPopulationCell& in_cell);
   ~cPopulationCell() { delete m_mut_rates; }
 
@@ -105,7 +108,15 @@
   inline bool IsOccupied() const { return m_organism != NULL; }
 
   double UptakeCellEnergy(double frac_to_uptake);
+  
+  inline void BlockSending() { if(!m_sending_paused) m_blocked_from_sending = true; }
+  inline void UnblockSending() { m_blocked_from_sending = false; }
+  inline bool SendingIsBlocked() { return m_blocked_from_sending; }
 
+  inline void PauseSending() { m_sending_paused = true; }
+  inline void UnpauseSending() { m_sending_paused = false; }
+  inline bool SendingIsPaused() { return m_sending_paused; }
+
   bool OK();
 };
 

Modified: branches/energy/source/main/cStats.cc
===================================================================
--- branches/energy/source/main/cStats.cc	2007-10-03 16:19:14 UTC (rev 2122)
+++ branches/energy/source/main/cStats.cc	2007-10-04 01:42:29 UTC (rev 2123)
@@ -507,6 +507,7 @@
   num_msg_sent = 0;
   num_msg_received = 0;
   num_msg_retrieved = 0;
+  from_to_message_list.clear();
 }
 
 void cStats::RemoveLineage(int id_num, int parent_id, int update_born, double generation_born, int total_CPUs,
@@ -1048,6 +1049,28 @@
   df.Endl();
 }
 
+void cStats::PrintMsgSentBlockedDump(const cString& filename) {
+  cDataFile& df = m_world->GetDataFile(cStringUtil::Stringf("msg_sent_block_dump_%07i.dat", GetUpdate()));
+  cPopulation& pop = m_world->GetPopulation();
+  int width = pop.GetWorldX();
+  for(int i = 0; i < pop.GetSize(); i++) {
+    int data;
+    if(pop.GetCell(i).SendingIsBlocked()) {  // cell blocked
+      data = -1;
+    } else if(pop.GetCell(i).SendingIsPaused()) { //sent msg, cell paused
+      if(from_to_message_list.find(i) == from_to_message_list.end()) {
+        data = -2; // msg sent to no one
+      }
+      else {
+        data = from_to_message_list[i];
+      }
+    } else { // no msg sent
+      data = -3;
+    }
+    df.WriteBlockElement(data, i, width);
+  }
+}
+
 void cStats::PrintSenseData(const cString& filename)
 {
   cDataFile& df = m_world->GetDataFile(filename);
@@ -1104,6 +1127,10 @@
     (**i)(msg); // Predicate is responsible for tracking info about messages.
   }
   num_msg_sent++;
+  
+  from_to_message_list[msg.GetSender()->GetCellID()] = msg.GetReceiver()->GetCellID();
+//  pair<int, int> connection = make_pair(msg.GetSender()->GetID(), msg.GetReceiver()->GetID());
+//  from_to_message_list.Push(&connection);
 }
 
 
@@ -1162,7 +1189,6 @@
       } else {
         data = (double) relative_pos_pred_sat.ElementAt(x,y) / (double) relative_pos_event_count.ElementAt(x,y);
       }
-//        df.Write(data, "hello");
       df.WriteBlockElement(data, x*cols+y, cols);
     }
   }

Modified: branches/energy/source/main/cStats.h
===================================================================
--- branches/energy/source/main/cStats.h	2007-10-03 16:19:14 UTC (rev 2122)
+++ branches/energy/source/main/cStats.h	2007-10-04 01:42:29 UTC (rev 2123)
@@ -30,6 +30,7 @@
 #include <fstream>
 #include <iostream>
 #include <vector>
+#include <map>
 
 #ifndef defs_h
 #include "defs.h"
@@ -272,8 +273,8 @@
   int num_msg_received;
   int num_msg_retrieved;
   cIntSum inbox_size;
+  std::map<int, int> from_to_message_list;  //<int from, int to>
 
-
   cStats(); // @not_implemented
   cStats(const cStats&); // @not_implemented
   cStats& operator=(const cStats&); // @not_implemented
@@ -669,6 +670,7 @@
   void PrintGenotypeMap(const cString& filename);
   void PrintMarketData(const cString& filename);
   void PrintMessageData(const cString& filename);
+  void PrintMsgSentBlockedDump(const cString& filename);
   void PrintSenseData(const cString& filename);
   void PrintSenseExeData(const cString& filename);
   void PrintSleepData(const cString& filename);




More information about the Avida-cvs mailing list