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

hjg at myxo.css.msu.edu hjg at myxo.css.msu.edu
Mon Jan 21 05:15:32 PST 2008


Author: hjg
Date: 2008-01-21 08:15:31 -0500 (Mon, 21 Jan 2008)
New Revision: 2264

Added:
   branches/uml/source/main/cUMLClass.cc
   branches/uml/source/main/cUMLClass.h
Modified:
   branches/uml/Avida.xcodeproj/project.pbxproj
   branches/uml/source/cpu/cHardwareCPU.cc
   branches/uml/source/cpu/cHardwareCPU.h
   branches/uml/source/main/cOrganism.cc
   branches/uml/source/main/cUMLModel.cc
   branches/uml/source/main/cUMLModel.h
Log:
New structure (cUMLClass.*) to enable organisms to generate properties. 
New seed-model input file format. 




Modified: branches/uml/Avida.xcodeproj/project.pbxproj
===================================================================
--- branches/uml/Avida.xcodeproj/project.pbxproj	2008-01-18 04:17:34 UTC (rev 2263)
+++ branches/uml/Avida.xcodeproj/project.pbxproj	2008-01-21 13:15:31 UTC (rev 2264)
@@ -31,6 +31,8 @@
 		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 */; };
+		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 */; };
 		3EDCA1BD0C47FAB70078778D /* cUMLStateDiagram.cc in Sources */ = {isa = PBXBuildFile; fileRef = 3EDCA0170C46C9B70078778D /* cUMLStateDiagram.cc */; };
 		5629D8110C3EE14800C5F152 /* cTextWindow.cc in Sources */ = {isa = PBXBuildFile; fileRef = 5629D80D0C3EE13500C5F152 /* cTextWindow.cc */; };
@@ -336,6 +338,7 @@
 				3E26D90A0CFA0453009616CC /* cMDEExistenceProperty.h in CopyFiles */,
 				3E26D90C0CFA0453009616CC /* cMDEProperty.h in CopyFiles */,
 				3E26D90E0CFA0453009616CC /* cMDEUniversalProperty.h in CopyFiles */,
+				3ED30B230D43D73D00B3E0A7 /* cUMLClass.h in CopyFiles */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
@@ -372,6 +375,8 @@
 		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>"; };
+		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>"; };
 		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>"; };
@@ -1393,6 +1398,8 @@
 				3E26D9060CFA0453009616CC /* cMDEUniversalProperty.h */,
 				3EDCA0150C46C9B70078778D /* cUMLModel.cc */,
 				3EDCA0160C46C9B70078778D /* cUMLModel.h */,
+				3ED30B200D43D73D00B3E0A7 /* cUMLClass.cc */,
+				3ED30B210D43D73D00B3E0A7 /* cUMLClass.h */,
 				3EDCA0170C46C9B70078778D /* cUMLStateDiagram.cc */,
 				3EDCA0180C46C9B70078778D /* cUMLStateDiagram.h */,
 				42490EFE0BE2472800318058 /* cGermline.h */,
@@ -2025,6 +2032,7 @@
 				3E26D9090CFA0453009616CC /* cMDEExistenceProperty.cc in Sources */,
 				3E26D90D0CFA0453009616CC /* cMDEUniversalProperty.cc in Sources */,
 				3E54F4170CFB147300FC5B63 /* cMDEProperty.cc in Sources */,
+				3ED30B220D43D73D00B3E0A7 /* cUMLClass.cc in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};

Modified: branches/uml/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/uml/source/cpu/cHardwareCPU.cc	2008-01-18 04:17:34 UTC (rev 2263)
+++ branches/uml/source/cpu/cHardwareCPU.cc	2008-01-21 13:15:31 UTC (rev 2264)
@@ -541,8 +541,16 @@
 							 "Add a universality property"),						
 	tInstLibEntry<tMethod>("prop-ex", &cHardwareCPU::Inst_ExistenceProperty, false, 
 							 "Add an existence property"),	
+	tInstLibEntry<tMethod>("move-rel-p", &cHardwareCPU::Inst_RelativeMoveExpressionP, false, 
+							 "Relative move p"),		
+	tInstLibEntry<tMethod>("move-abs-p", &cHardwareCPU::Inst_AbsoluteMoveExpressionP, false, 
+							 "Absolute move p"),						
+	tInstLibEntry<tMethod>("next-p", &cHardwareCPU::Inst_NextExpressionP, false, 
+							 "Next p"),						
+	tInstLibEntry<tMethod>("prev-p", &cHardwareCPU::Inst_PrevExpressionP, false, 
+							 "Previous p"),	
+	  
 											
-
 	
     // Placebo instructions
     tInstLibEntry<tMethod>("skip", &cHardwareCPU::Inst_Skip),
@@ -5072,7 +5080,8 @@
 { 
 	bool val = 0;
 	// Call a function on the model to create this property.
-	std::string s = organism->getStateDiagram()->getGuard();
+	// Currently it just uses p
+	std::string s = organism->getUMLModel()->getP();
 	
 	if (s != "<null>" ) {
 //		std::string n = organism->getStateDiagram()->getName();
@@ -5087,7 +5096,7 @@
 { 
 	bool val = 0;
 	// Call a function on the model to create this property.
-	std::string s = organism->getStateDiagram()->getGuard();
+	std::string s = organism->getUMLModel()->getP();
 	
 	if (s != "<null>" ) {
 //		std::string n = organism->getStateDiagram()->getName();
@@ -5102,7 +5111,7 @@
 {
 	bool val = 0;
 	// Call a function on the model to create this property.
-	std::string s = organism->getStateDiagram()->getGuard();
+	std::string s = organism->getUMLModel()->getP();
 	
 	if (s != "<null>" ) {
 //		std::string n = organism->getStateDiagram()->getName();
@@ -5113,4 +5122,26 @@
 	return val;
 } 
 
+bool cHardwareCPU::Inst_RelativeMoveExpressionP(cAvidaContext& ctx) 
+{
+	ReadLabel();
+	int jump_amount = GetLabel().AsInt(NUM_NOPS);
+	return (m_world->GetPopulation().getUMLModel()->relativeMoveExpressionP(jump_amount));
+}
 
+bool cHardwareCPU::Inst_NextExpressionP(cAvidaContext& ctx)
+{
+	return (m_world->GetPopulation().getUMLModel()->relativeMoveExpressionP(1));
+}
+
+bool cHardwareCPU::Inst_PrevExpressionP(cAvidaContext& ctx)
+{
+	return (m_world->GetPopulation().getUMLModel()->relativeMoveExpressionP(-1));
+}
+
+bool cHardwareCPU::Inst_AbsoluteMoveExpressionP(cAvidaContext& ctx)
+{
+	ReadLabel();
+	int jump_amount = GetLabel().AsInt(NUM_NOPS);
+	return (m_world->GetPopulation().getUMLModel()->absoluteMoveExpressionP(jump_amount));
+}

Modified: branches/uml/source/cpu/cHardwareCPU.h
===================================================================
--- branches/uml/source/cpu/cHardwareCPU.h	2008-01-18 04:17:34 UTC (rev 2263)
+++ branches/uml/source/cpu/cHardwareCPU.h	2008-01-21 13:15:31 UTC (rev 2264)
@@ -650,6 +650,11 @@
   bool Inst_UniversialityProperty(cAvidaContext& ctx);
   bool Inst_ExistenceProperty(cAvidaContext& ctx);
     
+  bool Inst_RelativeMoveExpressionP(cAvidaContext& ctx);
+  bool Inst_NextExpressionP(cAvidaContext& ctx);
+  bool Inst_PrevExpressionP(cAvidaContext& ctx);
+  bool Inst_AbsoluteMoveExpressionP(cAvidaContext& ctx);
+//  bool 
 };
 
 

Modified: branches/uml/source/main/cOrganism.cc
===================================================================
--- branches/uml/source/main/cOrganism.cc	2008-01-18 04:17:34 UTC (rev 2263)
+++ branches/uml/source/main/cOrganism.cc	2008-01-21 13:15:31 UTC (rev 2264)
@@ -591,12 +591,12 @@
 void cOrganism::modelCheck(cAvidaContext& ctx)
 {
 	if(GetCellID()==-1) return;
-	m_model.printXMI();	
+//	m_model.printXMI();	
 	
 	// Update the value of max trans
-	if (m_model.numTrans() > m_model.getMaxTrans()) { 
-		m_model.setMaxTrans(m_model.numTrans());
-	} 
+//	if (m_model.numTrans() > m_model.getMaxTrans()) { 
+//		m_model.setMaxTrans(m_model.numTrans());
+//	} 
 
 
   const tArray<double> & resource_count = m_interface->GetResources();

Added: branches/uml/source/main/cUMLClass.cc
===================================================================
--- branches/uml/source/main/cUMLClass.cc	                        (rev 0)
+++ branches/uml/source/main/cUMLClass.cc	2008-01-21 13:15:31 UTC (rev 2264)
@@ -0,0 +1,26 @@
+/*
+ *  cUMLClass.cc
+ *  
+ *
+ *  Created by Heather Goldsby on 1/18/08.
+ *  Copyright 2008 __MyCompanyName__. All rights reserved.
+ *
+ */
+
+#include "cUMLClass.h"
+
+void cUMLClass::addOperation(std::string n, std::string c) { 
+	operation o; 
+	o.op_name = n; 
+	o.op_code = c;
+	operations.push_back(o);
+}
+
+void cUMLClass::addAttribute(std::string n, std::string t, std::vector<std::string> vals) {
+	class_attribute c;
+	c.attribute_name = n;
+	c.attribute_type = t;
+//	c.attribute_values = vals;
+	c.attribute_values.assign(vals.begin(), vals.end());
+	attributes.push_back(c);
+}

Added: branches/uml/source/main/cUMLClass.h
===================================================================
--- branches/uml/source/main/cUMLClass.h	                        (rev 0)
+++ branches/uml/source/main/cUMLClass.h	2008-01-21 13:15:31 UTC (rev 2264)
@@ -0,0 +1,58 @@
+/*
+ *  cUMLClass.h
+ *  
+ *
+ *  Created by Heather Goldsby on 1/18/08.
+ *  Copyright 2008 __MyCompanyName__. All rights reserved.
+ *
+ */
+
+#ifndef _C_UMLCLASS_H_
+#define _C_UMLCLASS_H_
+
+//#include "cUMLStateDiagram.h"
+
+
+#include <string>
+#include <iostream>
+#include <map>
+#include <utility>
+#include <set>
+#include <vector>
+#include <fstream>
+
+struct class_attribute{
+	std::string attribute_type;
+	std::string attribute_name;
+	std::vector<std::string> attribute_values;
+};
+
+struct operation{
+	std::string op_name; 
+	std::string op_code;
+};
+
+class cUMLClass{
+	
+public:
+	void addOperation(std::string, std::string);
+	void addAssociatedClass(std::string s) { associated_class_names.push_back(s); }
+	void addAttribute(std::string, std::string, std::vector<std::string>);
+	void addClassName(std::string s) { name = s; }
+	
+	std::string getClassName() { return name; }
+	int numAttributes() { return attributes.size(); }
+	int numOperations() { return operations.size(); }
+	class_attribute getAttribute(int i) { return attributes[i]; }
+	operation getOperation(int i) { return operations[i]; }
+	
+		
+protected:
+	std::vector<std::string> associated_class_names;
+	std::vector<operation> operations;
+	std::vector<class_attribute> attributes;
+	std::string name;
+
+};
+
+#endif

Modified: branches/uml/source/main/cUMLModel.cc
===================================================================
--- branches/uml/source/main/cUMLModel.cc	2008-01-18 04:17:34 UTC (rev 2263)
+++ branches/uml/source/main/cUMLModel.cc	2008-01-21 13:15:31 UTC (rev 2264)
@@ -68,108 +68,85 @@
 follow the *very* specific file format."
 */
 void seed_diagrams(const char* seed_model,
-                   std::vector<cUMLStateDiagram>& state_diagrams,
+				   std::vector<cUMLClass>& classes,
+//                   std::vector<cUMLStateDiagram>& state_diagrams,
                    std::vector<scenario_info>& scenarios,
                    int& hydra_mode, 
 				   bool& witness_mode) {
-  std::string data, line; // or maybe stringstream? (strstream?)
-	int num_states;
-	int num_sd = 0;
-	int cur_sd = -1;
-	bool include_trans = 0;
-	std::string tr_l, tr_o, gu, act, temp;
-	int trig_i, guard_i, act_i, orig_i, dest_i;
+  std::string data, line; 
+	//int num_states;
+	//int num_sd = 0;
+	int cur_class = -1;
+	//bool include_trans = 0;
+	//std::string tr_l, tr_o, gu, act, temp;
+	//int trig_i, guard_i, act_i, orig_i, dest_i;
+	int num_classes;
 	std::ifstream infile;
 	infile.open(seed_model);
 	assert(infile.is_open());
-	scenario_info s;
-	std::string path_step;
+	//scenario_info s;
+	//std::string path_step;
 	std::string class_name;
+	std::string temp1, temp2;
+	std::string op_name, op_code;
+	std::string att_name, att_type, att_val;
+	std::vector<std::string> att_vals;
 	
 	while (getline (infile, line))
 	{
-		// Read in states
-		if (line == "=STATES====================") {
+		if (line == "==MODEL==") {
 			line.erase();
-			infile >> num_states;
-      // Read in number of state diagrams	
-		} else if (line == "=HYDRA=====================") { 
-			line.erase(); 
-			infile >> hydra_mode;
-		} else if (line == "=WITNESS===================") { 
-			line.erase(); 
-			infile >> witness_mode;
-		} else if (line == "=INCLUDE-TRANSITIONS=======") { 
-			line.erase(); 
-			infile >> include_trans;
-		} else if (line == "=STATE-DIAGRAM=============") { 
+			infile >> temp1 >> num_classes;
+			infile >> temp1 >> hydra_mode;
+			infile >> temp1 >> witness_mode;
+			//std::cout << "num_classes " << num_classes << std::endl;
+			//std::cout << "hydra_mode " << hydra_mode << std::endl;
+			//std::cout << "witness_mode " << witness_mode << std::endl;
+			classes.resize(num_classes);
+		} else if (line == "==CLASS==") { 
 			line.erase();
-			infile >> num_sd;
-			state_diagrams.resize(num_sd);
-      // Read in each state diagram	
-		} else if (line == "=SD========================") { 
+			infile >> temp1 >> class_name;
+			cur_class++;
+			classes[cur_class].addClassName(class_name);
+			//std::cout << "current class " << cur_class << std::endl;
+			//std::cout << "class name " << class_name << std::endl;
+		} else if (line == "==ATTRIBUTES==") {
 			line.erase();
-			infile >> class_name;
-			cur_sd++;
-			state_diagrams[cur_sd].addName(class_name);
-		} else if (line == "-TRIGGERS------------------") { 
-			line.erase();
-			infile >> tr_l;
-			while (tr_l != "-END---------------------------") { 
-				infile >> tr_o;
-				state_diagrams[cur_sd].addTrigger(tr_l, tr_o);
-				infile >> tr_l;
+			infile >> att_name;
+			att_vals.clear();
+			while (att_name != "==END==") { 
+				infile >> att_type >> temp1 >> att_val;
+			//	std::cout << "attribute " << att_name << " " << att_type << std::endl;
+				while (att_val != "]") { // && att_val != "==END=CLASS==") { 
+					att_vals.push_back(att_val);
+			//		std::cout << "value " << att_val << std::endl;
+					infile >> att_val;
+				}
+				
+				classes[cur_class].addAttribute(att_name, att_type, att_vals);
+				infile >> att_name;				
 			}
-		}else if (line == "-GUARDS--------------------") { 
+		} else if (line == "==OPERATIONS==") {
 			line.erase();
-			infile >> gu;
-			while (gu != "-END---------------------------") { 
-				state_diagrams[cur_sd].addGuard(gu);
-				infile >> gu;
+			infile >> op_name;
+			while (op_name != "==END==") { 
+				infile >> op_code;
+//				state_diagrams[cur_sd].addTrigger(tr_l, tr_o);
+				classes[cur_class].addOperation(op_name, op_code);
+			//	std::cout << "operation " << op_name << " " << op_code << std::endl;
+				infile >> op_name;				
 			}
-		} else if (line == "-ACTIONS--------------------") { 
+		} else if (line == "==ASSOCIATIONS==") {
 			line.erase();
-			infile >> act;
-			while (act != "-END---------------------------") { 
-				state_diagrams[cur_sd].addAction(act);
-				infile >> act;
+			infile >> class_name;
+			while (class_name != "==END==") { 
+				classes[cur_class].addAssociatedClass(class_name);
+			//	std::cout << "Associated Class " << class_name << std::endl;
+				infile >> class_name;			
 			}
-		} else if (line == "-TRANSITIONS---------------") { 
-			line.erase();
-			infile >> temp; 
-			while (temp != "-END---------------------------") { 
-				infile >> orig_i >> dest_i >> trig_i >> guard_i >> act_i; 
-				if (include_trans) { 
-					state_diagrams[cur_sd].addTransitionTotal(orig_i, dest_i, trig_i, guard_i, act_i);
-				}	
-				infile >> temp; 
-			}
-		}  else if (line == "-SCENARIO----------------------") { 
-			line.erase();
-			s.path.clear();
-			s.stateDiagramID = cur_sd;
-			infile >> s.shouldLoop >> s.startState;
-			infile >> temp;
-			while (temp!= "-END---------------------------") { 
-				infile >> path_step;
-				s.path.push_back(path_step);
-				infile >> temp;
-			}
-			scenarios.push_back(s);
-			
-		} else if (line == "-TRANSITION-LABELS-------------") { 
-			line.erase();
-			infile >> temp;			
-			while (temp!= "-END---------------------------") { 
-				infile >> trig_i >> guard_i >> act_i; 
-				state_diagrams[cur_sd].addTransitionLabel(trig_i, guard_i, act_i); 
-				infile >> temp; 
-			}
-		//	infile >> temp;
 		}
-
-		line.erase();
-  }
+		
+	}
   
 	infile.close();
 	return;
@@ -182,6 +159,7 @@
 
 bool cUMLModel::_cfgLoaded = false;
 std::vector<cUMLStateDiagram> cUMLModel::_cfg_state_diagrams;
+std::vector<cUMLClass> cUMLModel::_cfg_classes;
 std::vector<scenario_info> cUMLModel::_cfg_scenarios;
 int cUMLModel::_cfg_hydra_mode;
 bool cUMLModel::_cfg_witness_mode;
@@ -189,14 +167,21 @@
 
 cUMLModel::cUMLModel(const char* seed_model) {
   if(!_cfgLoaded) {
-    seed_diagrams(seed_model, _cfg_state_diagrams, _cfg_scenarios, _cfg_hydra_mode, _cfg_witness_mode);
+    seed_diagrams(seed_model, _cfg_classes, _cfg_scenarios, _cfg_hydra_mode, _cfg_witness_mode);
     _cfgLoaded = true;
   }
   
-  state_diagrams = _cfg_state_diagrams;
+  //state_diagrams = _cfg_state_diagrams;
+  classes = _cfg_classes;
   scenarios = _cfg_scenarios;
   hydraMode = _cfg_hydra_mode; 
   witnessMode = _cfg_witness_mode;
+  expression_p = 0;
+  expression_q = 0;
+  expression_r = 0;
+  createExpressionsFromClasses();
+  int t = expressions.size();
+
 }
 
 
@@ -230,8 +215,8 @@
 
 cUMLStateDiagram* cUMLModel::getStateDiagram (unsigned int x) 
 {
-  assert(x<state_diagrams.size());
-  return &state_diagrams[x];
+  assert(x<classes.size());
+  return (getStateDiagram(x));
 }
 
 
@@ -246,7 +231,7 @@
 	
 	for (unsigned int i=0; i<xi.classes_info.size(); i++) { 
 		xmi += xi.classes_info[i];
-		xmi += state_diagrams[i].getXMI("sd" + i);
+		xmi += (getStateDiagram(i))->getXMI("sd" + i);
 	}
 	
 	xmi += xi.xmi_end;
@@ -261,7 +246,7 @@
 int cUMLModel::numStates() 
 { 
 	int temp_states = 0;
-	for (unsigned int i=0; i<state_diagrams.size(); i++) { 
+	for (unsigned int i=0; i<numSDs(); i++) { 
 		temp_states += getStateDiagram(i)->numStates();
 	}
 	return temp_states;
@@ -270,7 +255,7 @@
 int cUMLModel::numTrans()
 {
 int temp_trans = 0;
-	for (unsigned int i=0; i<state_diagrams.size(); i++) { 
+	for (unsigned int i=0;  i<numSDs(); i++) { 
 		temp_trans += getStateDiagram(i)->numTrans();
 	}
 	return temp_trans;
@@ -279,7 +264,7 @@
 int cUMLModel::numTriggers()
 {
 int temp_trigger = 0;
-	for (unsigned int i=0; i<state_diagrams.size(); i++) { 
+	for (unsigned int i=0;  i<numSDs(); i++) { 
 		temp_trigger += getStateDiagram(i)->numTriggers();
 	}
 	return temp_trigger;
@@ -288,7 +273,7 @@
 int cUMLModel::numGuards() 
 {
 int temp = 0;
-	for (unsigned int i=0; i<state_diagrams.size(); i++) { 
+	for (unsigned int i=0;  i<numSDs(); i++) { 
 		temp += getStateDiagram(i)->numGuards();
 	}
 	return temp;
@@ -297,7 +282,7 @@
 int cUMLModel::numActions()
 {
 int temp = 0;
-	for (unsigned int i=0; i<state_diagrams.size(); i++) { 
+	for (unsigned int i=0;  i<numSDs(); i++) { 
 		temp += getStateDiagram(i)->numActions();
 	}
 	return temp;
@@ -444,7 +429,7 @@
 bool cUMLModel::addExistenceProperty(std::string s)
 {
 	// a pointer to the existence property
-	std::string temp = getStateDiagram(0)->StringifyAnInt(mdeprops.size());
+	std::string temp = StringifyAnInt(mdeprops.size());
 	cMDEExistenceProperty* e = new cMDEExistenceProperty(s, temp);
 	mdeprops.insert (e);
 	//int q = mdeprops.size();
@@ -454,7 +439,7 @@
 bool cUMLModel::addAbsenceProperty(std::string s)
 {
 	// a pointer to the absence property
-	std::string temp = getStateDiagram(0)->StringifyAnInt(mdeprops.size());
+	std::string temp = StringifyAnInt(mdeprops.size());
 	cMDEAbsenceProperty* e = new cMDEAbsenceProperty(s, temp);
 	mdeprops.insert (e);
 	//int q = mdeprops.size();
@@ -465,10 +450,116 @@
 bool cUMLModel::addUniversalProperty(std::string s)
 {
 	// a pointer to the universal property
-	std::string temp = getStateDiagram(0)->StringifyAnInt(mdeprops.size());
+	std::string temp = StringifyAnInt(mdeprops.size());
 	cMDEUniversalProperty* e = new cMDEUniversalProperty(s, temp);
 	mdeprops.insert (e);
 	//int q = mdeprops.size();
 	return true;
 	
 }
+
+
+// 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
+//   Methods
+void cUMLModel::createExpressionsFromClasses()
+{
+	std::string class_name;
+	class_attribute a;
+	operation o;
+	cUMLClass c;
+	int temp_size;
+	std::string temp1, temp2, temp3;
+	
+	// For each class, create its set of expressions. 
+	for (unsigned int i=0; i<classes.size(); i++) { 
+		c = classes[i];
+		class_name = c.getClassName();
+		temp_size = c.numAttributes();
+		
+		// For each attribute...
+		for (unsigned int j=0; j<temp_size; j++) {
+			a = c.getAttribute(j);
+			temp1 = class_name + "_V." + a.attribute_name;
+			
+			// For each attribute value
+			for (unsigned int k=0; k<a.attribute_values.size(); k++){
+				// create both an equality and an inequality expression
+				temp2 = a.attribute_values[k];
+				temp3 = temp1 + "==" + temp2;
+				addExpression(temp3);
+				//std::cout << temp3 << std::endl;
+				temp3 = temp1 + "!=" + temp2;
+				//std::cout << temp3 << std::endl;
+				addExpression(temp3);
+			}
+		}
+		
+		// For each method
+		temp_size = c.numOperations();
+		for (unsigned int m=0; m<temp_size; m++) {
+			o = c.getOperation(m);
+			temp1 = class_name + "_q??[" + o.op_name + "]";
+			addExpression(temp1);
+			//std::cout << temp1 << std::endl;
+		}
+	}
+}
+
+
+//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() {
+	int t = expressions.size();
+	return expressions[expression_p]; 
+} 
+
+
+// print the label. Change - signs to _
+std::string cUMLModel::StringifyAnInt(int x) { 
+	
+	std::ostringstream o;
+	
+	if (x < 0) {
+		x = abs(x);
+		o << "_";
+	} 
+	
+	o << x;
+	return o.str();
+}

Modified: branches/uml/source/main/cUMLModel.h
===================================================================
--- branches/uml/source/main/cUMLModel.h	2008-01-18 04:17:34 UTC (rev 2263)
+++ branches/uml/source/main/cUMLModel.h	2008-01-21 13:15:31 UTC (rev 2264)
@@ -1,6 +1,7 @@
 #ifndef _C_UMLMODEL_H_
 #define _C_UMLMODEL_H_
 
+#include "cUMLClass.h"
 #include "cUMLStateDiagram.h"
 #include "cMDEProperty.h"
 #include "cMDEExistenceProperty.h"
@@ -11,6 +12,7 @@
 #include <iostream>
 #include <map>
 #include <utility>
+#include <algorithm>              
 #include <set>
 #include <vector>
 #include <fstream>
@@ -72,7 +74,49 @@
 	bool addExistenceProperty(std::string);
 	bool addAbsenceProperty(std::string);
 	bool addUniversalProperty(std::string);
+	void addExpression(std::string s) { expressions.push_back(s); }
+	void createExpressionsFromClasses();
+	std::string StringifyAnInt(int);
+	template <typename T>
+		bool absoluteMoveIndex (T x, int &y, int z)
+	{
+			
+			int x_size = (int) x.size();
+			if (x_size == 0 || z > x_size) {
+				return false;
+			}
+			
+			y = 0;
+			return relativeMoveIndex(x, y, z);
+	}
 	
+	template <typename T>
+		bool relativeMoveIndex (T x, int &y, int z)
+	{
+			int x_size = (int) x.size();
+			
+			if (x_size == 0) {
+				return false;
+			}
+			
+			if (z > 0) { 
+				y += (z % x_size);
+				
+				// index is greater than vector
+				if (y >= x_size) { 
+					y -= x_size;
+				} else if(index < 0) { 
+					y += x_size;
+				}
+			}	
+			return true;
+	}	
+	std::string getP(); // { return expressions[expression_p]; } 
+	std::string getQ() { return expressions[expression_q]; }
+	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); }
+
 	
 	// check if the model is ready for hydra
 	bool readyForHydra(); 
@@ -85,21 +129,30 @@
 	std::string	xmi; 
 	static int max_trans;
 	std::vector<cUMLStateDiagram> state_diagrams;
+	std::vector<cUMLClass> classes;
 	std::map<std::string, float> bonus_info;
 	std::vector<scenario_info> scenarios;
 	std::vector<double> scenario_completion;
 	int hydraMode; 
 	bool witnessMode;
+	int expression_p;
+	int expression_q;
+	int expression_r;
 	
 	// set of properties.
 	std::set<cMDEProperty*, ltcMDEProperty> mdeprops;
 	int m_property_success;
 	int m_property_failure;
 
+	// vector of expressions
+	std::vector<std::string> expressions;
 	
+	
   // 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.
+  static std::vector<cUMLClass> _cfg_classes; // !< Classes read from seed model config
+  
   static std::vector<scenario_info> _cfg_scenarios; //!< Scenarios as read from seed-model.cfg.
   static int _cfg_hydra_mode; //!< Execution mode for hydra, as read from seed-model.cfg.
   static bool _cfg_witness_mode; //!< Execution mode for hydra, as read from seed-model.cfg.




More information about the Avida-cvs mailing list