[Avida-SVN] r1677 - in branches/collect: source/actions source/analyze source/classification source/cpu source/main source/python/AvidaGui2 source/targets source/tools tests tests/resources_9r/config

blwalker at myxo.css.msu.edu blwalker at myxo.css.msu.edu
Wed Jun 13 13:47:13 PDT 2007


Author: blwalker
Date: 2007-06-13 16:47:13 -0400 (Wed, 13 Jun 2007)
New Revision: 1677

Added:
   branches/collect/source/python/AvidaGui2/avida-ED-logo.png
   branches/collect/source/targets/viewer-core/
   branches/collect/tests/resources_9r/
   branches/collect/tests/resources_9r/config/instset-classic.cfg
Modified:
   branches/collect/source/actions/PopulationActions.cc
   branches/collect/source/analyze/cAnalyze.cc
   branches/collect/source/classification/cGenotype.cc
   branches/collect/source/classification/cGenotype.h
   branches/collect/source/cpu/cHardwareCPU.cc
   branches/collect/source/main/cAvidaConfig.cc
   branches/collect/source/main/cPopulation.cc
   branches/collect/source/main/cPopulation.h
   branches/collect/source/tools/cRandom.cc
   branches/collect/source/tools/cRandom.h
Log:

Porting r1651:1676 from development to collect branch


Modified: branches/collect/source/actions/PopulationActions.cc
===================================================================
--- branches/collect/source/actions/PopulationActions.cc	2007-06-13 20:42:16 UTC (rev 1676)
+++ branches/collect/source/actions/PopulationActions.cc	2007-06-13 20:47:13 UTC (rev 1677)
@@ -1436,6 +1436,42 @@
   }
 };
 
+
+class cActionSwapCells : public cAction
+{
+private:
+  int id1;
+  int id2;
+
+public:
+  cActionSwapCells(cWorld* world, const cString& args) : cAction(world, args), id1(-1), id2(-1)
+  {
+    cString largs(args);
+    if (largs.GetSize()) id1 = largs.PopWord().AsInt();
+    if (largs.GetSize()) id2 = largs.PopWord().AsInt();
+  }
+  
+  static const cString GetDescription() { return "Arguments: <int cell_id1> <int cell_id2>"; }
+  
+  void Process(cAvidaContext& ctx)
+  {
+    const int num_cells = m_world->GetPopulation().GetSize();
+    if (id1 < 0 || id1 >= num_cells ||
+	id2 < 0 || id2 >= num_cells) {
+      m_world->GetDriver().RaiseException("SwapCells cell ID out of range");
+      return;
+    }
+    if (id1 == id2) {
+      m_world->GetDriver().NotifyWarning("SwapCells cell IDs identical");
+    }
+
+    cPopulationCell& cell1 = m_world->GetPopulation().GetCell(id1);
+    cPopulationCell& cell2 = m_world->GetPopulation().GetCell(id2);
+    m_world->GetPopulation().SwapCells(cell1, cell2);
+  }
+};
+
+
 void RegisterPopulationActions(cActionLibrary* action_lib)
 {
   action_lib->Register<cActionInject>("Inject");
@@ -1472,6 +1508,8 @@
 
   action_lib->Register<cActionConnectCells>("ConnectCells");
   action_lib->Register<cActionDisconnectCells>("DisconnectCells");
+  action_lib->Register<cActionSetOptimizeMinMax>("SetOptimizeMinMax");
+  action_lib->Register<cActionSwapCells>("SwapCells");
 
   // @DMB - The following actions are DEPRECATED aliases - These will be removed in 2.7.
   action_lib->Register<cActionInject>("inject");
@@ -1500,6 +1538,5 @@
 
   action_lib->Register<cActionConnectCells>("connect_cells");
   action_lib->Register<cActionDisconnectCells>("disconnect_cells");
-
-  action_lib->Register<cActionSetOptimizeMinMax>("SetOptimizeMinMax");
+  action_lib->Register<cActionSwapCells>("swap_cells");
 }

Modified: branches/collect/source/analyze/cAnalyze.cc
===================================================================
--- branches/collect/source/analyze/cAnalyze.cc	2007-06-13 20:42:16 UTC (rev 1676)
+++ branches/collect/source/analyze/cAnalyze.cc	2007-06-13 20:47:13 UTC (rev 1677)
@@ -1758,7 +1758,8 @@
     ofstream& fp = m_world->GetDataFileOFStream(filename);
     CommandDetail_Header(fp, file_type, output_it);
     CommandDetail_Body(fp, file_type, output_it);
-  }
+		m_world->GetDataFileManager().Remove(filename);
+	}
   
   // And clean up...
   while (output_list.GetSize() != 0) delete output_list.Pop();

Modified: branches/collect/source/classification/cGenotype.cc
===================================================================
--- branches/collect/source/classification/cGenotype.cc	2007-06-13 20:42:16 UTC (rev 1676)
+++ branches/collect/source/classification/cGenotype.cc	2007-06-13 20:47:13 UTC (rev 1677)
@@ -46,6 +46,7 @@
   , defer_adjust(0)
   , id_num(in_id)
   , symbol(0)
+  , map_id(-1)
   , birth_data(in_update_born)
   , num_organisms(0)
   , last_num_organisms(0)
@@ -62,6 +63,7 @@
   // Reset some of the variables to make sure program will crash if a deleted
   // cell is read!
   symbol = '!';
+  map_id = -1;
 
   num_organisms = -1;
   total_organisms = -1;

Modified: branches/collect/source/classification/cGenotype.h
===================================================================
--- branches/collect/source/classification/cGenotype.h	2007-06-13 20:42:16 UTC (rev 1676)
+++ branches/collect/source/classification/cGenotype.h	2007-06-13 20:47:13 UTC (rev 1677)
@@ -61,6 +61,7 @@
 
   int id_num;
   char symbol;
+  int map_id;
 
   mutable cGenotype_TestData test_data;
   cGenotype_BirthData birth_data;
@@ -137,6 +138,7 @@
   void SetNext(cGenotype* in_next) { next = in_next; }
   void SetPrev(cGenotype* in_prev) { prev = in_prev; }
   void SetSymbol(char in_symbol) { symbol = in_symbol; }
+  void SetMapID(int in_id) { map_id = in_id; }
   inline void SetThreshold();
   void IncDeferAdjust() { defer_adjust++; }
   void DecDeferAdjust() { defer_adjust--; assert(defer_adjust >= 0); }
@@ -218,6 +220,7 @@
   bool GetThreshold() const     { return flag_threshold; }
   int GetID() const             { return id_num; }
   char GetSymbol() const        { return symbol; }
+  int GetMapID() const          { return map_id; }
 
   // Calculate a crude phylogentic distance based off of tracking parents
   // and grand-parents, including sexual tracking.
@@ -261,6 +264,7 @@
 {
   flag_threshold = true;
   if (symbol == '.') symbol = '+';
+  if (map_id == 0) map_id = 1;
 }
 
 inline void cGenotype::SetBreedStats(cGenotype & daughter)

Modified: branches/collect/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/collect/source/cpu/cHardwareCPU.cc	2007-06-13 20:42:16 UTC (rev 1676)
+++ branches/collect/source/cpu/cHardwareCPU.cc	2007-06-13 20:47:13 UTC (rev 1677)
@@ -486,8 +486,7 @@
   
   cPhenotype & phenotype = organism->GetPhenotype();
   
-  if (m_world->GetConfig().PROMOTERS_ENABLED.Get() == 1) 
-  {
+  if (m_world->GetConfig().PROMOTERS_ENABLED.Get() == 1) {
     //First instruction - check whether we should be starting at a promoter.
     if (phenotype.GetTimeUsed() == 0) Inst_Terminate(m_world->GetDefaultContext());
   }
@@ -499,8 +498,7 @@
   
   // If we have threads turned on and we executed each thread in a single
   // timestep, adjust the number of instructions executed accordingly.
-  const int num_inst_exec = (m_world->GetConfig().THREAD_SLICING_METHOD.Get() == 1) ?
-num_threads : 1;
+  const int num_inst_exec = (m_world->GetConfig().THREAD_SLICING_METHOD.Get() == 1) ? num_threads : 1;
   
   for (int i = 0; i < num_inst_exec; i++) {
     // Setup the hardware for the next instruction to be executed.
@@ -535,8 +533,7 @@
       const int addl_time_cost = m_inst_set->GetAddlTimeCost(cur_inst);
 
       // Prob of exec (moved from SingleProcess_PayCosts so that we advance IP after a fail)
-      if ( m_inst_set->GetProbFail(cur_inst) > 0.0 ) 
-      {
+      if ( m_inst_set->GetProbFail(cur_inst) > 0.0 ) {
         exec = !( ctx.GetRandom().P(m_inst_set->GetProbFail(cur_inst)) );
       }
       
@@ -551,8 +548,7 @@
       
       // In the promoter model, there may be a chance of termination
       // that causes execution to start at a new instruction (per instruction executed)
-      if ( m_world->GetConfig().PROMOTERS_ENABLED.Get() )
-      {
+      if ( m_world->GetConfig().PROMOTERS_ENABLED.Get() ) {
         const double processivity = m_world->GetConfig().PROMOTER_PROCESSIVITY_INST.Get();
         if ( ctx.GetRandom().P(1-processivity) ) Inst_Terminate(ctx);
       }
@@ -665,9 +661,11 @@
 	
   // And execute it.
   const bool exec_success = (this->*(m_functions[inst_idx]))(ctx);
-	
+
+  // NOTE: Organism may be dead now if instruction executed killed it (such as some divides, "die", or "kazi")
+
 #if INSTRUCTION_COUNT
-  // decrement if the instruction was not executed successfully
+  // Decrement if the instruction was not executed successfully.
   if (exec_success == false) {
     organism->GetPhenotype().DecCurInstCount(actual_inst.GetOp());
   }

Modified: branches/collect/source/main/cAvidaConfig.cc
===================================================================
--- branches/collect/source/main/cAvidaConfig.cc	2007-06-13 20:42:16 UTC (rev 1676)
+++ branches/collect/source/main/cAvidaConfig.cc	2007-06-13 20:47:13 UTC (rev 1677)
@@ -393,7 +393,7 @@
 	   << "  -h[elp]               Help on options (this listing)"<<endl
 	   << "  -i[nteractive]        Run analyze mode interactively" << endl
 	   << "  -l[oad] <filename>    Load a clone file" << endl
-	   << "  -r[eview]             Review analyze.cfg settings." << endl
+	   << "  -r[eview]             Review avida.cfg settings." << endl
 	   << "  -s[eed] <value>       Set random seed to <value>" << endl
 	   << "  -set <name> <value>   Overide values in avida.cfg" << endl
 	   << "  -v[ersion]            Prints the version number" << endl

Modified: branches/collect/source/main/cPopulation.cc
===================================================================
--- branches/collect/source/main/cPopulation.cc	2007-06-13 20:42:16 UTC (rev 1676)
+++ branches/collect/source/main/cPopulation.cc	2007-06-13 20:47:13 UTC (rev 1677)
@@ -649,6 +649,26 @@
 	return receive_value;
 }
 
+void cPopulation::SwapCells(cPopulationCell & cell1, cPopulationCell & cell2)
+{
+  cOrganism * org1 = cell1.RemoveOrganism();
+  cOrganism * org2 = cell2.RemoveOrganism();
+  if (org2 != NULL) {
+    cell1.InsertOrganism(*org2);
+    schedule->Adjust(cell1.GetID(), org2->GetPhenotype().GetMerit());
+  } else {
+    schedule->Adjust(cell1.GetID(), cMerit(0));
+  }
+
+  if (org1 != NULL) {
+    cell2.InsertOrganism(*org1);
+    schedule->Adjust(cell2.GetID(), org1->GetPhenotype().GetMerit());
+  } else {
+    schedule->Adjust(cell2.GetID(), cMerit(0));
+  }
+}
+
+
 // CompeteDemes  probabilistically copies demes into the next generation
 // based on their fitness. How deme fitness is estimated is specified by 
 // competition_type input argument as:

Modified: branches/collect/source/main/cPopulation.h
===================================================================
--- branches/collect/source/main/cPopulation.h	2007-06-13 20:42:16 UTC (rev 1676)
+++ branches/collect/source/main/cPopulation.h	2007-06-13 20:47:13 UTC (rev 1677)
@@ -162,9 +162,12 @@
   
   // Deactivate an organism in the population (required for deactivations)
   void KillOrganism(cPopulationCell& in_cell);
+
+  // Specialized functionality
   void Kaboom(cPopulationCell& in_cell, int distance=0);
   void AddSellValue(const int data, const int label, const int sell_price, const int org_id, const int cell_id);
   int BuyValue(const int label, const int buy_price, const int cell_id);
+  void SwapCells(cPopulationCell & cell1, cPopulationCell & cell2);
 
   // Deme-related methods
   void CompeteDemes(int competition_type);

Copied: branches/collect/source/python/AvidaGui2/avida-ED-logo.png (from rev 1675, development/source/python/AvidaGui2/avida-ED-logo.png)
===================================================================
(Binary files differ)


Property changes on: branches/collect/source/python/AvidaGui2/avida-ED-logo.png
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Copied: branches/collect/source/targets/viewer-core (from rev 1675, development/source/targets/viewer-core)

Modified: branches/collect/source/tools/cRandom.cc
===================================================================
--- branches/collect/source/tools/cRandom.cc	2007-06-13 20:42:16 UTC (rev 1676)
+++ branches/collect/source/tools/cRandom.cc	2007-06-13 20:47:13 UTC (rev 1677)
@@ -40,6 +40,9 @@
 
 cRandom::cRandom(const int in_seed)
 : seed(0), original_seed(0), inext(0), inextp(0), expRV(0)
+#ifdef DEBUG_CRANDOM
+, m_call_count(0)
+#endif
 {
   for (int i = 0; i < 56; ++i) {
     ma[i] = 0;
@@ -118,6 +121,9 @@
 
 unsigned int cRandom::Get()
 {
+#ifdef DEBUG_CRANDOM
+  m_call_count++;
+#endif
   if (++inext == 56) inext = 0;
   if (++inextp == 56) inextp = 0;
   assert(inext < 56);

Modified: branches/collect/source/tools/cRandom.h
===================================================================
--- branches/collect/source/tools/cRandom.h	2007-06-13 20:42:16 UTC (rev 1676)
+++ branches/collect/source/tools/cRandom.h	2007-06-13 20:47:13 UTC (rev 1677)
@@ -43,6 +43,9 @@
   int inext;
   int inextp;
   int ma[56];
+#ifdef DEBUG_CRANDOM
+  long m_call_count;
+#endif
   
   // Constants ////////////////////////////////////////////////////////////////
   // Statistical Approximation
@@ -76,7 +79,12 @@
    **/
   cRandom(const int in_seed = -1);
   virtual ~cRandom() { ; }
+
   
+#ifdef DEBUG_CRANDOM
+  inline long GetCallCount() { return m_call_count; }
+#endif
+  
   /**
    * @return The seed that was actually used to start the random sequence.
    **/

Copied: branches/collect/tests/resources_9r (from rev 1675, development/tests/resources_9r)

Copied: branches/collect/tests/resources_9r/config/instset-classic.cfg (from rev 1676, development/tests/resources_9r/config/instset-classic.cfg)
===================================================================
--- branches/collect/tests/resources_9r/config/instset-classic.cfg	                        (rev 0)
+++ branches/collect/tests/resources_9r/config/instset-classic.cfg	2007-06-13 20:47:13 UTC (rev 1677)
@@ -0,0 +1,52 @@
+nop-A      1   # a
+nop-B      1   # b
+nop-C      1   # c
+if-n-equ   1   # d
+if-less    1   # e
+pop        1   # f
+push       1   # g
+swap-stk   1   # h
+swap       1   # i 
+shift-r    1   # j
+shift-l    1   # k
+inc        1   # l
+dec        1   # m
+add        1   # n
+sub        1   # o
+nand       1   # p
+IO         1   # q   Puts current contents of register and gets new.
+h-alloc    1   # r   Allocate as much memory as organism can use.
+h-divide   1   # s   Cuts off everything between the read and write heads
+h-copy     1   # t   Combine h-read and h-write
+h-search   1   # u   Search for matching template, set flow head & return info
+               #   #   if no template, move flow-head here, set size&offset=0.
+mov-head   1   # v   Move ?IP? head to flow control.
+jmp-head   1   # w   Move ?IP? head by fixed amount in CX.  Set old pos in CX.
+get-head   1   # x   Get position of specified head in CX.
+if-label   1   # y
+set-flow   1   # z   Move flow-head to address in ?CX? 
+
+#adv-head   1
+#jump-f     1
+#jump-b     1
+#call       1
+#return     1
+#if-bit-1   1
+#get        1
+#put        1
+#h-read     1
+#h-write    1
+#set-head   1
+#search-f   1
+#search-b   1
+
+
+# Works on multiple nops:  pop  push  inc  dec  IO  adv-head 
+
+# What if we add a new head.  Search will return the location of something,
+# and put the new head there.  Then set-head will move another head to that
+# point.  In the case of the copy loop, it only needs to be set once and
+# this will speed up the code quite a bit!
+
+# Search with no template returns current position (abs line number) in
+# genome.
\ No newline at end of file




More information about the Avida-cvs mailing list