[Avida-SVN] r1550 - in branches/uml/source: cpu main
hjg at myxo.css.msu.edu
hjg at myxo.css.msu.edu
Mon May 14 10:59:46 PDT 2007
Author: hjg
Date: 2007-05-14 13:59:45 -0400 (Mon, 14 May 2007)
New Revision: 1550
Modified:
branches/uml/source/cpu/cHardwareCPU.cc
branches/uml/source/cpu/cHardwareCPU.h
branches/uml/source/cpu/nHardware.h
branches/uml/source/main/cAvidaConfig.h
branches/uml/source/main/cDeme.cc
branches/uml/source/main/cDeme.h
branches/uml/source/main/cOrganism.cc
branches/uml/source/main/cOrganism.h
branches/uml/source/main/cPopulation.cc
branches/uml/source/main/cUMLModel.h
Log:
Modified: branches/uml/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/uml/source/cpu/cHardwareCPU.cc 2007-05-14 14:34:28 UTC (rev 1549)
+++ branches/uml/source/cpu/cHardwareCPU.cc 2007-05-14 17:59:45 UTC (rev 1550)
@@ -67,7 +67,8 @@
cNOPEntryCPU("nop-C", REG_CX),
cNOPEntryCPU("nop-D", REG_DX),
cNOPEntryCPU("nop-E", REG_EX),
- cNOPEntryCPU("nop-F", REG_FX)
+ cNOPEntryCPU("nop-F", REG_FX),
+ cNOPEntryCPU("nop-G", REG_GX),
};
static const tInstLibEntry<tMethod> s_f_array[] = {
@@ -82,6 +83,8 @@
tInstLibEntry<tMethod>("nop-D", &cHardwareCPU::Inst_Nop, (nInstFlag::DEFAULT | nInstFlag::NOP), "No-operation instruction; modifies other instructions"),
tInstLibEntry<tMethod>("nop-E", &cHardwareCPU::Inst_Nop, (nInstFlag::DEFAULT | nInstFlag::NOP), "No-operation instruction; modifies other instructions"),
tInstLibEntry<tMethod>("nop-F", &cHardwareCPU::Inst_Nop, (nInstFlag::DEFAULT | nInstFlag::NOP), "No-operation instruction; modifies other instructions"),
+ tInstLibEntry<tMethod>("nop-G", &cHardwareCPU::Inst_Nop, (nInstFlag::DEFAULT | nInstFlag::NOP), "No-operation instruction; modifies other instructions"),
+
tInstLibEntry<tMethod>("NULL", &cHardwareCPU::Inst_Nop, 0, "True no-operation instruction: does nothing"),
tInstLibEntry<tMethod>("nop-X", &cHardwareCPU::Inst_Nop, 0, "True no-operation instruction: does nothing"),
@@ -3416,6 +3419,8 @@
bool cHardwareCPU::Inst_HeadDivide(cAvidaContext& ctx)
{
+ // modified for UML branch
+ organism->modelCheck(ctx);
return Inst_HeadDivideMut(ctx, 1);
}
@@ -3909,6 +3914,10 @@
// decement the destination state index
organism->getStateDiagram()->relativeJumpDestinationState(jump_amount);
break;
+ case 6:
+ // jump the state diagram index
+ organism->relativeMoveSDIndex(jump_amount);
+ break;
}
return true;
}
@@ -3946,6 +3955,10 @@
// decement the destination state index
organism->getStateDiagram()->relativeJumpDestinationState(jump_amount);
break;
+ case 6:
+ // jump the state diagram index
+ organism->relativeMoveSDIndex(jump_amount);
+ break;
}
return true;
}
@@ -3984,6 +3997,10 @@
// decement the destination state index
organism->getStateDiagram()->absoluteJumpDestinationState(jump_amount);
break;
+ case 6:
+ // jump the state diagram index
+ organism->absoluteMoveSDIndex(jump_amount);
+ break;
}
return true;
}
@@ -4001,29 +4018,33 @@
switch (reg_used){
case 0:
- // decrement the triggers vector index
+ // jump the triggers vector index
organism->getStateDiagram()->absoluteJumpTrigger(jump_amount);
break;
case 1:
- // decrement the guards vector index
+ // jump the guards vector index
organism->getStateDiagram()->absoluteJumpGuard(jump_amount);
break;
case 2:
- // decrement the actions vector index
+ // jump the actions vector index
organism->getStateDiagram()->absoluteJumpAction(jump_amount);
break;
case 3:
- // decrement the transition labels index
+ // jump the transition labels index
organism->getStateDiagram()->absoluteJumpTransitionLabel(jump_amount);
break;
case 4:
- // decrement the original state index
+ // jump the original state index
organism->getStateDiagram()->absoluteJumpOriginState(jump_amount);
break;
case 5:
- // decement the destination state index
+ // jump the destination state index
organism->getStateDiagram()->absoluteJumpDestinationState(jump_amount);
break;
+ case 6:
+ // jump the state diagram index
+ organism->absoluteMoveSDIndex(jump_amount);
+ break;
}
return true;
}
@@ -4063,6 +4084,10 @@
// decement the destination state index
organism->getStateDiagram()->firstDestinationState();
break;
+ case 6:
+ // decrement the state diagram index
+ organism->firstStateDiagram();
+
}
return true;
}
@@ -4102,6 +4127,9 @@
// decement the destination state index
organism->getStateDiagram()->lastDestinationState();
break;
+ case 6:
+ // decrement the state diagram index`
+ organism->lastStateDiagram();
}
return true;
}
Modified: branches/uml/source/cpu/cHardwareCPU.h
===================================================================
--- branches/uml/source/cpu/cHardwareCPU.h 2007-05-14 14:34:28 UTC (rev 1549)
+++ branches/uml/source/cpu/cHardwareCPU.h 2007-05-14 17:59:45 UTC (rev 1550)
@@ -85,10 +85,10 @@
protected:
// -------- Structure Constants --------
- static const int NUM_REGISTERS = 6;
+ static const int NUM_REGISTERS = 7;
static const int NUM_HEADS = nHardware::NUM_HEADS >= NUM_REGISTERS ? nHardware::NUM_HEADS : NUM_REGISTERS;
- enum tRegisters { REG_AX = 0, REG_BX, REG_CX, REG_DX, REG_EX, REG_FX };
- static const int NUM_NOPS = 6;
+ enum tRegisters { REG_AX = 0, REG_BX, REG_CX, REG_DX, REG_EX, REG_FX, REG_GX };
+ static const int NUM_NOPS = 7;
// -------- Data Structures --------
struct cLocalThread
Modified: branches/uml/source/cpu/nHardware.h
===================================================================
--- branches/uml/source/cpu/nHardware.h 2007-05-14 14:34:28 UTC (rev 1549)
+++ branches/uml/source/cpu/nHardware.h 2007-05-14 17:59:45 UTC (rev 1550)
@@ -32,7 +32,7 @@
static const int TEST_CPU_GENERATIONS = 3; // Default generations tested for viability.
- static const int MAX_NOPS = 6;
+ static const int MAX_NOPS = 7;
static const int MAX_LABEL_SIZE = 10;
enum tHeads { HEAD_IP = 0, HEAD_READ, HEAD_WRITE, HEAD_FLOW, NUM_HEADS };
Modified: branches/uml/source/main/cAvidaConfig.h
===================================================================
--- branches/uml/source/main/cAvidaConfig.h 2007-05-14 14:34:28 UTC (rev 1549)
+++ branches/uml/source/main/cAvidaConfig.h 2007-05-14 17:59:45 UTC (rev 1550)
@@ -210,14 +210,12 @@
// Deme & germline group.
CONFIG_ADD_GROUP(DEME_GROUP, "Demes and Germlines");
CONFIG_ADD_VAR(NUM_DEMES, int, 1, "Number of independent groups in the population.");
-// CONFIG_ADD_VAR(DEME_ORGS_ARE_STATIC, int, 0, "Whether the organisms remain the same throughout the lifetime of the deme. 0=no");
CONFIG_ADD_VAR(DEMES_USE_GERMLINE, int, 0, "Whether demes use a distinct germline; 0=off");
CONFIG_ADD_VAR(DEMES_HAVE_MERIT, int, 0, "Whether demes have merit; 0=no");
CONFIG_ADD_VAR(GERMLINE_COPY_MUT, double, 0.0075, "Prob. of copy mutations occuring during\ngermline replication.");
CONFIG_ADD_VAR(GERMLINE_REPLACES_SOURCE, int, 0, "Whether the source germline is updated\non replication; 0=no.");
CONFIG_ADD_VAR(GERMLINE_RANDOM_PLACEMENT, int, 0, "Whether the seed for a germline is placed\n randomly within the deme; 0=no.");
CONFIG_ADD_VAR(MAX_DEME_AGE, int, 500, "The maximum age of a deme (in updates) to be\nused for age-based replication (default=500).");
- CONFIG_ADD_VAR(DEMES_USE_UML_MOD, int, 0, "Whether the demes manipulate UML models; 0=off");
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");
Modified: branches/uml/source/main/cDeme.cc
===================================================================
--- branches/uml/source/main/cDeme.cc 2007-05-14 14:34:28 UTC (rev 1549)
+++ branches/uml/source/main/cDeme.cc 2007-05-14 17:59:45 UTC (rev 1550)
@@ -42,7 +42,6 @@
cell_ids = in_cells;
birth_count = 0;
org_count = 0;
- _germlines.resize(cell_ids.GetSize());
// Initialize the UML model with 1 state diagram per organism.
umlMod.resetStateDiagrams(cell_ids.GetSize());
@@ -91,16 +90,9 @@
_germline = germline;
}*/
-
-void cDeme::SetGermlines(std::vector<cGermline>::iterator b, std::vector<cGermline>::iterator e)
-{
- _germlines.clear();
-
- for (std::vector<cGermline>::iterator i=b; i!=e; ++i) {
- _germlines.push_back(*i);
- }
-
-
+void cDeme::ReplaceGermline(const cGermline& germline) {
+ _germline = germline;
}
+
Modified: branches/uml/source/main/cDeme.h
===================================================================
--- branches/uml/source/main/cDeme.h 2007-05-14 14:34:28 UTC (rev 1549)
+++ branches/uml/source/main/cDeme.h 2007-05-14 17:59:45 UTC (rev 1550)
@@ -26,9 +26,9 @@
#include "cGermline.h"
#include "tArray.h"
#include "cUMLModel.h"
-#include <vector>
+
/*! Demes are groups of cells in the population that are somehow bound together
as a unit. The deme object is used from within cPopulation to manage these
groups. */
@@ -60,16 +60,14 @@
bool IsFull() const { return org_count == cell_ids.GetSize(); }
// -= Germline =-
- //! Returns a vector of the deme's germlines.
-// orig -- cGermline& GetGermline() { return _germline; }
- // vector<cGermline> GetGermLines() { return _germlines; }
-
-
+ //! Returns this deme's germline.
+ cGermline& GetGermline() { return _germline; }
//! Replaces this deme's germline.
- //void ReplaceGermline(const cGermline& germline);
- void SetGermlines(std::vector<cGermline>::iterator, std::vector<cGermline>::iterator);
-
+ void ReplaceGermline(const cGermline& germline);
+ // UML Model functions
+ cUMLModel* getUMLModel() { return ¨Mod; }
+
// -= Update support =-
//! Called once, at the end of every update.
void ProcessUpdate() { ++_age; }
@@ -77,28 +75,16 @@
updates since the last time Reset() was called. */
int GetAge() const { return _age; }
- // UML Model functions
- cUMLModel* getUMLModel() { return ¨Mod; }
-
- std::vector<cGermline>::iterator begin() { return _germlines.begin(); }
- std::vector<cGermline>::iterator end() { return _germlines.end(); }
- // for(vector<cGermline>::iterator i=source_deme.begin(); i!=source_deme.end(); ++i)
-
private:
tArray<int> cell_ids;
int width; //!< Width of this deme.
int birth_count; //!< Number of organisms that have been born into this deme since reset.
int org_count; //!< Number of organisms are currently in this deme.
int _age; //!< Age of this deme, in updates.
-
- // cGermline _germline; //!< The germline for this deme, if used.
- std::vector<cGermline> _germlines; //!< The germlines for this deme, if used
-
-
cUMLModel umlMod; // !< The UML model for this deme, if used.
cUMLModel prevMod; // !< The previous (possibly parent) model for the deme, if used
-
-
+
+ cGermline _germline; //!< The germline for this deme, if used.
};
#endif
Modified: branches/uml/source/main/cOrganism.cc
===================================================================
--- branches/uml/source/main/cOrganism.cc 2007-05-14 14:34:28 UTC (rev 1549)
+++ branches/uml/source/main/cOrganism.cc 2007-05-14 17:59:45 UTC (rev 1550)
@@ -88,86 +88,8 @@
if (m_world->GetConfig().NET_ENABLED.Get()) m_net = new cNetSupport();
m_id = m_world->GetStats().GetTotCreatures();
+ m_state_diag = 0;
- // Initialize UML model with elements
-
-/*
- // create in-memory representation of model
- AddTrans(0,0,1);
- AddTrans(1,1,2);
- AddTrans(2,2,3);
- AddTrans(3,3,1);
-*/
-
-/*
- trigger_info trig;
- trig.label = "<null>";
- trig.operation_id = "<null>";
- triggers.push_back(trig);
- trig.label = "setTempOpState";
- trig.operation_id = "XDE-4437EBF1-9C42-4EB4-B7CF-415697B567CD";
- triggers.push_back(trig);
- trig.label = "setTempData";
- trig.operation_id = "XDE-9517D6BA-8666-4A82-AFEA-62D60FE37B07";
- triggers.push_back(trig);
- guards.push_back("<null>");
- actions.push_back("<null>");
- actions.push_back("^TempSensor.getOpState()");
- actions.push_back("^TempSensor.getTempData()");
-
- // initialize w/ 10 states
-
- state s;
- for (int i=0; i<11; i++) {
- s.identifier = i;
- s.num_incoming = 0;
- s.num_outgoing = 0;
- states.push_back(s);
- }
-
- // initialize transitions
- transition t;
-
- // State 0->1
- t.orig_state = 0;
- t.dest_state = 1;
- states[0].num_outgoing += 1;
- states[1].num_incoming += 1;
- t.trans.trigger = 0;
- t.trans.guard = "<null>";
- t.trans.action = "<null>";
- transitions.push_back(t);
-
- // State 1->2
- t.orig_state = 1;
- t.dest_state = 2;
- states[1].num_outgoing += 1;
- states[2].num_incoming += 1;
- t.trans.trigger = 0;
- t.trans.guard = "<null>";
- t.trans.action = "^TempSensor.getTempData()";
- transitions.push_back(t);
-
- // State 2->1
- t.orig_state = 2;
- t.dest_state = 1;
- states[2].num_outgoing += 1;
- states[1].num_incoming += 1;
- t.trans.trigger = 2;
- t.trans.guard = "<null>";
- t.trans.action = "<null>";
- transitions.push_back(t);
-
- // initialize the iterators to point to the first element
- trigger_index = 0;
- action_index = 0;
- guard_index = 0;
- trans_label_index = 0;
- orig_state_index = 0;
- dest_state_index = 9;
-// END UML model initialization
- */
-
}
@@ -644,7 +566,9 @@
/// This function is a copy of DoOutput ///
void cOrganism::modelCheck(cAvidaContext& ctx)
{
+ if(GetCellID()==-1) return;
+
// printXMI();
@@ -711,6 +635,45 @@
}
+cUMLModel* cOrganism::getUMLModel()
+{
+ cDeme& deme = m_world->GetPopulation().GetDeme(m_world->GetPopulation().GetCell(GetCellID()).GetDemeID());
+ return deme.getUMLModel();
+}
+bool cOrganism::absoluteMoveSDIndex (int amount )
+{
+ m_state_diag = 0;
+ return relativeMoveSDIndex(amount);
+}
+bool cOrganism::relativeMoveSDIndex (int amount )
+{
+ int size = getUMLModel()->getStateDiagramSize();
+
+ if (size == 0) {
+ return false;
+ }
+
+ if (size > 0) {
+ m_state_diag += (amount % size);
+ // index is greater than vector
+ if (m_state_diag >= size) {
+ m_state_diag -= size;
+ } else if(m_state_diag < 0) {
+ m_state_diag += size;
+ }
+ }
+
+ return true;
+}
+
+cUMLStateDiagram* cOrganism::getStateDiagram()
+{
+ int m = m_state_diag;
+ return getUMLModel()->getStateDiagram(m);
+
+}
+
+
Modified: branches/uml/source/main/cOrganism.h
===================================================================
--- branches/uml/source/main/cOrganism.h 2007-05-14 14:34:28 UTC (rev 1549)
+++ branches/uml/source/main/cOrganism.h 2007-05-14 17:59:45 UTC (rev 1550)
@@ -73,9 +73,21 @@
#ifndef tSmartArray_h
#include "tSmartArray.h"
#endif
+#ifndef _C_UMLMODEL_H_
+#include "cUMLModel.h"
+#endif
#ifndef _C_UMLSTATEDIAGRAM_H_
#include "cUMLStateDiagram.h"
#endif
+#ifndef _C_DEME_H_
+#include "cDeme.h"
+#endif
+#ifndef _C_POPULATION_H_
+#include "cPopulation.h"
+#endif
+#ifndef _C_POPULATIONCELL_H_
+#include "cPopulationCell.h"
+#endif
class cAvidaContext;
class cCodeLabel;
@@ -128,7 +140,8 @@
bool m_is_running; // Does this organism have the CPU?
// UML
- cUMLStateDiagram* m_sd;
+ int m_state_diag; // Index of the state diagram that the organism is currently
+ // manipulating
class cNetSupport
{
@@ -288,10 +301,14 @@
// UML
void modelCheck(cAvidaContext& ctx);
- cUMLStateDiagram* getStateDiagram() { return m_sd; }
- void setStateDiagram (cUMLStateDiagram* sd) { m_sd = sd; }
+ cUMLModel* getUMLModel();
+ int getStateDiagramIndex() { return m_state_diag; }
+ bool absoluteMoveSDIndex (int);
+ bool relativeMoveSDIndex (int);
+ bool lastStateDiagram () { m_state_diag = getUMLModel()->getStateDiagramSize(); }
+ bool firstStateDiagram() { m_state_diag = 0; }
+ cUMLStateDiagram* getStateDiagram();
-
};
Modified: branches/uml/source/main/cPopulation.cc
===================================================================
--- branches/uml/source/main/cPopulation.cc 2007-05-14 14:34:28 UTC (rev 1549)
+++ branches/uml/source/main/cPopulation.cc 2007-05-14 17:59:45 UTC (rev 1550)
@@ -289,22 +289,8 @@
if (parent_alive == true) {
schedule->Adjust(parent_cell.GetID(), parent_phenotype.GetMerit());
- // We're going to try something a little different here, and also take into
- // account a per-germline merit, if we're configured to do such.
- if(m_world->GetConfig().DEMES_USE_GERMLINE.Get() &&
- m_world->GetConfig().DEMES_HAVE_MERIT.Get()) {
-
- cDeme& deme = deme_array[parent_cell.GetDemeID()];
- cGermline& germy = deme.begin()[parent_cell.GetID() - deme.GetCellID(0)];
-
- schedule->Adjust(parent_cell.GetID(), parent_phenotype.GetMerit() + germy.GetMerit());
- } else {
- schedule->Adjust(parent_cell.GetID(), parent_phenotype.GetMerit());
- }
-
-
- // In a local run, face the child toward the parent.
- const int birth_method = m_world->GetConfig().BIRTH_METHOD.Get();
+ // In a local run, face the child toward the parent.
+ const int birth_method = m_world->GetConfig().BIRTH_METHOD.Get();
if (birth_method < NUM_LOCAL_POSITION_CHILD ||
birth_method == POSITION_CHILD_PARENT_FACING) {
for (int i = 0; i < child_array.GetSize(); i++) {
@@ -430,16 +416,6 @@
deme_array[target_cell.GetDemeID()].IncOrgCount();
}
- // If we're using models in conjunction with demes, we need to
- // provide the organism with a pointer to its state diagram.
- if(m_world->GetConfig().DEMES_USE_UML_MOD.Get()) {
- // assign a state diagram to the organism
- cDeme& deme = deme_array[target_cell.GetDemeID()];
-
- cUMLStateDiagram* s = deme.getUMLModel()->getStateDiagram(target_cell.GetID() - deme.GetCellID(0));
- in_organism->setStateDiagram(s);
- }
-
// Statistics...
m_world->GetStats().RecordBirth(target_cell.GetID(), in_genotype->GetID(),
in_organism->GetPhenotype().ParentTrue());
@@ -784,6 +760,16 @@
}
}
break;
+ case 7: {
+ for (int deme_id = 0; deme_id < num_demes; deme_id++) {
+ cDeme& cur_deme = deme_array[deme_id];
+ double f = cur_deme.getUMLModel()->evaluateModel();
+ deme_fitness[deme_id] = f;
+ total_fitness += f;
+ }
+ break;
+ }
+
}
// Pick which demes should be in the next generation.
@@ -868,8 +854,6 @@
0: 'all' - ...all non-empty demes in the population.
1: 'full_deme' - ...demes that have been filled up.
2: 'corners' - ...demes with upper left and lower right corners filled.
-3: 'uml-mod' - ...demes whose UML models are correct
-4: 'old' - ...replicate when demes get too old
*/
void cPopulation::ReplicateDemes(int rep_trigger)
@@ -909,39 +893,11 @@
cell_array[id2].IsOccupied() == false) continue;
break;
}
- case 3: {
- // Replicates old demes.
+ case 3: {
+ // Replicate old demes.
if(source_deme.GetAge() < m_world->GetConfig().MAX_DEME_AGE.Get()) continue;
break;
}
- //case 4: {
-
- // Replicate demes with working models
- // What checks should be done prior to the model being checked?
- // model same as parent?
- // model same as last time (dirty bit)
-
- // Need for a deme to have a UML model.
-
- // The models have 10 transitions
-/* int num_trans = 0;
-
- for (int k=0; k< source_deme.GetSize(); k++) {
- num_trans += source_deme.getUMLModel()->getStateDiagram(k)->numTrans();
- }
- if (num_trans < 1) continue;
- // Checks for working model:
- // 1) Should include the sequence diagram scenarios (if any)
- // 2) Should satisfy the properties (if any)
- // To conserve CPU time, only check properties if scnearios pass
-
- // Should be awarded partial merit for satisfying parts of some scenarios or
- // partially satisfying a property.
-
- break;
-
- }*/
-
default: {
cerr << "ERROR: Invalid replication trigger " << rep_trigger
<< " in cPopulation::ReplicateDemes()" << endl;
@@ -968,84 +924,39 @@
// Second, it could be an offspring of the source deme's germline, if the config
// option DEMES_USE_GERMLINE is set.
if(m_world->GetConfig().DEMES_USE_GERMLINE.Get()) {
-
- std::vector<cGermline> temp_germlines;
-
- // For each of the germs...
- for(std::vector<cGermline>::iterator i=source_deme.begin(); i!=source_deme.end(); ++i){
// Get the latest germ from the source deme.
- cGermline& source_germline = (*i);
+ cGermline& source_germline = source_deme.GetGermline();
cGenome& source_germ = source_germline.GetLatest();
- // Now create the next germ by manually mutating the source.
- // @refactor (strategy pattern)
- cGenome next_germ(source_germ);
- if(m_world->GetConfig().GERMLINE_COPY_MUT.Get() > 0) {
- const cInstSet& instset = m_world->GetHardwareManager().GetInstSet();
- cAvidaContext ctx(m_world->GetRandom());
- for(int i=0; i<next_germ.GetSize(); ++i) {
- if(m_world->GetRandom().P(m_world->GetConfig().GERMLINE_COPY_MUT.Get())) {
- next_germ[i] = instset.GetRandomInst(ctx);
- }
- }
- }
+ // Now create the next germ by manually mutating the source.
+ // @refactor (strategy pattern)
+ cGenome next_germ(source_germ);
+ if(m_world->GetConfig().GERMLINE_COPY_MUT.Get() > 0) {
+ const cInstSet& instset = m_world->GetHardwareManager().GetInstSet();
+ cAvidaContext ctx(m_world->GetRandom());
+ for(int i=0; i<next_germ.GetSize(); ++i) {
+ if(m_world->GetRandom().P(m_world->GetConfig().GERMLINE_COPY_MUT.Get())) {
+ next_germ[i] = instset.GetRandomInst(ctx);
+ }
+ }
+ }
- // Here we're adding the next_germ to the germline(s). Note the
- // config option to determine if we should update the source_germline
- // as well.
- //
- //target_deme.ReplaceGermline(source_germline);
- temp_germlines.push_back(source_germline);
- //cGermline& target_germline = target_deme.GetGermline();
- // use last element of the temp germlines as the germline
- cGermline& temp_germline = temp_germlines.back();
- temp_germline.Add(next_germ);
- if(m_world->GetConfig().GERMLINE_REPLACES_SOURCE.Get()) {
- source_germline.Add(next_germ);
- }
+ // Here we're adding the next_germ to the germline(s). Note the
+ // config option to determine if we should update the source_germline
+ // as well.
+ target_deme.ReplaceGermline(source_germline);
+ cGermline& target_germline = target_deme.GetGermline();
+ target_germline.Add(next_germ);
+ if(m_world->GetConfig().GERMLINE_REPLACES_SOURCE.Get()) {
+ source_germline.Add(next_germ);
+ }
- } // end do for all germlines
-
- // replace the target demes germline
- target_deme.SetGermlines(temp_germlines.begin(), temp_germlines.end());
-
// Kill all the organisms in the source deme.
- // Inject organisms with the new germlines
- // Note for this to work:
- // (1) the source deme and target deme must be the same size
- // (2) there must be a germline for each cell...
- std::vector<cGermline>::iterator s = source_deme.begin();
- std::vector<cGermline>::iterator t = target_deme.begin();
-
- double merit = 0.0;
-
- merit += source_deme.getUMLModel()->evaluateModel();
-
-
- for (int i=0; i<source_deme.GetSize(); i++) {
- KillOrganism(cell_array[source_deme.GetCellID(i)]);
- KillOrganism(cell_array[target_deme.GetCellID(i)]);
-
- // Inject new organisms
- InjectGenome(source_deme.GetCellID(i), (*s).GetLatest(), 0);
- InjectGenome(target_deme.GetCellID(i), (*t).GetLatest(), 0);
-
- // update the merit of each cell
- cell_array[source_deme.GetCellID(i)].GetOrganism()->UpdateMerit(merit);
- cell_array[target_deme.GetCellID(i)].GetOrganism()->UpdateMerit(merit);
-
- s++;
- t++;
- }
-
- /* // Setup the merit of both old and new individuals.
- for (int pos = 0; pos < deme_size; pos += 2) {
- cell_array[source_deme.GetCellID(pos)].GetOrganism()->UpdateMerit(merit);
- cell_array[target_deme.GetCellID(pos)].GetOrganism()->UpdateMerit(merit);
- }*/
-
+ for (int i=0; i<source_deme.GetSize(); i++) {
+ KillOrganism(cell_array[source_deme.GetCellID(i)]);
+ }
-/* // Lineage label is wrong here; fix.
+ // Lineage label is wrong here; fix.
if(m_world->GetConfig().GERMLINE_RANDOM_PLACEMENT.Get()) {
InjectGenome(source_deme.GetCellID(m_world->GetRandom().GetInt(0, source_deme.GetSize()-1)),
source_germline.GetLatest(), 0);
@@ -1089,9 +1000,7 @@
cell_array[cell3_id].Rotate(cell_array[GridNeighbor(cell3_id-offset,
source_deme.GetWidth(),
source_deme.GetHeight(), -1, -1)+offset]);
- */
}
-
// And reset both demes, in case they have any cleanup work to do.
source_deme.Reset();
@@ -2173,28 +2082,12 @@
LineageSetupOrganism(GetCell(cell_id).GetOrganism(), 0, lineage_label);
// If we're using germlines, then we have to be a little careful here.
- if(m_world->GetConfig().DEMES_USE_GERMLINE.Get()) {
+ if(m_world->GetConfig().DEMES_USE_GERMLINE.Get()) {
cDeme& deme = deme_array[GetCell(cell_id).GetDemeID()];
- // index into germline vector
- // cell_id - deme.GetCellID(0)
-
-
- cGermline& germy = deme.begin()[cell_id - deme.GetCellID(0)];
- if (germy.Size() == 0){
-
-// if(deme.GetGermline().Size()==0) {
- germy.Add(GetCell(cell_id).GetOrganism()->GetGenome());
+ if(deme.GetGermline().Size()==0) {
+ deme.GetGermline().Add(GetCell(cell_id).GetOrganism()->GetGenome());
}
}
- // If we're using models in conjunction with demes, we need to
- // provide the organism with a pointer to its state diagram.
- if(m_world->GetConfig().DEMES_USE_UML_MOD.Get()) {
- // assign a state diagram to the organism
- cDeme& deme = deme_array[GetCell(cell_id).GetDemeID()];
-
- cUMLStateDiagram* s = deme.getUMLModel()->getStateDiagram(cell_id - deme.GetCellID(0));
- GetCell(cell_id).GetOrganism()->setStateDiagram(s);
- }
}
Modified: branches/uml/source/main/cUMLModel.h
===================================================================
--- branches/uml/source/main/cUMLModel.h 2007-05-14 14:34:28 UTC (rev 1549)
+++ branches/uml/source/main/cUMLModel.h 2007-05-14 17:59:45 UTC (rev 1550)
@@ -26,6 +26,8 @@
void resetStateDiagrams (int);
void seedDiagrams();
+ int getStateDiagramSize() { return state_diagrams.size(); }
+
// Track bonus info for model
std::map <std::string, double> getBonus() {return self_bonus;}
void setBonusInfo(std::string x, double y) {self_bonus[x] = y;}
More information about the Avida-cvs
mailing list