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

hjg at myxo.css.msu.edu hjg at myxo.css.msu.edu
Wed Feb 13 05:59:36 PST 2008


Author: hjg
Date: 2008-02-13 08:59:36 -0500 (Wed, 13 Feb 2008)
New Revision: 2323

Modified:
   branches/uml/Avida.xcodeproj/project.pbxproj
   branches/uml/source/cpu/cHardwareCPU.cc
   branches/uml/source/main/cUMLClass.h
   branches/uml/source/main/cUMLModel.cc
   branches/uml/source/main/cUMLModel.h
Log:
Moved expressions to their own class.



Modified: branches/uml/Avida.xcodeproj/project.pbxproj
===================================================================
--- branches/uml/Avida.xcodeproj/project.pbxproj	2008-02-13 13:22:20 UTC (rev 2322)
+++ branches/uml/Avida.xcodeproj/project.pbxproj	2008-02-13 13:59:36 UTC (rev 2323)
@@ -35,6 +35,7 @@
 		3E849FD80D4A7F04003DE1BF /* cMDEResponseProperty.cc in Sources */ = {isa = PBXBuildFile; fileRef = 3E849FD70D4A7F04003DE1BF /* cMDEResponseProperty.cc */; };
 		3E849FEF0D4A8331003DE1BF /* cMDEPrecedenceProperty.cc in Sources */ = {isa = PBXBuildFile; fileRef = 3E849FED0D4A8331003DE1BF /* cMDEPrecedenceProperty.cc */; };
 		3E849FF00D4A8331003DE1BF /* cMDEPrecedenceProperty.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 3E849FEE0D4A8331003DE1BF /* cMDEPrecedenceProperty.h */; };
+		3E97D6CA0D63307E00FA7028 /* cMDEExpression.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 3E97D6C90D63307D00FA7028 /* cMDEExpression.h */; };
 		3ED30B220D43D73D00B3E0A7 /* cUMLClass.cc in Sources */ = {isa = PBXBuildFile; fileRef = 3ED30B200D43D73D00B3E0A7 /* cUMLClass.cc */; };
 		3ED30B230D43D73D00B3E0A7 /* cUMLClass.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 3ED30B210D43D73D00B3E0A7 /* cUMLClass.h */; };
 		3EDCA1BC0C47FAB50078778D /* cUMLModel.cc in Sources */ = {isa = PBXBuildFile; fileRef = 3EDCA0150C46C9B70078778D /* cUMLModel.cc */; };
@@ -345,6 +346,7 @@
 				3ED30B230D43D73D00B3E0A7 /* cUMLClass.h in CopyFiles */,
 				3E849FD60D4A7ECB003DE1BF /* cMDEExistenceProperty.h in CopyFiles */,
 				3E849FF00D4A8331003DE1BF /* cMDEPrecedenceProperty.h in CopyFiles */,
+				3E97D6CA0D63307E00FA7028 /* cMDEExpression.h in CopyFiles */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
@@ -385,6 +387,7 @@
 		3E849FD70D4A7F04003DE1BF /* cMDEResponseProperty.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = cMDEResponseProperty.cc; sourceTree = "<group>"; };
 		3E849FED0D4A8331003DE1BF /* cMDEPrecedenceProperty.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = cMDEPrecedenceProperty.cc; sourceTree = "<group>"; };
 		3E849FEE0D4A8331003DE1BF /* cMDEPrecedenceProperty.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cMDEPrecedenceProperty.h; sourceTree = "<group>"; };
+		3E97D6C90D63307D00FA7028 /* cMDEExpression.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cMDEExpression.h; sourceTree = "<group>"; };
 		3ED30B200D43D73D00B3E0A7 /* cUMLClass.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = cUMLClass.cc; sourceTree = "<group>"; };
 		3ED30B210D43D73D00B3E0A7 /* cUMLClass.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cUMLClass.h; sourceTree = "<group>"; };
 		3EDCA0150C46C9B70078778D /* cUMLModel.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = cUMLModel.cc; sourceTree = "<group>"; };
@@ -1398,6 +1401,7 @@
 		DCC310040762539D008F7A48 /* main */ = {
 			isa = PBXGroup;
 			children = (
+				3E97D6C90D63307D00FA7028 /* cMDEExpression.h */,
 				3E26D8FF0CFA0453009616CC /* cMDEAbsenceProperty.cc */,
 				3E26D9000CFA0453009616CC /* cMDEAbsenceProperty.h */,
 				3E849FD50D4A7ECB003DE1BF /* cMDEExistenceProperty.h */,

Modified: branches/uml/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/uml/source/cpu/cHardwareCPU.cc	2008-02-13 13:22:20 UTC (rev 2322)
+++ branches/uml/source/cpu/cHardwareCPU.cc	2008-02-13 13:59:36 UTC (rev 2323)
@@ -5107,7 +5107,7 @@
 	float val = 0;
 	// Call a function on the model to create this property.
 	// Currently it just uses p
-	std::string s = organism->getUMLModel()->getP();
+	std::string s = organism->getUMLModel()->getPstring();
 	
 	if (s != "<null>" ) {
 //		std::string n = organism->getStateDiagram()->getName();
@@ -5125,7 +5125,7 @@
 { 
 	float val = 0;
 	// Call a function on the model to create this property.
-	std::string s = organism->getUMLModel()->getP();
+	std::string s = organism->getUMLModel()->getPstring();
 	
 	if (s != "<null>" ) {
 //		std::string n = organism->getStateDiagram()->getName();
@@ -5143,7 +5143,7 @@
 {
 	float val = 0;
 	// Call a function on the model to create this property.
-	std::string s = organism->getUMLModel()->getP();
+	std::string s = organism->getUMLModel()->getPstring();
 	
 	if (s != "<null>" ) {
 //		std::string n = organism->getStateDiagram()->getName();
@@ -5161,8 +5161,8 @@
 {
 	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();
+	std::string p = organism->getUMLModel()->getPstring();
+	std::string q = organism->getUMLModel()->getQstring();
 	
 	if (p != q) {
 		val = m_world->GetPopulation().getUMLModel()->addPrecedenceProperty(p, q);
@@ -5177,8 +5177,8 @@
 {
 	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();
+	std::string p = organism->getUMLModel()->getPstring();
+	std::string q = organism->getUMLModel()->getQstring();
 	
 	if (p != q) {
 		val = m_world->GetPopulation().getUMLModel()->addResponseProperty(p, q);

Modified: branches/uml/source/main/cUMLClass.h
===================================================================
--- branches/uml/source/main/cUMLClass.h	2008-02-13 13:22:20 UTC (rev 2322)
+++ branches/uml/source/main/cUMLClass.h	2008-02-13 13:59:36 UTC (rev 2323)
@@ -36,7 +36,7 @@
 	
 public:
 	void addOperation(std::string, std::string);
-	void addAssociatedClass(std::string s) { associated_class_names.push_back(s); }
+	void addAssociatedClass(std::string s) { associated_class_names.insert(s); }
 	void addAttribute(std::string, std::string, std::vector<std::string>);
 	void addClassName(std::string s) { name = s; }
 	
@@ -45,10 +45,11 @@
 	int numOperations() { return operations.size(); }
 	class_attribute getAttribute(int i) { return attributes[i]; }
 	operation getOperation(int i) { return operations[i]; }
+	std::set<std::string> getAssociatedClasses() { return associated_class_names; }
 	
 		
 protected:
-	std::vector<std::string> associated_class_names;
+	std::set<std::string> associated_class_names;
 	std::vector<operation> operations;
 	std::vector<class_attribute> attributes;
 	std::string name;

Modified: branches/uml/source/main/cUMLModel.cc
===================================================================
--- branches/uml/source/main/cUMLModel.cc	2008-02-13 13:22:20 UTC (rev 2322)
+++ branches/uml/source/main/cUMLModel.cc	2008-02-13 13:59:36 UTC (rev 2323)
@@ -453,18 +453,18 @@
 	std::set<cMDEProperty*, ltcMDEProperty>::iterator mdepropiter = mdeprops.find(&e);
 	if (mdepropiter != mdeprops.end()) {
 		val = (*mdepropiter)->getEvaluationInformation();
-//		delete e;
+		//		delete e;
 	} else {
 		e.evaluate();
 		val = e.getEvaluationInformation();
 		mdeprops.insert(new cMDEExistenceProperty(e));
 		if (val >0) {
-				m_property_success++;
-				m_existence_property_success++;
-			} else { 
-				m_property_failure++;
-				m_existence_property_failure++;
-			}
+			m_property_success++;
+			m_existence_property_success++;
+		} else { 
+			m_property_failure++;
+			m_existence_property_failure++;
+		}
 	}
 	
 	return val;
@@ -475,10 +475,10 @@
 	// a pointer to the absence property
 	std::string temp = StringifyAnInt(mdeprops.size());
 	float val = 0;
-//	cMDEAbsenceProperty* e = new cMDEAbsenceProperty(s, temp);
+	//	cMDEAbsenceProperty* e = new cMDEAbsenceProperty(s, temp);
 	cMDEAbsenceProperty e(s, temp);
 	
-//	mdeprops.insert (e);
+	//	mdeprops.insert (e);
 	//int q = mdeprops.size();
 	std::set<cMDEProperty*, ltcMDEProperty>::iterator mdepropiter = mdeprops.find(&e);
 	if (mdepropiter != mdeprops.end()) {
@@ -488,14 +488,14 @@
 		val = e.getEvaluationInformation();
 		mdeprops.insert (new cMDEAbsenceProperty(e));
 		if (val >0) {
-				m_property_success++;
-				m_absence_property_success++;
-			} else { 
-				m_property_failure++;
-				m_absence_property_failure++;
-			}
+			m_property_success++;
+			m_absence_property_success++;
+		} else { 
+			m_property_failure++;
+			m_absence_property_failure++;
+		}
 	}
-
+	
 	return val;
 	
 }
@@ -505,10 +505,10 @@
 	// a pointer to the universal property
 	std::string temp = StringifyAnInt(mdeprops.size());
 	float val = 0;	
-//	cMDEUniversalProperty* e = new cMDEUniversalProperty(s, temp);
+	//	cMDEUniversalProperty* e = new cMDEUniversalProperty(s, temp);
 	cMDEUniversalProperty e(s, temp);
 	
-//	mdeprops.insert (e);
+	//	mdeprops.insert (e);
 	//int q = mdeprops.size();
 	std::set<cMDEProperty*, ltcMDEProperty>::iterator mdepropiter = mdeprops.find(&e);
 	if (mdepropiter != mdeprops.end()) {
@@ -518,21 +518,20 @@
 		val = e.getEvaluationInformation();
 		mdeprops.insert (new cMDEUniversalProperty(e));
 		if (val >0) {
-				m_property_success++;
-				m_universal_property_success++;
-			} else { 
-				m_property_failure++;
-				m_universal_property_failure++;
-			}
+			m_property_success++;
+			m_universal_property_success++;
+		} else { 
+			m_property_failure++;
+			m_universal_property_failure++;
+		}
 	}
-
+	
 	return val;
 	
 }
 
 
 
-
 // Create expressions for each class. Expressions are: 
 //   Equality of an attribute and each of its values
 //   Inequality of an attribute and each of its values
@@ -562,11 +561,11 @@
 				// create both an equality and an inequality expression
 				temp2 = a.attribute_values[k];
 				temp3 = temp1 + "==" + temp2;
-				addExpression(temp3);
+				addExpression(temp3, c.getAssociatedClasses());
 				//std::cout << temp3 << std::endl;
 				temp3 = temp1 + "!=" + temp2;
 				//std::cout << temp3 << std::endl;
-				addExpression(temp3);
+				addExpression(temp3, c.getAssociatedClasses());
 			}
 		}
 		
@@ -574,19 +573,16 @@
 		temp_size = c.numOperations();
 		for (int m=0; m<temp_size; m++) {
 			o = c.getOperation(m);
-			temp1 = class_name + "_q??[" + o.op_name + "]";
-			addExpression(temp1);
+			temp1 = class_name;
+			temp3 = class_name + "_q??[" + o.op_name + "]";
+			addExpression(temp3, c.getAssociatedClasses());
 			//std::cout << temp1 << std::endl;
 		}
 	}
 }
 
 
-std::string cUMLModel::getP() {
-	return expressions[expression_p]; 
-} 
 
-
 // print the label. Change - signs to _
 std::string cUMLModel::StringifyAnInt(int x) { 
 	
@@ -600,15 +596,18 @@
 }
 
 // Check if the expression exists in the vector. If not, add it.
-bool cUMLModel::addExpression(std::string s)
+bool cUMLModel::addExpression(std::string s, std::set<std::string> t)
 { 
 	bool val = false;
-	std::vector<std::string>::iterator exprit;
-	exprit = find(expressions.begin(), expressions.end(), s); 
+	cMDEExpression e; 
+	e.setExpr(s);
+	e.setRelatedClasses(t);
+	std::vector<cMDEExpression>::iterator exprit;
+	exprit = find(expressions.begin(), expressions.end(), e); 
 	if (exprit == expressions.end()) { 
-		expressions.push_back(s); 
+		expressions.push_back(e); 
 		val = true;
-	}
+	} 
 	return val;
 }
 
@@ -618,12 +617,18 @@
 bool cUMLModel::ANDExpressions()
 {
 	bool val = false;
-	std::string pstring, qstring, totalstring;
+	std::set<std::string> classes;
+	std::string totalstring;
+	cMDEExpression p, q;
+	
 	if (expression_p != expression_q){
-		pstring = getP();
-		qstring = getQ();
-		totalstring = pstring + " && " + qstring;
-		val = addExpression(totalstring); 
+		p = getP();
+		q = getQ();
+		totalstring = p.getExpr() + " && " + q.getExpr();
+
+	//	classes = p.getRelatedClasses();
+	//	classes.insert(q.getRelatedClasses().begin(), q.getRelatedClasses().end());
+		val = addExpression(totalstring, classes); 
 	}
 	return (val);
 }
@@ -635,12 +640,17 @@
 {
 	
 	bool val = false;
-	std::string pstring, qstring, totalstring;
+	std::set<std::string> classes;
+	std::string totalstring;
+	cMDEExpression p, q;
+
 	if (expression_p != expression_q){
-		pstring = getP();
-		qstring = getQ();
-		totalstring = pstring + " || " + qstring;
-		val = addExpression(totalstring); 
+		p = getP();
+		q = getQ();
+//		classes = p.getRelatedClasses();
+//		classes.insert(q.getRelatedClasses().begin(), q.getRelatedClasses().end());
+		totalstring = p.getExpr() + " || " + q.getExpr();
+		val = addExpression(totalstring, classes); 
 	}
 	return (val);
 }
@@ -650,7 +660,7 @@
 	// a pointer to the universal property
 	std::string temp = StringifyAnInt(mdeprops.size());
 	float val = 0;	
-//	cMDEResponseProperty* e = new cMDEResponseProperty(s1, s2, temp);
+	//	cMDEResponseProperty* e = new cMDEResponseProperty(s1, s2, temp);
 	cMDEResponseProperty e(s1, s2, temp);
 	
 	//	mdeprops.insert (e);
@@ -678,7 +688,7 @@
 	// a pointer to the universal property
 	std::string temp = StringifyAnInt(mdeprops.size());
 	float val = 0;	
-//	cMDEPrecedenceProperty* e = new cMDEPrecedenceProperty(s1, s2, temp);
+	//	cMDEPrecedenceProperty* e = new cMDEPrecedenceProperty(s1, s2, temp);
 	cMDEPrecedenceProperty e(s1, s2, temp);
 	
 	//	mdeprops.insert (e);
@@ -702,5 +712,15 @@
 	
 }
 
+
 	
+void cUMLModel::printExpressions() 
+{
+	std::vector<cMDEExpression>::iterator exprit;
+	for (exprit = expressions.begin(); exprit < expressions.end(); exprit++){
+		std::cout << exprit->getExpr() << std::endl;
+	}
 
+}
+
+

Modified: branches/uml/source/main/cUMLModel.h
===================================================================
--- branches/uml/source/main/cUMLModel.h	2008-02-13 13:22:20 UTC (rev 2322)
+++ branches/uml/source/main/cUMLModel.h	2008-02-13 13:59:36 UTC (rev 2323)
@@ -9,6 +9,7 @@
 #include "cMDEUniversalProperty.h"
 #include "cMDEResponseProperty.h"
 #include "cMDEPrecedenceProperty.h"
+#include "cMDEExpression.h"
 
 #include <string>
 #include <iostream>
@@ -106,8 +107,9 @@
 	float addResponseProperty(std::string, std::string);
 	float addPrecedenceProperty(std::string, std::string);
 
-	bool addExpression(std::string s);  
+	bool addExpression(std::string, std::set<std::string>);  
 	void createExpressionsFromClasses();
+	void printExpressions();
 	std::string StringifyAnInt(int);
 	template <typename T>
 		bool absoluteMoveIndex (T x, int &y, int z)
@@ -143,9 +145,12 @@
 			}	
 			return true;
 	}	
-	std::string getP(); // { return expressions[expression_p]; } 
-	std::string getQ() { return expressions[expression_q]; }
-	std::string getR() { return expressions[expression_r]; }
+	cMDEExpression getP() { return expressions[expression_p]; } 
+	cMDEExpression getQ() { return (expressions[expression_q]);  }
+	cMDEExpression getR() { return (expressions[expression_r]); }
+	std::string getPstring() { return (expressions[expression_p]).getExpr(); } 
+	std::string getQstring() { return (expressions[expression_q]).getExpr();  }
+	std::string getRstring() { return (expressions[expression_r]).getExpr(); }
 	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); }
@@ -195,7 +200,7 @@
 	
 
 	// vector of expressions
-	std::vector<std::string> expressions;
+	std::vector<cMDEExpression> expressions;
 	
 	
   // The following are set once per Avida experiment, when the first cUMLModel is constructed:




More information about the Avida-cvs mailing list