[Avida-SVN] r2893 - in branches/movement/source: actions main
grabow38 at myxo.css.msu.edu
grabow38 at myxo.css.msu.edu
Tue Oct 28 12:17:20 PDT 2008
Author: grabow38
Date: 2008-10-28 15:17:20 -0400 (Tue, 28 Oct 2008)
New Revision: 2893
Modified:
branches/movement/source/actions/PopulationActions.cc
branches/movement/source/main/cAvidaConfig.h
branches/movement/source/main/cDeme.h
branches/movement/source/main/cPopulation.cc
Log:
Bug fix in cAbstractCompeteDemes_ConsumeCellResources.
Modified: branches/movement/source/actions/PopulationActions.cc
===================================================================
--- branches/movement/source/actions/PopulationActions.cc 2008-10-28 04:01:39 UTC (rev 2892)
+++ branches/movement/source/actions/PopulationActions.cc 2008-10-28 19:17:20 UTC (rev 2893)
@@ -1342,6 +1342,7 @@
fitness.push_back(Fitness(m_world->GetPopulation().GetDeme(i)));
assert(fitness.back() >= 0.0);
}
+
m_world->GetPopulation().CompeteDemes(fitness);
}
@@ -1696,28 +1697,35 @@
// Compete demes based on how much resource has been consumed within the deme
class cAbstractCompeteDemes_ConsumeCellResources : public cAbstractCompeteDemes {
public:
+ //! Constructor
cAbstractCompeteDemes_ConsumeCellResources(cWorld* world, const cString& args) : cAbstractCompeteDemes(world, args) { }
-
+
+ //! Destructor
+ virtual ~cAbstractCompeteDemes_ConsumeCellResources() { }
+
static const cString GetDescription() { return "No Arguments"; }
- double Fitness(const cDeme& deme) {
+ virtual double Fitness(const cDeme& deme) {
- cResourceCount res = deme.GetDemeResourceCount();
- double current_res = 0.0;// Current total resource in deme
- double initial_res = 0.0;// Initial total resource in deme
-
- for (int i = 0; i < res.GetSize(); i++) {
- if ( (res.GetResourcesGeometry())[i] != nGeometry::GLOBAL) {
- cSpatialResCount sp_res = res.GetSpatialResource(i);
- current_res += sp_res.GetAmount(i);
- initial_res += res.GetInitialResourceValue(i);
- }
- }
+ // Current total resource in deme
+ double current_res = 0.0;
+ // Initial resource in deme
+ double initial_res = (double) deme.GetWidth() * deme.GetHeight() * m_world->GetConfig().DEMES_INITIAL_CELL_RES_AMT.Get();
- // Fitness is square of how much resource has been consumed
- double fitnessOfDeme = pow( (initial_res - current_res), 2.0);
+ tArray<int> cell_ids = deme.GetCellIDList();
- return fitnessOfDeme;
+ for ( int j = 0; j < cell_ids.GetSize(); j++ ) {
+ cResourceCount res = deme.GetDemeResourceCount();
+ tArray<double> res_counts = res.GetCellResources(j);
+ for (int i = 0; i< res.GetSize(); i++) {
+ current_res += res_counts[i];
+ }
+ }
+
+ // Fitness is square of how much resource has been consumed
+ double fitnessOfDeme = pow( (initial_res - current_res), 2.0);
+
+ return fitnessOfDeme;
}
};
Modified: branches/movement/source/main/cAvidaConfig.h
===================================================================
--- branches/movement/source/main/cAvidaConfig.h 2008-10-28 04:01:39 UTC (rev 2892)
+++ branches/movement/source/main/cAvidaConfig.h 2008-10-28 19:17:20 UTC (rev 2893)
@@ -329,7 +329,8 @@
CONFIG_ADD_VAR(DEMES_DEFAULT_GERMLINE_PROPENSITY, double, 0.0, "Default germline propensity of organisms in deme.\nFor use with DEMES_DIVIDE_METHOD 2.");
CONFIG_ADD_VAR(DEMES_FOUNDER_GERMLINE_PROPENSITY, double, -1.0, "Default germline propensity of founder organisms in deme.\nFor use with DEMES_DIVIDE_METHOD 2.\n <0 = OFF");
CONFIG_ADD_VAR(DEMES_PREFER_EMPTY, int, 0, "Give empty demes preference as targets of deme replication?");
-
+ CONFIG_ADD_VAR(DEMES_INITIAL_CELL_RES_AMT, double, 0.0, "Initial localized (cell) resource amount for localized resource in deme (default = 0.0).");
+
CONFIG_ADD_GROUP(REPRODUCTION_GROUP, "Birth and Death");
CONFIG_ADD_VAR(BIRTH_METHOD, int, 0, "Which organism should be replaced on birth?\n0 = Random organism in neighborhood\n1 = Oldest in neighborhood\n2 = Largest Age/Merit in neighborhood\n3 = None (use only empty cells in neighborhood)\n4 = Random from population (Mass Action)\n5 = Oldest in entire population\n6 = Random within deme\n7 = Organism faced by parent\n8 = Next grid cell (id+1)\n9 = Largest energy used in entire population\n10 = Largest energy used in neighborhood");
CONFIG_ADD_VAR(PREFER_EMPTY, int, 1, "Give empty cells preference in offsping placement?");
Modified: branches/movement/source/main/cDeme.h
===================================================================
--- branches/movement/source/main/cDeme.h 2008-10-28 04:01:39 UTC (rev 2892)
+++ branches/movement/source/main/cDeme.h 2008-10-28 19:17:20 UTC (rev 2893)
@@ -135,6 +135,7 @@
int GetCellID(int pos) const { return cell_ids[pos]; }
int GetCellID(int x, int y) const;
int GetDemeID() const { return _id; }
+ tArray<int> GetCellIDList() const { return cell_ids; } // @ LMG
//! Returns an (x,y) pair for the position of the passed-in cell ID.
std::pair<int, int> GetCellPosition(int cellid) const;
cPopulationCell& GetCell(int pos) const;
Modified: branches/movement/source/main/cPopulation.cc
===================================================================
--- branches/movement/source/main/cPopulation.cc 2008-10-28 04:01:39 UTC (rev 2892)
+++ branches/movement/source/main/cPopulation.cc 2008-10-28 19:17:20 UTC (rev 2893)
@@ -2303,7 +2303,7 @@
}
break;
}
- case 3: { // Spin to face N @ LMG
+ case 3: { // Spin to face N @ LMG.
cell.Rotate(cell_array[GridNeighbor(cell.GetID()-deme.GetCellID(0),
deme.GetWidth(),
deme.GetHeight(), 0, -1)+deme.GetCellID(0)]);
More information about the Avida-cvs
mailing list