[Avida-cvs] [Avida2-svn] r347 - in trunk: . Avida2.xcodeproj source/main
brysonda@myxo.css.msu.edu
brysonda at myxo.css.msu.edu
Sun Oct 16 12:24:07 PDT 2005
Author: brysonda
Date: 2005-10-16 15:24:07 -0400 (Sun, 16 Oct 2005)
New Revision: 347
Modified:
trunk/AUTHORS
trunk/Avida2.xcodeproj/project.pbxproj
trunk/README
trunk/source/main/cAvidaConfig.cc
trunk/source/main/cAvidaConfig.h
trunk/source/main/primitive.cc
Log:
Implement command line argument loading for cAvidaConfig. Can easily co-exist next to the current config object, though it is incompatible with existing genesis files. WORLD-X and WORLD-Y have to be WORLD_X and WORLD_Y, respectively. C++ will not allow dashes in identifiers. The default configuration file name for cAvidaConfig is set to 'avida.cfg' in order to avoid the clash with old style genesis files.
Modified: trunk/AUTHORS
===================================================================
--- trunk/AUTHORS 2005-10-16 14:39:55 UTC (rev 346)
+++ trunk/AUTHORS 2005-10-16 19:24:07 UTC (rev 347)
@@ -2,14 +2,26 @@
1993-2002 primarily at the California Institute of Technology and Michigan
State University.
+2005 - Present
+Starting with the 2.3 series, significant enhancements and features are being
+added, along vast portions of the code refactored. David Michael Bryson,
+Charles Ofria, and Kaben Nanlohy are currently responsible for the changes.
+
+1999 - 2002
The 2.0 release series contains many improvements over earlier releases.
-These improvements were written in 2000-2002 by Charles Ofria, Claus O. Wilke
+These improvements were written in 2000-2002 by Charles Ofria, Claus O. Wilke,
and Kaben Nanlohy.
+1993 - 1998
The core avida system was designed by Chris Adami, C. Titus Brown, and
Charles Ofria in 1993-1998. Portions of the design were supported by NSF
grant #PHY91-15574, NSF grant #DEB-9981397, a Caltech divisional fellowship,
the 1993 Caltech SURF program, and the 1993 SUNY Stony Brook URECA program.
Portions of Avida have been implemented by: Charles Ofria, Claus O. Wilke,
-Kaben Nanlohy, Travis Collier, Dusan Misevic, and Dennis Adler.
\ No newline at end of file
+Kaben Nanlohy, Travis Collier, Dusan Misevic, Dennis Adler, and David Michael
+Bryson.
+
+This list is in no way comprehensive, many others have contributed various
+features.
+
Modified: trunk/Avida2.xcodeproj/project.pbxproj
===================================================================
--- trunk/Avida2.xcodeproj/project.pbxproj 2005-10-16 14:39:55 UTC (rev 346)
+++ trunk/Avida2.xcodeproj/project.pbxproj 2005-10-16 19:24:07 UTC (rev 347)
@@ -30,6 +30,8 @@
7013846209028B3E0087ED2E /* cAvidaConfig.cc in Sources */ = {isa = PBXBuildFile; fileRef = 7013846009028B3E0087ED2E /* cAvidaConfig.cc */; };
7013846309028B3E0087ED2E /* cAvidaConfig.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 7013845F09028B3E0087ED2E /* cAvidaConfig.h */; };
7013846409028B3E0087ED2E /* cAvidaConfig.cc in Sources */ = {isa = PBXBuildFile; fileRef = 7013846009028B3E0087ED2E /* cAvidaConfig.cc */; };
+ 7013852D0902E36B0087ED2E /* avida.cfg in CopyFiles */ = {isa = PBXBuildFile; fileRef = 7013852C0902E36B0087ED2E /* avida.cfg */; };
+ 7013852E0902E36B0087ED2E /* avida.cfg in CopyFiles */ = {isa = PBXBuildFile; fileRef = 7013852C0902E36B0087ED2E /* avida.cfg */; };
702D4EFE08DA5341007BA469 /* cAvidaDriver_Analyze.cc in Sources */ = {isa = PBXBuildFile; fileRef = 702D4EF908DA5341007BA469 /* cAvidaDriver_Analyze.cc */; };
702D4EFF08DA5341007BA469 /* cAvidaDriver_Base.cc in Sources */ = {isa = PBXBuildFile; fileRef = 702D4EFA08DA5341007BA469 /* cAvidaDriver_Base.cc */; };
702D4F0008DA5341007BA469 /* cAvidaDriver_Population.cc in Sources */ = {isa = PBXBuildFile; fileRef = 702D4EFB08DA5341007BA469 /* cAvidaDriver_Population.cc */; };
@@ -335,6 +337,7 @@
700E2B7D085DE50C00CF158A /* inst_set.smt in CopyFiles */,
701384340900A45B0087ED2E /* organism.smtx in CopyFiles */,
7013846109028B3E0087ED2E /* cAvidaConfig.h in CopyFiles */,
+ 7013852E0902E36B0087ED2E /* avida.cfg in CopyFiles */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -361,6 +364,7 @@
706D33280854A90D00D7DC8F /* inst_set.smt in CopyFiles */,
701384350900A45B0087ED2E /* organism.smtx in CopyFiles */,
7013846309028B3E0087ED2E /* cAvidaConfig.h in CopyFiles */,
+ 7013852D0902E36B0087ED2E /* avida.cfg in CopyFiles */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -373,6 +377,7 @@
7013845F09028B3E0087ED2E /* cAvidaConfig.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = cAvidaConfig.h; sourceTree = "<group>"; };
7013846009028B3E0087ED2E /* cAvidaConfig.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = cAvidaConfig.cc; sourceTree = "<group>"; };
701384A10902A16F0087ED2E /* defs.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = defs.h; sourceTree = "<group>"; };
+ 7013852C0902E36B0087ED2E /* avida.cfg */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = avida.cfg; sourceTree = "<group>"; };
702D4EF208DA5328007BA469 /* cAvidaDriver_Analyze.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cAvidaDriver_Analyze.h; sourceTree = "<group>"; };
702D4EF308DA5328007BA469 /* cAvidaDriver_Base.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cAvidaDriver_Base.h; sourceTree = "<group>"; };
702D4EF408DA5328007BA469 /* cAvidaDriver_Population.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cAvidaDriver_Population.h; sourceTree = "<group>"; };
@@ -2278,6 +2283,7 @@
DCC3118B0762539F008F7A48 /* organism.sex */,
706D330E0854A7B900D7DC8F /* organism.smt */,
DCC3118C0762539F008F7A48 /* preset_organisms */,
+ 7013852C0902E36B0087ED2E /* avida.cfg */,
);
path = support;
sourceTree = "<group>";
Modified: trunk/README
===================================================================
--- trunk/README 2005-10-16 14:39:55 UTC (rev 346)
+++ trunk/README 2005-10-16 19:24:07 UTC (rev 347)
@@ -1,4 +1,4 @@
-Avida 2.2
+Avida 2.3.x
----------------------------------------------------------------------
Digital Evolution Laboratory at Michigan State University
@@ -14,7 +14,8 @@
OR
In Mac OS X, an Xcode project has been provided for building the
-'primitive' console only version of Avida.
+'primitive' console only version of Avida, as well as the NCurses
+viewer. Xcode 2.1 or greater is required.
GETTING STARTED
@@ -100,4 +101,4 @@
-Revised 2005-14-02 DMB
+Revised 2005-16-10 DMB
Modified: trunk/source/main/cAvidaConfig.cc
===================================================================
--- trunk/source/main/cAvidaConfig.cc 2005-10-16 14:39:55 UTC (rev 346)
+++ trunk/source/main/cAvidaConfig.cc 2005-10-16 19:24:07 UTC (rev 347)
@@ -11,7 +11,10 @@
#include <fstream>
#include "defs.h"
+#include "cEventFactoryManager.h"
#include "cInitFile.h"
+#include "cPopulationEventFactory.h"
+#include "tDictionary.h"
tList<cAvidaConfig::cBaseConfigGroup> cAvidaConfig::global_group_list;
@@ -26,30 +29,34 @@
// If the default value was originally a string, it will begin and end with
// quotes. We should make sure to remove those.
if (default_value[0] == '"') {
- cout << "Removing quotes from " << default_value << endl;
default_value = default_value.Substring(1, default_value.GetSize() - 2);
- cout << "...now " << default_value << endl;
}
}
-
-cAvidaConfig::cAvidaConfig()
-{
- group_list.Transfer(global_group_list);
-}
-
-cAvidaConfig::~cAvidaConfig()
-{
-}
-
void cAvidaConfig::Load(const cString & filename)
{
// Load the contents from the file.
cInitFile init_file(filename);
+
+ 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;
+ Print(filename);
+ exit(0);
+ }
+
init_file.Load();
init_file.Compress();
init_file.Close();
+
+ cString version_id = init_file.ReadString("VERSION_ID", "Unknown");
+ if (version_id != VERSION) {
+ cerr << "Warning: Configuration file version number mismatch." << endl;
+ cerr << " Avida Version: \"" << VERSION << "\". Config Version: \"" << version_id << "\"" << endl;
+ }
+ init_file.SetVerbose();
+
// Loop through all groups, then all entrys, and try to load each one.
tListIterator<cBaseConfigGroup> group_it(group_list);
cBaseConfigGroup * cur_group;
@@ -64,6 +71,8 @@
cur_entry->LoadString( init_file.ReadString(keyword, default_val) );
}
}
+
+ init_file.WarnUnused();
}
void cAvidaConfig::Print(const cString & filename)
@@ -130,7 +139,6 @@
fp << " # " << cur_desc.Pop() << endl;
}
}
-
}
}
}
@@ -255,3 +263,147 @@
fp << endl;
}
}
+
+cAvidaConfig* cAvidaConfig::LoadWithCmdLineArgs(int argc, char * argv[])
+{
+ cString config_filename = "avida.cfg";
+ tDictionary<cString> sets;
+
+ int arg_num = 1; // Argument number being looked at.
+
+ // Load all of the args into string objects for ease of access.
+ cString* args = new cString[argc];
+ for (int i = 0; i < argc; i++) args[i] = argv[i];
+
+ // -config option
+ if (argc > 1 && (args[1] == "-c" || args[1] == "-config")) {
+ if (argc < 3) {
+ cerr << "Error: Filename for configuration must be specified." << endl;
+ exit(0);
+ }
+ config_filename = args[2];
+ arg_num += 2;
+ } else if (argc > 1 && (args[1] == "-g" || args[1] == "-genesis")) {
+ cerr << "Warning: Use of -g[enesis] deprecated in favor of -c[onfig]." << endl;
+ if (argc < 3) {
+ cerr << "Error: Filename for configuration must be specified." << endl;
+ exit(0);
+ }
+ config_filename = args[2];
+ arg_num += 2;
+ }
+
+ // Create Config object, load with values from configuration file
+ cAvidaConfig* cfg = new cAvidaConfig();
+ cfg->Load(config_filename);
+
+ // Then scan through and process the rest of the args.
+ while (arg_num < argc) {
+ cString cur_arg = args[arg_num];
+
+ // Test against the possible inputs.
+ if (cur_arg == "-events" || cur_arg == "-e") {
+ cout << "Known events:" << endl;
+ // @DMB - A cleaner way of constructing the cEventFactoryManager should be created
+ cEventFactoryManager event_manager;
+ event_manager.AddFactory(new cPopulationEventFactory(NULL));
+ event_manager.PrintAllEventDescriptions();
+ exit(0);
+ }
+ else if (cur_arg == "--help" || cur_arg == "-help" || cur_arg == "-h") {
+ cout << "Options:"<<endl
+ << " -c[onfig] <filename> Set config file to be <filename>"<<endl
+ << " -h[elp] Help on options (this listing)"<<endl
+ << " -e[vents] Print a list of all known events"<< endl
+ << " -s[eed] <value> Set random seed to <value>"<<endl
+ << " -v[ersion] Prints the version number"<<endl
+ << " -set <name> <value> Overide the genesis file"<<endl
+ << " -l[oad] <filename> Load a clone file"<<endl
+ << " -loadpop <filename> Load a saved population file (precedence over load)"<<endl
+ << " -a[nalyze] Process analyze.cfg instead of normal run."<<endl
+ << " -i[nteractive] Run analyze mode interactively."
+ << endl;
+
+ exit(0);
+ }
+ else if (cur_arg == "-seed" || cur_arg == "-s") {
+ int in_seed = 0;
+ if (arg_num + 1 == argc || args[arg_num + 1][0] == '-') {
+ cerr << "Error: Must include a number as the random seed!" << endl;
+ exit(0);
+ } else {
+ arg_num++; if (arg_num < argc) cur_arg = args[arg_num];
+ in_seed = cur_arg.AsInt();
+ }
+ cfg->RANDOM_SEED.Set(in_seed);
+ } else if (cur_arg == "-analyze" || cur_arg == "-a") {
+ if (cfg->ANALYZE_MODE.Get() < 1) {
+ cfg->ANALYZE_MODE.Set(1);
+ }
+ } else if (cur_arg == "-interactive" || cur_arg == "-i") {
+ if (cfg->ANALYZE_MODE.Get() < 2) {
+ cfg->ANALYZE_MODE.Set(2);
+ }
+ } else if (cur_arg == "-load" || cur_arg == "-l") {
+ if (arg_num + 1 == argc || args[arg_num + 1][0] == '-') {
+ cerr << "Error: Must include a filename to load from." << endl;
+ exit(0);
+ } else {
+ arg_num++; if (arg_num < argc) cur_arg = args[arg_num];
+ cfg->CLONE_FILE.Set(cur_arg);
+ }
+ } else if (cur_arg == "-loadpop" || cur_arg == "-lp") {
+ if (arg_num + 1 == argc || args[arg_num + 1][0] == '-') {
+ cerr << "Error: Must include a filename to load from." << endl;
+ exit(0);
+ } else {
+ arg_num++; if (arg_num < argc) cur_arg = args[arg_num];
+ cfg->POPULATION_FILE.Set(cur_arg);
+ }
+ } else if (cur_arg == "-version" || cur_arg == "-v") {
+ cout << " For more information, see: http://devolab.cse.msu.edu/software/avida/" << endl;
+ exit(0);
+ } else if (cur_arg == "-set") {
+ if (arg_num + 1 == argc || arg_num + 2 == argc) {
+ cerr << "'-set' option must be followed by name and value" << endl;
+ exit(0);
+ }
+ arg_num++; if (arg_num < argc) cur_arg = args[arg_num];
+ cString name(cur_arg);
+ arg_num++; if (arg_num < argc) cur_arg = args[arg_num];
+ cString value(cur_arg);
+ sets.Add(name, value);
+ } else if (cur_arg == "-c" || cur_arg == "-config") {
+ cerr << "Error: -c[onfig] option must be listed first." << endl;
+ exit(0);
+ } else if (cur_arg == "-g" || cur_arg == "-genesis") {
+ cerr << "Warning: Use of '-g[enesis]' deprecated in favor or -c[onfig]." << endl;
+ cerr << "Error: -c[onfig] option must be listed first." << endl;
+ exit(0);
+ } else {
+ cerr << "Error: Unknown Option '" << argv[arg_num] << "'" << endl
+ << "Type: \"" << argv[0] << " -h\" for a full option list." << endl;
+ exit(0);
+ }
+
+ arg_num++; if (arg_num < argc) cur_arg = args[arg_num];
+ }
+
+ // Loop through all groups, then all entrys, and try to load each one.
+ tListIterator<cBaseConfigGroup> group_it(cfg->group_list);
+ cBaseConfigGroup * cur_group;
+ cString val;
+ while ((cur_group = group_it.Next()) != NULL) {
+ // Loop through entries for this group...
+ tListIterator<cBaseConfigEntry> entry_it(cur_group->GetEntryList());
+ cBaseConfigEntry * cur_entry;
+ while ((cur_entry = entry_it.Next()) != NULL) {
+ if (sets.Find(cur_entry->GetName(), val)) cur_entry->LoadString(val);
+ }
+ }
+
+ delete [] args;
+
+ return cfg;
+}
+
Modified: trunk/source/main/cAvidaConfig.h
===================================================================
--- trunk/source/main/cAvidaConfig.h 2005-10-16 14:39:55 UTC (rev 346)
+++ trunk/source/main/cAvidaConfig.h 2005-10-16 19:24:07 UTC (rev 347)
@@ -8,8 +8,8 @@
*
*/
-#ifndef CONFIG_HH
-#define CONFIG_HH
+#ifndef cAvidaConfig_h
+#define cAvidaConfig_h
// This class is designed to easily allow the construction of a dynamic
// configuration object that will handle the loading and management of all
@@ -141,12 +141,20 @@
tList<cBaseConfigGroup> group_list;
public:
- cAvidaConfig();
- ~cAvidaConfig();
+ cAvidaConfig() { group_list.Transfer(global_group_list); }
+ ~cAvidaConfig() { ; }
+
+ static cAvidaConfig* LoadWithCmdLineArgs(int argc, char* argv[]);
#ifdef OVERRIDE_CONFIG
#include "config_overrides.h"
#else
+ CONFIG_ADD_GROUP(GENERAL_GROUP, "General Settings");
+ CONFIG_ADD_VAR(ANALYZE_MODE, int, 0, "0 = Disabled\n1 = Enabled\n2 = Interactive");
+ CONFIG_ADD_VAR(VIEW_MODE, int, 0, "Initial viewer screen");
+ CONFIG_ADD_VAR(CLONE_FILE, cString, "-", "Clone file to load");
+ CONFIG_ADD_VAR(POPULATION_FILE, cString, "-", "Population file to load");
+
CONFIG_ADD_GROUP(ARCH_GROUP, "Architecture Variables");
CONFIG_ADD_VAR(MAX_UPDATES, int, -1, "Maximum updates to run experiment (-1 = no limit)");
CONFIG_ADD_VAR(MAX_GENERATIONS, int, -1, "Maximum generations to run experiment (-1 = no limit)");
@@ -249,9 +257,6 @@
CONFIG_ADD_VAR(LOG_SPECIES, bool, 0, "0/1 (off/on) toggle to print file.");
CONFIG_ADD_VAR(LOG_LANDSCAPE, bool, 0, "0/1 (off/on) toggle to print file.");
- CONFIG_ADD_GROUP(VIEWER_GROUP, "Viewer Settings");
- CONFIG_ADD_VAR(VIEW_MODE, int, 0, "Initial viewer screen");
-
CONFIG_ADD_GROUP(LINEAGE_GROUP, "Lineage\nNOTE: This should probably be called \"Clade\"\nThis one can slow down avida a lot. It is used to get an idea of how\noften an advantageous mutation arises, and where it goes afterwards.\nLineage creation options are. Works only when LOG_LINEAGES is set to 1.\n 0 = manual creation (on inject, use successive integers as lineage labels).\n 1 = when a child's (potential) fitness is higher than that of its parent.\n 2 = when a child's (potential) fitness is higher than max in population.\n 3 = when a child's (potential) fitness is higher than max in dom. lineage\n*and* the child is in the dominant lineage, or (2)\n 4 = when a child's (potential) fitness is higher than max in dom. lineage\n(and that of its own lineage)\n 5 = same as child's (potential) fitness is higher than that of the\n currently dominant organism, and also than that of any organism\n currently in the same lineage.\n 6 = when a child's (potential) f!
itness is higher than any organism\n currently in the same lineage.\n 7 = when a child's (potential) fitness is higher than that of any\n organism in its line of descent");
CONFIG_ADD_VAR(LOG_LINEAGES, bool, 0, "");
CONFIG_ADD_VAR(LINEAGE_CREATION_METHOD, int, 0, "");
@@ -264,10 +269,6 @@
void GenerateOverides();
};
-
-
-
-
// Concept:
// Setup #define to build class that will manage the specific variable inside
// of config, as well as any other necessary functions. Each class must have
Modified: trunk/source/main/primitive.cc
===================================================================
--- trunk/source/main/primitive.cc 2005-10-16 14:39:55 UTC (rev 346)
+++ trunk/source/main/primitive.cc 2005-10-16 19:24:07 UTC (rev 347)
@@ -10,6 +10,9 @@
#ifndef avida_h
#include "avida.h"
#endif
+#ifndef cAvidaConfig_h
+#include "cAvidaConfig.h"
+#endif
#ifndef AVIDA_DRIVER_ANALYZE_HH
#include "cAvidaDriver_Analyze.h"
#endif
@@ -79,6 +82,7 @@
cout << "under certain conditions. See file COPYING for details." << endl << endl;
// Initialize the configuration data...
+ //cAvidaConfig* cfg = cAvidaConfig::LoadWithCmdLineArgs(argc, argv);
cConfig::InitGroupList();
cConfig::Setup(argc, argv);
cConfig::SetupMS();
More information about the Avida-cvs
mailing list