[Avida-SVN] r2319 - in development: Avida.xcodeproj source/cpu
brysonda at myxo.css.msu.edu
brysonda at myxo.css.msu.edu
Tue Feb 12 08:19:22 PST 2008
Author: brysonda
Date: 2008-02-12 11:19:22 -0500 (Tue, 12 Feb 2008)
New Revision: 2319
Modified:
development/Avida.xcodeproj/project.pbxproj
development/source/cpu/cHardwareExperimental.cc
development/source/cpu/cHardwareExperimental.h
Log:
Add consensus based conditional terminate instruction (and necessary support).
Modified: development/Avida.xcodeproj/project.pbxproj
===================================================================
--- development/Avida.xcodeproj/project.pbxproj 2008-02-09 17:33:40 UTC (rev 2318)
+++ development/Avida.xcodeproj/project.pbxproj 2008-02-12 16:19:22 UTC (rev 2319)
@@ -844,7 +844,7 @@
DCC315CE076253A5008F7A48 /* environment.rotate */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text; path = environment.rotate; 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 */
@@ -1784,10 +1784,12 @@
DCC30C4D0762532C008F7A48 /* Project object */ = {
isa = PBXProject;
buildConfigurationList = 702442D70859E0B00059BD9B /* Build configuration list for PBXProject "Avida" */;
+ compatibilityVersion = "Xcode 2.4";
hasScannedForEncodings = 0;
mainGroup = DCC30C490762532C008F7A48;
productRefGroup = DCC3164E07626CF3008F7A48 /* Products */;
projectDirPath = "";
+ projectRoot = "";
targets = (
7023ED520C0A590200362B9C /* full-suite */,
DCC3164C07626CF3008F7A48 /* avida */,
Modified: development/source/cpu/cHardwareExperimental.cc
===================================================================
--- development/source/cpu/cHardwareExperimental.cc 2008-02-09 17:33:40 UTC (rev 2318)
+++ development/source/cpu/cHardwareExperimental.cc 2008-02-12 16:19:22 UTC (rev 2319)
@@ -161,6 +161,8 @@
// Promoter Model
tInstLibEntry<tMethod>("promoter", &cHardwareExperimental::Inst_Promoter, nInstFlag::PROMOTER),
tInstLibEntry<tMethod>("terminate", &cHardwareExperimental::Inst_Terminate),
+ tInstLibEntry<tMethod>("term-cons", &cHardwareExperimental::Inst_TerminateConsensus),
+ tInstLibEntry<tMethod>("term-cons-24", &cHardwareExperimental::Inst_TerminateConsensus24),
tInstLibEntry<tMethod>("regulate", &cHardwareExperimental::Inst_Regulate),
tInstLibEntry<tMethod>("regulate-sp", &cHardwareExperimental::Inst_RegulateSpecificPromoters),
tInstLibEntry<tMethod>("s-regulate", &cHardwareExperimental::Inst_SenseRegulate),
@@ -320,7 +322,7 @@
cPhenotype& phenotype = organism->GetPhenotype();
// First instruction - check whether we should be starting at a promoter, when enabled.
- if (phenotype.GetCPUCyclesUsed() == 0 && m_promoters_enabled) Inst_Terminate(ctx);
+ if (phenotype.GetCPUCyclesUsed() == 0 && m_promoters_enabled) PromoterTerminate(ctx);
phenotype.IncCPUCyclesUsed();
if (!m_no_cpu_cycle_time) phenotype.IncTimeUsed();
@@ -400,10 +402,10 @@
// In the promoter model, we may force termination after a certain number of inst have been executed
if (m_promoters_enabled) {
const double processivity = m_world->GetConfig().PROMOTER_PROCESSIVITY.Get();
- if (ctx.GetRandom().P(1 - processivity)) Inst_Terminate(ctx);
+ if (ctx.GetRandom().P(1 - processivity)) PromoterTerminate(ctx);
if (m_world->GetConfig().PROMOTER_INST_MAX.Get() &&
(m_threads[m_cur_thread].GetPromoterInstExecuted() >= m_world->GetConfig().PROMOTER_INST_MAX.Get())) {
- Inst_Terminate(ctx);
+ PromoterTerminate(ctx);
}
}
} // if exec
@@ -1401,81 +1403,28 @@
// Move the instruction ptr to the next active promoter
bool cHardwareExperimental::Inst_Terminate(cAvidaContext& ctx)
{
- // Optionally,
- // Reset the thread.
- if (m_world->GetConfig().TERMINATION_RESETS.Get())
- {
- m_threads[m_cur_thread].Reset(this, m_threads[m_cur_thread].GetID());
-
- //Setting this makes it harder to do things. You have to be modular.
- organism->GetOrgInterface().ResetInputs(ctx); // Re-randomize the inputs this organism sees
- organism->ClearInput(); // Also clear their input buffers, or they can still claim
- // rewards for numbers no longer in their environment!
- }
-
- // Reset our count
- m_threads[m_cur_thread].ResetPromoterInstExecuted();
- m_advance_ip = false;
- const int promoter_reg_used = REG_DX; // register to put chosen promoter code in, default to DX
-
-
- // @DMB - should the promoter index and offset be stored in cLocalThread to allow multiple threads?
-
- // Search for an active promoter
- int start_offset = m_promoter_offset;
- int start_index = m_promoter_index;
-
- bool no_promoter_found = true;
- if (m_promoters.GetSize() > 0) {
- while (true) {
- // If the next promoter is active, then break out
- NextPromoter();
- if (IsActivePromoter()) {
- no_promoter_found = false;
- break;
- }
-
- // If we just checked the promoter that we were originally on, then there
- // are no active promoters.
- if ((start_offset == m_promoter_offset) && (start_index == m_promoter_index)) break;
-
- // If we originally were not on a promoter, then stop once we check the
- // first promoter and an offset of zero
- if (start_index == -1) start_index = 0;
- }
- }
-
- if (no_promoter_found) {
- switch (m_world->GetConfig().NO_ACTIVE_PROMOTER_EFFECT.Get()) {
- case 0:
- case 2:
- // Set defaults for when no active promoter is found
- m_promoter_index = -1;
- IP().Set(0);
- GetRegister(promoter_reg_used) = 0;
- break;
-
- case 1: // Death to organisms that refuse to use promoters!
- organism->Die();
- break;
-
- default:
- cout << "Unrecognized NO_ACTIVE_PROMOTER_EFFECT setting: " << m_world->GetConfig().NO_ACTIVE_PROMOTER_EFFECT.Get() << endl;
- exit(1);
- break;
- }
- } else {
- // We found an active match, offset to just after it.
- // cHeadCPU will do the mod genome size for us
- IP().Set(m_promoters[m_promoter_index].m_pos + 1);
-
- // Put its bit code in BX for the organism to have if option is set
- if (m_world->GetConfig().PROMOTER_TO_REGISTER.Get())
- GetRegister(promoter_reg_used) = m_promoters[m_promoter_index].m_bit_code;
- }
+ PromoterTerminate(ctx);
return true;
}
+// Move the instruction ptr to the next active promoter
+bool cHardwareExperimental::Inst_TerminateConsensus(cAvidaContext& ctx)
+{
+ const int op1 = FindModifiedRegister(REG_DX);
+ if (BitCount(GetRegister(op1)) < CONSENSUS) PromoterTerminate(ctx);
+ return true;
+}
+
+
+// Move the instruction ptr to the next active promoter
+bool cHardwareExperimental::Inst_TerminateConsensus24(cAvidaContext& ctx)
+{
+ const int op1 = FindModifiedRegister(REG_DX);
+ if (BitCount(GetRegister(op1) & MASK24) < CONSENSUS24) PromoterTerminate(ctx);
+ return true;
+}
+
+
// Set a new regulation code (which is XOR'ed with ALL promoter codes).
bool cHardwareExperimental::Inst_Regulate(cAvidaContext& ctx)
{
@@ -1550,40 +1499,109 @@
return true;
}
-// Move to the next promoter.
-void cHardwareExperimental::NextPromoter()
+
+void cHardwareExperimental::PromoterTerminate(cAvidaContext& ctx)
{
- // Move promoter index, rolling over if necessary
- m_promoter_index++;
+ // Optionally,
+ // Reset the thread.
+ if (m_world->GetConfig().TERMINATION_RESETS.Get())
+ {
+ m_threads[m_cur_thread].Reset(this, m_threads[m_cur_thread].GetID());
+
+ //Setting this makes it harder to do things. You have to be modular.
+ organism->GetOrgInterface().ResetInputs(ctx); // Re-randomize the inputs this organism sees
+ organism->ClearInput(); // Also clear their input buffers, or they can still claim
+ // rewards for numbers no longer in their environment!
+ }
- if (m_promoter_index == m_promoters.GetSize()) {
- m_promoter_index = 0;
+ // Reset our count
+ m_threads[m_cur_thread].ResetPromoterInstExecuted();
+ m_advance_ip = false;
+ const int promoter_reg_used = REG_DX; // register to put chosen promoter code in, default to DX
+
+
+ // @DMB - should the promoter index and offset be stored in cLocalThread to allow multiple threads?
+
+ // Search for an active promoter
+ int start_offset = m_promoter_offset;
+ int start_index = m_promoter_index;
+
+
+ bool no_promoter_found = true;
+ if (m_promoters.GetSize() > 0) {
+ const int promoter_exe_length = m_world->GetConfig().PROMOTER_EXE_LENGTH.Get();
+ const int promoter_code_size = m_world->GetConfig().PROMOTER_CODE_SIZE.Get();
+ const int promoter_exe_threshold = m_world->GetConfig().PROMOTER_EXE_THRESHOLD.Get();
- // Move offset, rolling over when there are not enough bits before we would have to wrap around left
- const int promoter_exe_length = m_world->GetConfig().PROMOTER_EXE_LENGTH.Get();
- m_promoter_offset += promoter_exe_length;
- if (m_promoter_offset + promoter_exe_length > m_world->GetConfig().PROMOTER_CODE_SIZE.Get()) m_promoter_offset = 0;
+ while (true) {
+ // If the next promoter is active, then break out
+
+ // Move promoter index, rolling over if necessary
+ m_promoter_index++;
+
+ if (m_promoter_index == m_promoters.GetSize()) {
+ m_promoter_index = 0;
+
+ // Move offset, rolling over when there are not enough bits before we would have to wrap around left
+ m_promoter_offset += promoter_exe_length;
+ if (m_promoter_offset + promoter_exe_length > promoter_code_size) m_promoter_offset = 0;
+ }
+
+
+ int count = 0;
+ unsigned int code = m_promoters[m_promoter_index].GetRegulatedBitCode();
+ for (int i = 0; i < promoter_exe_length; i++) {
+ // @DMB - changed the following to avoid integer division. We should only ever need to circle around once
+ //int offset = (m_promoter_offset + i) % promoter_code_size;
+ int offset = m_promoter_offset + i;
+ if (offset >= promoter_code_size) offset -= promoter_code_size;
+ int state = code >> offset;
+ count += (state & 1);
+ }
+
+ if (count >= promoter_exe_threshold) {
+ no_promoter_found = false;
+ break;
+ }
+
+ // If we just checked the promoter that we were originally on, then there
+ // are no active promoters.
+ if ((start_offset == m_promoter_offset) && (start_index == m_promoter_index)) break;
+
+ // If we originally were not on a promoter, then stop once we check the
+ // first promoter and an offset of zero
+ if (start_index == -1) start_index = 0;
+ }
}
-}
-
-
-// Check whether the current promoter is active.
-bool cHardwareExperimental::IsActivePromoter()
-{
- assert( m_promoters.GetSize() != 0 );
-
- const int promoter_exe_length = m_world->GetConfig().PROMOTER_EXE_LENGTH.Get();
- const int promoter_code_size = m_world->GetConfig().PROMOTER_CODE_SIZE.Get();
-
- int count = 0;
- unsigned int code = m_promoters[m_promoter_index].GetRegulatedBitCode();
- for (int i = 0; i < promoter_exe_length; i++) {
- int offset = (m_promoter_offset + i) % promoter_code_size;
- int state = code >> offset;
- count += (state & 1);
- }
- return (count >= m_world->GetConfig().PROMOTER_EXE_THRESHOLD.Get());
+ if (no_promoter_found) {
+ switch (m_world->GetConfig().NO_ACTIVE_PROMOTER_EFFECT.Get()) {
+ case 0:
+ case 2:
+ // Set defaults for when no active promoter is found
+ m_promoter_index = -1;
+ IP().Set(0);
+ GetRegister(promoter_reg_used) = 0;
+ break;
+
+ case 1: // Death to organisms that refuse to use promoters!
+ organism->Die();
+ break;
+
+ default:
+ cout << "Unrecognized NO_ACTIVE_PROMOTER_EFFECT setting: " << m_world->GetConfig().NO_ACTIVE_PROMOTER_EFFECT.Get() << endl;
+ exit(1);
+ break;
+ }
+ } else {
+ // We found an active match, offset to just after it.
+ // cHeadCPU will do the mod genome size for us
+ IP().Set(m_promoters[m_promoter_index].m_pos + 1);
+
+ // Put its bit code in BX for the organism to have if option is set
+ if (m_world->GetConfig().PROMOTER_TO_REGISTER.Get())
+ GetRegister(promoter_reg_used) = m_promoters[m_promoter_index].m_bit_code;
+ }
}
// Construct a promoter bit code from instruction bit codes
Modified: development/source/cpu/cHardwareExperimental.h
===================================================================
--- development/source/cpu/cHardwareExperimental.h 2008-02-09 17:33:40 UTC (rev 2318)
+++ development/source/cpu/cHardwareExperimental.h 2008-02-12 16:19:22 UTC (rev 2319)
@@ -371,6 +371,8 @@
// Promoter Model
bool Inst_Promoter(cAvidaContext& ctx);
bool Inst_Terminate(cAvidaContext& ctx);
+ bool Inst_TerminateConsensus(cAvidaContext& ctx);
+ bool Inst_TerminateConsensus24(cAvidaContext& ctx);
bool Inst_Regulate(cAvidaContext& ctx);
bool Inst_RegulateSpecificPromoters(cAvidaContext& ctx);
bool Inst_SenseRegulate(cAvidaContext& ctx);
@@ -379,8 +381,7 @@
bool Do_Numberate(cAvidaContext& ctx, int num_bits = 0);
// Promoter Helper functions
- bool IsActivePromoter();
- void NextPromoter();
+ void PromoterTerminate(cAvidaContext& ctx);
int Numberate(int _pos, int _dir, int _num_bits = 0);
More information about the Avida-cvs
mailing list