[Avida-SVN] r1086 - in branches/uml: Avida.xcodeproj source/cpu source/main

hjg at myxo.css.msu.edu hjg at myxo.css.msu.edu
Thu Nov 16 14:09:49 PST 2006


Author: hjg
Date: 2006-11-16 17:09:49 -0500 (Thu, 16 Nov 2006)
New Revision: 1086

Modified:
   branches/uml/Avida.xcodeproj/project.pbxproj
   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/cTaskContext.h
   branches/uml/source/main/cTaskLib.cc
   branches/uml/source/main/cTaskLib.h
Log:
Currently, the UML branch is able to create 3 states and 3 transitions using the special instructions cr-state and cr-trans. These instructions are modified by nops to indicate which state/trans is being created.




Modified: branches/uml/Avida.xcodeproj/project.pbxproj
===================================================================
--- branches/uml/Avida.xcodeproj/project.pbxproj	2006-11-16 15:04:17 UTC (rev 1085)
+++ branches/uml/Avida.xcodeproj/project.pbxproj	2006-11-16 22:09:49 UTC (rev 1086)
@@ -793,7 +793,7 @@
 		DCC315CF076253A5008F7A48 /* Makefile */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.make; path = Makefile; sourceTree = "<group>"; };
 		DCC315D0076253A5008F7A48 /* task_event_gen.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = task_event_gen.cc; sourceTree = "<group>"; };
 		DCC315D1076253A5008F7A48 /* task_event_gen.old.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = task_event_gen.old.cc; sourceTree = "<group>"; };
-		DCC3164D07626CF3008F7A48 /* avida */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = "compiled.mach-o.executable"; path = avida; sourceTree = BUILT_PRODUCTS_DIR; };
+		DCC3164D07626CF3008F7A48 /* avida */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = avida; sourceTree = BUILT_PRODUCTS_DIR; };
 /* End PBXFileReference section */
 
 /* Begin PBXFrameworksBuildPhase section */
@@ -1246,11 +1246,11 @@
 				DCC3109C0762539E008F7A48 /* avida.cc */,
 				70B086BE08F5D86100FC65FE /* avida.h */,
 				7013846009028B3E0087ED2E /* cAvidaConfig.cc */,
+				702D4EF508DA5328007BA469 /* cEnvironment.h */,
 				7013845F09028B3E0087ED2E /* cAvidaConfig.h */,
 				702D4F3F08DA61FE007BA469 /* cBirthChamber.cc */,
 				702D4F3908DA61E2007BA469 /* cBirthChamber.h */,
 				702D4EFC08DA5341007BA469 /* cEnvironment.cc */,
-				702D4EF508DA5328007BA469 /* cEnvironment.h */,
 				70CA6EB208DB7F8200068AC2 /* cFitnessMatrix.cc */,
 				70CA6EE208DB7F9E00068AC2 /* cFitnessMatrix.h */,
 				70CA6EB408DB7F8200068AC2 /* cGenome.cc */,
@@ -1410,6 +1410,7 @@
 				70B08B8208FB2E5500FC65FE /* cWeightedIndex.h */,
 				70B08B8308FB2E5500FC65FE /* tArgDataEntry.h */,
 				70B08B8408FB2E5500FC65FE /* tArray.h */,
+				70B0891708F7630100FC65FE /* cHelpManager.cc */,
 				70B08B8508FB2E5500FC65FE /* tBuffer.h */,
 				70B08B8608FB2E5500FC65FE /* tDataEntry.h */,
 				70B08B8708FB2E5500FC65FE /* tDataEntryBase.h */,
@@ -1422,7 +1423,6 @@
 				70B08B8E08FB2E5500FC65FE /* tMemTrack.h */,
 				70B08B8F08FB2E5500FC65FE /* tVector.h */,
 				70B0891608F7630100FC65FE /* cHelpAlias.cc */,
-				70B0891708F7630100FC65FE /* cHelpManager.cc */,
 				70B0891808F7630100FC65FE /* cHelpType.cc */,
 				70B0891908F7630100FC65FE /* cHistogram.cc */,
 				70B0891A08F7630100FC65FE /* cInitFile.cc */,

Modified: branches/uml/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/uml/source/cpu/cHardwareCPU.cc	2006-11-16 15:04:17 UTC (rev 1085)
+++ branches/uml/source/cpu/cHardwareCPU.cc	2006-11-16 22:09:49 UTC (rev 1086)
@@ -268,6 +268,14 @@
                   "If copied label compl., exec next inst; else SKIP W/NOPS"),
     cInstEntryCPU("set-flow",  &cHardwareCPU::Inst_SetFlow, true,
                   "Set flow-head to position in ?CX?"),
+				  
+    // UML Element Creation
+	cInstEntryCPU("cr-state", &cHardwareCPU::Inst_CreateState, false, 
+					"Create a state"), 
+	cInstEntryCPU("cr-trans", &cHardwareCPU::Inst_CreateTransition, false, 
+					"Create a transition"), 
+	cInstEntryCPU("model-ch", &cHardwareCPU::Inst_ModelCheck, false, 
+					"Model check the model"), 
     
     cInstEntryCPU("h-copy2",    &cHardwareCPU::Inst_HeadCopy2),
     cInstEntryCPU("h-copy3",    &cHardwareCPU::Inst_HeadCopy3),
@@ -347,7 +355,6 @@
     cInstEntryCPU("die",	&cHardwareCPU::Inst_Die),
     
     
-    
     // Placebo instructions
     // nop-x (included with nops)
     cInstEntryCPU("skip",      &cHardwareCPU::Inst_Skip)
@@ -3355,7 +3362,59 @@
 return true; 
 }
 
+//// UML Element Construction ////
+bool cHardwareCPU::Inst_CreateState(cAvidaContext& ctx)
+{
+	const int reg_used = FindModifiedRegister(REG_AX);
+// currently, we are only allowing for 3 states, nop-A, nop-B, nop-C	
+	organism->uml_states[reg_used]=reg_used;
+	if (organism->uml_states.size() > 2) 
+		return true; 
+	 
+	
+	return true;
+}
 
+bool cHardwareCPU::Inst_CreateTransition(cAvidaContext& ctx)
+{
+	// a transition should consist of 3 nops; all of which are optional....
+	// must figure out how to do that...
+	const int trans = FindModifiedRegister(REG_AX);
+	const int orig_state = FindModifiedRegister(REG_AX);
+	const int dest_state = FindModifiedRegister(REG_BX);
+	
+	pair<int, int> st;
+	st = make_pair (orig_state, dest_state);
+	
+	//m.insert(pair<const char* const, int>("a", 1));
+	organism->uml_transitions.insert(pair<int, pair<int, int> >(trans, st));
+	if ((trans == 1) && (orig_state == 1) && (dest_state == 2))
+		return true;
+	
+	return true;
+}
+
+
+/// This function is the same as the Inst_TaskIO function ///
+/// It should be modified to update the fitness value for the organism without performing IO. ///
+bool cHardwareCPU::Inst_ModelCheck(cAvidaContext& ctx)
+{
+//  const int reg_used = FindModifiedRegister(REG_BX);
+  
+  // Do the "put" component
+//  const int value_out = GetRegister(reg_used);
+  organism->ModelCheck(ctx); // , value_out);  // Check for tasks completed.
+  
+// Do the "get" component
+//  const int value_in = organism->GetNextInput();
+//  GetRegister(reg_used) = value_in;
+//  organism->DoInput(value_in);
+  return true;
+
+
+}
+
+
 //// Placebo insts ////
 bool cHardwareCPU::Inst_Skip(cAvidaContext& ctx)
 {

Modified: branches/uml/source/cpu/cHardwareCPU.h
===================================================================
--- branches/uml/source/cpu/cHardwareCPU.h	2006-11-16 15:04:17 UTC (rev 1085)
+++ branches/uml/source/cpu/cHardwareCPU.h	2006-11-16 22:09:49 UTC (rev 1086)
@@ -468,6 +468,11 @@
   bool Inst_HeadDivide0_01(cAvidaContext& ctx);
   bool Inst_HeadDivide0_001(cAvidaContext& ctx);
 
+  //// UML Element Construction ////
+  bool Inst_CreateState(cAvidaContext& ctx);
+  bool Inst_CreateTransition(cAvidaContext& ctx);
+  bool Inst_ModelCheck(cAvidaContext& ctx);
+
   //// Placebo ////
   bool Inst_Skip(cAvidaContext& ctx);
 };

Modified: branches/uml/source/main/cOrganism.cc
===================================================================
--- branches/uml/source/main/cOrganism.cc	2006-11-16 15:04:17 UTC (rev 1085)
+++ branches/uml/source/main/cOrganism.cc	2006-11-16 22:09:49 UTC (rev 1086)
@@ -400,7 +400,66 @@
   }
 }
 
+/// UML Functions /// 
+/// This function is a copy of DoOutput /// 
+void cOrganism::ModelCheck(cAvidaContext& ctx)
+{
+  assert(m_interface);
+  const tArray<double> & resource_count = m_interface->GetResources();
 
+  tList<tBuffer<int> > other_input_list;
+  tList<tBuffer<int> > other_output_list;
+
+  // If tasks require us to consider neighbor inputs, collect them...
+  if (m_world->GetEnvironment().GetTaskLib().UseNeighborInput() == true) {
+    const int num_neighbors = m_interface->GetNumNeighbors();
+    for (int i = 0; i < num_neighbors; i++) {
+      m_interface->Rotate();
+      cOrganism * cur_neighbor = m_interface->GetNeighbor();
+      if (cur_neighbor == NULL) continue;
+
+      other_input_list.Push( &(cur_neighbor->input_buf) );
+    }
+  }
+
+  // If tasks require us to consider neighbor outputs, collect them...
+  if (m_world->GetEnvironment().GetTaskLib().UseNeighborOutput() == true) {
+    const int num_neighbors = m_interface->GetNumNeighbors();
+    for (int i = 0; i < num_neighbors; i++) {
+      m_interface->Rotate();
+      cOrganism * cur_neighbor = m_interface->GetNeighbor();
+      if (cur_neighbor == NULL) continue;
+
+      other_output_list.Push( &(cur_neighbor->output_buf) );
+    }
+  }
+  
+//  bool net_valid = false;
+//  if (m_net) net_valid = NetValidate(ctx, value);
+
+  // Do the testing of tasks performed...
+ // output_buf.Add(value);
+  tArray<double> res_change(resource_count.GetSize());
+  tArray<int> insts_triggered;
+
+  tBuffer<int>* received_messages_point = &received_messages;
+  if (!m_world->GetConfig().SAVE_RECEIVED.Get())
+	  received_messages_point = NULL; 
+// change task context eventually	  
+  cTaskContext taskctx(input_buf, output_buf, other_input_list, other_output_list, false, 0, received_messages_point, this);
+  phenotype.TestOutput(ctx, taskctx, send_buf, receive_buf, resource_count, res_change, insts_triggered);
+  m_interface->UpdateResources(res_change);
+
+  for (int i = 0; i < insts_triggered.GetSize(); i++) {
+    const int cur_inst = insts_triggered[i];
+    m_hardware->ProcessBonusInst(ctx, cInstruction(cur_inst) );
+  }
+  
+  
+}
+
+
+
 bool cOrganism::InjectParasite(const cGenome& injected_code)
 {
   assert(m_interface);

Modified: branches/uml/source/main/cOrganism.h
===================================================================
--- branches/uml/source/main/cOrganism.h	2006-11-16 15:04:17 UTC (rev 1085)
+++ branches/uml/source/main/cOrganism.h	2006-11-16 22:09:49 UTC (rev 1086)
@@ -12,7 +12,13 @@
 #define cOrganism_h
 
 #include <fstream>
+#include <map>
+#include <utility>
+//#include <multimap>
+//#include <string>
+//using namespace std;
 
+
 #ifndef cCPUMemory_h
 #include "cCPUMemory.h"
 #endif
@@ -74,6 +80,14 @@
 
 class cOrganism
 {
+public:
+
+//!Types of the UML maps for states and transitions
+	typedef std::map<int,int> t_stateMap; //!< state map type
+	typedef t_stateMap::iterator sm_it; //!< state map iterator type
+	typedef std::multimap<int,std::pair<int,int> > t_transitionMap; //!< transition map type
+	typedef t_transitionMap::iterator tr_it; //<! transition map iterator type
+	
 protected:
   cWorld* m_world;
   cHardwareBase* m_hardware;            // The actual machinary running this organism.
@@ -178,7 +192,14 @@
   bool NetRemoteValidate(cAvidaContext& ctx, int value);
   int NetLast() { return m_net->last_seq; }
   void NetReset();
+  
+  // UML Stuff
+  t_stateMap uml_states;
+  t_transitionMap uml_transitions;
+  void ModelCheck(cAvidaContext& ctx);
 
+
+
   bool InjectParasite(const cGenome& genome);
   bool InjectHost(const cCodeLabel& in_label, const cGenome& genome);
   void AddParasite(cInjectGenotype* cur) { m_parasites.Push(cur); }

Modified: branches/uml/source/main/cTaskContext.h
===================================================================
--- branches/uml/source/main/cTaskContext.h	2006-11-16 15:04:17 UTC (rev 1085)
+++ branches/uml/source/main/cTaskContext.h	2006-11-16 22:09:49 UTC (rev 1086)
@@ -18,8 +18,8 @@
 #endif
 
 class cTaskEntry;
+class cOrganism;
 
-
 class cTaskContext
 {
   friend class cTaskLib;
@@ -33,18 +33,21 @@
   tBuffer<int>* received_messages;
   int logic_id;
   
+  
   cTaskEntry* task_entry;
+  cOrganism* organism;
 
 public:
+
   cTaskContext(const tBuffer<int>& inputs, const tBuffer<int>& outputs, const tList<tBuffer<int> >& other_inputs,
                const tList<tBuffer<int> >& other_outputs, bool in_net_valid, int in_net_completed, 
-               tBuffer<int>* in_received_messages = NULL)
+               tBuffer<int>* in_received_messages = NULL, cOrganism* in_org = NULL)
     : input_buffer(inputs), output_buffer(outputs), other_input_buffers(other_inputs),
     other_output_buffers(other_outputs), net_valid(in_net_valid), net_completed(in_net_completed), 
-    received_messages(in_received_messages), logic_id(0), task_entry(NULL)
+    received_messages(in_received_messages), organism(in_org), logic_id(0), task_entry(NULL)
   {
   }
-  
+ 
   void SetTaskEntry(cTaskEntry* in_entry) { task_entry = in_entry; }
 };
 

Modified: branches/uml/source/main/cTaskLib.cc
===================================================================
--- branches/uml/source/main/cTaskLib.cc	2006-11-16 15:04:17 UTC (rev 1085)
+++ branches/uml/source/main/cTaskLib.cc	2006-11-16 22:09:49 UTC (rev 1086)
@@ -10,6 +10,7 @@
 
 #include "cTaskLib.h"
 
+
 extern "C" {
 #include <math.h>
 #include <limits.h>
@@ -322,8 +323,20 @@
   else if (name == "net_receive")
 	  NewTask(name, "Successfully Received Network Message", &cTaskLib::Task_NetReceive);
   
-  
-  
+  // UML tasks
+  if (name == "uml_stA")
+	NewTask(name, "Successfully Created State A", &cTaskLib::Task_CreateStateA);
+  else if (name == "uml_stB")
+	NewTask(name, "Successfully Created State B", &cTaskLib::Task_CreateStateB);	
+  else if (name == "uml_stC")
+	NewTask(name, "Successfully Created State C", &cTaskLib::Task_CreateStateC);  
+  else if (name == "uml_trA") 
+	NewTask(name, "Successfully Created Transition A", &cTaskLib::Task_CreateTransA);  
+  else if (name == "uml_trB") 
+	NewTask(name, "Successfully Created Transition B", &cTaskLib::Task_CreateTransB);  	
+  else if (name == "uml_trC") 
+	NewTask(name, "Successfully Created Transition C", &cTaskLib::Task_CreateTransC);  
+	
   // Make sure we have actually found a task  
   if (task_array.GetSize() == start_size) {
     cerr << "Unknown task entry '" << name << "'." << endl;
@@ -1827,3 +1840,99 @@
   if (ctx->net_valid) return 1.0;
   return 0.0;
 }
+
+double cTaskLib::Task_CreateStateA(cTaskContext* ctx) const
+{
+	cOrganism* org = ctx->organism; 
+	cOrganism::t_stateMap::iterator i;
+
+	if ( (i = org->uml_states.find(0)) != org->uml_states.end()) {
+		return 1.0;	
+		}
+	return 0.0;	
+}
+
+double cTaskLib::Task_CreateStateB(cTaskContext* ctx) const
+{
+	cOrganism* org = ctx->organism; 
+	cOrganism::t_stateMap::iterator i;
+	
+	if ( (i = org->uml_states.find(1)) != org->uml_states.end()) {
+		return 1.0;
+		}
+	return 0.0;	
+}
+
+double cTaskLib::Task_CreateStateC(cTaskContext* ctx) const
+{
+	
+	cOrganism* org = ctx->organism; 
+	cOrganism::t_stateMap::iterator i;
+	
+	if ( (i = org->uml_states.find(2)) != org->uml_states.end()) {
+		return 1.0;
+		}
+	return 0.0;	
+}
+
+
+double cTaskLib::Task_CreateTransA(cTaskContext* ctx) const
+{
+	std::pair<cOrganism::tr_it, cOrganism::tr_it> trans_range;
+	std::pair<int, int> st;
+	cOrganism* org = ctx->organism; 
+	cOrganism::tr_it i;
+	
+	trans_range = org->uml_transitions.equal_range(0);
+	for(i=trans_range.first; i!=trans_range.second; ++i) {
+		st = i->second;
+		
+		if ((st.first == 0) && (st.second == 1)) {
+			return 1.0;
+		}
+		
+	}
+	
+	return 0.0;	
+}
+
+double cTaskLib::Task_CreateTransB(cTaskContext* ctx) const
+{
+	std::pair<cOrganism::tr_it, cOrganism::tr_it> trans_range;
+	std::pair<int, int> st;
+	cOrganism* org = ctx->organism; 
+	cOrganism::tr_it i;
+	
+	trans_range = org->uml_transitions.equal_range(1);
+	for(i=trans_range.first; i!=trans_range.second; ++i) {
+		st = i->second;
+		
+		if ((st.first == 1) && (st.second == 2)) {
+			return 1.0;
+		}
+		
+	}
+	
+	return 0.0;	
+
+}
+
+double cTaskLib::Task_CreateTransC(cTaskContext* ctx) const
+{
+	std::pair<cOrganism::tr_it, cOrganism::tr_it> trans_range;
+	std::pair<int, int> st;
+	cOrganism* org = ctx->organism; 
+	cOrganism::tr_it i;
+	
+	trans_range = org->uml_transitions.equal_range(2);
+	for(i=trans_range.first; i!=trans_range.second; ++i) {
+		st = i->second;
+		
+		if ((st.first == 2) && (st.second == 0)) {
+			return 1.0;
+		}
+		
+	}
+	
+	return 0.0;	
+}

Modified: branches/uml/source/main/cTaskLib.h
===================================================================
--- branches/uml/source/main/cTaskLib.h	2006-11-16 15:04:17 UTC (rev 1085)
+++ branches/uml/source/main/cTaskLib.h	2006-11-16 22:09:49 UTC (rev 1086)
@@ -26,8 +26,12 @@
 #ifndef cStats_h
 #include "cStats.h"
 #endif
+#ifndef cOrganism_h
+#include "cOrganism.h"
+#endif
 
 
+class cOrganism;
 class cString;
 class cWorld;
 
@@ -224,6 +228,15 @@
   
   double Task_NetSend(cTaskContext* ctx) const;
   double Task_NetReceive(cTaskContext* ctx) const;
+  
+  // UML Tasks... 
+  double Task_CreateStateA(cTaskContext* ctx) const;
+  double Task_CreateStateB(cTaskContext* ctx) const;
+  double Task_CreateStateC(cTaskContext* ctx) const;
+  double Task_CreateTransA(cTaskContext* ctx) const;
+  double Task_CreateTransB(cTaskContext* ctx) const;
+  double Task_CreateTransC(cTaskContext* ctx) const;
+
 };
 
 




More information about the Avida-cvs mailing list