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

hjg at myxo.css.msu.edu hjg at myxo.css.msu.edu
Sat Jan 26 15:01:54 PST 2008


Author: hjg
Date: 2008-01-26 18:01:54 -0500 (Sat, 26 Jan 2008)
New Revision: 2280

Modified:
   branches/uml/source/cpu/cHardwareCPU.cc
   branches/uml/source/cpu/cHardwareCPU.h
   branches/uml/source/main/cMDEPrecedenceProperty.cc
   branches/uml/source/main/cOrganism.cc
   branches/uml/source/main/cStats.cc
   branches/uml/source/main/cStats.h
   branches/uml/source/main/cUMLModel.cc
   branches/uml/source/main/cUMLModel.h
Log:
Added the next parts of the precedence & response properties.



Modified: branches/uml/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/uml/source/cpu/cHardwareCPU.cc	2008-01-26 15:47:02 UTC (rev 2279)
+++ branches/uml/source/cpu/cHardwareCPU.cc	2008-01-26 23:01:54 UTC (rev 2280)
@@ -541,6 +541,10 @@
 							 "Add a universality property"),						
 	tInstLibEntry<tMethod>("prop-ex", &cHardwareCPU::Inst_ExistenceProperty, false, 
 							 "Add an existence property"),	
+	tInstLibEntry<tMethod>("prop-prec", &cHardwareCPU::Inst_PrecedenceProperty, false, 
+							 "Add a precedence property"),						
+	tInstLibEntry<tMethod>("prop-resp", &cHardwareCPU::Inst_ResponseProperty, false, 
+							 "Add a response property"),
 	tInstLibEntry<tMethod>("move-rel-p", &cHardwareCPU::Inst_RelativeMoveExpressionP, false, 
 							 "Relative move p"),		
 	tInstLibEntry<tMethod>("move-abs-p", &cHardwareCPU::Inst_AbsoluteMoveExpressionP, false, 
@@ -5153,7 +5157,38 @@
 	return val;
 } 
 
+bool cHardwareCPU::Inst_PrecedenceProperty(cAvidaContext& ctx)
+{
+	float val = 0;
+	// Call a function on the model to create this property.
+	std::string p = organism->getUMLModel()->getP();
+	std::string q = organism->getUMLModel()->getQ();
+	
+	if (p != "<null>" && q != "<null>") {
+		val = m_world->GetPopulation().getUMLModel()->addPrecedenceProperty(p, q);
+	}
+	
+	organism->getUMLModel()->addPropertyReward(val);
+	
+	return val;
+} 
 
+bool cHardwareCPU::Inst_ResponseProperty(cAvidaContext& ctx)
+{
+	float val = 0;
+	// Call a function on the model to create this property.
+	std::string p = organism->getUMLModel()->getP();
+	std::string q = organism->getUMLModel()->getQ();
+	
+	if (p != "<null>" && q != "<null>") {
+		val = m_world->GetPopulation().getUMLModel()->addResponseProperty(p, q);
+	}
+	
+	organism->getUMLModel()->addPropertyReward(val);
+	
+	return val;
+} 
+
 bool cHardwareCPU::Inst_RelativeMoveExpressionP(cAvidaContext& ctx) 
 {
 	ReadLabel();

Modified: branches/uml/source/cpu/cHardwareCPU.h
===================================================================
--- branches/uml/source/cpu/cHardwareCPU.h	2008-01-26 15:47:02 UTC (rev 2279)
+++ branches/uml/source/cpu/cHardwareCPU.h	2008-01-26 23:01:54 UTC (rev 2280)
@@ -649,6 +649,8 @@
   bool Inst_AbsenceProperty(cAvidaContext& ctx);
   bool Inst_UniversialityProperty(cAvidaContext& ctx);
   bool Inst_ExistenceProperty(cAvidaContext& ctx);
+  bool Inst_ResponseProperty(cAvidaContext& ctx);
+  bool Inst_PrecedenceProperty(cAvidaContext& ctx);
   
   bool Inst_ANDExpressions(cAvidaContext& ctx);
   bool Inst_ORExpressions(cAvidaContext& ctx);  

Modified: branches/uml/source/main/cMDEPrecedenceProperty.cc
===================================================================
--- branches/uml/source/main/cMDEPrecedenceProperty.cc	2008-01-26 15:47:02 UTC (rev 2279)
+++ branches/uml/source/main/cMDEPrecedenceProperty.cc	2008-01-26 23:01:54 UTC (rev 2280)
@@ -15,19 +15,31 @@
 	outfile.open ("property");
 	assert(outfile.is_open());
 	
-	outfile << "/* Precedence property " << _expr_p  << " " << _expr_q << "*/" << std::endl;
-	outfile << "#define q (" << _expr_q << ")" << std::endl;
-	outfile << "#define p (" << _expr_p << ")" << std::endl;
-	outfile << "never {  /*  !([](p -> <>s))  */ " << std::endl;
+	outfile << "never {    /*  !(([](!p)) || ((!p) U  s))  */" << std::endl;
 	outfile << "T0_init:" << std::endl;
 	outfile << "if" << std::endl;
-	outfile << "(! ((s)) && (p)) -> goto accept_S4" << std::endl;
-	outfile << ":: (1) -> goto T0_init" << std::endl;
+	outfile << ":: (! ((s)) && (p)) -> goto accept_S4" << std::endl;
+	outfile << ":: (! ((s)) && (p)) -> goto accept_all" << std::endl;
+	outfile << ":: (! ((s))) -> goto T0_init" << std::endl;
+	outfile << ":: (! ((s)) && (p)) -> goto accept_S13" << std::endl;
 	outfile << "fi;" << std::endl;
 	outfile << "accept_S4:" << std::endl;
-	outfile << "if " << std::endl;
+	outfile << "if" << std::endl;
 	outfile << ":: (! ((s))) -> goto accept_S4" << std::endl;
-	outfile << "fi; }" << std::endl;
+	outfile << ":: (! ((s)) && (p)) -> goto accept_all" << std::endl;
+	outfile << "fi;" << std::endl;
+	outfile << "accept_S13:" << std::endl;
+	outfile << "if" << std::endl;
+	outfile << ":: ((p)) -> goto accept_all" << std::endl;
+	outfile << ":: (1) -> goto T0_S13" << std::endl;
+	outfile << "fi;" << std::endl;
+	outfile << "T0_S13:" << std::endl;
+    outfile << "if" << std::endl;
+	outfile << ":: ((p)) -> goto accept_all" << std::endl;
+	outfile << ":: (1) -> goto T0_S13" << std::endl;
+	outfile << "fi;" << std::endl;
+	outfile << "accept_all:" << std::endl;
+	outfile << "skip }" << std::endl;
 	
 	outfile.close();
 
@@ -40,23 +52,24 @@
 	outfile.open (file_name.c_str());
 	assert(outfile.is_open());
 	
-	outfile << "#define s (" << _expr_q << ")" << std::endl;
+	outfile << "/* Precedence property " << _expr_p  << " " << _expr_q << "*/" << std::endl;
+	outfile << "#define q (" << _expr_q << ")" << std::endl;
 	outfile << "#define p (" << _expr_p << ")" << std::endl;
-	outfile << "never {    /* !(!(<>(p && <>s))) */" << std::endl;
+	outfile << "never {    /* !p U (q && <>p) */" << std::endl;
 	outfile << "T0_init:" << std::endl;
 	outfile << "if" << std::endl;
-	outfile << ":: ((p) && (s)) -> goto accept_all" << std::endl;
-	outfile << ":: ((p)) -> goto T0_S4" << std::endl;
-	outfile << ":: (1) -> goto T0_init" << std::endl;
+	outfile << ":: ((p) && (q)) -> goto accept_all" << std::endl;
+	outfile << ":: ((q)) -> goto T0_S4" << std::endl;
+	outfile << ":: (! ((p))) -> goto T0_init" << std::endl;
 	outfile << "fi;" << std::endl;
 	outfile << "T0_S4:" << std::endl;
 	outfile << "if" << std::endl;
-	outfile << ":: ((s)) -> goto accept_all" << std::endl;
+	outfile << 	":: ((p)) -> goto accept_all" << std::endl;
 	outfile << ":: (1) -> goto T0_S4" << std::endl;
-	outfile << "fi;" << std::endl;	
+	outfile << "fi;" << std::endl;
 	outfile << "accept_all:" << std::endl;
-	outfile << "skip}" << std::endl;
-	
+    outfile << "skip }" << std::endl;
+
 	outfile.close();
 	
 }

Modified: branches/uml/source/main/cOrganism.cc
===================================================================
--- branches/uml/source/main/cOrganism.cc	2008-01-26 15:47:02 UTC (rev 2279)
+++ branches/uml/source/main/cOrganism.cc	2008-01-26 23:01:54 UTC (rev 2280)
@@ -690,6 +690,12 @@
 	m_world->GetStats().existPropSuccess(pop_model->numExistencePropertySuccess());
 	m_world->GetStats().existPropFailure(pop_model->numExistencePropertyFailure());
 	m_world->GetStats().existPropTotal(pop_model->numExistencePropertyTotal());
+	m_world->GetStats().precPropSuccess(pop_model->numPrecedencePropertySuccess());
+	m_world->GetStats().precPropFailure(pop_model->numPrecedencePropertyFailure());
+	m_world->GetStats().precPropTotal(pop_model->numPrecedencePropertyTotal());
+	m_world->GetStats().respPropSuccess(pop_model->numResponsePropertySuccess());
+	m_world->GetStats().respPropFailure(pop_model->numResponsePropertyFailure());
+	m_world->GetStats().respPropTotal(pop_model->numResponsePropertyTotal());	
 //	int x = pop_model->propertySize();
 //	int y = pop_model->numTotalProperty();
 	

Modified: branches/uml/source/main/cStats.cc
===================================================================
--- branches/uml/source/main/cStats.cc	2008-01-26 15:47:02 UTC (rev 2279)
+++ branches/uml/source/main/cStats.cc	2008-01-26 23:01:54 UTC (rev 2280)
@@ -1012,6 +1012,9 @@
 {
 	
 	cDataFile& df = m_world->GetDataFile(filename);
+	df.WriteComment( "Avida uml properties\n" );
+	df.WriteTimeStamp();
+	df.Write( GetUpdate(), "update" );
 	df.Write( m_propertySuccess, "total number of properties that passed" );
 	df.Write( m_propertyFailure, "total number of properties that failed" );
 	df.Write( m_propertyTotal, "total number of properties" );
@@ -1024,7 +1027,12 @@
 	df.Write( m_existPropertySuccess, "existence properties that passed" );
 	df.Write( m_existPropertyFailure, "existence properties that failed" );
 	df.Write( m_existPropertyTotal, "total number of existence properties" ); 
-	
+	df.Write( m_precPropertySuccess, "precedence properties that passed" );
+	df.Write( m_precPropertyFailure, "precedence properties that failed" );
+	df.Write( m_precPropertyTotal, "total number of precedence properties" ); 
+	df.Write( m_respPropertySuccess, "response properties that passed" );
+	df.Write( m_respPropertyFailure, "response properties that failed" );
+	df.Write( m_respPropertyTotal, "total number of response properties" ); 
 
 	df.Endl();
 

Modified: branches/uml/source/main/cStats.h
===================================================================
--- branches/uml/source/main/cStats.h	2008-01-26 15:47:02 UTC (rev 2279)
+++ branches/uml/source/main/cStats.h	2008-01-26 23:01:54 UTC (rev 2280)
@@ -283,6 +283,12 @@
   int m_existPropertySuccess; 
   int m_existPropertyFailure; 
   int m_existPropertyTotal; 
+  int m_precPropertySuccess; 
+  int m_precPropertyFailure; 
+  int m_precPropertyTotal; 
+  int m_respPropertySuccess; 
+  int m_respPropertyFailure; 
+  int m_respPropertyTotal; 
     
 
   
@@ -691,7 +697,12 @@
   void existPropSuccess(int x) {m_existPropertySuccess =x; }
   void existPropFailure(int x) {m_existPropertyFailure =x;}
   void existPropTotal(int x)  {m_existPropertyTotal =x;}
-      
+  void precPropSuccess(int x) {m_precPropertySuccess =x; }
+  void precPropFailure(int x) {m_precPropertyFailure =x;}
+  void precPropTotal(int x)  {m_precPropertyTotal =x;}
+  void respPropSuccess(int x) {m_respPropertySuccess =x; }
+  void respPropFailure(int x) {m_respPropertyFailure =x;}
+  void respPropTotal(int x)  {m_respPropertyTotal =x;}
 
   
   

Modified: branches/uml/source/main/cUMLModel.cc
===================================================================
--- branches/uml/source/main/cUMLModel.cc	2008-01-26 15:47:02 UTC (rev 2279)
+++ branches/uml/source/main/cUMLModel.cc	2008-01-26 23:01:54 UTC (rev 2280)
@@ -190,6 +190,10 @@
   m_existence_property_failure =0;
   m_universal_property_success =0;
   m_universal_property_failure =0;
+  m_precedence_property_success =0;
+  m_precedence_property_failure =0;
+  m_response_property_success =0;
+  m_response_property_failure =0;
 }
 
 
@@ -630,6 +634,61 @@
 		totalstring = pstring + " || " + qstring;
 		val = addExpression(totalstring); 
 	}
-	return (val);}
+	return (val);
+}
+
+float cUMLModel::addResponseProperty(std::string s1, std::string s2)
+{
+	// a pointer to the universal property
+	std::string temp = StringifyAnInt(mdeprops.size());
+	float val = 0;	
+	cMDEResponseProperty* e = new cMDEResponseProperty(s1, s2, temp);
+	//	mdeprops.insert (e);
+	//int q = mdeprops.size();
+	std::set<cMDEProperty*, ltcMDEProperty>::iterator mdepropiter = mdeprops.find(e);
+	if (mdepropiter != mdeprops.end()) {
+		val = (*mdepropiter)->getEvaluationInformation();
+	} else {
+		e->evaluate();
+		val = e->getEvaluationInformation();
+		mdeprops.insert (e);
+		if (val >0) {
+			m_property_success++;
+			m_response_property_success++;
+		} else { 
+			m_property_failure++;
+			m_response_property_failure++;
+		}
+	}
+	return val;
+}
+
+float cUMLModel::addPrecedenceProperty(std::string s1, std::string s2)
+{
+	// a pointer to the universal property
+	std::string temp = StringifyAnInt(mdeprops.size());
+	float val = 0;	
+	cMDEPrecedenceProperty* e = new cMDEPrecedenceProperty(s1, s2, temp);
+	//	mdeprops.insert (e);
+	//int q = mdeprops.size();
+	std::set<cMDEProperty*, ltcMDEProperty>::iterator mdepropiter = mdeprops.find(e);
+	if (mdepropiter != mdeprops.end()) {
+		val = (*mdepropiter)->getEvaluationInformation();
+	} else {
+		e->evaluate();
+		val = e->getEvaluationInformation();
+		mdeprops.insert (e);
+		if (val >0) {
+			m_property_success++;
+			m_precedence_property_success++;
+		} else { 
+			m_property_failure++;
+			m_precedence_property_failure++;
+		}
+	}
+	return val;	
 	
+}
 
+	
+

Modified: branches/uml/source/main/cUMLModel.h
===================================================================
--- branches/uml/source/main/cUMLModel.h	2008-01-26 15:47:02 UTC (rev 2279)
+++ branches/uml/source/main/cUMLModel.h	2008-01-26 23:01:54 UTC (rev 2280)
@@ -7,6 +7,8 @@
 #include "cMDEExistenceProperty.h"
 #include "cMDEAbsenceProperty.h"
 #include "cMDEUniversalProperty.h"
+#include "cMDEResponseProperty.h"
+#include "cMDEPrecedenceProperty.h"
 
 #include <string>
 #include <iostream>
@@ -75,10 +77,20 @@
 	int numAbsencePropertyTotal() { return m_absence_property_success + m_absence_property_failure; }
 	int numExistencePropertySuccess() { return m_existence_property_success; }
 	int numExistencePropertyFailure() { return m_existence_property_failure; }
-	int numExistencePropertyTotal() { return m_existence_property_success + m_existence_property_failure; }
+	int numExistencePropertyTotal() { 
+		return m_existence_property_success + m_existence_property_failure; }
 	int numUniversalPropertySuccess() { return m_universal_property_success; }
 	int numUniversalPropertyFailure() { return m_universal_property_failure; }
-	int numUniversalPropertyTotal() { return m_universal_property_success + m_universal_property_failure; }	
+	int numUniversalPropertyTotal() { 
+		return m_universal_property_success + m_universal_property_failure; }	
+	int numPrecedencePropertySuccess() { return m_precedence_property_success; }
+	int numPrecedencePropertyFailure() { return m_precedence_property_failure; }
+	int numPrecedencePropertyTotal() { 
+		return m_precedence_property_success + m_precedence_property_failure; }	
+	int numResponsePropertySuccess() { return m_response_property_success; }
+	int numResponsePropertyFailure() { return m_response_property_failure; }
+	int numResponsePropertyTotal() { return m_response_property_success + m_response_property_failure; }	
+	
 	int propertySize() { return mdeprops.size(); }
 	
 	void resetPropertyReward() { m_property_reward = 0; }
@@ -91,6 +103,9 @@
 	float addExistenceProperty(std::string);
 	float addAbsenceProperty(std::string);
 	float addUniversalProperty(std::string);
+	float addResponseProperty(std::string, std::string);
+	float addPrecedenceProperty(std::string, std::string);
+
 	bool addExpression(std::string s);  
 	void createExpressionsFromClasses();
 	std::string StringifyAnInt(int);
@@ -172,6 +187,10 @@
 	int m_existence_property_failure;
 	int m_universal_property_success;
 	int m_universal_property_failure;
+	int m_precedence_property_success;
+	int m_precedence_property_failure;
+	int m_response_property_success;
+	int m_response_property_failure;
 	float m_property_reward;
 	
 




More information about the Avida-cvs mailing list