[avida-cvs] avida CVS commits: /current/source/cpu hardware_4stack.hh /current/source/main genome.hh genotype.hh inject_genebank.cc inject_genotype.cc inject_genotype.hh population.cc /current/source/viewers text_screen.cc text_screen.hh

wisnelaw avida-cvs at alife.org
Wed Sep 24 00:01:16 PDT 2003


wisnelaw		Tue Sep 23 16:01:16 2003 EDT

  Modified files:              
    /avida/current/source/cpu	hardware_4stack.hh 
    /avida/current/source/main	genome.hh genotype.hh inject_genebank.cc 
                              	inject_genotype.cc inject_genotype.hh 
                              	population.cc 
    /avida/current/source/viewers	text_screen.cc text_screen.hh 
  Log:
  Updated 4-stack parasite stuff to fix a few bugs
   
  
  
-------------- next part --------------
Index: avida/current/source/cpu/hardware_4stack.hh
diff -u avida/current/source/cpu/hardware_4stack.hh:1.8 avida/current/source/cpu/hardware_4stack.hh:1.9
--- avida/current/source/cpu/hardware_4stack.hh:1.8	Thu Aug  7 20:24:18 2003
+++ avida/current/source/cpu/hardware_4stack.hh	Tue Sep 23 16:01:11 2003
@@ -62,7 +62,7 @@
   cCodeLabel next_label;
   // If this thread was spawned by Inject, this will point to the genotype 
   // of the parasite running the thread.  Otherwise, it will be NULL.
-  cInjectGenotype * owner;
+  cInjectGenotype* owner;
 public:
   cHardware4Stack_Thread(cHardwareBase * in_hardware=NULL, int _id=-1);
   cHardware4Stack_Thread(const cHardware4Stack_Thread & in_thread, int _id=-1);
@@ -229,7 +229,8 @@
   inline void PrevThread(); // Shift the current thread in use.
   inline void NextThread();
   inline void SetThread(int value);
-  inline cInjectGenotype * GetThreadOwner(); 
+  inline cInjectGenotype * GetCurThreadOwner(); 
+  inline cInjectGenotype * GetThreadOwner(int in_thread);
   inline void SetThreadOwner(cInjectGenotype * in_genotype);
 
   // --------  Tests  --------
@@ -436,9 +437,14 @@
     cur_thread=value;
 }
 
-inline cInjectGenotype * cHardware4Stack::GetThreadOwner() 
+inline cInjectGenotype * cHardware4Stack::GetCurThreadOwner() 
 { 
   return threads[cur_thread].owner; 
+}
+
+inline cInjectGenotype * cHardware4Stack::GetThreadOwner(int thread) 
+{ 
+  return threads[thread].owner; 
 }
 
 inline void cHardware4Stack::SetThreadOwner(cInjectGenotype * in_genotype)
Index: avida/current/source/main/genome.hh
diff -u avida/current/source/main/genome.hh:1.4 avida/current/source/main/genome.hh:1.5
--- avida/current/source/main/genome.hh:1.4	Thu Jul 31 15:34:27 2003
+++ avida/current/source/main/genome.hh	Tue Sep 23 16:01:12 2003
@@ -32,6 +32,8 @@
 
   virtual void operator=(const cGenome & other_genome);
   virtual bool operator==(const cGenome & other_genome) const;
+  virtual bool operator!=(const cGenome & other_genome) const
+  { return !(this->operator==(other_genome)); }
   virtual bool operator<(const cGenome & other_genome) const
   { return AsString() < other_genome.AsString(); }
 
Index: avida/current/source/main/genotype.hh
diff -u avida/current/source/main/genotype.hh:1.24 avida/current/source/main/genotype.hh:1.25
--- avida/current/source/main/genotype.hh:1.24	Sat May 17 02:48:09 2003
+++ avida/current/source/main/genotype.hh	Tue Sep 23 16:01:12 2003
@@ -219,6 +219,7 @@
   void Deactivate(int update);
 
 
+
   int GetUpdateBorn()           { return birth_data.update_born; }
   int GetParentID()             { return birth_data.parent_id; }
   int GetParentDistance()       { return birth_data.parent_distance; }
Index: avida/current/source/main/inject_genebank.cc
diff -u avida/current/source/main/inject_genebank.cc:1.2 avida/current/source/main/inject_genebank.cc:1.3
--- avida/current/source/main/inject_genebank.cc:1.2	Thu Aug  7 20:41:04 2003
+++ avida/current/source/main/inject_genebank.cc	Tue Sep 23 16:01:13 2003
@@ -455,13 +455,15 @@
   found_genotype = active_inject_genotypes[list_num].Find(in_genome);
 
   if (!found_genotype) {
-    found_genotype = new cInjectGenotype();
+    found_genotype = new cInjectGenotype(stats.GetUpdate());
     found_genotype->SetGenome(in_genome);
     found_genotype->SetParent(parent_genotype);
-    
+    if(parent_genotype!=NULL)
+      {
+	parent_genotype->SetCanReproduce();
+      }
     AddInjectGenotype( found_genotype, list_num );
   }
-
   return found_genotype;
 }
 
@@ -625,38 +627,24 @@
 
 void cInjectGenebank::DumpDetailedEntry(cInjectGenotype * genotype, const cString & filename, int update)
 {
-  /*fp << genotype->GetID() << " "                //  1
-     << genotype->GetParentID() << " "          //  2
-    //     << genotype->GetParentDistance() << " "    //  3
-     << genotype->GetNumInjected() << " "      //  4
-     << genotype->GetTotalInjected() << " "    //  5
-     << genotype->GetLength() << " "            //  6
-    // << genotype->GetMerit() << " "             //  7
-    // << genotype->GetGestationTime() << " "     //  8
-    // << genotype->GetFitness() << " "           //  9
-     << genotype->GetUpdateBorn() << " "        // 10
-     << genotype->GetUpdateDeactivated() << " " // 11
-     << genotype->GetDepth() << " "             // 12
-     << genotype->GetGenome().AsString() << " " // 13
-     << endl;*/
-
-  cDataFile & df = stats.GetDataFile(filename);
-
-  df.WriteComment( "Avida parasite dump data" );
-  df.WriteTimeStamp();
-
-  //df.Write( update,                            "update");
-  df.Write( genotype->GetID(),                 "parasite genotype ID");
-  df.Write( genotype->GetName(),              "parasite genotype name");
-  df.Write( genotype->GetParentID(),           "parasite parent ID");
-  df.Write( genotype->GetNumInjected(),        "current number of injected creatures with this genotype");
-  df.Write( genotype->GetTotalInjected(),      "total number of injected creatures with this genotype");
-  df.Write( genotype->GetLength(),             "genotype length");
-  df.Write( genotype->GetUpdateBorn(),         "update this genotype was born");
-  df.Write( genotype->GetUpdateDeactivated(),  "update this genotype was deactivated");
-  df.Write( genotype->GetDepth(),              "genotype depth");
-  df.Write( genotype->GetGenome().AsString(),  "genome of this genotype");
-  df.Endl();
+  //if(genotype->CanReproduce())
+  //  {
+      cDataFile & df = stats.GetDataFile(filename);
+      
+      df.WriteComment( "Avida parasite dump data" );
+      df.WriteTimeStamp();
+      
+      df.Write( genotype->GetID(),                 "parasite genotype ID");
+      df.Write( genotype->GetName(),              "parasite genotype name");
+      df.Write( genotype->GetParentID(),           "parasite parent ID");
+      df.Write( genotype->GetNumInjected(),        "current number of injected creatures with this genotype");
+      df.Write( genotype->GetTotalInjected(),      "total number of injected creatures with this genotype");
+      df.Write( genotype->GetLength(),             "genotype length");
+      df.Write( genotype->GetUpdateBorn(),         "update this genotype was born");
+      df.Write( genotype->CanReproduce(),          "has this genotype reproduced?");
+      df.Write( genotype->GetGenome().AsString(),  "genome of this genotype");
+      df.Endl();
+      //}
 }
 
 bool cInjectGenebank::OK()
Index: avida/current/source/main/inject_genotype.cc
diff -u avida/current/source/main/inject_genotype.cc:1.1 avida/current/source/main/inject_genotype.cc:1.2
--- avida/current/source/main/inject_genotype.cc:1.1	Thu Aug  7 20:24:19 2003
+++ avida/current/source/main/inject_genotype.cc	Tue Sep 23 16:01:13 2003
@@ -52,6 +52,7 @@
   , name("p001-no_name")
   , flag_threshold(false)
   , is_active(true)
+      , can_reproduce(false)
   , defer_adjust(0)
   , symbol(0)
   , birth_data(in_update_born)
Index: avida/current/source/main/inject_genotype.hh
diff -u avida/current/source/main/inject_genotype.hh:1.1 avida/current/source/main/inject_genotype.hh:1.2
--- avida/current/source/main/inject_genotype.hh:1.1	Thu Aug  7 20:24:19 2003
+++ avida/current/source/main/inject_genotype.hh	Tue Sep 23 16:01:14 2003
@@ -65,6 +65,7 @@
   cString name;
   bool flag_threshold;
   bool is_active;      // Is this genotype still alive?
+  bool can_reproduce;  // Can this genotype reproduce?
   int defer_adjust;    // Don't adjust in the genebank until all are cleared.
 
   int id_num;
@@ -143,10 +144,12 @@
   //int GetTestGenerations() const;
 
   void SetParent(cInjectGenotype * parent);
+  void SetUpdateBorn (int update) { birth_data.update_born = update; }
   void SetName(cString in_name)     { name = in_name; }
   void SetNext(cInjectGenotype * in_next) { next = in_next; }
   void SetPrev(cInjectGenotype * in_prev) { prev = in_prev; }
   void SetSymbol(char in_symbol) { symbol = in_symbol; }
+  void SetCanReproduce() { can_reproduce = true; }
   inline void SetThreshold();
   void IncDeferAdjust() { defer_adjust++; }
   void DecDeferAdjust() { defer_adjust--; assert(defer_adjust >= 0); }
@@ -218,6 +221,7 @@
   int GetUpdateDeactivated() { return birth_data.update_deactivated; }
   void Deactivate(int update);
 
+  bool CanReproduce()           { return can_reproduce; }
   int GetUpdateBorn()           { return birth_data.update_born; }
   int GetParentID()             { return birth_data.parent_id; }
 //int GetParentDistance()       { return birth_data.parent_distance; }
Index: avida/current/source/main/population.cc
diff -u avida/current/source/main/population.cc:1.114 avida/current/source/main/population.cc:1.115
--- avida/current/source/main/population.cc:1.114	Wed Sep 10 13:07:26 2003
+++ avida/current/source/main/population.cc	Tue Sep 23 16:01:14 2003
@@ -355,7 +355,7 @@
     return false;
 
   cHardware4Stack & parent_cpu = (cHardware4Stack &) parent.GetHardware();
-  cInjectGenotype * parent_genotype = parent_cpu.GetThreadOwner();
+  cInjectGenotype * parent_genotype = parent_cpu.GetCurThreadOwner();
   
   const int parent_id = parent.PopInterface().GetCellID();
   assert(parent_id >= 0 && parent_id < cell_array.GetSize());
@@ -377,12 +377,13 @@
 
   if(target_organism->InjectHost(parent_cpu.GetLabel(), injected_code)) {
     // If the parent genotype is not correct for the child, adjust it.
-    if (parent_genotype == NULL || !(parent_genotype->GetGenome() == injected_code)) {
+    if (parent_genotype == NULL || parent_genotype->GetGenome() != injected_code) {
       child_genotype = inject_genebank->AddInjectGenotype(injected_code, parent_genotype);
     }
     
     target_organism->AddParasite(child_genotype);
     child_genotype->AddParasite();
+    child_cpu.SetThreadOwner(child_genotype);
     //if(parent_genotype!=NULL)
     //  parent_genotype->RemoveParasite();
     inject_genebank->AdjustInjectGenotype(*child_genotype);
@@ -429,11 +430,12 @@
 bool cPopulation::ActivateInject(const int cell_id, const cGenome & injected_code)
 {
   cInjectGenotype * child_genotype = inject_genebank->AddInjectGenotype(injected_code);
-
+  cHardware4Stack & child_cpu = (cHardware4Stack &) cell_array[cell_id].GetOrganism()->GetHardware();
   if(cell_array[cell_id].GetOrganism()->InjectHost(cCodeLabel(), injected_code))
     {
       cell_array[cell_id].GetOrganism()->AddParasite(child_genotype);
       child_genotype->AddParasite();
+      child_cpu.SetThreadOwner(child_genotype);
       inject_genebank->AdjustInjectGenotype(*child_genotype);
     }
   else
@@ -1463,6 +1465,7 @@
   outfile.open("debug.out", ofstream::app);
   outfile << stats.GetUpdate() << endl;
   int total=0;
+  cInjectGenotype * temp;
   for(int x=0; x<cell_array.GetSize(); x++)
     {
       if(cell_array[x].GetOrganism()!=NULL)
@@ -1471,10 +1474,17 @@
 		 cell_array[x].GetOrganism()->GetNumParasites()<=1);
 	  total+=cell_array[x].GetOrganism()->GetNumParasites();
 	  if(cell_array[x].GetOrganism()->GetNumParasites())
-	    outfile << x << " ";
+	    {
+	      cHardware4Stack & cpu = (cHardware4Stack &) cell_array[x].GetOrganism()->GetHardware();
+	      outfile << x << " ";
+	      outfile << cell_array[x].GetOrganism()->GetGenotype()->GetID() << " ";
+	      temp = cpu.GetThreadOwner(1);
+	      assert(temp!=NULL);
+	      outfile << temp->GetID() << endl;	      
+	    }
 	}
     }
-  outfile << endl << total << endl;
+  outfile << total << endl;
   outfile.close();
 }
 
Index: avida/current/source/viewers/text_screen.cc
diff -u avida/current/source/viewers/text_screen.cc:1.13 avida/current/source/viewers/text_screen.cc:1.14
--- avida/current/source/viewers/text_screen.cc:1.13	Wed Jul 16 19:36:55 2003
+++ avida/current/source/viewers/text_screen.cc	Tue Sep 23 16:01:14 2003
@@ -10,6 +10,8 @@
 #include "../main/species.hh"
 #include "../main/genotype.hh"
 #include "../main/genebank.hh"
+#include "../main/inject_genotype.hh"
+#include "../main/inject_genebank.hh"
 #include "../main/population.hh"
 #include "../main/population_cell.hh"
 #include "../main/organism.hh"
@@ -61,6 +63,16 @@
   }
 }
 
+void cViewInfo::AddInjectGenChart(cInjectGenotype * in_gen)
+{
+  for (int i = 0; i < NUM_SYMBOLS; i++) {
+    if (inject_genotype_chart[i] == NULL) {
+      inject_genotype_chart[i] = in_gen;
+      in_gen->SetSymbol(symbol_chart[i]);
+      break;
+    }
+  }
+}
 
 void cViewInfo::SetupSymbolMaps(int map_mode, bool use_color)
 {
Index: avida/current/source/viewers/text_screen.hh
diff -u avida/current/source/viewers/text_screen.hh:1.12 avida/current/source/viewers/text_screen.hh:1.13
--- avida/current/source/viewers/text_screen.hh:1.12	Thu Aug  7 20:24:19 2003
+++ avida/current/source/viewers/text_screen.hh	Tue Sep 23 16:01:15 2003
@@ -23,6 +23,8 @@
 class cPopulationCell;
 class cOrganism;
 class cGenebank;
+class cInjectGenotype;
+class cInjectGenebank;
 
 #define NUM_SYMBOLS 12
 #define SYMBOL_THRESHOLD 10
@@ -68,6 +70,7 @@
   // Symbol information
   cGenotype * genotype_chart[NUM_SYMBOLS];
   cSpecies * species_chart[NUM_SYMBOLS];
+  cInjectGenotype * inject_genotype_chart[NUM_SYMBOLS];
   char symbol_chart[NUM_SYMBOLS];
 
   tArray<char> map;
@@ -75,8 +78,10 @@
 
   inline bool InGenChart(cGenotype * in_gen);
   inline bool InSpeciesChart(cSpecies * in_species);
+  inline bool InInjectGenChart(cInjectGenotype * in_gen);
   void AddGenChart(cGenotype * in_gen);
   void AddSpeciesChart(cSpecies * in_species);
+  void AddInjectGenChart(cInjectGenotype * in_gen);
 public:
   cViewInfo(cPopulation & in_population);
   ~cViewInfo() { ; }
@@ -100,6 +105,7 @@
   int GetNumSymbols() { return NUM_SYMBOLS; }
   cGenotype * GetGenotype(int index) { return genotype_chart[index]; }
   cSpecies * GetSpecies(int index) { return species_chart[index]; }
+  cInjectGenotype * GetInjectGenotype(int index) { return inject_genotype_chart[index]; }
 
   cPopulationCell * GetActiveCell() { return active_cell; }
 
@@ -167,6 +173,14 @@
 {
   for (int i = 0; i < NUM_SYMBOLS; i++) {
     if (species_chart[i] == in_species) return true;
+  }
+  return false;
+}
+
+inline bool cViewInfo::InInjectGenChart(cInjectGenotype * in_gen)
+{
+  for (int i = 0; i < NUM_SYMBOLS; i++) {
+    if (inject_genotype_chart[i] == in_gen) return true;
   }
   return false;
 }


More information about the Avida-cvs mailing list