[Avida-SVN] r2224 - in branches/coopcomm: Avida.xcodeproj source/cpu source/main
dknoester at myxo.css.msu.edu
dknoester at myxo.css.msu.edu
Thu Dec 6 17:49:30 PST 2007
Author: dknoester
Date: 2007-12-06 20:49:30 -0500 (Thu, 06 Dec 2007)
New Revision: 2224
Modified:
branches/coopcomm/Avida.xcodeproj/project.pbxproj
branches/coopcomm/source/cpu/cHardwareCPU.cc
branches/coopcomm/source/main/cOrgMessage.h
branches/coopcomm/source/main/cPopulation.cc
branches/coopcomm/source/main/cStats.cc
branches/coopcomm/source/main/cStats.h
Log:
Additional stats tracking for some old message types.
Modified: branches/coopcomm/Avida.xcodeproj/project.pbxproj
===================================================================
--- branches/coopcomm/Avida.xcodeproj/project.pbxproj 2007-12-04 19:29:08 UTC (rev 2223)
+++ branches/coopcomm/Avida.xcodeproj/project.pbxproj 2007-12-07 01:49:30 UTC (rev 2224)
@@ -363,23 +363,6 @@
E626209E0A372C2A00C07685 /* SaveLoadActions.cc in Sources */ = {isa = PBXBuildFile; fileRef = 708051A80A1F65FE00CBB8B6 /* SaveLoadActions.cc */; };
/* End PBXBuildFile section */
-/* Begin PBXBuildStyle section */
- B5F023EE0B4E9DA800B4F6F4 /* Development */ = {
- isa = PBXBuildStyle;
- buildSettings = {
- COPY_PHASE_STRIP = NO;
- };
- name = Development;
- };
- B5F023EF0B4E9DA800B4F6F4 /* Deployment */ = {
- isa = PBXBuildStyle;
- buildSettings = {
- COPY_PHASE_STRIP = YES;
- };
- name = Deployment;
- };
-/* End PBXBuildStyle section */
-
/* Begin PBXCopyFilesBuildPhase section */
700E2B6D085DE50C00CF158A /* CopyFiles */ = {
isa = PBXCopyFilesBuildPhase;
@@ -931,7 +914,7 @@
DCC315CF076253A5008F7A48 /* Makefile */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.make; path = Makefile; sourceTree = "<group>"; };
DCC315D0076253A5008F7A48 /* task_event_gen.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = task_event_gen.cc; sourceTree = "<group>"; };
DCC315D1076253A5008F7A48 /* task_event_gen.old.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = task_event_gen.old.cc; sourceTree = "<group>"; };
- DCC3164D07626CF3008F7A48 /* avida */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = avida; sourceTree = BUILT_PRODUCTS_DIR; };
+ DCC3164D07626CF3008F7A48 /* avida */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = "compiled.mach-o.executable"; path = avida; sourceTree = BUILT_PRODUCTS_DIR; };
E08178B90B3DCB9600B474B6 /* cTopology.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = cTopology.h; path = source/tools/cTopology.h; sourceTree = SOURCE_ROOT; };
E0DEC26C0B4D3DB200108C0C /* DemeStats.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DemeStats.h; sourceTree = "<group>"; };
E0DEC2700B4D414D00108C0C /* StatsPrinting.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StatsPrinting.h; sourceTree = "<group>"; };
@@ -1774,12 +1757,6 @@
DCC30C4D0762532C008F7A48 /* Project object */ = {
isa = PBXProject;
buildConfigurationList = 702442D70859E0B00059BD9B /* Build configuration list for PBXProject "Avida" */;
- buildSettings = {
- };
- buildStyles = (
- B5F023EE0B4E9DA800B4F6F4 /* Development */,
- B5F023EF0B4E9DA800B4F6F4 /* Deployment */,
- );
hasScannedForEncodings = 0;
mainGroup = DCC30C490762532C008F7A48;
productRefGroup = DCC3164E07626CF3008F7A48 /* Products */;
Modified: branches/coopcomm/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/coopcomm/source/cpu/cHardwareCPU.cc 2007-12-04 19:29:08 UTC (rev 2223)
+++ branches/coopcomm/source/cpu/cHardwareCPU.cc 2007-12-07 01:49:30 UTC (rev 2224)
@@ -3493,6 +3493,21 @@
cOrgMessage msg = cOrgMessage(organism);
msg.SetLabel(GetRegister(label_reg));
msg.SetData(GetRegister(data_reg));
+
+ if(msg.GetData() == organism->GetRandomCellID()) {
+ // Sending it's own ID -- hop count is 0, always.
+ msg.SetHopCount(0);
+ } else {
+ // Ok, potentially sending a message that has been forwarded.
+ cOrganism::t_sorted_messages::iterator i = organism->GetSortedReceivedMessages().find(msg.GetData());
+ if(i == organism->GetSortedReceivedMessages().end()) {
+ // Nope, didn't previously receive this message.
+ msg.SetHopCount(0);
+ } else {
+ // Ok, we've seen this before.
+ msg.SetHopCount(i->second.GetHopCount()+1);
+ }
+ }
return organism->SendMessage(ctx, msg);
}
Modified: branches/coopcomm/source/main/cOrgMessage.h
===================================================================
--- branches/coopcomm/source/main/cOrgMessage.h 2007-12-04 19:29:08 UTC (rev 2223)
+++ branches/coopcomm/source/main/cOrgMessage.h 2007-12-07 01:49:30 UTC (rev 2224)
@@ -27,6 +27,7 @@
cOrganism* m_pReceiver;
unsigned int m_data;
unsigned int m_label;
+ unsigned int m_hop;
cOrgMessage()
: m_pSender(NULL), m_pReceiver(NULL), m_data(0), m_label(0) {
@@ -49,9 +50,11 @@
unsigned int GetData() const { return m_data; }
unsigned int GetLabel() const { return m_label; }
+ unsigned int GetHopCount() const { return m_hop; }
void SetData(unsigned int data) { m_data = data; }
void SetLabel(unsigned int label) { m_label = label; }
+ void SetHopCount(unsigned int hop) { m_hop = hop; }
};
Modified: branches/coopcomm/source/main/cPopulation.cc
===================================================================
--- branches/coopcomm/source/main/cPopulation.cc 2007-12-04 19:29:08 UTC (rev 2223)
+++ branches/coopcomm/source/main/cPopulation.cc 2007-12-07 01:49:30 UTC (rev 2224)
@@ -448,7 +448,7 @@
// Statistics...
cOrganism* organism = in_cell.GetOrganism();
cGenotype* genotype = organism->GetGenotype();
- m_world->GetStats().RecordDeath();
+ m_world->GetStats().RecordDeath(organism);
tList<tListNode<cSaleItem> >* sold_items = organism->GetSoldItems();
if (sold_items)
@@ -2209,4 +2209,4 @@
}
}
return descendants;
-}
\ No newline at end of file
+}
Modified: branches/coopcomm/source/main/cStats.cc
===================================================================
--- branches/coopcomm/source/main/cStats.cc 2007-12-04 19:29:08 UTC (rev 2223)
+++ branches/coopcomm/source/main/cStats.cc 2007-12-07 01:49:30 UTC (rev 2224)
@@ -22,7 +22,7 @@
#include "cGenotype.h"
#include <float.h>
-#include <math.h>
+#include <cmath>
#include <algorithm>
@@ -98,6 +98,7 @@
, m_data_is_sender(0)
, m_data_is_id_and_grt_sender(0)
, m_data_is_leader(0)
+ , m_close_kin(0)
, m_detailedMessageLog(false)
, m_lazyMessageLog(false)
, m_lazyLogging(false)
@@ -894,6 +895,28 @@
}
+/*! A quick-and-dirty way to calculate kinship based on genetic similarity.
+This probably isn't the right way to do this -- But, it should work. The whole
+idea is to reduce kinship between genomes based on genetic differences.
+*/
+int kinship(const cGenome& one, const cGenome& two) {
+ std::string x((const char*)one.AsString());
+ std::string y((const char*)two.AsString());
+ int ks = 0;
+ const unsigned int len = std::min(x.size(), y.size());
+ for(unsigned int i=0; i<len; ++i) {
+ if(x[i] != y[i]) {
+ // Now, if we had an insertion or deletion, what to do?
+ // Let's not worry about it for now...
+ ++ks;
+ }
+ }
+ // Now account for difference in size...
+ ks += labs(x.size()-y.size());
+ return ks;
+}
+
+
/*! This captures all information that can be gleaned from a single message.
IMPORTANT: Go look at the comments here before you rely too heavily on cOrgMessages:
@@ -934,9 +957,32 @@
i!=m_predicate_list.end(); ++i) {
(**i)(msg); // Predicate is responsible for tracking info about messages.
}
+
+ // Added to cover niche-construction hypotheses:
+
+ // How related are the sender & receiver?
+ int ks = kinship(msg.GetSender()->GetGenome(), msg.GetReceiver()->GetGenome());
+ m_relatedness.Add(ks);
+ if(ks<=5) {
+ ++m_close_kin;
+ }
}
+void cStats::RecordDeath(cOrganism* organism) {
+ num_deaths++;
+
+ // And, continuing from above, how many messages did this organism send & receive?
+ m_num_sent_msgs.Add(organism->GetSentMessages().size());
+ m_num_recv_msgs.Add(organism->GetReceivedMessages().size());
+
+ // Now, get the hop counts for the messages that we've received
+ cOrganism::t_sorted_messages& recvd = organism->GetSortedReceivedMessages();
+ for(cOrganism::t_sorted_messages::iterator i = recvd.begin(); i!=recvd.end(); ++i) {
+ m_prop_dist.Add(i->second.GetHopCount());
+ }
+}
+
/*! This captures the maximum fitness of each deme since the last stat reset.
The max of all elements in m_maxDemeFitnesses is the global max deme fitness.
*/
@@ -1060,20 +1106,29 @@
void cStats::PrintMessageSummary(const cString& filename)
{
cDataFile& df = m_world->GetDataFile(filename);
- df.Write(m_update, "Update");
- df.Write(m_count_msgs, "Count of the number of messages sent.");
- df.Write(m_msg_data.Ave(), "Mean of all message data fields.");
- df.Write(m_max_id, "The maximum ID in the population.");
- df.Write(m_data_is_id, "Count of messages where the data field carries an ID.");
- df.Write(m_data_is_sender, "Count of messages where the data field carries the sender's ID.");
- df.Write(m_data_is_id_and_grt_sender, "Count of messages where the data field carries an ID, and is greater than the sender's ID.");
- df.Write(m_data_is_leader, "Count of messages where the data field is the leader's ID.");
- df.Write(m_data_is_id_not_sender.Ave(), "Mean of message data fields where the data field is an ID that is not the sender's ID.");
+ df.Write(m_update, "Update [update]");
+ df.Write(m_count_msgs, "Count of the number of messages sent [total]");
+ df.Write(m_msg_data.Ave(), "Mean of all message data fields [data_mean]");
+ df.Write(m_max_id, "The maximum ID in the population [maxid]");
+ df.Write(m_data_is_id, "Count of messages where the data field carries an ID [isid]");
+ df.Write(m_data_is_sender, "Count of messages where the data field carries the sender's ID [isself]");
+ df.Write(m_data_is_id_and_grt_sender, "Count of messages where the data field carries an ID, and is greater than the sender's ID [grtself]");
+ df.Write(m_data_is_leader, "Count of messages where the data field is the leader's ID [ismaxid]");
+ df.Write(m_data_is_id_not_sender.Ave(), "Mean of message data fields where the data field is an ID that is not the sender's ID [nonsender_mean]");
+ df.Write(m_num_sent_msgs.Ave(), "Mean number of messages sent per organism [mean_sent]");
+ df.Write(m_num_recv_msgs.Ave(), "Mean number of messages received per organism [mean_received]");
+ df.Write(m_relatedness.Ave(), "Mean kinship between message sender and receiver [kinship]");
+ df.Write(m_prop_dist.Ave(), "Mean propagation distance of messages [prop_dist]");
+ df.Write(m_close_kin, "Count of messages sent between close kin [close_kin]");
df.Endl();
m_msg_data.Clear();
m_data_is_id_not_sender.Clear();
- m_count_msgs = m_max_id = m_data_is_id = m_data_is_sender = m_data_is_id_and_grt_sender = m_data_is_leader = 0;
+ m_num_sent_msgs.Clear();
+ m_num_recv_msgs.Clear();
+ m_relatedness.Clear();
+ m_prop_dist.Clear();
+ m_count_msgs = m_max_id = m_data_is_id = m_data_is_sender = m_data_is_id_and_grt_sender = m_data_is_leader = m_close_kin = 0;
}
Modified: branches/coopcomm/source/main/cStats.h
===================================================================
--- branches/coopcomm/source/main/cStats.h 2007-12-04 19:29:08 UTC (rev 2223)
+++ branches/coopcomm/source/main/cStats.h 2007-12-07 01:49:30 UTC (rev 2224)
@@ -237,11 +237,13 @@
// Stats for coop-comm.
unsigned int m_count_msgs; //!< Count of the number of messages sent.
cDoubleSum m_msg_data; //!< Sum of all message data fields.
+ cDoubleSum m_relatedness; //!< Degree of relatedness between sender and receiver.
unsigned int m_max_id; //!< The maximum ID in the population.
unsigned int m_data_is_id; //!< Count of messages where the data field carries an ID.
unsigned int m_data_is_sender; //!< Count of messages where the data field carries the sender's ID.
unsigned int m_data_is_id_and_grt_sender; //!< Count of messages where the data field carries an ID, and is greater than the sender's ID.
unsigned int m_data_is_leader; //!< Count of messages where the data field is the leader's ID.
+ unsigned int m_close_kin; //!< Count of messages sent between close kin (<5 genomic).
cDoubleSum m_data_is_id_not_sender; //!< Sum of message data fields where the data field is an ID that is not the sender's ID.
std::set<int> m_cell_sent_leader; //!< Set of all cells that sent a message carrying the leader's ID.
t_predicate_list m_predicate_list; //!< The list of predicates used to choose which messages to track.
@@ -249,7 +251,12 @@
//! The index of the deme with maximum fitness within m_maxDemeFitness; correlates to
//! the index of the cell range from cPopulation::GetDemes().
unsigned int m_maxDemeIndex;
+
+ cDoubleSum m_num_sent_msgs; //!< Avg. number of messages sent per org.
+ cDoubleSum m_num_recv_msgs; //!< Avg. number of messages received per org.
+ cDoubleSum m_prop_dist; //!< Avg. propagation distance of messages.
+
//! An ElectionRecord is created every time a deme elects a leader.
struct ElectionRecord {
ElectionRecord(int update, unsigned int deme_id, int leader_id, int cell_id, int genomeId)
@@ -477,7 +484,7 @@
void CalcFidelity();
void RecordBirth(int cell_id, int genotype_id, bool breed_true);
- void RecordDeath() { num_deaths++; }
+ void RecordDeath(cOrganism* organism);
void AddGenotype() { tot_genotypes++; }
void RemoveGenotype(int id_num, int parent_id,
int parent_distance, int depth, int max_abundance,
More information about the Avida-cvs
mailing list