[Avida-SVN] r1664 - in development/source: actions classification cpu main targets
ofria at myxo.css.msu.edu
ofria at myxo.css.msu.edu
Mon Jun 11 09:55:21 PDT 2007
Author: ofria
Date: 2007-06-11 12:55:21 -0400 (Mon, 11 Jun 2007)
New Revision: 1664
Added:
development/source/targets/viewer-core/
Modified:
development/source/actions/PopulationActions.cc
development/source/classification/cGenotype.cc
development/source/classification/cGenotype.h
development/source/cpu/cHardwareCPU.cc
development/source/main/cAvidaConfig.cc
development/source/main/cPopulation.cc
development/source/main/cPopulation.h
Log:
Added in a SwapCells command in cPopulation to swap the contents of two cells.
Added in a corresponding SwapCells action so it can be called as an event.
+ Some general code cleanup.
Modified: development/source/actions/PopulationActions.cc
===================================================================
--- development/source/actions/PopulationActions.cc 2007-06-08 21:29:43 UTC (rev 1663)
+++ development/source/actions/PopulationActions.cc 2007-06-11 16:55:21 UTC (rev 1664)
@@ -1436,6 +1436,42 @@
}
};
+
+class cActionSwapCells : public cAction
+{
+private:
+ int id1;
+ int id2;
+
+public:
+ cActionSwapCells(cWorld* world, const cString& args) : cAction(world, args), id1(-1), id2(-1)
+ {
+ cString largs(args);
+ if (largs.GetSize()) id1 = largs.PopWord().AsInt();
+ if (largs.GetSize()) id2 = largs.PopWord().AsInt();
+ }
+
+ static const cString GetDescription() { return "Arguments: <int cell_id1> <int cell_id2>"; }
+
+ void Process(cAvidaContext& ctx)
+ {
+ const int num_cells = m_world->GetPopulation().GetSize();
+ if (id1 < 0 || id1 >= num_cells ||
+ id2 < 0 || id2 >= num_cells) {
+ m_world->GetDriver().RaiseException("SwapCells cell ID out of range");
+ return;
+ }
+ if (id1 == id2) {
+ m_world->GetDriver().NotifyWarning("SwapCells cell IDs identical");
+ }
+
+ cPopulationCell& cell1 = m_world->GetPopulation().GetCell(id1);
+ cPopulationCell& cell2 = m_world->GetPopulation().GetCell(id2);
+ m_world->GetPopulation().SwapCells(cell1, cell2);
+ }
+};
+
+
void RegisterPopulationActions(cActionLibrary* action_lib)
{
action_lib->Register<cActionInject>("Inject");
@@ -1472,6 +1508,8 @@
action_lib->Register<cActionConnectCells>("ConnectCells");
action_lib->Register<cActionDisconnectCells>("DisconnectCells");
+ action_lib->Register<cActionSetOptimizeMinMax>("SetOptimizeMinMax");
+ action_lib->Register<cActionSwapCells>("SwapCells");
// @DMB - The following actions are DEPRECATED aliases - These will be removed in 2.7.
action_lib->Register<cActionInject>("inject");
@@ -1500,6 +1538,5 @@
action_lib->Register<cActionConnectCells>("connect_cells");
action_lib->Register<cActionDisconnectCells>("disconnect_cells");
-
- action_lib->Register<cActionSetOptimizeMinMax>("SetOptimizeMinMax");
+ action_lib->Register<cActionSwapCells>("swap_cells");
}
Modified: development/source/classification/cGenotype.cc
===================================================================
--- development/source/classification/cGenotype.cc 2007-06-08 21:29:43 UTC (rev 1663)
+++ development/source/classification/cGenotype.cc 2007-06-11 16:55:21 UTC (rev 1664)
@@ -46,6 +46,7 @@
, defer_adjust(0)
, id_num(in_id)
, symbol(0)
+ , map_id(-1)
, birth_data(in_update_born)
, num_organisms(0)
, last_num_organisms(0)
@@ -62,6 +63,7 @@
// Reset some of the variables to make sure program will crash if a deleted
// cell is read!
symbol = '!';
+ map_id = -1;
num_organisms = -1;
total_organisms = -1;
Modified: development/source/classification/cGenotype.h
===================================================================
--- development/source/classification/cGenotype.h 2007-06-08 21:29:43 UTC (rev 1663)
+++ development/source/classification/cGenotype.h 2007-06-11 16:55:21 UTC (rev 1664)
@@ -61,6 +61,7 @@
int id_num;
char symbol;
+ int map_id;
mutable cGenotype_TestData test_data;
cGenotype_BirthData birth_data;
@@ -137,6 +138,7 @@
void SetNext(cGenotype* in_next) { next = in_next; }
void SetPrev(cGenotype* in_prev) { prev = in_prev; }
void SetSymbol(char in_symbol) { symbol = in_symbol; }
+ void SetMapID(int in_id) { map_id = in_id; }
inline void SetThreshold();
void IncDeferAdjust() { defer_adjust++; }
void DecDeferAdjust() { defer_adjust--; assert(defer_adjust >= 0); }
@@ -218,6 +220,7 @@
bool GetThreshold() const { return flag_threshold; }
int GetID() const { return id_num; }
char GetSymbol() const { return symbol; }
+ int GetMapID() const { return map_id; }
// Calculate a crude phylogentic distance based off of tracking parents
// and grand-parents, including sexual tracking.
@@ -261,6 +264,7 @@
{
flag_threshold = true;
if (symbol == '.') symbol = '+';
+ if (map_id == 0) map_id = 1;
}
inline void cGenotype::SetBreedStats(cGenotype & daughter)
Modified: development/source/cpu/cHardwareCPU.cc
===================================================================
--- development/source/cpu/cHardwareCPU.cc 2007-06-08 21:29:43 UTC (rev 1663)
+++ development/source/cpu/cHardwareCPU.cc 2007-06-11 16:55:21 UTC (rev 1664)
@@ -483,8 +483,7 @@
cPhenotype & phenotype = organism->GetPhenotype();
- if (m_world->GetConfig().PROMOTERS_ENABLED.Get() == 1)
- {
+ if (m_world->GetConfig().PROMOTERS_ENABLED.Get() == 1) {
//First instruction - check whether we should be starting at a promoter.
if (phenotype.GetTimeUsed() == 0) Inst_Terminate(m_world->GetDefaultContext());
}
@@ -496,8 +495,7 @@
// If we have threads turned on and we executed each thread in a single
// timestep, adjust the number of instructions executed accordingly.
- const int num_inst_exec = (m_world->GetConfig().THREAD_SLICING_METHOD.Get() == 1) ?
-num_threads : 1;
+ const int num_inst_exec = (m_world->GetConfig().THREAD_SLICING_METHOD.Get() == 1) ? num_threads : 1;
for (int i = 0; i < num_inst_exec; i++) {
// Setup the hardware for the next instruction to be executed.
@@ -532,8 +530,7 @@
const int addl_time_cost = m_inst_set->GetAddlTimeCost(cur_inst);
// Prob of exec (moved from SingleProcess_PayCosts so that we advance IP after a fail)
- if ( m_inst_set->GetProbFail(cur_inst) > 0.0 )
- {
+ if ( m_inst_set->GetProbFail(cur_inst) > 0.0 ) {
exec = !( ctx.GetRandom().P(m_inst_set->GetProbFail(cur_inst)) );
}
@@ -548,8 +545,7 @@
// In the promoter model, there may be a chance of termination
// that causes execution to start at a new instruction (per instruction executed)
- if ( m_world->GetConfig().PROMOTERS_ENABLED.Get() )
- {
+ if ( m_world->GetConfig().PROMOTERS_ENABLED.Get() ) {
const double processivity = m_world->GetConfig().PROMOTER_PROCESSIVITY_INST.Get();
if ( ctx.GetRandom().P(1-processivity) ) Inst_Terminate(ctx);
}
@@ -662,9 +658,11 @@
// And execute it.
const bool exec_success = (this->*(m_functions[inst_idx]))(ctx);
-
+
+ // NOTE: Organism may be dead now if instruction executed killed it (such as some divides, "die", or "kazi")
+
#if INSTRUCTION_COUNT
- // decrement if the instruction was not executed successfully
+ // Decrement if the instruction was not executed successfully.
if (exec_success == false) {
organism->GetPhenotype().DecCurInstCount(actual_inst.GetOp());
}
Modified: development/source/main/cAvidaConfig.cc
===================================================================
--- development/source/main/cAvidaConfig.cc 2007-06-08 21:29:43 UTC (rev 1663)
+++ development/source/main/cAvidaConfig.cc 2007-06-11 16:55:21 UTC (rev 1664)
@@ -393,7 +393,7 @@
<< " -h[elp] Help on options (this listing)"<<endl
<< " -i[nteractive] Run analyze mode interactively" << endl
<< " -l[oad] <filename> Load a clone file" << endl
- << " -r[eview] Review analyze.cfg settings." << endl
+ << " -r[eview] Review avida.cfg settings." << endl
<< " -s[eed] <value> Set random seed to <value>" << endl
<< " -set <name> <value> Overide values in avida.cfg" << endl
<< " -v[ersion] Prints the version number" << endl
Modified: development/source/main/cPopulation.cc
===================================================================
--- development/source/main/cPopulation.cc 2007-06-08 21:29:43 UTC (rev 1663)
+++ development/source/main/cPopulation.cc 2007-06-11 16:55:21 UTC (rev 1664)
@@ -642,6 +642,26 @@
return receive_value;
}
+void cPopulation::SwapCells(cPopulationCell & cell1, cPopulationCell & cell2)
+{
+ cOrganism * org1 = cell1.RemoveOrganism();
+ cOrganism * org2 = cell2.RemoveOrganism();
+ if (org2 != NULL) {
+ cell1.InsertOrganism(*org2);
+ schedule->Adjust(cell1.GetID(), org2->GetPhenotype().GetMerit());
+ } else {
+ schedule->Adjust(cell1.GetID(), cMerit(0));
+ }
+
+ if (org1 != NULL) {
+ cell2.InsertOrganism(*org1);
+ schedule->Adjust(cell2.GetID(), org1->GetPhenotype().GetMerit());
+ } else {
+ schedule->Adjust(cell2.GetID(), cMerit(0));
+ }
+}
+
+
// CompeteDemes probabilistically copies demes into the next generation
// based on their fitness. How deme fitness is estimated is specified by
// competition_type input argument as:
Modified: development/source/main/cPopulation.h
===================================================================
--- development/source/main/cPopulation.h 2007-06-08 21:29:43 UTC (rev 1663)
+++ development/source/main/cPopulation.h 2007-06-11 16:55:21 UTC (rev 1664)
@@ -162,9 +162,12 @@
// Deactivate an organism in the population (required for deactivations)
void KillOrganism(cPopulationCell& in_cell);
+
+ // Specialized functionality
void Kaboom(cPopulationCell& in_cell, int distance=0);
void AddSellValue(const int data, const int label, const int sell_price, const int org_id, const int cell_id);
int BuyValue(const int label, const int buy_price, const int cell_id);
+ void SwapCells(cPopulationCell & cell1, cPopulationCell & cell2);
// Deme-related methods
void CompeteDemes(int competition_type);
More information about the Avida-cvs
mailing list