[Avida-SVN] r2095 - in branches/uml/source: cpu main

hjg at myxo.css.msu.edu hjg at myxo.css.msu.edu
Mon Sep 17 07:55:34 PDT 2007


Author: hjg
Date: 2007-09-17 10:55:34 -0400 (Mon, 17 Sep 2007)
New Revision: 2095

Modified:
   branches/uml/source/cpu/cHardwareCPU.cc
   branches/uml/source/cpu/cHardwareCPU.h
   branches/uml/source/main/cUMLStateDiagram.cc
   branches/uml/source/main/cUMLStateDiagram.h
Log:

Added code to enable a transition to be removed from a state diagram. 




Modified: branches/uml/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/uml/source/cpu/cHardwareCPU.cc	2007-09-17 14:00:06 UTC (rev 2094)
+++ branches/uml/source/cpu/cHardwareCPU.cc	2007-09-17 14:55:34 UTC (rev 2095)
@@ -442,7 +442,7 @@
 					"Change the destination to state 11"),		
 	tInstLibEntry<tMethod>("s-dest-12", &cHardwareCPU::Inst_DestState12, false, 
 							 "Change the destination to state 12"),	  
-	tInstLibEntry<tMethod>("trans-0", &cHardwareCPU::Inst_TransLab0, false, 
+/*	tInstLibEntry<tMethod>("trans-0", &cHardwareCPU::Inst_TransLab0, false, 
 					"Change to transition label 0"),		
 	tInstLibEntry<tMethod>("trans-1", &cHardwareCPU::Inst_TransLab1, false, 
 					"Change to transition label 1"),		
@@ -466,6 +466,7 @@
 					"Change to transition label 10"),		
 	tInstLibEntry<tMethod>("trans-11", &cHardwareCPU::Inst_TransLab11, false, 
 					"Change to transition label 11"),	
+*/
 					
 	tInstLibEntry<tMethod>("trig-0", &cHardwareCPU::Inst_Trigger0, false, 
 					"Change to trigger 0"),	
@@ -4915,7 +4916,7 @@
 bool cHardwareCPU::Inst_DestState12(cAvidaContext& ctx)
 { return (organism->getStateDiagram()->absoluteJumpDestinationState(12)); }
 
-bool cHardwareCPU::Inst_TransLab0(cAvidaContext& ctx)
+/*bool cHardwareCPU::Inst_TransLab0(cAvidaContext& ctx)
 { return (organism->getStateDiagram()->absoluteJumpTransitionLabel(0)); }
 
 bool cHardwareCPU::Inst_TransLab1(cAvidaContext& ctx)
@@ -4951,7 +4952,7 @@
 
 bool cHardwareCPU::Inst_TransLab11(cAvidaContext& ctx)
 { return (organism->getStateDiagram()->absoluteJumpTransitionLabel(11)); }
-
+*/
 bool cHardwareCPU::Inst_Trigger0(cAvidaContext& ctx)
 { return (organism->getStateDiagram()->absoluteJumpTrigger(0)); }
 

Modified: branches/uml/source/cpu/cHardwareCPU.h
===================================================================
--- branches/uml/source/cpu/cHardwareCPU.h	2007-09-17 14:00:06 UTC (rev 2094)
+++ branches/uml/source/cpu/cHardwareCPU.h	2007-09-17 14:55:34 UTC (rev 2095)
@@ -593,7 +593,7 @@
   bool Inst_DestState12(cAvidaContext& ctx);
 
   
-  bool Inst_TransLab0(cAvidaContext& ctx);
+/*  bool Inst_TransLab0(cAvidaContext& ctx);
   bool Inst_TransLab1(cAvidaContext& ctx);
   bool Inst_TransLab2(cAvidaContext& ctx);
   bool Inst_TransLab3(cAvidaContext& ctx);
@@ -604,7 +604,7 @@
   bool Inst_TransLab8(cAvidaContext& ctx);
   bool Inst_TransLab9(cAvidaContext& ctx);
   bool Inst_TransLab10(cAvidaContext& ctx);
-  bool Inst_TransLab11(cAvidaContext& ctx);
+  bool Inst_TransLab11(cAvidaContext& ctx);*/
 
   bool Inst_Trigger0(cAvidaContext& ctx);
   bool Inst_Trigger1(cAvidaContext& ctx);

Modified: branches/uml/source/main/cUMLStateDiagram.cc
===================================================================
--- branches/uml/source/main/cUMLStateDiagram.cc	2007-09-17 14:00:06 UTC (rev 2094)
+++ branches/uml/source/main/cUMLStateDiagram.cc	2007-09-17 14:55:34 UTC (rev 2095)
@@ -13,10 +13,11 @@
 	orig = vertex(0, sd0);
 	dest = vertex(0, sd0);
   
-  trans_label_index = 0;
+//  trans_label_index = 0;
   trigger_index = 0;
   guard_index = 0;
   action_index = 0;
+  edge_id_count = 0;
 
   xmi = "";
     
@@ -364,10 +365,10 @@
 	return absoluteMoveIndex(actions, action_index, jump_amount);
 }
 
-bool cUMLStateDiagram::absoluteJumpTransitionLabel(int jump_amount)
+/*bool cUMLStateDiagram::absoluteJumpTransitionLabel(int jump_amount)
 {
 	return absoluteMoveIndex(transition_labels, trans_label_index, jump_amount);
-}
+}*/
 
 bool cUMLStateDiagram::absoluteJumpOriginState(int jump_amount) 
 {	
@@ -411,10 +412,10 @@
 }
 
 
-transition_label cUMLStateDiagram::getTransLabel()
+/*transition_label cUMLStateDiagram::getTransLabel()
 {
 	return transition_labels[trans_label_index];
-}
+}*/
 
 bool cUMLStateDiagram::addTrigger(std::string op_id, std::string lab) 
 {
@@ -439,49 +440,9 @@
 	return true;
 }
 
-/*
-bool cUMLStateDiagram::addTransition()
-{
-	
-	if ((states.size() == 0) || (transition_labels.size() == 0)) {
 
-		return false;
-	} 
 
-	transition t;
-	t.orig_state = getOrigStateIndex();
-	t.dest_state = getDestStateIndex();
-	// increment number of edges for a state
-	states[getOrigStateIndex()].num_outgoing += 1;
-	states[getDestStateIndex()].num_incoming += 1;
-	
-	t.trans = getTransLabel();
-	
-	if ((t.orig_state != 0) && (states[t.orig_state].num_incoming == 0)) {
-		return false;
-	}
-	
-	// no dupes
-    if (findTrans(t.orig_state, t.dest_state, t.trans.trigger, t.trans.guard, t.trans.action)) {
-		return false;
-	}
-
-	transitions.push_back(t);
-//	boost::add_edge(transition_properties());
-
-	orig_state_index = 0;
-	dest_state_index = 0;
-	trans_label_index = 0;
-	trigger_index = 0;
-	guard_index = 0 ;
-	action_index = 0;
-	
-	return true;
-
-}
-*/
-
-bool cUMLStateDiagram::addTransitionLabel(int tr, int gu, int act)
+/*bool cUMLStateDiagram::addTransitionLabel(int tr, int gu, int act)
 {
 	transition_label t;
 	t.trigger = tr;
@@ -493,7 +454,7 @@
 	transition_labels.push_back(t);
 	
 	return true;
-}
+}*/
 
 bool cUMLStateDiagram::addTransitionTotal(int o, int d, int t, int g, int a) { 
 	absoluteJumpGuard(g);
@@ -529,8 +490,12 @@
 		return false;
 	}
 	
+//	int id_num = num_edges(sd0);
+	std::cout << "Adding an edge with id " << edge_id_count << std::endl;
+	
 	// Create the transition properties
-	transition_properties tp = transition_properties(trigger_index, guard_index, action_index); 
+	transition_properties tp = transition_properties(trigger_index, guard_index, action_index, edge_id_count); 
+	edge_id_count++;
 	
 	// Create the transition
 	add_edge(orig, dest, tp, sd0);
@@ -546,9 +511,39 @@
 
 }
 
+// For this function, x is an id of a transition. If a transition with this id exists, remove it and return
+// true; otherwise, return false.
+bool cUMLStateDiagram::removeTransition(int x) { 
 
+	std::cout << "attempting to remove transition " << x << std::endl;
+	bool val = false;
+	boost::graph_traits<state_diagram>::edge_descriptor ed;
 
+	
+	// Preliminary check that x is a possible transition id
+	if (x > edge_id_count || x < 0) return false;
+	
+	boost::graph_traits<state_diagram>::edge_iterator edge_start, edge_end;
+	for (tie(edge_start, edge_end) = edges(sd0);
+		 edge_start != edge_end; ++edge_start) {
+		
+		ed = *edge_start;
+		std::cout << "trans id is  " << (sd0[ed]._eid) << std::endl;
 
+		if (x == (sd0[ed]._eid)) {
+
+			remove_edge(ed, sd0);	
+			val = true;
+			std::cout << "removed  " << x << std::endl;
+
+			break;
+		}
+		
+	}
+	return val;
+}	
+
+
 int cUMLStateDiagram::numStates()
 {
 	return num_vertices(sd0);
@@ -573,35 +568,7 @@
 	return o.str();
 }
 
-/*void cUMLStateDiagram::executeVisitor() {
 
-	PathVisitor visitor; 
-	boost::graph_traits<state_diagram>::vertex_descriptor o_temp;
-	o_temp = vertex(0, sd0);
-	
-	boost::breadth_first_search(sd0, o_temp, boost::visitor(visitor));
-
-}
-
-
-struct transition_writer {
-	transition_writer(cUMLStateDiagram::state_diagram& sd) : _sd(sd) { }
-	
-	template<typename Edge>
-	void operator()(std::ostream& out) {
-		out << "working?";
-	}
-  
-	cUMLStateDiagram::state_diagram& _sd;
-}; 
-
-void cUMLStateDiagram::printGraphViz() { 
-	std::ofstream outfile("gv");
-    boost::write_graphviz(outfile, sd0); //, transition_writer(sd0)); //, topo_vertex_writer(_topo_last_network));
-    outfile.close();
-
-}*/
-
 std::string cUMLStateDiagram::getXMI(std::string name)
 {
 	printXMI(name);

Modified: branches/uml/source/main/cUMLStateDiagram.h
===================================================================
--- branches/uml/source/main/cUMLStateDiagram.h	2007-09-17 14:00:06 UTC (rev 2094)
+++ branches/uml/source/main/cUMLStateDiagram.h	2007-09-17 14:55:34 UTC (rev 2095)
@@ -17,16 +17,17 @@
 
 struct transition_properties { 
 	transition_properties() {}
-	transition_properties(int trigger, int guard, int action) 
-		: _tr(trigger), _gu(guard), _act(action) {}
-	int _tr, _gu, _act; 
+	transition_properties(int trigger, int guard, int action, int edge_id) 
+		: _tr(trigger), _gu(guard), _act(action), _eid(edge_id){}
+	int _tr, _gu, _act, _eid; 
 }; 
 
-struct transition_label { 
+/*struct transition_label { 
 	int trigger;
 	int guard;
 	int action;
-};
+	int edge_id;
+};*/
 
 struct state {
 	int identifier;
@@ -46,17 +47,17 @@
   std::vector<std::string> guards;
   std::vector<std::string> actions;
 //  std::vector<transition> transitions;
-  std::vector<transition_label> transition_labels;
+//  std::vector<transition_label> transition_labels;
 
 //  int orig_state_index;
 //  int dest_state_index;
-  int trans_label_index;
+//  int trans_label_index;
   int trigger_index;
   int guard_index;
   int action_index;
-
   
   std::string xmi;
+  int edge_id_count;
   	
 public:
 
@@ -140,7 +141,7 @@
   int getTriggerIndex();
   int getGuardIndex();
   int getActionIndex();
-  transition_label getTransLabel();
+//  transition_label getTransLabel();
   
 // Visit graph
 //  void executeVisitor();
@@ -155,7 +156,8 @@
   bool addTrigger(std::string, std::string);
   bool addGuard(std::string);
   bool addAction(std::string);
-  bool addTransitionLabel(int, int, int);
+  bool removeTransition(int);
+//  bool addTransitionLabel(int, int, int);
   // END UML functions
 protected:
     state_diagram sd0;




More information about the Avida-cvs mailing list