[Avida-SVN] r1335 - in branches/dkdev/source: cpu main
dknoester at myxo.css.msu.edu
dknoester at myxo.css.msu.edu
Mon Feb 19 10:51:05 PST 2007
Author: dknoester
Date: 2007-02-19 13:51:04 -0500 (Mon, 19 Feb 2007)
New Revision: 1335
Modified:
branches/dkdev/source/cpu/cHardwareCPU.cc
branches/dkdev/source/cpu/cHardwareCPU.h
branches/dkdev/source/cpu/cTestCPUInterface.cc
branches/dkdev/source/cpu/cTestCPUInterface.h
branches/dkdev/source/main/cAvidaConfig.h
branches/dkdev/source/main/cDeme.cc
branches/dkdev/source/main/cDeme.h
branches/dkdev/source/main/cEnvironment.cc
branches/dkdev/source/main/cOrgInterface.h
branches/dkdev/source/main/cOrganism.h
branches/dkdev/source/main/cPhenotype.cc
branches/dkdev/source/main/cPhenotype.h
branches/dkdev/source/main/cPopulation.cc
branches/dkdev/source/main/cPopulation.h
branches/dkdev/source/main/cPopulationInterface.cc
branches/dkdev/source/main/cPopulationInterface.h
branches/dkdev/source/main/cTaskLib.cc
Log:
Merge: r1053:1054 from avida/development; more changes to demes.
Modified: branches/dkdev/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/dkdev/source/cpu/cHardwareCPU.cc 2007-02-19 18:48:39 UTC (rev 1334)
+++ branches/dkdev/source/cpu/cHardwareCPU.cc 2007-02-19 18:51:04 UTC (rev 1335)
@@ -340,6 +340,8 @@
cInstEntryCPU("repro-X", &cHardwareCPU::Inst_Repro),
cInstEntryCPU("repro-Y", &cHardwareCPU::Inst_Repro),
cInstEntryCPU("repro-Z", &cHardwareCPU::Inst_Repro),
+
+ cInstEntryCPU("spawn-deme", &cHardwareCPU::Inst_SpawnDeme),
// Suicide
cInstEntryCPU("kazi", &cHardwareCPU::Inst_Kazi),
@@ -2451,6 +2453,12 @@
}
+bool cHardwareCPU::Inst_SpawnDeme(cAvidaContext& ctx)
+{
+ organism->SpawnDeme();
+ return true;
+}
+
bool cHardwareCPU::Inst_Kazi(cAvidaContext& ctx)
{
const int reg_used = FindModifiedRegister(REG_AX);
@@ -2469,8 +2477,7 @@
bool cHardwareCPU::Inst_Die(cAvidaContext& ctx)
{
- const double die_prob = m_world->GetConfig().DIE_PROB.Get();
- if(ctx.GetRandom().GetDouble() < die_prob) { organism->Die(); }
+ organism->Die();
return true;
}
@@ -2643,6 +2650,7 @@
organism->DoInput(value_in);
return true;
}
+
bool cHardwareCPU::Inst_TaskIO_Feedback(cAvidaContext& ctx)
{
const int reg_used = FindModifiedRegister(REG_BX);
Modified: branches/dkdev/source/cpu/cHardwareCPU.h
===================================================================
--- branches/dkdev/source/cpu/cHardwareCPU.h 2007-02-19 18:48:39 UTC (rev 1334)
+++ branches/dkdev/source/cpu/cHardwareCPU.h 2007-02-19 18:51:04 UTC (rev 1335)
@@ -368,6 +368,7 @@
bool Inst_InjectRand(cAvidaContext& ctx);
bool Inst_InjectThread(cAvidaContext& ctx);
bool Inst_Repro(cAvidaContext& ctx);
+ bool Inst_SpawnDeme(cAvidaContext& ctx);
bool Inst_Kazi(cAvidaContext& ctx);
bool Inst_Kazi5(cAvidaContext& ctx);
bool Inst_Die(cAvidaContext& ctx);
Modified: branches/dkdev/source/cpu/cTestCPUInterface.cc
===================================================================
--- branches/dkdev/source/cpu/cTestCPUInterface.cc 2007-02-19 18:48:39 UTC (rev 1334)
+++ branches/dkdev/source/cpu/cTestCPUInterface.cc 2007-02-19 18:51:04 UTC (rev 1335)
@@ -71,6 +71,10 @@
// record the probability it used.
}
+void cTestCPUInterface::SpawnDeme()
+{
+}
+
bool cTestCPUInterface::SendMessage(cOrgMessage& mess)
{
return false;
Modified: branches/dkdev/source/cpu/cTestCPUInterface.h
===================================================================
--- branches/dkdev/source/cpu/cTestCPUInterface.h 2007-02-19 18:48:39 UTC (rev 1334)
+++ branches/dkdev/source/cpu/cTestCPUInterface.h 2007-02-19 18:51:04 UTC (rev 1335)
@@ -44,6 +44,7 @@
void UpdateResources(const tArray<double>& res_change);
void Die();
void Kaboom(int distance);
+ void SpawnDeme();
bool SendMessage(cOrgMessage& mess);
cOrgSinkMessage* NetReceive() { return NULL; } // @DMB - todo: receive message
bool NetRemoteValidate(cAvidaContext& ctx, cOrgSinkMessage* msg) { return false; } // @DMB - todo: validate message
Modified: branches/dkdev/source/main/cAvidaConfig.h
===================================================================
--- branches/dkdev/source/main/cAvidaConfig.h 2007-02-19 18:48:39 UTC (rev 1334)
+++ branches/dkdev/source/main/cAvidaConfig.h 2007-02-19 18:51:04 UTC (rev 1335)
@@ -199,7 +199,6 @@
CONFIG_ADD_VAR(REQUIRED_TASK, int, -1, "Task ID required for successful divide.");
CONFIG_ADD_VAR(IMMUNITY_TASK, int, -1, "Task providing immunity from the required task.");
CONFIG_ADD_VAR(REQUIRED_REACTION, int, -1, "Reaction ID required for successful divide.");
- CONFIG_ADD_VAR(DIE_PROB, double, 0.0, "probability of death when 'die' instruction is executed");
CONFIG_ADD_GROUP(MUTATION_GROUP, "Mutations");
CONFIG_ADD_VAR(POINT_MUT_PROB, double, 0.0, "Mutation rate (per-location per update)");
Modified: branches/dkdev/source/main/cDeme.cc
===================================================================
--- branches/dkdev/source/main/cDeme.cc 2007-02-19 18:48:39 UTC (rev 1334)
+++ branches/dkdev/source/main/cDeme.cc 2007-02-19 18:51:04 UTC (rev 1335)
@@ -11,6 +11,7 @@
cDeme::cDeme()
: width(0)
, birth_count(0)
+ , org_count(0)
{
}
@@ -22,6 +23,7 @@
{
cell_ids = in_cells;
birth_count = 0;
+ org_count = 0;
// If width is negative, set it to the full number of cells.
width = in_width;
Modified: branches/dkdev/source/main/cDeme.h
===================================================================
--- branches/dkdev/source/main/cDeme.h 2007-02-19 18:48:39 UTC (rev 1334)
+++ branches/dkdev/source/main/cDeme.h 2007-02-19 18:51:04 UTC (rev 1335)
@@ -22,8 +22,9 @@
class cDeme {
private:
tArray<int> cell_ids;
- int width;
- int birth_count;
+ int width; // How wide is the deme?
+ int birth_count; // How many organisms have been born into deme since reset?
+ int org_count; // How many organisms are currently in the deme?
public:
cDeme();
@@ -41,6 +42,10 @@
void Reset() { birth_count = 0; }
int GetBirthCount() const { return birth_count; }
void IncBirthCount() { birth_count++; }
+
+ int GetOrgCount() const { return org_count; }
+ void IncOrgCount() { org_count++; }
+ void DecOrgCount() { org_count--; }
};
#endif
Modified: branches/dkdev/source/main/cEnvironment.cc
===================================================================
--- branches/dkdev/source/main/cEnvironment.cc 2007-02-19 18:48:39 UTC (rev 1334)
+++ branches/dkdev/source/main/cEnvironment.cc 2007-02-19 18:51:04 UTC (rev 1335)
@@ -639,10 +639,11 @@
}
-bool cEnvironment::TestOutput(cAvidaContext& ctx, cReactionResult& result, cTaskContext& taskctx,
- const tBuffer<int>& send_buf, const tBuffer<int>& receive_buf,
- const tArray<int>& task_count, const tArray<int>& reaction_count,
- const tArray<double>& resource_count) const
+bool cEnvironment::TestOutput(cAvidaContext& ctx, cReactionResult& result,
+ cTaskContext& taskctx,
+ const tBuffer<int>& send_buf, const tBuffer<int>& receive_buf,
+ const tArray<int>& task_count, const tArray<int>& reaction_count,
+ const tArray<double>& resource_count) const
{
// Do setup for reaction tests...
m_tasklib.SetupTests(taskctx);
Modified: branches/dkdev/source/main/cOrgInterface.h
===================================================================
--- branches/dkdev/source/main/cOrgInterface.h 2007-02-19 18:48:39 UTC (rev 1334)
+++ branches/dkdev/source/main/cOrgInterface.h 2007-02-19 18:51:04 UTC (rev 1335)
@@ -7,6 +7,15 @@
*
*/
+// This class is responsible for establishing the interface that links an
+// organism back to its population. It is a base class that is derived in:
+//
+// cpu/cTestCPUInterface.{h,cc} - Test CPU interface
+// main/cPopulationInterface.{h,cc} - Main population interface.
+//
+// Make sure that any new function you implment here also has versions in
+// those classes.
+
#ifndef cOrgInterface_h
#define cOrgInterface_h
@@ -44,6 +53,7 @@
virtual void UpdateResources(const tArray<double>& res_change) = 0;
virtual void Die() = 0;
virtual void Kaboom(int distance) = 0;
+ virtual void SpawnDeme() = 0;
virtual bool SendMessage(cOrgMessage& mess) = 0;
virtual cOrgSinkMessage* NetReceive() = 0;
virtual bool NetRemoteValidate(cAvidaContext& ctx, cOrgSinkMessage* msg) = 0;
Modified: branches/dkdev/source/main/cOrganism.h
===================================================================
--- branches/dkdev/source/main/cOrganism.h 2007-02-19 18:48:39 UTC (rev 1334)
+++ branches/dkdev/source/main/cOrganism.h 2007-02-19 18:51:04 UTC (rev 1335)
@@ -148,6 +148,7 @@
int GetNextInput() { assert(m_interface); return m_interface->GetInputAt(input_pointer); }
void Die() { assert(m_interface); m_interface->Die(); }
void Kaboom(int dist) { assert(m_interface); m_interface->Kaboom(dist);}
+ void SpawnDeme() { assert(m_interface); m_interface->SpawnDeme(); }
int GetCellID() { assert(m_interface); return m_interface->GetCellID(); }
int GetDebugInfo() { assert(m_interface); return m_interface->Debug(); }
int GetID() { return m_id; }
Modified: branches/dkdev/source/main/cPhenotype.cc
===================================================================
--- branches/dkdev/source/main/cPhenotype.cc 2007-02-19 18:48:39 UTC (rev 1334)
+++ branches/dkdev/source/main/cPhenotype.cc 2007-02-19 18:51:04 UTC (rev 1335)
@@ -498,9 +498,11 @@
return false; // Nothing happened...
}
-bool cPhenotype::TestOutput(cAvidaContext& ctx, cTaskContext& taskctx, tBuffer<int>& send_buf,
- tBuffer<int>& receive_buf, const tArray<double>& res_in,
- tArray<double>& res_change, tArray<int>& insts_triggered)
+bool cPhenotype::TestOutput(cAvidaContext& ctx, cTaskContext& taskctx,
+ tBuffer<int>& send_buf, tBuffer<int>& receive_buf,
+ const tArray<double>& res_in,
+ tArray<double>& res_change,
+ tArray<int>& insts_triggered)
{
assert(initialized == true);
@@ -524,10 +526,8 @@
// Start with updating task and reaction counters
for (int i = 0; i < num_tasks; i++) {
if (result.TaskDone(i) == true) cur_task_count[i]++;
+ if (result.TaskQuality(i) > 0) cur_task_quality[i]+= result.TaskQuality(i);
}
- for (int i = 0; i < num_tasks; i++) {
- if (result.TaskQuality(i) > 0) cur_task_quality[i]+= result.TaskQuality(i);
- }
for (int i = 0; i < num_reactions; i++) {
if (result.ReactionTriggered(i) == true) cur_reaction_count[i]++;
}
Modified: branches/dkdev/source/main/cPhenotype.h
===================================================================
--- branches/dkdev/source/main/cPhenotype.h 2007-02-19 18:48:39 UTC (rev 1334)
+++ branches/dkdev/source/main/cPhenotype.h 2007-02-19 18:51:04 UTC (rev 1335)
@@ -159,8 +159,10 @@
// Input and Output Reaction Tests
bool TestInput(tBuffer<int>& inputs, tBuffer<int>& outputs);
- bool TestOutput(cAvidaContext& ctx, cTaskContext& taskctx, tBuffer<int>& send_buf, tBuffer<int>& receive_buf,
- const tArray<double>& res_in, tArray<double>& res_change, tArray<int>& insts_triggered);
+ bool TestOutput(cAvidaContext& ctx, cTaskContext& taskctx,
+ tBuffer<int>& send_buf, tBuffer<int>& receive_buf,
+ const tArray<double>& res_in, tArray<double>& res_change,
+ tArray<int>& insts_triggered);
// State saving and loading, and printing...
bool SaveState(std::ofstream& fp);
Modified: branches/dkdev/source/main/cPopulation.cc
===================================================================
--- branches/dkdev/source/main/cPopulation.cc 2007-02-19 18:48:39 UTC (rev 1334)
+++ branches/dkdev/source/main/cPopulation.cc 2007-02-19 18:51:04 UTC (rev 1335)
@@ -338,7 +338,7 @@
// Update the contents of the target cell.
KillOrganism(target_cell);
target_cell.InsertOrganism(*in_organism);
-
+
// Setup the inputs in the target cell.
environment.SetupInputs(ctx, target_cell.input_array);
@@ -359,7 +359,11 @@
reaper_queue.Push(&target_cell);
}
+ // Keep track of statistics for organism counts...
num_organisms++;
+ if (deme_array.GetSize() > 0) {
+ deme_array[target_cell.GetDemeID()].IncOrgCount();
+ }
// Statistics...
m_world->GetStats().RecordBirth(target_cell.GetID(), in_genotype->GetID(),
@@ -392,7 +396,11 @@
// Do the lineage handling
if (m_world->GetConfig().LOG_LINEAGES.Get()) { m_world->GetClassificationManager().RemoveLineageOrganism(organism); }
+ // Update count statistics...
num_organisms--;
+ if (deme_array.GetSize() > 0) {
+ deme_array[in_cell.GetDemeID()].DecOrgCount();
+ }
genotype->RemoveOrganism();
for (int i = 0; i < organism->GetNumParasites(); i++) {
@@ -798,20 +806,41 @@
void cPopulation::SpawnDeme(int deme1_id, int deme2_id)
{
+ // Must spawn into a different deme.
+ assert(deme1_id != deme2_id);
+
+ const int num_demes = deme_array.GetSize();
+
+ // If the second argument is a -1, choose a deme at random.
+ cRandom & random = m_world->GetRandom();
+ while (deme2_id == -1 || deme2_id == deme1_id) {
+ deme2_id = random.GetUInt(num_demes);
+ }
+
+ // Make sure we have all legal values...
+ assert(deme1_id >= 0 && deme1_id < num_demes);
+ assert(deme2_id >= 0 && deme2_id < num_demes);
+
+ // Find the demes that we're working with.
cDeme & deme1 = deme_array[deme1_id];
cDeme & deme2 = deme_array[deme2_id];
- // Determine the cell to copy from and to.
- cRandom & random = m_world->GetRandom();
+ // Make sure that the deme we're copying from has at least 1 organism.
+ assert(deme1.GetOrgCount() > 0);
+
+ // Determine the cell to copy from.
int cell1_id = deme1.GetCellID( random.GetUInt(deme1.GetSize()) );
- int cell2_id = deme2.GetCellID( random.GetUInt(deme2.GetSize()) );
-
+ while (cell_array[cell1_id].IsOccupied() == false) {
+ cell1_id = deme1.GetCellID( random.GetUInt(deme1.GetSize()) );
+ }
+
// Clear out existing cells in target deme.
for (int i = 0; i < deme2.GetSize(); i++) {
KillOrganism(cell_array[ deme2.GetCellID(i) ]);
}
// And do the spawning.
+ int cell2_id = deme2.GetCellID( random.GetUInt(deme2.GetSize()) );
InjectClone( cell2_id, *(cell_array[cell1_id].GetOrganism()) );
}
Modified: branches/dkdev/source/main/cPopulation.h
===================================================================
--- branches/dkdev/source/main/cPopulation.h 2007-02-19 18:48:39 UTC (rev 1334)
+++ branches/dkdev/source/main/cPopulation.h 2007-02-19 18:51:04 UTC (rev 1335)
@@ -136,7 +136,7 @@
void CompeteDemes(int competition_type);
void ResetDemes();
void CopyDeme(int deme1_id, int deme2_id);
- void SpawnDeme(int deme1_id, int deme2_id);
+ void SpawnDeme(int deme1_id, int deme2_id=-1);
void PrintDemeStats();
// Process a single organism one instruction...
@@ -161,6 +161,7 @@
int GetSize() { return cell_array.GetSize(); }
int GetWorldX() { return world_x; }
int GetWorldY() { return world_y; }
+ int GetNumDemes() { return deme_array.GetSize(); }
cPopulationCell& GetCell(int in_num);
const tArray<double>& GetResources() const { return resource_count.GetResources(); }
Modified: branches/dkdev/source/main/cPopulationInterface.cc
===================================================================
--- branches/dkdev/source/main/cPopulationInterface.cc 2007-02-19 18:48:39 UTC (rev 1334)
+++ branches/dkdev/source/main/cPopulationInterface.cc 2007-02-19 18:51:04 UTC (rev 1335)
@@ -102,6 +102,16 @@
m_world->GetPopulation().Kaboom(cell, distance);
}
+void cPopulationInterface::SpawnDeme()
+{
+ const int num_demes = m_world->GetPopulation().GetNumDemes();
+
+ // Spawn the current deme; no target ID will put it into a random deme.
+ const int deme_id = m_world->GetPopulation().GetCell(m_cell_id).GetDemeID();
+
+ m_world->GetPopulation().SpawnDeme(deme_id);
+}
+
bool cPopulationInterface::SendMessage(cOrgMessage & mess)
{
mess.SetSenderID(m_cell_id);
Modified: branches/dkdev/source/main/cPopulationInterface.h
===================================================================
--- branches/dkdev/source/main/cPopulationInterface.h 2007-02-19 18:48:39 UTC (rev 1334)
+++ branches/dkdev/source/main/cPopulationInterface.h 2007-02-19 18:51:04 UTC (rev 1335)
@@ -53,6 +53,7 @@
void UpdateResources(const tArray<double>& res_change);
void Die();
void Kaboom(int distance);
+ void SpawnDeme();
bool SendMessage(cOrgMessage& mess);
cOrgSinkMessage* NetReceive();
bool NetRemoteValidate(cAvidaContext& ctx, cOrgSinkMessage* msg);
Modified: branches/dkdev/source/main/cTaskLib.cc
===================================================================
--- branches/dkdev/source/main/cTaskLib.cc 2007-02-19 18:48:39 UTC (rev 1334)
+++ branches/dkdev/source/main/cTaskLib.cc 2007-02-19 18:51:04 UTC (rev 1335)
@@ -1783,45 +1783,49 @@
return bonus;
}
+
double cTaskLib::Task_CommEcho(cTaskContext* ctx) const
{
- const int test_output = ctx->output_buffer[0];
+ const int test_output = ctx->output_buffer[0];
- tConstListIterator<tBuffer<int> > buff_it(ctx->other_input_buffers);
+ tConstListIterator<tBuffer<int> > buff_it(ctx->other_input_buffers);
+
+ while (buff_it.Next() != NULL) {
+ const tBuffer<int>& cur_buff = *(buff_it.Get());
+ const int buff_size = cur_buff.GetNumStored();
+ for (int i = 0; i < buff_size; i++) {
+ if (test_output == cur_buff[i]) return 1.0;
+ }
+ }
- while (buff_it.Next() != NULL) {
- const tBuffer<int>& cur_buff = *(buff_it.Get());
- const int buff_size = cur_buff.GetNumStored();
- for (int i = 0; i < buff_size; i++) {
- if (test_output == cur_buff[i]) return 1.0;
- }
- }
-
- return 0.0;
+ return 0.0;
}
+
double cTaskLib::Task_CommNot(cTaskContext* ctx) const
{
- const int test_output = ctx->output_buffer[0];
+ const int test_output = ctx->output_buffer[0];
+
+ tConstListIterator<tBuffer<int> > buff_it(ctx->other_input_buffers);
+
+ while (buff_it.Next() != NULL) {
+ const tBuffer<int>& cur_buff = *(buff_it.Get());
+ const int buff_size = cur_buff.GetNumStored();
+ for (int i = 0; i < buff_size; i++) {
+ if (test_output == (0-(cur_buff[i]+1))) return 1.0;
+ }
+ }
+
+ return 0.0;
+}
- tConstListIterator<tBuffer<int> > buff_it(ctx->other_input_buffers);
- while (buff_it.Next() != NULL) {
- const tBuffer<int>& cur_buff = *(buff_it.Get());
- const int buff_size = cur_buff.GetNumStored();
- for (int i = 0; i < buff_size; i++) {
- if (test_output == (0-(cur_buff[i]+1))) return 1.0;
- }
- }
-
- return 0.0;
-}
-
double cTaskLib::Task_NetSend(cTaskContext* ctx) const
{
return 1.0 * ctx->net_completed;
}
+
double cTaskLib::Task_NetReceive(cTaskContext* ctx) const
{
if (ctx->net_valid) return 1.0;
More information about the Avida-cvs
mailing list