[Avida-SVN] r1587 - branches/uml/source/main

hjg at myxo.css.msu.edu hjg at myxo.css.msu.edu
Tue May 22 08:57:29 PDT 2007


Author: hjg
Date: 2007-05-22 11:57:29 -0400 (Tue, 22 May 2007)
New Revision: 1587

Modified:
   branches/uml/source/main/cAvidaConfig.h
   branches/uml/source/main/cDeme.cc
   branches/uml/source/main/cDeme.h
   branches/uml/source/main/cOrganism.cc
   branches/uml/source/main/cOrganism.h
   branches/uml/source/main/cTaskLib.cc
   branches/uml/source/main/cTaskLib.h
   branches/uml/source/main/cUMLModel.cc
   branches/uml/source/main/cUMLModel.h
Log:
Enable each organism to have its own UML diagram. (Essentially, this code enables experiments to be run without using demes.)




Modified: branches/uml/source/main/cAvidaConfig.h
===================================================================
--- branches/uml/source/main/cAvidaConfig.h	2007-05-22 10:39:38 UTC (rev 1586)
+++ branches/uml/source/main/cAvidaConfig.h	2007-05-22 15:57:29 UTC (rev 1587)
@@ -216,7 +216,7 @@
   CONFIG_ADD_VAR(GERMLINE_REPLACES_SOURCE, int, 0, "Whether the source germline is updated\non replication; 0=no.");
   CONFIG_ADD_VAR(GERMLINE_RANDOM_PLACEMENT, int, 0, "Whether the seed for a germline is placed\n randomly within the deme; 0=no.");
   CONFIG_ADD_VAR(MAX_DEME_AGE, int, 500, "The maximum age of a deme (in updates) to be\nused for age-based replication (default=500).");  
-  CONFIG_ADD_VAR(UML_MODEL, int, 0, "Whether or not we are manipulating UML models; 0=no");
+  CONFIG_ADD_VAR(UML_MODEL, int, 0, "Whether or not we are manipulating UML models; 0=no; 1=DEME; 2=ORG");
   
   CONFIG_ADD_GROUP(REPRODUCTION_GROUP, "Birth and Death");
   CONFIG_ADD_VAR(BIRTH_METHOD, int, 0, "Which organism should be replaced on birth?\n0 = Random organism in neighborhood\n1 = Oldest in neighborhood\n2 = Largest Age/Merit in neighborhood\n3 = None (use only empty cells in neighborhood)\n4 = Random from population (Mass Action)\n5 = Oldest in entire population\n6 = Random within deme\n7 = Organism faced by parent\n8 = Next grid cell (id+1)\n9 = Largest energy used in entire population\n10 = Largest energy used in neighborhood");

Modified: branches/uml/source/main/cDeme.cc
===================================================================
--- branches/uml/source/main/cDeme.cc	2007-05-22 10:39:38 UTC (rev 1586)
+++ branches/uml/source/main/cDeme.cc	2007-05-22 15:57:29 UTC (rev 1587)
@@ -43,8 +43,8 @@
   birth_count = 0;
   org_count = 0;
   
-  // Initialize the UML model with 1 state diagram per organism.
-  umlMod.resetStateDiagrams(cell_ids.GetSize());
+  // Initialize the UML model with 1 state diagram per 
+  umlMod.resetUMLModel();
 
   // If width is negative, set it to the full number of cells.
   width = in_width;

Modified: branches/uml/source/main/cDeme.h
===================================================================
--- branches/uml/source/main/cDeme.h	2007-05-22 10:39:38 UTC (rev 1586)
+++ branches/uml/source/main/cDeme.h	2007-05-22 15:57:29 UTC (rev 1587)
@@ -56,10 +56,12 @@
   void IncOrgCount() { org_count++; }
   void DecOrgCount() { org_count--; }
 
+
   bool IsEmpty() const { return org_count == 0; }
   bool IsFull() const { return org_count == cell_ids.GetSize(); }
   
   // -= Germline =-
+  
   //! Returns this deme's germline.
   cGermline& GetGermline() { return _germline; }
   //! Replaces this deme's germline.

Modified: branches/uml/source/main/cOrganism.cc
===================================================================
--- branches/uml/source/main/cOrganism.cc	2007-05-22 10:39:38 UTC (rev 1586)
+++ branches/uml/source/main/cOrganism.cc	2007-05-22 15:57:29 UTC (rev 1587)
@@ -95,6 +95,7 @@
   m_guard_index = 0;
   m_action_index = 0;	
   
+  
 }
 
 
@@ -642,8 +643,17 @@
 
 cUMLModel* cOrganism::getUMLModel()
 {
-	cDeme& deme = m_world->GetPopulation().GetDeme(m_world->GetPopulation().GetCell(GetCellID()).GetDemeID());
-	return deme.getUMLModel();
+	cUMLModel* temp_mod;
+	
+	// Check if using deme...
+	if (m_world->GetConfig().NUM_DEMES.Get() != 1) { 
+			cDeme& deme = m_world->GetPopulation().GetDeme(m_world->GetPopulation().GetCell(GetCellID()).GetDemeID());
+			temp_mod = deme.getUMLModel();
+	} else { 
+	
+			temp_mod = &m_model;
+	}
+	return temp_mod;
 }
 
 bool cOrganism::absoluteJumpStateDiagram (int amount )

Modified: branches/uml/source/main/cOrganism.h
===================================================================
--- branches/uml/source/main/cOrganism.h	2007-05-22 10:39:38 UTC (rev 1586)
+++ branches/uml/source/main/cOrganism.h	2007-05-22 15:57:29 UTC (rev 1587)
@@ -147,7 +147,8 @@
   int m_trans_label_index;
   int m_trigger_index;
   int m_guard_index;
-  int m_action_index;							
+  int m_action_index;	
+  cUMLModel m_model;		// Used when not running as deme
   
   class cNetSupport
   {

Modified: branches/uml/source/main/cTaskLib.cc
===================================================================
--- branches/uml/source/main/cTaskLib.cc	2007-05-22 10:39:38 UTC (rev 1586)
+++ branches/uml/source/main/cTaskLib.cc	2007-05-22 15:57:29 UTC (rev 1587)
@@ -403,6 +403,9 @@
 	  NewTask(name, "Successfully ran Spin", &cTaskLib::Task_SpinN1);	  
   else if (name == "mult_trans") // 
 	  NewTask(name, "Successfully completed multiple transitions", &cTaskLib::Task_MultTrans);
+ else if (name == "mod_eval") // 
+	  NewTask(name, "Successfully evaluated model", &cTaskLib::Task_ModEval);
+	  
 	 
   
   // Make sure we have actually found a task  
@@ -2746,7 +2749,7 @@
 	cOrganism* organism = ctx.organism;
 	std::string temp;
 
-	temp = organism->getStateDiagram()->getXMI();
+	temp = organism->getUMLModel()->getXMI();
 /*
 	if (temp == organism->getParentXMI()) {
 		ctx.task_success_complete += organism->getParentBonusInfo("hydra");
@@ -2814,8 +2817,7 @@
 			subavida_output += line;
 			memset(line, 0, read_size);
 		}
-//	} while(((status==-1) && (errno == EINTR)) || (status>0));
-	} while(((status==-1) )|| (status>0));
+	} while(((status==-1) && (errno == EINTR)) || (status>0));
 
 	// Done with subavida.
 	close(from_subavida[0]);
@@ -2878,13 +2880,13 @@
 	
 	// check if the trigger is present
 //	if (organism->getStateDiagram()->findTrans(-1,-1,1,"*","*")){
-//		temp += 1;
+		temp += 1;
 		
 		// check property
 		if (ctx.task_success_complete) {
 			temp1 += SpinCoprocess(ctx, "N1");
 		} 
-	//}
+//	}
 	
 //	organism->setBonusInfo("spinn1", temp1); 
 	return temp1;
@@ -2894,3 +2896,6 @@
 	return (2^ctx.task_success_complete);
 }
 
+double cTaskLib::Task_ModEval(cTaskContext& ctx) const { 
+	return (ctx.organism->getUMLModel()->evaluateModel(ctx.organism->GetID(), m_world));
+} 

Modified: branches/uml/source/main/cTaskLib.h
===================================================================
--- branches/uml/source/main/cTaskLib.h	2007-05-22 10:39:38 UTC (rev 1586)
+++ branches/uml/source/main/cTaskLib.h	2007-05-22 15:57:29 UTC (rev 1587)
@@ -288,6 +288,7 @@
   double SpinCoprocess(cTaskContext& ctx, const std::string& neverclaimFile) const;
   double Task_SpinN1(cTaskContext& ctx) const;
   double Task_MultTrans(cTaskContext& ctx) const;  
+  double Task_ModEval(cTaskContext& ctx) const;  
   
 };
 

Modified: branches/uml/source/main/cUMLModel.cc
===================================================================
--- branches/uml/source/main/cUMLModel.cc	2007-05-22 10:39:38 UTC (rev 1586)
+++ branches/uml/source/main/cUMLModel.cc	2007-05-22 15:57:29 UTC (rev 1587)
@@ -34,12 +34,24 @@
 cUMLModel::cUMLModel()
 {
 	// initialize / seed UML model here
+	resetUMLModel();
+
 }
 
 cUMLModel::~cUMLModel()
 {
 }
 
+
+
+void cUMLModel::resetUMLModel()
+{
+	// Currently there are 2 state diagrams...
+	resetStateDiagrams(2);
+	return;
+
+}
+
 cUMLStateDiagram* cUMLModel::getStateDiagram (int x) 
 {
 	// check to see whether this state diagram exists
@@ -143,11 +155,13 @@
   
 }
 
-double cUMLModel::evaluateModel(int deme_id, cWorld* world)
+double cUMLModel::evaluateModel(int id, cWorld* world)
 {
 	double bonus = 0.0;
 	double mod_bonus = 0.0;
 	
+	double size = state_diagrams.size();
+	
 	int s0_nt = getStateDiagram(0)->numTrans();
 	int s1_nt = getStateDiagram(1)->numTrans();
 
@@ -172,7 +186,7 @@
 	// Check if the model meets the properties. 
 	if (mod_bonus > 0.0) {
 		self_bonus["spin_attemp"] = 1;
-		mod_bonus += propertyN1(deme_id, world);
+		mod_bonus += propertyN1(id, world);
 		self_bonus["spin_pass"] = mod_bonus;		
 		bonus += mod_bonus;
 	}
@@ -407,7 +421,7 @@
 }
 
 
-double cUMLModel::checkProperty(const std::string& neverclaimFile, int deme_id, cWorld* world) const {
+double cUMLModel::checkProperty(const std::string& neverclaimFile, int id, cWorld* world) const {
 //	m_world->GetStats().SpinAttempt();
 	double status=0;
 	std::string cmd = "cat " + neverclaimFile + " >> tmp.pr && ./spin -a tmp.pr &> /dev/null";
@@ -422,7 +436,7 @@
 	
 	
 	std::ostringstream strstrm;
-	strstrm << "cp tmp.xmi " << world->GetStats().GetUpdate() << "." << deme_id;
+	strstrm << "cp tmp.xmi " << world->GetStats().GetUpdate() << "." << id;
 	strstrm << ".xml";	
 	if(system(strstrm.str().c_str())!=0) return 0.0;
 			

Modified: branches/uml/source/main/cUMLModel.h
===================================================================
--- branches/uml/source/main/cUMLModel.h	2007-05-22 10:39:38 UTC (rev 1586)
+++ branches/uml/source/main/cUMLModel.h	2007-05-22 15:57:29 UTC (rev 1587)
@@ -21,6 +21,7 @@
 	~cUMLModel();
 	std::string getXMI(); // get the XMI version of the model
 	void printXMI();
+	void resetUMLModel();
 	double formalizeModel(); // formalize the model using Hydra
 	double checkProperty(const std::string& neverclaimFile, int, cWorld*) const; // check for property satisfaction using Spin
 	double propertyN1(int, cWorld*) const; // check for property N1




More information about the Avida-cvs mailing list