[Avida-SVN] r1732 - in development: . source/cpu source/main
matt at myxo.css.msu.edu
matt at myxo.css.msu.edu
Fri Jun 29 14:16:00 PDT 2007
Author: matt
Date: 2007-06-29 17:16:00 -0400 (Fri, 29 Jun 2007)
New Revision: 1732
Modified:
development/build_avida
development/source/cpu/cCPUTestInfo.cc
development/source/cpu/cTestCPU.cc
development/source/cpu/cTestCPU.h
development/source/main/cAvidaConfig.h
development/source/main/cPopulation.cc
Log:
Submitting entire implementation for pre-calculate merit and reset_inputs_on_divide.
Modified: development/build_avida
===================================================================
--- development/build_avida 2007-06-29 21:13:38 UTC (rev 1731)
+++ development/build_avida 2007-06-29 21:16:00 UTC (rev 1732)
@@ -3,6 +3,6 @@
mkdir -p cbuild
cd cbuild
cmake "$@" ../
-make
+make -j 3
make install
Modified: development/source/cpu/cCPUTestInfo.cc
===================================================================
--- development/source/cpu/cCPUTestInfo.cc 2007-06-29 21:13:38 UTC (rev 1731)
+++ development/source/cpu/cCPUTestInfo.cc 2007-06-29 21:16:00 UTC (rev 1732)
@@ -36,6 +36,7 @@
, trace_execution(false)
, trace_task_order(false)
, use_random_inputs(false)
+ , use_manual_inputs(false)
, m_tracer(NULL)
, org_array(max_tests)
{
Modified: development/source/cpu/cTestCPU.cc
===================================================================
--- development/source/cpu/cTestCPU.cc 2007-06-29 21:13:38 UTC (rev 1731)
+++ development/source/cpu/cTestCPU.cc 2007-06-29 21:16:00 UTC (rev 1732)
@@ -56,6 +56,7 @@
{
m_world = world;
InitResources();
+ m_use_manual_inputs = false;
}
void cTestCPU::InitResources(int res_method, std::vector<std::pair<int, std::vector<double> > > * res, int update, int time_spent_offset)
@@ -320,8 +321,11 @@
// Input sizes can vary based on environment settings, must at least initialize
m_use_random_inputs = test_info.GetUseRandomInputs(); // save this value in case ResetInputs is used.
- m_world->GetEnvironment().SetupInputs(ctx, input_array, m_use_random_inputs);
-
+ if (!test_info.GetUseManualInputs())
+ m_world->GetEnvironment().SetupInputs(ctx, input_array, m_use_random_inputs);
+ else
+ input_array = test_info.manual_inputs;
+
receive_array.Resize(3);
if (test_info.GetUseRandomInputs()) {
receive_array[0] = (15 << 24) + ctx.GetRandom().GetUInt(1 << 24); // 00001111
@@ -333,6 +337,9 @@
receive_array[2] = 0x5562eb41; // 01010101 01100010 11101011 01000001
}
+ if (cur_depth == 0)
+ test_info.used_inputs = input_array;
+
if (cur_depth > test_info.max_depth) test_info.max_depth = cur_depth;
// Setup the organism we're working with now.
@@ -518,6 +525,7 @@
void cTestCPU::ResetInputs(cAvidaContext& ctx)
{
- m_world->GetEnvironment().SetupInputs(ctx, input_array, m_use_random_inputs);
+ if (!m_use_manual_inputs)
+ m_world->GetEnvironment().SetupInputs(ctx, input_array, m_use_random_inputs);
}
Modified: development/source/cpu/cTestCPU.h
===================================================================
--- development/source/cpu/cTestCPU.h 2007-06-29 21:13:38 UTC (rev 1731)
+++ development/source/cpu/cTestCPU.h 2007-06-29 21:16:00 UTC (rev 1732)
@@ -67,7 +67,8 @@
int cur_input;
int cur_receive;
bool m_use_random_inputs;
-
+ bool m_use_manual_inputs;
+
eTestCPUResourceMethod m_res_method;
std::vector<std::pair<int, std::vector<double> > > * m_res;
int m_res_time_spent_offset;
Modified: development/source/main/cAvidaConfig.h
===================================================================
--- development/source/main/cAvidaConfig.h 2007-06-29 21:13:38 UTC (rev 1731)
+++ development/source/main/cAvidaConfig.h 2007-06-29 21:16:00 UTC (rev 1732)
@@ -226,7 +226,8 @@
CONFIG_ADD_VAR(DIVIDE_METHOD, int, 1, "0 = Divide leaves state of mother untouched.\n1 = Divide resets state of mother\n (after the divide, we have 2 children)\n2 = Divide resets state of current thread only\n (does not touch possible parasite threads)");
CONFIG_ADD_VAR(INJECT_METHOD, int, 0, "0 = Leaves the parasite thread state untouched.\n1 = Resets the calling thread state on inject");
CONFIG_ADD_VAR(GENERATION_INC_METHOD, int, 1, "0 = Only the generation of the child is\n increased on divide.\n1 = Both the generation of the mother and child are\n increased on divide (good with DIVIDE_METHOD 1).");
-
+ CONFIG_ADD_VAR(RESET_INPUTS_ON_DIVIDE, int, 0, "Reset environment inputs of parent upon successful divide.");
+
CONFIG_ADD_GROUP(RECOMBINATION_GROUP, "Sexual Recombination and Modularity");
CONFIG_ADD_VAR(RECOMBINATION_PROB, double, 1.0, "probability of recombination in div-sex");
CONFIG_ADD_VAR(MAX_BIRTH_WAIT_TIME, int, -1, "Updates incipiant orgs can wait for crossover");
Modified: development/source/main/cPopulation.cc
===================================================================
--- development/source/main/cPopulation.cc 2007-06-29 21:13:38 UTC (rev 1731)
+++ development/source/main/cPopulation.cc 2007-06-29 21:16:00 UTC (rev 1732)
@@ -54,6 +54,8 @@
#include "cTopology.h"
#include "cWorld.h"
#include "cTopology.h"
+#include "cTestCPU.h"
+#include "cCPUTestInfo.h"
#include <fstream>
#include <vector>
@@ -299,7 +301,20 @@
// If we're not about to kill the parent, do some extra work on it.
if (parent_alive == true) {
- schedule->Adjust(parent_cell.GetID(), parent_phenotype.GetMerit());
+
+ // Reset inputs and re-calculate merit if required
+ if (m_world->GetConfig().RESET_INPUTS_ON_DIVIDE.Get() > 0){
+ environment.SetupInputs(ctx, parent_cell.input_array);
+ if (m_world->GetConfig().PRECALC_MERIT.Get() > 0){
+ cCPUTestInfo test_info;
+ cTestCPU* test_cpu = m_world->GetHardwareManager().CreateTestCPU();
+ test_info.UseManualInputs(parent_cell.input_array); // Test using what the environment will be
+ test_cpu->TestGenome(ctx, test_info, parent_organism.GetHardware().GetMemory()); // Use the true genome
+ parent_phenotype.SetMerit(test_info.GetTestPhenotype().GetMerit()); // Update merit
+ delete test_cpu;
+ }
+ }
+ 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();
@@ -406,6 +421,16 @@
// Setup the inputs in the target cell.
environment.SetupInputs(ctx, target_cell.input_array);
+
+ // Precalculate the merit if requested
+ if (m_world->GetConfig().PRECALC_MERIT.Get() > 0){
+ cCPUTestInfo test_info;
+ cTestCPU* test_cpu = m_world->GetHardwareManager().CreateTestCPU();
+ test_info.UseManualInputs(target_cell.input_array); // Test using what the environment will be
+ test_cpu->TestGenome(ctx, test_info, in_organism->GetHardware().GetMemory()); // Use the true genome
+ in_organism->GetPhenotype().SetMerit(test_info.GetTestPhenotype().GetMerit()); // Update merit
+ delete test_cpu;
+ }
// Update the archive...
More information about the Avida-cvs
mailing list