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

hjg at myxo.css.msu.edu hjg at myxo.css.msu.edu
Wed May 9 07:08:00 PDT 2007


Author: hjg
Date: 2007-05-09 10:07:59 -0400 (Wed, 09 May 2007)
New Revision: 1535

Modified:
   branches/uml/source/actions/PopulationActions.cc
   branches/uml/source/cpu/cHardwareCPU.cc
   branches/uml/source/cpu/cHardwareCPU.h
   branches/uml/source/main/cAvidaConfig.h
   branches/uml/source/main/cBirthChamber.cc
   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/cPopulation.cc
   branches/uml/source/main/cTaskLib.cc
   branches/uml/source/main/cUMLModel.cc
   branches/uml/source/main/cUMLModel.h
Log:
The beginning of infrastructure changes to enable a deme to construct a UML model comprising multiple state diagrams. Specifically, each organism modifies its own state diagram. 

1. Added deme replication event - uml-mod - which will evaluate the model constructed by the deme. 2. Added multiple germlines per deme to enable ALL of the organisms to be copied over for a replication event. 
3. Removed support for normal Avida runs to construct models... will have to be added back in at some point. 




Modified: branches/uml/source/actions/PopulationActions.cc
===================================================================
--- branches/uml/source/actions/PopulationActions.cc	2007-05-08 02:11:51 UTC (rev 1534)
+++ branches/uml/source/actions/PopulationActions.cc	2007-05-09 14:07:59 UTC (rev 1535)
@@ -1005,6 +1005,7 @@
     else if (in_trigger == "full_deme") m_rep_trigger = 1;
     else if (in_trigger == "corners") m_rep_trigger = 2;
     else if (in_trigger == "deme-age") m_rep_trigger = 3;
+	else if (in_trigger == "uml-mod") m_rep_trigger = 4;
     else {
       cString err("Unknown replication trigger '");
       err += in_trigger;

Modified: branches/uml/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/uml/source/cpu/cHardwareCPU.cc	2007-05-08 02:11:51 UTC (rev 1534)
+++ branches/uml/source/cpu/cHardwareCPU.cc	2007-05-09 14:07:59 UTC (rev 1535)
@@ -64,7 +64,10 @@
   static const cNOPEntryCPU s_n_array[] = {
     cNOPEntryCPU("nop-A", REG_AX),
     cNOPEntryCPU("nop-B", REG_BX),
-    cNOPEntryCPU("nop-C", REG_CX)
+    cNOPEntryCPU("nop-C", REG_CX), 
+	cNOPEntryCPU("nop-D", REG_DX),
+    cNOPEntryCPU("nop-E", REG_EX),
+    cNOPEntryCPU("nop-F", REG_FX)
   };
   
   static const tInstLibEntry<tMethod> s_f_array[] = {
@@ -76,6 +79,9 @@
     tInstLibEntry<tMethod>("nop-A", &cHardwareCPU::Inst_Nop, (nInstFlag::DEFAULT | nInstFlag::NOP), "No-operation instruction; modifies other instructions"),
     tInstLibEntry<tMethod>("nop-B", &cHardwareCPU::Inst_Nop, (nInstFlag::DEFAULT | nInstFlag::NOP), "No-operation instruction; modifies other instructions"),
     tInstLibEntry<tMethod>("nop-C", &cHardwareCPU::Inst_Nop, (nInstFlag::DEFAULT | nInstFlag::NOP), "No-operation instruction; modifies other instructions"),
+    tInstLibEntry<tMethod>("nop-D", &cHardwareCPU::Inst_Nop, (nInstFlag::DEFAULT | nInstFlag::NOP), "No-operation instruction; modifies other instructions"),
+    tInstLibEntry<tMethod>("nop-E", &cHardwareCPU::Inst_Nop, (nInstFlag::DEFAULT | nInstFlag::NOP), "No-operation instruction; modifies other instructions"),
+    tInstLibEntry<tMethod>("nop-F", &cHardwareCPU::Inst_Nop, (nInstFlag::DEFAULT | nInstFlag::NOP), "No-operation instruction; modifies other instructions"),
     
     tInstLibEntry<tMethod>("NULL", &cHardwareCPU::Inst_Nop, 0, "True no-operation instruction: does nothing"),
     tInstLibEntry<tMethod>("nop-X", &cHardwareCPU::Inst_Nop, 0, "True no-operation instruction: does nothing"),

Modified: branches/uml/source/cpu/cHardwareCPU.h
===================================================================
--- branches/uml/source/cpu/cHardwareCPU.h	2007-05-08 02:11:51 UTC (rev 1534)
+++ branches/uml/source/cpu/cHardwareCPU.h	2007-05-09 14:07:59 UTC (rev 1535)
@@ -85,10 +85,10 @@
 
 protected:
   // --------  Structure Constants  --------
-  static const int NUM_REGISTERS = 3;
+  static const int NUM_REGISTERS = 6;
   static const int NUM_HEADS = nHardware::NUM_HEADS >= NUM_REGISTERS ? nHardware::NUM_HEADS : NUM_REGISTERS;
   enum tRegisters { REG_AX = 0, REG_BX, REG_CX, REG_DX, REG_EX, REG_FX };
-  static const int NUM_NOPS = 3;
+  static const int NUM_NOPS = 6;
   
   // --------  Data Structures  --------
   struct cLocalThread

Modified: branches/uml/source/main/cAvidaConfig.h
===================================================================
--- branches/uml/source/main/cAvidaConfig.h	2007-05-08 02:11:51 UTC (rev 1534)
+++ branches/uml/source/main/cAvidaConfig.h	2007-05-09 14:07:59 UTC (rev 1535)
@@ -210,6 +210,7 @@
   // 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(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.");

Modified: branches/uml/source/main/cBirthChamber.cc
===================================================================
--- branches/uml/source/main/cBirthChamber.cc	2007-05-08 02:11:51 UTC (rev 1534)
+++ branches/uml/source/main/cBirthChamber.cc	2007-05-09 14:07:59 UTC (rev 1535)
@@ -165,8 +165,6 @@
     
   child_genotype->IncDeferAdjust();
 
-  // FOR UML branch - hjg
-  child_array[0]->setParentInfo(parent.getStateDiagram()->getXMI(), parent.getBonus());
 
   return true;
 }

Modified: branches/uml/source/main/cDeme.cc
===================================================================
--- branches/uml/source/main/cDeme.cc	2007-05-08 02:11:51 UTC (rev 1534)
+++ branches/uml/source/main/cDeme.cc	2007-05-09 14:07:59 UTC (rev 1535)
@@ -42,6 +42,7 @@
   cell_ids = in_cells;
   birth_count = 0;
   org_count = 0;
+  _germlines.resize(cell_ids.GetSize());
 
   // If width is negative, set it to the full number of cells.
   width = in_width;
@@ -83,6 +84,20 @@
 
 \todo Fix lineage labels in germlines.
 */
-void cDeme::ReplaceGermline(const cGermline& germline) {
+/*void cDeme::ReplaceGermline(const cGermline& germline) {
 	_germline = germline;
+}*/
+
+
+void cDeme::SetGermlines(std::vector<cGermline>::iterator b, std::vector<cGermline>::iterator e)
+{
+	_germlines.clear();
+	
+	for (std::vector<cGermline>::iterator i=b; i!=e; ++i) {
+		_germlines.push_back(*i);
+	}
+	
+	
 }
+
+

Modified: branches/uml/source/main/cDeme.h
===================================================================
--- branches/uml/source/main/cDeme.h	2007-05-08 02:11:51 UTC (rev 1534)
+++ branches/uml/source/main/cDeme.h	2007-05-09 14:07:59 UTC (rev 1535)
@@ -26,6 +26,7 @@
 #include "cGermline.h"
 #include "tArray.h"
 #include "cUMLModel.h"
+#include <vector>
 
 
 /*! Demes are groups of cells in the population that are somehow bound together
@@ -59,10 +60,15 @@
   bool IsFull() const { return org_count == cell_ids.GetSize(); }
   
   // -= Germline =-
-  //! Returns this deme's germline.
-  cGermline& GetGermline() { return _germline; }
+  //! Returns a vector of the deme's germlines.
+// orig --  cGermline& GetGermline() { return _germline; }
+  // vector<cGermline> GetGermLines() { return _germlines; }
+	
+	
   //! Replaces this deme's germline.
-  void ReplaceGermline(const cGermline& germline);
+   //void ReplaceGermline(const cGermline& germline);
+    void SetGermlines(std::vector<cGermline>::iterator, std::vector<cGermline>::iterator);
+
   
   // -= Update support =-
   //! Called once, at the end of every update.
@@ -74,6 +80,10 @@
   // UML Model functions
   cUMLModel* getUMLModel() { return &umlMod; }
   
+  std::vector<cGermline>::iterator begin() { return _germlines.begin(); }
+  std::vector<cGermline>::iterator end() { return _germlines.end(); }
+  // for(vector<cGermline>::iterator i=source_deme.begin(); i!=source_deme.end(); ++i)
+  
 private:
   tArray<int> cell_ids;
   int width; //!< Width of this deme.
@@ -81,8 +91,14 @@
   int org_count; //!< Number of organisms are currently in this deme.
   int _age; //!< Age of this deme, in updates.
   
-  cGermline _germline; //!< The germline for this deme, if used.
+  // cGermline _germline; //!< The germline for this deme, if used.
+  std::vector<cGermline> _germlines; //!< The germlines for this deme, if used
+  
+  
   cUMLModel umlMod; // !< The UML model for this deme, if used.
+  cUMLModel prevMod; // !< The previous (possibly parent) model for the deme, if used
+
+
 };
 
 #endif

Modified: branches/uml/source/main/cOrganism.cc
===================================================================
--- branches/uml/source/main/cOrganism.cc	2007-05-08 02:11:51 UTC (rev 1534)
+++ branches/uml/source/main/cOrganism.cc	2007-05-09 14:07:59 UTC (rev 1535)
@@ -68,7 +68,6 @@
   , m_max_executed(-1)
   , m_is_running(false)
   , m_net(NULL)
-  , parent_xmi("")
 {
   // Initialization of structures...
   m_hardware = m_world->GetHardwareManager().Create(this);

Modified: branches/uml/source/main/cOrganism.h
===================================================================
--- branches/uml/source/main/cOrganism.h	2007-05-08 02:11:51 UTC (rev 1534)
+++ branches/uml/source/main/cOrganism.h	2007-05-09 14:07:59 UTC (rev 1535)
@@ -144,13 +144,8 @@
   };
   cNetSupport* m_net;
 
-  // UML - Track information about the parent's model & their rewards for the model.
-  std::string parent_xmi;
-  std::map <std::string, double> parent_bonus;
-  std::map <std::string, double> self_bonus;
 
 
-
   cOrganism(); // @not_implemented
   cOrganism(const cOrganism&); // @not_implemented
   cOrganism& operator=(const cOrganism&); // @not_implemented
@@ -294,12 +289,6 @@
   // UML
   void modelCheck(cAvidaContext& ctx);
   cUMLStateDiagram* getStateDiagram() { return sd; }
-   void setParentInfo(std::string x,   std::map <std::string, double> pb) {parent_xmi = x; parent_bonus = pb;}
-  double getParentBonusInfo(std::string x) {return parent_bonus[x];}
-  std::map <std::string, double> getBonus() {return self_bonus;}
-  void setBonusInfo(std::string x, double y) {self_bonus[x] = y;}
-  std::string getParentXMI() { return parent_xmi; }
-
   
   
 };

Modified: branches/uml/source/main/cPopulation.cc
===================================================================
--- branches/uml/source/main/cPopulation.cc	2007-05-08 02:11:51 UTC (rev 1534)
+++ branches/uml/source/main/cPopulation.cc	2007-05-09 14:07:59 UTC (rev 1535)
@@ -843,6 +843,8 @@
 0: 'all'       - ...all non-empty demes in the population.
 1: 'full_deme' - ...demes that have been filled up.
 2: 'corners'   - ...demes with upper left and lower right corners filled.
+3: 'uml-mod'   - ...demes whose UML models are correct
+4: 'old'	   - ...replicate when demes get too old
 */
 
 void cPopulation::ReplicateDemes(int rep_trigger)
@@ -882,14 +884,16 @@
            cell_array[id2].IsOccupied() == false) continue;
 				break;
       }
-			case 3: {
-        // Replicate old demes.
+	  case 3: {
+        // Replicates old demes.
         if(source_deme.GetAge() < m_world->GetConfig().MAX_DEME_AGE.Get()) continue;
         break;
       }
-	  
 	  case 4: { 
-		// Replicate demes with working models:
+		// Replicate demes with working models 		
+		// What checks should be done prior to the model being checked? 
+			// model same as parent?
+			// model same as last time (dirty bit)
 		
 		// Need for a deme to have a UML model.
 		
@@ -901,7 +905,7 @@
 			// Should be awarded partial merit for satisfying parts of some scenarios or
 			// partially satisfying a property.
 			
-			
+			break;
 	  
 	  }
 	  
@@ -931,39 +935,66 @@
 		// Second, it could be an offspring of the source deme's germline, if the config
 		// option DEMES_USE_GERMLINE is set.
 		if(m_world->GetConfig().DEMES_USE_GERMLINE.Get()) {
+		
+		std::vector<cGermline> temp_germlines;
+		
+		// For each of the germs...
+		for(std::vector<cGermline>::iterator i=source_deme.begin(); i!=source_deme.end(); ++i){
 			// Get the latest germ from the source deme.
-			cGermline& source_germline = source_deme.GetGermline();
+			cGermline& source_germline = (*i);
 			cGenome& source_germ = source_germline.GetLatest();
       
-      // Now create the next germ by manually mutating the source.
-      // @refactor (strategy pattern)
-      cGenome next_germ(source_germ);
-      if(m_world->GetConfig().GERMLINE_COPY_MUT.Get() > 0) {
-        const cInstSet& instset = m_world->GetHardwareManager().GetInstSet();
-        cAvidaContext ctx(m_world->GetRandom());        
-        for(int i=0; i<next_germ.GetSize(); ++i) {
-          if(m_world->GetRandom().P(m_world->GetConfig().GERMLINE_COPY_MUT.Get())) {
-            next_germ[i] = instset.GetRandomInst(ctx);
-          }
-        }
-      }
+		  // Now create the next germ by manually mutating the source.
+		  // @refactor (strategy pattern)
+		  cGenome next_germ(source_germ);
+		  if(m_world->GetConfig().GERMLINE_COPY_MUT.Get() > 0) {
+			const cInstSet& instset = m_world->GetHardwareManager().GetInstSet();
+			cAvidaContext ctx(m_world->GetRandom());        
+			for(int i=0; i<next_germ.GetSize(); ++i) {
+			  if(m_world->GetRandom().P(m_world->GetConfig().GERMLINE_COPY_MUT.Get())) {
+				next_germ[i] = instset.GetRandomInst(ctx);
+			  }
+			}
+		   }
       
-			// Here we're adding the next_germ to the germline(s).  Note the
-      // config option to determine if we should update the source_germline
-      // as well.
-			target_deme.ReplaceGermline(source_germline);
-      cGermline& target_germline = target_deme.GetGermline();
-      target_germline.Add(next_germ);
-      if(m_world->GetConfig().GERMLINE_REPLACES_SOURCE.Get()) {
-        source_germline.Add(next_germ);
-      }
+		  // Here we're adding the next_germ to the germline(s).  Note the
+		  // config option to determine if we should update the source_germline
+		  // as well.
+		  //
+		  //target_deme.ReplaceGermline(source_germline);
+		  temp_germlines.push_back(source_germline);
+		  //cGermline& target_germline = target_deme.GetGermline();
+		  // use last element of the temp germlines as the germline
+		  cGermline& temp_germline = temp_germlines.back();
+		  temp_germline.Add(next_germ);
+		  if(m_world->GetConfig().GERMLINE_REPLACES_SOURCE.Get()) {
+			source_germline.Add(next_germ);
+		  }
       
+	  } // end do for all germlines
+	  
+	  // replace the target demes germline
+	  target_deme.SetGermlines(temp_germlines.begin(), temp_germlines.end());
+	  
       // Kill all the organisms in the source deme.
+	  // Inject organisms with the new germlines
+	  // Note for this to work:
+		// (1) the source deme and target deme must be the same size
+		// (2) there must be a germline for each cell...
+	  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++;
 			}
+			
+			
       
-			// Lineage label is wrong here; fix.
+/*			// Lineage label is wrong here; fix.
       if(m_world->GetConfig().GERMLINE_RANDOM_PLACEMENT.Get()) {
         InjectGenome(source_deme.GetCellID(m_world->GetRandom().GetInt(0, source_deme.GetSize()-1)),
                      source_germline.GetLatest(), 0);
@@ -1007,8 +1038,10 @@
 			cell_array[cell3_id].Rotate(cell_array[GridNeighbor(cell3_id-offset,
                                                           source_deme.GetWidth(),
                                                           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();
@@ -2089,10 +2122,19 @@
   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()) {
 		cDeme& deme = deme_array[GetCell(cell_id).GetDemeID()];
-		if(deme.GetGermline().Size()==0) {  
-			deme.GetGermline().Add(GetCell(cell_id).GetOrganism()->GetGenome());
+		// index into germline vector 
+		// cell_id - deme.GetCellID(0)
+		
+		
+		cGermline& germy = deme.begin()[cell_id - deme.GetCellID(0)];
+		if (germy.Size() == 0){
+		
+//		if(deme.GetGermline().Size()==0) {  
+			germy.Add(GetCell(cell_id).GetOrganism()->GetGenome());
 		}
 	}  
 }

Modified: branches/uml/source/main/cTaskLib.cc
===================================================================
--- branches/uml/source/main/cTaskLib.cc	2007-05-08 02:11:51 UTC (rev 1534)
+++ branches/uml/source/main/cTaskLib.cc	2007-05-09 14:07:59 UTC (rev 1535)
@@ -2731,12 +2731,13 @@
 	std::string temp;
 
 	temp = organism->getStateDiagram()->getXMI();
-
+/*
 	if (temp == organism->getParentXMI()) {
 		ctx.task_success_complete += organism->getParentBonusInfo("hydra");
 		organism->setBonusInfo("hydra", organism->getParentBonusInfo("hydra"));
 		return organism->getParentBonusInfo("hydra");
 	}
+	*/
 
 // Check for task success...	
 /*	if (ctx->task_failed == 0) {
@@ -2810,13 +2811,13 @@
 	// if there are no errors, return 0 from hydraulic.  otherwise, return non-zero.
 	if(status != 0) {
 //		ctx->task_failed = 0;
-		organism->setBonusInfo("hydra", 0.0); 
+//		organism->setBonusInfo("hydra", 0.0); 
 		return 0.0;
 	} else {
 	//	ctx->task_failed = ctx->task_failed && 1;
-		ctx.task_success_complete += 1;
-		m_world->GetStats().HydraPassed();
-		organism->setBonusInfo("hydra", 1.0); 
+//		ctx.task_success_complete += 1;
+//		m_world->GetStats().HydraPassed();
+//		organism->setBonusInfo("hydra", 1.0); 
 		return 1.0;
 	}
 	
@@ -2852,11 +2853,12 @@
 	std::string temp = organism->getStateDiagram()->getXMI();
 	double temp1 = 0.0;
 	
-	if (temp == organism->getParentXMI()) { 
+/*	if (temp == organism->getParentXMI()) { 
 		ctx.task_success_complete += organism->getParentBonusInfo("spinn1");
 		organism->setBonusInfo("spinn1", organism->getParentBonusInfo("spinn1"));
 		return organism->getParentBonusInfo("spinn1");
 	}
+*/	
 	
 	// check if the trigger is present
 	if (organism->getStateDiagram()->findTrans(-1,-1,1,"*","*")){
@@ -2868,7 +2870,7 @@
 		} 
 	}
 	
-	organism->setBonusInfo("spinn1", temp1); 
+//	organism->setBonusInfo("spinn1", temp1); 
 	return temp1;
 }
 

Modified: branches/uml/source/main/cUMLModel.cc
===================================================================
--- branches/uml/source/main/cUMLModel.cc	2007-05-08 02:11:51 UTC (rev 1534)
+++ branches/uml/source/main/cUMLModel.cc	2007-05-09 14:07:59 UTC (rev 1535)
@@ -2,6 +2,7 @@
 
 
 #include <iomanip>
+#include <errno.h>
 
 
 using namespace std;
@@ -26,6 +27,15 @@
 std::string cUMLModel::xmi_begin = loadFile("xmi_begin");
 std::string cUMLModel::xmi_end = loadFile("xmi_end");
 
+cUMLModel::cUMLModel()
+{
+	// initialize / seed UML model here
+}
+
+cUMLModel::~cUMLModel()
+{
+}
+
 std::string cUMLModel::getXMI()
 {
 	std::string x;
@@ -43,4 +53,144 @@
 
 }
 
+int cUMLModel::formalizeModel() const
+{
+	std::string temp;
 
+	temp = xmi;
+
+/*(	if (temp == organism->getParentXMI()) {
+		ctx.task_success_complete += organism->getParentBonusInfo("hydra");
+		organism->setBonusInfo("hydra", organism->getParentBonusInfo("hydra"));
+		return organism->getParentBonusInfo("hydra");
+	}*/
+
+
+//	m_world->GetStats().HydraAttempt();
+
+	double bonus = 0.0;
+	unsigned int status_total = 0;
+	int status=0;
+
+	int to_subavida[2]={0};
+	int from_subavida[2]={0};
+	
+	pipe(to_subavida); //write to 1, read from 0
+	pipe(from_subavida);
+	
+	pid_t subavida = fork();
+	if(subavida == 0) {
+		//child
+		close(to_subavida[1]);
+		close(from_subavida[0]);
+		dup2(to_subavida[0], STDIN_FILENO); //oldd, newd
+		dup2(from_subavida[1], STDOUT_FILENO);
+		execl("/usr/bin/java", "-cp .", "-jar", "./hydraulic.jar", NULL);
+		// We don't ever get here.
+	} 
+	//parent
+	close(to_subavida[0]);
+	close(from_subavida[1]);
+
+	// At this point, forget about subavida - It's running.
+	// Write the model to to_subavida[1].  Close to_subavida[1] (which wakes up subavida).
+	// Then, read from from_subavida[0] as long as is possible, after which point subavida will die.
+
+	// Write the model to STDIN of subavida (be careful; write may not write all that you ask!)
+	do {
+		status = write(to_subavida[1], temp.c_str()+status_total, temp.size());	
+		if (status < 0) {
+			break;
+		} else {
+			 status_total += status;
+		}
+	} while (status_total < temp.size());
+	close(to_subavida[1]); // Wakes up subavida.
+
+	// Time passes...
+
+	// Read the output from subavida.  Keep reading until subavida closes the pipe.
+	const int read_size=128; // The number of bytes that we're going to try to read from subavida.
+	std::string subavida_output;
+	char line[read_size]={0};
+	do {
+		status = read(from_subavida[0], line, read_size-1);
+		if(status > 0) {
+			subavida_output += line;
+			memset(line, 0, read_size);
+		}
+	} while(((status==-1) && (errno == EINTR)) || (status>0));
+
+	// Done with subavida.
+	close(from_subavida[0]);
+	// Make sure that subavida dies.
+	pid_t done=0;
+	while((done=waitpid(subavida, &status, 0))==-1 && (errno == EINTR)); 
+	assert(done==subavida);
+	
+	// if there are no errors, return 0 from hydraulic.  otherwise, return non-zero.
+	if(status != 0) {
+//		ctx->task_failed = 0;
+//		organism->setBonusInfo("hydra", 0.0); 
+		return 0;
+	} else {
+	//	ctx->task_failed = ctx->task_failed && 1;
+//		ctx.task_success_complete += 1;
+////		m_world->GetStats().HydraPassed();
+//		organism->setBonusInfo("hydra", 1.0); 
+		return 1;
+	}
+	
+}
+
+
+int cUMLModel::checkProperty(const std::string& neverclaimFile) const {
+//	m_world->GetStats().SpinAttempt();
+	int 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();
+//	m_world->GetStats().PanAttempt();
+	
+	if(system("/usr/bin/gcc -DMEMLIM=512 pan.c -o pan &> /dev/null")!=0) return 0;
+	if(system("./pan -a &> ./pan.out")!=0) return 0;
+	if(system("cat pan.out | perl -e 'while(<STDIN>) { if(/errors:\\s(\\d+)/) {exit($1);}}'")!=0) return 0;
+	if(system("cat pan.out | perl -e 'while(<STDIN>) { if(/unreached/) {exit(1);}}'")!=0) return 0;
+	
+	
+	std::ostringstream strstrm;
+//	strstrm << "cp tmp.xmi " << m_world->GetStats().GetUpdate() << "." << organism->GetID();
+//	strstrm << ".xml";	
+	if(system(strstrm.str().c_str())!=0) return 0;
+			
+//	m_world->GetStats().PanPassed();
+	return 3;
+}
+
+int cUMLModel::propertyN1() const {
+	std::string temp = xmi;
+	int temp1 = 0;
+
+/*	
+	if (temp == organism->getParentXMI()) { 
+		ctx.task_success_complete += organism->getParentBonusInfo("spinn1");
+		organism->setBonusInfo("spinn1", organism->getParentBonusInfo("spinn1"));
+		return organism->getParentBonusInfo("spinn1");
+	}
+*/	
+	
+	// check if the trigger is present in the relevant diagram... 
+//	if (organism->getStateDiagram()->findTrans(-1,-1,1,"*","*")){
+//		temp += 1;
+		
+		// check property
+//		if (ctx.task_success_complete) {
+			temp1 += checkProperty("N1");
+//		} 
+//	}
+	
+//	organism->setBonusInfo("spinn1", temp1); 
+	return temp1;
+}
+
+

Modified: branches/uml/source/main/cUMLModel.h
===================================================================
--- branches/uml/source/main/cUMLModel.h	2007-05-08 02:11:51 UTC (rev 1534)
+++ branches/uml/source/main/cUMLModel.h	2007-05-09 14:07:59 UTC (rev 1535)
@@ -13,16 +13,32 @@
 
 
 class cUMLModel { 
+public:
+	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
+	
+	// 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;}
+	
+	// Determine the "fitness" of the model
+	// does the model satisfy the sequence diagrams? 
+	// does the model meet the properties? 
+
+
 protected: 
 	static std::string xmi_begin;
 	std::string	xmi; // the XMI created by the model
 	static std::string xmi_end;
-	std::vector<cUMLStateDiagram> state_diagrams;											
+	std::vector<cUMLStateDiagram> state_diagrams;
 	
-public:
-
-	std::string getXMI(); // get the XMI version of the model
-
+	// UML - Track information about the bonus received for this model.
+	std::map <std::string, double> self_bonus;											
+	
 };
 
 #endif




More information about the Avida-cvs mailing list