[Avida-SVN] r2834 - in branches/hjg-dev/source: cpu main
hjg at myxo.css.msu.edu
hjg at myxo.css.msu.edu
Sat Oct 11 14:08:56 PDT 2008
Author: hjg
Date: 2008-10-11 17:08:56 -0400 (Sat, 11 Oct 2008)
New Revision: 2834
Modified:
branches/hjg-dev/source/cpu/cHardwareCPU.cc
branches/hjg-dev/source/cpu/cHardwareCPU.h
branches/hjg-dev/source/main/cAvidaConfig.h
branches/hjg-dev/source/main/cOrganism.cc
branches/hjg-dev/source/main/cOrganism.h
branches/hjg-dev/source/main/cStats.cc
Log:
Added infrastructure for enabling organism's to manually compute reputations (praise-neighbor, punish-neighbor instructions).
Modified: branches/hjg-dev/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/hjg-dev/source/cpu/cHardwareCPU.cc 2008-10-10 22:50:47 UTC (rev 2833)
+++ branches/hjg-dev/source/cpu/cHardwareCPU.cc 2008-10-11 21:08:56 UTC (rev 2834)
@@ -457,10 +457,9 @@
tInstLibEntry<tMethod>("get-reputation", &cHardwareCPU::Inst_GetReputation, nInstFlag::STALL),
tInstLibEntry<tMethod>("get-raw-mat-amount", &cHardwareCPU::Inst_GetAmountOfRawMaterials, nInstFlag::STALL),
tInstLibEntry<tMethod>("donation-scam", &cHardwareCPU::Inst_DonationScam, nInstFlag::STALL),
-
-
+ tInstLibEntry<tMethod>("punish-neighbor", &cHardwareCPU::Inst_PunishNeighbor, nInstFlag::STALL),
+ tInstLibEntry<tMethod>("praise-neighbor", &cHardwareCPU::Inst_PraiseNeighbor, nInstFlag::STALL),
-
// Must always be the last instruction in the array
tInstLibEntry<tMethod>("NULL", &cHardwareCPU::Inst_Nop, 0, "True no-operation instruction: does nothing"),
};
@@ -6730,11 +6729,13 @@
// update reputation to include this donation.
// get the current reputation; increment by 1.
- if (organism->HasOpinion()) {
- int opinion = organism->GetOpinion().first + 1;
- organism->SetOpinion(opinion);
- } else {
- organism->SetOpinion(1);
+ if (m_world->GetConfig().AUTO_REPUTATION.Get()) {
+ if (organism->HasOpinion()) {
+ int opinion = organism->GetOpinion().first + 1;
+ organism->SetOpinion(opinion);
+ } else {
+ organism->SetOpinion(1);
+ }
}
}
@@ -6817,5 +6818,34 @@
}
+/* Punish Neighbor - decrease reputation of neighbor */
+bool cHardwareCPU::Inst_PunishNeighbor(cAvidaContext& ctx)
+{
+ cOrganism * neighbor = organism->GetNeighbor();
+ // improve neighbor reputation
+ if (neighbor != NULL && neighbor->HasOpinion()) {
+ int opinion = neighbor->GetOpinion().first - 1;
+ neighbor->SetOpinion(opinion);
+ } else {
+ neighbor->SetOpinion(-1);
+ }
+ return true;
+}
+/* Praise Neighbor - increase reputation of neighbor */
+bool cHardwareCPU::Inst_PraiseNeighbor(cAvidaContext& ctx)
+{
+ cOrganism * neighbor = organism->GetNeighbor();
+
+ // improve neighbor reputation
+ if (neighbor != NULL && neighbor->HasOpinion()) {
+ int opinion = neighbor->GetOpinion().first + 1;
+ neighbor->SetOpinion(opinion);
+ } else {
+ neighbor->SetOpinion(1);
+ }
+ return true;
+}
+
+
Modified: branches/hjg-dev/source/cpu/cHardwareCPU.h
===================================================================
--- branches/hjg-dev/source/cpu/cHardwareCPU.h 2008-10-10 22:50:47 UTC (rev 2833)
+++ branches/hjg-dev/source/cpu/cHardwareCPU.h 2008-10-11 21:08:56 UTC (rev 2834)
@@ -686,6 +686,11 @@
bool Inst_GetAmountOfRawMaterials(cAvidaContext& ctx);
// Pretend to donate
bool Inst_DonationScam(cAvidaContext& ctx);
+ // Punish Neighbor - increase reputation of neighbor
+ bool Inst_PunishNeighbor(cAvidaContext& ctx);
+ // Praise Neighbor - decrease reputation of neighbor
+ bool Inst_PraiseNeighbor(cAvidaContext& ctx);
+
};
Modified: branches/hjg-dev/source/main/cAvidaConfig.h
===================================================================
--- branches/hjg-dev/source/main/cAvidaConfig.h 2008-10-10 22:50:47 UTC (rev 2833)
+++ branches/hjg-dev/source/main/cAvidaConfig.h 2008-10-11 21:08:56 UTC (rev 2834)
@@ -558,6 +558,7 @@
CONFIG_ADD_CUSTOM_FORMAT(REPUTATION_GROUP, "Reputation Settings");
CONFIG_ADD_VAR(RAW_MATERIAL_AMOUNT, int, 100, "Number of raw materials an organism starts with");
+ CONFIG_ADD_VAR(AUTO_REPUTATION, bool, 1, "Is an organism's reputation automatically computed based on its donations");
#endif
Modified: branches/hjg-dev/source/main/cOrganism.cc
===================================================================
--- branches/hjg-dev/source/main/cOrganism.cc 2008-10-10 22:50:47 UTC (rev 2833)
+++ branches/hjg-dev/source/main/cOrganism.cc 2008-10-11 21:08:56 UTC (rev 2834)
@@ -770,10 +770,13 @@
return isSuccessful;
}
-/* Called when a orgaism receives a donation in order to turn the recipient to
-face its donor. It is designed to work in conjunction with the fact that an
-orgaism donates to the neighbor it is facing. */
-//void cOrganism::RotateToFaceOrganism(cOrganism& org) {
-// this->GetWorld()->GetPopulation().GetCell(this->GetCellID()).ConnectionList().Front().ConnectionList().Rotate(org);
-//}
+int cOrganism::GetReputation() {
+ int rep =0;
+
+ if (HasOpinion()) {
+ rep = GetOpinion().first;
+ }
+
+ return rep;
+}
Modified: branches/hjg-dev/source/main/cOrganism.h
===================================================================
--- branches/hjg-dev/source/main/cOrganism.h 2008-10-10 22:50:47 UTC (rev 2833)
+++ branches/hjg-dev/source/main/cOrganism.h 2008-10-11 21:08:56 UTC (rev 2834)
@@ -452,7 +452,9 @@
// retrieve the amount of raw materials collected from others
int GetOtherRawMaterials() { return m_other_raw_materials; }
// get the number of donations
- int GetReputation() { return (m_world->GetConfig().RAW_MATERIAL_AMOUNT.Get() - m_self_raw_materials); }
+ int GetNumberOfDonations() { return (m_world->GetConfig().RAW_MATERIAL_AMOUNT.Get() - m_self_raw_materials); }
+ // get the organism's reputation
+ int GetReputation();
protected:
// Initialize reputation support
Modified: branches/hjg-dev/source/main/cStats.cc
===================================================================
--- branches/hjg-dev/source/main/cStats.cc 2008-10-10 22:50:47 UTC (rev 2833)
+++ branches/hjg-dev/source/main/cStats.cc 2008-10-11 21:08:56 UTC (rev 2834)
@@ -1721,6 +1721,8 @@
cDataFile& df = m_world->GetDataFile(filename);
cDoubleSum reputations;
+ cDoubleSum donations;
+
int min_rep = 100;
int max_rep = 0;
int cur_rep;
@@ -1741,6 +1743,7 @@
if (cur_rep < min_rep) min_rep = cur_rep;
if (max_rep < cur_rep) max_rep = cur_rep;
reputations.Add(cur_rep);
+ donations.Add(cell.GetOrganism()->GetNumberOfDonations());
pop_size++;
if (cur_rep > 0) num_alt++;
@@ -1748,6 +1751,7 @@
}
// float rep = reputations/pop_size;
df.Write(reputations.Average(), "Avg. reputation");
+ df.Write(donations.Average(), "Avg. donations");
df.Write(reputations.StdDeviation(), "Standard Deviation");
df.Write(min_rep, "Minimum reputation");
df.Write(max_rep, "Maximum reputation");
More information about the Avida-cvs
mailing list