[Avida-SVN] r2101 - in branches/dkdev: Avida.xcodeproj source/actions source/cpu source/main

dknoester at myxo.css.msu.edu dknoester at myxo.css.msu.edu
Mon Sep 24 15:26:44 PDT 2007


Author: dknoester
Date: 2007-09-24 18:26:43 -0400 (Mon, 24 Sep 2007)
New Revision: 2101

Modified:
   branches/dkdev/Avida.xcodeproj/project.pbxproj
   branches/dkdev/source/actions/PopulationActions.cc
   branches/dkdev/source/actions/PrintActions.cc
   branches/dkdev/source/cpu/cHardwareCPU.cc
   branches/dkdev/source/cpu/cHardwareCPU.h
   branches/dkdev/source/main/cOrganism.cc
   branches/dkdev/source/main/cOrganism.h
   branches/dkdev/source/main/cPopulation.cc
   branches/dkdev/source/main/cStats.cc
   branches/dkdev/source/main/cStats.h
   branches/dkdev/source/main/cTaskLib.cc
   branches/dkdev/source/main/cTaskLib.h
Log:
Changes to support the detection of a region between two randomly selected cells (continuation of network creation experiments).

Modified: branches/dkdev/Avida.xcodeproj/project.pbxproj
===================================================================
--- branches/dkdev/Avida.xcodeproj/project.pbxproj	2007-09-21 16:45:24 UTC (rev 2100)
+++ branches/dkdev/Avida.xcodeproj/project.pbxproj	2007-09-24 22:26:43 UTC (rev 2101)
@@ -10,7 +10,6 @@
 		428C60240C17978C000212E2 /* cTopology.cc in Sources */ = {isa = PBXBuildFile; fileRef = 428C60230C17978C000212E2 /* cTopology.cc */; };
 		7005A70609BA0FA90007E16E /* cTestCPUInterface.cc in Sources */ = {isa = PBXBuildFile; fileRef = 7005A70209BA0FA90007E16E /* cTestCPUInterface.cc */; };
 		7005A70809BA0FA90007E16E /* cTestCPUInterface.cc in Sources */ = {isa = PBXBuildFile; fileRef = 7005A70209BA0FA90007E16E /* cTestCPUInterface.cc */; };
-		700E2996085A1F6000CF158A /* avida in CopyFiles */ = {isa = PBXBuildFile; fileRef = DCC3164D07626CF3008F7A48 /* avida */; };
 		700E2AF8085DE50C00CF158A /* avida.cc in Sources */ = {isa = PBXBuildFile; fileRef = DCC3109C0762539E008F7A48 /* avida.cc */; };
 		700E2B87085DE54400CF158A /* avida-viewer in CopyFiles */ = {isa = PBXBuildFile; fileRef = 700E2B83085DE50C00CF158A /* avida-viewer */; };
 		7013846209028B3E0087ED2E /* cAvidaConfig.cc in Sources */ = {isa = PBXBuildFile; fileRef = 7013846009028B3E0087ED2E /* cAvidaConfig.cc */; };
@@ -29,10 +28,6 @@
 		702D4F0708DA5341007BA469 /* cPopulationInterface.cc in Sources */ = {isa = PBXBuildFile; fileRef = 702D4EFD08DA5341007BA469 /* cPopulationInterface.cc */; };
 		702D4F4508DA61FE007BA469 /* cBirthChamber.cc in Sources */ = {isa = PBXBuildFile; fileRef = 702D4F3F08DA61FE007BA469 /* cBirthChamber.cc */; };
 		702D4F4B08DA61FE007BA469 /* cBirthChamber.cc in Sources */ = {isa = PBXBuildFile; fileRef = 702D4F3F08DA61FE007BA469 /* cBirthChamber.cc */; };
-		7039884D09F00D020052ACE7 /* analyze.cfg in CopyFiles */ = {isa = PBXBuildFile; fileRef = 707AF2D309EE8501001AEA89 /* analyze.cfg */; };
-		7039884E09F00D030052ACE7 /* avida.cfg in CopyFiles */ = {isa = PBXBuildFile; fileRef = 707AF2D509EE8501001AEA89 /* avida.cfg */; };
-		7039884F09F00D060052ACE7 /* environment.cfg in CopyFiles */ = {isa = PBXBuildFile; fileRef = 707AF2D709EE8501001AEA89 /* environment.cfg */; };
-		7039885009F00D080052ACE7 /* events.cfg in CopyFiles */ = {isa = PBXBuildFile; fileRef = 707AF2D809EE8501001AEA89 /* events.cfg */; };
 		7040D3A6090964D100AA820F /* cMxCodeArray.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70B0865808F4974300FC65FE /* cMxCodeArray.cc */; };
 		70422A28091B141000A5E67F /* cAnalyze.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70422A1C091B141000A5E67F /* cAnalyze.cc */; };
 		70422A30091B141000A5E67F /* cAnalyzeGenotype.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70422A24091B141000A5E67F /* cAnalyzeGenotype.cc */; };
@@ -40,14 +35,6 @@
 		70422A3C091B141000A5E67F /* cAnalyzeGenotype.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70422A24091B141000A5E67F /* cAnalyzeGenotype.cc */; };
 		7049F2D90A66859700640512 /* cHardwareTransSMT.cc in Sources */ = {isa = PBXBuildFile; fileRef = 7049F2D70A66859300640512 /* cHardwareTransSMT.cc */; };
 		7049F2DB0A66859F00640512 /* cHardwareTransSMT.cc in Sources */ = {isa = PBXBuildFile; fileRef = 7049F2D70A66859300640512 /* cHardwareTransSMT.cc */; };
-		7049F3560A66A8F500640512 /* instset-classic.cfg in CopyFiles */ = {isa = PBXBuildFile; fileRef = 7049F3520A66A8F500640512 /* instset-classic.cfg */; };
-		7049F3570A66A8F500640512 /* instset-sex-classic.cfg in CopyFiles */ = {isa = PBXBuildFile; fileRef = 7049F3530A66A8F500640512 /* instset-sex-classic.cfg */; };
-		7049F3580A66A8F500640512 /* instset-smt.cfg in CopyFiles */ = {isa = PBXBuildFile; fileRef = 7049F3540A66A8F500640512 /* instset-smt.cfg */; };
-		7049F3590A66A8F500640512 /* instset-transsmt.cfg in CopyFiles */ = {isa = PBXBuildFile; fileRef = 7049F3550A66A8F500640512 /* instset-transsmt.cfg */; };
-		7049F3700A66AD7E00640512 /* default-classic.org in CopyFiles */ = {isa = PBXBuildFile; fileRef = 7049F36C0A66AD7E00640512 /* default-classic.org */; };
-		7049F3710A66AD7E00640512 /* default-sex-classic.org in CopyFiles */ = {isa = PBXBuildFile; fileRef = 7049F36D0A66AD7E00640512 /* default-sex-classic.org */; };
-		7049F3720A66AD7E00640512 /* default-smt.org in CopyFiles */ = {isa = PBXBuildFile; fileRef = 7049F36E0A66AD7E00640512 /* default-smt.org */; };
-		7049F3730A66AD7E00640512 /* default-transsmt.org in CopyFiles */ = {isa = PBXBuildFile; fileRef = 7049F36F0A66AD7E00640512 /* default-transsmt.org */; };
 		704ADBC80A6EEFC300666970 /* DriverActions.cc in Sources */ = {isa = PBXBuildFile; fileRef = 704ADBC40A6EEFC300666970 /* DriverActions.cc */; };
 		704ADBF90A6EF3A300666970 /* DriverActions.cc in Sources */ = {isa = PBXBuildFile; fileRef = 704ADBC40A6EEFC300666970 /* DriverActions.cc */; };
 		7053324C0929764C006BD186 /* cSpecies.cc in Sources */ = {isa = PBXBuildFile; fileRef = 705332480929764A006BD186 /* cSpecies.cc */; };
@@ -270,28 +257,6 @@
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
-		70486B9508267145009328F0 /* CopyFiles */ = {
-			isa = PBXCopyFilesBuildPhase;
-			buildActionMask = 2147483647;
-			dstPath = work;
-			dstSubfolderSpec = 16;
-			files = (
-				700E2996085A1F6000CF158A /* avida in CopyFiles */,
-				7039884D09F00D020052ACE7 /* analyze.cfg in CopyFiles */,
-				7039884E09F00D030052ACE7 /* avida.cfg in CopyFiles */,
-				7039884F09F00D060052ACE7 /* environment.cfg in CopyFiles */,
-				7039885009F00D080052ACE7 /* events.cfg in CopyFiles */,
-				7049F3560A66A8F500640512 /* instset-classic.cfg in CopyFiles */,
-				7049F3570A66A8F500640512 /* instset-sex-classic.cfg in CopyFiles */,
-				7049F3580A66A8F500640512 /* instset-smt.cfg in CopyFiles */,
-				7049F3590A66A8F500640512 /* instset-transsmt.cfg in CopyFiles */,
-				7049F3700A66AD7E00640512 /* default-classic.org in CopyFiles */,
-				7049F3710A66AD7E00640512 /* default-sex-classic.org in CopyFiles */,
-				7049F3720A66AD7E00640512 /* default-smt.org in CopyFiles */,
-				7049F3730A66AD7E00640512 /* default-transsmt.org in CopyFiles */,
-			);
-			runOnlyForDeploymentPostprocessing = 0;
-		};
 /* End PBXCopyFilesBuildPhase section */
 
 /* Begin PBXFileReference section */
@@ -1629,7 +1594,6 @@
 			buildPhases = (
 				DCC3164A07626CF3008F7A48 /* Sources */,
 				DCC3164B07626CF3008F7A48 /* Frameworks */,
-				70486B9508267145009328F0 /* CopyFiles */,
 			);
 			buildRules = (
 			);

Modified: branches/dkdev/source/actions/PopulationActions.cc
===================================================================
--- branches/dkdev/source/actions/PopulationActions.cc	2007-09-21 16:45:24 UTC (rev 2100)
+++ branches/dkdev/source/actions/PopulationActions.cc	2007-09-24 22:26:43 UTC (rev 2101)
@@ -908,8 +908,7 @@
     else if (in_trigger == "topo-cpl-edge-norm-merit") m_rep_trigger = 16;
     else if (in_trigger == "topo-ladder-edge-merit") m_rep_trigger = 17;
     else if (in_trigger == "topo-ladder-cpl-merit") m_rep_trigger = 18;
-    
-//    else if (in_trigger == "topo-2cells-edge-merit") m_rep_trigger = 7;
+    else if (in_trigger == "two-cells-region-latched") m_rep_trigger = 19;
 //    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/actions/PrintActions.cc
===================================================================
--- branches/dkdev/source/actions/PrintActions.cc	2007-09-21 16:45:24 UTC (rev 2100)
+++ branches/dkdev/source/actions/PrintActions.cc	2007-09-24 22:26:43 UTC (rev 2101)
@@ -67,8 +67,10 @@
 STATS_OUT_FILE(PrintTopologyData, topology.dat);
 STATS_OUT_FILE(PrintDemeData, deme.dat);
 STATS_OUT_FILE(PrintCollectionData, collection.dat);
+STATS_OUT_FILE(PrintTwoCellsData, twocells.dat);
 
 
+
 #define POP_OUT_FILE(METHOD, DEFAULT)                                                     /*  1 */ \
 class cAction ## METHOD : public cAction {                                                /*  2 */ \
 private:                                                                                  /*  3 */ \
@@ -1560,6 +1562,9 @@
   
   // Satellite
   action_lib->Register<cActionPrintCollectionData>("PrintCollectionData");  
+  
+  // Two-cells
+  action_lib->Register<cActionPrintTwoCellsData>("PrintTwoCellsData");
 
   // @DMB - The following actions are DEPRECATED aliases - These will be removed in 2.7.
   action_lib->Register<cActionPrintAverageData>("print_average_data");

Modified: branches/dkdev/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/dkdev/source/cpu/cHardwareCPU.cc	2007-09-21 16:45:24 UTC (rev 2100)
+++ branches/dkdev/source/cpu/cHardwareCPU.cc	2007-09-24 22:26:43 UTC (rev 2101)
@@ -375,7 +375,10 @@
     cInstEntryCPU("if-not-linked", &cHardwareCPU::Inst_IfNotLinked),
     
     // Satellite instructions.
-    cInstEntryCPU("sat-send", &cHardwareCPU::Inst_SatelliteSend)
+    cInstEntryCPU("sat-send", &cHardwareCPU::Inst_SatelliteSend),
+    
+    // Two-cells instructions.
+    cInstEntryCPU("region", &cHardwareCPU::Inst_Region)
   };
   
   const int n_size = sizeof(s_n_array)/sizeof(cNOPEntryCPU);
@@ -3793,3 +3796,15 @@
   deme.CollectMessages(organism->GetReceivedMessages());
   return true;
 }
+
+
+
+/*! When called, this instruction latches a "decision" made by this organism.  If
+the value is "true" (one), then the organism is in the region.  If the value is
+"false" (zero), then the organism is not in the region.  We allow standard
+nop-modification. */
+bool cHardwareCPU::Inst_Region(cAvidaContext& ctx) {
+  if(organism->GetCellID() == -1) return false;
+  organism->SetRegion(GetRegister(FindModifiedRegister(REG_BX)));
+  return true;
+}

Modified: branches/dkdev/source/cpu/cHardwareCPU.h
===================================================================
--- branches/dkdev/source/cpu/cHardwareCPU.h	2007-09-21 16:45:24 UTC (rev 2100)
+++ branches/dkdev/source/cpu/cHardwareCPU.h	2007-09-24 22:26:43 UTC (rev 2101)
@@ -493,6 +493,9 @@
   
   // Satellite instructions.
   bool Inst_SatelliteSend(cAvidaContext& ctx);
+  
+  // Two cells instructions.
+  bool Inst_Region(cAvidaContext& ctx);
 };
 
 

Modified: branches/dkdev/source/main/cOrganism.cc
===================================================================
--- branches/dkdev/source/main/cOrganism.cc	2007-09-21 16:45:24 UTC (rev 2100)
+++ branches/dkdev/source/main/cOrganism.cc	2007-09-24 22:26:43 UTC (rev 2101)
@@ -56,6 +56,8 @@
   , m_is_running(false)
   , m_net(NULL)
   , m_msg_rtrv_index(0)
+  , _region(0)
+  , _region_latched(false)
 {
   // Initialization of structures...
   m_hardware = m_world->GetHardwareManager().Create(this);
@@ -191,7 +193,7 @@
   tBuffer<int>* received_messages_point = &m_received_messages;
   if (!m_world->GetConfig().SAVE_RECEIVED.Get())
 	  received_messages_point = NULL;
-  cTaskContext taskctx(m_input_buf, m_output_buf, other_input_list, other_output_list, net_valid, 0, received_messages_point);
+  cTaskContext taskctx(m_input_buf, m_output_buf, other_input_list, other_output_list, net_valid, 0, received_messages_point, this);
   m_phenotype.TestOutput(ctx, taskctx, m_send_buf, m_receive_buf, resource_count, res_change, insts_triggered);
   m_interface->UpdateResources(res_change);
 

Modified: branches/dkdev/source/main/cOrganism.h
===================================================================
--- branches/dkdev/source/main/cOrganism.h	2007-09-21 16:45:24 UTC (rev 2100)
+++ branches/dkdev/source/main/cOrganism.h	2007-09-24 22:26:43 UTC (rev 2101)
@@ -276,6 +276,16 @@
   const t_message_list& GetReceivedMessages() { return m_msg_recv; }
   //! Returns the list of all messages sent by this organism.
   const t_message_list& GetSentMessages() { return m_msg_sent; }
+  
+  // -------- Two-cells support --------
+private:
+  bool _region_latched;
+  int _region;
+public:
+  void SetRegion(int region) { if(!_region_latched) { _region = region; _region_latched = true; } }
+  
+  int GetRegion() const { return _region; }
+  bool IsRegionLatched() const { return _region_latched; }
 };
 
 

Modified: branches/dkdev/source/main/cPopulation.cc
===================================================================
--- branches/dkdev/source/main/cPopulation.cc	2007-09-21 16:45:24 UTC (rev 2100)
+++ branches/dkdev/source/main/cPopulation.cc	2007-09-24 22:26:43 UTC (rev 2101)
@@ -1022,8 +1022,20 @@
         }
         break;
       }
+      case 19: {
+        // Replicate demes where all organisms in the deme have latched a region decision.
+        // No merit is used here.
+        if(!source_deme.IsFull()) continue;
         
-//      case 8: {
+        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;
+        
+        break;
+      }
+//      case 19: {
 //        // Replicate demes that have connected two randomly-selected cells.
 //        // Merit is the inverse of edge count.
 //        cDeme::Network& network = source_deme.GetNetwork();

Modified: branches/dkdev/source/main/cStats.cc
===================================================================
--- branches/dkdev/source/main/cStats.cc	2007-09-21 16:45:24 UTC (rev 2100)
+++ branches/dkdev/source/main/cStats.cc	2007-09-24 22:26:43 UTC (rev 2101)
@@ -96,6 +96,9 @@
   , num_own_used(0)
   , _topo_connected(0)
   , _deme_repl_count(0)
+  , _two_cells_latched(0)
+  , _two_cells_unlatched(0)
+  , _two_cells_correct(0)
 {
   task_cur_count.Resize( m_world->GetNumTasks() );
   task_last_count.Resize( m_world->GetNumTasks() );
@@ -1055,3 +1058,30 @@
     ++boost::get(boost::edge_bundle, _genotype_net)[i.first];
   }
 }
+
+
+void cStats::TwoCellsRegionLatched(bool correct) {
+  ++_two_cells_latched;
+  if(correct) ++_two_cells_correct;
+}
+
+
+void cStats::TwoCellsRegionUnlatched() {
+  ++_two_cells_unlatched;
+}
+
+
+void cStats::PrintTwoCellsData(const cString& filename) {
+  cDataFile& df = m_world->GetDataFile(filename);
+  df.WriteComment("Two-cells path finding data");
+  df.WriteTimeStamp();
+  df.Write(GetUpdate(), "update [update]");
+  df.Write(_two_cells_latched, "count of orgs that latched their region and called IO [latched]");
+  df.Write(_two_cells_unlatched, "count of orgs that did not latch their region but called IO [unlatched]");
+  df.Write(_two_cells_correct, "count of orgs that correctly latched their region [correct]");
+  df.Endl();
+  
+  _two_cells_latched = 0;
+  _two_cells_unlatched = 0;
+  _two_cells_correct = 0;
+}

Modified: branches/dkdev/source/main/cStats.h
===================================================================
--- branches/dkdev/source/main/cStats.h	2007-09-21 16:45:24 UTC (rev 2100)
+++ branches/dkdev/source/main/cStats.h	2007-09-24 22:26:43 UTC (rev 2101)
@@ -615,7 +615,19 @@
   
 private:
   GenotypeNetwork _genotype_net;
+  
+  //
+  // Two-cells related statistics
+  //
+public:
+  void TwoCellsRegionLatched(bool correct);
+  void TwoCellsRegionUnlatched();
+  void PrintTwoCellsData(const cString& filename);
 
+private:
+  int _two_cells_latched; //!< Count of organisms that have latched their region and called IO.
+  int _two_cells_unlatched; //!< Count of organisms that have not latched their region and called IO.
+  int _two_cells_correct; //!< Count of organisms that latched their region correctly.
 };
 
 

Modified: branches/dkdev/source/main/cTaskLib.cc
===================================================================
--- branches/dkdev/source/main/cTaskLib.cc	2007-09-21 16:45:24 UTC (rev 2100)
+++ branches/dkdev/source/main/cTaskLib.cc	2007-09-24 22:26:43 UTC (rev 2101)
@@ -329,6 +329,9 @@
   if(name == "satellite")
     NewTask(name, "Sent a message from the perimeter to the satellite", &cTaskLib::Task_SentIdFromPerimeter);
   
+  if(name == "correct-region")
+    NewTask(name, "Determined whether in the correct region of the environment", &cTaskLib::Task_CorrectRegion);
+
   
   // Make sure we have actually found a task  
   if (task_array.GetSize() == start_size) {
@@ -1854,3 +1857,43 @@
   std::pair<int,int> location = deme.GetCellPosition(organism->GetCellID());
   return (location.first==0 || location.second==0);
 }
+
+
+/*! Reward an organism for successfully determining if it is in the region described
+by its population's two randomly selected cells -- This should work in both the deme
+and non-deme case.  Note that this task works in conjunction with deme replication -
+The trigger for deme replication is currently undefined.  It may be more appropriate to
+use compete demes with this approach. */
+double cTaskLib::Task_CorrectRegion(cTaskContext* ctx) const {
+  cOrganism* organism = ctx->GetOrganism();
+  if(organism->IsRegionLatched()) {
+    // get the data that we need to check if this cell is within the region described
+    // by the two randomly selected cells.
+    cPopulationCell& cell = m_world->GetPopulation().GetCell(organism->GetCellID());
+    cDeme& deme = m_world->GetPopulation().GetDeme(cell.GetDemeID());
+    std::pair<int,int> one_xy = deme.GetCellPosition(deme.GetCellsToLink().first);
+    std::pair<int,int> two_xy = deme.GetCellPosition(deme.GetCellsToLink().second);
+    
+    // get 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));
+    
+    // and test if this organism has selected the correct region.
+    std::pair<int,int> self_xy = deme.GetCellPosition(organism->GetCellID());
+    bool correct = false;
+    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)) {
+      // within region
+      correct = (organism->GetRegion() == 1);
+    } else {
+      correct = (organism->GetRegion() == 0);
+    }
+    
+    m_world->GetStats().TwoCellsRegionLatched(correct);
+    return correct;    
+  }
+  m_world->GetStats().TwoCellsRegionUnlatched();
+  return 0.0;
+}

Modified: branches/dkdev/source/main/cTaskLib.h
===================================================================
--- branches/dkdev/source/main/cTaskLib.h	2007-09-21 16:45:24 UTC (rev 2100)
+++ branches/dkdev/source/main/cTaskLib.h	2007-09-24 22:26:43 UTC (rev 2101)
@@ -226,6 +226,7 @@
   double Task_NetReceive(cTaskContext* ctx) const;
   
   double Task_SentIdFromPerimeter(cTaskContext* ctx) const;
+  double Task_CorrectRegion(cTaskContext* ctx) const;
 };
 
 




More information about the Avida-cvs mailing list