[Avida-SVN] r1094 - in development/source: main targets/avida-viewer

ofria at myxo.css.msu.edu ofria at myxo.css.msu.edu
Tue Nov 21 14:03:08 PST 2006


Author: ofria
Date: 2006-11-21 17:03:01 -0500 (Tue, 21 Nov 2006)
New Revision: 1094

Modified:
   development/source/main/cAvidaConfig.h
   development/source/main/cMutationRates.cc
   development/source/main/cMutationRates.h
   development/source/main/cPopulation.cc
   development/source/targets/avida-viewer/cBarScreen.cc
   development/source/targets/avida-viewer/cEnvironmentScreen.cc
   development/source/targets/avida-viewer/cHistScreen.cc
   development/source/targets/avida-viewer/cHistScreen.h
   development/source/targets/avida-viewer/cOptionsScreen.cc
   development/source/targets/avida-viewer/cScreen.h
   development/source/targets/avida-viewer/cView.cc
Log:
Added three new settings to avida.cfg:
 MUT_RATE_SOURCE determines if mutation rates should be inhereitedfrom parents
   or set by the environment.

 META_COPY_MUT gives the probability of the copy mutation changing from parent
   to offsping.

 META_STD_DEV gives the standard deviation for the copy mutation rates if they
   do change between parent and offspring.

Modified the action PrintDemeStats to also print out the average mutation rate
used by each deme.

Made a bunch of modification to the ncurses viewer:
* Setup histogram screen to include legend.
* Centered message boxes on screen.
* Setup environment screen to work, even when no resources are present, or not
  ever reaction is associated with a resource.  (Before in many cases it would
  appear, but crash when you tried to use it).
* Minor reorganization of options screen



Modified: development/source/main/cAvidaConfig.h
===================================================================
--- development/source/main/cAvidaConfig.h	2006-11-21 15:18:16 UTC (rev 1093)
+++ development/source/main/cAvidaConfig.h	2006-11-21 22:03:01 UTC (rev 1094)
@@ -223,7 +223,10 @@
   CONFIG_ADD_VAR(INJECT_INS_PROB, double, 0.0, "Insertion rate (per site, applied on inject)");
   CONFIG_ADD_VAR(INJECT_DEL_PROB, double, 0.0, "Deletion rate (per site, applied on inject)");
   CONFIG_ADD_VAR(INJECT_MUT_PROB, double, 0.0, "Mutation rate (per site, applied on inject)");
-  
+  CONFIG_ADD_VAR(META_COPY_MUT, double, 0.0, "Prob. of copy mutation rate changing (per gen)");
+  CONFIG_ADD_VAR(META_STD_DEV, double, 0.0, "Standard deviation of meta mutation size.");
+  CONFIG_ADD_VAR(MUT_RATE_SOURCE, int, 1, "1 = Mutation rates determined by environment.\n2 = Mutation rates inhereted from parent.");
+ 
   CONFIG_ADD_GROUP(REVERSION_GROUP, "Mutation Reversion\nThese slow down avida a lot, and should be set to 0.0 normally.");
   CONFIG_ADD_VAR(REVERT_FATAL, double, 0.0, "Should any mutations be reverted on birth?");
   CONFIG_ADD_VAR(REVERT_DETRIMENTAL, double, 0.0, "  0.0 to 1.0; Probability of reversion.");

Modified: development/source/main/cMutationRates.cc
===================================================================
--- development/source/main/cMutationRates.cc	2006-11-21 15:18:16 UTC (rev 1093)
+++ development/source/main/cMutationRates.cc	2006-11-21 22:03:01 UTC (rev 1094)
@@ -28,6 +28,8 @@
   inject.ins_prob = world->GetConfig().INJECT_INS_PROB.Get();
   inject.del_prob = world->GetConfig().INJECT_DEL_PROB.Get();
   inject.mut_prob = world->GetConfig().INJECT_MUT_PROB.Get();
+  meta.copy_mut_prob = world->GetConfig().META_COPY_MUT.Get();
+  meta.standard_dev = world->GetConfig().META_STD_DEV.Get();
 }
 
 void cMutationRates::Clear()
@@ -44,6 +46,8 @@
   inject.ins_prob = 0.0;
   inject.del_prob = 0.0;
   inject.mut_prob = 0.0;
+  meta.copy_mut_prob = 0.0;
+  meta.standard_dev = 0.0;
 }
 
 void cMutationRates::Copy(const cMutationRates& in_muts)
@@ -60,4 +64,6 @@
   inject.ins_prob = in_muts.inject.ins_prob;
   inject.del_prob = in_muts.inject.del_prob;
   inject.mut_prob = in_muts.inject.mut_prob;
+  meta.copy_mut_prob = in_muts.meta.copy_mut_prob;
+  meta.standard_dev = in_muts.meta.standard_dev;
 }

Modified: development/source/main/cMutationRates.h
===================================================================
--- development/source/main/cMutationRates.h	2006-11-21 15:18:16 UTC (rev 1093)
+++ development/source/main/cMutationRates.h	2006-11-21 22:03:01 UTC (rev 1094)
@@ -57,7 +57,13 @@
   };
   sInjectMuts inject;
   
-  
+  // Mutations in mutation rates...
+  struct sMetaMuts {
+    double copy_mut_prob;  // Prob of copy mut changing.
+    double standard_dev;   // Standard dev. on meta muts.
+  };
+  sMetaMuts meta;
+
   cMutationRates& operator=(const cMutationRates&); // @not_implemented
 
 public:
@@ -75,6 +81,13 @@
   bool TestDivideIns(cAvidaContext& ctx) const { return ctx.GetRandom().P(divide.divide_ins_prob); }
   bool TestDivideDel(cAvidaContext& ctx) const { return ctx.GetRandom().P(divide.divide_del_prob); }
   bool TestParentMut(cAvidaContext& ctx) const { return ctx.GetRandom().P(divide.parent_mut_prob); }
+  double DoMetaCopyMut(cAvidaContext& ctx) {
+    if (ctx.GetRandom().P(meta.copy_mut_prob) == false) return 1.0;
+    const double exp = ctx.GetRandom().GetRandNormal() * meta.standard_dev;
+    const double change = pow(2, exp);
+    copy.mut_prob *= change;
+    return change;
+  }
 
   double GetPointMutProb() const     { return exec.point_mut_prob; }
   double GetCopyMutProb() const      { return copy.mut_prob; }
@@ -88,9 +101,11 @@
   double GetInjectInsProb() const    { return inject.ins_prob; }
   double GetInjectDelProb() const    { return inject.del_prob; }
   double GetInjectMutProb() const    { return inject.mut_prob; }
+  double GetMetaCopyMutProb() const  { return meta.copy_mut_prob; }
+  double GetMetaStandardDev() const  { return meta.standard_dev; }
   
   void SetPointMutProb(double in_prob)  { exec.point_mut_prob    = in_prob; }
-  void SetCopyMutProb(double in_prob)   { copy.mut_prob     = in_prob; }
+  void SetCopyMutProb(double in_prob)   { copy.mut_prob          = in_prob; }
   void SetInsMutProb(double in_prob)    { divide.ins_prob        = in_prob; }
   void SetDelMutProb(double in_prob)    { divide.del_prob        = in_prob; }
   void SetDivMutProb(double in_prob)    { divide.mut_prob        = in_prob; }
@@ -101,6 +116,8 @@
   void SetInjectInsProb(double in_prob) { inject.ins_prob        = in_prob; }
   void SetInjectDelProb(double in_prob) { inject.del_prob        = in_prob; }
   void SetInjectMutProb(double in_prob) { inject.mut_prob        = in_prob; }
+  void SetMetaCopyMutProb(double in_prob) { meta.copy_mut_prob   = in_prob; }
+  void SetMetaStandardDev(double in_dev) { meta.standard_dev     = in_dev; }
 };
 
 

Modified: development/source/main/cPopulation.cc
===================================================================
--- development/source/main/cPopulation.cc	2006-11-21 15:18:16 UTC (rev 1093)
+++ development/source/main/cPopulation.cc	2006-11-21 22:03:01 UTC (rev 1094)
@@ -299,9 +299,19 @@
     // If we replaced the parent, make a note of this.
     if (target_cells[i] == parent_cell.GetID()) parent_alive = false;      
     
-    // Update the mutation rates of each child....
-    child_array[i]->MutationRates().Copy(GetCell(target_cells[i]).MutationRates());
-    
+    const int mut_source = m_world->GetConfig().MUT_RATE_SOURCE.Get();
+    if (mut_source == 1) {
+      // Update the mutation rates of each child from the environment....
+      child_array[i]->MutationRates().Copy(GetCell(target_cells[i]).MutationRates());
+    } else {
+      // Update the mutation rates of each child from its parent.
+      child_array[i]->MutationRates().Copy(parent_organism.MutationRates());
+      // If there is a meta-mutation rate, do tests for it.
+      if (child_array[i]->MutationRates().GetMetaCopyMutProb() > 0.0) {
+	child_array[i]->MutationRates().DoMetaCopyMut(ctx);
+      }    
+    }
+
     // Update the phenotypes of each child....
     const int child_length = child_array[i]->GetGenome().GetSize();
     child_array[i]->GetPhenotype().SetupOffspring(parent_phenotype,child_length);
@@ -1093,6 +1103,7 @@
   cDataFile & df_task = m_world->GetDataFile("deme_task.dat");
   cDataFile & df_donor = m_world->GetDataFile("deme_donor.dat");
   cDataFile & df_receiver = m_world->GetDataFile("deme_receiver.dat");
+  cDataFile & df_mut_rates = m_world->GetDataFile("deme_mut_rates.dat");
   
   df_fit.WriteComment("Average fitnesses for each deme in the population");
   df_life_fit.WriteComment("Average life fitnesses for each deme in the population");
@@ -1101,6 +1112,7 @@
   df_task.WriteComment("Num orgs doing each task for each deme in population");
   df_donor.WriteComment("Num orgs doing doing a donate for each deme in population");
   df_receiver.WriteComment("Num orgs doing receiving a donate for each deme in population");
+  df_mut_rates.WriteComment("Average mutation rates for organisms in each deme");
   
   df_fit.WriteTimeStamp();
   df_life_fit.WriteTimeStamp();
@@ -1109,6 +1121,7 @@
   df_task.WriteTimeStamp();
   df_donor.WriteTimeStamp();
   df_receiver.WriteTimeStamp();
+  df_mut_rates.WriteTimeStamp();
   
   df_fit.Write(stats.GetUpdate(), "update");
   df_life_fit.Write(stats.GetUpdate(), "update");
@@ -1117,6 +1130,7 @@
   df_task.Write(stats.GetUpdate(), "update");
   df_donor.Write(stats.GetUpdate(), "update");
   df_receiver.Write(stats.GetUpdate(), "update");
+  df_mut_rates.Write(stats.GetUpdate(), "update");
   
   const int num_inst = m_world->GetNumInstructions();
   const int num_task = environment.GetTaskLib().GetSize();
@@ -1139,6 +1153,7 @@
     cDoubleSum single_deme_gest_time;
     cDoubleSum single_deme_donor;
     cDoubleSum single_deme_receiver;
+    cDoubleSum single_deme_mut_rate;
     tArray<cIntSum> single_deme_task(num_task);
     tArray<cIntSum> single_deme_inst(num_inst);
     
@@ -1153,6 +1168,7 @@
       single_deme_gest_time.Add(phenotype.GetGestationTime()); 	
       single_deme_donor.Add(phenotype.IsDonorLast()); 	
       single_deme_receiver.Add(phenotype.IsReceiver()); 	
+      single_deme_mut_rate.Add(GetCell(cur_cell).GetOrganism()->MutationRates().GetCopyMutProb());
       
       for (int j = 0; j < num_inst; j++) {
         single_deme_inst[j].Add(phenotype.GetLastInstCount()[j]);
@@ -1173,6 +1189,7 @@
     df_gest.Write(single_deme_gest_time.Ave(), comment);
     df_donor.Write(single_deme_donor.Sum(), comment);
     df_receiver.Write(single_deme_receiver.Sum(), comment);
+    df_mut_rates.Write(single_deme_mut_rate.Ave(), comment);
     
     for (int j = 0; j < num_task; j++) {
       comment.Set("Deme %d, Task %d", deme_id, j);
@@ -1193,6 +1210,7 @@
   df_task.Endl();
   df_donor.Endl();
   df_receiver.Endl();
+  df_mut_rates.Endl();
 }
 
 

Modified: development/source/targets/avida-viewer/cBarScreen.cc
===================================================================
--- development/source/targets/avida-viewer/cBarScreen.cc	2006-11-21 15:18:16 UTC (rev 1093)
+++ development/source/targets/avida-viewer/cBarScreen.cc	2006-11-21 22:03:01 UTC (rev 1094)
@@ -15,14 +15,12 @@
 
 int cBarScreen::AddMenuOption(const cString option, int max_x, int cur_x)
 {
-  if (cur_x + option.GetSize() + 2 >= max_x) return cur_x;
+  if (cur_x + option.GetSize() >= max_x) return cur_x;
 
-  SetBoldColor(COLOR_WHITE);
-  Print(1, cur_x, option);
-  SetBoldColor(COLOR_CYAN);
-  Print(1, cur_x+1, option[1]);  
+  PrintOption(1, cur_x, option);
 
-  return cur_x+option.GetSize()+2;
+  if (option.GetSize() < 6)  return cur_x+option.GetSize()+2;
+  return cur_x+option.GetSize()+1;
 }
 
 void cBarScreen::Draw()
@@ -35,7 +33,7 @@
 
   int offset = prog_name.GetSize() + 4;
   VLine(Width() - offset - 2);
-  Print(1, Width() - offset, "%s", static_cast<const char*>(prog_name));
+  Print(1, Width() - offset+1, "%s", static_cast<const char*>(prog_name));
 
   Print(1, 2, "Update:");
 
@@ -45,10 +43,11 @@
   // Include options in their general order of importance.
   cur_x = AddMenuOption("[M]ap", max_x, cur_x);
   cur_x = AddMenuOption("[S]tats", max_x, cur_x);
-  cur_x = AddMenuOption("[O]ptions", max_x, cur_x);
+  cur_x = AddMenuOption("[A]nalyze", max_x, cur_x);
   cur_x = AddMenuOption("[Z]oom", max_x, cur_x);
-  cur_x = AddMenuOption("[E]nv", max_x, cur_x);
+  cur_x = AddMenuOption("[O]ptions", max_x, cur_x);
   cur_x = AddMenuOption("[H]ist", max_x, cur_x);
+  cur_x = AddMenuOption("[E]nv", max_x, cur_x);
   cur_x = AddMenuOption("[B]lank", max_x, cur_x);
   cur_x = AddMenuOption("[P]ause", max_x, cur_x);
   cur_x = AddMenuOption("[C]hoose CPU", max_x, cur_x);

Modified: development/source/targets/avida-viewer/cEnvironmentScreen.cc
===================================================================
--- development/source/targets/avida-viewer/cEnvironmentScreen.cc	2006-11-21 15:18:16 UTC (rev 1093)
+++ development/source/targets/avida-viewer/cEnvironmentScreen.cc	2006-11-21 22:03:01 UTC (rev 1094)
@@ -134,38 +134,40 @@
 {
   const cResourceLib & res_lib = m_world->GetEnvironment().GetResourceLib();
   const cReactionLib & rxn_lib = m_world->GetEnvironment().GetReactionLib();
+  const int num_resources = m_world->GetPopulation().GetResources().GetSize();
   
+  // If there are no resources, then we have nothing to update.
+  if (num_resources == 0) return;
+
+  // Update the quantity of each resource.
   SetBoldColor(COLOR_CYAN);
-  //int j=0;
-  //int last_count=0;
-  for(int i=0; i<m_world->GetPopulation().GetResources().GetSize(); i++)
+  for(int i = 0; i < num_resources; i++)
   {
     Print(i+1, 40, "%7.2f", m_world->GetPopulation().GetResources()[i]);
   }
   
+  // Highlight the current resource in blue.
   SetBoldColor(COLOR_BLUE);
   Print(res_selection+1, 1, res_lib.GetResource(res_selection)->GetName());
   Print(res_selection+1, 12, "%7.2f", res_lib.GetResource(res_selection)->GetInflow());
   Print(res_selection+1, 24, "%7.2f", res_lib.GetResource(res_selection)->GetOutflow());
   Print(res_selection+1, 40, "%7.2f", m_world->GetPopulation().GetResources()[res_selection]);
   
+  // Print all of the information about the current resources.
   int offset=0;
-  
   SetBoldColor(COLOR_CYAN);
-  for(int i=0; i<rxn_lib.GetSize(); i++)
-  {
-    for(int j=0; j<rxn_lib.GetReaction(i)->GetProcesses().GetSize(); j++)
-    {
+  for(int i=0; i<rxn_lib.GetSize(); i++) {
+    for(int j=0; j<rxn_lib.GetReaction(i)->GetProcesses().GetSize(); j++) {
       if(rxn_lib.GetReaction(i)->GetProcesses().GetPos(j)->GetResource()->GetName() == 
-         res_lib.GetResource(res_selection)->GetName())
-	    {
-	      Print(m_world->GetPopulation().GetResources().GetSize()+5+offset, 2, 
-              rxn_lib.GetReaction(i)->GetName());
-	      offset++;
-	    }
+         res_lib.GetResource(res_selection)->GetName()) {
+	Print(num_resources + 5 + offset, 2,
+	      rxn_lib.GetReaction(i)->GetName());
+	offset++;
+      }
     }
   }
   
+  // Print the name of the current resource at the bottom of the screen.
   SetBoldColor(COLOR_WHITE);
   Print(res_lib.GetSize()+3, 37, "%s", static_cast<const char*>(res_lib.GetResource(res_selection)->GetName()));
   Print(res_lib.GetSize()+3, res_lib.GetResource(res_selection)->GetName().GetSize()+37, ":");
@@ -177,43 +179,55 @@
 {
   const cReactionLib & rxn_lib = m_world->GetEnvironment().GetReactionLib();
   const cResourceLib & res_lib = m_world->GetEnvironment().GetResourceLib();
+  const int num_reactions = m_world->GetStats().GetReactions().GetSize();
   
+  // If we have no reactions, stop right here.
+  if (num_reactions == 0) return;
+
+  // For each reaction, print how often it was performed.
   SetBoldColor(COLOR_CYAN);
-  for(int i=0; i<m_world->GetStats().GetReactions().GetSize(); i++)
-  {
+  for(int i = 0; i < num_reactions; i++) {
     Print(i+1, 40, "%7.2f", m_world->GetStats().GetReactions()[i]);
   }
   
+  // Highlight the selected reaction.
   SetBoldColor(COLOR_BLUE);
   Print(rxn_selection+1, 1, rxn_lib.GetReaction(rxn_selection)->GetName());
   Print(rxn_selection+1, 40, "%7.2f", m_world->GetStats().GetReactions()[rxn_selection]);
   
   
+  // Update header on reaction section.
+  SetBoldColor(COLOR_WHITE);
+  Print(rxn_lib.GetSize()+3, 37, "%s", static_cast<const char*>(rxn_lib.GetReaction(rxn_selection)->GetName()));
+  Print(rxn_lib.GetSize()+3, rxn_lib.GetReaction(rxn_selection)->GetName().GetSize()+37, ":");
+  Print(rxn_lib.GetSize()+3, rxn_lib.GetReaction(rxn_selection)->GetName().GetSize()+38, "        ");
+  
+  // Print information about each resource associated with active reaction.
   int offset=0;
-  
   SetBoldColor(COLOR_CYAN);
-  for(int i=0; i<rxn_lib.GetReaction(rxn_selection)->GetProcesses().GetSize(); i++)
-  {
-    Print(m_world->GetStats().GetReactions().GetSize()+5+offset, 2, 
-          rxn_lib.GetReaction(rxn_selection)->GetProcesses().GetPos(i)->GetResource()->GetName());
+  const int num_processes = rxn_lib.GetReaction(rxn_selection)->GetProcesses().GetSize();
+  for(int i = 0; i < num_processes; i++) {
+    cResource * cur_resource =
+      rxn_lib.GetReaction(rxn_selection)->GetProcesses().GetPos(i)->GetResource();
+
+    // Ignore all processes that are not associated with resources.
+    if (cur_resource == NULL) continue;
+
+    // Print info about this resource.
+    Print(m_world->GetStats().GetReactions().GetSize()+5+offset, 2,
+	  cur_resource->GetName());
     Print(m_world->GetStats().GetReactions().GetSize()+5+offset, 13, "%7.2f",
-          rxn_lib.GetReaction(rxn_selection)->GetProcesses().GetPos(i)->GetResource()->GetInflow());
+	  cur_resource->GetInflow());
     Print(m_world->GetStats().GetReactions().GetSize()+5+offset, 25, "%7.2f",
-          rxn_lib.GetReaction(rxn_selection)->GetProcesses().GetPos(i)->GetResource()->GetOutflow());
-    for(int j=0; j<res_lib.GetSize(); j++)
-    {
-      if(res_lib.GetResource(j)->GetName() ==
-         rxn_lib.GetReaction(rxn_selection)->GetProcesses().GetPos(i)->GetResource()->GetName())
+          cur_resource->GetOutflow());
+    for(int j=0; j < res_lib.GetSize(); j++) {
+      if (res_lib.GetResource(j)->GetName() == cur_resource->GetName()) {
         Print(m_world->GetStats().GetReactions().GetSize()+5+offset, 40, "%7.2f", 
               m_world->GetPopulation().GetResources()[j]);
+      }
     }
     offset++;  
   }
-  SetBoldColor(COLOR_WHITE);
-  Print(rxn_lib.GetSize()+3, 37, "%s", static_cast<const char*>(rxn_lib.GetReaction(rxn_selection)->GetName()));
-  Print(rxn_lib.GetSize()+3, rxn_lib.GetReaction(rxn_selection)->GetName().GetSize()+37, ":");
-  Print(rxn_lib.GetSize()+3, rxn_lib.GetReaction(rxn_selection)->GetName().GetSize()+38, "        ");
-  
 }
 
 void cEnvironmentScreen::DoInput(int in_char)
@@ -224,59 +238,73 @@
   SetBoldColor(COLOR_CYAN);
   
   switch (in_char) {
-    case KEY_DOWN:
-      if(mode==ENVIRONMENT_MODE_RESOURCE ) {
-        last_selection=res_selection;
-        res_selection++;
-        res_selection%=m_world->GetPopulation().GetResources().GetSize();
-        
-        Print(last_selection+1, 1, res_lib.GetResource(last_selection)->GetName());
-        Print(last_selection+1, 12, "%7.2f", res_lib.GetResource(last_selection)->GetInflow());
-        Print(last_selection+1, 24, "%7.2f", res_lib.GetResource(last_selection)->GetOutflow());
+  case KEY_DOWN:
+    if(mode==ENVIRONMENT_MODE_RESOURCE ) {
+      const int num_resources = m_world->GetPopulation().GetResources().GetSize();
+      if (num_resources > 0) {
+	last_selection=res_selection;
+	res_selection++;
+	res_selection %= num_resources;
+	
+	Print(last_selection+1, 1, res_lib.GetResource(last_selection)->GetName());
+	Print(last_selection+1, 12, "%7.2f", res_lib.GetResource(last_selection)->GetInflow());
+	Print(last_selection+1, 24, "%7.2f", res_lib.GetResource(last_selection)->GetOutflow());
       }
-      else {
-        last_selection=rxn_selection;
-        rxn_selection++;
-        rxn_selection%=m_world->GetStats().GetReactions().GetSize();
-        
-        Print(last_selection+1, 1, rxn_lib.GetReaction(last_selection)->GetName());
-        //Print(last_selection+1, 12, "%7.2f", rxn_lib.GetReaction(last_selection)->GetInflow());
-        //Print(last_selection+1, 24, "%7.2f", rxn_lib.GetReaction(last_selection)->GetOutflow());
+    }
+    else { // ENVIRONMENT_MODE_REACTION
+      const int num_reactions = m_world->GetStats().GetReactions().GetSize();
+      if (num_reactions > 0) {
+	last_selection = rxn_selection;
+	rxn_selection++;
+	rxn_selection %= num_reactions;
+	
+	Print(last_selection+1, 1, rxn_lib.GetReaction(last_selection)->GetName());
+	//Print(last_selection+1, 12, "%7.2f", rxn_lib.GetReaction(last_selection)->GetInflow());
+	//Print(last_selection+1, 24, "%7.2f", rxn_lib.GetReaction(last_selection)->GetOutflow());
       }
-      
-      Update();
-      break;
-    case KEY_UP:
-      if(mode==ENVIRONMENT_MODE_RESOURCE) {
-        last_selection=res_selection;
-        res_selection--;
-        if(res_selection < 0) res_selection=m_world->GetPopulation().GetResources().GetSize()-1;
-        
-        Print(last_selection+1, 1, res_lib.GetResource(last_selection)->GetName());
-        Print(last_selection+1, 12, "%7.2f", res_lib.GetResource(last_selection)->GetInflow());
-        Print(last_selection+1, 24, "%7.2f", res_lib.GetResource(last_selection)->GetOutflow());
+    }
+    
+    Update();
+    break;
+  case KEY_UP:
+    if(mode == ENVIRONMENT_MODE_RESOURCE) {
+      const int num_resources = m_world->GetPopulation().GetResources().GetSize();
+      if (num_resources > 0) {
+	last_selection = res_selection;
+	res_selection--;
+	if(res_selection < 0) res_selection = num_resources - 1;
+	
+	Print(last_selection+1, 1, res_lib.GetResource(last_selection)->GetName());
+	Print(last_selection+1, 12, "%7.2f", res_lib.GetResource(last_selection)->GetInflow());
+	Print(last_selection+1, 24, "%7.2f", res_lib.GetResource(last_selection)->GetOutflow());
       }
-      else {
-        last_selection=rxn_selection;
-        rxn_selection--;
-        if(rxn_selection < 0) rxn_selection=m_world->GetStats().GetReactions().GetSize()-1;
-        
-        Print(last_selection+1, 1, rxn_lib.GetReaction(last_selection)->GetName());
-        //Print(last_selection+1, 12, "%7.2f", rxn_lib.GetReaction(last_selection)->GetInflow());
-        //Print(last_selection+1, 24, "%7.2f", rxn_lib.GetReaction(last_selection)->GetOutflow());
+    }
+    else { // ENVIRONMENT_MODE_REACTIONS
+      const int num_reactions = m_world->GetStats().GetReactions().GetSize();
+      if (num_reactions > 0) {
+	last_selection=rxn_selection;
+	rxn_selection--;
+	if (rxn_selection < 0) rxn_selection = num_reactions - 1;
+	
+	Print(last_selection+1, 1, rxn_lib.GetReaction(last_selection)->GetName());
+	//Print(last_selection+1, 12, "%7.2f", rxn_lib.GetReaction(last_selection)->GetInflow());
+	//Print(last_selection+1, 24, "%7.2f", rxn_lib.GetReaction(last_selection)->GetOutflow());
       }
-      
-      Update();
-      break;
-    case '>':
-    case '<':
-      if(mode==ENVIRONMENT_MODE_RESOURCE)
-        mode=ENVIRONMENT_MODE_REACTION;
-      else
-        mode=ENVIRONMENT_MODE_RESOURCE;
-      Clear();
-      Draw();
-      break;
+    }
+    
+    Update();
+    break;
+  case '>':
+  case '.':
+  case '<':
+  case ',':
+    if(mode==ENVIRONMENT_MODE_RESOURCE)
+      mode=ENVIRONMENT_MODE_REACTION;
+    else
+      mode=ENVIRONMENT_MODE_RESOURCE;
+    Clear();
+    Draw();
+    break;
   }
 }
 

Modified: development/source/targets/avida-viewer/cHistScreen.cc
===================================================================
--- development/source/targets/avida-viewer/cHistScreen.cc	2006-11-21 15:18:16 UTC (rev 1093)
+++ development/source/targets/avida-viewer/cHistScreen.cc	2006-11-21 22:03:01 UTC (rev 1094)
@@ -19,7 +19,7 @@
 
 
 void cHistScreen::PrintGenotype(cGenotype * in_gen, int in_pos,
-				       int max_num)
+				int max_stars, int star_size)
 {
   SetBoldColor(COLOR_CYAN);
   PrintFitness(in_pos, 0, in_gen->GetFitness());
@@ -27,10 +27,6 @@
   SetBoldColor(COLOR_WHITE);
   Print(in_pos, 8, "%s: ", static_cast<const char*>(in_gen->GetName()));
 
-  int max_stars = Width() - 28;
-  int star_size = (max_num / max_stars);
-  if (max_num % max_stars) star_size++;
-
   int cur_num = in_gen->GetNumOrganisms();
   int cur_stars = cur_num / star_size;
   if (cur_num % star_size) cur_stars++;
@@ -114,28 +110,41 @@
 
 void cHistScreen::Update()
 {
-  int max_num = 0;
-  int i;
+  const int max_stars = Width() - 28;
+  int max_num = 0, star_size = 0;
 
   switch(mode) {
   case HIST_GENOTYPE:
     max_num = info.GetWorld().GetClassificationManager().GetBestGenotype()->GetNumOrganisms();
+    star_size = (max_num / max_stars);
+    if (max_num % max_stars) star_size++;
+
     SetBoldColor(COLOR_WHITE);
     Print(1,  34, "Genotype Abundance");
+
     // Print out top NUM_SYMBOL genotypes in fixed order.
-    for (i = 0; i < info.GetNumSymbols(); i++) {
+    for (int i = 0; i < info.GetNumSymbols(); i++) {
       if (info.GetGenotype(i)) {
-	PrintGenotype(info.GetGenotype(i), i + 2, max_num);
+	PrintGenotype(info.GetGenotype(i), i + 2, max_stars, star_size);
       }
       else {
 	Move(i + 2, 0);
 	ClearToEOL();
       }
     }
+
+    SetBoldColor(COLOR_WHITE);
+    if (star_size == 1) {
+      Print(info.GetNumSymbols() + 3, 0, "Each '#' = %d Organism   ", star_size);
+    } else {
+      Print(info.GetNumSymbols() + 3, 0, "Each '#' = %d Organisms  ", star_size);
+    }
+    ClearToEOL();
+
     break;
   case HIST_SPECIES:
     max_num = 0;
-    for (i = 0; i < NUM_SYMBOLS; i++) {
+    for (int i = 0; i < NUM_SYMBOLS; i++) {
       if (info.GetSpecies(i) && info.GetSpecies(i)->GetNumOrganisms()
 	  > max_num)
 	max_num = info.GetSpecies(i)->GetNumOrganisms();
@@ -145,7 +154,7 @@
     Print(1,  34, "Species Abundance");
 
     // Print out top number of symbols species in fixed order.
-    for (i = 0; i < info.GetNumSymbols(); i++) {
+    for (int i = 0; i < info.GetNumSymbols(); i++) {
       if (info.GetSpecies(i)) {
 	PrintSpecies(info.GetSpecies(i), i + 2, max_num);
       }

Modified: development/source/targets/avida-viewer/cHistScreen.h
===================================================================
--- development/source/targets/avida-viewer/cHistScreen.h	2006-11-21 15:18:16 UTC (rev 1093)
+++ development/source/targets/avida-viewer/cHistScreen.h	2006-11-21 22:03:01 UTC (rev 1094)
@@ -28,7 +28,7 @@
   cPopulation & population;
   int mode;
 
-  void PrintGenotype(cGenotype * in_gen, int in_pos, int max_num);
+  void PrintGenotype(cGenotype * in_gen, int in_pos, int max_stars, int star_size);
   void PrintSpecies(cSpecies * in_species, int in_pos, int max_num);
 public:
   cHistScreen(int y_size, int x_size, int y_start, int x_start,

Modified: development/source/targets/avida-viewer/cOptionsScreen.cc
===================================================================
--- development/source/targets/avida-viewer/cOptionsScreen.cc	2006-11-21 15:18:16 UTC (rev 1093)
+++ development/source/targets/avida-viewer/cOptionsScreen.cc	2006-11-21 22:03:01 UTC (rev 1094)
@@ -34,47 +34,36 @@
 
   Print(7, 40, "Point  Mut:");
   Print(8, 40, "Copy   Mut:");
-  Print(9, 40, "Divide Mut:      Ins:      Del:");
+  Print(9, 40, "Divide Mut:");
+  Print(10,47,        "Ins:");
+  Print(11,47,        "Del:");
 
   Print(1, 0, "Current CPU..:");
   Print(2, 0, "Genotype.....:");
   Print(3, 0, "ID #.........:");
 
-  // SetBoldColor(COLOR_WHITE);
-  //  Print(Height() - 5, 2, "-- Screen --");
-  Print(Height() - 4, 2, "[H]istogram Screen");
-  Print(Height() - 3, 2, "[B]lank Screen");
-  Print(Height() - 2, 2, "[CTRL-L] Redraw Screen");
+  PrintOption(Height() - 4, 2, "[M]ap Screen");
+  PrintOption(Height() - 4, 2, "[S]tats Screen");
+  PrintOption(Height() - 4, 2, "[A]nalyze Screen");
+  PrintOption(Height() - 4, 2, "[Z]oom Screen");
+  PrintOption(Height() - 4, 2, "[H]istogram Screen");
+  PrintOption(Height() - 4, 2, "[E]nvironment Screen");
 
-  Print(Height() - 4, 30, "[C]hoose New CPU");
-  Print(Height() - 3, 30, "E[x]tract Creature");
-  //  Print(Height() - 3, 30, "[I]nject Creature");
-  Print(Height() - 2, 30, "[W]rite Soup Clone");
+  PrintOption(Height() - 4, 2, "[O]ptions Screen");
+  PrintOption(Height() - 3, 2, "[B]lank Screen");
+  PrintOption(Height() - 2, 2, "[CTRL-L] Redraw Screen");
+  PrintOption(Height() - 4, 30, "[C]hoose New CPU");
+  PrintOption(Height() - 3, 30, "E[x]tract Creature");
+  PrintOption(Height() - 2, 30, "[W]rite Soup Clone");
 
-  //  Print(Height() - 5, 55, "[V]iew Instructions");
   if (info.GetPauseLevel()) {
-    Print(Height() - 4, 55, "Un-[P]ause");
-    Print(Height() - 3, 55, "[N]ext Update");
+    PrintOption(Height() - 4, 55, "Un-[P]ause");
+    PrintOption(Height() - 3, 55, "[N]ext Update");
   } else {
-    Print(Height() - 4, 55, "[P]ause   ");
-    Print(Height() - 3, 55, "             ");
+    PrintOption(Height() - 4, 55, "[P]ause   ");
+    PrintOption(Height() - 3, 55, "             ");
   }
 
-  SetBoldColor(COLOR_CYAN);
-  Print(Height() - 4, 3, 'H');
-  Print(Height() - 3, 3, 'B');
-  Print(Height() - 2, 3, "CTRL-L");
-
-  Print(Height() - 4, 31, 'C');
-  Print(Height() - 3, 32, 'x');
-  Print(Height() - 2, 31, 'W');
-  if (info.GetPauseLevel()) {
-    Print(Height() - 4, 59, 'P');
-    Print(Height() - 3, 56, 'N');
-  } else {
-    Print(Height() - 4, 56, 'P');
-  }
-
   SetColor(COLOR_WHITE);
   Box(0, Height() - 5, Width(), 5);
 
@@ -138,8 +127,8 @@
   Print(7, 52, "%.3f", info.GetConfig().POINT_MUT_PROB.Get());
   Print(8, 52, "%.3f", info.GetConfig().COPY_MUT_PROB.Get());
   Print(9, 52, "%.3f", info.GetConfig().DIVIDE_MUT_PROB.Get());
-  Print(9, 62, "%.3f", info.GetConfig().DIVIDE_INS_PROB.Get());
-  Print(9, 72, "%.3f", info.GetConfig().DIVIDE_DEL_PROB.Get());
+  Print(10, 52, "%.3f", info.GetConfig().DIVIDE_INS_PROB.Get());
+  Print(11, 52, "%.3f", info.GetConfig().DIVIDE_DEL_PROB.Get());
 
   SetColor(COLOR_WHITE);
 

Modified: development/source/targets/avida-viewer/cScreen.h
===================================================================
--- development/source/targets/avida-viewer/cScreen.h	2006-11-21 15:18:16 UTC (rev 1093)
+++ development/source/targets/avida-viewer/cScreen.h	2006-11-21 22:03:01 UTC (rev 1094)
@@ -65,6 +65,8 @@
   inline void SetSymbolColor(char color);
   inline void PrintMerit(int in_y, int in_x, cMerit in_merit);
   inline void PrintFitness(int in_y, int in_x, double in_fitness);
+  inline void PrintOption(int in_y, int in_x, const cString & option);
+
 public:
   cScreen(int y_size, int x_size, int y_start, int x_start,
 	  cViewInfo & in_info) :
@@ -165,4 +167,21 @@
     Print(in_y, in_x, "%7.1e", in_fitness);
 }
 
+
+inline void cScreen::PrintOption(int in_y, int in_x, const cString & option)
+{
+  // Print the main option...
+  SetBoldColor(COLOR_WHITE);
+  Print(in_y, in_x, option);
+
+  // Highlight the keypress...
+  SetBoldColor(COLOR_YELLOW);
+  bool highlight = false;
+  for (int i = 0; i < option.GetSize(); i++) {
+    if (option[i] == '[') { highlight = true; continue; }
+    if (option[i] == ']') { highlight = false; continue; }
+    if (highlight == true) Print(in_y, in_x+i, option[i]);
+  }
+}
+
 #endif

Modified: development/source/targets/avida-viewer/cView.cc
===================================================================
--- development/source/targets/avida-viewer/cView.cc	2006-11-21 15:18:16 UTC (rev 1093)
+++ development/source/targets/avida-viewer/cView.cc	2006-11-21 22:03:01 UTC (rev 1094)
@@ -226,7 +226,7 @@
       break;
     case 'e':
     case 'E':
-      if(info.GetPopulation().GetEnvironment().GetResourceLib().GetSize() > 0)
+      //      if(info.GetPopulation().GetEnvironment().GetResourceLib().GetSize() > 0)
 	ChangeCurScreen(environment_screen);
       break;
     case 's':
@@ -384,12 +384,12 @@
 
 int cView::Confirm(const cString & message)
 {
-  int mess_length = message.GetSize();
+  const int mess_length = message.GetSize();
 
   // Create a confirm window, and draw it on the screen.
 
   cTextWindow * conf_win
-    = new cTextWindow(3, mess_length + 10, 10, (70 - mess_length) / 2);
+    = new cTextWindow(3, mess_length + 10, 10, (base_window->Width() - 10 - mess_length) / 2);
   conf_win->Box();
   conf_win->SetBoldColor(COLOR_WHITE);
   conf_win->Print(1, 2, "%s (y/n)", static_cast<const char*>(message));




More information about the Avida-cvs mailing list