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

hjg at myxo.css.msu.edu hjg at myxo.css.msu.edu
Fri May 18 05:25:05 PDT 2007


Author: hjg
Date: 2007-05-18 08:25:05 -0400 (Fri, 18 May 2007)
New Revision: 1571

Modified:
   branches/uml/source/main/cOrganism.cc
   branches/uml/source/main/cOrganism.h
   branches/uml/source/main/cTaskLib.cc
   branches/uml/source/main/cUMLModel.cc
   branches/uml/source/main/cUMLStateDiagram.cc
   branches/uml/source/main/cUMLStateDiagram.h
Log:


Modified: branches/uml/source/main/cOrganism.cc
===================================================================
--- branches/uml/source/main/cOrganism.cc	2007-05-17 22:56:59 UTC (rev 1570)
+++ branches/uml/source/main/cOrganism.cc	2007-05-18 12:25:05 UTC (rev 1571)
@@ -682,7 +682,7 @@
 }
 
 // Determines if this is the transition the organism is about to add
-bool cOrganism::currTrans (int sd, int orig, int dest, std::string tr, std::string gu, std::string act)
+bool cOrganism::currTrans (int sd, int orig, int dest, int tr, int gu, int act)
 {
 	// check if it is manipulating this diagram 
 	if (sd != m_state_diag) return false;
@@ -740,11 +740,14 @@
 {
 	bool val;
 	val = getStateDiagram()->addTransitionTotal(m_orig_state_index, m_dest_state_index, m_trigger_index, m_guard_index, m_action_index);
-	m_orig_state_index = 0;
-	m_dest_state_index = 0;
-	m_trigger_index = 0;
-	m_action_index = 0;
-	m_guard_index = 0;
+	
+	if (val) {
+		m_orig_state_index = 0;
+		m_dest_state_index = 0;
+		m_trigger_index = 0;
+		m_action_index = 0;
+		m_guard_index = 0;
+	}	
 	return val;
 }
 

Modified: branches/uml/source/main/cOrganism.h
===================================================================
--- branches/uml/source/main/cOrganism.h	2007-05-17 22:56:59 UTC (rev 1570)
+++ branches/uml/source/main/cOrganism.h	2007-05-18 12:25:05 UTC (rev 1571)
@@ -311,7 +311,7 @@
   int getStateDiagramIndex() { return m_state_diag; } 
 //  bool lastStateDiagram () { m_state_diag = getUMLModel()->getStateDiagramSize(); }
 //  bool firstStateDiagram() { m_state_diag = 0; }  
-  bool currTrans (int, int, int, std::string, std::string, std::string); 
+  bool currTrans (int, int, int, int, int, int); 
   cUMLStateDiagram* getStateDiagram();
 
  

Modified: branches/uml/source/main/cTaskLib.cc
===================================================================
--- branches/uml/source/main/cTaskLib.cc	2007-05-17 22:56:59 UTC (rev 1570)
+++ branches/uml/source/main/cTaskLib.cc	2007-05-18 12:25:05 UTC (rev 1571)
@@ -2645,9 +2645,10 @@
 double cTaskLib::Task_Trans1(cTaskContext& ctx) const
 {
 	double bonus = 0.0;
-//	if (ctx.organism->getStateDiagram()->findTrans(0,1,1, "ga", "aa")) {
-	if (ctx.organism->currTrans(0, -1, -1, "*", "*", "^TempSensor.getOpState()")) {		
+//	if (ctx.organism->currTrans(0, -1, -1, -1, -1, "^TempSensor.getOpState()")) {		
+	if (ctx.organism->currTrans(0, -1, -1, -1, -1, 1)) {		
 
+
 		ctx.task_success_complete = 1;	
 		bonus = 1.0;
 	}
@@ -2659,9 +2660,10 @@
 double cTaskLib::Task_Trans2(cTaskContext& ctx) const
 {
 	double bonus = 0.0;
-//	if (ctx.organism->getStateDiagram()->findTrans(1,2,1,"gd", "ab")){
-	if (ctx.organism->currTrans(0, -1, -1, "setTempOpState", "*", "*")) {		
+//	if (ctx.organism->currTrans(0, -1, -1, "setTempOpState", -1, -1)) {		
+	if (ctx.organism->currTrans(0, -1, -1, 1, -1, -1)) {		
 
+
 			ctx.task_success_complete += 1;	
 			bonus = 1.0;
 	}
@@ -2673,9 +2675,10 @@
 double cTaskLib::Task_Trans3(cTaskContext& ctx) const
 {
 	double bonus = 0.0;
-//	if (ctx.organism->getStateDiagram()->findTrans(2,3,3,"gb", "ac")){
-	if (ctx.organism->currTrans(1, -1, -1, "getOpState", "*", "*")) {		
+//	if (ctx.organism->currTrans(1, -1, -1, "getOpState", -1, -1)) {		
+	if (ctx.organism->currTrans(1, -1, -1, 1, -1, -1)) {		
 
+
 			bonus = 1.0;
 			ctx.task_success_complete += 1;	
 	}
@@ -2687,8 +2690,8 @@
 double cTaskLib::Task_Trans4(cTaskContext& ctx) const
 {
 	double bonus = 0.0;
-//	if (ctx.organism->getStateDiagram()->findTrans(3,4,2,"gc", "ad")){
-	if (ctx.organism->currTrans(1, -1, -1, "*", "*", "op_state:=1")) {		
+//	if (ctx.organism->currTrans(1, -1, -1, -1, -1, "op_state:=1")) {		
+	if (ctx.organism->currTrans(1, -1, -1, -1, -1, 3)) {		
 
 			ctx.task_success_complete += 1;	
 			bonus = 1.0;
@@ -2701,9 +2704,10 @@
 double cTaskLib::Task_Trans5(cTaskContext& ctx) const
 {
 	double bonus = 0.0;
-//	if (ctx.organism->getStateDiagram()->findTrans(4,0,4,"ga","ac")){		
-	if (ctx.organism->currTrans(1, -1, -1, "*", "*", "^SoftwareSensor.setTempOpState(op_state)")) {		
+//	if (ctx.organism->currTrans(1, -1, -1, -1, -1, "^SoftwareSensor.setTempOpState(op_state)")) {		
+	if (ctx.organism->currTrans(1, -1, -1, -1, -1, 1)) {		
 
+
 			ctx.task_success_complete += 1;	
 			bonus = 1.0;
 	}
@@ -2873,14 +2877,14 @@
 */	
 	
 	// check if the trigger is present
-	if (organism->getStateDiagram()->findTrans(-1,-1,1,"*","*")){
-		temp += 1;
+//	if (organism->getStateDiagram()->findTrans(-1,-1,1,"*","*")){
+//		temp += 1;
 		
 		// check property
 		if (ctx.task_success_complete) {
 			temp1 += SpinCoprocess(ctx, "N1");
 		} 
-	}
+	//}
 	
 //	organism->setBonusInfo("spinn1", temp1); 
 	return temp1;

Modified: branches/uml/source/main/cUMLModel.cc
===================================================================
--- branches/uml/source/main/cUMLModel.cc	2007-05-17 22:56:59 UTC (rev 1570)
+++ branches/uml/source/main/cUMLModel.cc	2007-05-18 12:25:05 UTC (rev 1571)
@@ -77,47 +77,66 @@
   cUMLStateDiagram* soft_sense = getStateDiagram(0);
 	
   // init triggers, guards, and actions
+  // trig 0
   std::string trig_label = "<null>";
   std::string trig_operation_id = "<null>";
   soft_sense->addTrigger(trig_label, trig_operation_id);
+  // trig 1
   trig_label = "setTempOpState";
   trig_operation_id = "XDE-4437EBF1-9C42-4EB4-B7CF-415697B567CD";
   soft_sense->addTrigger(trig_label, trig_operation_id);
+  // trig 2
   trig_label = "setTempData";
   trig_operation_id = "XDE-9517D6BA-8666-4A82-AFEA-62D60FE37B07";
   soft_sense->addTrigger(trig_label, trig_operation_id);
+  // guard 0
   soft_sense->addGuard("<null>");
+  // action 0
   soft_sense->addAction("<null>");
+  // action 1
   soft_sense->addAction("^TempSensor.getOpState()");
+  // action 2
   soft_sense->addAction("^TempSensor.getTempData()");
   
   
   // null trans Init state to Idle state
-  soft_sense->absoluteJumpDestinationState(1);
-  soft_sense->addTransitionTotal(0, 1, 0, 0, 0);
+//  soft_sense->absoluteJumpDestinationState(1);
+//  soft_sense->addTransitionTotal(0, 1, 0, 0, 0);
   
   
   // Temperature Sensor
   cUMLStateDiagram* temp_sense = getStateDiagram(1);
 
   // init triggers, guards, and actions
+  // trig 0
   trig_label = "<null>";
   trig_operation_id = "<null>";
   temp_sense->addTrigger(trig_label, trig_operation_id);  
+  // trig 1
   trig_label = "getOpState";
   trig_operation_id = "XDE-73C1C501-493F-44F2-A70A-0C7BFA92160D";
   temp_sense->addTrigger(trig_label, trig_operation_id);
+  // trig 2
   trig_label = "getTempData";
   trig_operation_id = "XDE-7C41CD1F-6E52-4E32-9C8E-999BA1919EC6";
   temp_sense->addTrigger(trig_label, trig_operation_id);  
+  // guard 0
   temp_sense->addGuard("<null>");
+  // action 0
   temp_sense->addAction("<null>");
+  // action 1
   temp_sense->addAction("^SoftwareSensor.setTempOpState(op_state)");
+  // action 2
   temp_sense->addAction("^SoftwareSensor.setTempData(data)");
+  // action 3
   temp_sense->addAction("op_state:=1");
+  // action 4
   temp_sense->addAction("op_state:=0");
+  // action 5
   temp_sense->addAction("data:=100");
+  // action 6
   temp_sense->addAction("data:=200");
+  // action 7
   temp_sense->addAction("data:=300");
   
   
@@ -157,13 +176,13 @@
 	if (s0_nt <= 2) { 
 		bonus += (s0_nt / 2);
 	} else {
-		bonus += 2;
+		bonus += 1;
 	}
 	
 	if (s1_nt <= 2) { 
 		bonus += (s1_nt / 2);
 	} else {
-		bonus += 2;
+		bonus += 1;
 	}
 	
 	
@@ -197,13 +216,15 @@
 	
 	// action: 
 	// TempSensor.getOpState()
-	temp_bonus = soft_sense->findTrans(-1, -1, -1, "*", "^TempSensor.getOpState()");	
+//	temp_bonus = soft_sense->findTrans(-1, -1, -1, "*", "^TempSensor.getOpState()");	
+	temp_bonus = soft_sense->findTrans(-1, -1, -1, -1, 1);	
 	self_bonus["seq_d_1"] = temp_bonus;
 	bonus += temp_bonus;
 			
 	// trigger:
 	// setTempOpState(op_state)
-	temp_bonus = soft_sense->findTrans(-1, -1, 1, "*", "*");
+//	temp_bonus = soft_sense->findTrans(-1, -1, 1, "*", "*");
+	temp_bonus = soft_sense->findTrans(-1, -1, 1, -1, -1);
 	self_bonus["seq_d_2"] = temp_bonus;
 	bonus += temp_bonus;		
 
@@ -212,18 +233,22 @@
 	
 	// trigger:
 	// getOpState()
-	temp_bonus = temp_sense->findTrans(-1, -1, 1, "*", "*");		
+	temp_bonus = temp_sense->findTrans(-1, -1, 1, -1, -1);		
 	self_bonus["seq_d_3"] = temp_bonus;
 	bonus += temp_bonus;
 	
 			
 	// action:
 	// op_state := 1
-	temp_bonus = temp_sense->findTrans(-1, -1, -1, "*", "op_state:=1");		
+	//temp_bonus = temp_sense->findTrans(-1, -1, -1, "*", "op_state:=1");		
+	temp_bonus = temp_sense->findTrans(-1, -1, -1, -1, 3);		
+
 	self_bonus["seq_d_4"] = temp_bonus;
 	bonus += temp_bonus;
 
-	temp_bonus = temp_sense->findTrans(-1, -1, -1, "*", "^SoftwareSensor.setTempOpState(op_state)");
+//	temp_bonus = temp_sense->findTrans(-1, -1, -1, "*", "^SoftwareSensor.setTempOpState(op_state)");
+	temp_bonus = temp_sense->findTrans(-1, -1, -1, -1, 1);
+
 	self_bonus["seq_d_5"] = temp_bonus;
 	bonus += temp_bonus;
 	

Modified: branches/uml/source/main/cUMLStateDiagram.cc
===================================================================
--- branches/uml/source/main/cUMLStateDiagram.cc	2007-05-17 22:56:59 UTC (rev 1570)
+++ branches/uml/source/main/cUMLStateDiagram.cc	2007-05-18 12:25:05 UTC (rev 1571)
@@ -31,6 +31,7 @@
 }
 
 
+/*
 bool cUMLStateDiagram::findTransLabel(transition_label t) { 
 	for(std::vector<transition_label>::iterator i=transition_labels.begin(); i!=transition_labels.end(); ++i){
 		if ((i->trigger == t.trigger) && (i->guard == t.guard) && (i->action == t.action)) {
@@ -40,6 +41,8 @@
 	return false;
 }
 
+
+
 bool cUMLStateDiagram::findTrans(int orig, int dest, std::string tr, std::string gu, std::string act) 
 {
 	int tracker = 0;
@@ -54,6 +57,7 @@
 	return false;
 }
 
+// Check to see if i->trans.trigger is ever equal to trig
 bool cUMLStateDiagram::findTrans(int orig, int dest, int trig, std::string gu, std::string act) 
 {
 	// the wild cards for there are 
@@ -71,8 +75,24 @@
 	}
 	return false;
 }
+*/
 
+bool cUMLStateDiagram::findTrans(int orig, int dest, int trig, int gu, int act) 
+{
+	for(std::vector<transition>::iterator i=transitions.begin(); i!=transitions.end(); ++i){
+		if (((orig == -1) || (orig == i->orig_state)) && 
+			((dest == -1) || (dest == i->dest_state)) && 
+			((trig == -1) || (trig == i->trans.trigger)) && 
+			((gu == -1) || (gu == i->trans.guard)) &&
+			((act == -1) || (act == i->trans.action))) { 
+						return true;
+			}
+	}
+	return false;
 
+}
+
+
 template <typename T>
 bool cUMLStateDiagram::absoluteMoveIndex (T x, int &index, int amount )
 {
@@ -168,30 +188,18 @@
 
 int cUMLStateDiagram::getTriggerIndex()
 {
-	/*if (triggers.size() == 0) {
-		return 0;
-	} else {*/
-	
-		return trigger_index;
-	//}
+	return trigger_index;
 }
 
-std::string cUMLStateDiagram::getGuard()
+int cUMLStateDiagram::getGuardIndex()
 {
-	if (guards.size() == 0) {
-		return "";
-	} else {
-		return guards[guard_index];
-	}
+		return guard_index;
 }
 
-std::string cUMLStateDiagram::getAction()
+int cUMLStateDiagram::getActionIndex()
 {
-	if (actions.size() == 0) {
-		return "";
-	} else {
-		return actions[action_index];
-	}
+		return action_index;
+	
 }
 
 int cUMLStateDiagram::getOrigStateIndex()
@@ -328,8 +336,8 @@
 	
 	transition_label tl;
 	tl.trigger = getTriggerIndex();
-	tl.guard = getGuard();
-	tl.action = getAction();
+	tl.guard = getGuardIndex();
+	tl.action = getActionIndex();
 	trany.trans = tl;
 	
 	
@@ -354,14 +362,14 @@
 }
 
 
-bool cUMLStateDiagram::currTrans(int orig, int dest, std::string tr, std::string gu, std::string act)
+bool cUMLStateDiagram::currTrans(int orig, int dest, int tr, int gu, int act)
 {
 
 	if (((orig == -1) || (orig == getOrigStateIndex())) &&
 		((dest == -1) || (dest == getDestStateIndex())) && 
-		((tr == "*") || (tr == triggers[getTriggerIndex()].label)) &&
-		((gu == "*") || (gu == getGuard())) &&
-		((act == "*") || (act == getAction()))) { 
+		((tr == -1)  || (tr == getTriggerIndex())) &&
+		((gu == -1)  || (gu == getGuardIndex())) &&
+		((act == -1) || (act == getActionIndex()))) { 
 
 			return true;
 	}
@@ -413,12 +421,13 @@
 
 	// This state is the initial state; thus it should be printed regardless of whether it has an incoming
 	// edge or not.
-	if (numStates() > 0) {
-		temp = StringifyAnInt(s_count);
+	// Initial state - designed to help with Hydra.
+//	if (numStates() > 0) {
+		temp = "_1";
 		xmi += "<UML:Pseudostate xmi.id=\"s" + temp + "\" kind=\"initial\" outgoing=\"\" name=\"s";
 		xmi += temp + "\" isSpecification=\"false\"/>\n";
 		++s_count;
-	}
+//	}
 	
 	for (; s_count < numStates(); ++s_count) {
 	
@@ -456,8 +465,8 @@
 
 		// Get guard, trigger, and action
 //		temp = transitions[t_count].trans.trigger;
-		temp1 = transitions[t_count].trans.guard;
-		temp2 = transitions[t_count].trans.action;
+		temp1 = guards[transitions[t_count].trans.guard];
+		temp2 = actions[transitions[t_count].trans.action];
 		trig_label = triggers[transitions[t_count].trans.trigger].label;
 		trig_op_name = triggers[transitions[t_count].trans.trigger].operation_id;
 

Modified: branches/uml/source/main/cUMLStateDiagram.h
===================================================================
--- branches/uml/source/main/cUMLStateDiagram.h	2007-05-17 22:56:59 UTC (rev 1570)
+++ branches/uml/source/main/cUMLStateDiagram.h	2007-05-18 12:25:05 UTC (rev 1571)
@@ -9,8 +9,10 @@
 
 struct transition_label { 
 	int trigger;
-	std::string guard;
-	std::string action;
+//	std::string guard;
+	int guard;
+//	std::string action;
+	int action;
 };
 
 struct  transition {
@@ -62,10 +64,11 @@
   int numStates();
   int numTrans();
 
-  bool findTrans(int, int, int, std::string, std::string) ;
-  bool findTrans(int, int, std::string, std::string, std::string);
+//  bool findTrans(int, int, int, std::string, std::string) ;
+//  bool findTrans(int, int, std::string, std::string, std::string);
+  bool findTrans(int, int, int, int, int);
   bool findTransLabel(transition_label); // find a specific transition label
-  bool currTrans(int, int, std::string, std::string, std::string);
+  bool currTrans(int, int, int, int, int);
 
 
 // These functions have been moved to the organism.
@@ -120,8 +123,8 @@
 //  std::string getTriggerIndex();
 
   int getTriggerIndex();
-  std::string getGuard();
-  std::string getAction();
+  int getGuardIndex();
+  int getActionIndex();
   transition_label getTransLabel();
   int getOrigStateIndex();
   int getDestStateIndex();




More information about the Avida-cvs mailing list