[Avida-SVN] r2177 - in branches/dkdev/source: actions cpu main
dknoester at myxo.css.msu.edu
dknoester at myxo.css.msu.edu
Sat Nov 3 06:11:35 PDT 2007
Author: dknoester
Date: 2007-11-03 09:11:34 -0400 (Sat, 03 Nov 2007)
New Revision: 2177
Modified:
branches/dkdev/source/actions/PopulationActions.cc
branches/dkdev/source/cpu/cHardwareCPU.cc
branches/dkdev/source/main/cOrganism.cc
branches/dkdev/source/main/cOrganism.h
branches/dkdev/source/main/cPopulation.cc
Log:
Resilient region declaration (count-based).
Modified: branches/dkdev/source/actions/PopulationActions.cc
===================================================================
--- branches/dkdev/source/actions/PopulationActions.cc 2007-11-02 19:17:17 UTC (rev 2176)
+++ branches/dkdev/source/actions/PopulationActions.cc 2007-11-03 13:11:34 UTC (rev 2177)
@@ -910,7 +910,8 @@
else if (in_trigger == "topo-ladder-cpl-merit") m_rep_trigger = 18;
else if (in_trigger == "two-cells-region-latched") m_rep_trigger = 19;
else if (in_trigger == "two-cells-germline-region") m_rep_trigger = 20;
-// else if (in_trigger == "topo-2cells-path-merit") m_rep_trigger = 8;
+ else if (in_trigger == "two-cells-germline-region-count") m_rep_trigger = 21;
+ // else if (in_trigger == "topo-2cells-path-merit") m_rep_trigger = 8;
// else if (in_trigger == "message-collection") m_rep_trigger = 9;
else {
cString err("Unknown replication trigger '");
Modified: branches/dkdev/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/dkdev/source/cpu/cHardwareCPU.cc 2007-11-02 19:17:17 UTC (rev 2176)
+++ branches/dkdev/source/cpu/cHardwareCPU.cc 2007-11-03 13:11:34 UTC (rev 2177)
@@ -3834,7 +3834,7 @@
bool cHardwareCPU::Inst_RegionDown(cAvidaContext& ctx) {
if(organism->GetCellID() == -1) return false;
- organism->SetRegion(0);
+ organism->SetRegion(-1);
return true;
}
Modified: branches/dkdev/source/main/cOrganism.cc
===================================================================
--- branches/dkdev/source/main/cOrganism.cc 2007-11-02 19:17:17 UTC (rev 2176)
+++ branches/dkdev/source/main/cOrganism.cc 2007-11-03 13:11:34 UTC (rev 2177)
@@ -58,6 +58,7 @@
, m_msg_rtrv_index(0)
, _region(0)
, _region_latched(false)
+ , _region_count(0)
{
// Initialization of structures...
m_hardware = m_world->GetHardwareManager().Create(this);
@@ -577,3 +578,12 @@
return &m_msg_recv.at(m_msg_rtrv_index++);
}
}
+
+
+void cOrganism::SetRegion(int region) {
+ if(!_region_latched) {
+ _region = region;
+ _region_latched = true;
+ }
+ _region_count += region;
+}
Modified: branches/dkdev/source/main/cOrganism.h
===================================================================
--- branches/dkdev/source/main/cOrganism.h 2007-11-02 19:17:17 UTC (rev 2176)
+++ branches/dkdev/source/main/cOrganism.h 2007-11-03 13:11:34 UTC (rev 2177)
@@ -281,9 +281,11 @@
private:
bool _region_latched;
int _region;
+ int _region_count;
public:
- void SetRegion(int region) { if(!_region_latched) { _region = region; _region_latched = true; } }
+ void SetRegion(int region);
int GetRegion() const { return _region; }
+ int GetRegionCount() const { return _region_count; }
bool IsRegionLatched() const { return _region_latched; }
};
Modified: branches/dkdev/source/main/cPopulation.cc
===================================================================
--- branches/dkdev/source/main/cPopulation.cc 2007-11-02 19:17:17 UTC (rev 2176)
+++ branches/dkdev/source/main/cPopulation.cc 2007-11-03 13:11:34 UTC (rev 2177)
@@ -75,7 +75,7 @@
if((self_xy.second >= (cell1_xy.second)) && (organism->GetRegion()==1)) {
result += 1.0;
// std::cout << " up.";
- } else if((self_xy.second <= (cell1_xy.second)) && (organism->GetRegion()==0)) {
+ } else if((self_xy.second <= (cell1_xy.second)) && (organism->GetRegion()==-1)) {
result += 1.0;
// std::cout << " down.";
}
@@ -89,7 +89,48 @@
};
+/*! As above, this is an accumulator type for adding up the number of organisms that have their
+region correct within a deme. However, this one is based on the number of times that
+an Organism has called the correct region function, as opposed to the *first* one that
+was called.
+*/
+struct correct_region_count_accumulator : std::binary_function<double, cPopulationCell, double> {
+ correct_region_count_accumulator(cDeme& deme) : _deme(deme) { }
+ double operator()(double result, cPopulationCell& cell) {
+ // What are the deme dimensions, and where is the organism located?
+ assert(cell.IsOccupied());
+ cOrganism* organism = cell.GetOrganism();
+ assert(organism != 0);
+ //std::pair<int,int> deme_xy = std::make_pair(_deme.GetWidth(), _deme.GetHeight());
+
+ std::pair<int,int> cells = _deme.GetCellsToLink();
+ std::pair<int,int> cell1_xy = _deme.GetCellPosition(cells.first);
+ std::pair<int,int> self_xy = _deme.GetCellPosition(organism->GetCellID());
+
+ std::cout << "Organism " << organism->GetCellID() << " @ (" << self_xy.first << "," << self_xy.second << ") declares "
+ << organism->GetRegion() << " for cell1 @ (" << cell1_xy.first << "," << cell1_xy.second << ");";
+
+ // Has the organism declared correctly or not? If so, increment result.
+ if((self_xy.second >= (cell1_xy.second)) && (organism->GetRegionCount() > 0)) {
+ result += 1.0;
+ std::cout << " up.";
+ } else if((self_xy.second <= (cell1_xy.second)) && (organism->GetRegionCount() < 0)) {
+ result += 1.0;
+ std::cout << " down.";
+ }
+ std::cout << endl;
+
+ // All done.
+ return result;
+ }
+
+ cDeme& _deme;
+};
+
+
+
+
cPopulation::cPopulation(cWorld* world)
: m_world(world)
, schedule(NULL)
@@ -1084,9 +1125,6 @@
}
if(!all_latched) continue;
-// source_germline_merit = pow(2, std::accumulate(&cell_array.begin()[source_deme.GetCellID(0)],
-// &cell_array.begin()[source_deme.GetCellID(source_deme.GetSize()-1)+1],
-// 0.0, correct_region_accumulator(source_deme)));
source_germline_merit = pow(std::accumulate(&cell_array.begin()[source_deme.GetCellID(0)],
&cell_array.begin()[source_deme.GetCellID(source_deme.GetSize()-1)+1],
0.0, correct_region_accumulator(source_deme)),
@@ -1094,7 +1132,26 @@
break;
}
+ case 21: {
+ // Replicate demes where all organisms in the deme have decided on a region.
+ // Merit is proportional to the number of organisms that have correctly decided.
+ // In this case, their decision is based on the number of times that they have called
+ // the correct region instruction.
+ if(!source_deme.IsFull()) continue;
+ bool all_latched=true;
+ for(int i=0; i<source_deme.GetSize() && all_latched; ++i) {
+ all_latched = all_latched && (cell_array[source_deme.GetCellID(i)].GetOrganism()->GetRegionCount() != 0);
+ }
+ if(!all_latched) continue;
+
+ source_germline_merit = pow(std::accumulate(&cell_array.begin()[source_deme.GetCellID(0)],
+ &cell_array.begin()[source_deme.GetCellID(source_deme.GetSize()-1)+1],
+ 0.0, correct_region_count_accumulator(source_deme)),
+ 2);
+ break;
+ }
+
// case 19: {
// // Replicate demes that have connected two randomly-selected cells.
// // Merit is the inverse of edge count.
@@ -1189,9 +1246,8 @@
// break;
// }
default: {
- cerr << "ERROR: Invalid replication trigger " << rep_trigger
- << " in cPopulation::ReplicateDemes()" << endl;
- continue;
+ cerr << "ERROR: Invalid replication trigger " << rep_trigger << " in cPopulation::ReplicateDemes()" << endl;
+ assert(false);
}
}
More information about the Avida-cvs
mailing list