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

hjg at myxo.css.msu.edu hjg at myxo.css.msu.edu
Thu Jan 24 11:46:56 PST 2008


Author: hjg
Date: 2008-01-24 14:46:56 -0500 (Thu, 24 Jan 2008)
New Revision: 2273

Modified:
   branches/uml/source/cpu/cHardwareCPU.cc
   branches/uml/source/cpu/cHardwareCPU.h
   branches/uml/source/main/cMDEAbsenceProperty.cc
   branches/uml/source/main/cMDEProperty.cc
   branches/uml/source/main/cOrganism.cc
   branches/uml/source/main/cUMLModel.cc
   branches/uml/source/main/cUMLModel.h
Log:
added && and || for property generation.

Modified: branches/uml/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/uml/source/cpu/cHardwareCPU.cc	2008-01-24 17:27:20 UTC (rev 2272)
+++ branches/uml/source/cpu/cHardwareCPU.cc	2008-01-24 19:46:56 UTC (rev 2273)
@@ -549,6 +549,28 @@
 							 "Next p"),						
 	tInstLibEntry<tMethod>("prev-p", &cHardwareCPU::Inst_PrevExpressionP, false, 
 							 "Previous p"),	
+	tInstLibEntry<tMethod>("move-rel-q", &cHardwareCPU::Inst_RelativeMoveExpressionQ, false, 
+							 "Relative move q"),		
+	tInstLibEntry<tMethod>("move-abs-q", &cHardwareCPU::Inst_AbsoluteMoveExpressionQ, false, 
+							 "Absolute move q"),						
+	tInstLibEntry<tMethod>("next-q", &cHardwareCPU::Inst_NextExpressionQ, false, 
+							 "Next q"),						
+	tInstLibEntry<tMethod>("prev-q", &cHardwareCPU::Inst_PrevExpressionQ, false, 
+							 "Previous q"),	
+	tInstLibEntry<tMethod>("move-rel-r", &cHardwareCPU::Inst_RelativeMoveExpressionR, false, 
+							 "Relative move r"),		
+	tInstLibEntry<tMethod>("move-abs-r", &cHardwareCPU::Inst_AbsoluteMoveExpressionR, false, 
+							 "Absolute move r"),						
+	tInstLibEntry<tMethod>("next-r", &cHardwareCPU::Inst_NextExpressionR, false, 
+							 "Next r"),						
+	tInstLibEntry<tMethod>("prev-r", &cHardwareCPU::Inst_PrevExpressionR, false, 
+							 "Previous r"),						
+	tInstLibEntry<tMethod>("and-exp", &cHardwareCPU::Inst_ANDExpressions, false, 
+							 "AND expressions"),						
+	tInstLibEntry<tMethod>("or-exp", &cHardwareCPU::Inst_ORExpressions, false, 
+							 "OR expressions"),									 
+							
+													
 	  
 											
 	
@@ -5131,6 +5153,7 @@
 	return val;
 } 
 
+
 bool cHardwareCPU::Inst_RelativeMoveExpressionP(cAvidaContext& ctx) 
 {
 	ReadLabel();
@@ -5154,3 +5177,63 @@
 	int jump_amount = GetLabel().AsInt(NUM_NOPS);
 	return (organism->getUMLModel()->absoluteMoveExpressionP(jump_amount));
 }
+
+bool cHardwareCPU::Inst_RelativeMoveExpressionQ(cAvidaContext& ctx) 
+{
+	ReadLabel();
+	int jump_amount = GetLabel().AsInt(NUM_NOPS);
+	return (organism->getUMLModel()->relativeMoveExpressionQ(jump_amount));
+}
+
+bool cHardwareCPU::Inst_NextExpressionQ(cAvidaContext& ctx)
+{
+	return (organism->getUMLModel()->relativeMoveExpressionQ(1));
+}
+
+bool cHardwareCPU::Inst_PrevExpressionQ(cAvidaContext& ctx)
+{
+	return (organism->getUMLModel()->relativeMoveExpressionQ(-1));
+}
+
+bool cHardwareCPU::Inst_AbsoluteMoveExpressionQ(cAvidaContext& ctx)
+{
+	ReadLabel();
+	int jump_amount = GetLabel().AsInt(NUM_NOPS);
+	return (organism->getUMLModel()->absoluteMoveExpressionQ(jump_amount));
+}
+
+bool cHardwareCPU::Inst_RelativeMoveExpressionR(cAvidaContext& ctx) 
+{
+	ReadLabel();
+	int jump_amount = GetLabel().AsInt(NUM_NOPS);
+	return (organism->getUMLModel()->relativeMoveExpressionR(jump_amount));
+}
+
+bool cHardwareCPU::Inst_NextExpressionR(cAvidaContext& ctx)
+{
+	return (organism->getUMLModel()->relativeMoveExpressionR(1));
+}
+
+bool cHardwareCPU::Inst_PrevExpressionR(cAvidaContext& ctx)
+{
+	return (organism->getUMLModel()->relativeMoveExpressionR(-1));
+}
+
+bool cHardwareCPU::Inst_AbsoluteMoveExpressionR(cAvidaContext& ctx)
+{
+	ReadLabel();
+	int jump_amount = GetLabel().AsInt(NUM_NOPS);
+	return (organism->getUMLModel()->absoluteMoveExpressionR(jump_amount));
+}
+
+bool cHardwareCPU::Inst_ANDExpressions(cAvidaContext& ctx)
+{	
+	return (organism->getUMLModel()->ANDExpressions());
+}
+
+bool cHardwareCPU::Inst_ORExpressions(cAvidaContext& ctx)
+{
+	return (organism->getUMLModel()->ORExpressions());
+}
+  
+  
\ No newline at end of file

Modified: branches/uml/source/cpu/cHardwareCPU.h
===================================================================
--- branches/uml/source/cpu/cHardwareCPU.h	2008-01-24 17:27:20 UTC (rev 2272)
+++ branches/uml/source/cpu/cHardwareCPU.h	2008-01-24 19:46:56 UTC (rev 2273)
@@ -649,11 +649,22 @@
   bool Inst_AbsenceProperty(cAvidaContext& ctx);
   bool Inst_UniversialityProperty(cAvidaContext& ctx);
   bool Inst_ExistenceProperty(cAvidaContext& ctx);
+  
+  bool Inst_ANDExpressions(cAvidaContext& ctx);
+  bool Inst_ORExpressions(cAvidaContext& ctx);  
     
   bool Inst_RelativeMoveExpressionP(cAvidaContext& ctx);
   bool Inst_NextExpressionP(cAvidaContext& ctx);
   bool Inst_PrevExpressionP(cAvidaContext& ctx);
   bool Inst_AbsoluteMoveExpressionP(cAvidaContext& ctx);
+  bool Inst_RelativeMoveExpressionQ(cAvidaContext& ctx);
+  bool Inst_NextExpressionQ(cAvidaContext& ctx);
+  bool Inst_PrevExpressionQ(cAvidaContext& ctx);
+  bool Inst_AbsoluteMoveExpressionQ(cAvidaContext& ctx);
+  bool Inst_RelativeMoveExpressionR(cAvidaContext& ctx);
+  bool Inst_NextExpressionR(cAvidaContext& ctx);
+  bool Inst_PrevExpressionR(cAvidaContext& ctx);
+  bool Inst_AbsoluteMoveExpressionR(cAvidaContext& ctx);
 //  bool 
 };
 

Modified: branches/uml/source/main/cMDEAbsenceProperty.cc
===================================================================
--- branches/uml/source/main/cMDEAbsenceProperty.cc	2008-01-24 17:27:20 UTC (rev 2272)
+++ branches/uml/source/main/cMDEAbsenceProperty.cc	2008-01-24 19:46:56 UTC (rev 2273)
@@ -68,8 +68,6 @@
 	std::string cmd;
 	std::string work_prop = "properties_that_passed";
 
-	
-	
 		// if this property passed, then save it to a file
 	if (verify_reward) { 
 		cmd = "cat property >> " + work_prop;

Modified: branches/uml/source/main/cMDEProperty.cc
===================================================================
--- branches/uml/source/main/cMDEProperty.cc	2008-01-24 17:27:20 UTC (rev 2272)
+++ branches/uml/source/main/cMDEProperty.cc	2008-01-24 19:46:56 UTC (rev 2273)
@@ -87,7 +87,8 @@
 		system(cmd.c_str());
 	}
 	
-	_reward = wit_reward + verify_reward;
+//	_reward = wit_reward + verify_reward;
+	_reward = verify_reward;
 	
 }
 

Modified: branches/uml/source/main/cOrganism.cc
===================================================================
--- branches/uml/source/main/cOrganism.cc	2008-01-24 17:27:20 UTC (rev 2272)
+++ branches/uml/source/main/cOrganism.cc	2008-01-24 19:46:56 UTC (rev 2273)
@@ -690,6 +690,9 @@
 	m_world->GetStats().existPropSuccess(pop_model->numExistencePropertySuccess());
 	m_world->GetStats().existPropFailure(pop_model->numExistencePropertyFailure());
 	m_world->GetStats().existPropTotal(pop_model->numExistencePropertyTotal());
+//	int x = pop_model->propertySize();
+//	int y = pop_model->numTotalProperty();
+	
 		
 	m_model.resetPropertyReward();
 	

Modified: branches/uml/source/main/cUMLModel.cc
===================================================================
--- branches/uml/source/main/cUMLModel.cc	2008-01-24 17:27:20 UTC (rev 2272)
+++ branches/uml/source/main/cUMLModel.cc	2008-01-24 19:46:56 UTC (rev 2273)
@@ -182,6 +182,14 @@
   expression_r = 0;
   createExpressionsFromClasses();
   m_property_reward = 0;
+  m_property_success =0;
+  m_property_failure =0;
+  m_absence_property_success =0;
+  m_absence_property_failure =0;
+  m_existence_property_success =0;
+  m_existence_property_failure =0;
+  m_universal_property_success =0;
+  m_universal_property_failure =0;
 }
 
 
@@ -562,42 +570,6 @@
 }
 
 
-//template <typename T>
-//bool cUMLModel::absoluteMoveIndex (T x, int &index, int amount )
-//{
-//	
-//	int x_size = (int) x.size();
-//	if (x_size == 0 || amount > x_size) {
-//		return false;
-//	}
-//	
-//	index = 0;
-//	return relativeMoveIndex(x, index, amount);
-//}
-//
-//template <typename T>
-//bool cUMLModel::relativeMoveIndex (T x, int &index, int amount )
-//{
-//	int x_size = (int) x.size();
-//	
-//	if (x_size == 0) {
-//		return false;
-//	}
-//	
-//	if (amount > 0) { 
-//		index += (amount % x_size);
-//		
-//		// index is greater than vector
-//		if (index >= x_size) { 
-//			index -= x_size;
-//		} else if(index < 0) { 
-//			index += x_size;
-//		}
-//	}	
-//	return true;
-//}
-
-
 std::string cUMLModel::getP() {
 	return expressions[expression_p]; 
 } 
@@ -607,13 +579,57 @@
 std::string cUMLModel::StringifyAnInt(int x) { 
 	
 	std::ostringstream o;
-	
 	if (x < 0) {
 		x = abs(x);
 		o << "_";
 	} 
-	
 	o << x;
 	return o.str();
 }
 
+// Check if the expression exists in the vector. If not, add it.
+bool cUMLModel::addExpression(std::string s)
+{ 
+	bool val = false;
+	std::vector<std::string>::iterator exprit;
+	exprit = find(expressions.begin(), expressions.end(), s); 
+	if (exprit == expressions.end()) { 
+		expressions.push_back(s); 
+		val = true;
+	}
+	return val;
+}
+
+// AND expressions p & q to create a new expression
+// return true if this is a new expression
+// return false otherwise
+bool cUMLModel::ANDExpressions()
+{
+	bool val = false;
+	std::string pstring, qstring, totalstring;
+	if (expression_p != expression_q){
+		pstring = getP();
+		qstring = getQ();
+		totalstring = pstring + " && " + qstring;
+		val = addExpression(totalstring); 
+	}
+	return (val);
+}
+
+// OR expressions p & q to create a new expression
+// return true if this is a new expression
+// return false otherwise
+bool cUMLModel::ORExpressions()
+{
+	
+	bool val = false;
+	std::string pstring, qstring, totalstring;
+	if (expression_p != expression_q){
+		pstring = getP();
+		qstring = getQ();
+		totalstring = pstring + " || " + qstring;
+		val = addExpression(totalstring); 
+	}
+	return (val);}
+	
+

Modified: branches/uml/source/main/cUMLModel.h
===================================================================
--- branches/uml/source/main/cUMLModel.h	2008-01-24 17:27:20 UTC (rev 2272)
+++ branches/uml/source/main/cUMLModel.h	2008-01-24 19:46:56 UTC (rev 2273)
@@ -79,6 +79,7 @@
 	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 propertySize() { return mdeprops.size(); }
 	
 	void resetPropertyReward() { m_property_reward = 0; }
 	void addPropertyReward(float x) { m_property_reward += x; }
@@ -90,7 +91,7 @@
 	float addExistenceProperty(std::string);
 	float addAbsenceProperty(std::string);
 	float addUniversalProperty(std::string);
-	void addExpression(std::string s) { expressions.push_back(s); }
+	bool addExpression(std::string s);  
 	void createExpressionsFromClasses();
 	std::string StringifyAnInt(int);
 	template <typename T>
@@ -132,8 +133,14 @@
 	std::string getR() { return expressions[expression_r]; }
 	bool relativeMoveExpressionP(int x) { return relativeMoveIndex(expressions, expression_p, x); }
 	bool absoluteMoveExpressionP(int x) { return absoluteMoveIndex(expressions, expression_p, x); }
-
+	bool relativeMoveExpressionQ(int x) { return relativeMoveIndex(expressions, expression_q, x); }
+	bool absoluteMoveExpressionQ(int x) { return absoluteMoveIndex(expressions, expression_q, x); }
+	bool relativeMoveExpressionR(int x) { return relativeMoveIndex(expressions, expression_r, x); }
+	bool absoluteMoveExpressionR(int x) { return absoluteMoveIndex(expressions, expression_r, x); }
 	
+	bool ANDExpressions();
+	bool ORExpressions();
+	
 	// check if the model is ready for hydra
 	bool readyForHydra(); 
 	bool getWitnessMode() {return witnessMode; }




More information about the Avida-cvs mailing list