[Avida-SVN] r1729 - in development/source: analyze main tools

ofria at myxo.css.msu.edu ofria at myxo.css.msu.edu
Fri Jun 29 09:59:16 PDT 2007


Author: ofria
Date: 2007-06-29 12:59:16 -0400 (Fri, 29 Jun 2007)
New Revision: 1729

Modified:
   development/source/analyze/cAnalyze.cc
   development/source/analyze/cAnalyze.h
   development/source/main/cAvidaConfig.h
   development/source/tools/cFlexVar.h
Log:
Added commands to convert the base type in cFlexVar (MakeInt(), MakeChar(), etc.)

Added a proper comparison command in order to compare two cFlexValues and produce a change quality.  This change
quality will them be use when we print a value to the screen to indicate if it is an improvement or if it makes
things worse.  This has NOT been hooked in anywhere yet, but I wanted to check it all in while everything was
still working.



Modified: development/source/analyze/cAnalyze.cc
===================================================================
--- development/source/analyze/cAnalyze.cc	2007-06-29 16:51:32 UTC (rev 1728)
+++ development/source/analyze/cAnalyze.cc	2007-06-29 16:59:16 UTC (rev 1729)
@@ -7756,24 +7756,24 @@
  }
 
 
- // const cFlexVar & stat, std::ostream& fp, int compare=0, const cString & null_keyword="0",
- // 		     const cString & html_cell_flags="align=center", bool print_text=true);
-
+// The following function will print a cell in a table with a background color based on a comparison
+// with its parent (the result of which is passed in as the 'compare' argument.
  void cAnalyze::HTMLPrintStat(tDataEntryCommand<cAnalyzeGenotype> * command, std::ostream& fp,
 			      int compare, bool print_text)
 {
   fp << "<td " << command->GetHtmlCellFlags() << " ";
-  if (compare == -2) {
+  if (compare == COMPARE_RESULT_OFF) {
     fp << "bgcolor=\"#" << m_world->GetConfig().COLOR_NEG2.Get() << "\">";
     if (print_text == true) fp << command->GetNull() << " ";
     else fp << "&nbsp; ";
     return;
   }
   
-  if (compare == -1)     fp << "bgcolor=\"#" << m_world->GetConfig().COLOR_NEG1.Get() << "\">";
-  else if (compare == 0) fp << ">";
-  else if (compare == 1) fp << "bgcolor=\"#" << m_world->GetConfig().COLOR_POS1.Get() << "\">";
-  else if (compare == 2) fp << "bgcolor=\"#" << m_world->GetConfig().COLOR_POS2.Get() << "\">";
+  if (compare == COMPARE_RESULT_NEG)       fp << "bgcolor=\"#" << m_world->GetConfig().COLOR_NEG1.Get() << "\">";
+  else if (compare == COMPARE_RESULT_SAME) fp << "bgcolor=\"#" << m_world->GetConfig().COLOR_SAME.Get() << "\">";
+  else if (compare == COMPARE_RESULT_POS)  fp << "bgcolor=\"#" << m_world->GetConfig().COLOR_POS1.Get() << "\">";
+  else if (compare == COMPARE_RESULT_ON)   fp << "bgcolor=\"#" << m_world->GetConfig().COLOR_POS2.Get() << "\">";
+  else if (compare == COMPARE_RESULT_DIFF) fp << "bgcolor=\"#" << m_world->GetConfig().COLOR_DIFF.Get() << "\">";
   else {
     std::cerr << "Error! Illegal case in Compare:" << compare << std::endl;
     exit(0);
@@ -7784,9 +7784,51 @@
   
 }
 
+int cAnalyze::CompareFlexStat(const cFlexVar & org_stat, const cFlexVar & parent_stat, int compare_type)
+{
+  // If no comparisons need be done, return zero and stop here.
+  if (compare_type == FLEX_COMPARE_NONE) {
+    return COMPARE_RESULT_SAME;
+  }
 
+  // In all cases, if the stats are the same, we should return this and stop.
+  if (org_stat == parent_stat) return COMPARE_RESULT_SAME;
 
+  // If we made it this far and all we care about is if they differ, return that they do.
+  if (compare_type == FLEX_COMPARE_DIFF) return COMPARE_RESULT_DIFF;
 
+  // If zero is not special we can calculate our result.
+  if (compare_type == FLEX_COMPARE_MAX) {     // Color higher values as beneficial, lower as harmful.
+    if (org_stat > parent_stat) return COMPARE_RESULT_POS;
+    return COMPARE_RESULT_NEG;
+  }
+  if (compare_type == FLEX_COMPARE_MIN) {     // Color lower values as beneficial, higher as harmful.
+    if (org_stat > parent_stat) return COMPARE_RESULT_NEG;
+    return COMPARE_RESULT_POS;
+  }
+
+
+  // If we made it this far, it means that zero has a special status.
+  if (org_stat == 0) return COMPARE_RESULT_OFF;
+  if (parent_stat == 0) return COMPARE_RESULT_ON;
+
+
+  // No zeros are involved, so we can go back to basic checks...
+  if (compare_type == FLEX_COMPARE_DIFF2) return COMPARE_RESULT_DIFF;
+
+  if (compare_type == FLEX_COMPARE_MAX2) {     // Color higher values as beneficial, lower as harmful.
+    if (org_stat > parent_stat) return COMPARE_RESULT_POS;
+    return COMPARE_RESULT_NEG;
+  }
+  if (compare_type == FLEX_COMPARE_MIN2) {     // Color lower values as beneficial, higher as harmful.
+    if (org_stat > parent_stat) return COMPARE_RESULT_NEG;
+    return COMPARE_RESULT_POS;
+  }
+
+}
+
+
+
 // A basic macro to link a keyword to a description and Get and Set methods in cAnalyzeGenotype.
 #define ADD_GDATA(TYPE, KEYWORD, DESC, GET, SET, COMP, NSTR, HSTR)                                         \
 {                                                                                                          \

Modified: development/source/analyze/cAnalyze.h
===================================================================
--- development/source/analyze/cAnalyze.h	2007-06-29 16:51:32 UTC (rev 1728)
+++ development/source/analyze/cAnalyze.h	2007-06-29 16:59:16 UTC (rev 1729)
@@ -132,7 +132,27 @@
 
   cRandom random;
 
+  // These are a set of constants used to determine what type of comparisons should be done between an
+  // organism and its parent to determine how it should be colored
+  enum eFlexCompareTypes {
+    FLEX_COMPARE_NONE  = 0,  // No comparisons should be done at all.
+    FLEX_COMPARE_DIFF  = 1,  // Only track if a stat has changed, don't worry about direction.
+    FLEX_COMPARE_MAX   = 2,  // Color higher values as beneficial, lower as harmful.
+    FLEX_COMPARE_MIN   = 3,  // Color lower values as beneficial, higher as harmful.
+    FLEX_COMPARE_DIFF2 = 4,  // Same as FLEX_COMPARE_DIFF, but 0 indicates trait is off.
+    FLEX_COMPARE_MAX2  = 5,  // Same as FLEX_COMPARE_MAX, and 0 indicates trait is off.
+    FLEX_COMPARE_MIN2  = 6   // Same as FLEX_COMPARE_MIN, BUT 0 still indicates off.
+  };
 
+  enum eFlexCompareResults {
+    COMPARE_RESULT_OFF  = -2, // Has turned off since parent.
+    COMPARE_RESULT_NEG  = -1, // Has gotten worse since parent.
+    COMPARE_RESULT_SAME =  0, // No difference since parent.
+    COMPARE_RESULT_POS  =  1, // Has improved since parent.
+    COMPARE_RESULT_ON   =  2, // Has turned on since parent.
+    COMPARE_RESULT_DIFF =  3  // Is different from parent (non qualtity).
+  };
+
   // Pop specific types of arguments from an arg list.
   cString PopDirectory(cString & in_string, const cString & default_dir);
   int PopBatch(const cString & in_string);
@@ -145,8 +165,10 @@
   void PreProcessArgs(cString & args);
   void ProcessCommands(tList<cAnalyzeCommand> & clist);
 
+  // Helper functions for printing to HTML files...
   void HTMLPrintStat(tDataEntryCommand<cAnalyzeGenotype> * command, std::ostream& fp, int compare=0,
 		     bool print_text=true);
+  int CompareFlexStat(const cFlexVar & org_stat, const cFlexVar & parent_stat, int compare_type=FLEX_COMPARE_MAX);
 
   // Deal with genotype data list (linking keywords to stats)
   void SetupGenotypeDataList();	

Modified: development/source/main/cAvidaConfig.h
===================================================================
--- development/source/main/cAvidaConfig.h	2007-06-29 16:51:32 UTC (rev 1728)
+++ development/source/main/cAvidaConfig.h	2007-06-29 16:59:16 UTC (rev 1729)
@@ -375,7 +375,8 @@
   CONFIG_ADD_VAR(REGULATION_DECAY_FRAC, double, 0.1, "Fraction of regulation that decays away. \nMax regulation = 2^(REGULATION_STRENGTH/REGULATION_DECAY_FRAC)");
 
   CONFIG_ADD_GROUP(COLORS_GROUP, "Output colors for when data files are printed in HTML mode.\nThere are two sets of these; the first are for lineages,\nand the second are for mutation tests.");
-  CONFIG_ADD_VAR(COLOR_CHANGE, cString, "CCCCFF", "Color to flag stat that has changed since parent.");
+  CONFIG_ADD_VAR(COLOR_DIFF, cString, "CCCCFF", "Color to flag stat that has changed since parent.");
+  CONFIG_ADD_VAR(COLOR_SAME, cString, "FFFFFF", "Color to flag stat that has NOT changed since parent.");
   CONFIG_ADD_VAR(COLOR_NEG2, cString, "FF0000", "Color to flag stat that is significantly worse than parent.");
   CONFIG_ADD_VAR(COLOR_NEG1, cString, "FFCCCC", "Color to flag stat that is minorly worse than parent.");
   CONFIG_ADD_VAR(COLOR_POS1, cString, "CCFFCC", "Color to flag stat that is minorly better than parent.");

Modified: development/source/tools/cFlexVar.h
===================================================================
--- development/source/tools/cFlexVar.h	2007-06-29 16:51:32 UTC (rev 1728)
+++ development/source/tools/cFlexVar.h	2007-06-29 16:59:16 UTC (rev 1729)
@@ -18,6 +18,8 @@
   };
   
 private:
+  ////////////////////////////////////////////////////////////
+  // Base class for the internal type system....
   class cFlexVar_Base {
   public:
     cFlexVar_Base() { ; }
@@ -45,6 +47,8 @@
     ABSTRACT_FLEX_VAR_BASE_OP(>=, bool)
   };
   
+  ////////////////////////////////////////////////////////////
+  // Internal class for managing int type......
   class cFlexVar_Int : public cFlexVar_Base {
   private:
     int value;
@@ -73,6 +77,10 @@
     CREATE_FLEX_VAR_INT_MATH_OP(>=, bool);
   };
 
+
+  ////////////////////////////////////////////////////////////
+  // Internal class for managing char type......
+
   class cFlexVar_Char : public cFlexVar_Base {
   private:
     char value;
@@ -101,6 +109,10 @@
     CREATE_FLEX_VAR_CHAR_MATH_OP(>=, bool);
   };
 
+
+  ////////////////////////////////////////////////////////////
+  // Internal class for managing double type......
+
   class cFlexVar_Double : public cFlexVar_Base {
   private:
     double value;
@@ -129,6 +141,10 @@
     CREATE_FLEX_VAR_DOUBLE_MATH_OP(>=, bool);
   };
 
+
+  ////////////////////////////////////////////////////////////
+  // Internal class for managing cString type......
+
   class cFlexVar_String : public cFlexVar_Base {
   private:
     cString value;
@@ -173,16 +189,22 @@
   cFlexVar(const cString & in_value) : var(new cFlexVar_String(in_value)) { ; }
   ~cFlexVar() { delete var; }
 
+  // Setup an accessor to determine the native type of this variable.
+  eFlexType GetType() const { return var->GetType(); }
+
   // Setup accessors to get this variable as any type we might need.
   int AsInt() const { return var->AsInt(); }
   char AsChar() const { return var->AsChar(); }
   double AsDouble() const { return var->AsDouble(); }
   cString AsString() const { return var->AsString(); }
   void SetString(cString & in_str) const { var->SetString(in_str); }
+
+  // Setup a way to convert the native types
+  int MakeInt() { int val = AsInt(); delete var; var = new cFlexVar_Int(val); return val; }
+  char MakeChar() { char val = AsChar(); delete var; var = new cFlexVar_Char(val); return val; }
+  double MakeDouble() { double val = AsDouble(); delete var; var = new cFlexVar_Double(val); return val; }
+  cString MakeString() { cString val = AsString(); delete var; var = new cFlexVar_String(val); return val; }
   
-  // Setup an accessor to determine the native type of this variable.
-  eFlexType GetType() const { return var->GetType(); }
-
   // Setup assignment operators...
   cFlexVar & operator=(const cFlexVar & in_var) {
     delete var;




More information about the Avida-cvs mailing list