[Avida-SVN] r1986 - branches/uml/source/main
dknoester at myxo.css.msu.edu
dknoester at myxo.css.msu.edu
Wed Aug 22 12:56:02 PDT 2007
Author: dknoester
Date: 2007-08-22 15:56:02 -0400 (Wed, 22 Aug 2007)
New Revision: 1986
Modified:
branches/uml/source/main/cOrganism.cc
branches/uml/source/main/cUMLModel.cc
branches/uml/source/main/cUMLModel.h
Log:
Updated to use cached seed information.
Modified: branches/uml/source/main/cOrganism.cc
===================================================================
--- branches/uml/source/main/cOrganism.cc 2007-08-22 19:33:53 UTC (rev 1985)
+++ branches/uml/source/main/cOrganism.cc 2007-08-22 19:56:02 UTC (rev 1986)
@@ -91,15 +91,9 @@
if (m_world->GetConfig().NET_ENABLED.Get()) m_net = new cNetSupport();
m_id = m_world->GetStats().GetTotCreatures();
-
- /* m_state_diag = 1;
-*/
+
m_orig_state_index = 0;
m_dest_state_index = 0;
-/* m_trigger_index = 0;
- m_guard_index = 0;
- m_action_index = 0;*/
- m_model.seedDiagrams();
m_parent_xmi = "";
}
Modified: branches/uml/source/main/cUMLModel.cc
===================================================================
--- branches/uml/source/main/cUMLModel.cc 2007-08-22 19:33:53 UTC (rev 1985)
+++ branches/uml/source/main/cUMLModel.cc 2007-08-22 19:56:02 UTC (rev 1986)
@@ -55,50 +55,22 @@
line.erase();
}
-
+
infile.close();
-
return x;
}
-xmi_info cUMLModel::xi = loadFile("xmi_info");
-int cUMLModel::max_trans = 0;
+/*! This function intializes variables with data read from a file named "seed-model.cfg".
-cUMLModel::cUMLModel()
-{}
-
-cUMLModel::~cUMLModel()
-{}
-
-float cUMLModel::getBonusInfo (std::string s)
-{
- float val;
- std::map<std::string, float>::iterator bonus_info_pointer;
-
- bonus_info_pointer = bonus_info.find(s);
-
- if (bonus_info_pointer != bonus_info.end()) {
- val = bonus_info[s];
- } else {
- val = 0;
- }
- return val;
-}
-
-
-cUMLStateDiagram* cUMLModel::getStateDiagram (unsigned int x)
-{
- assert(x<state_diagrams.size());
- return &state_diagrams[x];
-}
-
-/* This is a crappy little function to read in from a file.
+"This is a crappy little function to read in from a file.
It is not robust. It will not understand things unless you
-follow the *very* specific file format. */
-void cUMLModel::seedDiagrams()
-{
- std::string data, line; // or maybe stringstream? (strstream?)
+follow the *very* specific file format."
+*/
+void seed_diagrams(std::vector<cUMLStateDiagram>& state_diagrams,
+ std::vector<scenario_info>& scenarios,
+ int& hydra_mode) {
+ std::string data, line; // or maybe stringstream? (strstream?)
int num_states;
int num_sd = 0;
int cur_sd = -1;
@@ -117,10 +89,10 @@
if (line == "=STATES====================") {
line.erase();
infile >> num_states;
- // Read in number of state diagrams
+ // Read in number of state diagrams
} else if (line == "=HYDRA=====================") {
line.erase();
- infile >> hydraMode;
+ infile >> hydra_mode;
} else if (line == "=INCLUDE-TRANSITIONS=======") {
line.erase();
infile >> include_trans;
@@ -128,7 +100,7 @@
line.erase();
infile >> num_sd;
state_diagrams.resize(num_sd);
- // Read in each state diagram
+ // Read in each state diagram
} else if (line == "=SD========================") {
line.erase();
cur_sd++;
@@ -178,20 +150,64 @@
scenarios.push_back(s);
}
-
+
/* Missing code for reading in transition labels .... */
-
line.erase();
- }
-
- //read from file; load into string/strstream, and return it.
+ }
+
infile.close();
+ return;
+}
- return;
+
+xmi_info cUMLModel::xi = loadFile("xmi_info");
+int cUMLModel::max_trans = 0;
+
+
+bool cUMLModel::_cfgLoaded = false;
+std::vector<cUMLStateDiagram> cUMLModel::_cfg_state_diagrams;
+std::vector<scenario_info> cUMLModel::_cfg_scenarios;
+int cUMLModel::_cfg_hydra_mode;
+
+
+cUMLModel::cUMLModel() {
+ if(!_cfgLoaded) {
+ seed_diagrams(_cfg_state_diagrams, _cfg_scenarios, _cfg_hydra_mode);
+ _cfgLoaded = true;
+ }
+ state_diagrams = _cfg_state_diagrams;
+ scenarios = _cfg_scenarios;
+ hydraMode = _cfg_hydra_mode;
}
+cUMLModel::~cUMLModel()
+{}
+
+float cUMLModel::getBonusInfo (std::string s)
+{
+ float val;
+ std::map<std::string, float>::iterator bonus_info_pointer;
+
+ bonus_info_pointer = bonus_info.find(s);
+
+ if (bonus_info_pointer != bonus_info.end()) {
+ val = bonus_info[s];
+ } else {
+ val = 0;
+ }
+ return val;
+}
+
+
+cUMLStateDiagram* cUMLModel::getStateDiagram (unsigned int x)
+{
+ assert(x<state_diagrams.size());
+ return &state_diagrams[x];
+}
+
+
void cUMLModel::printXMI()
{
xmi = "";
Modified: branches/uml/source/main/cUMLModel.h
===================================================================
--- branches/uml/source/main/cUMLModel.h 2007-08-22 19:33:53 UTC (rev 1985)
+++ branches/uml/source/main/cUMLModel.h 2007-08-22 19:56:02 UTC (rev 1986)
@@ -27,11 +27,9 @@
class cUMLModel {
public:
+ //! Constructor that loads state diagram and scenario information from seed-model.cfg.
cUMLModel();
~cUMLModel();
-
- // Read in from file seed-model.cfg and add the building blocks for the diagrams.
- void seedDiagrams();
// Used to check if the diagrams satisfy the specified scenarios
double checkForScenarios();
@@ -76,7 +74,12 @@
std::vector<scenario_info> scenarios;
std::vector<double> scenario_completion;
int hydraMode;
-
+
+ // The following are set once per Avida experiment, when the first cUMLModel is constructed:
+ static bool _cfgLoaded; //!< Whether or not we've already loaded seed-model.cfg.
+ static std::vector<cUMLStateDiagram> _cfg_state_diagrams; //!< State diagrams as read from seed-model.cfg.
+ static std::vector<scenario_info> _cfg_scenarios; //!< Scenarios as read from seed-model.cfg.
+ static int _cfg_hydra_mode; //!< Execution mode for hydra, as read from seed-model.cfg.
};
More information about the Avida-cvs
mailing list