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

hjg at myxo.css.msu.edu hjg at myxo.css.msu.edu
Wed Nov 28 04:21:05 PST 2007


Author: hjg
Date: 2007-11-28 07:21:04 -0500 (Wed, 28 Nov 2007)
New Revision: 2211

Modified:
   branches/uml/Avida.xcodeproj/project.pbxproj
   branches/uml/source/cpu/cHardwareCPU.cc
   branches/uml/source/cpu/cHardwareCPU.h
   branches/uml/source/main/cTaskLib.cc
   branches/uml/source/main/cTaskLib.h
   branches/uml/source/main/cUMLModel.cc
   branches/uml/source/main/cUMLModel.h
   branches/uml/source/main/cUMLStateDiagram.h
Log:
First set of coding changes to enable organisms to generate properties.



Modified: branches/uml/Avida.xcodeproj/project.pbxproj
===================================================================
--- branches/uml/Avida.xcodeproj/project.pbxproj	2007-11-24 21:05:06 UTC (rev 2210)
+++ branches/uml/Avida.xcodeproj/project.pbxproj	2007-11-28 12:21:04 UTC (rev 2211)
@@ -23,6 +23,14 @@
 /* End PBXAggregateTarget section */
 
 /* Begin PBXBuildFile section */
+		3E26D9070CFA0453009616CC /* cMDEAbsenceProperty.cc in Sources */ = {isa = PBXBuildFile; fileRef = 3E26D8FF0CFA0453009616CC /* cMDEAbsenceProperty.cc */; };
+		3E26D9080CFA0453009616CC /* cMDEAbsenceProperty.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 3E26D9000CFA0453009616CC /* cMDEAbsenceProperty.h */; };
+		3E26D9090CFA0453009616CC /* cMDEExistenceProperty.cc in Sources */ = {isa = PBXBuildFile; fileRef = 3E26D9010CFA0453009616CC /* cMDEExistenceProperty.cc */; };
+		3E26D90A0CFA0453009616CC /* cMDEExistenceProperty.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 3E26D9020CFA0453009616CC /* cMDEExistenceProperty.h */; };
+		3E26D90C0CFA0453009616CC /* cMDEProperty.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 3E26D9040CFA0453009616CC /* cMDEProperty.h */; };
+		3E26D90D0CFA0453009616CC /* cMDEUniversalProperty.cc in Sources */ = {isa = PBXBuildFile; fileRef = 3E26D9050CFA0453009616CC /* cMDEUniversalProperty.cc */; };
+		3E26D90E0CFA0453009616CC /* cMDEUniversalProperty.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 3E26D9060CFA0453009616CC /* cMDEUniversalProperty.h */; };
+		3E54F4170CFB147300FC5B63 /* cMDEProperty.cc in Sources */ = {isa = PBXBuildFile; fileRef = 3E54F4160CFB147300FC5B63 /* cMDEProperty.cc */; };
 		3EDCA1BC0C47FAB50078778D /* cUMLModel.cc in Sources */ = {isa = PBXBuildFile; fileRef = 3EDCA0150C46C9B70078778D /* cUMLModel.cc */; };
 		3EDCA1BD0C47FAB70078778D /* cUMLStateDiagram.cc in Sources */ = {isa = PBXBuildFile; fileRef = 3EDCA0170C46C9B70078778D /* cUMLStateDiagram.cc */; };
 		5629D8110C3EE14800C5F152 /* cTextWindow.cc in Sources */ = {isa = PBXBuildFile; fileRef = 5629D80D0C3EE13500C5F152 /* cTextWindow.cc */; };
@@ -324,6 +332,10 @@
 				70B1A7430B7E3FFD00067486 /* instset-experimental.cfg in CopyFiles */,
 				70B1A75A0B7E431F00067486 /* experimental.org in CopyFiles */,
 				70D046610C32EA90000614E7 /* cBirthChamber.h in CopyFiles */,
+				3E26D9080CFA0453009616CC /* cMDEAbsenceProperty.h in CopyFiles */,
+				3E26D90A0CFA0453009616CC /* cMDEExistenceProperty.h in CopyFiles */,
+				3E26D90C0CFA0453009616CC /* cMDEProperty.h in CopyFiles */,
+				3E26D90E0CFA0453009616CC /* cMDEUniversalProperty.h in CopyFiles */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
@@ -352,6 +364,14 @@
 /* Begin PBXFileReference section */
 		1097463D0AE9606E00929ED6 /* cDeme.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = cDeme.cc; sourceTree = "<group>"; };
 		1097463E0AE9606E00929ED6 /* cDeme.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cDeme.h; sourceTree = "<group>"; };
+		3E26D8FF0CFA0453009616CC /* cMDEAbsenceProperty.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = cMDEAbsenceProperty.cc; sourceTree = "<group>"; };
+		3E26D9000CFA0453009616CC /* cMDEAbsenceProperty.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cMDEAbsenceProperty.h; sourceTree = "<group>"; };
+		3E26D9010CFA0453009616CC /* cMDEExistenceProperty.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = cMDEExistenceProperty.cc; sourceTree = "<group>"; };
+		3E26D9020CFA0453009616CC /* cMDEExistenceProperty.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cMDEExistenceProperty.h; sourceTree = "<group>"; };
+		3E26D9040CFA0453009616CC /* cMDEProperty.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cMDEProperty.h; sourceTree = "<group>"; };
+		3E26D9050CFA0453009616CC /* cMDEUniversalProperty.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = cMDEUniversalProperty.cc; sourceTree = "<group>"; };
+		3E26D9060CFA0453009616CC /* cMDEUniversalProperty.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cMDEUniversalProperty.h; sourceTree = "<group>"; };
+		3E54F4160CFB147300FC5B63 /* cMDEProperty.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = cMDEProperty.cc; sourceTree = "<group>"; };
 		3EDCA0150C46C9B70078778D /* cUMLModel.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = cUMLModel.cc; sourceTree = "<group>"; };
 		3EDCA0160C46C9B70078778D /* cUMLModel.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cUMLModel.h; sourceTree = "<group>"; };
 		3EDCA0170C46C9B70078778D /* cUMLStateDiagram.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = cUMLStateDiagram.cc; sourceTree = "<group>"; };
@@ -1363,6 +1383,14 @@
 		DCC310040762539D008F7A48 /* main */ = {
 			isa = PBXGroup;
 			children = (
+				3E26D8FF0CFA0453009616CC /* cMDEAbsenceProperty.cc */,
+				3E26D9000CFA0453009616CC /* cMDEAbsenceProperty.h */,
+				3E26D9010CFA0453009616CC /* cMDEExistenceProperty.cc */,
+				3E26D9020CFA0453009616CC /* cMDEExistenceProperty.h */,
+				3E54F4160CFB147300FC5B63 /* cMDEProperty.cc */,
+				3E26D9040CFA0453009616CC /* cMDEProperty.h */,
+				3E26D9050CFA0453009616CC /* cMDEUniversalProperty.cc */,
+				3E26D9060CFA0453009616CC /* cMDEUniversalProperty.h */,
 				3EDCA0150C46C9B70078778D /* cUMLModel.cc */,
 				3EDCA0160C46C9B70078778D /* cUMLModel.h */,
 				3EDCA0170C46C9B70078778D /* cUMLStateDiagram.cc */,
@@ -1993,6 +2021,10 @@
 			buildActionMask = 2147483647;
 			files = (
 				70DCAC9C097AF7C0002F8733 /* primitive.cc in Sources */,
+				3E26D9070CFA0453009616CC /* cMDEAbsenceProperty.cc in Sources */,
+				3E26D9090CFA0453009616CC /* cMDEExistenceProperty.cc in Sources */,
+				3E26D90D0CFA0453009616CC /* cMDEUniversalProperty.cc in Sources */,
+				3E54F4170CFB147300FC5B63 /* cMDEProperty.cc in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};

Modified: branches/uml/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/uml/source/cpu/cHardwareCPU.cc	2007-11-24 21:05:06 UTC (rev 2210)
+++ branches/uml/source/cpu/cHardwareCPU.cc	2007-11-28 12:21:04 UTC (rev 2211)
@@ -530,7 +530,13 @@
 	tInstLibEntry<tMethod>("action-12", &cHardwareCPU::Inst_Action12, false, 
 					"Change to action 12"),						
 	tInstLibEntry<tMethod>("action-13", &cHardwareCPU::Inst_Action13, false, 
-					"Change to action 13"),						
+					"Change to action 13"),		
+	tInstLibEntry<tMethod>("prop-abs", &cHardwareCPU::Inst_AbsenceProperty, false, 
+							 "Add an absence property"),						
+	tInstLibEntry<tMethod>("prop-uni", &cHardwareCPU::Inst_UniversialityProperty, false, 
+							 "Add a universality property"),						
+	tInstLibEntry<tMethod>("prop-ex", &cHardwareCPU::Inst_ExistenceProperty, false, 
+							 "Add an existence property"),	
 											
 
 	
@@ -5044,3 +5050,48 @@
 
 bool cHardwareCPU::Inst_Action13(cAvidaContext& ctx)
 { return (organism->getStateDiagram()->absoluteJumpAction(13)); }
+
+
+bool cHardwareCPU::Inst_AbsenceProperty(cAvidaContext& ctx)
+{ 
+	bool val = 0;
+	// Call a function on the model to create this property.
+	std::string s = organism->getStateDiagram()->getGuard();
+	
+	if (s != "<null>" ) {
+//		std::string n = organism->getStateDiagram()->getName();
+//		s = n + "." + s;
+		val = organism->getUMLModel()->addAbsenceProperty(s);
+	}
+	return val;
+} 
+
+bool cHardwareCPU::Inst_UniversialityProperty(cAvidaContext& ctx) 
+{ 
+	bool val = 0;
+	// Call a function on the model to create this property.
+	std::string s = organism->getStateDiagram()->getGuard();
+	
+	if (s != "<null>" ) {
+//		std::string n = organism->getStateDiagram()->getName();
+//		s = n + "." + s;
+		val = organism->getUMLModel()->addUniversalProperty(s);
+	}
+	return val;
+} 
+
+bool cHardwareCPU::Inst_ExistenceProperty(cAvidaContext& ctx)
+{
+	bool val = 0;
+	// Call a function on the model to create this property.
+	std::string s = organism->getStateDiagram()->getGuard();
+	
+	if (s != "<null>" ) {
+//		std::string n = organism->getStateDiagram()->getName();
+//		s = n + "." + s;
+		val = organism->getUMLModel()->addExistenceProperty(s);
+	}
+	return val;
+} 
+
+

Modified: branches/uml/source/cpu/cHardwareCPU.h
===================================================================
--- branches/uml/source/cpu/cHardwareCPU.h	2007-11-24 21:05:06 UTC (rev 2210)
+++ branches/uml/source/cpu/cHardwareCPU.h	2007-11-28 12:21:04 UTC (rev 2211)
@@ -640,6 +640,11 @@
   bool Inst_Action11(cAvidaContext& ctx);
   bool Inst_Action12(cAvidaContext& ctx);
   bool Inst_Action13(cAvidaContext& ctx);
+  
+  // UML instructions used to construct properties
+  bool Inst_AbsenceProperty(cAvidaContext& ctx);
+  bool Inst_UniversialityProperty(cAvidaContext& ctx);
+  bool Inst_ExistenceProperty(cAvidaContext& ctx);
     
 };
 

Modified: branches/uml/source/main/cTaskLib.cc
===================================================================
--- branches/uml/source/main/cTaskLib.cc	2007-11-24 21:05:06 UTC (rev 2210)
+++ branches/uml/source/main/cTaskLib.cc	2007-11-28 12:21:04 UTC (rev 2211)
@@ -431,6 +431,8 @@
 	  NewTask(name, "Non-determinism", &cTaskLib::Task_Nondeterminism);
   else if (name == "export-xmi")
 	  NewTask(name, "Export XMI", &cTaskLib::Task_ExportXMI);
+  else if (name == "check-props") 
+	  NewTask(name, "Check Properties", &cTaskLib::Task_Properties);
 /*  else if (name == "mult_trans") // 
 	  NewTask(name, "Successfully completed multiple transitions", &cTaskLib::Task_MultTrans);*/
 	  
@@ -2958,6 +2960,18 @@
 	return bonus;
 }
 
+double cTaskLib::Task_Properties(cTaskContext& ctx) const
+{
+	double bonus = 0.0; 
+	cOrganism* org = ctx.getOrganism();
+	
+	// call some sort of check properties function for the model.
+	bonus = org->getUMLModel()->checkProperties();
+	
+	return bonus;
+	
+}
+
 double cTaskLib::Task_NumStates(cTaskContext& ctx) const
 {
 	double ns = (double) ctx.getOrganism()->getStateDiagram()->numStates();

Modified: branches/uml/source/main/cTaskLib.h
===================================================================
--- branches/uml/source/main/cTaskLib.h	2007-11-24 21:05:06 UTC (rev 2210)
+++ branches/uml/source/main/cTaskLib.h	2007-11-28 12:21:04 UTC (rev 2211)
@@ -302,6 +302,7 @@
 //  double Task_MultTrans(cTaskContext& ctx) const;  
   double Task_Nondeterminism(cTaskContext& ctx) const;
   double Task_ExportXMI(cTaskContext& ctx) const;
+  double Task_Properties(cTaskContext& ctx) const;
 
 };
 

Modified: branches/uml/source/main/cUMLModel.cc
===================================================================
--- branches/uml/source/main/cUMLModel.cc	2007-11-24 21:05:06 UTC (rev 2210)
+++ branches/uml/source/main/cUMLModel.cc	2007-11-28 12:21:04 UTC (rev 2211)
@@ -84,6 +84,7 @@
 	assert(infile.is_open());
 	scenario_info s;
 	std::string path_step;
+	std::string class_name;
 	
 	while (getline (infile, line))
 	{
@@ -108,7 +109,9 @@
       // Read in each state diagram	
 		} else if (line == "=SD========================") { 
 			line.erase();
+			infile >> class_name;
 			cur_sd++;
+			state_diagrams[cur_sd].addName(class_name);
 		} else if (line == "-TRIGGERS------------------") { 
 			line.erase();
 			infile >> tr_l;
@@ -221,7 +224,6 @@
 //	int v;
 	
 	xmi = xi.xmi_begin; 
-//	std::cout << "xi.classes.size " << xi.classes_info.size() << " state_diagrams.size() " << state_diagrams.size() << std::endl;
 	
 	assert (xi.classes_info.size() == state_diagrams.size());
 	
@@ -229,8 +231,6 @@
 		xmi += xi.classes_info[i];
 		xmi += state_diagrams[i].getXMI("sd" + i);
 	}
-//	xmi += state_diagrams[0].getXMI("sd0");	
-//	xmi += xmi_class2;
 	
 	xmi += xi.xmi_end;
 	
@@ -238,7 +238,6 @@
 
 std::string cUMLModel::getXMI()
 {
-//	printXMI();
 	return xmi;
 }
 
@@ -398,8 +397,61 @@
 	// close outfile.
 	outfile.close();
 	
-	return;
+	return;	
+}
+
+float cUMLModel::checkProperties() 
+{
+	// for all properties:
+	std::set<cMDEProperty*>::iterator prop_ptr;
+	float total = 0;
+	float temp_val = 0;
+
+	for (prop_ptr=mdeprops.begin(); prop_ptr!=mdeprops.end(); prop_ptr++)  
+	{
+		temp_val = (*prop_ptr)->getEvaluationInformation();
+		if (temp_val == -1) { 
+			(*prop_ptr)->evaluate();
+			temp_val = (*prop_ptr)->getEvaluationInformation();
+		} 
+		
+		total += temp_val;
+	}
 	
+	
+	// return the reward.
+	return total;
 }
 
 
+bool cUMLModel::addExistenceProperty(std::string s)
+{
+	// a pointer to the existence property
+	std::string temp = getStateDiagram(0)->StringifyAnInt(mdeprops.size());
+	cMDEExistenceProperty* e = new cMDEExistenceProperty(s, temp);
+	mdeprops.insert (mdeprops.end(), e);
+	//int q = mdeprops.size();
+	return true;
+}
+
+bool cUMLModel::addAbsenceProperty(std::string s)
+{
+	// a pointer to the absence property
+	std::string temp = getStateDiagram(0)->StringifyAnInt(mdeprops.size());
+	cMDEAbsenceProperty* e = new cMDEAbsenceProperty(s, temp);
+	mdeprops.insert (mdeprops.end(), e);
+	//int q = mdeprops.size();
+	return true;
+	
+}
+
+bool cUMLModel::addUniversalProperty(std::string s)
+{
+	// a pointer to the universal property
+	std::string temp = getStateDiagram(0)->StringifyAnInt(mdeprops.size());
+	cMDEUniversalProperty* e = new cMDEUniversalProperty(s, temp);
+	mdeprops.insert (mdeprops.end(), e);
+	//int q = mdeprops.size();
+	return true;
+	
+}

Modified: branches/uml/source/main/cUMLModel.h
===================================================================
--- branches/uml/source/main/cUMLModel.h	2007-11-24 21:05:06 UTC (rev 2210)
+++ branches/uml/source/main/cUMLModel.h	2007-11-28 12:21:04 UTC (rev 2211)
@@ -2,6 +2,10 @@
 #define _C_UMLMODEL_H_
 
 #include "cUMLStateDiagram.h"
+#include "cMDEProperty.h"
+#include "cMDEExistenceProperty.h"
+#include "cMDEAbsenceProperty.h"
+#include "cMDEUniversalProperty.h"
 
 #include <string>
 #include <iostream>
@@ -62,9 +66,15 @@
 	int numSDs();
 	int numSCs();
 	
+	// Properties
+	bool addExistenceProperty(std::string);
+	bool addAbsenceProperty(std::string);
+	bool addUniversalProperty(std::string);
+	
 	// check if the model is ready for hydra
 	bool readyForHydra(); 
 	bool getWitnessMode() {return witnessMode; }
+	float checkProperties();
 
 protected: 
 	static xmi_info xi;
@@ -77,6 +87,10 @@
 	int hydraMode; 
 	bool witnessMode;
 	
+	// set of properties.
+	std::set<cMDEProperty*> mdeprops;
+
+	
   // The following are set once per Avida experiment, when the first cUMLModel is constructed:
   static bool _cfgLoaded; //!< Whether or not we've already loaded seed-model.cfg.
   static std::vector<cUMLStateDiagram> _cfg_state_diagrams; //!< State diagrams as read from seed-model.cfg.

Modified: branches/uml/source/main/cUMLStateDiagram.h
===================================================================
--- branches/uml/source/main/cUMLStateDiagram.h	2007-11-24 21:05:06 UTC (rev 2210)
+++ branches/uml/source/main/cUMLStateDiagram.h	2007-11-28 12:21:04 UTC (rev 2211)
@@ -71,6 +71,7 @@
   int numTriggers() { return triggers.size(); } 
   int numGuards() { return guards.size(); } 
   int numActions() { return actions.size(); }
+  void addName(std::string s) { name = s; } 
 
   unsigned int getNumberOfNonDeterministicStates();
 
@@ -140,7 +141,9 @@
   int getTriggerIndex();
   int getGuardIndex();
   int getActionIndex();
+  std::string getGuard() { return guards[getGuardIndex()]; } 
   transition_label getTransLabel();
+  std::string getName() { return name; } 
   
 // Visit graph
 //  void executeVisitor();
@@ -162,6 +165,7 @@
 	boost::graph_traits<state_diagram>::vertex_descriptor orig;
 	boost::graph_traits<state_diagram>::vertex_descriptor dest;
 	int actual_end_state;
+	std::string name;
 	
 
 };




More information about the Avida-cvs mailing list