[Avida-SVN] r2683 - in branches/uml-merge/source: main orchid
dk at myxo.css.msu.edu
dk at myxo.css.msu.edu
Tue Jun 24 09:20:15 PDT 2008
Author: dk
Date: 2008-06-24 12:20:15 -0400 (Tue, 24 Jun 2008)
New Revision: 2683
Modified:
branches/uml-merge/source/main/cOrganism.cc
branches/uml-merge/source/main/cOrganism.h
branches/uml-merge/source/main/cPopulation.h
branches/uml-merge/source/orchid/cUMLModel.cc
branches/uml-merge/source/orchid/cUMLModel.h
Log:
Refactoring cOrganism, cPopulation wrt Orchid.
Modified: branches/uml-merge/source/main/cOrganism.cc
===================================================================
--- branches/uml-merge/source/main/cOrganism.cc 2008-06-24 13:12:42 UTC (rev 2682)
+++ branches/uml-merge/source/main/cOrganism.cc 2008-06-24 16:20:15 UTC (rev 2683)
@@ -74,10 +74,7 @@
, killed_event(false)
, m_net(NULL)
, m_msg(0)
- , m_state_diag(0)
- , m_orig_state_index(0)
- , m_dest_state_index(0)
- , m_model((const char*)world->GetConfig().SEED_MODEL.Get())
+ , m_orchid(0)
{
// Initialization of structures...
m_hardware = m_world->GetHardwareManager().Create(this);
@@ -697,17 +694,32 @@
}
-//-------- Orchid functions --------
-/// This function is a copy of DoOutput ///
+// -------- Orchid support --------
+
+/*! Default constructor for Orchid support. Initialize all Orchid-related variables
+ that are specific to this organism.
+ */
+cOrganism::cOrchidSupport::cOrchidSupport(cWorld* world)
+: m_state_diag(0)
+, m_orig_state_index(0)
+, m_dest_state_index(0)
+, m_model((const char*)world->GetConfig().SEED_MODEL.Get())
+{
+}
+
+
+/*! Model check this organism... (more)
+ */
void cOrganism::ModelCheck(cAvidaContext& ctx)
{
if(GetCellID()==-1) return;
-
- if (m_model.GetGenMode() == 0) {
- m_model.PrintXMI();
+ InitOrchid();
+
+ if(m_orchid->m_model.GetGenMode() == 0) {
+ m_orchid->m_model.PrintXMI();
// Update the value of max trans
- if (m_model.NumTrans() > m_model.GetMaxTrans()) {
- m_model.SetMaxTrans(m_model.NumTrans());
+ if(m_orchid->m_model.NumTrans() > m_orchid->m_model.GetMaxTrans()) {
+ m_orchid->m_model.SetMaxTrans(m_orchid->m_model.NumTrans());
}
}
@@ -716,81 +728,91 @@
cUMLModel* org_model = GetUMLModel();
cUMLModel* pop_model = m_world->GetPopulation().GetUMLModel();
m_world->GetStats().OrchidStatsPostTaskCheck(org_model, pop_model);
- m_model.GetPropertyGenerator()->ResetPropertyReward();
-
-
+ m_orchid->m_model.GetPropertyGenerator()->ResetPropertyReward();
}
+
cUMLModel* cOrganism::GetUMLModel()
{
- return &m_model;
+ InitOrchid();
+ return &m_orchid->m_model;
}
-bool cOrganism::AbsoluteJumpStateDiagram (int amount )
+
+bool cOrganism::AbsoluteJumpStateDiagram(int amount)
{
- m_state_diag = 0;
+ InitOrchid();
+ m_orchid->m_state_diag = 0;
return RelativeJumpStateDiagram(amount);
}
-bool cOrganism::RelativeJumpStateDiagram (int amount )
+
+bool cOrganism::RelativeJumpStateDiagram(int amount)
{
+ InitOrchid();
int size = GetUMLModel()->GetStateDiagramSize();
- if (size == 0) {
+ if(size == 0) {
return false;
}
- if (size > 0) {
- m_state_diag += (amount % size);
-
+ if(size > 0) {
+ m_orchid->m_state_diag += (amount % size);
+
// index is greater than vector
- if (m_state_diag >= size) {
- m_state_diag -= size;
- } else if(m_state_diag < 0) {
- m_state_diag += size;
+ if(m_orchid->m_state_diag >= size) {
+ m_orchid->m_state_diag -= size;
+ } else if(m_orchid->m_state_diag < 0) {
+ m_orchid->m_state_diag += size;
}
}
-
+
return true;
}
+
cUMLStateDiagram* cOrganism::GetStateDiagram()
{
- return m_model.GetStateDiagram(m_state_diag);
+ InitOrchid();
+ return m_orchid->m_model.GetStateDiagram(m_orchid->m_state_diag);
}
bool cOrganism::AbsoluteJumpOriginState(int amount)
{
- m_orig_state_index = 0;
+ InitOrchid();
+ m_orchid->m_orig_state_index = 0;
return (RelativeJumpOriginState(amount));
}
+
bool cOrganism::AbsoluteJumpDestinationState(int amount)
{
- m_dest_state_index = 0;
+ InitOrchid();
+ m_orchid->m_dest_state_index = 0;
return (RelativeJumpDestinationState(amount));
}
bool cOrganism::AddTransitionTotal()
{
+ InitOrchid();
bool val;
- val = GetStateDiagram()->AddTransitionTotal();
-
+ val = GetStateDiagram()->AddTransitionTotal();
return val;
}
bool cOrganism::RelativeJumpOriginState(int amount)
{
- m_orig_state_index += amount;
+ InitOrchid();
+ m_orchid->m_orig_state_index += amount;
return true;
}
bool cOrganism::RelativeJumpDestinationState(int amount)
{
- m_dest_state_index += amount;
+ InitOrchid();
+ m_orchid->m_dest_state_index += amount;
return true;
}
-
Modified: branches/uml-merge/source/main/cOrganism.h
===================================================================
--- branches/uml-merge/source/main/cOrganism.h 2008-06-24 13:12:42 UTC (rev 2682)
+++ branches/uml-merge/source/main/cOrganism.h 2008-06-24 16:20:15 UTC (rev 2683)
@@ -149,16 +149,6 @@
};
cNetSupport* m_net;
-//-------- Orchid variables --------
- int m_state_diag; // Index of the state diagram that the organism is currently
- // manipulating
- int m_orig_state_index;
- int m_dest_state_index;
- cUMLModel m_model;
- std::string m_parent_xmi;
- std::map<std::string, float> m_parent_bonus;
- std::vector<double> m_parent_scenario_completion;
-
cOrganism(); // @not_implemented
cOrganism(const cOrganism&); // @not_implemented
cOrganism& operator=(const cOrganism&); // @not_implemented
@@ -409,24 +399,34 @@
void SetEventKilled() { killed_event = true; }
bool GetEventKilled() { return killed_event; }
-
-
-//-------- Orchid functions --------
+ // -------- Orchid support --------
+public:
+ //!
void ModelCheck(cAvidaContext& ctx);
+ //!
cUMLModel* GetUMLModel();
- std::string GetParentXMI() { return m_parent_xmi; }
- int GetStateDiagramIndex() { return m_state_diag; }
+ //! Return the XMI string for the model generated by this organism's parent.
+ const std::string& GetParentXMI() { InitOrchid(); return m_orchid->m_parent_xmi; }
+ //!
+ int GetStateDiagramIndex() { InitOrchid(); return m_orchid->m_state_diag; }
+ //! (use meaningful names for parameters)
bool CurrTrans (int, int, int, int, int, int);
+ //!
cUMLStateDiagram* GetStateDiagram();
- void SetParentXMI(std::string s) { m_parent_xmi = s; }
- void SetParentBonus (std::map<std::string, float> v) { m_parent_bonus = v; }
- float GetParentBonus (std::string s) { return m_parent_bonus[s]; }
- std::map<std::string, float> GetParentBonus() { return m_parent_bonus; }
- std::vector<double> GetParentScenarioCompletion() { return m_parent_scenario_completion; }
- void SetParentScenarioCompletion (std::vector<double> s) { m_parent_scenario_completion = s; }
-
+ //! consider const std::string& (parameter name)
+ void SetParentXMI(const std::string& xmi) { InitOrchid(); m_orchid->m_parent_xmi = xmi; }
+ //!
+ void SetParentBonus(const std::map<std::string,float>& parent_bonus) { InitOrchid(); m_orchid->m_parent_bonus = parent_bonus; }
+ //! (names)
+ float GetParentBonus(const std::string& s) { InitOrchid(); return m_orchid->m_parent_bonus[s]; }
+ //! Returns the bonus map for this organism's parent.
+ const std::map<std::string, float>& GetParentBonus() { InitOrchid(); return m_orchid->m_parent_bonus; }
+ //! Returns a vector for scenario completion of this organism's parent.
+ const std::vector<double>& GetParentScenarioCompletion() { InitOrchid(); return m_orchid->m_parent_scenario_completion; }
+ //! (names)
+ void SetParentScenarioCompletion (const std::vector<double>& s) { InitOrchid(); m_orchid->m_parent_scenario_completion = s; }
-// The jump functions jump the index of the various vectors either forward (+ int) or backwards (- int)
+ // The jump functions jump the index of the various vectors either forward (+ int) or backwards (- int)
bool AbsoluteJumpOriginState(int);
bool AbsoluteJumpDestinationState(int);
bool AbsoluteJumpStateDiagram (int);
@@ -435,6 +435,30 @@
bool RelativeJumpStateDiagram (int);
bool AddTransitionTotal();
+protected:
+ /*! Contains all the different data structures needed to support Orchid-related
+ functionality. Inspired by cMessagingSupport (above), the idea is to minimize
+ impact when not running Orchid experiments. */
+ struct cOrchidSupport
+ {
+ //! Default constructor.
+ cOrchidSupport(cWorld* world);
+ int m_state_diag; //!< Index of the state diagram currently being manipulated.
+ int m_orig_state_index; //!<
+ int m_dest_state_index; //!<
+ cUMLModel m_model; //!<
+ std::string m_parent_xmi; //!<
+ std::map<std::string, float> m_parent_bonus; //!<
+ std::vector<double> m_parent_scenario_completion; //!<
+ };
+
+ /*! This member variable is lazily initialized whenever any of the messaging
+ methods are used. (My kingdom for boost::shared_ptr.) */
+ cOrchidSupport* m_orchid;
+
+ //! Called to check for (and initialize) orchid support within this organism.
+ inline void InitOrchid() { if(!m_orchid) m_orchid = new cOrchidSupport(m_world); }
+ //-------- End of Orchid support --------
};
Modified: branches/uml-merge/source/main/cPopulation.h
===================================================================
--- branches/uml-merge/source/main/cPopulation.h 2008-06-24 13:12:42 UTC (rev 2682)
+++ branches/uml-merge/source/main/cPopulation.h 2008-06-24 16:20:15 UTC (rev 2683)
@@ -58,9 +58,6 @@
#ifndef tVector_h
#include "tVector.h"
#endif
-#ifndef _C_UMLMODEL_H_
-#include "cUMLModel.h"
-#endif
#if USE_tMemTrack
# ifndef tMemTrack_h
@@ -115,9 +112,6 @@
// Outside interactions...
bool sync_events; // Do we need to sync up the event list with population?
- // UML branch -- for property generation
- cUMLModel m_model;
-
///////////////// Private Methods ////////////////////
void BuildTimeSlicer(cChangeList* change_list); // Build the schedule object
@@ -323,11 +317,6 @@
// Let users change environmental variables durning the run @BDB 22-Feb-2008
void UpdateResourceCount(const int Verbosity);
-
-
-//-------- Orchid function --------
-// get at the population's model.
- cUMLModel* GetUMLModel() { return &m_model; }
};
Modified: branches/uml-merge/source/orchid/cUMLModel.cc
===================================================================
--- branches/uml-merge/source/orchid/cUMLModel.cc 2008-06-24 13:12:42 UTC (rev 2682)
+++ branches/uml-merge/source/orchid/cUMLModel.cc 2008-06-24 16:20:15 UTC (rev 2683)
@@ -12,7 +12,7 @@
xmi_info loadFile(const char* filename) {
std::string data, line; // or maybe stringstream? (strstream?)
std::ifstream infile;
- infile.open(filename);
+ infile.open(filename);
assert(infile.is_open());
std::string s;
xmi_info x;
@@ -357,7 +357,7 @@
return;
}
-xmi_info cUMLModel::xi = loadFile("xmi_info");
+xmi_info cUMLModel::xi;// = loadFile("xmi_info");
int cUMLModel::max_trans = 0;
Modified: branches/uml-merge/source/orchid/cUMLModel.h
===================================================================
--- branches/uml-merge/source/orchid/cUMLModel.h 2008-06-24 13:12:42 UTC (rev 2682)
+++ branches/uml-merge/source/orchid/cUMLModel.h 2008-06-24 16:20:15 UTC (rev 2683)
@@ -11,7 +11,7 @@
#include <map>
#include <utility>
#include <algorithm>
-#include <Set>
+#include <set>
#include <vector>
#include <fstream>
@@ -25,12 +25,14 @@
std::string alt_Set_name;
};
+
struct xmi_info {
- std::string xmi_begin;
- std::string xmi_end;
+ std::string xmi_begin;
+ std::string xmi_end;
std::vector<std::string> classes_info;
};
+
class cUMLModel {
public:
//! Constructor that loads state diagram and scenario information from seed-model.cfg.
@@ -149,9 +151,7 @@
static cMDEPropertyGenerator _cfg_gen;
cMDEPropertyGenerator* gen;
-
};
-
#endif
More information about the Avida-cvs
mailing list