[Avida-SVN] r3369 - in development/source: actions cpu main

connel42 at myxo.css.msu.edu connel42 at myxo.css.msu.edu
Tue Aug 18 11:52:30 PDT 2009


Author: connel42
Date: 2009-08-18 14:52:30 -0400 (Tue, 18 Aug 2009)
New Revision: 3369

Modified:
   development/source/actions/PopulationActions.cc
   development/source/cpu/cHardwareCPU.cc
   development/source/cpu/cHardwareCPU.h
   development/source/main/cAvidaConfig.h
Log:
Added resource-dependent jmp-head and mov-head instructions

Modified: development/source/actions/PopulationActions.cc
===================================================================
--- development/source/actions/PopulationActions.cc	2009-08-17 18:53:26 UTC (rev 3368)
+++ development/source/actions/PopulationActions.cc	2009-08-18 18:52:30 UTC (rev 3369)
@@ -3510,7 +3510,6 @@
             int counter = 0;
             do {
               src_cellid = m_world->GetRandom().GetInt(0, (deme.GetWidth() * deme.GetHeight())-1);
-              cout << ".";
               counter++;
             } while((counter < deme_size) && (!deme.GetCell(src_cellid).IsOccupied()));
                         

Modified: development/source/cpu/cHardwareCPU.cc
===================================================================
--- development/source/cpu/cHardwareCPU.cc	2009-08-17 18:53:26 UTC (rev 3368)
+++ development/source/cpu/cHardwareCPU.cc	2009-08-18 18:52:30 UTC (rev 3369)
@@ -342,6 +342,9 @@
     tInstLibEntry<tMethod>("if-label2", &cHardwareCPU::Inst_IfLabel2, 0, "If copied label compl., exec next inst; else SKIP W/NOPS"),
     tInstLibEntry<tMethod>("set-flow", &cHardwareCPU::Inst_SetFlow, nInstFlag::DEFAULT, "Set flow-head to position in ?CX?"),
     
+    tInstLibEntry<tMethod>("res-mov-head", &cHardwareCPU::Inst_ResMoveHead, nInstFlag::STALL, "Move head ?IP? to the flow head depending on resource level"),
+    tInstLibEntry<tMethod>("res-jmp-head", &cHardwareCPU::Inst_ResJumpHead, nInstFlag::STALL, "Move head ?IP? by amount in CX register depending on resource level; CX = old pos."),
+    
     tInstLibEntry<tMethod>("h-copy2", &cHardwareCPU::Inst_HeadCopy2),
     tInstLibEntry<tMethod>("h-copy3", &cHardwareCPU::Inst_HeadCopy3),
     tInstLibEntry<tMethod>("h-copy4", &cHardwareCPU::Inst_HeadCopy4),
@@ -5683,6 +5686,47 @@
   return true;
 }
 
+bool cHardwareCPU::Inst_ResMoveHead(cAvidaContext& ctx)
+{
+  const cString& resname = m_world->GetConfig().INST_RES.Get();
+  const double floor = m_world->GetConfig().INST_RES_FLOOR.Get();
+  const double ceil = m_world->GetConfig().INST_RES_CEIL.Get();
+  double current_level=0;
+  
+  assert(floor >= 0);
+  assert(ceil >= 0);
+  assert(ceil >= floor);
+    
+  cPopulation& pop = m_world->GetPopulation();
+  cDeme &deme = pop.GetDeme(pop.GetCell(m_organism->GetCellID()).GetDemeID());
+  
+  const cResourceCount& deme_resources = deme.GetDemeResourceCount();
+  const cResourceCount& resources = pop.GetResourceCount();
+  
+  int resid = deme_resources.GetResourceByName(resname);
+  
+  if(resid >= 0) {
+    current_level = deme_resources.Get(resid);
+  } else if( (resid = resources.GetResourceByName(resname)) >= 0) {
+    current_level = resources.Get(resid);
+  } else {
+    cout << "Error: Cannot find resource '" << resname << "'" << endl;
+    return true;
+  }
+  
+  double current_frac = (current_level - floor) / (ceil - floor);
+  
+  if(ctx.GetRandom().P(current_frac)) {
+    //cout << "Doing move-head with current resource fraction is: " << current_frac << " (floor: " << floor << ") (ceil: " << ceil << ") (level: " << current_level << ")"<<endl;
+
+    return Inst_MoveHead(ctx);
+  } else {
+    //cout << "not doing jump" << endl;
+  }
+  
+  return true;
+}
+
 bool cHardwareCPU::Inst_JumpHead(cAvidaContext& ctx)
 {
   const int head_used = FindModifiedHead(nHardware::HEAD_IP);
@@ -5693,6 +5737,44 @@
   return true;
 }
 
+bool cHardwareCPU::Inst_ResJumpHead(cAvidaContext& ctx)
+{
+  const cString& resname = m_world->GetConfig().INST_RES.Get();
+  const double floor = m_world->GetConfig().INST_RES_FLOOR.Get();
+  const double ceil = m_world->GetConfig().INST_RES_CEIL.Get();
+  double current_level=0;
+  
+  assert(floor >= 0);
+  assert(ceil >= 0);
+  assert(ceil >= floor);
+  
+  cPopulation& pop = m_world->GetPopulation();
+  cDeme &deme = pop.GetDeme(pop.GetCell(m_organism->GetCellID()).GetDemeID());
+  
+  const cResourceCount& deme_resources = deme.GetDemeResourceCount();
+  const cResourceCount& resources = pop.GetResourceCount();
+  
+  int resid = deme_resources.GetResourceByName(resname);
+  
+  if(resid >= 0) {
+    current_level = deme_resources.Get(resid);
+  } else if( (resid = resources.GetResourceByName(resname)) >= 0) {
+    current_level = resources.Get(resid);
+  } else {
+    cout << "Error: Cannot find resource '" << resname << "'" << endl;
+    return true;
+  }
+  
+  double current_frac = (current_level - floor) / (ceil - floor);
+  
+  if(ctx.GetRandom().P(current_frac)) {
+    return Inst_JumpHead(ctx);
+  }
+  
+  return true;
+}
+
+
 bool cHardwareCPU::Inst_GetHead(cAvidaContext& ctx)
 {
   const int head_used = FindModifiedHead(nHardware::HEAD_IP);

Modified: development/source/cpu/cHardwareCPU.h
===================================================================
--- development/source/cpu/cHardwareCPU.h	2009-08-17 18:53:26 UTC (rev 3368)
+++ development/source/cpu/cHardwareCPU.h	2009-08-18 18:52:30 UTC (rev 3369)
@@ -603,7 +603,9 @@
   bool Inst_SetHead(cAvidaContext& ctx);
   bool Inst_AdvanceHead(cAvidaContext& ctx);
   bool Inst_MoveHead(cAvidaContext& ctx);
+  bool Inst_ResMoveHead(cAvidaContext& ctx);
   bool Inst_JumpHead(cAvidaContext& ctx);
+  bool Inst_ResJumpHead(cAvidaContext& ctx);
   bool Inst_GetHead(cAvidaContext& ctx);
   bool Inst_IfLabel(cAvidaContext& ctx);
   bool Inst_IfLabelDirect(cAvidaContext& ctx);

Modified: development/source/main/cAvidaConfig.h
===================================================================
--- development/source/main/cAvidaConfig.h	2009-08-17 18:53:26 UTC (rev 3368)
+++ development/source/main/cAvidaConfig.h	2009-08-18 18:52:30 UTC (rev 3369)
@@ -661,6 +661,11 @@
 	CONFIG_ADD_VAR(HGT_DIFFUSION_METHOD, int, 0, "Method to use for diffusion of genome\nfragments (0=none [default]).");
 	CONFIG_ADD_VAR(HGT_INSERTION_PROB, double, 0.0, "Probability that a genome fragment\nwill be inserted during a copy (default=0.0).");
 	CONFIG_ADD_VAR(HGT_LOOKAHEAD_LENGTH, int, 4, "Number of instructions forward from the\nread head that will be used to calculate\nthe liklihood of HGT.");	
+  
+  CONFIG_ADD_GROUP(INST_RES_GROUP, "Resource-Dependent Instructions Settings");
+  CONFIG_ADD_VAR(INST_RES, cString, "", "Resource upon which the execution of certain instruction depends");
+  CONFIG_ADD_VAR(INST_RES_FLOOR, double, 0.0, "Assumed lower level of resource in environment.  Used for probability dist.");
+  CONFIG_ADD_VAR(INST_RES_CEIL, double, 0.0, "Assumed upper level of resource in environment.  Used for probability dist.");
 	
 #endif
   




More information about the Avida-cvs mailing list