[Avida-SVN] r3100 - in development/source: actions cpu main
hjg at myxo.css.msu.edu
hjg at myxo.css.msu.edu
Sat Jan 10 18:36:01 PST 2009
Author: hjg
Date: 2009-01-10 21:36:00 -0500 (Sat, 10 Jan 2009)
New Revision: 3100
Modified:
development/source/actions/PopulationActions.cc
development/source/actions/PrintActions.cc
development/source/cpu/cHardwareCPU.cc
development/source/cpu/cHardwareCPU.h
development/source/main/cAvidaConfig.h
development/source/main/cDeme.h
development/source/main/cPopulation.cc
development/source/main/cStats.cc
development/source/main/cStats.h
Log:
- Added a deme migration option that is based on the number of points a deme has.
- Added a suicide instruction that probabilistically kills organisms and assigns points to a deme.
- Added stats tracking for both suicides and migrations.
Modified: development/source/actions/PopulationActions.cc
===================================================================
--- development/source/actions/PopulationActions.cc 2009-01-10 22:24:39 UTC (rev 3099)
+++ development/source/actions/PopulationActions.cc 2009-01-11 02:36:00 UTC (rev 3100)
@@ -2019,6 +2019,36 @@
}
};
+
+/* This action decays the number of points a deme has accumulated by
+ a percentage that is set in the configuration file. (hjg)*/
+class cActionDecayPoints : public cAction
+ {
+ private:
+ public:
+ cActionDecayPoints(cWorld* world, const cString& args) : cAction(world, args)
+ {
+ cString largs(args);
+ }
+
+ static const cString GetDescription() { return "No Arguments"; }
+
+ void Process(cAvidaContext& ctx)
+ {
+ double decay_percent = (double) m_world->GetConfig().POINT_DECAY_PERCENT.Get() / 100;
+ double cur_points = 0;
+ int sub_points = 0;
+
+ // For each deme, subtract decay_percent of its points.
+ for(int i=0; i<m_world->GetPopulation().GetNumDemes(); ++i) {
+ cur_points = m_world->GetPopulation().GetDeme(i).GetNumberOfPoints();
+ sub_points = (int) (cur_points * decay_percent);
+ m_world->GetPopulation().GetDeme(i).SubtractNumberOfPoints(sub_points);
+ }
+
+ }
+ };
+
class cActionCompeteOrganisms : public cAction
{
private:
@@ -2566,6 +2596,8 @@
action_lib->Register<cActionDivideDemes>("DivideDemes");
action_lib->Register<cActionResetDemes>("ResetDemes");
action_lib->Register<cActionCopyDeme>("CopyDeme");
+
+ action_lib->Register<cActionDecayPoints>("DecayPoints");
action_lib->Register<cActionFlash>("Flash");
Modified: development/source/actions/PrintActions.cc
===================================================================
--- development/source/actions/PrintActions.cc 2009-01-10 22:24:39 UTC (rev 3099)
+++ development/source/actions/PrintActions.cc 2009-01-11 02:36:00 UTC (rev 3100)
@@ -113,6 +113,9 @@
STATS_OUT_FILE(PrintDemeOrgTasksExeData, deme_org_tasks_exe.dat );
STATS_OUT_FILE(PrintDemeOrgReactionData, deme_org_reactions.dat );
STATS_OUT_FILE(PrintDemeCurrentTaskExeData, deme_cur_task_exe.dat );
+STATS_OUT_FILE(PrintDemeMigrationSuicidePoints, deme_mig_suicide_points.dat );
+
+
STATS_OUT_FILE(PrintCurrentTaskCounts, curr_task_counts.dat);
STATS_OUT_FILE(PrintGermlineData, germline.dat );
STATS_OUT_FILE(PrintPredicatedMessages, messages.dat );
@@ -2765,7 +2768,10 @@
action_lib->Register<cActionPrintDemeCurrentTaskExeData>("PrintDemeCurrentTaskExeData");
action_lib->Register<cActionPrintCurrentTaskCounts>("PrintCurrentTaskCounts");
action_lib->Register<cActionPrintPerDemeGenPerFounderData>("PrintPerDemeGenPerFounderData");
+ action_lib->Register<cActionPrintDemeMigrationSuicidePoints>("PrintDemeMigrationSuicidePoints");
+
+
//Coalescence Clade Actions
action_lib->Register<cActionPrintCCladeCounts>("PrintCCladeCounts");
action_lib->Register<cActionPrintCCladeFitnessHistogram>("PrintCCladeFitnessHistogram");
Modified: development/source/cpu/cHardwareCPU.cc
===================================================================
--- development/source/cpu/cHardwareCPU.cc 2009-01-10 22:24:39 UTC (rev 3099)
+++ development/source/cpu/cHardwareCPU.cc 2009-01-11 02:36:00 UTC (rev 3100)
@@ -386,6 +386,7 @@
tInstLibEntry<tMethod>("kazi", &cHardwareCPU::Inst_Kazi, nInstFlag::STALL),
tInstLibEntry<tMethod>("kazi5", &cHardwareCPU::Inst_Kazi5, nInstFlag::STALL),
tInstLibEntry<tMethod>("die", &cHardwareCPU::Inst_Die, nInstFlag::STALL),
+ tInstLibEntry<tMethod>("suicide", &cHardwareCPU::Inst_Suicide, nInstFlag::STALL),
tInstLibEntry<tMethod>("relinquishEnergyToFutureDeme", &cHardwareCPU::Inst_RelinquishEnergyToFutureDeme, nInstFlag::STALL),
tInstLibEntry<tMethod>("relinquishEnergyToNeighborOrganisms", &cHardwareCPU::Inst_RelinquishEnergyToNeighborOrganisms, nInstFlag::STALL),
tInstLibEntry<tMethod>("relinquishEnergyToOrganismsInDeme", &cHardwareCPU::Inst_RelinquishEnergyToOrganismsInDeme, nInstFlag::STALL),
@@ -2800,6 +2801,25 @@
return true;
}
+/* Similar to Kazi, this instructon probabilistically causes
+ the organism to die. However, in this case it does so in
+ order to win points for its deme and it does not take out
+ any other organims. */
+bool cHardwareCPU::Inst_Suicide(cAvidaContext& ctx)
+{
+ const int reg_used = FindModifiedRegister(REG_AX);
+ double percentProb = ((double) (GetRegister(reg_used) % 100)) / 100.0;
+ if (m_organism->GetDeme() == NULL)
+ return false; // in test CPU
+ if ( ctx.GetRandom().P(percentProb) ) {
+ // Add points as determined by config file to the deme.
+ m_organism->GetDeme()->AddNumberOfPoints(m_world->GetConfig().DEMES_PROTECTION_POINTS.Get());
+ m_organism->GetDeme()->AddSuicide();
+ m_organism->Die();
+ }
+ return true;
+}
+
bool cHardwareCPU::Inst_RelinquishEnergyToFutureDeme(cAvidaContext& ctx)
{
double stored_energy = m_organism->GetPhenotype().GetStoredEnergy() * m_world->GetConfig().FRAC_ENERGY_RELINQUISH.Get();
Modified: development/source/cpu/cHardwareCPU.h
===================================================================
--- development/source/cpu/cHardwareCPU.h 2009-01-10 22:24:39 UTC (rev 3099)
+++ development/source/cpu/cHardwareCPU.h 2009-01-11 02:36:00 UTC (rev 3100)
@@ -445,6 +445,7 @@
bool Inst_Kazi(cAvidaContext& ctx);
bool Inst_Kazi5(cAvidaContext& ctx);
bool Inst_Die(cAvidaContext& ctx);
+ bool Inst_Suicide(cAvidaContext& ctx);
bool Inst_RelinquishEnergyToFutureDeme(cAvidaContext& ctx);
bool Inst_RelinquishEnergyToNeighborOrganisms(cAvidaContext& ctx);
bool Inst_RelinquishEnergyToOrganismsInDeme(cAvidaContext& ctx);
Modified: development/source/main/cAvidaConfig.h
===================================================================
--- development/source/main/cAvidaConfig.h 2009-01-10 22:24:39 UTC (rev 3099)
+++ development/source/main/cAvidaConfig.h 2009-01-11 02:36:00 UTC (rev 3100)
@@ -324,14 +324,18 @@
CONFIG_ADD_VAR(DEMES_REPLICATE_ORGS, int, 0, "Replicate a deme immediately once it reaches a\ncertain number of organisms (0 = OFF).");
CONFIG_ADD_VAR(DEMES_REPLICATION_ONLY_RESETS, int, 0, "Kin selection mode. Deme replication really:\n1=resets deme resources\n2=rests deme resources and re-injects organisms");
CONFIG_ADD_VAR(DEMES_MIGRATION_RATE, double, 0.0, "Probability of an offspring being born in a different deme.");
- CONFIG_ADD_VAR(DEMES_MIGRATION_METHOD, int, 0, "How do we choose what demes an org may land in when it migrates?\n0=all other demes\n1=eight adjacent neighbors\n2=two adjacent demes in list");
+ CONFIG_ADD_VAR(DEMES_MIGRATION_METHOD, int, 0, "How do we choose what demes an org may land in when it migrates?\n0=all other demes\n1=eight adjacent neighbors\n2=two adjacent demes in list\n3=proportional based on the number of points");
CONFIG_ADD_VAR(DEMES_NUM_X, int, 0, "Simulated number of demes in X dimension. Only used for migration. ");
CONFIG_ADD_VAR(DEMES_SEED_METHOD, int, 0, "Deme seeding method.\n0=maintain old consistency\n1=new method using genotypes");
CONFIG_ADD_VAR(DEMES_DIVIDE_METHOD, int, 0, "Deme divide method. Only works with DEMES_SEED_METHOD 1\n0=replace and target demes\n1= replace target deme, reset source deme to founders\n2=replace target deme, leave source deme unchanged");
CONFIG_ADD_VAR(DEMES_DEFAULT_GERMLINE_PROPENSITY, double, 0.0, "Default germline propensity of organisms in deme.\nFor use with DEMES_DIVIDE_METHOD 2.");
CONFIG_ADD_VAR(DEMES_FOUNDER_GERMLINE_PROPENSITY, double, -1.0, "Default germline propensity of founder organisms in deme.\nFor use with DEMES_DIVIDE_METHOD 2.\n <0 = OFF");
CONFIG_ADD_VAR(DEMES_PREFER_EMPTY, int, 0, "Give empty demes preference as targets of deme replication?");
+ CONFIG_ADD_VAR(DEMES_PROTECTION_POINTS, int, 0, "The number of points a deme receives for each suicide.");
+ CONFIG_ADD_VAR(POINT_DECAY_PERCENT, int, 0, "The percentage of points decayed each time cActionDecayPoints is called.");
+
+
CONFIG_ADD_GROUP(REPRODUCTION_GROUP, "Birth and Death");
CONFIG_ADD_VAR(BIRTH_METHOD, int, 0, "Which organism should be replaced on birth?\n0 = Random organism in neighborhood\n1 = Oldest in neighborhood\n2 = Largest Age/Merit in neighborhood\n3 = None (use only empty cells in neighborhood)\n4 = Random from population (Mass Action)\n5 = Oldest in entire population\n6 = Random within deme\n7 = Organism faced by parent\n8 = Next grid cell (id+1)\n9 = Largest energy used in entire population\n10 = Largest energy used in neighborhood");
CONFIG_ADD_VAR(PREFER_EMPTY, int, 1, "Give empty cells preference in offsping placement?");
Modified: development/source/main/cDeme.h
===================================================================
--- development/source/main/cDeme.h 2009-01-10 22:24:39 UTC (rev 3099)
+++ development/source/main/cDeme.h 2009-01-11 02:36:00 UTC (rev 3100)
@@ -127,6 +127,13 @@
tVector<cOrgMessagePredicate*> message_pred_list; // Message Predicates
tVector<cOrgMovementPredicate*> movement_pred_list; // Movement Predicates
+
+ // For the points infrastructure
+ double points;
+ unsigned int migrations_out;
+ unsigned int migrations_in;
+ unsigned int suicides;
+
public:
cDeme() : _id(0), width(0), replicateDeme(false), cur_birth_count(0), last_birth_count(0), cur_org_count(0), last_org_count(0), injected_count(0), birth_count_perslot(0),
@@ -136,7 +143,7 @@
eventsTotal(0), eventsKilled(0), eventsKilledThisSlot(0), eventKillAttempts(0), eventKillAttemptsThisSlot(0),
consecutiveSuccessfulEventPeriods(0), sleeping_count(0),
avg_founder_generation(0.0), generations_per_lifetime(0.0),
- deme_resource_count(0), m_germline_genotype_id(0) { ; }
+ deme_resource_count(0), m_germline_genotype_id(0), points(0), migrations_out(0), migrations_in(0), suicides(0){ ; }
~cDeme() { ; }
void Setup(int id, const tArray<int>& in_cells, int in_width = -1, cWorld* world = NULL);
@@ -321,6 +328,21 @@
// --- Pheromones --- //
void AddPheromone(int absolute_cell_id, double value);
+ // --- Points --- //
+ double GetNumberOfPoints() { return points; }
+ void AddNumberOfPoints(double num_points) { points += num_points; }
+ void SubtractNumberOfPoints(double num_points) { if (num_points > points) points = 0; }
+ int GetMigrationsOut() { return migrations_out; }
+ int GetMigrationsIn() { return migrations_in; }
+ int GetSuicides() { return suicides; }
+ void AddMigrationOut() { migrations_out++; }
+ void AddMigrationIn() { migrations_in++; }
+ void AddSuicide() { suicides++; }
+ void ClearMigrationOut() { migrations_out = 0; }
+ void ClearMigrationIn() { migrations_in = 0; }
+ void ClearSuicides() { suicides = 0; }
+
+
void GetSurroundingCellIds(tVector<int> &cells, const int absolute_cell_id, const int radius);
};
Modified: development/source/main/cPopulation.cc
===================================================================
--- development/source/main/cPopulation.cc 2009-01-10 22:24:39 UTC (rev 3099)
+++ development/source/main/cPopulation.cc 2009-01-11 02:36:00 UTC (rev 3100)
@@ -3394,7 +3394,9 @@
{
//cerr << "Attempting to migrate with rate " << m_world->GetConfig().MIGRATION_RATE.Get() << "!" << endl;
int deme_id = parent_cell.GetDemeID();
-
+ int parent_id = parent_cell.GetDemeID();
+ GetDeme(deme_id).AddMigrationOut();
+
// Position randomly in any other deme
if (m_world->GetConfig().DEMES_MIGRATION_METHOD.Get() == 0) {
@@ -3457,7 +3459,42 @@
//set the new deme_id
deme_id = (deme_id + rnd_deme_id + GetNumDemes()) % GetNumDemes();
}
+
+ //Proportional-based on a points system (hjg)
+ // The odds of a deme being selected are inversely proportional to the
+ // number of points it has.
+ else if (m_world->GetConfig().DEMES_MIGRATION_METHOD.Get() == 3) {
+
+ double total_points = 0;
+ int num_demes = GetNumDemes();
+
+ // Identify how many points are in the population as a whole.
+ for (int did = 0; did < num_demes; did++) {
+ if (did != parent_id) {
+ total_points += (1/(1+GetDeme(did).GetNumberOfPoints()));
+ }
+ }
+ // Select a random number from 0 to 1:
+ double rand_point = m_world->GetRandom().GetDouble(0, total_points);
+
+ // Iterate through the demes until you find the appropriate
+ // deme to insert the organism into.
+ double lower_point = 0;
+ double upper_point = 0;
+
+ for (int curr_deme = 0; curr_deme < num_demes; curr_deme++) {
+ if (curr_deme != parent_id){
+ upper_point = lower_point + (1+GetDeme(curr_deme).GetNumberOfPoints());
+ if ((lower_point <= rand_point) && (rand_point < upper_point)) {
+ deme_id = curr_deme;
+ }
+ lower_point = upper_point;
+ }
+ }
+ }
+ GetDeme(deme_id).AddMigrationIn();
+
// TODO the above choice of deme does not respect PREFER_EMPTY
// i.e., it does not preferentially pick a deme with empty cells if they are
// it might make sense for that to happen...
Modified: development/source/main/cStats.cc
===================================================================
--- development/source/main/cStats.cc 2009-01-10 22:24:39 UTC (rev 3099)
+++ development/source/main/cStats.cc 2009-01-11 02:36:00 UTC (rev 3100)
@@ -1867,7 +1867,78 @@
df.Endl();
}
+void cStats::PrintDemeMigrationSuicidePoints(const cString& filename){
+ cDataFile& df = m_world->GetDataFile(filename);
+ df.WriteComment("Avida average stats");
+ df.WriteTimeStamp();
+
+ df.Write(m_update, "Update");
+ double max_points = 0;
+ double min_points = -1;
+ double total_points = 0;
+ double temp_points = 0;
+ int max_suicides = 0;
+ int min_suicides = -1;
+ double total_suicides = 0;
+ int temp_suicides = 0;
+ int max_migrations = 0;
+ int min_migrations = -1;
+ double total_migrations = 0;
+ int temp_migrations = 0;
+ int deme_count = 0;
+
+
+ for(int i=0; i<m_world->GetPopulation().GetNumDemes(); ++i) {
+ cDeme& deme = m_world->GetPopulation().GetDeme(i);
+
+ temp_points = deme.GetNumberOfPoints();
+ temp_suicides = deme.GetSuicides();
+ temp_migrations = deme.GetMigrationsOut();
+
+
+ // Calculate Min
+ if ((min_points == -1) || (temp_points < min_points)) {
+ min_points = temp_points;
+ }
+ if ((min_suicides == -1) || (temp_suicides < min_suicides)) {
+ min_suicides = temp_suicides;
+ }
+ if ((min_migrations == -1) || (temp_migrations < min_migrations)) {
+ min_migrations = temp_migrations;
+ }
+
+ // Calculate Max
+ if (temp_points > max_points) max_points = temp_points;
+ if (temp_suicides > max_suicides) max_suicides = temp_suicides;
+ if (temp_migrations > max_migrations) max_migrations = temp_migrations;
+
+ total_points += temp_points;
+ total_suicides += temp_suicides;
+ total_migrations += temp_migrations;
+
+
+ if (temp_points > 0) deme_count++;
+ }
+
+ df.Write((total_points/m_world->GetPopulation().GetNumDemes()), "AveragePoints[avpoints]" );
+ df.Write(min_points, "MinPoints[minpoints]" );
+ df.Write(max_points, "MaxPoints[maxpoints]" );
+ df.Write(deme_count, "DemesWithPoints[demeswithpoints]");
+ df.Write((total_suicides/m_world->GetPopulation().GetNumDemes()), "AverageSuicides[avsuicides]" );
+ df.Write(min_suicides, "MinSuicides[minsuicides]" );
+ df.Write(max_suicides, "MaxSuicides[maxsuicides]" );
+ df.Write((total_migrations/m_world->GetPopulation().GetNumDemes()), "AverageMigrations[avmigrations]" );
+ df.Write(min_migrations, "MinMigrations[minmigrations]" );
+ df.Write(max_migrations, "MaxMigrations[maxmigrations]" );
+ df.Write((total_suicides/total_migrations), "SuicideMigrationRate[suicidemigrationrate]" );
+
+ df.Endl();
+}
+
+
+
+
void cStats::CompeteDemes(const std::vector<double>& fitness) {
m_deme_fitness = fitness;
}
Modified: development/source/main/cStats.h
===================================================================
--- development/source/main/cStats.h 2009-01-10 22:24:39 UTC (rev 3099)
+++ development/source/main/cStats.h 2009-01-11 02:36:00 UTC (rev 3100)
@@ -841,7 +841,11 @@
void PrintDemeCurrentTaskExeData(const cString& filename);
void PrintCurrentTaskCounts(const cString& filename);
void PrintPerDemeGenPerFounderData(const cString& filename);
+ void PrintDemeMigrationSuicidePoints(const cString& filename);
+
+
+
void IncNumOccupiedDemes() { m_num_occupied_demes++; }
void ClearNumOccupiedDemes() { m_num_occupied_demes = 0; }
int GetNumOccupiedDemes() { return m_num_occupied_demes; }
More information about the Avida-cvs
mailing list