[Avida-SVN] r2370 - in development/source: actions tools
brysonda at myxo.css.msu.edu
brysonda at myxo.css.msu.edu
Sat Feb 23 12:53:11 PST 2008
Author: brysonda
Date: 2008-02-23 15:53:11 -0500 (Sat, 23 Feb 2008)
New Revision: 2370
Modified:
development/source/actions/PopulationActions.cc
development/source/tools/cDemeProbSchedule.cc
development/source/tools/cDemeProbSchedule.h
development/source/tools/cProbDemeProbSchedule.cc
development/source/tools/cProbDemeProbSchedule.h
Log:
Fix several compile warnings. Add some cleanup code to the deme schedulers.
Modified: development/source/actions/PopulationActions.cc
===================================================================
--- development/source/actions/PopulationActions.cc 2008-02-23 20:48:59 UTC (rev 2369)
+++ development/source/actions/PopulationActions.cc 2008-02-23 20:53:11 UTC (rev 2370)
@@ -368,9 +368,11 @@
double m_div_mut_rate;
int m_lineage_label;
double m_neutral_metric;
+
+
public:
cActionInjectSequenceWithDivMutRate(cWorld* world, const cString& args)
- : cAction(world, args), m_cell_start(0), m_cell_end(-1), m_div_mut_rate(0.0),m_merit(-1), m_lineage_label(0), m_neutral_metric(0)
+ : cAction(world, args), m_cell_start(0), m_cell_end(-1), m_merit(-1), m_div_mut_rate(0.0), m_lineage_label(0), m_neutral_metric(0)
{
cString largs(args);
m_sequence = largs.PopWord();
Modified: development/source/tools/cDemeProbSchedule.cc
===================================================================
--- development/source/tools/cDemeProbSchedule.cc 2008-02-23 20:48:59 UTC (rev 2369)
+++ development/source/tools/cDemeProbSchedule.cc 2008-02-23 20:53:11 UTC (rev 2370)
@@ -41,21 +41,20 @@
//get the next CPU cycle, awarded to the next populated deme and cycled in a round-robin fashion
int cDemeProbSchedule::GetNextID()
{
- //iterate the deme
+ // iterate the deme
curr_deme = ++curr_deme % num_demes;
//loop to check each deme at most once -- this could be a problem in sparse pops, best to start with populated or mostly-poulated demes
- for (int i = 0; i < num_demes; i++){
+ for (int i = 0; i < num_demes; i++) {
- //check to see if deme is populated
- if (chart[curr_deme]->GetTotalWeight() == 0){
-
- //deme is empty -- iterate the deme
+ // check to see if deme is populated
+ if (chart[curr_deme]->GetTotalWeight() == 0) {
+ // deme is empty -- iterate the deme
curr_deme = ++curr_deme % num_demes;
- }
- else{ //deme not empty -- return offset id
+ } else {
+ // deme not empty -- return offset id
- //calculate the offset
+ // calculate the offset
int offset = curr_deme * deme_size;
// get the within postion of the node whos corresponding cell will get the CPU cycle
@@ -65,6 +64,9 @@
return chart[curr_deme]->FindPosition(position) + offset;
}
}
+
+ assert(false);
+ return -1;
}
Modified: development/source/tools/cDemeProbSchedule.h
===================================================================
--- development/source/tools/cDemeProbSchedule.h 2008-02-23 20:48:59 UTC (rev 2369)
+++ development/source/tools/cDemeProbSchedule.h 2008-02-23 20:53:11 UTC (rev 2370)
@@ -35,11 +35,6 @@
#ifndef cWeightedIndex_h
#include "cWeightedIndex.h"
#endif
-//need a pointer to the world to figure out number of demes
-#ifndef cWorld_h
-#include "cWorld.h"
-#endif
-//need tList to construct array of trees
#ifndef tArray_h
#include "tArray.h"
#endif
@@ -59,37 +54,34 @@
{
private:
- //Keep our own RNG so as to better preserve consistancy.
+ // Keep our own RNG so as to better preserve consistancy.
cRandom m_rng;
- //Array of WeightedIndex tree's to farm out the scheduling.
+ // Array of WeightedIndex tree's to farm out the scheduling.
tArray<cWeightedIndex*> chart;
- //how many demes are there?
+ // how many demes are there?
int num_demes;
- //size of each deme... num_cells/num_demes
+ // size of each deme... num_cells/num_demes
int deme_size;
- //what deme should GetNextID give the next CPU cycle to?
+ // what deme should GetNextID give the next CPU cycle to?
int curr_deme;
- //const cWorld* m_world;
-
cDemeProbSchedule(const cDemeProbSchedule&); // @not_implemented
cDemeProbSchedule& operator=(const cDemeProbSchedule&); // @not_implemented
+
public:
- cDemeProbSchedule(int num_cells, int seed, int ndemes) : cSchedule(num_cells), m_rng(seed), num_demes(ndemes) {
-
- deme_size = num_cells/num_demes;
+ cDemeProbSchedule(int num_cells, int seed, int ndemes) : cSchedule(num_cells), m_rng(seed), num_demes(ndemes)
+ {
+ deme_size = num_cells / num_demes;
- for(int i = 0; i < num_demes; i++){
- chart.Push(new cWeightedIndex(deme_size));
- }
+ for(int i = 0; i < num_demes; i++) chart.Push(new cWeightedIndex(deme_size));
}
- ~cDemeProbSchedule() { ; }
+ ~cDemeProbSchedule() { for (int i = 0; i < chart.GetSize(); i++) delete chart[i]; }
void Adjust(int item_id, const cMerit& merit, int deme_id=0);
int GetNextID();
Modified: development/source/tools/cProbDemeProbSchedule.cc
===================================================================
--- development/source/tools/cProbDemeProbSchedule.cc 2008-02-23 20:48:59 UTC (rev 2369)
+++ development/source/tools/cProbDemeProbSchedule.cc 2008-02-23 20:53:11 UTC (rev 2370)
@@ -52,8 +52,6 @@
// return the adjusted ID of the cell to get the CPU cycle
return chart[curr_deme]->FindPosition(position) + offset;
-
-
}
@@ -64,13 +62,12 @@
int offset_id = item_id - (deme_id * deme_size);
//is this cell about to be populated by a living organism?
- if(item_merit.GetDouble() > 0.0){
- if(chart[deme_id]->GetWeight(offset_id) == 0.0){ //...was it previously unpopulated? -- if so, population size has increased
+ if (item_merit.GetDouble() > 0.0) {
+ if (chart[deme_id]->GetWeight(offset_id) == 0.0) { //...was it previously unpopulated? -- if so, population size has increased
demeChart.SetWeight(deme_id,demeChart.GetWeight(deme_id) + 1.0);//increment the deme's weight to reflect the new population size
}
- }
- else { //by definition the merit is zero -- no such thing as merits less than 0.0 in Avida
- if(chart[deme_id]->GetWeight(offset_id) > 0.0){ //...was the cell previously populated -- is so, populatino size has decreased
+ } else { //by definition the merit is zero -- no such thing as merits less than 0.0 in Avida
+ if (chart[deme_id]->GetWeight(offset_id) > 0.0) { //...was the cell previously populated -- is so, populatino size has decreased
demeChart.SetWeight(deme_id,demeChart.GetWeight(deme_id) - 1.0);//decrement the deme's weight to reflect the new population size
}
}
Modified: development/source/tools/cProbDemeProbSchedule.h
===================================================================
--- development/source/tools/cProbDemeProbSchedule.h 2008-02-23 20:48:59 UTC (rev 2369)
+++ development/source/tools/cProbDemeProbSchedule.h 2008-02-23 20:53:11 UTC (rev 2370)
@@ -35,11 +35,6 @@
#ifndef cWeightedIndex_h
#include "cWeightedIndex.h"
#endif
-//need a pointer to the world to figure out number of demes
-#ifndef cWorld_h
-#include "cWorld.h"
-#endif
-//need tList to construct array of trees
#ifndef tArray_h
#include "tArray.h"
#endif
@@ -59,41 +54,41 @@
{
private:
- //Keep our own RNG so as to better preserve consistancy.
+ // Keep our own RNG so as to better preserve consistancy.
cRandom m_rng;
- //Array of WeightedIndex tree's to farm out the scheduling.
+ // Array of WeightedIndex tree's to farm out the scheduling.
tArray<cWeightedIndex*> chart;
- //WeightedIndex tree for scheduling demes based on population size.
+ // WeightedIndex tree for scheduling demes based on population size.
cWeightedIndex demeChart;
- //how many demes are there?
+ // how many demes are there?
int num_demes;
- //size of each deme... num_cells/num_demes
+ // size of each deme... num_cells/num_demes
int deme_size;
- //what deme should GetNextID give the next CPU cycle to?
+ // what deme should GetNextID give the next CPU cycle to?
int curr_deme;
cProbDemeProbSchedule(const cProbDemeProbSchedule&); // @not_implemented
cProbDemeProbSchedule& operator=(const cProbDemeProbSchedule&); // @not_implemented
+
public:
- cProbDemeProbSchedule(int num_cells, int seed, int ndemes) : cSchedule(num_cells), m_rng(seed), num_demes(ndemes), demeChart(ndemes) {
+ cProbDemeProbSchedule(int num_cells, int seed, int ndemes)
+ : cSchedule(num_cells), m_rng(seed), demeChart(ndemes), num_demes(ndemes)
+ {
+ deme_size = num_cells / num_demes;
- deme_size = num_cells/num_demes;
-
- for(int i = 0; i < num_demes; i++){
- chart.Push(new cWeightedIndex(deme_size));
- }
+ for (int i = 0; i < num_demes; i++) chart.Push(new cWeightedIndex(deme_size));
}
- ~cProbDemeProbSchedule() { ; }
+ ~cProbDemeProbSchedule() { for (int i = 0; i < chart.GetSize(); i++) delete chart[i]; }
- void Adjust(int item_id, const cMerit& merit, int deme_id=0);
+ void Adjust(int item_id, const cMerit& merit, int deme_id = 0);
int GetNextID();
};
More information about the Avida-cvs
mailing list