[Avida-SVN] r1232 - in extras: . source/testsuites
avidaedward at myxo.css.msu.edu
avidaedward at myxo.css.msu.edu
Sat Jan 27 22:18:05 PST 2007
Author: avidaedward
Date: 2007-01-28 01:18:04 -0500 (Sun, 28 Jan 2007)
New Revision: 1232
Modified:
extras/
extras/source/testsuites/nAnalyze.cpp
Log:
r1256 at clearly: kaben | 2007-01-27 20:58:37 -0500
Mocked-up version of "COMPETE" command works !
Property changes on: extras
___________________________________________________________________
Name: svk:merge
- 079b078a-dbed-46b9-b3da-37668d4295ca:/avida/local/extras:1251
+ 079b078a-dbed-46b9-b3da-37668d4295ca:/avida/local/extras:1256
Modified: extras/source/testsuites/nAnalyze.cpp
===================================================================
--- extras/source/testsuites/nAnalyze.cpp 2007-01-28 06:18:00 UTC (rev 1231)
+++ extras/source/testsuites/nAnalyze.cpp 2007-01-28 06:18:04 UTC (rev 1232)
@@ -5,10 +5,20 @@
#include "cAnalyzeCommandDefBase.h"
#include "cAnalyzeFlowCommand.h"
#include "cAnalyzeGenotype.h"
+#include "cConstSchedule.h"
+#include "cCPUMemory.h"
+#include "cCPUTestInfo.h"
#include "cDefaultAnalyzeDriver.h"
#include "cDefaultRunDriver.h"
#include "cDrivermanager.h"
+#include "cHardwareManager.h"
+#include "cIntegratedSchedule.h"
+#include "cMerit.h"
+#include "cOrganism.h"
+#include "cProbSchedule.h"
+#include "cSchedule.h"
#include "cStringUtil.h"
+#include "cTestCPU.h"
#include "cTestLib.h"
#include "cXMLArchive.h"
#include "cWorld.h"
@@ -884,9 +894,10 @@
cAddTestSuite t("cAnalyze_Brainstorm_CumulativeStemminess", test);
}
- /* cAnalyze_Brainstorm_EpochalVsContinuous {{{2 */
- namespace Brainstorm_EpochalVsContinuous {
+ /* cAnalyze_Brainstorm_SynchronousVsContinuous {{{2 */
+ namespace Brainstorm_SynchronousVsContinuous {
void test(cTestSettings &settings){
+ /* Check settings. {{{3 */
if(
(!settings.HasSetting("DevelBase"))
||
@@ -907,9 +918,7 @@
ERROR("kgn at FIXME: should verify paths to config files and data dir -");
ERROR("kgn at FIXME: brainstorm not complete -");
- /*
- Initialize
- */
+ /* Initialize. {{{3 */
cDriverManager::Initialize();
cStringList args;
@@ -925,7 +934,7 @@
= settings.Setting("ExtrasBase")
+ "/source/testsuites/nAnalyze/Brainstorm/EpochalVsContinuous/data";
- args.PushRear("cAnalyze_Brainstorm_EpochalVsContinuous");
+ args.PushRear("cAnalyze_Brainstorm_SynchronousVsContinuous");
args.PushRear("-c");
args.PushRear(config_dir + "/avida.cfg");
@@ -953,9 +962,7 @@
args.PushRear("DATA_DIR");
args.PushRear(data_dir);
- /*
- Run Avida in standard mode to generate data files.
- */
+ /* Run Avida in standard mode to generate data files. {{{3 */
if(false){
cout << "------ Starting standard Avida run." << endl;
@@ -973,78 +980,339 @@
}
// note: driver deletes world deletes config.
}
- /*
- Run Avida in analyze mode to analyze data files.
- */
- {
+ /* Run Avida in analyze mode to analyze data files. {{{3 */
+ if(true){
cout << "------ Starting Avida analysis." << endl;
-
+ /* Setup of Analyze mode. {{{4 */
+ ERROR("kgn at FIXME: write unit test verifying args list is not destroyed in cAvidaConfig::LoadWithArgs() -");
cWorld *world = new cWorld(cAvidaConfig::LoadWithArgs(args));
- ERROR("kgn at FIXME: write unit test verifying args list is not destroyed in cAvidaConfig::LoadWithArgs() -");
- TEST(world);
- if(world){
- cAvidaDriver* driver = new cDefaultAnalyzeDriver(world, false);
- TEST(driver);
- if(driver){
- cAnalyze& a = world->GetAnalyze();
- cString s;
+ if(!world){
+ ERROR("Couldn't instantiate cWorld -");
+ return;
+ }
- //a.Send(cString("SET d ") + data_dir);
- //a.Send("SET_BATCH 0");
+ cAvidaDriver* driver = new cDefaultAnalyzeDriver(world, false);
+ if(!driver){
+ ERROR("Couldn't instantiate cDefaultAnalyzeDriver -");
+ return;
+ }
- //a.Send("PURGE_BATCH");
- //a.Send("LOAD $d/detail-500.pop");
- //a.Send("LOAD $d/historic-500.pop");
+ cAnalyze& a = world->GetAnalyze();
+ cString s;
+ /* Begin Analyze script. {{{4 */
+ a.Send("VERBOSE");
+ a.Send("SET_BATCH 0");
+ a.Send("PURGE_BATCH");
+ {
+ s = "LOAD_ORGANISM ";
+ s += local_config_dir;
+ s += "/default-classic.org";
+ }
+ a.Send(s);
+ a.Send("RECALCULATE");
- //for(int i=0; i<10; i++){
- // blah = "blah";
- // blah += cStringUtil::Convert(i);
- // cout << blah << endl;
- //}
+ /* 'num_gens' synchronous generations. {{{4 */
+ int num_gens = 3;
+ for(int g=0; g<num_gens; g++){
+ /* Mock-up of arguments to COMPETE command. {{{5 */
+ int world_x = world->GetConfig().WORLD_X.Get();
+ int world_y = world->GetConfig().WORLD_Y.Get();
+ int batch_size = world_x * world_y;
+ int batch_from = g;
+ int batch_to = g + 1;
- //a.Send("VERBOSE");
- //s = "SET d ";
- //s += data_dir;
- //a.Send(s);
+ {
+ s = "SET f ";
+ s += cStringUtil::Convert(batch_from);
+ }
+ a.Send(s);
- //for(int i=0; i<3; i++){
- // s = "SET i ";
- // s += cStringUtil::Convert(i);
- // a.Send(s);
- // a.Send("SET_BATCH $i");
- // a.Send("PURGE_BATCH");
- // a.Send("LOAD_SEQUENCE rmzavcgmciqqptqpqcpctletncogcbeamqdtqcptipqfpgqxutycuastttva");
- // a.Send("RECALCULATE");
- // a.Send("DETAIL $d/detail-analyze.dat fitness merit gest_time length viable sequence");
- // a.Send("TRACE");
- // a.Send("PRINT");
- //}
+ a.Send("SET_BATCH $f");
+ a.Send("RECALCULATE");
+ a.Send("DETAIL archive_$f/detail.dat id parent_id num_cpus fitness viable length sequence");
+ //a.Send("RECALCULATE");
+ //a.Send("DETAIL archive_$f/detail.dat fitness merit gest_time length viable sequence");
+ //a.Send("TRACE archive_$f");
+ //a.Send("PRINT archive_$f");
+ {
+ s = "SET t ";
+ s += cStringUtil::Convert(batch_to);
+ }
+ a.Send(s);
- a.Send("VERBOSE");
- for(int i=1; i<=3; i++){
- s = "SET i ";
- s += cStringUtil::Convert(i);
- a.Send(s);
- a.Send("SET_BATCH $i");
- a.Send("PURGE_BATCH");
- a.Send("LOAD_SEQUENCE rmzavcgmciqqptqpqcpctletncogcbeamqdtqcptipqfpgqxutycuastttva");
- a.Send("RECALCULATE");
- a.Send("DETAIL detail_test_$i.dat fitness merit gest_time length viable sequence");
- a.Send("TRACE");
- a.Send("PRINT");
+ a.Send("SET_BATCH $t");
+ a.Send("PURGE_BATCH");
+
+ /* COMPETE : brainstorm 1 of new Analyze command. {{{5 */
+ if(false){
+ /* Arguments to COMPETE: */
+ /*
+ COMPETE
+ batch_size
+ from_id
+ to_id=current
+ //test_viable=1
+ //type='fitness'
+ */
+ /* Get iterator into "from" batch. */
+ tListIterator<cAnalyzeGenotype> batch_it(a.batch[batch_from].List());
+ /* Get size of "from" batch. */
+ const int parent_batch_size = a.batch[batch_from].List().GetSize();
+ if(parent_batch_size <= 0){
+ cout << "Warning: origin batch is empty, cannot sample to destination batch." << endl;
+ break;
}
+ /* Create scheduler. */
+ cSchedule* schedule = new cProbSchedule(
+ parent_batch_size,
+ world->GetRandom().GetInt(0x7FFFFFFF)
+ );
- delete driver; driver=0;
+ /* Initialize scheduler with fitness values per-organism. */
+ tArray<cAnalyzeGenotype *> gen_array(parent_batch_size);
+ tArray<cMerit> fitness_array(parent_batch_size);
+ cAnalyzeGenotype * genotype = NULL;
+ int array_pos = 0;
+ while ((genotype = batch_it.Next()) != NULL) {
+ //cAnalyzeGenotype * new_genotype = new cAnalyzeGenotype(*genotype);
+ //batch[batch_to].List().PushRear(new_genotype);
+ gen_array[array_pos] = genotype;
+ /*
+ kgn at XXX FIXME HACK
+ multiplication by 1000 because merits less than 1 are truncated to zero.
+ */
+ fitness_array[array_pos] = genotype->GetFitness() * 1000;
+ schedule->Adjust(array_pos, fitness_array[array_pos]);
+ array_pos++;
+ }
+
+
+ /* Use scheduler to sample organisms in "from" batch. */
+ for(int i=0; i<batch_size; /* don't increment i yet */){
+ /* Sample an organism. */
+ array_pos = schedule->GetNextID();
+ if(array_pos < 0){
+ cout << "Warning: No organisms in origin batch have positive fitness, cannot sample to destination batch." << endl;
+ break;
+ }
+ genotype = gen_array[array_pos];
+ /* If not viable, discard and continue. */
+ if(!genotype->GetViable()){
+ continue;
+ }
+ /* Replicate an offspring. */
+ /*
+ Mutate / crossover (how?) the offspring.
+ - Q : In cHardwareCPU, for example, how do we:
+ - determine lineage ?
+ - determine how to mutate ?
+ - determine whether to crossover ?
+ - Consider both of repro and h-divide instructions.
+ */
+ /* Place offspring in "to" batch. */
+ /* Increment and continue. */
+ i++;
+ }
}
- cout << "------ Finished Avida analysis." << endl;
+
+ /* COMPETE : brainstorm 2 of new Analyze command. {{{5 */
+ if(true){
+ /* Arguments to COMPETE: */
+ /*
+ batch_size
+ from_id
+ to_id=current
+ */
+ /* Get iterator into "from" batch. */
+ tListIterator<cAnalyzeGenotype> batch_it(a.batch[batch_from].List());
+ /* Get size of "from" batch. */
+ const int parent_batch_size = a.batch[batch_from].List().GetSize();
+ if(parent_batch_size <= 0){
+ cout << "Warning: origin batch is empty, cannot sample to destination batch." << endl;
+ break;
+ }
+ /* Create scheduler. */
+ cSchedule* schedule = new cProbSchedule(
+ parent_batch_size,
+ world->GetRandom().GetInt(0x7FFFFFFF)
+ );
+
+ /* Initialize scheduler with fitness values per-organism. */
+ tArray<cAnalyzeGenotype *> genotype_array(parent_batch_size);
+ tArray<cCPUMemory> offspring_genome_array(parent_batch_size);
+ tArray<cMerit> fitness_array(parent_batch_size);
+ cAnalyzeGenotype * genotype = NULL;
+
+ cTestCPU *testcpu = world->GetHardwareManager().CreateTestCPU();
+ TEST(0 != testcpu);
+
+ cCPUTestInfo *test_info = new cCPUTestInfo();
+ TEST(0 != test_info);
+
+ test_info->UseRandomInputs(false);
+
+ int array_pos = 0;
+ while ((genotype = batch_it.Next()) != NULL) {
+ //cAnalyzeGenotype * new_genotype = new cAnalyzeGenotype(*genotype);
+ //batch[batch_to].List().PushRear(new_genotype);
+ genotype_array[array_pos] = genotype;
+ genotype->Recalculate(world->GetDefaultContext(), testcpu, NULL, test_info);
+ if(genotype->GetViable()){
+ /*
+ kgn at XXX FIXME HACK
+ multiplication by 1000 because merits less than 1 are truncated to zero.
+ */
+ fitness_array[array_pos] = genotype->GetFitness() * 1000.;
+ offspring_genome_array[array_pos] = test_info->GetTestOrganism(0)->ChildGenome();
+ } else {
+ fitness_array[array_pos] = 0.0;
+ //offspring_genome_array[array_pos].Reset(0);
+ }
+ schedule->Adjust(array_pos, fitness_array[array_pos]);
+ array_pos++;
+ }
+
+
+ /* Use scheduler to sample organisms in "from" batch. */
+ for(int i=0; i<batch_size; /* don't increment i yet */){
+ cout << "i : " << i << endl;
+ /* Sample an organism. */
+ array_pos = schedule->GetNextID();
+ if(array_pos < 0){
+ cout << "Warning: No organisms in origin batch have positive fitness, cannot sample to destination batch." << endl;
+ break;
+ }
+ genotype = genotype_array[array_pos];
+ /* If not viable, discard and continue. */
+ if(!genotype->GetViable()){
+ ERROR("scheduler sampled a non-viable organism!");
+ continue;
+ }
+
+ /*
+ Replication brainstorm : construction & test : step 1
+ - try exact replicationm, without mutation or crossover.
+ - this works !
+ */
+ if(false){
+ cAnalyzeGenotype * new_genotype = new cAnalyzeGenotype(*genotype);
+ a.batch[batch_to].List().PushRear(new_genotype);
+ }
+
+ /*
+ Replication brainstorm : construction & test : step 2
+ - now split-out a genome, such that it can be altered, and use
+ that genome (unaltered) for replication.
+ */
+ if(false){
+ cCPUMemory child_genome = offspring_genome_array[array_pos];
+ cAnalyzeGenotype * new_genotype = new cAnalyzeGenotype(
+ world,
+ child_genome,
+ a.inst_set
+ );
+ a.batch[batch_to].List().PushRear(new_genotype);
+ cout << "size : " << a.batch[batch_to].List().GetSize() << endl;
+ }
+
+ /*
+ Replication brainstorm : construction & test : step 3
+ - now split-out a genome, such that it can be altered, and use
+ that genome (unaltered) for replication.
+ */
+ if(false){
+ cCPUMemory child_genome = offspring_genome_array[array_pos];
+ child_genome[2*batch_to + 9].SetOp(batch_to + 5);
+ child_genome[2*batch_to + 10].SetOp(i % 2);
+ cAnalyzeGenotype * new_genotype = new cAnalyzeGenotype(
+ world,
+ child_genome,
+ a.inst_set
+ );
+ a.batch[batch_to].List().PushRear(new_genotype);
+ cout << "size : " << a.batch[batch_to].List().GetSize() << endl;
+ }
+
+ /*
+ Replication brainstorm : construction & test : step 4
+ - Mutations: Copy Mutation, Divide Insertion, Divide Deletion
+ */
+ if(true){
+ double copy_mut_prob = world->GetConfig().COPY_MUT_PROB.Get();
+ double ins_mut_prob = world->GetConfig().DIVIDE_INS_PROB.Get();
+ double del_mut_prob = world->GetConfig().DIVIDE_DEL_PROB.Get();
+ int ins_line = -1;
+ int del_line = -1;
+ cout << "copy_mut_prob:" << copy_mut_prob << endl;
+ cout << "ins_mut_prob:" << ins_mut_prob << endl;
+ cout << "del_mut_prob:" << del_mut_prob << endl;
+ cCPUMemory child_genome = offspring_genome_array[array_pos];
+
+ if (copy_mut_prob > 0.0) {
+ for (int n = 0; n < child_genome.GetSize(); n++) {
+ if (world->GetRandom().P(copy_mut_prob)) {
+ child_genome[n] = a.inst_set.GetRandomInst(world->GetDefaultContext());
+ }
+ }
+ }
+
+ // Perform an Insertion if it has one.
+ if (world->GetRandom().P(ins_mut_prob)) {
+ ins_line = world->GetRandom().GetInt(child_genome.GetSize() + 1);
+ child_genome.Insert(ins_line, a.inst_set.GetRandomInst(world->GetDefaultContext()));
+ }
+
+ // Perform a Deletion if it has one.
+ if (world->GetRandom().P(del_mut_prob)) {
+ del_line = world->GetRandom().GetInt(child_genome.GetSize());
+ child_genome.Remove(del_line);
+ }
+
+ cAnalyzeGenotype * new_genotype = new cAnalyzeGenotype(
+ world,
+ child_genome,
+ a.inst_set
+ );
+ a.batch[batch_to].List().PushRear(new_genotype);
+ cout << "size : " << a.batch[batch_to].List().GetSize() << endl;
+ }
+
+ /* Replicate an offspring. */
+ /*
+ Mutate / crossover (how?) the offspring.
+ - Q : In cHardwareCPU, for example, how do we:
+ - determine lineage ?
+ - determine how to mutate ?
+ - determine whether to crossover ?
+ - Consider both of repro and h-divide instructions.
+ */
+ /* Place offspring in "to" batch. */
+ /* Increment and continue. */
+ i++;
+
+ a.batch[batch_to].SetLineage(false);
+ a.batch[batch_to].SetAligned(false);
+ }
+
+ if(test_info){ delete test_info; test_info = 0; }
+ if(testcpu){ delete testcpu; testcpu = 0; }
+ if(schedule){ delete schedule; schedule = 0; }
+ }
+ a.Send("SET_BATCH $t");
+ a.Send("RECALCULATE");
+ a.Send("DETAIL archive_$t/detail.dat id parent_id num_cpus fitness viable length sequence");
}
+
+ delete driver; driver=0;
// note: driver deletes world deletes config.
+
+ cout << "------ Finished Avida analysis." << endl;
}
}
- cAddTestSuite t("cAnalyze_Brainstorm_EpochalVsContinuous", test);
+ cAddTestSuite t("cAnalyze_Brainstorm_SynchronousVsContinuous", test);
}
/* Unit tests. {{{1 */
@@ -1154,5 +1422,3 @@
*/
void PhysicalLink(){}
}
-
-
More information about the Avida-cvs
mailing list