[Avida-SVN] r2340 - development/source/main

covertar at myxo.css.msu.edu covertar at myxo.css.msu.edu
Mon Feb 18 07:39:30 PST 2008


Author: covertar
Date: 2008-02-18 10:39:30 -0500 (Mon, 18 Feb 2008)
New Revision: 2340

Modified:
   development/source/main/cPopulation.cc
   development/source/main/cPopulationCell.cc
   development/source/main/cPopulationCell.h
Log:
Modified migration rate to work under all birth methods.



Modified: development/source/main/cPopulation.cc
===================================================================
--- development/source/main/cPopulation.cc	2008-02-18 15:07:38 UTC (rev 2339)
+++ development/source/main/cPopulation.cc	2008-02-18 15:39:30 UTC (rev 2340)
@@ -2097,16 +2097,46 @@
  * and it gives a centralized function to work with.  The parent_ok flag asks
  * if it is okay to replace the parent.
  **/
-
+//@AWC -- This could REALLY stand some functional abstraction...
 cPopulationCell& cPopulation::PositionChild(cPopulationCell& parent_cell, bool parent_ok)
 {
   assert(parent_cell.IsOccupied());
   
   const int birth_method = m_world->GetConfig().BIRTH_METHOD.Get();
-  
-  // Try out global/full-deme birth methods first...
-  
-  if (birth_method == POSITION_CHILD_FULL_SOUP_RANDOM) {
+
+  //@AWC -- decide wether the child will migrate to another deme -- if migrating we ignore the birth method.  
+  if ((m_world->GetConfig().MIGRATION_RATE.Get() > 0.0) //@AWC -- Pedantic test to maintain consistancy.
+      && m_world->GetRandom().P(m_world->GetConfig().MIGRATION_RATE.Get())){
+
+    int deme_id = parent_cell.GetDemeID();
+
+    //get another -unadjusted- deme id
+    int rnd_deme_id = m_world->GetRandom().GetInt(deme_array.GetSize()-1);
+    
+    //if the -unadjusted- id is above the excluded id, bump it up one
+    //insures uniform prob of landing in any deme but the parent's
+    if(rnd_deme_id >= deme_id) rnd_deme_id++;
+    
+    //set the new deme_id
+    deme_id = rnd_deme_id;
+
+    //The rest of this is essentially POSITION_CHILD_DEME_RANDOM
+    const int deme_size = deme_array[deme_id].GetSize();
+    
+    int out_pos = m_world->GetRandom().GetUInt(deme_size);
+    int out_cell_id = deme_array[deme_id].GetCellID(out_pos);
+    while (parent_ok == false && out_cell_id == parent_cell.GetID()) {
+      out_pos = m_world->GetRandom().GetUInt(deme_size);
+      out_cell_id = deme_array[deme_id].GetCellID(out_pos);
+    }
+    
+    deme_array[deme_id].IncBirthCount();
+    GetCell(out_cell_id).SetMigrant();
+    return GetCell(out_cell_id);    
+    
+  }
+  // @AWC If not migrating try out global/full-deme birth methods first...
+  else if (birth_method == POSITION_CHILD_FULL_SOUP_RANDOM) {
     int out_pos = m_world->GetRandom().GetUInt(cell_array.GetSize());
     while (parent_ok == false && out_pos == parent_cell.GetID()) {
       out_pos = m_world->GetRandom().GetUInt(cell_array.GetSize());
@@ -2122,24 +2152,8 @@
     return *out_cell;
   }
   else if (birth_method == POSITION_CHILD_DEME_RANDOM) {
-    int deme_id = parent_cell.GetDemeID();
-    
-    //@AWC -- decide wether the child will migrate to another deme
-    if((m_world->GetConfig().MIGRATION_RATE.Get() > 0.0) //@AWC -- Pedantic test to maintain consistancy.
-       && m_world->GetRandom().P(m_world->GetConfig().MIGRATION_RATE.Get())){
-      
-      //get another -unadjusted- deme id
-      int rnd_deme_id = m_world->GetRandom().GetInt(deme_array.GetSize()-1);
-      
-      //if the -unadjusted- id is above the excluded id, bump it up one
-      //insures uniform prob of landing in any deme but the parent's
-      if(rnd_deme_id >= deme_id) rnd_deme_id++;
-      
-      //set the new deme_id
-      deme_id = rnd_deme_id;
-    }
-    
-    
+
+    const int deme_id = parent_cell.GetDemeID();    
     const int deme_size = deme_array[deme_id].GetSize();
     
     int out_pos = m_world->GetRandom().GetUInt(deme_size);

Modified: development/source/main/cPopulationCell.cc
===================================================================
--- development/source/main/cPopulationCell.cc	2008-02-18 15:07:38 UTC (rev 2339)
+++ development/source/main/cPopulationCell.cc	2008-02-18 15:39:30 UTC (rev 2340)
@@ -99,6 +99,12 @@
 {
   // @CAO Note, this breaks avida if new_facing is not in connection_list
 
+  //@AWC if this cell contains a migrant then we assume new_facing is not in the connection list and bail out ...
+  if(IsMigrant()){
+    UnsetMigrant(); //@AWC -- unset the migrant flag for the next time this cell is used
+    return;
+  }
+
 #ifdef DEBUG
   int scan_count = 0;
 #endif

Modified: development/source/main/cPopulationCell.h
===================================================================
--- development/source/main/cPopulationCell.h	2008-02-18 15:07:38 UTC (rev 2339)
+++ development/source/main/cPopulationCell.h	2008-02-18 15:39:30 UTC (rev 2340)
@@ -63,6 +63,8 @@
   int m_cell_data;         // "data" that is local to the cell and can be retrieaved by the org.
   int m_spec_state;
 
+  bool m_migrant; //@AWC -- does the cell contain a migrant genome?
+
   // location in population
   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.
@@ -73,7 +75,7 @@
 
   
 public:
-  cPopulationCell() : m_world(NULL), m_organism(NULL), m_hardware(NULL), m_mut_rates(NULL) { ; }
+  cPopulationCell() : m_world(NULL), m_organism(NULL), m_hardware(NULL), m_mut_rates(NULL), m_migrant(false) { ; }
   cPopulationCell(const cPopulationCell& in_cell);
   ~cPopulationCell() { delete m_mut_rates; }
 
@@ -83,6 +85,11 @@
   void SetDemeID(int in_id) { m_deme_id = in_id; }
   void Rotate(cPopulationCell& new_facing);
 
+  //@AWC -- This is, admittatidly, a hack to get migration between demes working under local copy...
+  void SetMigrant() {m_migrant = true;} //@AWC -- this cell will contain a migrant genome
+  void UnsetMigrant() {m_migrant = false;} //@AWC -- unset the migrant flag
+  bool IsMigrant() {return m_migrant;} //@AWC -- does this contain a migrant genome?
+
   inline cOrganism* GetOrganism() const { return m_organism; }
   inline cHardwareBase* GetHardware() const { return m_hardware; }
   inline tList<cPopulationCell>& ConnectionList() { return m_connections; }




More information about the Avida-cvs mailing list