[Avida-SVN] r3535 - in branches/topology-manager/source: drivers main
pakanati at myxo.css.msu.edu
pakanati at myxo.css.msu.edu
Wed Nov 18 22:29:22 PST 2009
Author: pakanati
Date: 2009-11-19 01:29:22 -0500 (Thu, 19 Nov 2009)
New Revision: 3535
Modified:
branches/topology-manager/source/drivers/cDefaultRunDriver.cc
branches/topology-manager/source/main/cPopulation.cc
branches/topology-manager/source/main/cPopulation.h
branches/topology-manager/source/main/cPopulationInterface.h
branches/topology-manager/source/main/cTopologyManager.cc
branches/topology-manager/source/main/cTopologyManager.h
branches/topology-manager/source/main/cWorld.cc
branches/topology-manager/source/main/cWorld.h
Log:
another broken version
Modified: branches/topology-manager/source/drivers/cDefaultRunDriver.cc
===================================================================
--- branches/topology-manager/source/drivers/cDefaultRunDriver.cc 2009-11-18 20:58:59 UTC (rev 3534)
+++ branches/topology-manager/source/drivers/cDefaultRunDriver.cc 2009-11-19 06:29:22 UTC (rev 3535)
@@ -34,6 +34,7 @@
#include "cOrganism.h"
#include "cPopulation.h"
#include "cPopulationCell.h"
+#include "cTopologyManager.h"
#include "cStats.h"
#include "cString.h"
#include "cWorld.h"
@@ -45,12 +46,12 @@
using namespace std;
-cDefaultRunDriver::cDefaultRunDriver(cWorld* world) : m_world(world), m_done(false),
- m_fastforward(false),m_last_generation(0), m_generation_same_update_count(0)
+cDefaultRunDriver::cDefaultRunDriver(cWorld* world) : m_world(world), m_done(false),
+ m_fastforward(false),m_last_generation(0), m_generation_same_update_count(0)
{
cDriverManager::Register(this);
world->SetDriver(this);
-
+
// Save this config variable
m_generation_update_fastforward_threshold = m_world->GetConfig().FASTFORWARD_UPDATES.Get();
m_population_fastforward_threshold = m_world->GetConfig().FASTFORWARD_NUM_ORGS.Get();
@@ -67,35 +68,36 @@
{
cClassificationManager& classmgr = m_world->GetClassificationManager();
cPopulation& population = m_world->GetPopulation();
+ cTopologyManager& topology_manager = m_world->GetTopologyManager();
cStats& stats = m_world->GetStats();
-
- const int ave_time_slice = m_world->GetConfig().AVE_TIME_SLICE.Get();
+
+ const int ave_time_slice = m_world->GetConfig().AVE_TIME_SLICE.Get(cDefaultRunDriver);
const double point_mut_prob = m_world->GetConfig().POINT_MUT_PROB.Get();
-
+
void (cPopulation::*ActiveProcessStep)(cAvidaContext& ctx, double step_size, int cell_id) = &cPopulation::ProcessStep;
if (m_world->GetConfig().SPECULATIVE.Get() &&
m_world->GetConfig().THREAD_SLICING_METHOD.Get() != 1 && !m_world->GetConfig().IMPLICIT_REPRO_END.Get()) {
ActiveProcessStep = &cPopulation::ProcessStepSpeculative;
}
-
+
cAvidaContext& ctx = m_world->GetDefaultContext();
-
+
while (!m_done) {
- if (cChangeList* change_list = population.GetChangeList()) {
+ if (cChangeList* change_list = topology_manager.GetChangeList()) {
change_list->Reset();
}
-
+
m_world->GetEvents(ctx);
if (m_done == true) break;
-
+
// Increment the Update.
stats.IncCurrentUpdate();
-
+
// Handle all data collection for previous update.
if (stats.GetUpdate() > 0) {
// Tell the stats object to do update calculations and printing.
stats.ProcessUpdate();
-
+
// Update all the genotypes for the end of this update.
for (cGenotype * cur_genotype = classmgr.ResetThread(0);
cur_genotype != NULL && cur_genotype->GetThreshold();
@@ -103,31 +105,31 @@
cur_genotype->UpdateReset();
}
}
-
+
// don't process organisms if we are in fast-forward mode. -- @JEB
if (!GetFastForward())
{
// Process the update.
const int UD_size = ave_time_slice * population.GetNumOrganisms();
const double step_size = 1.0 / (double) UD_size;
-
+
for (int i = 0; i < UD_size; i++) {
if (population.GetNumOrganisms() == 0) {
m_done = true;
break;
}
- (population.*ActiveProcessStep)(ctx, step_size, population.ScheduleOrganism());
+ (population.*ActiveProcessStep)(ctx, step_size, topology_manager.ScheduleOrganism());
}
}
-
+
// end of update stats...
population.CalcUpdateStats();
-
+
// Process the update for each deme.
for(int i=0; i<population.GetNumDemes(); ++i) {
population.GetDeme(i).ProcessUpdate();
}
-
+
// No viewer; print out status for this update....
if (m_world->GetVerbosity() > VERBOSE_SILENT) {
cout.setf(ios::left);
@@ -145,8 +147,8 @@
if (m_world->GetPopulation().GetNumDemes() > 1) cout << "Demes: " << setw(4) << stats.GetNumOccupiedDemes() << " ";
cout << endl;
}
-
-
+
+
// Do Point Mutations
if (point_mut_prob > 0 ) {
for (int i = 0; i < population.GetSize(); i++) {
@@ -155,10 +157,10 @@
}
}
}
-
+
// Keep track of changes in generation for fast-forward purposes
UpdateFastForward(stats.GetGeneration(),stats.GetNumCreatures());
-
+
// Exit conditons...
if (population.GetNumOrganisms() == 0) m_done = true;
}
Modified: branches/topology-manager/source/main/cPopulation.cc
===================================================================
--- branches/topology-manager/source/main/cPopulation.cc 2009-11-18 20:58:59 UTC (rev 3534)
+++ branches/topology-manager/source/main/cPopulation.cc 2009-11-19 06:29:22 UTC (rev 3535)
@@ -77,11 +77,12 @@
using namespace std;
-cPopulation::cPopulation(cWorld* world, int numcells) // AP add in cTopologyInterface 10/2
-: m_world(world)
+cPopulation::cPopulation(cTopologyManager* top, int num_cells) // AP add in cTopologyInterface 10/2
+: m_world(top->m_world)
+, topology_manager(top)
//, resource_count(world->GetEnvironment().GetResourceLib().GetSize())
-, birth_chamber(world)
-, environment(world->GetEnvironment())
+, birth_chamber(m_world)
+, environment(m_world->GetEnvironment())
, num_organisms(0)
, sync_events(false)
{
@@ -92,9 +93,9 @@
// Setup the cells. Do things that are not dependent upon topology here.
for(int i=0; i<num_cells; ++i) {
- cell_array[i].Setup(world, i, environment.GetMutRates(), i%world_x, i/world_x);
+ cell_array[i].Setup(m_world, i, environment.GetMutRates(), i%world_x, i/world_x);
// Setup the reaper queue.
- if (world->GetConfig().BIRTH_METHOD.Get() == POSITION_CHILD_FULL_SOUP_ELDEST) {
+ if (m_world->GetConfig().BIRTH_METHOD.Get() == POSITION_CHILD_FULL_SOUP_ELDEST) {
reaper_queue.Push(&(cell_array[i]));
}
}
@@ -122,12 +123,12 @@
res->GetInflowY2(), res->GetOutflowX1(),
res->GetOutflowX2(), res->GetOutflowY1(),
res->GetOutflowY2(), res->GetCellListPtr(),
- res->GetCellIdListPtr(), world->GetVerbosity() );
+ res->GetCellIdListPtr(), m_world->GetVerbosity() );
m_world->GetStats().SetResourceName(global_res_index, res->GetName());
} else if(res->GetDemeResource()) {
deme_res_index++;
for(int j = 0; j < GetNumDemes(); j++) {
- GetDeme(j).SetupDemeRes(deme_res_index, res, world->GetVerbosity());
+ GetDeme(j).SetupDemeRes(deme_res_index, res, m_world->GetVerbosity());
// could add deme resources to global resource stats here
}
} else {
@@ -168,20 +169,9 @@
cPopulation::~cPopulation()
{
for (int i = 0; i < cell_array.GetSize(); i++) KillOrganism(cell_array[i]);
- delete schedule;
}
-inline void cPopulation::AdjustSchedule(const cPopulationCell& cell, const cMerit& merit)
-{
- const int deme_id = cell.GetDemeID();
-// cout << " CCC " << deme_id;
- const cDeme& deme = topology_manager->deme_array[deme_id];
- schedule->Adjust(cell.GetID(), deme.HasDemeMerit() ? (merit * deme.GetDemeMerit()) : merit, cell.GetDemeID());
-}
-
-
-
// Activate the child, given information from the parent.
// Return true if parent lives through this process.
@@ -311,7 +301,7 @@
delete test_cpu;
}
}
- AdjustSchedule(parent_cell, parent_phenotype.GetMerit());
+ topology_manager->AdjustSchedule(parent_cell, parent_phenotype.GetMerit());
// In a local run, face the child toward the parent.
const int birth_method = m_world->GetConfig().BIRTH_METHOD.Get();
@@ -466,7 +456,7 @@
m_world->GetClassificationManager().AdjustGenotype(*in_genotype);
// Initialize the time-slice for this new organism.
- AdjustSchedule(target_cell, in_organism->GetPhenotype().GetMerit());
+ topology_manager->AdjustSchedule(target_cell, in_organism->GetPhenotype().GetMerit());
// Special handling for certain birth methods.
if (m_world->GetConfig().BIRTH_METHOD.Get() == POSITION_CHILD_FULL_SOUP_ELDEST) {
@@ -668,7 +658,7 @@
else organism->GetPhenotype().SetToDelete();
// Alert the scheduler that this cell has a 0 merit.
- AdjustSchedule(in_cell, cMerit(0));
+ topology_manager->AdjustSchedule(in_cell, cMerit(0));
// Update the archive (note: genotype adjustment may be defered)
m_world->GetClassificationManager().AdjustGenotype(*genotype);
@@ -806,9 +796,9 @@
cOrganism * org2 = cell2.RemoveOrganism();
if (org2 != NULL) {
cell1.InsertOrganism(org2);
- AdjustSchedule(cell1, org2->GetPhenotype().GetMerit());
+ topology_manager->AdjustSchedule(cell1, org2->GetPhenotype().GetMerit());
} else {
- AdjustSchedule(cell1, cMerit(0));
+ topology_manager->AdjustSchedule(cell1, cMerit(0));
}
if (org1 != NULL) {
cell2.InsertOrganism(org1);
@@ -824,9 +814,9 @@
cAvidaContext& ctx = m_world->GetDefaultContext();
org1->DoOutput(ctx,0);
}
- AdjustSchedule(cell2, org1->GetPhenotype().GetMerit());
+ topology_manager->AdjustSchedule(cell2, org1->GetPhenotype().GetMerit());
} else {
- AdjustSchedule(cell2, cMerit(0));
+ topology_manager->AdjustSchedule(cell2, cMerit(0));
}
}
@@ -1439,12 +1429,6 @@
return num_empty_cells;
}
-
-int cPopulation::ScheduleOrganism()
-{
- return schedule->GetNextID();
-}
-
void cPopulation::ProcessStep(cAvidaContext& ctx, double step_size, int cell_id)
{
assert(step_size > 0.0);
@@ -2126,7 +2110,7 @@
InjectGenotype( current_cell, (*it).genotype );
cPhenotype & phenotype = GetCell(current_cell).GetOrganism()->GetPhenotype();
if ( (*it).merit > 0) phenotype.SetMerit( cMerit((*it).merit) );
- AdjustSchedule(GetCell(current_cell), phenotype.GetMerit());
+ topology_manager->AdjustSchedule(GetCell(current_cell), phenotype.GetMerit());
int lineage_label = 0;
LineageSetupOrganism(GetCell(current_cell).GetOrganism(),
@@ -2324,7 +2308,7 @@
cPhenotype& phenotype = GetCell(cell_id).GetOrganism()->GetPhenotype();
if (tmp.merit > 0) phenotype.SetMerit(cMerit(tmp.merit));
- AdjustSchedule(GetCell(cell_id), phenotype.GetMerit());
+ topology_manager->AdjustSchedule(GetCell(cell_id), phenotype.GetMerit());
LineageSetupOrganism(GetCell(cell_id).GetOrganism(), NULL, 0, tmp.genotype->GetParentGenotype());
}
@@ -2358,23 +2342,7 @@
return true;
}
-bool cPopulation::OK()
-{
- // First check all sub-objects...
- if (!schedule->OK()) return false;
- // Next check organisms...
- for (int i = 0; i < cell_array.GetSize(); i++) {
- assert(cell_array[i].GetID() == i);
- }
-
- // And stats...
- assert(world_x * world_y == cell_array.GetSize());
-
- return true;
-}
-
-
/**
* This function loads a genome from a given file, and initializes
* a cpu with it.
@@ -2403,7 +2371,7 @@
phenotype.SetNeutralMetric(neutral);
if (merit > 0) phenotype.SetMerit(cMerit(merit));
- AdjustSchedule(GetCell(cell_id), phenotype.GetMerit());
+ topology_manager->AdjustSchedule(GetCell(cell_id), phenotype.GetMerit());
LineageSetupOrganism(GetCell(cell_id).GetOrganism(), 0, lineage_label);
@@ -2865,15 +2833,11 @@
if (new_merit <= old_merit) {
phenotype.SetIsDonorCur(); }
else { phenotype.SetIsReceiver(); }
- AdjustSchedule(GetCell(cell_id), phenotype.GetMerit());
+ topology_manager->AdjustSchedule(GetCell(cell_id), phenotype.GetMerit());
return true;
}
-void cPopulation::SetChangeList(cChangeList *change_list){
- schedule->SetChangeList(change_list);
-}
-
void cPopulation::AddBeginSleep(int cellID, int start_time) {
sleep_log[cellID].Add(make_pair(start_time,-1));
}
Modified: branches/topology-manager/source/main/cPopulation.h
===================================================================
--- branches/topology-manager/source/main/cPopulation.h 2009-11-18 20:58:59 UTC (rev 3534)
+++ branches/topology-manager/source/main/cPopulation.h 2009-11-19 06:29:22 UTC (rev 3535)
@@ -151,15 +151,12 @@
// Must be called to activate *any* organism in the population.
void ActivateOrganism(cAvidaContext& ctx, cOrganism* in_organism, cPopulationCell& target_cell);
- inline void AdjustSchedule(const cPopulationCell& cell, const cMerit& merit);
-
-
cPopulation(); // @not_implemented
cPopulation(const cPopulation&); // @not_implemented
cPopulation& operator=(const cPopulation&); // @not_implemented
public:
- cPopulation(cWorld* world);
+ cPopulation(cTopologyManager* topology, int numcells);
~cPopulation();
void InitiatePop();
@@ -203,7 +200,6 @@
// Process a single organism one instruction...
- int ScheduleOrganism(); // Determine next organism to be processed.
void ProcessStep(cAvidaContext& ctx, double step_size, int cell_id);
void ProcessStepSpeculative(cAvidaContext& ctx, double step_size, int cell_id);
@@ -221,7 +217,6 @@
bool LoadStructuredPopulation(const cString& filename);
bool DumpMemorySummary(std::ofstream& fp);
- bool OK();
int GetSize() const { return cell_array.GetSize(); }
int GetWorldX() const { return world_x; }
Modified: branches/topology-manager/source/main/cPopulationInterface.h
===================================================================
--- branches/topology-manager/source/main/cPopulationInterface.h 2009-11-18 20:58:59 UTC (rev 3534)
+++ branches/topology-manager/source/main/cPopulationInterface.h 2009-11-19 06:29:22 UTC (rev 3535)
@@ -38,12 +38,14 @@
#ifndef cWorldDriver_h
#include "cWorldDriver.h"
#endif
+#ifndef cDeme_h
#include "cDeme.h"
+#endif
class cPopulation;
class cOrgMessage;
+class cWorld;
-
class cPopulationInterface : public cOrgInterface, cDemeInterface
{
private:
Modified: branches/topology-manager/source/main/cTopologyManager.cc
===================================================================
--- branches/topology-manager/source/main/cTopologyManager.cc 2009-11-18 20:58:59 UTC (rev 3534)
+++ branches/topology-manager/source/main/cTopologyManager.cc 2009-11-19 06:29:22 UTC (rev 3535)
@@ -200,15 +200,16 @@
cTopologyManager::~cTopologyManager()
{
-
+ delete schedule;
}
-/*
-cTopologyManager::InitiateTop()
+
+void cTopologyManager::InitiateTopologyManager()
{
-
+ const int num_cells = world_x * world_y * world_z;
+ m_pop = new cPopulation(this, num_cells);
+ m_pop->InitiatePop();
}
-*/
@@ -2655,10 +2656,10 @@
schedule = new cProbSchedule(cell_array.GetSize(), m_world->GetRandom().GetInt(0x7FFFFFFF));
break;
case SLICE_DEME_PROB_MERIT:
- schedule = new cDemeProbSchedule(cell_array.GetSize(), m_world->GetRandom().GetInt(0x7FFFFFFF), topology_manager->deme_array.GetSize());
+ schedule = new cDemeProbSchedule(cell_array.GetSize(), m_world->GetRandom().GetInt(0x7FFFFFFF), deme_array.GetSize());
break;
case SLICE_PROB_DEMESIZE_PROB_MERIT:
- schedule = new cProbDemeProbSchedule(cell_array.GetSize(), m_world->GetRandom().GetInt(0x7FFFFFFF), topology_manager->deme_array.GetSize());
+ schedule = new cProbDemeProbSchedule(cell_array.GetSize(), m_world->GetRandom().GetInt(0x7FFFFFFF), deme_array.GetSize());
break;
case SLICE_INTEGRATED_MERIT:
schedule = new cIntegratedSchedule(cell_array.GetSize());
@@ -2677,3 +2678,39 @@
{
return schedule->GetChangeList();
}
+
+void cTopologyManager::SetChangeList(cChangeList *change_list)
+{
+ schedule->SetChangeList(change_list);
+}
+
+bool cTopologyManager::OK()
+{
+ // First check all sub-objects...
+ if (!schedule->OK()) return false;
+
+ // Next check organisms...
+ for (int i = 0; i < cell_array.GetSize(); i++) {
+ assert(cell_array[i].GetID() == i);
+ }
+
+ // And stats...
+ assert(world_x * world_y == cell_array.GetSize());
+
+ return true;
+}
+
+
+int cTopologyManager::ScheduleOrganism()
+{
+ return schedule->GetNextID();
+}
+
+
+inline void cTopologyManager::AdjustSchedule(const cPopulationCell& cell, const cMerit& merit)
+{
+ const int deme_id = cell.GetDemeID();
+// cout << " CCC " << deme_id;
+ const cDeme& deme = deme_array[deme_id];
+ schedule->Adjust(cell.GetID(), deme.HasDemeMerit() ? (merit * deme.GetDemeMerit()) : merit, cell.GetDemeID());
+}
Modified: branches/topology-manager/source/main/cTopologyManager.h
===================================================================
--- branches/topology-manager/source/main/cTopologyManager.h 2009-11-18 20:58:59 UTC (rev 3534)
+++ branches/topology-manager/source/main/cTopologyManager.h 2009-11-19 06:29:22 UTC (rev 3535)
@@ -66,7 +66,6 @@
class cTopologyManager : public cTopoElement
{
private:
- cWorld* m_world;
cSchedule* schedule; // Handles allocation of CPU cycles
cPopulation* m_pop;
@@ -78,19 +77,22 @@
int world_z; // Population depth.
+public:
+ cWorld* m_world;
+ cTopologyManager(); // not implemented
+ cTopologyManager(cWorld* world); //, cPopulation* pop);
+ ~cTopologyManager();
+
+
+ tArray<cDeme> deme_array; // Deme structure of the population.
+
/** Scheduling Functions **/
void BuildTimeSlicer(cChangeList* change_list); // Build the schedule object
cChangeList* GetChangeList();
void SetChangeList(cChangeList* change_list);
+ void InitiateTopologyManager();
-public:
- cTopologyManager(); // not implemented
- cTopologyManager(cWorld* world, cPopulation* pop);
- ~cTopologyManager();
-
- tArray<cDeme> deme_array; // Deme structure of the population.
-
cPopulationCell& GetCell(int in_num) { return cell_array[in_num]; };
@@ -197,6 +199,18 @@
// cDeme& GetDeme(int i) { return deme_array[i]; }
+ // Saving and Loading
+
+ bool OK();
+
+ bool GetSyncEvents() { return m_pop->GetSyncEvents(); }
+ void SetSyncEvents(bool _in) { m_pop->SetSyncEvents(_in); }
+
+
+ int ScheduleOrganism(); // Determine next organism to be processed.
+ inline void AdjustSchedule(const cPopulationCell& cell, const cMerit& merit);
+
+
};
Modified: branches/topology-manager/source/main/cWorld.cc
===================================================================
--- branches/topology-manager/source/main/cWorld.cc 2009-11-18 20:58:59 UTC (rev 3534)
+++ branches/topology-manager/source/main/cWorld.cc 2009-11-19 06:29:22 UTC (rev 3535)
@@ -32,12 +32,12 @@
#include "cEventList.h"
#include "cHardwareManager.h"
#include "cInstSet.h"
-#include "cPopulation.h"
+// #include "cPopulation.h"
#include "cStats.h"
#include "cTestCPU.h"
#include "cTools.h"
#include "cTopology.h"
-#include "cTopologyManager.h"
+//#include "cTopologyManager.h"
#include "cFallbackWorldDriver.h"
#include <cassert>
@@ -49,7 +49,7 @@
// These must be deleted first
delete m_analyze; m_analyze = NULL;
- delete m_pop; m_pop = NULL;
+// delete m_pop; m_pop = NULL;
delete m_class_mgr; m_class_mgr = NULL;
delete m_env; m_env = NULL;
@@ -107,11 +107,8 @@
if (m_conf->TRACK_CCLADES.Get() > 0)
m_class_mgr->LoadCCladeFounders(m_conf->TRACK_CCLADES_IDS.Get());
-// m_pop = new cPopulation(this);
-// m_pop->InitiatePop();
-
m_top = new cTopologyManager(this);
- m_top->InitiateTop();
+ m_top->InitiateTopologyManager();
// Setup Event List
@@ -146,9 +143,9 @@
void cWorld::GetEvents(cAvidaContext& ctx)
{
- if (m_pop->GetSyncEvents() == true) {
+ if (m_top->GetSyncEvents() == true) {
m_event_list->Sync();
- m_pop->SetSyncEvents(false);
+ m_top->SetSyncEvents(false);
}
m_event_list->Process(ctx);
}
@@ -190,3 +187,5 @@
cPopulation& cWorld::GetPopulation() { return m_top->GetPopulation(); }
+cTopologyManager& cWorld::GetTopologyManager() { return *m_top; }
+
Modified: branches/topology-manager/source/main/cWorld.h
===================================================================
--- branches/topology-manager/source/main/cWorld.h 2009-11-18 20:58:59 UTC (rev 3534)
+++ branches/topology-manager/source/main/cWorld.h 2009-11-19 06:29:22 UTC (rev 3535)
@@ -112,6 +112,7 @@
cHardwareManager& GetHardwareManager() { return *m_hw_mgr; }
// cPopulation& GetPopulation() { return *m_pop; }
cPopulation& GetPopulation();
+ cTopologyManager& GetTopologyManager();
cRandom& GetRandom() { return m_rng; }
cStats& GetStats() { return *m_stats; }
cWorldDriver& GetDriver() { return *m_driver; }
More information about the Avida-cvs
mailing list