[Avida-SVN] r2894 - in branches/hjg-dev/source: cpu main
hjg at myxo.css.msu.edu
hjg at myxo.css.msu.edu
Tue Oct 28 19:55:39 PDT 2008
Author: hjg
Date: 2008-10-28 22:55:38 -0400 (Tue, 28 Oct 2008)
New Revision: 2894
Modified:
branches/hjg-dev/source/cpu/cHardwareCPU.cc
branches/hjg-dev/source/cpu/cHardwareCPU.h
branches/hjg-dev/source/cpu/cTestCPUInterface.h
branches/hjg-dev/source/main/cOrgInterface.h
branches/hjg-dev/source/main/cOrganism.cc
branches/hjg-dev/source/main/cOrganism.h
branches/hjg-dev/source/main/cPopulationInterface.cc
branches/hjg-dev/source/main/cPopulationInterface.h
Log:
added nowak reputation-based scheme
Modified: branches/hjg-dev/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/hjg-dev/source/cpu/cHardwareCPU.cc 2008-10-28 19:17:20 UTC (rev 2893)
+++ branches/hjg-dev/source/cpu/cHardwareCPU.cc 2008-10-29 02:55:38 UTC (rev 2894)
@@ -453,6 +453,7 @@
// Reputation instructions
tInstLibEntry<tMethod>("donate-frm", &cHardwareCPU::Inst_DonateFacingRawMaterials, nInstFlag::STALL),
+ tInstLibEntry<tMethod>("donate-k", &cHardwareCPU::Inst_DonateFacingConditionalOnK, nInstFlag::STALL),
tInstLibEntry<tMethod>("donate-pr", &cHardwareCPU::Inst_DonateProbReciprocate, nInstFlag::STALL),
tInstLibEntry<tMethod>("get-neighbors-reputation", &cHardwareCPU::Inst_GetNeighborsReputation, nInstFlag::STALL),
tInstLibEntry<tMethod>("get-reputation", &cHardwareCPU::Inst_GetReputation, nInstFlag::STALL),
@@ -463,7 +464,10 @@
tInstLibEntry<tMethod>("praise-neighbor", &cHardwareCPU::Inst_PraiseNeighbor, nInstFlag::STALL),
tInstLibEntry<tMethod>("inc-recip", &cHardwareCPU::Inst_IncRecipProb, nInstFlag::STALL),
tInstLibEntry<tMethod>("dec-recip", &cHardwareCPU::Inst_DecRecipProb, nInstFlag::STALL),
+ tInstLibEntry<tMethod>("inc-k", &cHardwareCPU::Inst_IncK, nInstFlag::STALL),
+ tInstLibEntry<tMethod>("dec-k", &cHardwareCPU::Inst_DecK, nInstFlag::STALL),
tInstLibEntry<tMethod>("rotate-to-rep", &cHardwareCPU::Inst_RotateToGreatestReputation, nInstFlag::STALL),
+ tInstLibEntry<tMethod>("rotate-to-rep-k", &cHardwareCPU::Inst_RotateToReputationK, nInstFlag::STALL),
tInstLibEntry<tMethod>("rotate-to-rep-and-donate", &cHardwareCPU::Inst_RotateToGreatestReputationAndDonate, nInstFlag::STALL),
@@ -6705,8 +6709,22 @@
}
+/* Donate raw material to the facing organism if its reputation
+ is > k. */
+bool cHardwareCPU::Inst_DonateFacingConditionalOnK(cAvidaContext& ctx)
+{
+ cOrganism * neighbor = organism->GetNeighbor();
+ int k = organism->GetK();
+ if (neighbor != NULL) {
+ if (k <= neighbor->GetReputation()) {
+ Inst_DonateFacingRawMaterials(ctx);
+ }
+ }
+ return true;
+}
+
/* Donate raw materials to the facing organism. */
bool cHardwareCPU::Inst_DonateFacingRawMaterials(cAvidaContext& ctx)
{
@@ -6946,4 +6964,25 @@
return true;
}
+/* Rotate to face an organism with a reputation of >= k */
+bool cHardwareCPU::Inst_RotateToReputationK(cAvidaContext& ctx)
+{
+ organism->GetOrgInterface().RotateToReputationK(organism->GetK());
+ return true;
+}
+
+/* Decrease the lower reputation bar */
+bool cHardwareCPU:: Inst_DecK(cAvidaContext& ctx)
+{
+ organism->DecK();
+ return true;
+}
+
+/* Increase the lower reputation bar */
+bool cHardwareCPU:: Inst_IncK(cAvidaContext& ctx)
+{
+ organism->IncK();
+ return true;
+}
+
\ No newline at end of file
Modified: branches/hjg-dev/source/cpu/cHardwareCPU.h
===================================================================
--- branches/hjg-dev/source/cpu/cHardwareCPU.h 2008-10-28 19:17:20 UTC (rev 2893)
+++ branches/hjg-dev/source/cpu/cHardwareCPU.h 2008-10-29 02:55:38 UTC (rev 2894)
@@ -678,10 +678,14 @@
*/
// Donate a raw material to the neighbor
bool Inst_DonateFacingRawMaterials(cAvidaContext& ctx);
+ // Donate a raw material to the neighbor, if its reputation > k
+ bool Inst_DonateFacingConditionalOnK(cAvidaContext& ctx);
// Rotate to the organims with the greatest reputation
bool Inst_RotateToGreatestReputation(cAvidaContext& ctx);
// Rotate to the organims with the greatest reputation and donate
bool Inst_RotateToGreatestReputationAndDonate(cAvidaContext& ctx);
+ // Roate to Reputation k
+ bool Inst_RotateToReputationK(cAvidaContext& ctx);
// Get a neighbor's reputation
bool Inst_GetNeighborsReputation(cAvidaContext& ctx);
// Get the organism's reputation
@@ -705,6 +709,10 @@
bool Inst_IncRecipProb(cAvidaContext& ctx);
// Decrease the reciprocation probability
bool Inst_DecRecipProb(cAvidaContext& ctx);
+ // Decrease k (lowest reputation bar)
+ bool Inst_DecK(cAvidaContext& ctx);
+ // Increase k (lowest reputation bar)
+ bool Inst_IncK(cAvidaContext& ctx);
Modified: branches/hjg-dev/source/cpu/cTestCPUInterface.h
===================================================================
--- branches/hjg-dev/source/cpu/cTestCPUInterface.h 2008-10-28 19:17:20 UTC (rev 2893)
+++ branches/hjg-dev/source/cpu/cTestCPUInterface.h 2008-10-29 02:55:38 UTC (rev 2894)
@@ -93,7 +93,8 @@
void DivideOrgTestamentAmongDeme(double value) {;}
- void RotateToGreatestReputation(){ }
+ void RotateToGreatestReputation(){ }
+ void RotateToReputationK(int k){ }
};
Modified: branches/hjg-dev/source/main/cOrgInterface.h
===================================================================
--- branches/hjg-dev/source/main/cOrgInterface.h 2008-10-28 19:17:20 UTC (rev 2893)
+++ branches/hjg-dev/source/main/cOrgInterface.h 2008-10-29 02:55:38 UTC (rev 2894)
@@ -103,6 +103,7 @@
virtual void DivideOrgTestamentAmongDeme(double value) = 0;
virtual void RotateToGreatestReputation() =0;
+ virtual void RotateToReputationK(int k) =0;
};
Modified: branches/hjg-dev/source/main/cOrganism.cc
===================================================================
--- branches/hjg-dev/source/main/cOrganism.cc 2008-10-28 19:17:20 UTC (rev 2893)
+++ branches/hjg-dev/source/main/cOrganism.cc 2008-10-29 02:55:38 UTC (rev 2894)
@@ -83,6 +83,7 @@
, m_num_reciprocate(0)
, m_max_recip_prob(5)
, m_min_recip_prob(5)
+ , m_k(0)
{
m_hardware = m_world->GetHardwareManager().Create(this);
Modified: branches/hjg-dev/source/main/cOrganism.h
===================================================================
--- branches/hjg-dev/source/main/cOrganism.h 2008-10-28 19:17:20 UTC (rev 2893)
+++ branches/hjg-dev/source/main/cOrganism.h 2008-10-29 02:55:38 UTC (rev 2894)
@@ -476,7 +476,13 @@
int GetNumberOfReciprocations() { return m_num_reciprocate; }
// get the change in reciprocal probability
int GetChangeInRecipProb() { return m_max_recip_prob - m_min_recip_prob; }
-
+ // get k
+ int GetK() { return m_k; }
+ // increase k
+ void IncK() { m_k++; }
+ // decrease k
+ void DecK() { m_k--; }
+
protected:
// The organism's own raw materials
int m_self_raw_materials;
@@ -494,6 +500,9 @@
int m_max_recip_prob;
// min-reciprocation probability
int m_min_recip_prob;
+ // reputation minimum for donation/rotation
+ // based on Nowak89
+ int m_k;
// -------- End of reputation support --------
Modified: branches/hjg-dev/source/main/cPopulationInterface.cc
===================================================================
--- branches/hjg-dev/source/main/cPopulationInterface.cc 2008-10-28 19:17:20 UTC (rev 2893)
+++ branches/hjg-dev/source/main/cPopulationInterface.cc 2008-10-29 02:55:38 UTC (rev 2894)
@@ -383,8 +383,8 @@
// if it has high reputation
if (cur_neighbor->GetID() == high_org_id) {
- int test_id = cur_neighbor->GetID();
- int test_rep = cur_neighbor->GetReputation();
+ // int test_id = cur_neighbor->GetID();
+ // int test_rep = cur_neighbor->GetReputation();
break;
}
}
@@ -395,3 +395,57 @@
}
}
+
+
+
+
+/* Rotate an organism to face a neighbor with a reputation of >= k*/
+void cPopulationInterface::RotateToReputationK(int k)
+{
+
+ cPopulationCell& cell = m_world->GetPopulation().GetCell(GetCellID());
+ vector <int> high_rep_orgs;
+
+ // loop to find the max reputation
+ for(int i=0; i<cell.ConnectionList().GetSize(); ++i) {
+ const cPopulationCell* faced_cell = cell.ConnectionList().GetFirst();
+ // cell->organism, if occupied, check reputation, etc.
+ if (IsNeighborCellOccupied()) {
+ cOrganism* cur_neighbor = faced_cell->GetOrganism();
+
+ // if it has high reputation
+ if (cur_neighbor->GetReputation() >= k) {
+ high_rep_orgs.push_back(cur_neighbor->GetID());
+ }
+ }
+
+ // check the next neighbor
+ cell.ConnectionList().CircNext();
+ }
+
+ // Pick an organism to donate to
+
+ if (high_rep_orgs.size() > 0) {
+ unsigned int rand_num = m_world->GetRandom().GetUInt(0, high_rep_orgs.size());
+ int high_org_id = high_rep_orgs[rand_num];
+
+ for(int i=0; i<cell.ConnectionList().GetSize(); ++i) {
+ const cPopulationCell* faced_cell = cell.ConnectionList().GetFirst();
+
+ if (IsNeighborCellOccupied()) {
+
+ cOrganism* cur_neighbor = faced_cell->GetOrganism();
+ // int test_rep = cell.ConnectionList().GetFirst()->GetOrganism()->GetReputation();
+
+ // if it has high reputation
+ if (cur_neighbor->GetID() == high_org_id) {
+ int test_id = cur_neighbor->GetID();
+ int test_rep = cur_neighbor->GetReputation();
+ break;
+ }
+ }
+ cell.ConnectionList().CircNext();
+
+ }
+ }
+}
Modified: branches/hjg-dev/source/main/cPopulationInterface.h
===================================================================
--- branches/hjg-dev/source/main/cPopulationInterface.h 2008-10-28 19:17:20 UTC (rev 2893)
+++ branches/hjg-dev/source/main/cPopulationInterface.h 2008-10-29 02:55:38 UTC (rev 2894)
@@ -109,6 +109,7 @@
// Reputation
void RotateToGreatestReputation();
+ void RotateToReputationK(int k);
void DivideOrgTestamentAmongDeme(double value);
};
More information about the Avida-cvs
mailing list