[Avida-cvs] [Avida2-svn] r285 - in trunk/source: cpu main support
ofria@myxo.css.msu.edu
ofria at myxo.css.msu.edu
Sun Aug 14 14:38:11 PDT 2005
Author: ofria
Date: 2005-08-14 17:38:11 -0400 (Sun, 14 Aug 2005)
New Revision: 285
Modified:
trunk/source/cpu/hardware_cpu.cc
trunk/source/cpu/hardware_cpu.hh
trunk/source/main/analyze.cc
trunk/source/main/birth_chamber.cc
trunk/source/main/birth_chamber.hh
trunk/source/main/phenotype.cc
trunk/source/main/phenotype.hh
trunk/source/support/genesis
Log:
Changed defailt genesis file to have death turned on with max lifetime being
genome length times 20.
Added in a new instruction (div-sex-MS) that allows sexual organims to have
a primitive ability to select their mates -- they will only crossover with
another organism that uses the same label as them following the divide.
Modified: trunk/source/cpu/hardware_cpu.cc
===================================================================
--- trunk/source/cpu/hardware_cpu.cc 2005-08-14 12:27:17 UTC (rev 284)
+++ trunk/source/cpu/hardware_cpu.cc 2005-08-14 21:38:11 UTC (rev 285)
@@ -265,6 +265,7 @@
cInstEntryCPU("div-sex", &cHardwareCPU::Inst_HeadDivideSex),
cInstEntryCPU("div-asex", &cHardwareCPU::Inst_HeadDivideAsex),
cInstEntryCPU("div-asex-w", &cHardwareCPU::Inst_HeadDivideAsexWait),
+ cInstEntryCPU("div-sex-MS", &cHardwareCPU::Inst_HeadDivideMateSelect),
cInstEntryCPU("h-divide1", &cHardwareCPU::Inst_HeadDivide1),
cInstEntryCPU("h-divide2", &cHardwareCPU::Inst_HeadDivide2),
@@ -3245,6 +3246,23 @@
return Inst_HeadDivide();
}
+bool cHardwareCPU::Inst_HeadDivideMateSelect()
+{
+ // Take the label that follows this divide and use it as the ID for which
+ // other organisms this one is willing to mate with.
+ ReadLabel();
+ organism->GetPhenotype().SetMateSelectID( GetLabel().AsInt(NUM_NOPS) );
+
+// int mate_id = GetLabel().AsInt(NUM_NOPS);
+// if (mate_id > 0) cout << mate_id << " "
+// << GetLabel().AsString() << endl;
+
+ // Proceed as normal with the rest of mate selection.
+ organism->GetPhenotype().SetDivideSex(true);
+ organism->GetPhenotype().SetCrossNum(1);
+ return Inst_HeadDivide();
+}
+
bool cHardwareCPU::Inst_HeadDivide1() { return Inst_HeadDivideMut(1); }
bool cHardwareCPU::Inst_HeadDivide2() { return Inst_HeadDivideMut(2); }
bool cHardwareCPU::Inst_HeadDivide3() { return Inst_HeadDivideMut(3); }
Modified: trunk/source/cpu/hardware_cpu.hh
===================================================================
--- trunk/source/cpu/hardware_cpu.hh 2005-08-14 12:27:17 UTC (rev 284)
+++ trunk/source/cpu/hardware_cpu.hh 2005-08-14 21:38:11 UTC (rev 285)
@@ -432,6 +432,7 @@
bool Inst_HeadDivideSex();
bool Inst_HeadDivideAsex();
bool Inst_HeadDivideAsexWait();
+ bool Inst_HeadDivideMateSelect();
bool Inst_HeadDivide1();
bool Inst_HeadDivide2();
Modified: trunk/source/main/analyze.cc
===================================================================
--- trunk/source/main/analyze.cc 2005-08-14 12:27:17 UTC (rev 284)
+++ trunk/source/main/analyze.cc 2005-08-14 21:38:11 UTC (rev 285)
@@ -641,7 +641,7 @@
// Calculate entropy ...
double this_entropy = 0.0;
- this_entropy -= (1-mut_rate)*log(1-mut_rate)/log(num_insts);
+ this_entropy -= (1.0-mut_rate)*log(1.0-mut_rate)/log((double) num_insts);
for (int i = 0; i < num_insts; i ++) {
if (i == parent_inst) { continue; }
prob[i] = prob[i] * mut_rate;
Modified: trunk/source/main/birth_chamber.cc
===================================================================
--- trunk/source/main/birth_chamber.cc 2005-08-14 12:27:17 UTC (rev 284)
+++ trunk/source/main/birth_chamber.cc 2005-08-14 21:38:11 UTC (rev 285)
@@ -245,6 +245,36 @@
}
cBirthChamber::cBirthEntry *
+ cBirthChamber::FindSexMateSelectWaiting(const cGenome & child_genome,
+ cOrganism & parent)
+{
+ const int mate_id = parent.GetPhenotype().MateSelectID();
+
+ // If this is a new largest ID, increase the array size.
+ if (mate_select_wait_entry.GetSize() <= mate_id) {
+ int old_wait_size = mate_select_wait_entry.GetSize();
+ mate_select_wait_entry.Resize(mate_id + 1);
+ for (int i = old_wait_size; i <= mate_id; i++) {
+ mate_select_wait_entry[i].is_waiting = false;
+ }
+ }
+
+ // Determine if we have an offspring of this length waiting already...
+ if (mate_select_wait_entry[mate_id].is_waiting == false) {
+ cGenotype * parent_genotype = parent.GetGenotype();
+ parent_genotype->IncDeferAdjust();
+ mate_select_wait_entry[mate_id].genome = child_genome;
+ mate_select_wait_entry[mate_id].merit = parent.GetPhenotype().GetMerit();
+ mate_select_wait_entry[mate_id].parent_genotype = parent_genotype;
+ mate_select_wait_entry[mate_id].is_waiting = true;
+ return NULL;
+ }
+
+ // There is already a child waiting -- do crossover between the two.
+ return &( mate_select_wait_entry[mate_id] );
+}
+
+cBirthChamber::cBirthEntry *
cBirthChamber::FindSexLocalWaiting(const cGenome & child_genome,
cOrganism & parent)
{
@@ -512,21 +542,28 @@
// First check if the birth method is one of the local ones...
if (cConfig::GetBirthMethod() < NUM_LOCAL_POSITION_CHILD) {
old_entry = FindSexLocalWaiting(child_genome, parent);
- } else {
- // ... then check if population is split into demes
- if (cConfig::GetBirthMethod() == POSITION_CHILD_DEME_RANDOM) {
- old_entry = FindSexDemeWaiting(child_genome, parent);
- } else {
- // ... it must be global, but now check if recombination must be
- // only with organisms of the same length
- if (cConfig::GetSameLengthSex() == 0) {
- old_entry = FindSexGlobalWaiting(child_genome, parent);
- } else {
- old_entry = FindSexSizeWaiting(child_genome, parent);
- }
- }
}
+ // ... then check if population is split into demes
+ else if (cConfig::GetBirthMethod() == POSITION_CHILD_DEME_RANDOM) {
+ old_entry = FindSexDemeWaiting(child_genome, parent);
+ }
+ // If none of the previous conditions were met, it must be global.
+ // ...check if recombination must be with organisms of the same length
+ else if (cConfig::GetSameLengthSex() != 0) {
+ old_entry = FindSexSizeWaiting(child_genome, parent);
+ }
+
+ // ...check if we have mate selection
+ else if (parent_phenotype.MateSelectID() >= 0) {
+ old_entry = FindSexMateSelectWaiting(child_genome, parent);
+ }
+
+ // If everything failed until this point, use default global.
+ else {
+ old_entry = FindSexGlobalWaiting(child_genome, parent);
+ }
+
// If we couldn't find a waiting entry, this one was saved -- stop here!
if (old_entry == NULL) {
return false;
@@ -542,7 +579,7 @@
child_array, merit_array);
}
- // RECOMBINATION will happen!
+ // If we made it this far, RECOMBINATION will happen!
cCPUMemory genome0 = old_entry->genome;
cCPUMemory genome1 = child_genome;
double merit0 = old_entry->merit.GetDouble();
Modified: trunk/source/main/birth_chamber.hh
===================================================================
--- trunk/source/main/birth_chamber.hh 2005-08-14 12:27:17 UTC (rev 284)
+++ trunk/source/main/birth_chamber.hh 2005-08-14 21:38:11 UTC (rev 285)
@@ -48,6 +48,7 @@
tArray<cBirthEntry> local_wait_entry;
tArray<cBirthEntry> deme_wait_entry;
tArray<cBirthEntry> size_wait_entry;
+ tArray<cBirthEntry> mate_select_wait_entry;
// mark whether that instruction has already been swapped
// between two genomes; used in modular recombination
@@ -72,14 +73,16 @@
cOrganism & parent,
tArray<cOrganism *> & child_array,
tArray<cMerit> & merit_array);
- cBirthEntry * FindSexSizeWaiting(const cGenome & child_genome,
- cOrganism & parent);
cBirthEntry * FindSexLocalWaiting(const cGenome & child_genome,
cOrganism & parent);
+ cBirthEntry * FindSexDemeWaiting(const cGenome & child_genome,
+ cOrganism & parent);
+ cBirthEntry * FindSexSizeWaiting(const cGenome & child_genome,
+ cOrganism & parent);
+ cBirthEntry * FindSexMateSelectWaiting(const cGenome & child_genome,
+ cOrganism & parent);
cBirthEntry * FindSexGlobalWaiting(const cGenome & child_genome,
cOrganism & parent);
- cBirthEntry * FindSexDemeWaiting(const cGenome & child_genome,
- cOrganism & parent);
void DoBasicRecombination(cCPUMemory & genome0, cCPUMemory & genome1,
double & merit0, double & merit1);
Modified: trunk/source/main/phenotype.cc
===================================================================
--- trunk/source/main/phenotype.cc 2005-08-14 12:27:17 UTC (rev 284)
+++ trunk/source/main/phenotype.cc 2005-08-14 21:38:11 UTC (rev 285)
@@ -150,6 +150,7 @@
// Setup child info...
copy_true = false;
divide_sex = false;
+ mate_select_id = -1;
cross_num = 0;
last_child_fertile = is_fertile;
child_fertile = true;
@@ -227,7 +228,8 @@
// Setup child info...
copy_true = false;
divide_sex = false;
- cross_num = 0;
+ mate_select_id = 0;
+ cross_num = 0;
child_fertile = true;
last_child_fertile = true;
child_copied_size = 0;
@@ -302,6 +304,7 @@
// Reset child info...
(void) copy_true;
(void) divide_sex;
+ (void) mate_select_id;
(void) cross_num;
last_child_fertile = child_fertile;
child_fertile = true;
@@ -389,6 +392,7 @@
// Reset child info...
(void) copy_true;
(void) divide_sex;
+ (void) mate_select_id;
(void) cross_num;
(void) child_fertile;
(void) last_child_fertile;
@@ -475,6 +479,7 @@
// Setup child info...
copy_true = false;
divide_sex = false;
+ mate_select_id = 0;
cross_num = 0;
last_child_fertile = is_fertile;
child_fertile = true;
@@ -623,7 +628,8 @@
fp << copy_true << " ";
fp << divide_sex << " ";
- fp << cross_num << " ";
+ fp << mate_select_id << " ";
+ fp << cross_num << " ";
fp << child_fertile << " ";
fp << last_child_fertile << " ";
@@ -697,6 +703,7 @@
fp >> copy_true;
fp >> divide_sex;
+ fp >> mate_select_id;
fp >> cross_num;
fp >> child_fertile;
fp >> last_child_fertile;
Modified: trunk/source/main/phenotype.hh
===================================================================
--- trunk/source/main/phenotype.hh 2005-08-14 12:27:17 UTC (rev 284)
+++ trunk/source/main/phenotype.hh 2005-08-14 21:38:11 UTC (rev 285)
@@ -118,7 +118,8 @@
// 6. Child information...
bool copy_true; // Can this genome produce an exact copy of itself?
bool divide_sex; // Was this child created with a sexual divide?
- int cross_num ; // How many crossovers should this child do?
+ int mate_select_id; // If divide sex, who to mate with?
+ int cross_num ; // ...how many crossovers should this child do?
bool child_fertile; // Will this organism's next child be fertile?
bool last_child_fertile; // Was the child being born to be fertile?
int child_copied_size; // Instruction copied into child.
@@ -256,6 +257,7 @@
bool CopyTrue() const { assert(initialized == true); return copy_true; }
bool DivideSex() const { assert(initialized == true); return divide_sex; }
+ int MateSelectID() const { assert(initialized == true); return mate_select_id; }
int CrossNum() const { assert(initialized == true); return cross_num; }
bool ChildFertile() const
{ assert(initialized == true); return child_fertile;}
@@ -273,6 +275,7 @@
void SetLinesCopied(int _copied_size) { child_copied_size = _copied_size; }
void SetDivType(double _div_type) { div_type = _div_type; }
void SetDivideSex(bool _divide_sex) { divide_sex = _divide_sex; }
+ void SetMateSelectID(int _select_id) { mate_select_id = _select_id; }
void SetCrossNum(int _cross_num) { cross_num = _cross_num; }
void SetToDie() { to_die = true; }
void SetToDelete() { to_delete = true; }
@@ -299,6 +302,7 @@
int & ParentCrossNum() { assert(initialized == true); return parent_cross_num; }
bool & CopyTrue() { assert(initialized == true); return copy_true; }
bool & DivideSex() { assert(initialized == true); return divide_sex; }
+ int & MateSelectID() { assert(initialized == true); return mate_select_id; }
int & CrossNum() { assert(initialized == true); return cross_num; }
bool & ChildFertile() { assert(initialized == true); return child_fertile; }
bool & IsMultiThread() { assert(initialized == true); return is_multi_thread; }
Modified: trunk/source/support/genesis
===================================================================
--- trunk/source/support/genesis 2005-08-14 12:27:17 UTC (rev 284)
+++ trunk/source/support/genesis 2005-08-14 21:38:11 UTC (rev 285)
@@ -36,10 +36,10 @@
# 4 = Replace random from entire population (Mass Action)
# 5 = Replace oldest in entire population (like Tierra)
PREFER_EMPTY 1 # Are empty cells given preference in offspring placement?
-DEATH_METHOD 0 # 0 = Never die of old age.
+DEATH_METHOD 2 # 0 = Never die of old age.
# 1 = Die when inst executed = AGE_LIMIT (with deviation)
# 2 = Die when inst executed = length * AGE_LIMIT (+ dev.)
-AGE_LIMIT 5000 # Modifies DEATH_METHOD
+AGE_LIMIT 20 # Modifies DEATH_METHOD
AGE_DEVIATION 0 # Modified DEATH_METHOD
ALLOC_METHOD 0 # 0 = Allocated space is set to default instruction.
# 1 = Set to section of dead genome (Necrophilia)
More information about the Avida-cvs
mailing list