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

hjg at myxo.css.msu.edu hjg at myxo.css.msu.edu
Tue Aug 7 14:15:19 PDT 2007


Author: hjg
Date: 2007-08-07 17:15:19 -0400 (Tue, 07 Aug 2007)
New Revision: 1904

Modified:
   branches/uml/source/main/cStats.cc
   branches/uml/source/main/cStats.h
   branches/uml/source/main/cTaskLib.cc
   branches/uml/source/main/cTaskLib.h
   branches/uml/source/main/cUMLModel.cc
   branches/uml/source/main/cUMLStateDiagram.cc
   branches/uml/source/main/cUMLStateDiagram.h
Log:
fixed stats for scenario 7

Modified: branches/uml/source/main/cStats.cc
===================================================================
--- branches/uml/source/main/cStats.cc	2007-08-07 21:09:59 UTC (rev 1903)
+++ branches/uml/source/main/cStats.cc	2007-08-07 21:15:19 UTC (rev 1904)
@@ -1027,8 +1027,12 @@
 */	
 	df.Write( m_scenario5.Sum(), "total number of scenario 5 all transitions");
 	df.Write( m_scenario6.Sum(), "total number of scenario 6 all transitions");
+	df.Write( m_scenario7.Sum(), "total number of scenario 7 all transitions");
+	df.Write( m_scenario8.Sum(), "total number of scenario 8 all transitions");
+
 	df.Write( m_scenario5loop.Sum(), "total number of scenario 5 all transitions - might loop");	
 	df.Write( m_scenario6loop.Sum(), "total number of scenario 6 all transitions - might loop");
+	df.Write( m_scenario7loop.Sum(), "total number of scenario 7 all transitions - might loop");
 
 	
 	av_number_of_states.Clear();
@@ -1052,8 +1056,13 @@
   m_N1andN2Passed.Clear();
   m_scenario5.Clear();
   m_scenario6.Clear();
+  m_scenario7.Clear();
+  m_scenario8.Clear();
+
   m_scenario5loop.Clear();
   m_scenario6loop.Clear();
+  m_scenario7loop.Clear();
 
+
 df.Endl();
 }

Modified: branches/uml/source/main/cStats.h
===================================================================
--- branches/uml/source/main/cStats.h	2007-08-07 21:09:59 UTC (rev 1903)
+++ branches/uml/source/main/cStats.h	2007-08-07 21:15:19 UTC (rev 1904)
@@ -272,6 +272,8 @@
   cDoubleSum m_scenario5;
   cDoubleSum m_scenario6;
   cDoubleSum m_scenario7;
+  cDoubleSum m_scenario8;
+
   cDoubleSum m_scenario5loop;
   cDoubleSum m_scenario6loop;
   cDoubleSum m_scenario7loop;
@@ -658,6 +660,7 @@
   void scenario5Complete() { m_scenario5.Add(1); } 
   void scenario6Complete() { m_scenario6.Add(1); } 
   void scenario7Complete() { m_scenario7.Add(1); } 
+  void scenario8Complete() { m_scenario8.Add(1); } 
   void scenario5Loop() { m_scenario5loop.Add(1); } 
   void scenario6Loop() { m_scenario6loop.Add(1); } 
   void scenario7Loop() { m_scenario7loop.Add(1); } 

Modified: branches/uml/source/main/cTaskLib.cc
===================================================================
--- branches/uml/source/main/cTaskLib.cc	2007-08-07 21:09:59 UTC (rev 1903)
+++ branches/uml/source/main/cTaskLib.cc	2007-08-07 21:15:19 UTC (rev 1904)
@@ -420,6 +420,8 @@
 	  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 == "numStates") // 
 	  NewTask(name, "Successfully created 5 states", &cTaskLib::Task_NumStates);  	  
   else if (name == "numTrans") // 
@@ -2966,7 +2968,7 @@
 	
 		// check for scneario
 //		bonus = ((ctx.organism->getUMLModel()->getStateDiagram(1)->findPath(path1)) / path1.size());
-		bonus = ((org->getUMLModel()->getStateDiagram(1)->findPath(path1))); // / path1.size());
+		bonus = ((org->getUMLModel()->getStateDiagram(1)->findPath(path1, 0, 0))); // / path1.size());
 
 	} else { 
 		bonus = org->getParentBonus("scenario1"); 
@@ -3007,7 +3009,7 @@
 	
 		// check for scneario
 		//bonus = ((ctx.organism->getUMLModel()->getStateDiagram(1)->findPath(path1)) / path1.size());
-		bonus = ((org->getUMLModel()->getStateDiagram(1)->findPath(path1))); // / path1.size());
+		bonus = ((org->getUMLModel()->getStateDiagram(1)->findPath(path1, 0, 0))); // / path1.size());
 		
 	} else { 
 		bonus = org->getParentBonus("scenario2"); 
@@ -3050,7 +3052,7 @@
 	
 		// check for scneario
 		//bonus = ((ctx.organism->getUMLModel()->getStateDiagram(0)->findPath(path1)) / path1.size());
-		bonus = ((org->getUMLModel()->getStateDiagram(0)->findPath(path1))); // / path1.size());
+		bonus = ((org->getUMLModel()->getStateDiagram(0)->findPath(path1, 0, 0))); // / path1.size());
 
 	} else { 
 		bonus = org->getParentBonus("scenario3"); 
@@ -3094,7 +3096,7 @@
 	
 		// check for scneario
 //		bonus = ((ctx.organism->getUMLModel()->getStateDiagram(0)->findPath(path1)) / path1.size());
-		bonus = ((org->getUMLModel()->getStateDiagram(0)->findPath(path1))); // / path1.size());
+		bonus = ((org->getUMLModel()->getStateDiagram(0)->findPath(path1, 0, 0))); // / path1.size());
 
 	} else { 
 		bonus = org->getParentBonus("scenario4"); 
@@ -3152,7 +3154,7 @@
 		path1.push_back("[]/^NavigationControl.restart()");
 		
 		// check for scneario
-		bonus = ((org->getUMLModel()->getStateDiagram(0)->findPath(path1))); // / path1.size());
+		bonus = ((org->getUMLModel()->getStateDiagram(0)->findPath(path1, 0, 0))); // / path1.size());
 
 	} else { 
 		bonus = org->getParentBonus("scenario5"); 
@@ -3196,7 +3198,7 @@
 		path1.push_back("[obstacle=0]/");
 	
 		// check for scneario
-		bonus = ((org->getUMLModel()->getStateDiagram(0)->findPath(path1))); // / path1.size());
+		bonus = ((org->getUMLModel()->getStateDiagram(0)->findPath(path1, 0, 0))); // / path1.size());
 
 	} else { 
 		bonus = org->getParentBonus("scenario6"); 
@@ -3237,7 +3239,7 @@
 		path1.push_back("setObstacleSensors[]/^ObstacleAvoidanceTimer.sensorData(obstacle)");		
 	
 		// check for scneario
-		bonus = ((org->getUMLModel()->getStateDiagram(0)->findPath(path1))); // / path1.size());
+		bonus = ((org->getUMLModel()->getStateDiagram(0)->findPath(path1, 0, 0))); // / path1.size());
 
 	} else { 
 		bonus = org->getParentBonus("scenario7"); 
@@ -3256,7 +3258,42 @@
 	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(1)->findPath(path1, 0, -1))); // / path1.size());
 
+	} else { 
+		bonus = org->getParentBonus("scenario8"); 
+	}
+	
+	// Track in stats.
+	if (bonus >= 3) { 
+		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:09:59 UTC (rev 1903)
+++ branches/uml/source/main/cTaskLib.h	2007-08-07 21:15:19 UTC (rev 1904)
@@ -294,6 +294,7 @@
   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_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:09:59 UTC (rev 1903)
+++ branches/uml/source/main/cUMLModel.cc	2007-08-07 21:15:19 UTC (rev 1904)
@@ -134,7 +134,6 @@
 				state_diagrams[cur_sd].addTransitionTotal(orig_i, dest_i, trig_i, guard_i, act_i);
 				infile >> temp; 
 			}
-		
 		}
 
 		
@@ -142,7 +141,7 @@
 		
 		line.erase();
 	}
-	
+		
 	//read from file; load into string/strstream, and return it.
 	infile.close();
 

Modified: branches/uml/source/main/cUMLStateDiagram.cc
===================================================================
--- branches/uml/source/main/cUMLStateDiagram.cc	2007-08-07 21:09:59 UTC (rev 1903)
+++ branches/uml/source/main/cUMLStateDiagram.cc	2007-08-07 21:15:19 UTC (rev 1904)
@@ -4,7 +4,7 @@
 {
 
   // initialize the state diagram with 10 states.
-  sd0 = state_diagram(10); 
+  sd0 = state_diagram(12); 
 
   // initialize / seed UML state diagram here
 //  orig_state_index = 0;
@@ -31,27 +31,29 @@
 // The function is complicated by the fact that the longest path segment could start at the 
 // beginning, middle, or end of the path itself. 
 // Currently the path must begin at the 0 vertex. 
-int cUMLStateDiagram::findPath(std::deque<std::string> p) { 
+int cUMLStateDiagram::findPath(std::deque<std::string> p, bool should_loop, int start_state) { 
 	unsigned int path_dist = 0; // the current path distance satisfied is 0. 
 //	int path_longest_length = 0; 
 	unsigned int len = 0;
 	int num_vert = num_vertices(sd0);
 	std::deque<std::string> p_temp = p;
-
+	int actual_path_start;
+			
 	// Entire path must start at state 0. 
-	len = checkForPathStep(p, vertex(0, sd0), 0);
+//	len = checkForPathStep(p, vertex(0, sd0), 0);
 	// If this returns a length, then the path is found & we can exit.
-	if (len > 0) { 
-		path_dist = len;
-	} else { 
+//	if (len > 0) { 
+//		path_dist = len;
+//	} else { 
 	// Else, check for partial paths, which can start from anywhere... 
-		p.pop_front();
+//		p.pop_front();
 		// Must check each state other than state 0.
 		while (!p.empty()) {
-			for (int i = 1; i<num_vert; i++) { 
+			for (int i = 0; i<num_vert; i++) { 
 				len = checkForPathStep(p, vertex(i, sd0), 0);
 				// check to see if this path is longer than other paths....
 				if (len > path_dist) { 
+					actual_path_start = i;
 					path_dist = len;
 				}	
 			}	
@@ -60,8 +62,17 @@
 			if (len > p.size()) break;
 		} 
 	 
-	} 
+	//} 
 	
+	
+	if (start_state != -1) { 
+		if (start_state == actual_path_start) { 
+			path_dist += 1;
+		}
+	}
+
+	
+	
 	return path_dist;
 }
 
@@ -75,7 +86,9 @@
 	int longest_dist = curr_dist;
 	int temp;
 
-	if (path.empty()) return curr_dist;
+	if (path.empty()) {
+		return curr_dist;
+	}	
 
 	// Get the outgoing edges of v
 	for(tie(out_edge_start, out_edge_end) = out_edges(v, sd0);
@@ -101,7 +114,10 @@
 				//std::cout << "Searching vertex " << target(ed, sd0) << "with distance " << curr_dist+1 << std::endl; 
 
 				temp = checkForPathStep(std::deque<std::string>(++path.begin(), path.end()), target(ed,sd0), curr_dist+1);
-				if (temp > longest_dist) longest_dist = temp;
+				
+				if (temp > longest_dist) {
+					longest_dist = temp;
+				}	
 			}
 	}
 	

Modified: branches/uml/source/main/cUMLStateDiagram.h
===================================================================
--- branches/uml/source/main/cUMLStateDiagram.h	2007-08-07 21:09:59 UTC (rev 1903)
+++ branches/uml/source/main/cUMLStateDiagram.h	2007-08-07 21:15:19 UTC (rev 1904)
@@ -129,9 +129,10 @@
   
   
 // Implement a scenario check.  
-//  void checkForPath(std::deque<std::string>, boost::graph_traits<state_diagram>::vertex_descriptor, bool&, int&);
-  int findPath(std::deque<std::string> p); 
-  int checkForPathStep(std::deque<std::string>, boost::graph_traits<state_diagram>::vertex_descriptor, int); 
+  int findPath(std::deque<std::string>, bool, int); 
+  int checkForPathStep(std::deque<std::string>, 
+		boost::graph_traits<state_diagram>::vertex_descriptor, int); 
+
   
 // The get functions get the value of the index of various vectors  
   int getTriggerIndex();




More information about the Avida-cvs mailing list