[Avida-SVN] r2922 - in branches/movement/source: actions main
grabow38 at myxo.css.msu.edu
grabow38 at myxo.css.msu.edu
Thu Nov 6 05:21:59 PST 2008
Author: grabow38
Date: 2008-11-06 08:21:59 -0500 (Thu, 06 Nov 2008)
New Revision: 2922
Modified:
branches/movement/source/actions/PopulationActions.cc
branches/movement/source/main/cAvidaConfig.h
branches/movement/source/main/cDeme.cc
branches/movement/source/main/cDeme.h
branches/movement/source/main/cPopulation.cc
branches/movement/source/main/cResourceCount.cc
branches/movement/source/main/cResourceCount.h
Log:
Overall cell resource totaling and initial cell resource counts added to cDeme.
Modified: branches/movement/source/actions/PopulationActions.cc
===================================================================
--- branches/movement/source/actions/PopulationActions.cc 2008-11-06 05:26:00 UTC (rev 2921)
+++ branches/movement/source/actions/PopulationActions.cc 2008-11-06 13:21:59 UTC (rev 2922)
@@ -1707,23 +1707,24 @@
virtual double Fitness(const cDeme& deme) {
- // 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();
-
- tArray<int> cell_ids = deme.GetCellIDList();
-
- 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];
- }
+
+ double current_res = 0.0; // Current total resource in deme
+ double initial_res = 0.0; // Current initial resource in deme
+ tArray<double> init_counts = deme.GetDemeInitCellResSum(); // Initial counts of all resources
+ tArray<double> curr_counts = deme.GetDemeCurrentCellResSum(); // Current counts of all resources
+
+ // Total all initial resources and current resources (if there are multiple resources)
+ for (int i = 0; i< curr_counts.GetSize(); i++) {
+ initial_res += init_counts[i];
+ current_res +=curr_counts[i];
}
// Fitness is square of how much resource has been consumed
double fitnessOfDeme = pow( (initial_res - current_res), 2.0);
+
+ // Debugging output
+ //cout << "Deme " << deme.GetID() << " Fitness " << fitnessOfDeme
+ // << " Init " << initial_res << " Curr " << current_res << endl;
return fitnessOfDeme;
}
Modified: branches/movement/source/main/cAvidaConfig.h
===================================================================
--- branches/movement/source/main/cAvidaConfig.h 2008-11-06 05:26:00 UTC (rev 2921)
+++ branches/movement/source/main/cAvidaConfig.h 2008-11-06 13:21:59 UTC (rev 2922)
@@ -330,7 +330,8 @@
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_VAR(DEMES_SUM_INIT_CELL_RES, int, 0, "Save sum of inital cell resource amounts 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.cc
===================================================================
--- branches/movement/source/main/cDeme.cc 2008-11-06 05:26:00 UTC (rev 2921)
+++ branches/movement/source/main/cDeme.cc 2008-11-06 13:21:59 UTC (rev 2922)
@@ -283,6 +283,11 @@
if(resetResources) {
deme_resource_count.ReinitializeResources(additional_resource);
+
+ // @ LMG
+ if ( m_world->GetConfig().DEMES_SUM_INIT_CELL_RES.Get() ) {
+ DoSumDemeCellResources(deme_init_spatial_res_count);
+ }
}
}
@@ -436,9 +441,62 @@
if(res->GetEnergyResource()) {
energy_res_ids.Push(id);
+ }
+
+ if ( m_world->GetConfig().DEMES_SUM_INIT_CELL_RES.Get() ) {
+ DoSumDemeCellResources(deme_init_spatial_res_count);
}
+ else {
+ deme_init_spatial_res_count.SetAll(0.0);
+ }
}
+// @ LMG
+// Sums the amount of cell resources in the deme
+void cDeme::DoSumDemeCellResources(tArray<double>& deme_res_count_array)
+{
+ tArray<double> cell_res_counts;
+ cell_res_counts.Resize(deme_resource_count.GetSize());
+ deme_res_count_array.Resize(deme_resource_count.GetSize());
+ deme_res_count_array.SetAll(0.0);
+
+ // cout << "Cell resource array size: " << cell_res_counts.GetSize() << endl;
+ // cout << "Deme resource array size: " << deme_res_count_array.GetSize() << endl;
+
+ for (int i = 0; i < cell_ids.GetSize(); i++) {
+ cell_res_counts = deme_resource_count.GetCellResources(i);
+// cout << "Deme res count " << deme_resource_count.GetSize() << endl;
+ for (int j = 0; j < deme_resource_count.GetSize(); j++) {
+ if ( cell_res_counts[j] > 0.0 ) {
+ deme_res_count_array[j] += cell_res_counts[j];
+// cout << "Deme resource array position " << j << "res amount " << deme_res_count_array[j] << " Cell res amt " << endl;
+ }
+ }
+ }
+}
+
+const tArray<double>& cDeme::GetDemeCurrentCellResSum() const
+{
+ tArray<double> cell_res_counts;
+ tArray<double> deme_res_count_array;
+ cell_res_counts.Resize(deme_resource_count.GetSize());
+ deme_res_count_array.Resize(deme_resource_count.GetSize());
+ deme_res_count_array.SetAll(0.0);
+ cell_res_counts.Resize(deme_resource_count.GetSize());
+
+ deme_res_count_array.SetAll(0.0);
+
+ for (int i = 0; i < cell_ids.GetSize(); i++) {
+ cell_res_counts = deme_resource_count.GetCellResources(i);
+ for (int j = 0; j < deme_resource_count.GetSize(); j++) {
+ if ( cell_res_counts[j] > 0.0 ) {
+ deme_res_count_array[j] += cell_res_counts[j];
+ }
+ }
+ }
+ return deme_res_count_array;
+}
+
double cDeme::GetAndClearCellEnergy(int absolute_cell_id) {
assert(cell_ids[0] <= absolute_cell_id);
assert(absolute_cell_id <= cell_ids[cell_ids.GetSize()-1]);
Modified: branches/movement/source/main/cDeme.h
===================================================================
--- branches/movement/source/main/cDeme.h 2008-11-06 05:26:00 UTC (rev 2921)
+++ branches/movement/source/main/cDeme.h 2008-11-06 13:21:59 UTC (rev 2922)
@@ -103,6 +103,7 @@
cResourceCount deme_resource_count; //!< Resources available to the deme
tArray<int> energy_res_ids; //!< IDs of energy resources
+ tArray<double> deme_init_spatial_res_count; // Total initial spatial resource count for deme @ LMG
tVector<cDemeCellEvent> cell_events;
std::vector<std::pair<int, int> > event_slot_end_points; // (slot end point, slot flow rate)
@@ -125,7 +126,7 @@
eventsTotal(0), eventsKilled(0), eventsKilledThisSlot(0), eventKillAttempts(0), eventKillAttemptsThisSlot(0),
consecutiveSuccessfulEventPeriods(0), sleeping_count(0),
avg_founder_generation(0.0), generations_per_lifetime(0.0),
- deme_resource_count(0), m_germline_genotype_id(0) { ; }
+ deme_resource_count(0), deme_init_spatial_res_count(0), m_germline_genotype_id(0) { ; }
~cDeme() { ; }
void Setup(int id, const tArray<int>& in_cells, int in_width = -1, cWorld* world = NULL);
@@ -232,6 +233,9 @@
void GiveBackCellEnergy(int absolute_cell_id, double value);
void SetupDemeRes(int id, cResource * res, int verbosity);
void UpdateDemeRes() { deme_resource_count.GetResources(); }
+ void DoSumDemeCellResources(tArray<double>& deme_res_count_array);// @ LMG Sums spatial resources in the deme
+ const tArray<double>& GetDemeInitCellResSum() const { return deme_init_spatial_res_count; } // Returns sum of initial spatial resources
+ const tArray<double>& GetDemeCurrentCellResSum() const; // { return deme_sum_spatial_res_count; } // Returns sum of current spatial resources
void Update(double time_step) { deme_resource_count.Update(time_step); }
int GetRelativeCellID(int absolute_cell_id) const { return absolute_cell_id % GetSize(); } //!< assumes all demes are the same size
Modified: branches/movement/source/main/cPopulation.cc
===================================================================
--- branches/movement/source/main/cPopulation.cc 2008-11-06 05:26:00 UTC (rev 2921)
+++ branches/movement/source/main/cPopulation.cc 2008-11-06 13:21:59 UTC (rev 2922)
@@ -944,17 +944,19 @@
int target_cell_id = org1->GetTargetCellID();
int target_x = target_cell_id % world_x;
int target_y = target_cell_id / world_x;
+ int facing_dir = org1-> GetFacing();
ofstream movelog;
movelog.open("data/movelog.txt",ios::app);
- // By columns: org ID, from cell xy, to cell xy
+ // By columns: org ID, from cell xy, to cell xy, target x, target y, facing
movelog << cid << " " <<
x1 << " " <<
y1 << " " <<
x << " " <<
y << " " <<
target_x << " " <<
- target_y << " " << endl;
+ target_y << " " <<
+ facing_dir << endl;
movelog.close();
}
} else {
Modified: branches/movement/source/main/cResourceCount.cc
===================================================================
--- branches/movement/source/main/cResourceCount.cc 2008-11-06 05:26:00 UTC (rev 2921)
+++ branches/movement/source/main/cResourceCount.cc 2008-11-06 13:21:59 UTC (rev 2922)
@@ -147,7 +147,7 @@
spatial_resource_count.ResizeClear(num_resources);
curr_grid_res_cnt.ResizeClear(num_resources);
curr_spatial_res_cnt.ResizeClear(num_resources);
-
+
resource_name.SetAll("");
resource_initial.SetAll(0.0);
resource_count.SetAll(0.0);
Modified: branches/movement/source/main/cResourceCount.h
===================================================================
--- branches/movement/source/main/cResourceCount.h 2008-11-06 05:26:00 UTC (rev 2921)
+++ branches/movement/source/main/cResourceCount.h 2008-11-06 13:21:59 UTC (rev 2922)
@@ -55,7 +55,7 @@
tArray<int> geometry; // Spatial layout of each resource
mutable tArray<cSpatialResCount> spatial_resource_count;
mutable tArray<double> curr_grid_res_cnt;
- mutable tArray< tArray<double> > curr_spatial_res_cnt;
+ mutable tArray< tArray<double> > curr_spatial_res_cnt;
int verbosity;
// Setup the update process to use lazy evaluation...
@@ -89,7 +89,7 @@
int GetResourceCountID(const cString& res_name);
void SetInflow(const cString& name, const double _inflow);
void SetDecay(const cString& name, const double _decay);
-
+
void Update(double in_time);
int GetSize(void) const { return resource_count.GetSize(); }
More information about the Avida-cvs
mailing list