[Avida-SVN] r2183 - in branches/dkdev/source: actions main

dknoester at myxo.css.msu.edu dknoester at myxo.css.msu.edu
Wed Nov 7 04:41:16 PST 2007


Author: dknoester
Date: 2007-11-07 07:41:16 -0500 (Wed, 07 Nov 2007)
New Revision: 2183

Modified:
   branches/dkdev/source/actions/PopulationActions.cc
   branches/dkdev/source/main/cPopulation.cc
Log:
Bounded region test - can orgs detect inside/outside region?

Modified: branches/dkdev/source/actions/PopulationActions.cc
===================================================================
--- branches/dkdev/source/actions/PopulationActions.cc	2007-11-06 20:50:51 UTC (rev 2182)
+++ branches/dkdev/source/actions/PopulationActions.cc	2007-11-07 12:41:16 UTC (rev 2183)
@@ -911,6 +911,7 @@
     else if (in_trigger == "two-cells-region-latched") m_rep_trigger = 19;
     else if (in_trigger == "two-cells-germline-region") m_rep_trigger = 20;
     else if (in_trigger == "two-cells-germline-region-count") m_rep_trigger = 21;
+    else if (in_trigger == "two-cells-germline-bounded-region") m_rep_trigger = 22;
         //    else if (in_trigger == "topo-2cells-path-merit") m_rep_trigger = 8;
 //    else if (in_trigger == "message-collection") m_rep_trigger = 9;
     else {

Modified: branches/dkdev/source/main/cPopulation.cc
===================================================================
--- branches/dkdev/source/main/cPopulation.cc	2007-11-06 20:50:51 UTC (rev 2182)
+++ branches/dkdev/source/main/cPopulation.cc	2007-11-07 12:41:16 UTC (rev 2183)
@@ -128,9 +128,53 @@
 };
 
 
+struct bounded_region_accumulator : std::binary_function<double, cPopulationCell, double> {
+  bounded_region_accumulator(cDeme& deme) : _deme(deme) { }
+  double operator()(double result, cPopulationCell& cell) {
+    // What are the deme dimensions, and where is the organism located?
+    assert(cell.IsOccupied());
+    cOrganism* organism = cell.GetOrganism();
+    assert(organism != 0);
+    
+    
+    std::pair<int,int> one_xy = _deme.GetCellPosition(_deme.GetCellsToLink().first);
+    std::pair<int,int> two_xy = _deme.GetCellPosition(_deme.GetCellsToLink().second);
+    std::pair<int,int> self_xy = _deme.GetCellPosition(organism->GetCellID());
 
+//    std::cout << "Organism " << organism->GetCellID() << " @ (" << self_xy.first << "," << self_xy.second << ") declares "
+//      << organism->GetRegion() << " for cell1 @ (" << one_xy.first << "," << one_xy.second << ") and cell2 @ ("
+//      << two_xy.first << "," << two_xy.second << "); ";
+    
+    // create the region
+    std::pair<int,int> x_range = std::make_pair(std::min(one_xy.first, two_xy.first), std::max(one_xy.first, two_xy.first));
+    std::pair<int,int> y_range = std::make_pair(std::min(one_xy.second, two_xy.second), std::max(one_xy.second, two_xy.second));
+    
+    if((self_xy.first >= x_range.first) 
+       && (self_xy.first <= x_range.second)
+       && (self_xy.second >= y_range.first)
+       && (self_xy.second <= y_range.second)
+       && (organism->GetRegion()==1)) {
+      // Is this organism correctly declaring itself to be in the region?
+//      std::cout << " inside.";
+      result += 1.0;
+    } else if(organism->GetRegion()==-1) {
+      //      if(((self_xy.first < x_range.first) || (self_xy.first > x_range.second))
+      //       && ((self_xy.second < y_range.first) || (self_xy.second > y_range.second))
+      //       && (organism->GetRegion()==-1)) {
+      // Is this organism correctly declaring itself to be outside the region?
+//      std::cout << " outside.";
+      result += 1.0;
+    }
+    
+//    std::cout << std::endl;
+    return result;
+  }
+  
+  cDeme& _deme;  
+};
 
 
+
 cPopulation::cPopulation(cWorld* world)
 : m_world(world)
 , schedule(NULL)
@@ -1151,7 +1195,25 @@
                                     2);
         break;
       }        
+      case 22: {
+        // Replicate demes where all organisms have decided on a region, and set
+        // merit proportional to the number of organisms that have correctly identified
+        // the region in which they reside.
+        if(!source_deme.IsFull()) continue;
         
+        bool all_latched=true;
+        for(int i=0; i<source_deme.GetSize() && all_latched; ++i) {
+          all_latched = all_latched && cell_array[source_deme.GetCellID(i)].GetOrganism()->IsRegionLatched();
+        }
+        if(!all_latched) continue;
+
+        source_germline_merit = pow(std::accumulate(&cell_array.begin()[source_deme.GetCellID(0)],
+                                                    &cell_array.begin()[source_deme.GetCellID(source_deme.GetSize()-1)+1],
+                                                    0.0, bounded_region_accumulator(source_deme)),
+                                    2);
+        
+        break;
+      }
 //      case 19: {
 //        // Replicate demes that have connected two randomly-selected cells.
 //        // Merit is the inverse of edge count.




More information about the Avida-cvs mailing list