[Avida-SVN] r2837 - in branches/hjg-dev/source: cpu main
hjg at myxo.css.msu.edu
hjg at myxo.css.msu.edu
Sun Oct 12 08:13:09 PDT 2008
Author: hjg
Date: 2008-10-12 11:13:09 -0400 (Sun, 12 Oct 2008)
New Revision: 2837
Modified:
branches/hjg-dev/source/cpu/cHardwareCPU.cc
branches/hjg-dev/source/main/cOrganism.cc
branches/hjg-dev/source/main/cOrganism.h
branches/hjg-dev/source/main/cStats.cc
Log:
Added stats to track number of cooperative partners.
Modified: branches/hjg-dev/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/hjg-dev/source/cpu/cHardwareCPU.cc 2008-10-12 03:53:59 UTC (rev 2836)
+++ branches/hjg-dev/source/cpu/cHardwareCPU.cc 2008-10-12 15:13:09 UTC (rev 2837)
@@ -6718,7 +6718,7 @@
// Subtract raw materials from the organism (currently subtracts 1 resource...)
// fails if the organism does not have any more resources
if (organism->SubtractSelfRawMaterials(1)) {
- neighbor->AddOtherRawMaterials(1);
+ neighbor->AddOtherRawMaterials(1, organism->GetID());
// rotate recipient to face donor
// by rotating until the recipient faces the donor
Modified: branches/hjg-dev/source/main/cOrganism.cc
===================================================================
--- branches/hjg-dev/source/main/cOrganism.cc 2008-10-12 03:53:59 UTC (rev 2836)
+++ branches/hjg-dev/source/main/cOrganism.cc 2008-10-12 15:13:09 UTC (rev 2837)
@@ -763,10 +763,11 @@
The boolean flag is used to indicate if the reception was successful, which should always
be the case... */
-bool cOrganism::AddOtherRawMaterials (int amount) {
+bool cOrganism::AddOtherRawMaterials (int amount, int donor_id) {
bool isSuccessful = true;
// InitReputation();
m_other_raw_materials += amount;
+ donor_list.insert(donor_id);
return isSuccessful;
}
Modified: branches/hjg-dev/source/main/cOrganism.h
===================================================================
--- branches/hjg-dev/source/main/cOrganism.h 2008-10-12 03:53:59 UTC (rev 2836)
+++ branches/hjg-dev/source/main/cOrganism.h 2008-10-12 15:13:09 UTC (rev 2837)
@@ -29,6 +29,7 @@
#include <iostream>
#include <string>
#include <vector>
+#include <set>
#ifndef cCPUMemory_h
#include "cCPUMemory.h"
@@ -446,7 +447,7 @@
// donate raw materials to others
bool SubtractSelfRawMaterials(int amount);
// receive raw materials from others
- bool AddOtherRawMaterials(int amount);
+ bool AddOtherRawMaterials(int amount, int donor_id);
// retrieve the organism's own amount of raw materials
int GetSelfRawMaterials() { return m_self_raw_materials; }
// retrieve the amount of raw materials collected from others
@@ -455,6 +456,8 @@
int GetNumberOfDonations() { return (m_world->GetConfig().RAW_MATERIAL_AMOUNT.Get() - m_self_raw_materials); }
// get the organism's reputation
int GetReputation();
+ // get number of donors
+ int GetNumberOfDonors() { return donor_list.size(); }
protected:
// Initialize reputation support
@@ -463,7 +466,10 @@
int m_self_raw_materials;
// The raw materials an oranism has collected from others
int m_other_raw_materials;
-
+ // Organisms that have donated to this organism
+ set<int> donor_list;
+
+
// -------- End of reputation support --------
};
Modified: branches/hjg-dev/source/main/cStats.cc
===================================================================
--- branches/hjg-dev/source/main/cStats.cc 2008-10-12 03:53:59 UTC (rev 2836)
+++ branches/hjg-dev/source/main/cStats.cc 2008-10-12 15:13:09 UTC (rev 2837)
@@ -1722,6 +1722,7 @@
cDoubleSum reputations;
cDoubleSum donations;
+ cDoubleSum donors;
int min_rep = 100;
int max_rep = 0;
@@ -1744,6 +1745,7 @@
if (max_rep < cur_rep) max_rep = cur_rep;
reputations.Add(cur_rep);
donations.Add(cell.GetOrganism()->GetNumberOfDonations());
+ donors.Add(cell.GetOrganism()->GetNumberOfDonors());
pop_size++;
if (cur_rep > 0) num_alt++;
@@ -1752,11 +1754,13 @@
// float rep = reputations/pop_size;
df.Write(reputations.Average(), "Avg. reputation");
df.Write(donations.Average(), "Avg. donations");
+ df.Write(donors.Average(), "Avg. number of donors partners");
df.Write(reputations.StdDeviation(), "Standard Deviation");
df.Write(min_rep, "Minimum reputation");
df.Write(max_rep, "Maximum reputation");
df.Write(num_alt, "Number of altruists");
+
df.Endl();
}
More information about the Avida-cvs
mailing list