[Avida-SVN] r3187 - in branches/hjg-dev/source: actions cpu main
hjg at myxo.css.msu.edu
hjg at myxo.css.msu.edu
Mon Mar 9 12:45:54 PDT 2009
Author: hjg
Date: 2009-03-09 15:45:54 -0400 (Mon, 09 Mar 2009)
New Revision: 3187
Modified:
branches/hjg-dev/source/actions/PrintActions.cc
branches/hjg-dev/source/cpu/cHardwareCPU.cc
branches/hjg-dev/source/main/cStats.cc
branches/hjg-dev/source/main/cStats.h
branches/hjg-dev/source/main/cTaskLib.cc
branches/hjg-dev/source/main/cTaskLib.h
Log:
greenbeard stats tracking.
Modified: branches/hjg-dev/source/actions/PrintActions.cc
===================================================================
--- branches/hjg-dev/source/actions/PrintActions.cc 2009-03-09 15:41:18 UTC (rev 3186)
+++ branches/hjg-dev/source/actions/PrintActions.cc 2009-03-09 19:45:54 UTC (rev 3187)
@@ -114,6 +114,7 @@
// reputation
STATS_OUT_FILE(PrintReputationData, reputation.dat);
+STATS_OUT_FILE(PrintGreenBeardSupport, gbstrategy.dat);
STATS_OUT_FILE(PrintDirectReciprocityData, reciprocity.dat);
STATS_OUT_FILE(PrintStringMatchData, stringmatch.dat);
@@ -2754,8 +2755,10 @@
action_lib->Register<cActionPrintReputationData>("PrintReputationData");
action_lib->Register<cActionPrintDirectReciprocityData>("PrintDirectReciprocityData");
action_lib->Register<cActionPrintStringMatchData>("PrintStringMatchData");
+ action_lib->Register<cActionPrintGreenBeardSupport>("PrintGreenBeardSupport");
+
// Grid Information Dumps
action_lib->Register<cActionDumpMemory>("DumpMemory");
Modified: branches/hjg-dev/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/hjg-dev/source/cpu/cHardwareCPU.cc 2009-03-09 15:41:18 UTC (rev 3186)
+++ branches/hjg-dev/source/cpu/cHardwareCPU.cc 2009-03-09 19:45:54 UTC (rev 3187)
@@ -3605,6 +3605,29 @@
neighbor = organism->GetNeighbor();
if (neighbor != NULL &&
genotype->GetPhyloDistance(neighbor->GetGenotype()) <= max_dist) {
+
+ // Code to track the edit distance between kin donors and recipients
+ const int edit_dist = cGenomeUtil::FindEditDistance(organism->GetGenome(),neighbor->GetGenome());
+
+ static ofstream kin_file("kin_dists.dat");
+ static int num_kin_donates = 0;
+ static int num_kin_donates_15_dist = 0;
+ static int tot_dist_kin_donate = 0;
+
+ num_kin_donates++;
+ if (edit_dist > 15) num_kin_donates_15_dist++;
+ tot_dist_kin_donate += edit_dist;
+
+ if (num_kin_donates == 1000) {
+ kin_file << num_kin_donates << " "
+ << (double) num_kin_donates_15_dist / (double) num_kin_donates << " "
+ << (double) tot_dist_kin_donate / (double) num_kin_donates << endl;
+
+ num_kin_donates = 0;
+ num_kin_donates_15_dist = 0;
+ tot_dist_kin_donate = 0;
+ }
+
found = true;
break;
}
@@ -3656,6 +3679,30 @@
}
if (edit_dist <= max_dist) {
found = true;
+
+ // Code to track the edit distance between edt donors and recipients
+ const int edit_dist = cGenomeUtil::FindEditDistance(organism->GetGenome(),neighbor->GetGenome());
+
+ static ofstream edit_file("edit_dists.dat");
+ static int num_edit_donates = 0;
+ static int num_edit_donates_15_dist = 0;
+ static int tot_dist_edit_donate = 0;
+
+ num_edit_donates++;
+ if (edit_dist > 15) num_edit_donates_15_dist++;
+ tot_dist_edit_donate += edit_dist;
+
+ if (num_edit_donates == 1000) {
+ edit_file << num_edit_donates << " "
+ << (double) num_edit_donates_15_dist / (double) num_edit_donates << " "
+ << (double) tot_dist_edit_donate / (double) num_edit_donates << endl;
+
+ num_edit_donates = 0;
+ num_edit_donates_15_dist = 0;
+ tot_dist_edit_donate = 0;
+ }
+
+
break;
}
organism->Rotate(1);
@@ -3818,6 +3865,29 @@
if (neighbor_shade_of_gb >= shade_of_gb) {
+ // Code to track the edit distance between shaded donors and recipients
+ const int edit_dist = cGenomeUtil::FindEditDistance(organism->GetGenome(),neighbor->GetGenome());
+
+ static ofstream gb_file("shaded_gb_dists.dat");
+ static int num_gb_donates = 0;
+ static int num_gb_donates_15_dist = 0;
+ static int tot_dist_gb_donate = 0;
+
+ num_gb_donates++;
+ if (edit_dist > 15) num_gb_donates_15_dist++;
+ tot_dist_gb_donate += edit_dist;
+
+ if (num_gb_donates == 1000) {
+ gb_file << num_gb_donates << " "
+ << (double) num_gb_donates_15_dist / (double) num_gb_donates << " "
+ << (double) tot_dist_gb_donate / (double) num_gb_donates << endl;
+
+ num_gb_donates = 0;
+ num_gb_donates_15_dist = 0;
+ tot_dist_gb_donate = 0;
+ }
+
+
// const cGenome & neighbor_genome = neighbor->GetGenome();
found = true;
@@ -3998,6 +4068,28 @@
if (neighbor_thresh_of_gb >= m_world->GetConfig().MIN_GB_DONATE_THRESHOLD.Get() ) {
const cGenome & neighbor_genome = neighbor->GetGenome();
+ // Code to track the edit distance between tgb donors and recipients
+ const int edit_dist = cGenomeUtil::FindEditDistance(organism->GetGenome(),neighbor->GetGenome());
+
+ static ofstream tgb_file("thresh_gb_dists.dat");
+ static int num_tgb_donates = 0;
+ static int num_tgb_donates_15_dist = 0;
+ static int tot_dist_tgb_donate = 0;
+
+ num_tgb_donates++;
+ if (edit_dist > 15) num_tgb_donates_15_dist++;
+ tot_dist_tgb_donate += edit_dist;
+
+ if (num_tgb_donates == 1000) {
+ tgb_file << num_tgb_donates << " "
+ << (double) num_tgb_donates_15_dist / (double) num_tgb_donates << " "
+ << (double) tot_dist_tgb_donate / (double) num_tgb_donates << endl;
+
+ num_tgb_donates = 0;
+ num_tgb_donates_15_dist = 0;
+ tot_dist_tgb_donate = 0;
+ }
+
// for each instruction in the genome...
for(int i=0;i<neighbor_genome.GetSize();i++){
Modified: branches/hjg-dev/source/main/cStats.cc
===================================================================
--- branches/hjg-dev/source/main/cStats.cc 2009-03-09 15:41:18 UTC (rev 3186)
+++ branches/hjg-dev/source/main/cStats.cc 2009-03-09 19:45:54 UTC (rev 3187)
@@ -135,6 +135,13 @@
, m_deme_num_repls(0)
, m_donate_to_donor (0)
, m_donate_to_facing (0)
+ , m_num_kin (0)
+ , m_num_edt (0)
+ , m_num_thresh_gb (0)
+ , m_num_shaded_gb (0)
+ , m_num_gb (0)
+ , m_num_rand (0)
+ , m_num_nopx (0)
{
const cEnvironment& env = m_world->GetEnvironment();
const int num_tasks = env.GetNumTasks();
@@ -1978,3 +1985,30 @@
df.Endl();
}
+
+void cStats::PrintGreenBeardSupport(const cString& filename) {
+ cDataFile& df = m_world->GetDataFile(filename);
+ df.WriteComment("The donation strategies preferred by an organism.");
+ df.WriteTimeStamp();
+ df.Write(m_update, "Update [update]");
+ df.Write(m_num_kin, "Kin [kin]");
+ df.Write(m_num_edt, "Edit [edit]");
+ df.Write(m_num_thresh_gb, "Thresh [thresh]");
+ df.Write(m_num_shaded_gb, "Shaded [shaded]");
+ df.Write(m_num_gb, "GB [gb]");
+ df.Write(m_num_rand, "Rand [rand]");
+ df.Write(m_num_nopx, "NopX [nopx]");
+
+ m_num_kin =0;
+ m_num_edt = 0;
+ m_num_thresh_gb =0;
+ m_num_shaded_gb =0;
+ m_num_gb =0;
+ m_num_rand =0;
+ m_num_nopx =0;
+
+ df.Endl();
+
+}
+
+
Modified: branches/hjg-dev/source/main/cStats.h
===================================================================
--- branches/hjg-dev/source/main/cStats.h 2009-03-09 15:41:18 UTC (rev 3186)
+++ branches/hjg-dev/source/main/cStats.h 2009-03-09 19:45:54 UTC (rev 3187)
@@ -805,6 +805,25 @@
cDoubleSum m_perfect_match_org;
std::map <int, int> m_tags;
+
+ // -------- Green beard support ---------
+public:
+ void PrintGreenBeardSupport(const cString& filename);
+ void IncNumKin() {m_num_kin++;}
+ void IncNumEdt() {m_num_edt++;}
+ void IncNumThreshGB() {m_num_thresh_gb++;}
+ void IncNumShadedGB() {m_num_shaded_gb++;}
+ void IncNumGB() {m_num_gb++;}
+ void IncNumRand() {m_num_rand++; }
+ void IncNumNopX() {m_num_nopx++; }
+protected:
+ int m_num_kin;
+ int m_num_edt;
+ int m_num_thresh_gb;
+ int m_num_shaded_gb;
+ int m_num_gb;
+ int m_num_rand;
+ int m_num_nopx;
// -------- Deme replication support --------
public:
Modified: branches/hjg-dev/source/main/cTaskLib.cc
===================================================================
--- branches/hjg-dev/source/main/cTaskLib.cc 2009-03-09 15:41:18 UTC (rev 3186)
+++ branches/hjg-dev/source/main/cTaskLib.cc 2009-03-09 19:45:54 UTC (rev 3187)
@@ -35,8 +35,10 @@
#include "cPopulationCell.h"
#include "cOrgMessagePredicate.h"
#include "cOrgMovementPredicate.h"
+#include "cHardwareManager.h"
+
#include "platform.h"
#include <cstdlib>
@@ -435,6 +437,10 @@
NewTask(name, "Produce and store perfect strings", &cTaskLib::Task_CreatePerfectStrings);
else if(name == "perfect_strings2")
NewTask(name, "Produce and store perfect strings", &cTaskLib::Task_CreatePerfectStrings2);
+
+ else if(name == "classify_donors")
+ NewTask(name, "Track which donation strategy is employed by organisms", &cTaskLib::Task_ClassifyDonors);
+
@@ -3289,4 +3295,85 @@
return bonus;
}
+/* Classify organisms by what type of donation they performed most
+ frequently. Should only be used on divide.*/
+double cTaskLib::Task_ClassifyDonors(cTaskContext& ctx) const {
+ // Ok, keep track of the number of each type executed...
+
+ cPhenotype & phenotype = ctx.GetOrganism()->GetPhenotype();
+
+ if (phenotype.GetCurInstCount().GetSize() == 0) return 0.0;
+ // Identify how many shaded green beard donations this organisms made
+ // First figure out what number instruction donate-shadedgb is
+ cInstSet& inst_set = m_world->GetHardwareManager().GetInstSet();
+ const int num_inst = m_world->GetNumInstructions();
+
+
+ //int num_nopx; (0)
+ //int num_kin; (1)
+ //int num_edt; (2)
+ //int num_thresh_gb; (3)
+ //int num_shaded_gb; (4)
+ //int num_gb; (5)
+ //int num_rand; (6)
+
+ // Init vector to 0.
+ vector<int> inst_count(7, 0);
+
+
+ int inst_number = 0;
+ for (int i = 0; i < num_inst; i++) {
+
+ if ((inst_set.GetName(i) == "nop-X")) {
+ inst_count[0] = phenotype.GetCurInstCount()[i];
+ } else if ((inst_set.GetName(i) == "donate-kin")){
+ inst_count[1] = phenotype.GetCurInstCount()[i];
+ } else if ((inst_set.GetName(i) == "donate-edt")){
+ inst_count[2] = phenotype.GetCurInstCount()[i];
+ } else if ((inst_set.GetName(i) == "donate-threshgb")){
+ inst_count[3] = phenotype.GetCurInstCount()[i];
+ } else if ((inst_set.GetName(i) == "donate-shadedgb")) {
+ inst_count[4] = phenotype.GetCurInstCount()[i];
+ } else if ((inst_set.GetName(i) == "donate-tgb")) {
+ inst_count[5] = phenotype.GetCurInstCount()[i];
+ } else if ((inst_set.GetName(i) == "donate-rnd")) {
+ inst_count[6] = phenotype.GetCurInstCount()[i];
+ }
+ }
+
+
+ int max = 0;
+ int max_i = -1;
+ for (int i = 0; i<7; i++) {
+ if (inst_count[i] > max) {
+ max_i = i;
+ }
+ }
+
+ switch (max_i) {
+ case 0:
+ m_world->GetStats().IncNumNopX();
+ break;
+ case 1:
+ m_world->GetStats().IncNumKin();
+ break;
+ case 2:
+ m_world->GetStats().IncNumEdt();
+ break;
+ case 3:
+ m_world->GetStats().IncNumThreshGB();
+ break;
+ case 4:
+ m_world->GetStats().IncNumShadedGB();
+ break;
+ case 5:
+ m_world->GetStats().IncNumGB();
+ break;
+ case 6:
+ m_world->GetStats().IncNumRand();
+ break;
+ }
+ return 0.0;
+
+}
Modified: branches/hjg-dev/source/main/cTaskLib.h
===================================================================
--- branches/hjg-dev/source/main/cTaskLib.h 2009-03-09 15:41:18 UTC (rev 3186)
+++ branches/hjg-dev/source/main/cTaskLib.h 2009-03-09 19:45:54 UTC (rev 3187)
@@ -48,6 +48,7 @@
class cWorld;
+
class cTaskLib
{
private:
@@ -307,8 +308,6 @@
double Task_EventKilled(cTaskContext& ctx) const;
// reputation
-
-
double Task_GoodReputation(cTaskContext& ctx) const;
double Task_ConsumeRawMaterials(cTaskContext& ctx) const;
double Task_UseRawMaterials(cTaskContext& ctx) const;
@@ -317,7 +316,7 @@
double Task_CreatePerfectStrings(cTaskContext& ctx) const;
double Task_CreatePerfectStrings2(cTaskContext& ctx) const;
-
+ double Task_ClassifyDonors(cTaskContext& ctx) const;
};
More information about the Avida-cvs
mailing list