[Avida-SVN] r1337 - in branches/dkdev/source: actions main utils
dknoester at myxo.css.msu.edu
dknoester at myxo.css.msu.edu
Mon Feb 19 11:08:21 PST 2007
Author: dknoester
Date: 2007-02-19 14:08:20 -0500 (Mon, 19 Feb 2007)
New Revision: 1337
Added:
branches/dkdev/source/utils/process_map/
Modified:
branches/dkdev/source/actions/PopulationActions.cc
branches/dkdev/source/main/cAvidaConfig.h
branches/dkdev/source/main/cDeme.h
branches/dkdev/source/main/cPopulation.cc
branches/dkdev/source/main/cPopulation.h
Log:
Merge: r1058:1059 from avida/development; ReplicateDemes.
Modified: branches/dkdev/source/actions/PopulationActions.cc
===================================================================
--- branches/dkdev/source/actions/PopulationActions.cc 2007-02-19 18:58:59 UTC (rev 1336)
+++ branches/dkdev/source/actions/PopulationActions.cc 2007-02-19 19:08:20 UTC (rev 1337)
@@ -820,6 +820,46 @@
};
+/* This Action will check if any demes have met the critera to be replicated
+ and do so. There are several bases this can be checked on:
+
+ 'all' - ...all non-empty demes in the population.
+ 'full_deme' - ...demes that have been filled up.
+ 'corners' - ...demes with upper left and lower right corners filled.
+*/
+
+class cActionReplicateDemes : public cAction
+{
+private:
+ int m_rep_trigger;
+public:
+ cActionReplicateDemes(cWorld* world, const cString& args) : cAction(world, args), m_rep_trigger(-1)
+ {
+ cString largs(args);
+ cString in_trigger("full_deme");
+ if (largs.GetSize()) in_trigger = largs.PopWord();
+
+ if (in_trigger == "all") m_rep_trigger = 0;
+ else if (in_trigger == "full_deme") m_rep_trigger = 1;
+ else if (in_trigger == "corners") m_rep_trigger = 2;
+ else {
+ cString err("Unknown replication trigger '");
+ err += in_trigger;
+ err += "' in ReplicatDemes action.";
+ m_world->GetDriver().RaiseException(err);
+ return;
+ }
+ }
+
+ static const cString GetDescription() { return "Arguments: [string trigger=full_deme]"; }
+
+ void Process(cAvidaContext& ctx)
+ {
+ m_world->GetPopulation().ReplicateDemes(m_rep_trigger);
+ }
+};
+
+
/*
Designed to serve as a control for the compete_demes. Each deme is
copied into itself and the parameters reset.
@@ -1212,6 +1252,7 @@
action_lib->Register<cActionZeroMuts>("ZeroMuts");
action_lib->Register<cActionCompeteDemes>("CompeteDemes");
+ action_lib->Register<cActionReplicateDemes>("ReplicateDemes");
action_lib->Register<cActionResetDemes>("ResetDemes");
action_lib->Register<cActionCopyDeme>("CopyDeme");
@@ -1238,6 +1279,7 @@
action_lib->Register<cActionZeroMuts>("zero_muts");
action_lib->Register<cActionCompeteDemes>("compete_demes");
+ action_lib->Register<cActionReplicateDemes>("replicate_demes");
action_lib->Register<cActionResetDemes>("reset_demes");
action_lib->Register<cActionCopyDeme>("copy_deme");
Modified: branches/dkdev/source/main/cAvidaConfig.h
===================================================================
--- branches/dkdev/source/main/cAvidaConfig.h 2007-02-19 18:58:59 UTC (rev 1336)
+++ branches/dkdev/source/main/cAvidaConfig.h 2007-02-19 19:08:20 UTC (rev 1337)
@@ -237,9 +237,10 @@
CONFIG_ADD_VAR(MAX_LABEL_EXE_SIZE, int, 1, "Max nops marked as executed when labels are used");
CONFIG_ADD_VAR(BASE_SIZE_MERIT, int, 100, "Base merit when size is *not* used");
CONFIG_ADD_VAR(DEFAULT_BONUS, double, 1.0, "The bonus an organism gets before any tasks");
- CONFIG_ADD_VAR(MERIT_GIVEN, double, 0.0, "Amount of merit donated with 'donoate' command.");
+ CONFIG_ADD_VAR(MERIT_DEFAULT_BONUS, int, 0, "Scale the merit of an offspring by the default bonus\nrather than the accumulated bonus of the parent?");
+ CONFIG_ADD_VAR(MERIT_GIVEN, double, 0.0, "Amount of merit donated with 'donate' command");
CONFIG_ADD_VAR(MERIT_RECEIVED, double, 0.0, "Amount of merit received with 'donate' command");
- CONFIG_ADD_VAR(MAX_DONATE_KIN_DIST, int, -1, "Limit on distance of relation donated to (in terms of hamilton's r: 1=50% shared genes, 2=25% shared genes, etc.; -1=no max");
+ CONFIG_ADD_VAR(MAX_DONATE_KIN_DIST, int, -1, "Limit on distance of relation for donate; -1=no max");
CONFIG_ADD_VAR(MAX_DONATE_EDIT_DIST, int, -1, "Limit on edit distance for donate; -1=no max");
CONFIG_ADD_VAR(MAX_DONATES, int, 1000000, "Limit on number of donates organisms are allowed.");
Modified: branches/dkdev/source/main/cDeme.h
===================================================================
--- branches/dkdev/source/main/cDeme.h 2007-02-19 18:58:59 UTC (rev 1336)
+++ branches/dkdev/source/main/cDeme.h 2007-02-19 19:08:20 UTC (rev 1337)
@@ -46,6 +46,9 @@
int GetOrgCount() const { return org_count; }
void IncOrgCount() { org_count++; }
void DecOrgCount() { org_count--; }
+
+ bool IsEmpty() const { return org_count == 0; }
+ bool IsFull() const { return org_count == cell_ids.GetSize(); }
};
#endif
Modified: branches/dkdev/source/main/cPopulation.cc
===================================================================
--- branches/dkdev/source/main/cPopulation.cc 2007-02-19 18:58:59 UTC (rev 1336)
+++ branches/dkdev/source/main/cPopulation.cc 2007-02-19 19:08:20 UTC (rev 1337)
@@ -767,6 +767,92 @@
}
+/* Check if any demes have met the critera to be replicated and do so.
+ There are several bases this can be checked on:
+
+ 0: 'all' - ...all non-empty demes in the population.
+ 1: 'full_deme' - ...demes that have been filled up.
+ 2: 'corners' - ...demes with upper left and lower right corners filled.
+*/
+
+void cPopulation::ReplicateDemes(int rep_trigger)
+{
+ // Determine which demes should be replicated.
+ const int num_demes = GetNumDemes();
+
+ // Loop through all candidate demes...
+ for (int deme_id = 0; deme_id < num_demes; deme_id++) {
+ cDeme & source_deme = deme_array[deme_id];
+
+ // Test this deme to determine if it should be replicated. If not,
+ // continue on to the next deme.
+ switch (rep_trigger) {
+ case 0: // CASE: Replicate all non-empty demes...
+ // If this deme is empt, continue looping...
+ if (source_deme.IsEmpty()) continue;
+ break;
+ case 1: // Replicate all full demes...
+ if (source_deme.IsFull() == false) continue;
+ break;
+ case 2: // Replicate all demes with the corners filled in.
+ {
+ // The first and last IDs represent the two corners.
+ const int id1 = source_deme.GetCellID(0);
+ const int id2 = source_deme.GetCellID(source_deme.GetSize() - 1);
+ if (cell_array[id1].IsOccupied() == false ||
+ cell_array[id2].IsOccupied() == false) continue;
+ }
+ break;
+ default:
+ cerr << "ERROR: Invalid replication trigger " << rep_trigger
+ << " in cPopulation::ReplicateDemes()" << endl;
+ continue;
+ }
+
+ // -- If we made it this far, we should replicate this deme --
+
+ cRandom & random = m_world->GetRandom();
+
+ // Choose a random organism from this deme...
+ int cell1_id = -1;
+ const int deme1_size = source_deme.GetSize();
+ while (cell1_id == -1 || cell_array[cell1_id].IsOccupied() == false) {
+ cell1_id = source_deme.GetCellID(random.GetUInt(deme1_size));
+ }
+
+ // Choose a random target deme to replicate to...
+ int target_id = deme_id;
+ while (target_id == deme_id) target_id = random.GetUInt(num_demes);
+ cDeme & target_deme = deme_array[target_id];
+
+ // Clear out existing cells in target deme.
+ const int deme2_size = target_deme.GetSize();
+ for (int i = 0; i < deme2_size; i++) {
+ KillOrganism(cell_array[ target_deme.GetCellID(i) ]);
+ }
+
+ // And do the replication into the central cell of the target deme...
+ const int cell2_id = target_deme.GetCellID( deme2_size/2 );
+ InjectClone( cell2_id, *(cell_array[cell1_id].GetOrganism()) );
+
+ // Clear out the source deme to reset it
+ for (int i = 0; i < deme1_size; i++) {
+ KillOrganism(cell_array[ source_deme.GetCellID(i) ]);
+ }
+
+ // Inject the target offspring back into the source ID.
+ const int cell3_id = source_deme.GetCellID( deme1_size/2 );
+ InjectClone( cell3_id, *(cell_array[cell2_id].GetOrganism()) );
+
+ // Rotate both injected cells to face northwest.
+ cell_array[cell2_id].Rotate(
+ cell_array[GridNeighbor(cell2_id, world_x, world_y, -1, -1)] );
+ cell_array[cell3_id].Rotate(
+ cell_array[GridNeighbor(cell3_id, world_x, world_y, -1, -1)] );
+ }
+}
+
+
// Reset Demes goes through each deme and resets the individual organisms as
// if they were just injected into the population.
void cPopulation::ResetDemes()
Modified: branches/dkdev/source/main/cPopulation.h
===================================================================
--- branches/dkdev/source/main/cPopulation.h 2007-02-19 18:58:59 UTC (rev 1336)
+++ branches/dkdev/source/main/cPopulation.h 2007-02-19 19:08:20 UTC (rev 1337)
@@ -134,6 +134,7 @@
// Deme-related methods
void CompeteDemes(int competition_type);
+ void ReplicateDemes(int rep_trigger);
void ResetDemes();
void CopyDeme(int deme1_id, int deme2_id);
void SpawnDeme(int deme1_id, int deme2_id=-1);
Copied: branches/dkdev/source/utils/process_map (from rev 1059, development/source/utils/process_map)
More information about the Avida-cvs
mailing list