[Avida-SVN] r1906 - branches/uml/source/main

hjg at myxo.css.msu.edu hjg at myxo.css.msu.edu
Wed Aug 8 05:41:27 PDT 2007


Author: hjg
Date: 2007-08-08 08:41:26 -0400 (Wed, 08 Aug 2007)
New Revision: 1906

Modified:
   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:
Added a checkForScenarios function to the cUMLModel class. This enables the guts of the scenario checking to be performed from within the model. Additionally, added the ability to read in a scenario from the config file.


Modified: branches/uml/source/main/cTaskLib.cc
===================================================================
--- branches/uml/source/main/cTaskLib.cc	2007-08-07 21:52:57 UTC (rev 1905)
+++ branches/uml/source/main/cTaskLib.cc	2007-08-08 12:41:26 UTC (rev 1906)
@@ -406,22 +406,8 @@
 	  NewTask(name, "Successfully created trans 9", &cTaskLib::Task_Trans9);
   else if (name == "trans10") // 
 	  NewTask(name, "Successfully created trans 10", &cTaskLib::Task_Trans10);	  
-  else if (name == "scene-1") // 
-	  NewTask(name, "Successfully created scenario 1", &cTaskLib::Task_Scenario1);
-  else if (name == "scene-2") // 
-	  NewTask(name, "Successfully created scenario 2", &cTaskLib::Task_Scenario2);
-  else if (name == "scene-3") // 
-	  NewTask(name, "Successfully created scenario 3", &cTaskLib::Task_Scenario3);
-  else if (name == "scene-4") // 
-	  NewTask(name, "Successfully created scenario 4", &cTaskLib::Task_Scenario4);	  
-  else if (name == "scene-5") // 
-	  NewTask(name, "Successfully created scenario 5", &cTaskLib::Task_Scenario5);
-  else if (name == "scene-6") // 
-	  NewTask(name, "Successfully created scenario 6", &cTaskLib::Task_Scenario6);	
-  else if (name == "scene-7") // 
-	  NewTask(name, "Successfully created scenario 7", &cTaskLib::Task_Scenario7);
-  else if (name == "scene-8") // 
-	  NewTask(name, "Successfully created scenario 8", &cTaskLib::Task_Scenario8);
+  else if (name == "scens") // 
+	  NewTask(name, "Successfully created scenarios", &cTaskLib::Task_Scenarios);	  
   else if (name == "numStates") // 
 	  NewTask(name, "Successfully created 5 states", &cTaskLib::Task_NumStates);  	  
   else if (name == "numTrans") // 
@@ -2945,355 +2931,24 @@
 	return bonus;
 }
 
-
-double cTaskLib::Task_Scenario1(cTaskContext& ctx) const
+double cTaskLib::Task_Scenarios(cTaskContext& ctx) const
 {
 	double bonus = 0.0; 
-	std::deque<std::string> path1;
 	cOrganism* org = ctx.getOrganism();
-	assert(org!=0);
 	
-	// Check if the tasks are complete so far... 
-	// This provides a basic ordering mechanism for the tasks.
-/*	if (!ctx.m_task_success_complete) {
-		return 0;
-	}*/	
-	
 	// Check if this model is different than the organism's parent's model
 	if (org->getParentXMI() != org->getUMLModel()->getXMI()) {
-		
-		// create the scenario
-		path1.push_back("^TempSensor.getOpState()");
-		path1.push_back("setTempOpState");
-	
-		// check for scneario
-//		bonus = ((ctx.organism->getUMLModel()->getStateDiagram(1)->findPath(path1)) / path1.size());
-		bonus = ((org->getUMLModel()->getStateDiagram(1)->findPath(path1, 0, 0))); // / path1.size());
-
+		bonus = org->getUMLModel()->checkForScenarios();
 	} else { 
-		bonus = org->getParentBonus("scenario1"); 
+		bonus = org->getParentBonus("scenarios"); 
 	}
 	
 	// Set bonus info for current model
-	org->getUMLModel()->setBonusInfo("scenario1", bonus);		
-		
-	/*if (bonus == 2) { 
-		ctx.m_task_success_complete  = ctx.m_task_success_complete && true;
-	} else { 
-		ctx.m_task_success_complete = false;	
-	}
-	path1.clear();*/
-	return bonus;
-}
-
-
-double cTaskLib::Task_Scenario2(cTaskContext& ctx) const
-{
-	double bonus = 0.0; 
-	std::deque<std::string> path1;
-	cOrganism* org = ctx.getOrganism();
-
+	org->getUMLModel()->setBonusInfo("scenarios", bonus);		
 	
-	// Check if the tasks are complete so far... 
-	// This provides a basic ordering mechanism for the tasks.
-	/*if (!ctx.m_task_success_complete) {
-		return 0;
-	}*/	
-	
-	// Check if this model is different than the organism's parent's model
-	if (org->getParentXMI() != org->getUMLModel()->getXMI()) {
-		
-		// create the scenario
-		path1.push_back("^TempSensor.getTempData()");
-		path1.push_back("setTempData");
-	
-		// check for scneario
-		//bonus = ((ctx.organism->getUMLModel()->getStateDiagram(1)->findPath(path1)) / path1.size());
-		bonus = ((org->getUMLModel()->getStateDiagram(1)->findPath(path1, 0, 0))); // / path1.size());
-		
-	} else { 
-		bonus = org->getParentBonus("scenario2"); 
-	}
-	
-	// Set bonus info for current model
-	/*ctx.organism->getUMLModel()->setBonusInfo("scenario2", bonus);		
-	if (bonus == 2) { 
-		ctx.m_task_success_complete  = ctx.m_task_success_complete && true;
-	} else { 
-		ctx.m_task_success_complete = false;	
-	}*/
-	
-	// Set bonus info for current model
-	org->getUMLModel()->setBonusInfo("scenario2", bonus);	
-	
 	return bonus;
 }
 
-double cTaskLib::Task_Scenario3(cTaskContext& ctx) const
-{
-	double bonus = 0.0; 
-	std::deque<std::string> path1;
-	cOrganism* org = ctx.getOrganism();
-		
-	// Check if the tasks are complete so far... 
-	// This provides a basic ordering mechanism for the tasks.
-	/*if (!ctx.m_task_success_complete) {
-		return 0;
-	}*/	
-	
-	// Check if this model is different than the organism's parent's model
-	if (org->getParentXMI() != org->getUMLModel()->getXMI()) {
-		
-		// create the scenario
-		path1.push_back("getOpState");
-		path1.push_back("op_state:=1");
-		path1.push_back("^SoftwareSensor.setTempOpState(op_state)");
-		
-	
-		// check for scneario
-		//bonus = ((ctx.organism->getUMLModel()->getStateDiagram(0)->findPath(path1)) / path1.size());
-		bonus = ((org->getUMLModel()->getStateDiagram(0)->findPath(path1, 0, 0))); // / path1.size());
-
-	} else { 
-		bonus = org->getParentBonus("scenario3"); 
-	}
-	
-	// Set bonus info for current model
-	org->getUMLModel()->setBonusInfo("scenario3", bonus);		
-
-	/*int temp = path1.size();	
-		
-	if (bonus == 3) { 
-		ctx.m_task_success_complete  = ctx.m_task_success_complete && true;
-	} else { 
-		ctx.m_task_success_complete = false;	
-	}*/
-	
-	return bonus;
-}
-
-double cTaskLib::Task_Scenario4(cTaskContext& ctx) const
-{
-	double bonus = 0.0; 
-	std::deque<std::string> path1;
-	cOrganism* org = ctx.getOrganism();
-	
-	
-	// Check if the tasks are complete so far... 
-	// This provides a basic ordering mechanism for the tasks.
-	/*if (!ctx.m_task_success_complete) {
-		return 0;
-	}*/	
-	
-	// Check if this model is different than the organism's parent's model
-	if (org->getParentXMI() != org->getUMLModel()->getXMI()) {
-		
-		// create the scenario
-		path1.push_back("getOpState");
-		path1.push_back("op_state:=0");
-		path1.push_back("^SoftwareSensor.setTempOpState(op_state)");
-		
-	
-		// check for scneario
-//		bonus = ((ctx.organism->getUMLModel()->getStateDiagram(0)->findPath(path1)) / path1.size());
-		bonus = ((org->getUMLModel()->getStateDiagram(0)->findPath(path1, 0, 0))); // / path1.size());
-
-	} else { 
-		bonus = org->getParentBonus("scenario4"); 
-	}
-	
-	// Set bonus info for current model
-	org->getUMLModel()->setBonusInfo("scenario4", bonus);		
-		
-	/*if (bonus == 3) { 
-		ctx.m_task_success_complete = ctx.m_task_success_complete && true;
-	} else { 
-		ctx.m_task_success_complete = false;	
-	}*/
-	
-	return bonus;
-}
-
-double cTaskLib::Task_Scenario5(cTaskContext& ctx) const
-{
-	double bonus = 0.0; 
-	std::deque<std::string> path1;
-	cOrganism* org = ctx.getOrganism();
-		
-	// Check if this model is different than the organism's parent's model
-	if (org->getParentXMI() != org->getUMLModel()->getXMI()) {
-		
-		// create the scenario
-		path1.push_back("timerEvent[]/");
-		path1.push_back("[]/^SensorInterface.readObstacleSensor()");
-		path1.push_back("sensorData[]/");
-		path1.push_back("[obstacle=1]/^WheelActuatorInterface.stop()");
-		path1.push_back("wheelStopped[]/");
-		path1.push_back("[]/^NavigationControl.suspend()");
-		path1.push_back("[]/^SensorInterface.readObstacleSensor()");
-		path1.push_back("sensorData[]/");
-		path1.push_back("[]/^NavigationControl.restart()");
-// sequence is repeated to encourage looping.		
-		path1.push_back("timerEvent[]/");
-		path1.push_back("[]/^SensorInterface.readObstacleSensor()");
-		path1.push_back("sensorData[]/");
-		path1.push_back("[obstacle=1]/^WheelActuatorInterface.stop()");
-		path1.push_back("wheelStopped[]/");
-		path1.push_back("[]/^NavigationControl.suspend()");
-		path1.push_back("[]/^SensorInterface.readObstacleSensor()");
-		path1.push_back("sensorData[]/");
-		path1.push_back("[]/^NavigationControl.restart()");
-		path1.push_back("timerEvent[]/");
-		path1.push_back("[]/^SensorInterface.readObstacleSensor()");
-		path1.push_back("sensorData[]/");
-		path1.push_back("[obstacle=1]/^WheelActuatorInterface.stop()");
-		path1.push_back("wheelStopped[]/");
-		path1.push_back("[]/^NavigationControl.suspend()");
-		path1.push_back("[]/^SensorInterface.readObstacleSensor()");
-		path1.push_back("sensorData[]/");
-		path1.push_back("[]/^NavigationControl.restart()");
-		
-		// check for scneario
-		bonus = ((org->getUMLModel()->getStateDiagram(0)->findPath(path1, 0, 0))); // / path1.size());
-
-	} else { 
-		bonus = org->getParentBonus("scenario5"); 
-	}
-	
-	// Track in stats.
-	if (bonus == 9) { 
-		m_world->GetStats().scenario5Complete();
-	}else if (bonus >= 18) { 
-		m_world->GetStats().scenario5Loop();
-	} 
-	
-	// Set bonus info for current model
-	org->getUMLModel()->setBonusInfo("scenario5", bonus);		
-	
-	return bonus;
-}
-
-double cTaskLib::Task_Scenario6(cTaskContext& ctx) const
-{
-	double bonus = 0.0; 
-	std::deque<std::string> path1;
-	cOrganism* org = ctx.getOrganism();
-	
-	// Check if this model is different than the organism's parent's model
-	if (org->getParentXMI() != org->getUMLModel()->getXMI()) {
-		
-		// create the scenario
-		path1.push_back("timerEvent[]/");
-		path1.push_back("[]/^SensorInterface.readObstacleSensor()");
-		path1.push_back("sensorData[]/");
-		path1.push_back("[obstacle=0]/");
-// sequence is repeated to encourage looping.		
-		path1.push_back("timerEvent[]/");
-		path1.push_back("[]/^SensorInterface.readObstacleSensor()");
-		path1.push_back("sensorData[]/");
-		path1.push_back("[obstacle=0]/");
-		path1.push_back("timerEvent[]/");
-		path1.push_back("[]/^SensorInterface.readObstacleSensor()");
-		path1.push_back("sensorData[]/");
-		path1.push_back("[obstacle=0]/");
-	
-		// check for scneario
-		bonus = ((org->getUMLModel()->getStateDiagram(0)->findPath(path1, 0, 0))); // / path1.size());
-
-	} else { 
-		bonus = org->getParentBonus("scenario6"); 
-	}
-	
-	// Track in stats.
-	if (bonus == 4) { 
-		m_world->GetStats().scenario6Complete();
-	} else if (bonus >= 8) { 
-		m_world->GetStats().scenario6Loop();
-	} 
-	
-	// Set bonus info for current model
-	org->getUMLModel()->setBonusInfo("scenario6", bonus);		
-	
-	return bonus;
-}
-
-double cTaskLib::Task_Scenario7(cTaskContext& ctx) const
-{
-	double bonus = 0.0; 
-	std::deque<std::string> path1;
-	cOrganism* org = ctx.getOrganism();
-	
-	// Check if this model is different than the organism's parent's model
-	if (org->getParentXMI() != org->getUMLModel()->getXMI()) {
-		
-		// create the scenario
-		path1.push_back("readObstacleSensors[]/");
-		path1.push_back("[]/^Environment.checkForObstacle()");
-		path1.push_back("setObstacleSensors[]/^ObstacleAvoidanceTimer.sensorData(obstacle)");
-// sequence is repeated to encourage looping.		
-		path1.push_back("readObstacleSensors[]/");
-		path1.push_back("[]/^Environment.checkForObstacle()");
-		path1.push_back("setObstacleSensors[]/^ObstacleAvoidanceTimer.sensorData(obstacle)");		
-		path1.push_back("readObstacleSensors[]/");
-		path1.push_back("[]/^Environment.checkForObstacle()");
-		path1.push_back("setObstacleSensors[]/^ObstacleAvoidanceTimer.sensorData(obstacle)");		
-	
-		// check for scneario
-		bonus = ((org->getUMLModel()->getStateDiagram(0)->findPath(path1, 0, 0))); // / path1.size());
-
-	} else { 
-		bonus = org->getParentBonus("scenario7"); 
-	}
-	
-	// Track in stats.
-	if (bonus >= 3) { 
-		m_world->GetStats().scenario7Complete();
-	} else if (bonus >= 6) { 
-		m_world->GetStats().scenario7Loop();
-	} 
-	
-	// Set bonus info for current model
-	org->getUMLModel()->setBonusInfo("scenario7", bonus);		
-	
-	return bonus;
-}
-
-double cTaskLib::Task_Scenario8(cTaskContext& ctx) const
-{
-	double bonus = 0.0; 
-	std::deque<std::string> path1;
-	cOrganism* org = ctx.getOrganism();
-	
-	// Check if this model is different than the organism's parent's model
-	if (org->getParentXMI() != org->getUMLModel()->getXMI()) {
-		
-		// create the scenario
-		path1.push_back("suspend[]/^NavigationTimer.stopTimer()");
-		path1.push_back("restart[]/^WheelActuatorInterface.start()");
-// sequence is repeated to encourage looping.		
-		
-	
-		// check for scneario
-		bonus = ((org->getUMLModel()->getStateDiagram(0)->findPath(path1, 0, -1))); // / path1.size());
-
-	} else { 
-		bonus = org->getParentBonus("scenario8"); 
-	}
-	
-	// Track in stats.
-	if (bonus >= 2) { 
-		m_world->GetStats().scenario8Complete();
-	} /*else if (bonus >= 6) { 
-		m_world->GetStats().scenario8Loop();
-	} */
-	
-	// Set bonus info for current model
-	org->getUMLModel()->setBonusInfo("scenario8", bonus);		
-	
-	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-08-07 21:52:57 UTC (rev 1905)
+++ branches/uml/source/main/cTaskLib.h	2007-08-08 12:41:26 UTC (rev 1906)
@@ -287,14 +287,7 @@
   double Task_Trans8(cTaskContext& ctx) const;
   double Task_Trans9(cTaskContext& ctx) const;   
   double Task_Trans10(cTaskContext& ctx) const;
-  double Task_Scenario1(cTaskContext& ctx) const;
-  double Task_Scenario2(cTaskContext& ctx) const;
-  double Task_Scenario3(cTaskContext& ctx) const;
-  double Task_Scenario4(cTaskContext& ctx) const;
-  double Task_Scenario5(cTaskContext& ctx) const;
-  double Task_Scenario6(cTaskContext& ctx) const;
-  double Task_Scenario7(cTaskContext& ctx) const;
-  double Task_Scenario8(cTaskContext& ctx) const;
+  double Task_Scenarios(cTaskContext& ctx) const;
   double Task_NumStates(cTaskContext& ctx) const;
   double Task_NumTrans(cTaskContext& ctx) const;
   double Task_PropTrigger(cTaskContext& ctx) const;

Modified: branches/uml/source/main/cUMLModel.cc
===================================================================
--- branches/uml/source/main/cUMLModel.cc	2007-08-07 21:52:57 UTC (rev 1905)
+++ branches/uml/source/main/cUMLModel.cc	2007-08-08 12:41:26 UTC (rev 1906)
@@ -74,27 +74,24 @@
 	int num_states;
 	int num_sd = 0;
 	int cur_sd = -1;
-//	char c;
 	std::string tr_l, tr_o, gu, act, temp;
 	int trig_i, guard_i, act_i, orig_i, dest_i;
 	std::ifstream infile;
 	infile.open("seed-model.cfg");
 	assert(infile.is_open());
+	scenario_info s;
+	std::string path_step;
 	
 	while (getline (infile, line))
 	{
 		// Read in states
 		if (line == "=STATES====================") {
-//			std::cout << "Ooh, I found a state! " << std::endl;
 			line.erase();
 			infile >> num_states;
-//			std::cout << "Numer of states: "<< num_states << std::endl;
 		// Read in number of state diagrams	
 		} else if (line == "=STATE-DIAGRAM=============") { 
-//			std::cout << "Yippee! A state diagram for me! " << std::endl;
 			line.erase();
 			infile >> num_sd;
-//			std::cout << "Numer of sds: "<< num_sd << std::endl;
 			state_diagrams.resize(num_sd);
 		// Read in each state diagram	
 		} else if (line == "=SD========================") { 
@@ -106,7 +103,6 @@
 			while (tr_l != "-END---------------------------") { 
 				infile >> tr_o;
 				state_diagrams[cur_sd].addTrigger(tr_l, tr_o);
-//				std::cout << "Adding a trigger " << tr_l << " " << tr_o << std::endl;
 				infile >> tr_l;
 			}
 		}else if (line == "-GUARDS--------------------") { 
@@ -114,7 +110,6 @@
 			infile >> gu;
 			while (gu != "-END---------------------------") { 
 				state_diagrams[cur_sd].addGuard(gu);
-//				std::cout << "Adding a guard " << gu << std::endl;
 				infile >> gu;
 			}
 		} else if (line == "-ACTIONS--------------------") { 
@@ -122,20 +117,30 @@
 			infile >> act;
 			while (act != "-END---------------------------") { 
 				state_diagrams[cur_sd].addAction(act);
-//				std::cout << "Adding an action " << act << std::endl;
 				infile >> act;
 			}
 		} else if (line == "-TRANSITIONS---------------") { 
 			line.erase();
 			infile >> temp; 
 			while (temp != "-END---------------------------") { 
-//				std::cout << "Ug in here again. Curr sd: " << cur_sd << std::endl;
 				infile >> orig_i >> dest_i >> trig_i >> guard_i >> act_i; 
 				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);
+			
 		}
-
 		
 		/* Missing code for reading in transition labels .... */
 		
@@ -222,3 +227,24 @@
 	return state_diagrams.size();
 }
 
+double cUMLModel::checkForScenarios()
+{
+	double total_bonus;
+	double temp_bonus;
+	scenario_info s;
+	
+	// Should check to see if each scenario is satisfied.
+	// Iterate through list of scnearios; Call each scenario on the appropriate state diagram
+	// Accrue results.
+	// Save bonus info.
+	for (unsigned int i=0; i< scenarios.size(); i++) { 
+		s = scenarios[i];
+		temp_bonus = getStateDiagram(s.stateDiagramID)->findPath(s.path, s.shouldLoop, s.startState);
+		std::cout << "TEMP BONUS: " << temp_bonus << std::endl;
+		total_bonus += temp_bonus;
+	}
+	
+	return total_bonus;
+}
+
+

Modified: branches/uml/source/main/cUMLModel.h
===================================================================
--- branches/uml/source/main/cUMLModel.h	2007-08-07 21:52:57 UTC (rev 1905)
+++ branches/uml/source/main/cUMLModel.h	2007-08-08 12:41:26 UTC (rev 1906)
@@ -12,6 +12,13 @@
 #include <fstream>
 
 
+struct scenario_info { 
+	int stateDiagramID;
+	std::deque<std::string> path; 
+	bool shouldLoop;
+	int startState;
+};
+
 class cUMLModel { 
 public:
 	cUMLModel();
@@ -20,6 +27,9 @@
 	// Read in from file seed-model.cfg and add the building blocks for the diagrams.
 	void seedDiagrams(); 
 	
+	// Used to check if the diagrams satisfy the specified scenarios
+	double checkForScenarios();
+	
 	// Used to generate and access the XMI version of the model.
 	std::string getXMI(); // get the XMI version of the model.
 	void printXMI(); // create the XMI version of the model.	
@@ -54,6 +64,8 @@
 	static int max_trans;
 	std::vector<cUMLStateDiagram> state_diagrams;
 	std::map<std::string, float> bonus_info;
+	std::vector<scenario_info> scenarios;
+
 										
 };
 

Modified: branches/uml/source/main/cUMLStateDiagram.h
===================================================================
--- branches/uml/source/main/cUMLStateDiagram.h	2007-08-07 21:52:57 UTC (rev 1905)
+++ branches/uml/source/main/cUMLStateDiagram.h	2007-08-08 12:41:26 UTC (rev 1906)
@@ -28,7 +28,6 @@
 	int action;
 };
 
-
 struct state {
 	int identifier;
 	int num_incoming;




More information about the Avida-cvs mailing list