[Avida-SVN] r1544 - in branches/uml: Avida.xcodeproj source/cpu source/main source/tools

hjg at myxo.css.msu.edu hjg at myxo.css.msu.edu
Fri May 11 19:34:28 PDT 2007


Author: hjg
Date: 2007-05-11 22:34:27 -0400 (Fri, 11 May 2007)
New Revision: 1544

Modified:
   branches/uml/Avida.xcodeproj/project.pbxproj
   branches/uml/source/cpu/cHardwareCPU.cc
   branches/uml/source/main/cAvidaConfig.h
   branches/uml/source/main/cDeme.cc
   branches/uml/source/main/cDeme.h
   branches/uml/source/main/cGermline.h
   branches/uml/source/main/cOrganism.h
   branches/uml/source/main/cPopulation.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
   branches/uml/source/tools/cMerit.h
Log:
Enabled each deme to have a UML model where each organism has a state diagram. 


Modified: branches/uml/Avida.xcodeproj/project.pbxproj
===================================================================
--- branches/uml/Avida.xcodeproj/project.pbxproj	2007-05-11 18:41:22 UTC (rev 1543)
+++ branches/uml/Avida.xcodeproj/project.pbxproj	2007-05-12 02:34:27 UTC (rev 1544)
@@ -14,13 +14,16 @@
 		3EC9C9490BEB96CB0046545F /* cUMLModel.cc in Sources */ = {isa = PBXBuildFile; fileRef = 3EC9C9480BEB96CB0046545F /* cUMLModel.cc */; };
 		3EC9C9700BEB97D20046545F /* cUMLStateDiagram.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 3EC9C96F0BEB97D20046545F /* cUMLStateDiagram.h */; };
 		3EC9C9980BEB99220046545F /* cUMLStateDiagram.cc in Sources */ = {isa = PBXBuildFile; fileRef = 3EC9C9970BEB99220046545F /* cUMLStateDiagram.cc */; };
+		3EC9D2940BF4BB530046545F /* cUMLClassDiagram.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 3EC9D2930BF4BB530046545F /* cUMLClassDiagram.h */; };
+		3EC9D3C90BF50D3C0046545F /* cUMLStateDiagram.cc in Sources */ = {isa = PBXBuildFile; fileRef = 3EC9C9970BEB99220046545F /* cUMLStateDiagram.cc */; };
+		3EC9D3CA0BF50D3E0046545F /* cUMLModel.cc in Sources */ = {isa = PBXBuildFile; fileRef = 3EC9C9480BEB96CB0046545F /* cUMLModel.cc */; };
+		3EC9D3D90BF511B00046545F /* avida in CopyFiles */ = {isa = PBXBuildFile; fileRef = DCC3164D07626CF3008F7A48 /* avida */; };
 		4233358A0BC067E3000DF681 /* cHardwareGX.cc in Sources */ = {isa = PBXBuildFile; fileRef = 423335880BC067E3000DF681 /* cHardwareGX.cc */; };
 		7005A70409BA0FA90007E16E /* cTestCPUInterface.cc in Sources */ = {isa = PBXBuildFile; fileRef = 7005A70209BA0FA90007E16E /* cTestCPUInterface.cc */; };
 		7005A70609BA0FA90007E16E /* cTestCPUInterface.cc in Sources */ = {isa = PBXBuildFile; fileRef = 7005A70209BA0FA90007E16E /* cTestCPUInterface.cc */; };
 		7005A70809BA0FA90007E16E /* cTestCPUInterface.cc in Sources */ = {isa = PBXBuildFile; fileRef = 7005A70209BA0FA90007E16E /* cTestCPUInterface.cc */; };
 		700E2996085A1F6000CF158A /* avida in CopyFiles */ = {isa = PBXBuildFile; fileRef = DCC3164D07626CF3008F7A48 /* avida */; };
 		700E2AF8085DE50C00CF158A /* avida.cc in Sources */ = {isa = PBXBuildFile; fileRef = DCC3109C0762539E008F7A48 /* avida.cc */; };
-		700E2B87085DE54400CF158A /* avida-viewer in CopyFiles */ = {isa = PBXBuildFile; fileRef = 700E2B83085DE50C00CF158A /* avida-viewer */; };
 		7013846209028B3E0087ED2E /* cAvidaConfig.cc in Sources */ = {isa = PBXBuildFile; fileRef = 7013846009028B3E0087ED2E /* cAvidaConfig.cc */; };
 		7013846409028B3E0087ED2E /* cAvidaConfig.cc in Sources */ = {isa = PBXBuildFile; fileRef = 7013846009028B3E0087ED2E /* cAvidaConfig.cc */; };
 		701D915D094B864A008B845F /* cFallbackWorldDriver.cc in Sources */ = {isa = PBXBuildFile; fileRef = 701D915C094B864A008B845F /* cFallbackWorldDriver.cc */; };
@@ -406,7 +409,7 @@
 			dstPath = work;
 			dstSubfolderSpec = 16;
 			files = (
-				700E2B87085DE54400CF158A /* avida-viewer in CopyFiles */,
+				3EC9D3D90BF511B00046545F /* avida in CopyFiles */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
@@ -433,6 +436,7 @@
 				70B1A75A0B7E431F00067486 /* experimental.org in CopyFiles */,
 				3EC9C9330BEB95320046545F /* cUMLModel.h in CopyFiles */,
 				3EC9C9700BEB97D20046545F /* cUMLStateDiagram.h in CopyFiles */,
+				3EC9D2940BF4BB530046545F /* cUMLClassDiagram.h in CopyFiles */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
@@ -465,6 +469,7 @@
 		3EC9C9480BEB96CB0046545F /* cUMLModel.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = cUMLModel.cc; sourceTree = "<group>"; };
 		3EC9C96F0BEB97D20046545F /* cUMLStateDiagram.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cUMLStateDiagram.h; sourceTree = "<group>"; };
 		3EC9C9970BEB99220046545F /* cUMLStateDiagram.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = cUMLStateDiagram.cc; sourceTree = "<group>"; };
+		3EC9D2930BF4BB530046545F /* cUMLClassDiagram.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cUMLClassDiagram.h; sourceTree = "<group>"; };
 		4201F39A0BE187F6006279B9 /* cTopology.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cTopology.h; sourceTree = "<group>"; };
 		423335880BC067E3000DF681 /* cHardwareGX.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = cHardwareGX.cc; sourceTree = "<group>"; };
 		423335890BC067E3000DF681 /* cHardwareGX.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cHardwareGX.h; sourceTree = "<group>"; };
@@ -1448,6 +1453,7 @@
 				70B0868308F49E9700FC65FE /* cOrganism.h */,
 				3EC9C9970BEB99220046545F /* cUMLStateDiagram.cc */,
 				3EC9C96F0BEB97D20046545F /* cUMLStateDiagram.h */,
+				3EC9D2930BF4BB530046545F /* cUMLClassDiagram.h */,
 				3EC9C9480BEB96CB0046545F /* cUMLModel.cc */,
 				3EC9C9320BEB95320046545F /* cUMLModel.h */,
 				70B0869C08F49F4800FC65FE /* cPhenotype.cc */,
@@ -1836,7 +1842,9 @@
 			isa = PBXSourcesBuildPhase;
 			buildActionMask = 2147483647;
 			files = (
+				3EC9D3CA0BF50D3E0046545F /* cUMLModel.cc in Sources */,
 				700E2AF8085DE50C00CF158A /* avida.cc in Sources */,
+				3EC9D3C90BF50D3C0046545F /* cUMLStateDiagram.cc in Sources */,
 				70C1EF4A08C393BA00F50912 /* cCodeLabel.cc in Sources */,
 				70C1EF5A08C3948C00F50912 /* cCPUMemory.cc in Sources */,
 				70C1EF6308C3954700F50912 /* cCPUStack.cc in Sources */,

Modified: branches/uml/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/uml/source/cpu/cHardwareCPU.cc	2007-05-11 18:41:22 UTC (rev 1543)
+++ branches/uml/source/cpu/cHardwareCPU.cc	2007-05-12 02:34:27 UTC (rev 1544)
@@ -3876,6 +3876,8 @@
 
 bool cHardwareCPU::Inst_Next(cAvidaContext& ctx) 
 {
+	if(organism->GetCellID()==-1) return false;
+
 	// by default, this instruction increments the triggers vector index
 	
 	int reg_used = FindModifiedRegister(REG_AX);
@@ -3913,6 +3915,8 @@
  
 bool cHardwareCPU::Inst_Prev(cAvidaContext& ctx)
 {
+	if(organism->GetCellID()==-1) return false;
+
 	int reg_used = FindModifiedRegister(REG_AX);
 	
 	int jump_amount = -1;
@@ -3948,6 +3952,8 @@
 
 bool cHardwareCPU::Inst_JumpIndex(cAvidaContext& ctx)
 {
+	if(organism->GetCellID()==-1) return false;
+
 	const int reg_used = FindModifiedRegister(REG_AX);
 	const int reg_jump = FindModifiedRegister(REG_BX);
 	int jump_amount = GetRegister(reg_jump);
@@ -3984,6 +3990,8 @@
 
 bool cHardwareCPU::Inst_JumpDist(cAvidaContext& ctx)
 {
+	if(organism->GetCellID()==-1) return false;
+	
 	const int reg_used = FindModifiedRegister(REG_AX);
 	ReadLabel();
 	int jump_amount = GetLabel().AsInt(NUM_NOPS);
@@ -4022,6 +4030,8 @@
 
 bool cHardwareCPU::Inst_First(cAvidaContext& ctx) 
 {
+	if(organism->GetCellID()==-1) return false;
+	
 	// by default, this instruction increments the triggers vector index
 	
 	int reg_used = FindModifiedRegister(REG_AX);
@@ -4059,6 +4069,8 @@
 
 bool cHardwareCPU::Inst_Last(cAvidaContext& ctx) 
 {
+	if(organism->GetCellID()==-1) return false;
+	
 	// by default, this instruction increments the triggers vector index
 	
 	int reg_used = FindModifiedRegister(REG_AX);
@@ -4097,22 +4109,30 @@
 
 bool cHardwareCPU::Inst_AddTransitionLabel(cAvidaContext& ctx)
 {
+	if(organism->GetCellID()==-1) return false;
+
 	return organism->getStateDiagram()->addTransitionLabel();
 //	return true;
 }
 
 bool cHardwareCPU::Inst_AddState(cAvidaContext& ctx)
 {
+	if(organism->GetCellID()==-1) return false;
+
 	return organism->getStateDiagram()->addState();
 }
 
 bool cHardwareCPU::Inst_AddTransition(cAvidaContext& ctx)
 {
+	if(organism->GetCellID()==-1) return false;
+
 	return organism->getStateDiagram()->addTransition();
 }
 
 bool cHardwareCPU::Inst_AddTransitionTotal(cAvidaContext& ctx)
 {
+	if(organism->GetCellID()==-1) return false;
+
 	return organism->getStateDiagram()->addTransitionTotal();
 }
 

Modified: branches/uml/source/main/cAvidaConfig.h
===================================================================
--- branches/uml/source/main/cAvidaConfig.h	2007-05-11 18:41:22 UTC (rev 1543)
+++ branches/uml/source/main/cAvidaConfig.h	2007-05-12 02:34:27 UTC (rev 1544)
@@ -210,15 +210,15 @@
   // Deme & germline group.
   CONFIG_ADD_GROUP(DEME_GROUP, "Demes and Germlines");
   CONFIG_ADD_VAR(NUM_DEMES, int, 1, "Number of independent groups in the population.");
-  CONFIG_ADD_VAR(DEME_ORGS_ARE_STATIC, int, 0, "Whether the organisms remain the same throughout the lifetime of the deme. 0=no");
+//  CONFIG_ADD_VAR(DEME_ORGS_ARE_STATIC, int, 0, "Whether the organisms remain the same throughout the lifetime of the deme. 0=no");
   CONFIG_ADD_VAR(DEMES_USE_GERMLINE, int, 0, "Whether demes use a distinct germline; 0=off");
   CONFIG_ADD_VAR(DEMES_HAVE_MERIT, int, 0, "Whether demes have merit; 0=no");
   CONFIG_ADD_VAR(GERMLINE_COPY_MUT, double, 0.0075, "Prob. of copy mutations occuring during\ngermline replication.");
   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(DEMES_USE_UML_MOD, int, 0, "Whether the demes manipulate UML models; 0=off");
   
-  
   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");
   CONFIG_ADD_VAR(PREFER_EMPTY, int, 1, "Give empty cells preference in offsping placement?");

Modified: branches/uml/source/main/cDeme.cc
===================================================================
--- branches/uml/source/main/cDeme.cc	2007-05-11 18:41:22 UTC (rev 1543)
+++ branches/uml/source/main/cDeme.cc	2007-05-12 02:34:27 UTC (rev 1544)
@@ -43,6 +43,9 @@
   birth_count = 0;
   org_count = 0;
   _germlines.resize(cell_ids.GetSize());
+  
+  // Initialize the UML model with 1 state diagram per organism.
+  umlMod.resetStateDiagrams(cell_ids.GetSize());
 
   // 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-11 18:41:22 UTC (rev 1543)
+++ branches/uml/source/main/cDeme.h	2007-05-12 02:34:27 UTC (rev 1544)
@@ -67,7 +67,7 @@
 	
   //! Replaces this deme's germline.
    //void ReplaceGermline(const cGermline& germline);
-    void SetGermlines(std::vector<cGermline>::iterator, std::vector<cGermline>::iterator);
+  void SetGermlines(std::vector<cGermline>::iterator, std::vector<cGermline>::iterator);
 
   
   // -= Update support =-

Modified: branches/uml/source/main/cGermline.h
===================================================================
--- branches/uml/source/main/cGermline.h	2007-05-11 18:41:22 UTC (rev 1543)
+++ branches/uml/source/main/cGermline.h	2007-05-12 02:34:27 UTC (rev 1544)
@@ -4,16 +4,20 @@
 #include <vector>
 
 #include "cGenome.h"
+#include "cMerit.h"
 
-
 class cGermline {
 public:
 	cGenome& GetLatest() { return _germline.back(); }
 	void Add(const cGenome& genome) { _germline.push_back(genome); }
 	unsigned int Size() const { return _germline.size(); }
+  
+  const cMerit& GetMerit() { return _merit; }
+  void UpdateMerit(double v) { _merit = v; }
 
 protected:
 	std::vector<cGenome> _germline;
+  cMerit _merit;
 };
 
 #endif

Modified: branches/uml/source/main/cOrganism.h
===================================================================
--- branches/uml/source/main/cOrganism.h	2007-05-11 18:41:22 UTC (rev 1543)
+++ branches/uml/source/main/cOrganism.h	2007-05-12 02:34:27 UTC (rev 1544)
@@ -128,7 +128,7 @@
   bool m_is_running;       // Does this organism have the CPU?
   
   // UML
-  cUMLStateDiagram* sd;
+  cUMLStateDiagram* m_sd;
   
   class cNetSupport
   {
@@ -288,7 +288,8 @@
   
   // UML
   void modelCheck(cAvidaContext& ctx);
-  cUMLStateDiagram* getStateDiagram() { return sd; }
+  cUMLStateDiagram* getStateDiagram() { return m_sd; }
+  void setStateDiagram (cUMLStateDiagram* sd) { m_sd = sd; }
   
   
 };

Modified: branches/uml/source/main/cPopulation.cc
===================================================================
--- branches/uml/source/main/cPopulation.cc	2007-05-11 18:41:22 UTC (rev 1543)
+++ branches/uml/source/main/cPopulation.cc	2007-05-12 02:34:27 UTC (rev 1544)
@@ -233,6 +233,7 @@
   
   tArray<cOrganism*> child_array;
   tArray<cMerit> merit_array;
+
   
   // Update the parent's phenotype.
   // This needs to be done before the parent goes into the birth chamber
@@ -287,6 +288,20 @@
   // If we're not about to kill the parent, do some extra work on it.
   if (parent_alive == true) {
     schedule->Adjust(parent_cell.GetID(), parent_phenotype.GetMerit());
+	
+	// We're going to try something a little different here, and also take into
+    // account a per-germline merit, if we're configured to do such.
+    if(m_world->GetConfig().DEMES_USE_GERMLINE.Get() &&
+       m_world->GetConfig().DEMES_HAVE_MERIT.Get()) {
+	   
+	  cDeme& deme = deme_array[parent_cell.GetDemeID()]; 
+	  cGermline& germy = deme.begin()[parent_cell.GetID() - deme.GetCellID(0)];
+ 
+      schedule->Adjust(parent_cell.GetID(), parent_phenotype.GetMerit() + germy.GetMerit());
+    } else {
+      schedule->Adjust(parent_cell.GetID(), parent_phenotype.GetMerit());
+    }
+
     
     // In a local run, face the child toward the parent. 
     const int birth_method = m_world->GetConfig().BIRTH_METHOD.Get();
@@ -415,6 +430,16 @@
     deme_array[target_cell.GetDemeID()].IncOrgCount();
   }
   
+  // If we're using models in conjunction with demes, we need to 
+  // provide the organism with a pointer to its state diagram. 
+  if(m_world->GetConfig().DEMES_USE_UML_MOD.Get()) { 
+		// assign a state diagram to the organism
+		cDeme& deme = deme_array[target_cell.GetDemeID()];
+
+		cUMLStateDiagram* s = deme.getUMLModel()->getStateDiagram(target_cell.GetID() - deme.GetCellID(0));
+		in_organism->setStateDiagram(s);
+  }
+  
   // Statistics...
   m_world->GetStats().RecordBirth(target_cell.GetID(), in_genotype->GetID(),
                                   in_organism->GetPhenotype().ParentTrue());
@@ -889,7 +914,8 @@
         if(source_deme.GetAge() < m_world->GetConfig().MAX_DEME_AGE.Get()) continue;
         break;
       }
-	  case 4: { 
+	  //case 4: { 
+	  
 		// Replicate demes with working models 		
 		// What checks should be done prior to the model being checked? 
 			// model same as parent?
@@ -897,6 +923,13 @@
 		
 		// Need for a deme to have a UML model.
 		
+		// The models have 10 transitions
+/*		int num_trans = 0;
+		
+		for (int k=0; k< source_deme.GetSize(); k++) { 
+			num_trans += source_deme.getUMLModel()->getStateDiagram(k)->numTrans();
+		}
+		if (num_trans < 1) continue;
 		// Checks for working model: 
 			// 1) Should include the sequence diagram scenarios (if any)
 			// 2) Should satisfy the properties (if any)
@@ -907,7 +940,7 @@
 			
 			break;
 	  
-	  }
+	  }*/
 	  
 			default: {
 				cerr << "ERROR: Invalid replication trigger " << rep_trigger
@@ -984,14 +1017,32 @@
 	  std::vector<cGermline>::iterator s = source_deme.begin(); 
 	  std::vector<cGermline>::iterator t = target_deme.begin(); 
 	  
-			for (int i=0; i<source_deme.GetSize(); i++) {
-				KillOrganism(cell_array[source_deme.GetCellID(i)]);
-				InjectGenome(source_deme.GetCellID(i), (*s).GetLatest(), 0); 
-				InjectGenome(target_deme.GetCellID(i), (*t).GetLatest(), 0); 
-				s++;
-				t++;
-			}
+	  double merit = 0.0;
+	  
+	  merit += source_deme.getUMLModel()->evaluateModel();
+	  
+	  
+		for (int i=0; i<source_deme.GetSize(); i++) {
+			KillOrganism(cell_array[source_deme.GetCellID(i)]);
+			KillOrganism(cell_array[target_deme.GetCellID(i)]);
+				
+			// Inject new organisms
+			InjectGenome(source_deme.GetCellID(i), (*s).GetLatest(), 0); 
+			InjectGenome(target_deme.GetCellID(i), (*t).GetLatest(), 0);
+				
+			// update the merit of each cell
+			cell_array[source_deme.GetCellID(i)].GetOrganism()->UpdateMerit(merit);  
+			cell_array[target_deme.GetCellID(i)].GetOrganism()->UpdateMerit(merit);  
+				  
+			s++;
+			t++;
+		}
 			
+			/*		 // Setup the merit of both old and new individuals.
+		for (int pos = 0; pos < deme_size; pos += 2) {
+			cell_array[source_deme.GetCellID(pos)].GetOrganism()->UpdateMerit(merit);
+			cell_array[target_deme.GetCellID(pos)].GetOrganism()->UpdateMerit(merit);
+		}*/
 			
       
 /*			// Lineage label is wrong here; fix.
@@ -1040,8 +1091,8 @@
                                                           source_deme.GetHeight(), -1, -1)+offset]);
 		*/												  
 		}
+
 		
-		
 		// And reset both demes, in case they have any cleanup work to do.
 		source_deme.Reset();
 		target_deme.Reset();
@@ -2122,9 +2173,7 @@
   LineageSetupOrganism(GetCell(cell_id).GetOrganism(), 0, lineage_label);
   
   // If we're using germlines, then we have to be a little careful here.
-  bool temp = m_world->GetConfig().DEMES_USE_GERMLINE.Get();
-  int temp1 =m_world->GetConfig().NUM_DEMES.Get(); 
-	if(m_world->GetConfig().DEMES_USE_GERMLINE.Get()) {
+  if(m_world->GetConfig().DEMES_USE_GERMLINE.Get()) {
 		cDeme& deme = deme_array[GetCell(cell_id).GetDemeID()];
 		// index into germline vector 
 		// cell_id - deme.GetCellID(0)
@@ -2137,6 +2186,16 @@
 			germy.Add(GetCell(cell_id).GetOrganism()->GetGenome());
 		}
 	}  
+  // If we're using models in conjunction with demes, we need to 
+  // provide the organism with a pointer to its state diagram. 
+  if(m_world->GetConfig().DEMES_USE_UML_MOD.Get()) { 
+		// assign a state diagram to the organism
+		cDeme& deme = deme_array[GetCell(cell_id).GetDemeID()];
+
+		cUMLStateDiagram* s = deme.getUMLModel()->getStateDiagram(cell_id - deme.GetCellID(0));
+		GetCell(cell_id).GetOrganism()->setStateDiagram(s);
+  }
+	
 }
 
 void cPopulation::InjectParasite(const cCodeLabel& label, const cGenome& injected_code, int cell_id)

Modified: branches/uml/source/main/cUMLModel.cc
===================================================================
--- branches/uml/source/main/cUMLModel.cc	2007-05-11 18:41:22 UTC (rev 1543)
+++ branches/uml/source/main/cUMLModel.cc	2007-05-12 02:34:27 UTC (rev 1544)
@@ -26,7 +26,10 @@
 
 std::string cUMLModel::xmi_begin = loadFile("xmi_begin");
 std::string cUMLModel::xmi_end = loadFile("xmi_end");
+std::string cUMLModel::xmi_class1 = loadFile("class1_xmi");
+std::string cUMLModel::xmi_class2 = loadFile("class2_xmi");
 
+
 cUMLModel::cUMLModel()
 {
 	// initialize / seed UML model here
@@ -36,28 +39,214 @@
 {
 }
 
+cUMLStateDiagram* cUMLModel::getStateDiagram (int x) 
+{
+	// check to see whether this state diagram exists
+	if (x < state_diagrams.size()) { 
+		return (&(state_diagrams.begin()[x]));
+	}
+
+}
+
+cUMLClassDiagram* cUMLModel::getClassDiagram (int x) 
+{
+	// check to see whether this state diagram exists
+	if (x < class_diagrams.size()) { 
+		return (&(class_diagrams.begin()[x]));
+	}
+
+}
+
+void cUMLModel::resetStateDiagrams(int x)
+{ 
+	// reset the number of state diagrams.
+	state_diagrams.resize(x); 
+	class_diagrams.resize(x);
+	
+	seedDiagrams();
+	
+	
+}
+
+void cUMLModel::seedDiagrams()
+{
+  
+  // For the first state diagram... 
+  // Software Sensor
+  cUMLStateDiagram* soft_sense = getStateDiagram(0);
+	
+  // init triggers, guards, and actions
+  std::string trig_label = "<null>";
+  std::string trig_operation_id = "<null>";
+  soft_sense->addTrigger(trig_label, trig_operation_id);
+  trig_label = "setTempOpState";
+  trig_operation_id = "XDE-4437EBF1-9C42-4EB4-B7CF-415697B567CD";
+  soft_sense->addTrigger(trig_label, trig_operation_id);
+  trig_label = "setTempData";
+  trig_operation_id = "XDE-9517D6BA-8666-4A82-AFEA-62D60FE37B07";
+  soft_sense->addTrigger(trig_label, trig_operation_id);
+  soft_sense->addGuard("<null>");
+  soft_sense->addAction("<null>");
+  soft_sense->addAction("^TempSensor.getOpState()");
+  soft_sense->addAction("^TempSensor.getTempData()");
+  
+  
+  // null trans Init state to Idle state
+  soft_sense->absoluteJumpDestinationState(1);
+  soft_sense->addTransitionTotal();
+  
+  
+  // Temperature Sensor
+  cUMLStateDiagram* temp_sense = getStateDiagram(1);
+
+  // init triggers, guards, and actions
+  trig_label = "<null>";
+  trig_operation_id = "<null>";
+  temp_sense->addTrigger(trig_label, trig_operation_id);  
+  trig_label = "getOpState";
+  trig_operation_id = "XDE-73C1C501-493F-44F2-A70A-0C7BFA92160D";
+  temp_sense->addTrigger(trig_label, trig_operation_id);
+  trig_label = "getTempData";
+  trig_operation_id = "XDE-7C41CD1F-6E52-4E32-9C8E-999BA1919EC6";
+  temp_sense->addTrigger(trig_label, trig_operation_id);  
+  temp_sense->addGuard("<null>");
+  temp_sense->addAction("<null>");
+  temp_sense->addAction("^SoftwareSensor.setTempOpState(op_state)");
+  temp_sense->addAction("^SoftwareSensor.setTempData(data)");
+  temp_sense->addAction("op_state:=1");
+  temp_sense->addAction("op_state:=0");
+  temp_sense->addAction("data:=100");
+  temp_sense->addAction("data:=200");
+  temp_sense->addAction("data:=300");
+  
+  
+  
+}
+
+double cUMLModel::evaluateModel()
+{
+	double bonus = 0.0;
+		// 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. 
+
+
+	return bonus;
+}
+
+
+double cUMLModel::checkForSequenceDiagram1()
+{
+	double 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();
+	if (nt <= 10) { 
+		bonus += nt;
+	} else {
+		bonus += 10;
+	}
+	
+
+				
+	// Software Sensor
+	
+	// action: 
+	// TempSensor.getOpState()
+	bonus += soft_sense->findTrans(-1, -1, -1, "*", "^TempSensor.getOpState()");		
+			
+	// trigger:
+	// setTempOpState(op_state)
+	bonus += soft_sense->findTrans(-1, -1, 1, "*", "*");		
+
+	
+	// Temperature Sensor		
+	
+	// trigger:
+	// getOpState()
+	bonus += temp_sense->findTrans(-1, -1, 1, "*", "*");		
+	
+			
+	// action:
+	// op_state := 1
+	bonus += temp_sense->findTrans(-1, -1, -1, "*", "op_state:=1");		
+
+	bonus += temp_sense->findTrans(-1, -1, -1, "*", "^SoftwareSensor.setTempOpState(op_state)");
+	
+	// For each state diagram, look for the relevant transitions
+/*	if(getStateDiagram(0)->findTrans(-1, -1, -1, "*", "<null>")) {
+		bonus += 1.0;
+	}
+	if(getStateDiagram(1)->findTrans(-1, -1, -1, "*", "<null>")) {
+		bonus += 1.0;
+	}	
+		if(getStateDiagram(2)->findTrans(-1, -1, -1, "*", "<null>")) {
+		bonus += 1.0;
+	}*/
+	
+	std::string x = getXMI();
+	
+//	bonus += formalizeModel();
+//	bonus += propertyN1();
+
+	return bonus;
+}
+
+void cUMLModel::printXMI()
+{
+	xmi = "";
+//	int v;
+	
+	xmi = xmi_begin; 
+	
+	xmi += xmi_class1;
+	xmi += state_diagrams[0].getXMI();
+	xmi += xmi_class2;
+	xmi += state_diagrams[1].getXMI();
+
+	xmi += xmi_end;
+	
+}
+
 std::string cUMLModel::getXMI()
 {
 	std::string x;
-	int v;
+//	int v;
 	
 	x = xmi_begin; 
 	
+	x += xmi_class1;
+	x += state_diagrams[0].getXMI();
+	x += xmi_class2;
+	x += state_diagrams[1].getXMI();
+	
+	
+	
 	// get the xmi for each state diagram
-	for (v = 0; v < state_diagrams.size(); ++v) { 
-		state_diagrams[v].printXMI();
-		x+=state_diagrams[v].getXMI();
-	}
+//	for (v = 0; v < state_diagrams.size(); ++v) { 
+//		state_diagrams[v].printXMI();
+//		x+=state_diagrams[v].getXMI();
+//	}
 	
 	x += xmi_end;
-
+	
+	return x;
 }
 
-int cUMLModel::formalizeModel() const
+double cUMLModel::formalizeModel() 
 {
-	std::string temp;
+	printXMI();
+	std::string temp = xmi;
 
-	temp = xmi;
 
 /*(	if (temp == organism->getParentXMI()) {
 		ctx.task_success_complete += organism->getParentBonusInfo("hydra");
@@ -144,9 +333,9 @@
 }
 
 
-int cUMLModel::checkProperty(const std::string& neverclaimFile) const {
+double cUMLModel::checkProperty(const std::string& neverclaimFile) const {
 //	m_world->GetStats().SpinAttempt();
-	int status=0;
+	double status=0;
 	std::string cmd = "cat " + neverclaimFile + " >> tmp.pr && ./spin -a tmp.pr &> /dev/null";
 	if(system(cmd.c_str())!=0) return 0;
 //	m_world->GetStats().SpinPassed();
@@ -159,17 +348,17 @@
 	
 	
 	std::ostringstream strstrm;
-//	strstrm << "cp tmp.xmi " << m_world->GetStats().GetUpdate() << "." << organism->GetID();
-//	strstrm << ".xml";	
+	strstrm << "cp tmp.xmi "; // << m_world->GetStats().GetUpdate() << "." << organism->GetID();
+	strstrm << "tmp.xml";	
 	if(system(strstrm.str().c_str())!=0) return 0;
 			
 //	m_world->GetStats().PanPassed();
 	return 3;
 }
 
-int cUMLModel::propertyN1() const {
+double cUMLModel::propertyN1() const {
 	std::string temp = xmi;
-	int temp1 = 0;
+	double temp1 = 0;
 
 /*	
 	if (temp == organism->getParentXMI()) { 

Modified: branches/uml/source/main/cUMLModel.h
===================================================================
--- branches/uml/source/main/cUMLModel.h	2007-05-11 18:41:22 UTC (rev 1543)
+++ branches/uml/source/main/cUMLModel.h	2007-05-12 02:34:27 UTC (rev 1544)
@@ -2,6 +2,7 @@
 #define _C_UMLMODEL_H_
 
 #include "cUMLStateDiagram.h"
+#include "cUMLClassDiagram.h"
 
 #include <string>
 #include <iostream>
@@ -17,24 +18,36 @@
 	cUMLModel();
 	~cUMLModel();
 	std::string getXMI(); // get the XMI version of the model
-	int formalizeModel() const; // formalize the model using Hydra
-	int checkProperty(const std::string& neverclaimFile) const; // check for property satisfaction using Spin
-	int propertyN1() const; // check for property N1
+	void printXMI();
+	double formalizeModel(); // formalize the model using Hydra
+	double checkProperty(const std::string& neverclaimFile) const; // check for property satisfaction using Spin
+	double propertyN1() const; // check for property N1
 	
+	void resetStateDiagrams (int);  
+	void seedDiagrams();
+	
 	// Track bonus info for model
 	std::map <std::string, double> getBonus() {return self_bonus;}
 	void setBonusInfo(std::string x, double y) {self_bonus[x] = y;}
 	
+	cUMLStateDiagram* getStateDiagram (int); 
+	cUMLClassDiagram* getClassDiagram (int);
+	
 	// Determine the "fitness" of the model
 	// does the model satisfy the sequence diagrams? 
 	// does the model meet the properties? 
+	double evaluateModel();
+	double checkForSequenceDiagram1();
 
 
 protected: 
 	static std::string xmi_begin;
 	std::string	xmi; // the XMI created by the model
 	static std::string xmi_end;
+	static std::string xmi_class1;
+	static std::string xmi_class2;
 	std::vector<cUMLStateDiagram> state_diagrams;
+	std::vector<cUMLClassDiagram> class_diagrams;
 	
 	// UML - Track information about the bonus received for this model.
 	std::map <std::string, double> self_bonus;											

Modified: branches/uml/source/main/cUMLStateDiagram.cc
===================================================================
--- branches/uml/source/main/cUMLStateDiagram.cc	2007-05-11 18:41:22 UTC (rev 1543)
+++ branches/uml/source/main/cUMLStateDiagram.cc	2007-05-12 02:34:27 UTC (rev 1544)
@@ -1,5 +1,85 @@
 #include "cUMLStateDiagram.h"
 
+cUMLStateDiagram::cUMLStateDiagram()
+{
+
+  // initialize / seed UML state diagram here
+  orig_state_index = 0;
+  dest_state_index = 0;
+  trans_label_index = 0;
+  trigger_index = 0;
+  guard_index = 0;
+  action_index = 0;
+  xmi = "";
+/*	
+  trigger_info trig;
+  trig.label = "<null>";
+  trig.operation_id = "<null>";
+  triggers.push_back(trig);
+  trig.label = "setTempOpState";
+  trig.operation_id = "XDE-4437EBF1-9C42-4EB4-B7CF-415697B567CD";
+  triggers.push_back(trig);
+  trig.label = "setTempData";
+  trig.operation_id = "XDE-9517D6BA-8666-4A82-AFEA-62D60FE37B07";
+  triggers.push_back(trig);
+  guards.push_back("<null>");
+  actions.push_back("<null>");
+  actions.push_back("^TempSensor.getOpState()");
+  actions.push_back("^TempSensor.getTempData()");
+ */
+   
+  // initialize w/ 10 states
+  
+  state s;
+  for (int i=0; i<11; i++) {
+	s.identifier = i;
+	s.num_incoming = 0;
+	s.num_outgoing = 0;
+	states.push_back(s);
+  }
+   
+/*
+  // initialize transitions
+  transition t;
+ 
+  
+  // State 0->1
+  t.orig_state = 0;
+  t.dest_state = 1;
+  states[0].num_outgoing += 1;
+  states[1].num_incoming += 1;  
+  t.trans.trigger = 0;
+  t.trans.guard = "<null>";
+  t.trans.action = "<null>";
+  transitions.push_back(t);
+
+  // State 1->2
+  t.orig_state = 1;
+  t.dest_state = 2;
+  states[1].num_outgoing += 1;
+  states[2].num_incoming += 1; 
+  t.trans.trigger = 0;
+  t.trans.guard = "<null>";
+  t.trans.action = "^TempSensor.getTempData()";
+  transitions.push_back(t);
+  
+  // State 2->1
+  t.orig_state = 2;
+  t.dest_state = 1;
+  states[2].num_outgoing += 1;
+  states[1].num_incoming += 1; 
+  t.trans.trigger =  2;
+  t.trans.guard = "<null>";
+  t.trans.action = "<null>";
+  transitions.push_back(t);
+*/  
+}
+
+cUMLStateDiagram::~cUMLStateDiagram()
+{
+}
+
+
 bool cUMLStateDiagram::findTransLabel(transition_label t) { 
 	for(std::vector<transition_label>::iterator i=transition_labels.begin(); i!=transition_labels.end(); ++i){
 		if ((i->trigger == t.trigger) && (i->guard == t.guard) && (i->action == t.action)) {
@@ -10,6 +90,20 @@
 	return false;
 }
 
+bool cUMLStateDiagram::findTrans(int orig, int dest, std::string tr, std::string gu, std::string act) 
+{
+	int tracker = 0;
+	
+	for(std::vector<trigger_info>::iterator i=triggers.begin(); i!=triggers.end(); i++) {
+		if (tr == i->label) { 
+			return findTrans(orig, dest, tracker, gu, act );
+		}
+		tracker++;
+	}
+
+	return false;
+}
+
 bool cUMLStateDiagram::findTrans(int orig, int dest, int trig, std::string gu, std::string act) 
 {
 	// the wild cards for there are 
@@ -173,6 +267,29 @@
 	return true;
 }
 
+bool cUMLStateDiagram::addTrigger(std::string op_id, std::string lab) 
+{
+	trigger_info t;
+	t.operation_id = op_id;
+	t.label = lab;
+	
+	triggers.push_back(t);
+	
+	return true;
+}
+
+bool cUMLStateDiagram::addGuard(std::string gu) 
+{
+	guards.push_back(gu);
+	return true;
+}
+
+bool cUMLStateDiagram::addAction(std::string act)
+{
+	actions.push_back(act);
+	return true;
+}
+
 bool cUMLStateDiagram::addTransitionLabel()
 {
 	transition_label t;
@@ -255,9 +372,14 @@
     if (findTrans(t.orig_state, t.dest_state, t.trans.trigger, t.trans.guard, t.trans.action)) {
 		return false;
 	}
+	
+	int q1 = numTrans();
 
+
 	transitions.push_back(t);
 	
+	int q = numTrans();
+	
 	// reset all indices
 	orig_state_index = 0;
 	dest_state_index = 0;
@@ -296,6 +418,7 @@
 
 std::string cUMLStateDiagram::getXMI()
 {
+	printXMI();
 	return (xmi);
 }
 

Modified: branches/uml/source/main/cUMLStateDiagram.h
===================================================================
--- branches/uml/source/main/cUMLStateDiagram.h	2007-05-11 18:41:22 UTC (rev 1543)
+++ branches/uml/source/main/cUMLStateDiagram.h	2007-05-12 02:34:27 UTC (rev 1544)
@@ -52,6 +52,9 @@
 	
 public:
 
+  cUMLStateDiagram();
+  ~cUMLStateDiagram();
+
   void printXMI();	 // print the XMI version of the model
   std::string getXMI (); // get the xmi string (including beginning & end read from file.)
   std::string StringifyAnInt(int);
@@ -59,6 +62,7 @@
   int numTrans();
 
   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
 
   template <typename T>
@@ -113,6 +117,9 @@
   bool addTransitionLabel();
   bool addTransition();
   bool addTransitionTotal();
+  bool addTrigger(std::string, std::string);
+  bool addGuard(std::string);
+  bool addAction(std::string);
   // END UML functions
 
 };

Modified: branches/uml/source/tools/cMerit.h
===================================================================
--- branches/uml/source/tools/cMerit.h	2007-05-11 18:41:22 UTC (rev 1543)
+++ branches/uml/source/tools/cMerit.h	2007-05-12 02:34:27 UTC (rev 1544)
@@ -61,6 +61,13 @@
 
   void operator=(double _merit) { UpdateValue(_merit); }
   void operator+=(const cMerit & _m){ UpdateValue(value + _m.GetDouble()); }
+  
+  //! Operator overload for this cMerit + that cMerit.
+  cMerit operator+(const cMerit& that) const {
+    cMerit r(*this);
+    r += that;
+    return r;
+  }
 
   int  operator>(const cMerit & _m)  const { return value >  _m.GetDouble(); }
   int  operator<(const cMerit & _m)  const { return value <  _m.GetDouble(); }




More information about the Avida-cvs mailing list