[Avida-cvs] [Avida2-svn] r353 - in trunk: Avida2.xcodeproj source/main source/testsuites/unit_testsuites source/tools

brysonda@myxo.css.msu.edu brysonda at myxo.css.msu.edu
Tue Oct 18 15:52:52 PDT 2005


Author: brysonda
Date: 2005-10-18 18:52:51 -0400 (Tue, 18 Oct 2005)
New Revision: 353

Added:
   trunk/source/main/cWorld.cc
   trunk/source/main/cWorld.h
Modified:
   trunk/Avida2.xcodeproj/project.pbxproj
   trunk/source/main/cAnalyze.h
   trunk/source/main/cAvidaConfig.cc
   trunk/source/main/cEnvironment.cc
   trunk/source/main/primitive.cc
   trunk/source/testsuites/unit_testsuites/random.t.cc
   trunk/source/tools/cRandom.cc
   trunk/source/tools/cRandom.h
   trunk/source/tools/cTools.h
Log:
Add a beginning cWorld object.

Modified: trunk/Avida2.xcodeproj/project.pbxproj
===================================================================
--- trunk/Avida2.xcodeproj/project.pbxproj	2005-10-18 19:20:44 UTC (rev 352)
+++ trunk/Avida2.xcodeproj/project.pbxproj	2005-10-18 22:52:51 UTC (rev 353)
@@ -248,6 +248,10 @@
 		70C1F19A08C6A11100F50912 /* cEventListIterator.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70C1F19008C6A11100F50912 /* cEventListIterator.cc */; };
 		70C1F19B08C6A11100F50912 /* cEventTriggers.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70C1F19108C6A11100F50912 /* cEventTriggers.cc */; };
 		70C1F19C08C6A11100F50912 /* cPopulationEventFactory.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70C1F19208C6A11100F50912 /* cPopulationEventFactory.cc */; };
+		70C5BC6409059A970028A785 /* cWorld.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 70C5BC6209059A970028A785 /* cWorld.h */; };
+		70C5BC6509059A970028A785 /* cWorld.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70C5BC6309059A970028A785 /* cWorld.cc */; };
+		70C5BC6609059A970028A785 /* cWorld.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 70C5BC6209059A970028A785 /* cWorld.h */; };
+		70C5BC6709059A970028A785 /* cWorld.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70C5BC6309059A970028A785 /* cWorld.cc */; };
 		70CA6EC208DB7F8200068AC2 /* cFitnessMatrix.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70CA6EB208DB7F8200068AC2 /* cFitnessMatrix.cc */; };
 		70CA6EC308DB7F8200068AC2 /* cGenebank.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70CA6EB308DB7F8200068AC2 /* cGenebank.cc */; };
 		70CA6EC408DB7F8200068AC2 /* cGenome.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70CA6EB408DB7F8200068AC2 /* cGenome.cc */; };
@@ -338,6 +342,7 @@
 				701384340900A45B0087ED2E /* organism.smtx in CopyFiles */,
 				7013846109028B3E0087ED2E /* cAvidaConfig.h in CopyFiles */,
 				7013852E0902E36B0087ED2E /* avida.cfg in CopyFiles */,
+				70C5BC6609059A970028A785 /* cWorld.h in CopyFiles */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
@@ -365,6 +370,7 @@
 				701384350900A45B0087ED2E /* organism.smtx in CopyFiles */,
 				7013846309028B3E0087ED2E /* cAvidaConfig.h in CopyFiles */,
 				7013852D0902E36B0087ED2E /* avida.cfg in CopyFiles */,
+				70C5BC6409059A970028A785 /* cWorld.h in CopyFiles */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
@@ -644,6 +650,8 @@
 		70C1F19008C6A11100F50912 /* cEventListIterator.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = cEventListIterator.cc; sourceTree = "<group>"; };
 		70C1F19108C6A11100F50912 /* cEventTriggers.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = cEventTriggers.cc; sourceTree = "<group>"; };
 		70C1F19208C6A11100F50912 /* cPopulationEventFactory.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = cPopulationEventFactory.cc; sourceTree = "<group>"; };
+		70C5BC6209059A970028A785 /* cWorld.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = cWorld.h; sourceTree = "<group>"; };
+		70C5BC6309059A970028A785 /* cWorld.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = cWorld.cc; sourceTree = "<group>"; };
 		70CA6EB208DB7F8200068AC2 /* cFitnessMatrix.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = cFitnessMatrix.cc; sourceTree = "<group>"; };
 		70CA6EB308DB7F8200068AC2 /* cGenebank.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = cGenebank.cc; sourceTree = "<group>"; };
 		70CA6EB408DB7F8200068AC2 /* cGenome.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = cGenome.cc; sourceTree = "<group>"; };
@@ -2179,6 +2187,8 @@
 				70B085D108F48C9400FC65FE /* nSpecies.h */,
 				7013845F09028B3E0087ED2E /* cAvidaConfig.h */,
 				7013846009028B3E0087ED2E /* cAvidaConfig.cc */,
+				70C5BC6209059A970028A785 /* cWorld.h */,
+				70C5BC6309059A970028A785 /* cWorld.cc */,
 			);
 			path = main;
 			sourceTree = "<group>";
@@ -3195,6 +3205,7 @@
 				70B08B9208FB2E6B00FC65FE /* cTools.cc in Sources */,
 				70B08B9308FB2E6B00FC65FE /* cWeightedIndex.cc in Sources */,
 				7013846209028B3E0087ED2E /* cAvidaConfig.cc in Sources */,
+				70C5BC6709059A970028A785 /* cWorld.cc in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
@@ -3317,6 +3328,7 @@
 				70B08B9408FB2E6B00FC65FE /* cTools.cc in Sources */,
 				70B08B9508FB2E6B00FC65FE /* cWeightedIndex.cc in Sources */,
 				7013846409028B3E0087ED2E /* cAvidaConfig.cc in Sources */,
+				70C5BC6509059A970028A785 /* cWorld.cc in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};

Modified: trunk/source/main/cAnalyze.h
===================================================================
--- trunk/source/main/cAnalyze.h	2005-10-18 19:20:44 UTC (rev 352)
+++ trunk/source/main/cAnalyze.h	2005-10-18 22:52:51 UTC (rev 353)
@@ -16,7 +16,7 @@
 #ifndef GENOTYPE_BATCH_HH
 #include "cGenotypeBatch.h"
 #endif
-#ifndef RANDOM_HH
+#ifndef cRandom_h
 #include "cRandom.h"
 #endif
 #ifndef STRING_HH

Modified: trunk/source/main/cAvidaConfig.cc
===================================================================
--- trunk/source/main/cAvidaConfig.cc	2005-10-18 19:20:44 UTC (rev 352)
+++ trunk/source/main/cAvidaConfig.cc	2005-10-18 22:52:51 UTC (rev 353)
@@ -40,9 +40,8 @@
   
   if (!init_file.IsOpen()) {
     // If we failed to open the config file, try creating it.
-    cerr << "Error: Unable to find file '" << filename << "'.  Creating default." << endl;
+    cerr << "Warning: Unable to find file '" << filename << "'.  Creating default." << endl;
     Print(filename);
-    exit(0);
   }
   
   init_file.Load();

Modified: trunk/source/main/cEnvironment.cc
===================================================================
--- trunk/source/main/cEnvironment.cc	2005-10-18 19:20:44 UTC (rev 352)
+++ trunk/source/main/cEnvironment.cc	2005-10-18 22:52:51 UTC (rev 353)
@@ -15,7 +15,7 @@
 #ifndef nMutation_h
 #include "nMutation.h"
 #endif
-#ifndef RANDOM_HH
+#ifndef cRandom_h
 #include "cRandom.h"
 #endif
 #ifndef REACTION_HH

Added: trunk/source/main/cWorld.cc
===================================================================
--- trunk/source/main/cWorld.cc	2005-10-18 19:20:44 UTC (rev 352)
+++ trunk/source/main/cWorld.cc	2005-10-18 22:52:51 UTC (rev 353)
@@ -0,0 +1,27 @@
+/*
+ *  cWorld.cc
+ *  Avida2
+ *
+ *  Created by David on 10/18/05.
+ *  Copyright 2005 Michigan State University. All rights reserved.
+ *
+ */
+
+#include "cWorld.h"
+
+void cWorld::Setup() {
+  // Setup Random Number Generator
+  const int rand_seed = m_config->RANDOM_SEED.Get();
+  cout << "Random Seed: " << rand_seed;
+  m_rng.ResetSeed(rand_seed);
+  if (rand_seed != m_rng.GetSeed()) cout << " -> " << m_rng.GetSeed();
+  cout << endl;  
+  
+  // The default directory should end in a '/'.
+  cString default_dir = m_config->DEFAULT_DIR.Get();
+  char dir_tail = default_dir[default_dir.GetSize() - 1];
+  if (dir_tail != '\\' && dir_tail != '/') {
+    default_dir += "/";
+    m_config->DEFAULT_DIR.Set(default_dir);
+  }
+}

Added: trunk/source/main/cWorld.h
===================================================================
--- trunk/source/main/cWorld.h	2005-10-18 19:20:44 UTC (rev 352)
+++ trunk/source/main/cWorld.h	2005-10-18 22:52:51 UTC (rev 353)
@@ -0,0 +1,61 @@
+/*
+ *  cWorld.h
+ *  Avida2
+ *
+ *  Created by David on 10/18/05.
+ *  Copyright 2005 Michigan State University. All rights reserved.
+ *
+ */
+
+#ifndef cWorld_h
+#define cWorld_h
+
+#ifndef cAvidaConfig_h
+#include "cAvidaConfig.h"
+#endif
+#ifndef cRandom_h
+#include "cRandom.h"
+#endif
+
+class cWorld
+{
+protected:
+  cAvidaConfig* m_config;
+  cRandom m_rng;
+
+  bool m_test_on_divide;
+  bool m_test_sterilize;
+  
+  void Setup();
+
+public:
+  explicit cWorld() : m_config(new cAvidaConfig()) { Setup(); }
+  cWorld(cAvidaConfig* cfg) : m_config(cfg) { Setup(); }
+  ~cWorld() { delete m_config; }
+  
+  void SetConfig(cAvidaConfig* cfg) { delete m_config; m_config = cfg; }
+  cAvidaConfig& GetConfig() { return *m_config; }
+  
+  // Config Dependent Modes
+  bool GetTestOnDivide() const
+  {
+    const bool revert_fatal = m_config->REVERT_FATAL.Get() > 0.0;
+    const bool revert_neg = m_config->REVERT_DETRIMENTAL.Get() > 0.0;
+    const bool revert_neut = m_config->REVERT_NEUTRAL.Get() > 0.0;
+    const bool revert_pos = m_config->REVERT_BENEFICIAL.Get() > 0.0;
+    const bool fail_implicit = m_config->FAIL_IMPLICIT.Get() > 0;
+    return (revert_fatal || revert_neg || revert_neut || revert_pos || fail_implicit);
+  }
+  bool GetTestSterilize() const
+  {
+    const bool sterilize_fatal = m_config->STERILIZE_FATAL.Get() > 0.0;
+    const bool sterilize_neg = m_config->STERILIZE_DETRIMENTAL.Get() > 0.0;
+    const bool sterilize_neut = m_config->STERILIZE_NEUTRAL.Get() > 0.0;
+    const bool sterilize_pos = m_config->STERILIZE_BENEFICIAL.Get() > 0.0;
+    return (sterilize_fatal || sterilize_neg || sterilize_neut || sterilize_pos);
+  }
+  
+  cRandom& GetRandom() { return m_rng; }
+};
+
+#endif

Modified: trunk/source/main/primitive.cc
===================================================================
--- trunk/source/main/primitive.cc	2005-10-18 19:20:44 UTC (rev 352)
+++ trunk/source/main/primitive.cc	2005-10-18 22:52:51 UTC (rev 353)
@@ -7,63 +7,28 @@
  *
  */
 
-#ifndef avida_h
+#include <signal.h>
+
 #include "avida.h"
-#endif
-#ifndef cAvidaConfig_h
 #include "cAvidaConfig.h"
-#endif
-#ifndef AVIDA_DRIVER_ANALYZE_HH
 #include "cAvidaDriver_Analyze.h"
-#endif
-#ifndef AVIDA_DRIVER_BASE_HH
 #include "cAvidaDriver_Base.h"
-#endif
-#ifndef AVIDA_DRIVER_POPULATION_HH
 #include "cAvidaDriver_Population.h"
-#endif
-#ifndef CALLBACK_UTIL_HH
 #include "cCallbackUtil.h"
-#endif
-#ifndef CONFIG_HH
 #include "cConfig.h"
-#endif
-#ifndef DEFS_HH
-#include "defs.h"
-#endif
-#ifndef ENVIRONMENT_HH
 #include "cEnvironment.h"
-#endif
-#ifndef HARDWARE_4STACK_HH
 #include "cHardware4Stack.h"
-#endif
-#ifndef HARDWARE_UTIL_HH
 #include "cHardwareUtil.h"
-#endif
-#ifndef HARDWARE_CPU_HH
 #include "cHardwareCPU.h"
-#endif
-#ifndef HARDWARE_SMT_H
 #include "cHardwareSMT.h"
-#endif
-#ifndef INST_LIB_CPU_HH
 #include "cInstLibCPU.h"
-#endif
-#ifndef POPULATION_HH
 #include "cPopulation.h"
-#endif
-#ifndef POPULATION_INTERFACE_HH
 #include "cPopulationInterface.h"
-#endif
-#ifndef RESOURCE_COUNT_HH
 #include "cResourceCount.h"
-#endif
-#ifndef TEST_CPU_HH
 #include "cTestCPU.h"
-#endif
+#include "cWorld.h"
+#include "defs.h"
 
-#include <signal.h>
-
 using namespace std;
 
 int main(int argc, char * argv[])
@@ -82,7 +47,10 @@
   cout << "under certain conditions. See file COPYING for details." << endl << endl;
   
   // Initialize the configuration data...
-  //cAvidaConfig* cfg = cAvidaConfig::LoadWithCmdLineArgs(argc, argv);
+  //cerr << "<newconfig>" << endl;
+  //cWorld* world = new cWorld(cAvidaConfig::LoadWithCmdLineArgs(argc, argv));
+  //cerr << "</newconfig>" << endl << endl;
+  
   cConfig::InitGroupList();
   cConfig::Setup(argc, argv);
   cConfig::SetupMS();

Modified: trunk/source/testsuites/unit_testsuites/random.t.cc
===================================================================
--- trunk/source/testsuites/unit_testsuites/random.t.cc	2005-10-18 19:20:44 UTC (rev 352)
+++ trunk/source/testsuites/unit_testsuites/random.t.cc	2005-10-18 22:52:51 UTC (rev 353)
@@ -1,6 +1,6 @@
 #include <iostream>
 
-#ifndef RANDOM_HH
+#ifndef cRandom_h
 #include "cRandom.h"
 #endif
 #ifndef TEST_CASE_H

Modified: trunk/source/tools/cRandom.cc
===================================================================
--- trunk/source/tools/cRandom.cc	2005-10-18 19:20:44 UTC (rev 352)
+++ trunk/source/tools/cRandom.cc	2005-10-18 22:52:51 UTC (rev 353)
@@ -5,7 +5,7 @@
 // before continuing.  SOME RESTRICTIONS MAY APPLY TO USE OF THIS FILE.     //
 //////////////////////////////////////////////////////////////////////////////
 
-#ifndef RANDOM_HH
+#ifndef cRandom_h
 #include "cRandom.h"
 #endif
 

Modified: trunk/source/tools/cRandom.h
===================================================================
--- trunk/source/tools/cRandom.h	2005-10-18 19:20:44 UTC (rev 352)
+++ trunk/source/tools/cRandom.h	2005-10-18 22:52:51 UTC (rev 353)
@@ -14,8 +14,8 @@
 
 ******************************************************************************/
 
-#ifndef RANDOM_HH
-#define RANDOM_HH
+#ifndef cRandom_h
+#define cRandom_h
 
 #include <time.h>
 #include <limits.h>

Modified: trunk/source/tools/cTools.h
===================================================================
--- trunk/source/tools/cTools.h	2005-10-18 19:20:44 UTC (rev 352)
+++ trunk/source/tools/cTools.h	2005-10-18 22:52:51 UTC (rev 353)
@@ -10,7 +10,7 @@
 #ifndef TOOLS_HH
 #define TOOLS_HH
 
-#ifndef RANDOM_HH
+#ifndef cRandom_h
 #include "cRandom.h"
 #endif
 




More information about the Avida-cvs mailing list