[Avida-SVN] r1556 - in branches/uml/source: actions cpu main

hjg at myxo.css.msu.edu hjg at myxo.css.msu.edu
Tue May 15 11:52:11 PDT 2007


Author: hjg
Date: 2007-05-15 14:52:10 -0400 (Tue, 15 May 2007)
New Revision: 1556

Modified:
   branches/uml/source/actions/PrintActions.cc
   branches/uml/source/cpu/cHardwareCPU.cc
   branches/uml/source/main/cAvidaConfig.h
   branches/uml/source/main/cOrganism.cc
   branches/uml/source/main/cOrganism.h
   branches/uml/source/main/cPopulation.cc
   branches/uml/source/main/cPopulation.h
   branches/uml/source/main/cTaskLib.cc
   branches/uml/source/main/cUMLModel.cc
   branches/uml/source/main/cUMLModel.h
   branches/uml/source/main/cUMLStateDiagram.cc
   branches/uml/source/main/cUMLStateDiagram.h
Log:
Enabled a deme of organisms to manipulate a UML diagram consisting of multiple state diagrams. Each organism can choose which diagram to manipulate. Additionally, tasks check if the organisms are contributing to the fulfillment of sequence diagrams. Deme competition checks if the models can be formalized and adhere to a property. It is missing support for stats. 



Modified: branches/uml/source/actions/PrintActions.cc
===================================================================
--- branches/uml/source/actions/PrintActions.cc	2007-05-15 14:13:14 UTC (rev 1555)
+++ branches/uml/source/actions/PrintActions.cc	2007-05-15 18:52:10 UTC (rev 1556)
@@ -1735,6 +1735,18 @@
   }
 };
 
+class cActionPrintDemeUMLStats : public cAction
+{
+public:
+  cActionPrintDemeUMLStats(cWorld* world, const cString& args) : cAction(world, args) { ; }
+  
+  static const cString GetDescription() { return "No Arguments"; }
+  
+  void Process(cAvidaContext& ctx)
+  {
+    m_world->GetPopulation().PrintDemeUMLStats();
+  }
+};
 
 class cActionSetVerbose : public cAction
 {
@@ -1810,6 +1822,8 @@
   action_lib->Register<cActionPrintPhenotypeData>("PrintPhenotypeData");
   action_lib->Register<cActionPrintPhenotypeStatus>("PrintPhenotypeStatus");
   action_lib->Register<cActionPrintDemeStats>("PrintDemeStats");
+  action_lib->Register<cActionPrintDemeUMLStats>("PrintDemeUMLStats");
+
   
   // Processed Data
   action_lib->Register<cActionPrintData>("PrintData");
@@ -1875,6 +1889,8 @@
   action_lib->Register<cActionPrintPhenotypeData>("print_number_phenotypes");
   action_lib->Register<cActionPrintPhenotypeStatus>("print_phenotype_status");
   action_lib->Register<cActionPrintDemeStats>("print_deme_stats");
+  action_lib->Register<cActionPrintDemeUMLStats>("print_deme_uml_stats");
+
   
   action_lib->Register<cActionPrintData>("print_data");
   action_lib->Register<cActionPrintInstructionAbundanceHistogram>("print_instruction_abundance_histogram");

Modified: branches/uml/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/uml/source/cpu/cHardwareCPU.cc	2007-05-15 14:13:14 UTC (rev 1555)
+++ branches/uml/source/cpu/cHardwareCPU.cc	2007-05-15 18:52:10 UTC (rev 1556)
@@ -3420,7 +3420,6 @@
 bool cHardwareCPU::Inst_HeadDivide(cAvidaContext& ctx)
 {
   // modified for UML branch
-  organism->modelCheck(ctx);
   return Inst_HeadDivideMut(ctx, 1);
   
 }
@@ -4160,6 +4159,8 @@
 bool cHardwareCPU::Inst_AddTransitionTotal(cAvidaContext& ctx)
 {
 	if(organism->GetCellID()==-1) return false;
+	
+	organism->modelCheck(ctx);
 
 	return organism->getStateDiagram()->addTransitionTotal();
 }

Modified: branches/uml/source/main/cAvidaConfig.h
===================================================================
--- branches/uml/source/main/cAvidaConfig.h	2007-05-15 14:13:14 UTC (rev 1555)
+++ branches/uml/source/main/cAvidaConfig.h	2007-05-15 18:52:10 UTC (rev 1556)
@@ -216,6 +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_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/cOrganism.cc
===================================================================
--- branches/uml/source/main/cOrganism.cc	2007-05-15 14:13:14 UTC (rev 1555)
+++ branches/uml/source/main/cOrganism.cc	2007-05-15 18:52:10 UTC (rev 1556)
@@ -676,4 +676,13 @@
 
 }
 
+// Determines if this is the transition the organism is about to add
+bool cOrganism::currTrans (int sd, int orig, int dest, std::string tr, std::string gu, std::string act)
+{
+	// check if it is manipulating this diagram 
+	if (sd != m_state_diag) return false;
+	
+	return (getUMLModel()->getStateDiagram(m_state_diag)->currTrans(orig, dest, tr, gu, act));
 
+}
+

Modified: branches/uml/source/main/cOrganism.h
===================================================================
--- branches/uml/source/main/cOrganism.h	2007-05-15 14:13:14 UTC (rev 1555)
+++ branches/uml/source/main/cOrganism.h	2007-05-15 18:52:10 UTC (rev 1556)
@@ -307,6 +307,7 @@
   bool relativeMoveSDIndex (int); 
   bool lastStateDiagram () { m_state_diag = getUMLModel()->getStateDiagramSize(); }
   bool firstStateDiagram() { m_state_diag = 0; }  
+  bool currTrans (int, int, int, std::string, std::string, std::string); 
   cUMLStateDiagram* getStateDiagram();
   
 };

Modified: branches/uml/source/main/cPopulation.cc
===================================================================
--- branches/uml/source/main/cPopulation.cc	2007-05-15 14:13:14 UTC (rev 1555)
+++ branches/uml/source/main/cPopulation.cc	2007-05-15 18:52:10 UTC (rev 1556)
@@ -827,6 +827,7 @@
       }
     }
     is_init[to_deme_id] = true;
+	
   }
   
   // Now re-inject all remaining demes into themselves to reset them.
@@ -1155,6 +1156,38 @@
 }
 
 
+void cPopulation::PrintDemeUMLStats()
+{
+  cStats& stats = m_world->GetStats();
+  
+  cDataFile & df_uml = m_world->GetDataFile("deme_uml.dat");
+ 
+  df_uml.WriteComment("UML info for each deme in the population");
+ 
+  df_uml.Write(stats.GetUpdate(), "update");
+
+  const int num_demes = deme_array.GetSize();
+  for (int deme_id = 0; deme_id < num_demes; deme_id++) {
+    cString comment;
+		df_uml.Write(deme_id, "Deme ID");
+		df_uml.Endl();
+
+		
+		// Print all the self_bonus info
+		std::map <std::string, double> uml_bonus = deme_array[deme_id].getUMLModel()->getBonus();
+		std::map<std::string, double>::const_iterator iter;
+		for (iter=uml_bonus.begin(); iter != uml_bonus.end(); ++iter) {
+//			cout << iter->second << " " << iter->first << endl;
+			df_uml.Write(iter->second, (iter->first).c_str());
+			df_uml.Endl();
+
+		}
+
+  }
+    
+  
+}
+
 // Print out statistics about individual demes
 
 void cPopulation::PrintDemeStats()
@@ -2475,3 +2508,7 @@
 cChangeList *cPopulation::GetChangeList(){
   return schedule->GetChangeList();
 }
+
+
+
+

Modified: branches/uml/source/main/cPopulation.h
===================================================================
--- branches/uml/source/main/cPopulation.h	2007-05-15 14:13:14 UTC (rev 1555)
+++ branches/uml/source/main/cPopulation.h	2007-05-15 18:52:10 UTC (rev 1556)
@@ -216,6 +216,11 @@
 
   void SetChangeList(cChangeList* change_list);
   cChangeList* GetChangeList();
+  
+  // UML stats
+  void PrintDemeUMLStats();
+
+  
 };
 
 

Modified: branches/uml/source/main/cTaskLib.cc
===================================================================
--- branches/uml/source/main/cTaskLib.cc	2007-05-15 14:13:14 UTC (rev 1555)
+++ branches/uml/source/main/cTaskLib.cc	2007-05-15 18:52:10 UTC (rev 1556)
@@ -2643,19 +2643,23 @@
 double cTaskLib::Task_Trans1(cTaskContext& ctx) const
 {
 	double bonus = 0.0;
-	if (ctx.organism->getStateDiagram()->findTrans(0,1,1, "ga", "aa")) {
+//	if (ctx.organism->getStateDiagram()->findTrans(0,1,1, "ga", "aa")) {
+	if (ctx.organism->currTrans(0, -1, -1, "*", "*", "^TempSensor.getOpState()")) {		
+
 		ctx.task_success_complete = 1;	
 		bonus = 1.0;
 	}
 	
-//	ctx->task_success_complete = 0;	
+	ctx.task_success_complete = 0;	
 	return bonus;
 }
 
 double cTaskLib::Task_Trans2(cTaskContext& ctx) const
 {
 	double bonus = 0.0;
-	if (ctx.organism->getStateDiagram()->findTrans(1,2,1,"gd", "ab")){
+//	if (ctx.organism->getStateDiagram()->findTrans(1,2,1,"gd", "ab")){
+	if (ctx.organism->currTrans(0, -1, -1, "setTempOpState", "*", "*")) {		
+
 			ctx.task_success_complete += 1;	
 			bonus = 1.0;
 	}
@@ -2667,7 +2671,9 @@
 double cTaskLib::Task_Trans3(cTaskContext& ctx) const
 {
 	double bonus = 0.0;
-	if (ctx.organism->getStateDiagram()->findTrans(2,3,3,"gb", "ac")){
+//	if (ctx.organism->getStateDiagram()->findTrans(2,3,3,"gb", "ac")){
+	if (ctx.organism->currTrans(1, -1, -1, "getOpState", "*", "*")) {		
+
 			bonus = 1.0;
 			ctx.task_success_complete += 1;	
 	}
@@ -2679,7 +2685,9 @@
 double cTaskLib::Task_Trans4(cTaskContext& ctx) const
 {
 	double bonus = 0.0;
-	if (ctx.organism->getStateDiagram()->findTrans(3,4,2,"gc", "ad")){
+//	if (ctx.organism->getStateDiagram()->findTrans(3,4,2,"gc", "ad")){
+	if (ctx.organism->currTrans(1, -1, -1, "*", "*", "op_state:=1")) {		
+
 			ctx.task_success_complete += 1;	
 			bonus = 1.0;
 	}
@@ -2691,7 +2699,9 @@
 double cTaskLib::Task_Trans5(cTaskContext& ctx) const
 {
 	double bonus = 0.0;
-	if (ctx.organism->getStateDiagram()->findTrans(4,0,4,"ga","ac")){
+//	if (ctx.organism->getStateDiagram()->findTrans(4,0,4,"ga","ac")){		
+	if (ctx.organism->currTrans(1, -1, -1, "*", "*", "^SoftwareSensor.setTempOpState(op_state)")) {		
+
 			ctx.task_success_complete += 1;	
 			bonus = 1.0;
 	}

Modified: branches/uml/source/main/cUMLModel.cc
===================================================================
--- branches/uml/source/main/cUMLModel.cc	2007-05-15 14:13:14 UTC (rev 1555)
+++ branches/uml/source/main/cUMLModel.cc	2007-05-15 18:52:10 UTC (rev 1556)
@@ -70,6 +70,7 @@
 
 void cUMLModel::seedDiagrams()
 {
+  self_bonus.clear();
   
   // For the first state diagram... 
   // Software Sensor
@@ -126,17 +127,47 @@
 double cUMLModel::evaluateModel()
 {
 	double bonus = 0.0;
-		// Check if the model meets the sequence diagram
-		bonus += checkForSequenceDiagram1();
+	double mod_bonus = 0.0;
+	
+	int s0_nt = getStateDiagram(0)->numTrans();
+	int s1_nt = getStateDiagram(1)->numTrans();
+
+	// Check if the model meets the sequence diagram
+	bonus += checkForSequenceDiagram1();
 		
 		
-		// Check if the model can be correctly formalized
-		
-		
-		
-		// Check if the model meets the properties. 
+	// Check if the model can be correctly formalized
+	if (bonus >= 6.0) {
+		self_bonus["hydra_attempt"] = 1;
+		mod_bonus = formalizeModel();
+		self_bonus["hydra_pass"] = mod_bonus;		
+		bonus += mod_bonus;
+	}
+	
 
+	// Check if the model meets the properties. 
+	if (mod_bonus > 0.0) {
+		self_bonus["spin_attemp"] = 1;
+		mod_bonus += propertyN1();
+		self_bonus["spin_pass"] = mod_bonus;		
+		bonus += mod_bonus;
+	}
 
+	// additional bonus for creating transitions...
+	if (s0_nt <= 2) { 
+		bonus += (s0_nt / 2);
+	} else {
+		bonus += 2;
+	}
+	
+	if (s1_nt <= 2) { 
+		bonus += (s1_nt / 2);
+	} else {
+		bonus += 2;
+	}
+	
+	
+
 	return bonus;
 }
 
@@ -144,17 +175,21 @@
 double cUMLModel::checkForSequenceDiagram1()
 {
 	double bonus = 0.0;
+	double temp_bonus = 0.0;
+
 	
 	cUMLStateDiagram* soft_sense = getStateDiagram(0);
 	cUMLStateDiagram* temp_sense = getStateDiagram(1);
 	
-	// reward if number of transitions is greater than 10
 	int nt = soft_sense->numTrans() + temp_sense->numTrans();
+/*	// reward if number of transitions is greater than 10
+	int nt = soft_sense->numTrans() + temp_sense->numTrans();
 	if (nt <= 10) { 
 		bonus += nt;
 	} else {
 		bonus += 10;
 	}
+*/	
 	
 
 				
@@ -162,25 +197,35 @@
 	
 	// action: 
 	// TempSensor.getOpState()
-	bonus += soft_sense->findTrans(-1, -1, -1, "*", "^TempSensor.getOpState()");		
+	temp_bonus += soft_sense->findTrans(-1, -1, -1, "*", "^TempSensor.getOpState()");	
+	self_bonus["seq_d_1"] = temp_bonus;
+	bonus += temp_bonus;
 			
 	// trigger:
 	// setTempOpState(op_state)
-	bonus += soft_sense->findTrans(-1, -1, 1, "*", "*");		
+	temp_bonus += soft_sense->findTrans(-1, -1, 1, "*", "*");
+	self_bonus["seq_d_2"] = temp_bonus;
+	bonus += temp_bonus;		
 
 	
 	// Temperature Sensor		
 	
 	// trigger:
 	// getOpState()
-	bonus += temp_sense->findTrans(-1, -1, 1, "*", "*");		
+	temp_bonus += temp_sense->findTrans(-1, -1, 1, "*", "*");		
+	self_bonus["seq_d_3"] = temp_bonus;
+	bonus += temp_bonus;
 	
 			
 	// action:
 	// op_state := 1
-	bonus += temp_sense->findTrans(-1, -1, -1, "*", "op_state:=1");		
+	temp_bonus += temp_sense->findTrans(-1, -1, -1, "*", "op_state:=1");		
+	self_bonus["seq_d_4"] = temp_bonus;
+	bonus += temp_bonus;
 
-	bonus += temp_sense->findTrans(-1, -1, -1, "*", "^SoftwareSensor.setTempOpState(op_state)");
+	temp_bonus += temp_sense->findTrans(-1, -1, -1, "*", "^SoftwareSensor.setTempOpState(op_state)");
+	self_bonus["seq_d_5"] = temp_bonus;
+	bonus += temp_bonus;
 	
 	// For each state diagram, look for the relevant transitions
 /*	if(getStateDiagram(0)->findTrans(-1, -1, -1, "*", "<null>")) {
@@ -193,7 +238,6 @@
 		bonus += 1.0;
 	}*/
 	
-	std::string x = getXMI();
 	
 //	bonus += formalizeModel();
 //	bonus += propertyN1();

Modified: branches/uml/source/main/cUMLModel.h
===================================================================
--- branches/uml/source/main/cUMLModel.h	2007-05-15 14:13:14 UTC (rev 1555)
+++ branches/uml/source/main/cUMLModel.h	2007-05-15 18:52:10 UTC (rev 1556)
@@ -41,7 +41,6 @@
 	double evaluateModel();
 	double checkForSequenceDiagram1();
 
-
 protected: 
 	static std::string xmi_begin;
 	std::string	xmi; // the XMI created by the model

Modified: branches/uml/source/main/cUMLStateDiagram.cc
===================================================================
--- branches/uml/source/main/cUMLStateDiagram.cc	2007-05-15 14:13:14 UTC (rev 1555)
+++ branches/uml/source/main/cUMLStateDiagram.cc	2007-05-15 18:52:10 UTC (rev 1556)
@@ -391,7 +391,23 @@
 
 }
 
+bool cUMLStateDiagram::currTrans(int orig, int dest, std::string tr, std::string gu, std::string act)
+{
 
+	if (((orig == -1) || (orig == getOrigStateIndex())) &&
+		((dest == -1) || (dest == getDestStateIndex())) && 
+		((tr == "*") || (tr == triggers[getTriggerIndex()].label)) &&
+		((gu == "*") || (gu == getGuard())) &&
+		((act == "*") || (act == getAction()))) { 
+
+			return true;
+	}
+	
+	return false;
+
+}
+
+
 int cUMLStateDiagram::numStates()
 {
 	return states.size();

Modified: branches/uml/source/main/cUMLStateDiagram.h
===================================================================
--- branches/uml/source/main/cUMLStateDiagram.h	2007-05-15 14:13:14 UTC (rev 1555)
+++ branches/uml/source/main/cUMLStateDiagram.h	2007-05-15 18:52:10 UTC (rev 1556)
@@ -64,7 +64,9 @@
   bool findTrans(int, int, int, std::string, std::string) ;
   bool findTrans(int, int, std::string, std::string, std::string);
   bool findTransLabel(transition_label); // find a specific transition label
+  bool currTrans(int, int, std::string, std::string, std::string);
 
+
   template <typename T>
   bool absoluteMoveIndex (T x, int &y, int z);
   




More information about the Avida-cvs mailing list