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

hjg at myxo.css.msu.edu hjg at myxo.css.msu.edu
Tue Jan 30 10:31:27 PST 2007


Author: hjg
Date: 2007-01-30 13:31:27 -0500 (Tue, 30 Jan 2007)
New Revision: 1240

Modified:
   branches/uml/source/cpu/cHardwareCPU.cc
   branches/uml/source/cpu/cHardwareCPU.h
   branches/uml/source/main/cOrganism.cc
   branches/uml/source/main/cOrganism.h
   branches/uml/source/main/cTaskLib.cc
Log:
Code changes to ensure the graph/state diagram is always connected. 


Modified: branches/uml/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/uml/source/cpu/cHardwareCPU.cc	2007-01-28 06:18:32 UTC (rev 1239)
+++ branches/uml/source/cpu/cHardwareCPU.cc	2007-01-30 18:31:27 UTC (rev 1240)
@@ -354,6 +354,8 @@
 	    // UML Element Creation
 //	cInstEntryCPU("cr-state", &cHardwareCPU::Inst_CreateState, false, 
 //					"Create a state"), 
+	cInstEntryCPU("cr-trans-con", &cHardwareCPU::Inst_CreateTransitionConnect, false, 
+					"Create a connected transition"), 
 	cInstEntryCPU("cr-trans", &cHardwareCPU::Inst_CreateTransition, false, 
 					"Create a transition"), 
 	cInstEntryCPU("get-trans", &cHardwareCPU::Inst_GetTrans, false, 
@@ -3489,7 +3491,30 @@
 //	return true;
 }
 
+bool cHardwareCPU::Inst_CreateTransitionConnect(cAvidaContext& ctx)
+{
+	// a transition should consist of an integer in a nop.
+	int reg_used = FindModifiedRegister(REG_AX);
+	int trans = GetRegister(reg_used);
+	
+// the origin and destination states are determined by the values in reg b and reg c.
+// both registers could be modified by a nop...
+	reg_used = FindModifiedRegister(REG_BX);
+    int orig_state = GetRegister(reg_used);
+	reg_used = FindNextRegister(reg_used);
+	int dest_state = GetRegister(reg_used);
+	
+	//cout << "trans: " << trans << " orig_state: " << orig_state << " dest_state: " << dest_state << endl;
+	return organism->AddTransConnect(trans, orig_state, dest_state);	
+	// create or find destination state
 
+	// check to see if this transition already exists; else add it
+
+	 
+//	return true;
+}
+
+
 bool cHardwareCPU::Inst_GetState(cAvidaContext& ctx) 
 {
 
@@ -3568,7 +3593,7 @@
 	
 	if ((trans_pos >= 0) && (trans_pos < organism->NumTrans())) {
 	
-		organism->deleteTrans(trans_pos);
+//		organism->deleteTrans(trans_pos);
 		// delete the transition in this position....
 //		int label = organism->getTransLabelInPosition(trans_pos);
 

Modified: branches/uml/source/cpu/cHardwareCPU.h
===================================================================
--- branches/uml/source/cpu/cHardwareCPU.h	2007-01-28 06:18:32 UTC (rev 1239)
+++ branches/uml/source/cpu/cHardwareCPU.h	2007-01-30 18:31:27 UTC (rev 1240)
@@ -476,6 +476,7 @@
 //  bool Inst_CreateTransition(cAvidaContext& ctx);
 //  bool Inst_ModelCheck(cAvidaContext& ctx);
   bool Inst_CreateTransition(cAvidaContext& ctx);
+  bool Inst_CreateTransitionConnect(cAvidaContext& ctx);
   bool Inst_GetState(cAvidaContext& ctx);
   bool Inst_GetTrans(cAvidaContext& ctx);
   bool Inst_DeleteTrans(cAvidaContext& ctx);

Modified: branches/uml/source/main/cOrganism.cc
===================================================================
--- branches/uml/source/main/cOrganism.cc	2007-01-28 06:18:32 UTC (rev 1239)
+++ branches/uml/source/main/cOrganism.cc	2007-01-30 18:31:27 UTC (rev 1240)
@@ -850,6 +850,23 @@
 }
 
 
+bool cOrganism::AddTransConnect(int trans, int orig, int dest) 
+{
+	// find either the orig int or the dest int in the map of states & names
+	/* if(grade_list.find("Tim") == grade_list.end())
+{
+    std::cout<<"Tim is not in the map!"<<endl;
+}*/
+	if ((states.find(orig) == states.end()) && (states.find(dest) == states.end()))
+	{
+		return false;
+	}
+	
+	return (AddTrans(trans,orig,dest));
+}
+
+
+
 // May eventually want to consider removing the states attached to a transition, if there are not
 // any other transitions that point to it...
 // Also, currently, this is not handling the potential that this is the only
@@ -857,12 +874,13 @@
 // of labels to strings...
 
 // NOT WORKING
+/*
 void cOrganism::deleteTrans(int pos) 
 {
 
 
 
-/*
+
 	Graph::edge_iterator e, eend, q;
 	int count = 0;
 	int num_trans_w_lab = 0;
@@ -930,10 +948,11 @@
 	if ((s_start_lab != s_end_lab) && (out_degree(*st_end, uml_state_diagram) == 0) && (in_degree(*st_end, uml_state_diagram) == 0)) {
 		remove_vertex(*st_end, uml_state_diagram);
 	}	
-*/	
+
 	
 	return;
 }
+*/
 
 
 
@@ -1298,6 +1317,7 @@
 
 }
 
+/*
 bool cOrganism::isConnected () 
 {
 //	std::vector<int> component(num_vertices(uml_state_diagram));
@@ -1310,13 +1330,7 @@
 	int count = 0;
 	
 	
-/*	if (NumStates() > 0) {
-		temp = StringifyAnInt(uml_state_diagram[0].state_label);
-		xmi += "<UML:Pseudostate xmi.id=\"s" + temp + "\" kind=\"initial\" outgoing=\"\" name=\"s";
-		xmi += temp + "\" isSpecification=\"false\"/>\n";
-		++i;
-	}
-*/	
+
 	
 	for (; i != iend; ++i) {
 			if (in_degree(*i, uml_state_diagram) == 0) {
@@ -1328,9 +1342,9 @@
 	}
 	return 1;
 }
+*/
 
 
-
 // if you ask for something greater than the number of trans -- you get the highest numbered one...
 int cOrganism::getTransLabelInPosition (int num)
 {

Modified: branches/uml/source/main/cOrganism.h
===================================================================
--- branches/uml/source/main/cOrganism.h	2007-01-28 06:18:32 UTC (rev 1239)
+++ branches/uml/source/main/cOrganism.h	2007-01-30 18:31:27 UTC (rev 1240)
@@ -248,6 +248,7 @@
   void InitTransForMSXMI();
   void InitTransForBSXMI();
   bool AddTrans(int trans, int orig, int dest);
+  bool AddTransConnect(int trans, int orig, int dest);
   double NumStates();
   double NumTrans();
   double NumUniqueTransLabels(); 
@@ -259,8 +260,8 @@
   bool isTrans(State, State, int);
   int getTransNumber (int pos);
   bool findTrans(int s0_pos, int s1_pos, int t_pos);
-  void deleteTrans (int pos);
-  bool isConnected();
+//  void deleteTrans (int pos);
+//  bool isConnected();
   
   // This returns the list of transitions between two states. What I want is to look up one based
   // on its placement in the trans_set, but this has already been solved by HIL printing. Check there after dinner.

Modified: branches/uml/source/main/cTaskLib.cc
===================================================================
--- branches/uml/source/main/cTaskLib.cc	2007-01-28 06:18:32 UTC (rev 1239)
+++ branches/uml/source/main/cTaskLib.cc	2007-01-30 18:31:27 UTC (rev 1240)
@@ -2186,10 +2186,11 @@
 {
 	cOrganism* organism = ctx->organism;
 	
-	if (organism->isConnected() == 0) {
+/*	if (organism->isConnected() == 0) {
 		ctx->task_failed = 0;
 		return 0;
 	}
+*/	
 
 	if (ctx->task_failed == 0) {
 		return 0;




More information about the Avida-cvs mailing list