[Avida-SVN] r2982 - branches/hjg-dev/source/main
hjg at myxo.css.msu.edu
hjg at myxo.css.msu.edu
Thu Nov 27 09:10:48 PST 2008
Author: hjg
Date: 2008-11-27 12:10:48 -0500 (Thu, 27 Nov 2008)
New Revision: 2982
Modified:
branches/hjg-dev/source/main/cOrganism.cc
branches/hjg-dev/source/main/cOrganism.h
branches/hjg-dev/source/main/cTaskLib.cc
Log:
added a reputation based component to string donations, where reputation is tied to string quality.
Modified: branches/hjg-dev/source/main/cOrganism.cc
===================================================================
--- branches/hjg-dev/source/main/cOrganism.cc 2008-11-27 03:14:09 UTC (rev 2981)
+++ branches/hjg-dev/source/main/cOrganism.cc 2008-11-27 17:10:48 UTC (rev 2982)
@@ -852,22 +852,24 @@
void cOrganism::ReceiveString(tBuffer<int> str, int org_id)
{
- m_all_received_messages.push_back(str);
+// m_all_received_messages.push_back(new_donation);
donor_list.insert(org_id);
+ m_all_received_messages.push_back(make_pair(str, org_id));
m_num_donate_received++;
}
/* Return an int that represents the largest number of bits
matched by any of the strings received. */
-int cOrganism::MatchString(const cString& string_to_match)
+std::pair < int, int > cOrganism::MatchString(const cString& string_to_match)
{
int num_matched = 0;
int max_num_matched = 0;
+ int org_id = 0;
if (m_all_received_messages.size()) {
for (unsigned int k = 0; k < m_all_received_messages.size(); k++) {
- tBuffer<int> received = m_all_received_messages[k];
+ tBuffer<int> received = m_all_received_messages[k].first;
num_matched = 0;
for (int j = 0; j < string_to_match.GetSize(); j++)
{
@@ -875,10 +877,13 @@
string_to_match[j]=='1' && received[j]==1)
num_matched++;
}
- if (num_matched > max_num_matched) max_num_matched = num_matched;
+ if (num_matched > max_num_matched){
+ max_num_matched = num_matched;
+ org_id = m_all_received_messages[k].second;
+ }
}
}
- return max_num_matched;
+ return make_pair(max_num_matched, org_id);
}
Modified: branches/hjg-dev/source/main/cOrganism.h
===================================================================
--- branches/hjg-dev/source/main/cOrganism.h 2008-11-27 03:14:09 UTC (rev 2981)
+++ branches/hjg-dev/source/main/cOrganism.h 2008-11-27 17:10:48 UTC (rev 2982)
@@ -113,7 +113,7 @@
tBuffer<int> m_input_buf;
tBuffer<int> m_output_buf;
tBuffer<int> m_received_messages;
- vector < tBuffer<int> > m_all_received_messages;
+// vector < tBuffer<int> > m_all_received_messages;
tList<tListNode<cSaleItem> > m_sold_items;
// Communication
@@ -462,6 +462,8 @@
int GetReputation();
// set the organism's reputation
void SetReputation(int rep);
+ // increment reputation
+ void IncReputation() { SetReputation(GetReputation() + 1); }
// get number of donors
int GetNumberOfDonors() { return donor_list.size(); }
// organism donated
@@ -487,7 +489,7 @@
// Receive a string
void ReceiveString(tBuffer<int> str, int org_id);
// Return the maximum number of characters matched by the received strings
- int MatchString(const cString& str);
+ std::pair < int, int > MatchString(const cString& str);
@@ -509,6 +511,8 @@
// reputation minimum for donation/rotation
// based on Nowak89
int m_k;
+ vector < std::pair < tBuffer<int>, int > > m_all_received_messages;
+
// -------- End of reputation support --------
Modified: branches/hjg-dev/source/main/cTaskLib.cc
===================================================================
--- branches/hjg-dev/source/main/cTaskLib.cc 2008-11-27 03:14:09 UTC (rev 2981)
+++ branches/hjg-dev/source/main/cTaskLib.cc 2008-11-27 17:10:48 UTC (rev 2982)
@@ -1934,7 +1934,9 @@
int num_matched = 0;
int test_output;
int max_num_matched = 0;
+ int max_org_id;
int num_real=0;
+ std::pair < int, int > best_string;
if (!binary)
{
@@ -1961,6 +1963,7 @@
num_matched++;
}
max_num_matched = num_matched;
+ max_org_id = ctx.GetOrganism()->GetID();
}
@@ -1979,14 +1982,39 @@
(string_to_match[string_index]=='1' && (test_output & k))) num_matched++;
}
*/
- num_matched = ctx.GetOrganism()->MatchString(string_to_match);
+ best_string = ctx.GetOrganism()->MatchString(string_to_match);
+ num_matched = best_string.first;
if (num_matched > max_num_matched) {
max_num_matched = num_matched;
+ max_org_id = best_string.second;
used_received = true;
}
// }
// }
+
+ // Update the reputation of the organism whose string we used!
+ // Check if it the organisms string:
+ cOrganism * neighbor = ctx.GetOrganism()->GetNeighbor();
+ if (max_org_id == ctx.GetOrganism()->GetID()) {
+ ctx.GetOrganism()->IncReputation();
+ } else {
+ // Rotate through neigbhors and look for the organism that donated
+ // the string
+ const int num_neighbors = ctx.GetOrganism()->GetNeighborhoodSize();
+ for (int i = 0; i < num_neighbors; i++){
+ // Check if this neigbhor donated the string
+ neighbor = ctx.GetOrganism()->GetNeighbor();
+
+ if ((neighbor != NULL) && (neighbor->GetID() == max_org_id)){
+ neighbor->IncReputation();
+ }
+
+ ctx.GetOrganism()->Rotate(1);
+ }
+
+ }
+
double bonus = 0.0;
// return value between 0 & 1 representing the percentage of string that was matched
More information about the Avida-cvs
mailing list