[Avida-cvs] [avida-svn] r495 - in development: Avida.xcodeproj source/classification source/cpu source/main
brysonda@myxo.css.msu.edu
brysonda at myxo.css.msu.edu
Sat Mar 4 16:35:01 PST 2006
Author: brysonda
Date: 2006-03-04 19:35:01 -0500 (Sat, 04 Mar 2006)
New Revision: 495
Added:
development/source/cpu/cTestCPUInterface.cc
development/source/cpu/cTestCPUInterface.h
development/source/main/cOrgInterface.h
Modified:
development/Avida.xcodeproj/project.pbxproj
development/source/classification/cSpecies.cc
development/source/cpu/CMakeLists.txt
development/source/cpu/cHardware4Stack.cc
development/source/cpu/cHardwareCPU.cc
development/source/cpu/cHardwareSMT.cc
development/source/cpu/cTestCPU.cc
development/source/cpu/cTestCPU.h
development/source/main/cBirthChamber.cc
development/source/main/cFitnessMatrix.cc
development/source/main/cLandscape.cc
development/source/main/cMxCodeArray.cc
development/source/main/cOrganism.cc
development/source/main/cOrganism.h
development/source/main/cPopulation.cc
development/source/main/cPopulation.h
development/source/main/cPopulationCell.cc
development/source/main/cPopulationInterface.cc
development/source/main/cPopulationInterface.h
Log:
Rework PopulationInterface to truly separate TestCPU usage from population usage. Needed to facilitate multiple TestCPU instances per World object.
Modified: development/Avida.xcodeproj/project.pbxproj
===================================================================
--- development/Avida.xcodeproj/project.pbxproj 2006-03-03 16:53:20 UTC (rev 494)
+++ development/Avida.xcodeproj/project.pbxproj 2006-03-05 00:35:01 UTC (rev 495)
@@ -7,6 +7,15 @@
objects = {
/* Begin PBXBuildFile section */
+ 7005A70309BA0FA90007E16E /* cTestCPUInterface.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 7005A70109BA0FA90007E16E /* cTestCPUInterface.h */; };
+ 7005A70409BA0FA90007E16E /* cTestCPUInterface.cc in Sources */ = {isa = PBXBuildFile; fileRef = 7005A70209BA0FA90007E16E /* cTestCPUInterface.cc */; };
+ 7005A70509BA0FA90007E16E /* cTestCPUInterface.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 7005A70109BA0FA90007E16E /* cTestCPUInterface.h */; };
+ 7005A70609BA0FA90007E16E /* cTestCPUInterface.cc in Sources */ = {isa = PBXBuildFile; fileRef = 7005A70209BA0FA90007E16E /* cTestCPUInterface.cc */; };
+ 7005A70709BA0FA90007E16E /* cTestCPUInterface.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 7005A70109BA0FA90007E16E /* cTestCPUInterface.h */; };
+ 7005A70809BA0FA90007E16E /* cTestCPUInterface.cc in Sources */ = {isa = PBXBuildFile; fileRef = 7005A70209BA0FA90007E16E /* cTestCPUInterface.cc */; };
+ 7005A70A09BA0FBE0007E16E /* cOrgInterface.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 7005A70909BA0FBE0007E16E /* cOrgInterface.h */; };
+ 7005A70B09BA0FBE0007E16E /* cOrgInterface.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 7005A70909BA0FBE0007E16E /* cOrgInterface.h */; };
+ 7005A83209BA621F0007E16E /* cOrgMessage.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70B0868808F49EA800FC65FE /* cOrgMessage.cc */; };
700E2996085A1F6000CF158A /* avida in CopyFiles */ = {isa = PBXBuildFile; fileRef = DCC3164D07626CF3008F7A48 /* avida */; };
700E2AF8085DE50C00CF158A /* avida.cc in Sources */ = {isa = PBXBuildFile; fileRef = DCC3109C0762539E008F7A48 /* avida.cc */; };
700E2B6F085DE50C00CF158A /* analyze.cfg in CopyFiles */ = {isa = PBXBuildFile; fileRef = DCC3114B0762539E008F7A48 /* analyze.cfg */; };
@@ -114,7 +123,6 @@
70B0866708F4974300FC65FE /* cMutationRates.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70B0865708F4974300FC65FE /* cMutationRates.cc */; };
70B0866808F4974300FC65FE /* cMxCodeArray.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70B0865808F4974300FC65FE /* cMxCodeArray.cc */; };
70B0868B08F49EA800FC65FE /* cOrganism.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70B0868708F49EA800FC65FE /* cOrganism.cc */; };
- 70B0868C08F49EA800FC65FE /* cOrgMessage.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70B0868808F49EA800FC65FE /* cOrgMessage.cc */; };
70B0868D08F49EA800FC65FE /* cPopulation.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70B0868908F49EA800FC65FE /* cPopulation.cc */; };
70B0868E08F49EA800FC65FE /* cPopulationCell.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70B0868A08F49EA800FC65FE /* cPopulationCell.cc */; };
70B0868F08F49EA800FC65FE /* cOrganism.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70B0868708F49EA800FC65FE /* cOrganism.cc */; };
@@ -461,6 +469,8 @@
7054A17209A8014600038658 /* cAnalyzeJobQueue.h in CopyFiles */,
7054A17B09A802BD00038658 /* cAnalyzeJob.h in CopyFiles */,
7054A1B709A810CB00038658 /* cAnalyzeJobWorker.h in CopyFiles */,
+ 7005A70509BA0FA90007E16E /* cTestCPUInterface.h in CopyFiles */,
+ 7005A70B09BA0FBE0007E16E /* cOrgInterface.h in CopyFiles */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -485,6 +495,7 @@
701384350900A45B0087ED2E /* organism.smtx in CopyFiles */,
7013852D0902E36B0087ED2E /* avida.cfg in CopyFiles */,
7054A12409A7BEFC00038658 /* cThread.h in CopyFiles */,
+ 7005A70709BA0FA90007E16E /* cTestCPUInterface.h in CopyFiles */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -512,12 +523,17 @@
7054A17009A8014600038658 /* cAnalyzeJobQueue.h in CopyFiles */,
7054A17A09A802BD00038658 /* cAnalyzeJob.h in CopyFiles */,
7054A1B509A810CB00038658 /* cAnalyzeJobWorker.h in CopyFiles */,
+ 7005A70309BA0FA90007E16E /* cTestCPUInterface.h in CopyFiles */,
+ 7005A70A09BA0FBE0007E16E /* cOrgInterface.h in CopyFiles */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
+ 7005A70109BA0FA90007E16E /* cTestCPUInterface.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = cTestCPUInterface.h; sourceTree = "<group>"; };
+ 7005A70209BA0FA90007E16E /* cTestCPUInterface.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = cTestCPUInterface.cc; sourceTree = "<group>"; };
+ 7005A70909BA0FBE0007E16E /* cOrgInterface.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = cOrgInterface.h; sourceTree = "<group>"; };
700E28CF0859FFD700CF158A /* tObjectFactory.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tObjectFactory.h; sourceTree = "<group>"; };
700E2B83085DE50C00CF158A /* avida-viewer */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = "avida-viewer"; sourceTree = BUILT_PRODUCTS_DIR; };
701384330900A45B0087ED2E /* organism.smtx */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text; path = organism.smtx; sourceTree = "<group>"; };
@@ -1244,6 +1260,8 @@
70C1EF6708C395D300F50912 /* sCPUStats.h */,
706D30CC0852328F00D7DC8F /* tInstLib.h */,
DCC30FA90762539D008F7A48 /* CMakeLists.txt */,
+ 7005A70109BA0FA90007E16E /* cTestCPUInterface.h */,
+ 7005A70209BA0FA90007E16E /* cTestCPUInterface.cc */,
);
path = cpu;
sourceTree = "<group>";
@@ -1343,6 +1361,7 @@
70B0867208F499C100FC65FE /* nMutation.h */,
70B0875C08F5ECBC00FC65FE /* nReaction.h */,
DCC310A90762539E008F7A48 /* CMakeLists.txt */,
+ 7005A70909BA0FBE0007E16E /* cOrgInterface.h */,
);
path = main;
sourceTree = "<group>";
@@ -1953,6 +1972,7 @@
7054A12309A7BEFC00038658 /* cThread.cc in Sources */,
7054A17309A8014600038658 /* cAnalyzeJobQueue.cc in Sources */,
7054A1B809A810CB00038658 /* cAnalyzeJobWorker.cc in Sources */,
+ 7005A70609BA0FA90007E16E /* cTestCPUInterface.cc in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -2070,6 +2090,7 @@
7054A12109A7BEFC00038658 /* cThread.cc in Sources */,
7054A17109A8014600038658 /* cAnalyzeJobQueue.cc in Sources */,
7054A1B609A810CB00038658 /* cAnalyzeJobWorker.cc in Sources */,
+ 7005A70409BA0FA90007E16E /* cTestCPUInterface.cc in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -2112,7 +2133,6 @@
70B0865E08F4974300FC65FE /* cMutationLib.cc in Sources */,
70B0865F08F4974300FC65FE /* cMutationRates.cc in Sources */,
70B0868B08F49EA800FC65FE /* cOrganism.cc in Sources */,
- 70B0868C08F49EA800FC65FE /* cOrgMessage.cc in Sources */,
70B0868D08F49EA800FC65FE /* cPopulation.cc in Sources */,
70B0868E08F49EA800FC65FE /* cPopulationCell.cc in Sources */,
70B0869D08F49F4800FC65FE /* cPhenotype.cc in Sources */,
@@ -2181,6 +2201,8 @@
7054A12509A7BEFC00038658 /* cThread.cc in Sources */,
7054A17509A8014600038658 /* cAnalyzeJobQueue.cc in Sources */,
7054A1BA09A810CB00038658 /* cAnalyzeJobWorker.cc in Sources */,
+ 7005A70809BA0FA90007E16E /* cTestCPUInterface.cc in Sources */,
+ 7005A83209BA621F0007E16E /* cOrgMessage.cc in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Modified: development/source/classification/cSpecies.cc
===================================================================
--- development/source/classification/cSpecies.cc 2006-03-03 16:53:20 UTC (rev 494)
+++ development/source/classification/cSpecies.cc 2006-03-05 00:35:01 UTC (rev 495)
@@ -15,6 +15,7 @@
#include "cGenotype.h"
#include "cGenomeUtil.h"
#include "cTestCPU.h"
+#include "cWorld.h"
using namespace std;
Modified: development/source/cpu/CMakeLists.txt
===================================================================
--- development/source/cpu/CMakeLists.txt 2006-03-03 16:53:20 UTC (rev 494)
+++ development/source/cpu/CMakeLists.txt 2006-03-05 00:35:01 UTC (rev 495)
@@ -15,6 +15,7 @@
cHeadCPU.cc
cHeadMultiMem.cc
cTestCPU.cc
+ cTestCPUInterface.cc
cTestUtil.cc
)
Modified: development/source/cpu/cHardware4Stack.cc
===================================================================
--- development/source/cpu/cHardware4Stack.cc 2006-03-03 16:53:20 UTC (rev 494)
+++ development/source/cpu/cHardware4Stack.cc 2006-03-05 00:35:01 UTC (rev 495)
@@ -26,6 +26,7 @@
#include "cStringUtil.h"
#include "cTestCPU.h"
#include "cWorldDriver.h"
+#include "cWorld.h"
#include <limits.h>
Modified: development/source/cpu/cHardwareCPU.cc
===================================================================
--- development/source/cpu/cHardwareCPU.cc 2006-03-03 16:53:20 UTC (rev 494)
+++ development/source/cpu/cHardwareCPU.cc 2006-03-05 00:35:01 UTC (rev 495)
@@ -27,6 +27,7 @@
#include "cStringUtil.h"
#include "cTestCPU.h"
#include "cWorldDriver.h"
+#include "cWorld.h"
#include <limits.h>
#include <fstream>
@@ -2761,7 +2762,7 @@
bool cHardwareCPU::Inst_Sense()
{
- const tArray<double> & res_count = organism->PopInterface().GetResources();
+ const tArray<double> & res_count = organism->GetOrgInterface().GetResources();
const int reg_used = FindModifiedRegister(nHardwareCPU::REG_BX);
// If there are no resources to measure, this instruction fails.
Modified: development/source/cpu/cHardwareSMT.cc
===================================================================
--- development/source/cpu/cHardwareSMT.cc 2006-03-03 16:53:20 UTC (rev 494)
+++ development/source/cpu/cHardwareSMT.cc 2006-03-05 00:35:01 UTC (rev 495)
@@ -25,6 +25,7 @@
#include "cStringUtil.h"
#include "cTestCPU.h"
#include "cWorldDriver.h"
+#include "cWorld.h"
#include <limits.h>
Modified: development/source/cpu/cTestCPU.cc
===================================================================
--- development/source/cpu/cTestCPU.cc 2006-03-03 16:53:20 UTC (rev 494)
+++ development/source/cpu/cTestCPU.cc 2006-03-05 00:35:01 UTC (rev 495)
@@ -20,7 +20,7 @@
#include "cInstUtil.h"
#include "cOrganism.h"
#include "cPhenotype.h"
-#include "cPopulationInterface.h"
+#include "cTestCPUInterface.h"
#include "cResourceCount.h"
#include "cResourceLib.h"
#include "cResource.h"
@@ -32,15 +32,6 @@
using namespace std;
-cTestCPU::cTestCPU(cWorld* world)
- : m_world(world)
- , test_interface(world)
- , time_mod(world->GetConfig().TEST_CPU_TIME_MOD.Get())
-{
- resource_count.SetSize(world->GetEnvironment().GetResourceLib().GetSize());
- SetupResources();
-}
-
void cTestCPU::SetupResources(void)
{
// Setup the resources...
@@ -72,10 +63,10 @@
}
return;
-
}
-void cTestCPU::SetupResourceArray(const tArray<double> &resources) {
+void cTestCPU::SetupResourceArray(const tArray<double> &resources)
+{
for(int i=0; i<d_resources.GetSize(); i++) {
if(i >= resources.GetSize()) {
d_resources[i] = 0.0;
@@ -93,7 +84,7 @@
cOrganism & organism = *( test_info.org_array[cur_depth] );
// Determine how long this organism should be tested for...
- int time_allocated = time_mod * organism.GetGenome().GetSize();
+ int time_allocated = m_world->GetConfig().TEST_CPU_TIME_MOD.Get() * organism.GetGenome().GetSize();
// Make sure this genome stands a chance...
if (TestIntegrity(organism.GetGenome()) == false) time_allocated = 0;
@@ -103,25 +94,22 @@
cur_receive = 0;
// Determine if we're tracing and what we need to print.
- cHardwareTracer * tracer =
- test_info.GetTraceExecution() ? (test_info.GetTracer()) : NULL;
+ cHardwareTracer* tracer = test_info.GetTraceExecution() ? (test_info.GetTracer()) : NULL;
int time_used = 0;
- while (time_used < time_allocated &&
- organism.GetHardware().GetMemory().GetSize() &&
- organism.GetPhenotype().GetNumDivides() == 0) {
+ organism.GetHardware().SetTrace(tracer);
+ while (time_used < time_allocated && organism.GetHardware().GetMemory().GetSize() &&
+ organism.GetPhenotype().GetNumDivides() == 0)
+ {
time_used++;
- organism.GetHardware().SetTrace(tracer);
organism.GetHardware().SingleProcess();
- organism.GetHardware().SetTrace(NULL);
// @CAO Need to watch out for parasites.
}
+ organism.GetHardware().SetTrace(NULL);
// Print out some final info in trace...
if (tracer != NULL) {
- if (cHardwareTracer_TestCPU * tracer_test_cpu
- = dynamic_cast<cHardwareTracer_TestCPU *>(tracer)
- ){
+ if (cHardwareTracer_TestCPU* tracer_test_cpu = dynamic_cast<cHardwareTracer_TestCPU*>(tracer)) {
tracer_test_cpu->TraceHardware_TestCPU(
time_used,
time_allocated,
@@ -211,6 +199,7 @@
}
test_info.org_array[cur_depth] = new cOrganism(m_world, genome);
cOrganism & organism = *( test_info.org_array[cur_depth] );
+ organism.SetOrgInterface(new cTestCPUInterface(this));
organism.GetPhenotype().SetupInject(genome.GetSize());
// Run the current organism.
Modified: development/source/cpu/cTestCPU.h
===================================================================
--- development/source/cpu/cTestCPU.h 2006-03-03 16:53:20 UTC (rev 494)
+++ development/source/cpu/cTestCPU.h 2006-03-05 00:35:01 UTC (rev 495)
@@ -19,9 +19,6 @@
#ifndef cString_h
#include "cString.h"
#endif
-#ifndef cPopulationInterface_h
-#include "cPopulationInterface.h"
-#endif
#ifndef cResourceCount_h
#include "cResourceCount.h"
#endif
@@ -36,27 +33,26 @@
{
private:
cWorld* m_world;
- cPopulationInterface test_interface;
tArray<int> input_array;
tArray<int> receive_array;
int cur_input;
int cur_receive;
+
cResourceCount resource_count;
bool d_useResources;
tArray<double> d_emptyDoubleArray;
tArray<double> d_resources;
- int time_mod;
-
bool ProcessGestation(cCPUTestInfo & test_info, int cur_depth);
bool TestGenome_Body(cCPUTestInfo & test_info, const cGenome & genome, int cur_depth);
+ void SetupResources(void);
cTestCPU(); // @not_implemented
cTestCPU(const cTestCPU&); // @not_implemented
cTestCPU& operator=(const cTestCPU&); // @not_implemented
public:
- cTestCPU(cWorld* world);
+ cTestCPU(cWorld* world) : m_world(world) { SetupResources(); }
~cTestCPU() { ; }
bool TestGenome(cCPUTestInfo & test_info, const cGenome & genome);
@@ -69,12 +65,11 @@
// default set, has an allocate, a copy, and a divide).
bool TestIntegrity(const cGenome & test_genome);
- int GetInput();
- int GetInputAt(int & input_pointer);
- int GetReceiveValue();
- const tArray<double> & GetResources();
- void SetResource(int id, double new_level);
- void SetupResources(void);
+ inline int GetInput();
+ inline int GetInputAt(int & input_pointer);
+ inline int GetReceiveValue();
+ inline const tArray<double>& GetResources();
+ inline void SetResource(int id, double new_level);
void SetupResourceArray(const tArray<double> &resources);
bool& UseResources(void) { return d_useResources; }
cResourceCount& GetResourceCount(void) { return resource_count; }
@@ -103,9 +98,7 @@
inline const tArray<double>& cTestCPU::GetResources()
{
- if(d_useResources) {
- return d_resources;
- }
+ if(d_useResources) return d_resources;
return d_emptyDoubleArray;
}
Added: development/source/cpu/cTestCPUInterface.cc
===================================================================
--- development/source/cpu/cTestCPUInterface.cc 2006-03-03 16:53:20 UTC (rev 494)
+++ development/source/cpu/cTestCPUInterface.cc 2006-03-05 00:35:01 UTC (rev 495)
@@ -0,0 +1,94 @@
+/*
+ * cTestCPUOrgInterface.cc
+ * Avida
+ *
+ * Created by David on 3/4/06.
+ * Copyright 2006 Michigan State University. All rights reserved.
+ *
+ */
+
+#include "cTestCPUInterface.h"
+
+#include "cGenotype.h"
+#include "cOrganism.h"
+#include "cOrgMessage.h"
+#include "cTestCPU.h"
+
+
+bool cTestCPUInterface::Divide(cOrganism * parent, cGenome& child_genome)
+{
+ parent->GetPhenotype().TestDivideReset(parent->GetGenome().GetSize());
+ // @CAO in the future, we probably want to pass this child the test_cpu!
+ return true;
+}
+
+cOrganism* cTestCPUInterface::GetNeighbor()
+{
+ return NULL;
+}
+
+int cTestCPUInterface::GetNumNeighbors()
+{
+ return 0;
+}
+
+void cTestCPUInterface::Rotate(int direction)
+{
+}
+
+double cTestCPUInterface::TestFitness()
+{
+ return -1.0;
+}
+
+int cTestCPUInterface::GetInput()
+{
+ return m_testcpu->GetInput();
+}
+
+int cTestCPUInterface::GetInputAt(int& input_pointer)
+{
+ return m_testcpu->GetInputAt(input_pointer);
+}
+
+int cTestCPUInterface::Debug()
+{
+ return -1;
+}
+
+const tArray<double>& cTestCPUInterface::GetResources()
+{
+ return m_testcpu->GetResources();
+}
+
+void cTestCPUInterface::UpdateResources(const tArray<double>& res_change)
+{
+}
+
+void cTestCPUInterface::Die()
+{
+}
+
+void cTestCPUInterface::Kaboom()
+{
+}
+
+bool cTestCPUInterface::SendMessage(cOrgMessage & mess)
+{
+ return false;
+}
+
+int cTestCPUInterface::ReceiveValue()
+{
+ return m_testcpu->GetReceiveValue();
+}
+
+bool cTestCPUInterface::InjectParasite(cOrganism * parent, const cGenome & injected_code)
+{
+ return false;
+}
+
+bool cTestCPUInterface::UpdateMerit(double new_merit)
+{
+ return false;
+}
Added: development/source/cpu/cTestCPUInterface.h
===================================================================
--- development/source/cpu/cTestCPUInterface.h 2006-03-03 16:53:20 UTC (rev 494)
+++ development/source/cpu/cTestCPUInterface.h 2006-03-05 00:35:01 UTC (rev 495)
@@ -0,0 +1,54 @@
+/*
+ * cTestCPUOrgInterface.h
+ * Avida
+ *
+ * Created by David on 3/4/06.
+ * Copyright 2006 Michigan State University. All rights reserved.
+ *
+ */
+
+#ifndef cTestCPUInterface_h
+#define cTestCPUInterface_h
+
+#ifndef cOrgInterface_h
+#include "cOrgInterface.h"
+#endif
+
+class cOrganism;
+class cGenome;
+template <class T> class tArray;
+class cOrgMessage;
+class cTestCPU;
+
+class cTestCPUInterface : public cOrgInterface
+{
+private:
+ cTestCPU* m_testcpu;
+
+public:
+ cTestCPUInterface(cTestCPU* testcpu) : m_testcpu(testcpu) { ; }
+ virtual ~cTestCPUInterface() { ; }
+
+ int GetCellID() { return -1; }
+ void SetCellID(int in_id) { ; }
+
+ bool Divide(cOrganism* parent, cGenome& child_genome);
+ cOrganism* GetNeighbor();
+ int GetNumNeighbors();
+ void Rotate(int direction = 1);
+ void Breakpoint() { ; }
+ double TestFitness();
+ int GetInput();
+ int GetInputAt(int& input_pointer);
+ int Debug();
+ const tArray<double>& GetResources();
+ void UpdateResources(const tArray<double>& res_change);
+ void Die();
+ void Kaboom();
+ bool SendMessage(cOrgMessage& mess);
+ int ReceiveValue();
+ bool InjectParasite(cOrganism* parent, const cGenome& injected_code);
+ bool UpdateMerit(double new_merit);
+};
+
+#endif
Modified: development/source/main/cBirthChamber.cc
===================================================================
--- development/source/main/cBirthChamber.cc 2006-03-03 16:53:20 UTC (rev 494)
+++ development/source/main/cBirthChamber.cc 2006-03-05 00:35:01 UTC (rev 495)
@@ -256,7 +256,7 @@
// Collect some info for building the child.
const int world_x = m_world->GetConfig().WORLD_X.Get();
const int world_y = m_world->GetConfig().WORLD_Y.Get();
- const int parent_id = parent.PopInterface().GetCellID();
+ const int parent_id = parent.GetOrgInterface().GetCellID();
// If nothing is waiting, store child locally.
if (GetNeighborWaiting(parent_id, world_x, world_y) == false) {
@@ -282,7 +282,7 @@
const int world_x = m_world->GetConfig().WORLD_X.Get();
const int world_y = m_world->GetConfig().WORLD_Y.Get();
const int num_demes = m_world->GetConfig().NUM_DEMES.Get();
- const int parent_id = parent.PopInterface().GetCellID();
+ const int parent_id = parent.GetOrgInterface().GetCellID();
const int parent_deme = (int) parent_id/(world_y*world_x/num_demes);
Modified: development/source/main/cFitnessMatrix.cc
===================================================================
--- development/source/main/cFitnessMatrix.cc 2006-03-03 16:53:20 UTC (rev 494)
+++ development/source/main/cFitnessMatrix.cc 2006-03-05 00:35:01 UTC (rev 495)
@@ -11,6 +11,7 @@
#include "cFitnessMatrix.h"
#include "cInstSet.h"
+#include "cWorld.h"
using namespace std;
Modified: development/source/main/cLandscape.cc
===================================================================
--- development/source/main/cLandscape.cc 2006-03-03 16:53:20 UTC (rev 494)
+++ development/source/main/cLandscape.cc 2006-03-05 00:35:01 UTC (rev 495)
@@ -25,7 +25,7 @@
cLandscape::cLandscape(cWorld* world, const cGenome & in_genome, const cInstSet & in_inst_set)
- : m_world(world), inst_set(in_inst_set), base_genome(1), peak_genome(1)
+: m_world(world), inst_set(in_inst_set), base_genome(1), peak_genome(1)
{
site_count = NULL;
Reset(in_genome);
@@ -50,30 +50,30 @@
del_distance = 0;
ins_distance = 0;
trials = 0;
-
+
total_count = 0;
dead_count = 0;
neg_count = 0;
neut_count = 0;
pos_count = 0;
-
+
pos_size = 0;
neg_size = 0;
-
+
total_epi_count = 0;
pos_epi_count = 0;
neg_epi_count = 0;
no_epi_count = 0;
dead_epi_count= 0;
-
+
pos_epi_size = 0;
neg_epi_size = 0;
no_epi_size = 0;
-
+
if (site_count != NULL) delete [] site_count;
site_count = new int[base_genome.GetSize() + 1];
for (int i = 0; i <= base_genome.GetSize(); i++) site_count[i] = 0;
-
+
total_entropy = 0.0;
complexity = 0.0;
neut_min = 0.0;
@@ -83,9 +83,9 @@
void cLandscape::ProcessGenome(cGenome & in_genome)
{
m_world->GetTestCPU().TestGenome(test_info, in_genome);
-
+
test_fitness = test_info.GetColonyFitness();
-
+
total_fitness += test_fitness;
total_sqr_fitness += test_fitness * test_fitness;
total_count++;
@@ -109,14 +109,14 @@
void cLandscape::ProcessBase()
{
// Collect info on base creature.
-
+
m_world->GetTestCPU().TestGenome(test_info, base_genome);
-
+
cPhenotype & phenotype = test_info.GetColonyOrganism()->GetPhenotype();
base_fitness = test_info.GetColonyFitness();
base_merit = phenotype.GetMerit().GetDouble();
base_gestation = phenotype.GetGestationTime();
-
+
peak_fitness = base_fitness;
peak_genome = base_genome;
@@ -128,15 +128,15 @@
void cLandscape::Process(int in_distance)
{
distance = in_distance;
-
+
// Get the info about the base creature.
ProcessBase();
-
+
// Now Process the new creature at the proper distance.
Process_Body(base_genome, distance, 0);
-
+
// Calculate the complexity...
-
+
double max_ent = log((double) inst_set.GetSize());
total_entropy = 0;
for (int i = 0; i < base_genome.GetSize(); i++) {
@@ -151,43 +151,43 @@
// For distances greater than one, this needs to be called recursively.
void cLandscape::Process_Body(cGenome & cur_genome, int cur_distance,
- int start_line)
+ int start_line)
{
const int max_line = base_genome.GetSize() - cur_distance + 1;
const int inst_size = inst_set.GetSize();
-
+
cGenome mod_genome(cur_genome);
-
+
// Loop through all the lines of genome, testing trying all combinations.
for (int line_num = start_line; line_num < max_line; line_num++) {
int cur_inst = base_genome[line_num].GetOp();
-
+
// Loop through all instructions...
for (int inst_num = 0; inst_num < inst_size; inst_num++) {
if (cur_inst == inst_num) continue;
-
+
mod_genome[line_num].SetOp(inst_num);
if (cur_distance <= 1) {
- ProcessGenome(mod_genome);
- if (test_info.GetColonyFitness() >= neut_min) site_count[line_num]++;
+ ProcessGenome(mod_genome);
+ if (test_info.GetColonyFitness() >= neut_min) site_count[line_num]++;
} else {
- Process_Body(mod_genome, cur_distance - 1, line_num + 1);
+ Process_Body(mod_genome, cur_distance - 1, line_num + 1);
}
}
-
+
mod_genome[line_num].SetOp(cur_inst);
}
-
+
}
void cLandscape::ProcessDelete()
{
// Get the info about the base creature.
ProcessBase();
-
+
const int max_line = base_genome.GetSize();
cCPUMemory mod_genome(base_genome);
-
+
// Loop through all the lines of genome, testing all deletions.
for (int line_num = 0; line_num < max_line; line_num++) {
int cur_inst = base_genome[line_num].GetOp();
@@ -196,19 +196,19 @@
if (test_info.GetColonyFitness() >= neut_min) site_count[line_num]++;
mod_genome.Insert(line_num, cInstruction(cur_inst));
}
-
+
}
void cLandscape::ProcessInsert()
{
// Get the info about the base creature.
ProcessBase();
-
+
const int max_line = base_genome.GetSize();
const int inst_size = inst_set.GetSize();
-
+
cCPUMemory mod_genome(base_genome);
-
+
// Loop through all the lines of genome, testing all insertions.
for (int line_num = 0; line_num <= max_line; line_num++) {
// Loop through all instructions...
@@ -219,24 +219,24 @@
mod_genome.Remove(line_num);
}
}
-
+
}
// Prediction for a landscape where n sites are _randomized_.
void cLandscape::PredictWProcess(ostream& fp, int update)
{
distance = 1;
-
+
// Get the info about the base creature.
ProcessBase();
if (base_fitness == 0.0) return;
-
+
BuildFitnessChart();
const int genome_size = fitness_chart.GetNumRows();
const int inst_size = fitness_chart.GetNumCols();
const double min_neut_fitness = 0.99;
const double max_neut_fitness = 1.01;
-
+
// Loop through the entries printing them and doing additional
// calculations.
int total_pos_found = 0;
@@ -246,7 +246,7 @@
double max_fitness = 1.0;
double total_fitness = 0.0;
double total_sqr_fitness = 0.0;
-
+
for (int row = 0; row < genome_size; row++) {
double max_line_fitness = 1.0;
for (int col = 0; col < inst_size; col++) {
@@ -257,33 +257,33 @@
if (cur_fitness > max_neut_fitness) total_pos_found++;
else if (cur_fitness > min_neut_fitness) total_neut_found++;
else if (cur_fitness > 0.0) total_neg_found++;
-
+
if (cur_fitness > max_line_fitness) max_line_fitness = cur_fitness;
}
max_fitness *= max_line_fitness;
}
-
+
const int total_tests = genome_size * inst_size;
total_dead_found = total_tests - total_pos_found - total_neut_found - total_neg_found;
fp << update << " "
- << "1 "
- << ((double) total_dead_found / (double) total_tests) << " "
- << ((double) total_neg_found / (double) total_tests) << " "
- << ((double) total_neut_found / (double) total_tests) << " "
- << ((double) total_pos_found / (double) total_tests) << " "
- << total_tests << " "
- << total_neut_found + total_pos_found << " "
- << total_fitness / (double) total_tests << " "
- << total_sqr_fitness / (double) total_tests << " "
- << endl;
+ << "1 "
+ << ((double) total_dead_found / (double) total_tests) << " "
+ << ((double) total_neg_found / (double) total_tests) << " "
+ << ((double) total_neut_found / (double) total_tests) << " "
+ << ((double) total_pos_found / (double) total_tests) << " "
+ << total_tests << " "
+ << total_neut_found + total_pos_found << " "
+ << total_fitness / (double) total_tests << " "
+ << total_sqr_fitness / (double) total_tests << " "
+ << endl;
fp.flush();
-
+
// Sample the table out to 10 mutations
const int max_muts = 10;
const int min_found = 100;
const int min_tests = 10000;
const int max_tests = 1000000000;
-
+
double test_fitness;
for (int num_muts = 2; num_muts <= max_muts; num_muts++) {
total_pos_found = 0;
@@ -292,44 +292,44 @@
total_fitness = 0.0;
total_sqr_fitness = 0.0;
tArray<int> mut_lines(num_muts);
-
+
int test_id = 0;
while ((test_id < min_tests) ||
- (test_id < max_tests && (total_neut_found + total_pos_found) < min_found)) {
+ (test_id < max_tests && (total_neut_found + total_pos_found) < min_found)) {
m_world->GetRandom().Choose(genome_size, mut_lines);
test_fitness = 1.0;
for (int j = 0; j < num_muts && test_fitness != 0.0; j++) {
- test_fitness *=
- fitness_chart(mut_lines[j], m_world->GetRandom().GetUInt(inst_size));
+ test_fitness *=
+ fitness_chart(mut_lines[j], m_world->GetRandom().GetUInt(inst_size));
}
total_fitness += test_fitness;
total_sqr_fitness += test_fitness * test_fitness;
if (test_fitness > max_neut_fitness) total_pos_found++;
else if (test_fitness > min_neut_fitness) total_neut_found++;
else if (test_fitness > 0.0) total_neg_found++;
-
+
test_id++;
}
-
+
total_dead_found = test_id - total_pos_found - total_neut_found - total_neg_found;
fp << update << " " // 1
- << num_muts << " " // 2
- << ((double) total_dead_found / (double) test_id) << " " // 3
- << ((double) total_neg_found / (double) test_id) << " " // 4
- << ((double) total_neut_found / (double) test_id) << " " // 5
- << ((double) total_pos_found / (double) test_id) << " " // 6
- << test_id << " " // 7
- << total_neut_found + total_pos_found << " " // 8
- << total_fitness / (double) test_id << " " // 9
- << total_sqr_fitness / (double) test_id << " " // 10
- << endl;
+ << num_muts << " " // 2
+ << ((double) total_dead_found / (double) test_id) << " " // 3
+ << ((double) total_neg_found / (double) test_id) << " " // 4
+ << ((double) total_neut_found / (double) test_id) << " " // 5
+ << ((double) total_pos_found / (double) test_id) << " " // 6
+ << test_id << " " // 7
+ << total_neut_found + total_pos_found << " " // 8
+ << total_fitness / (double) test_id << " " // 9
+ << total_sqr_fitness / (double) test_id << " " // 10
+ << endl;
fp.flush();
-
+
if (total_pos_found + total_neut_found < min_found / 2) break;
}
-
+
// Calculate the complexity...
-
+
double max_ent = log((double) inst_set.GetSize());
total_entropy = 0;
for (int i = 0; i < base_genome.GetSize(); i++) {
@@ -343,17 +343,17 @@
void cLandscape::PredictNuProcess(ostream& fp, int update)
{
distance = 1;
-
+
// Get the info about the base creature.
ProcessBase();
if (base_fitness == 0.0) return;
-
+
BuildFitnessChart();
const int genome_size = fitness_chart.GetNumRows();
const int inst_size = fitness_chart.GetNumCols();
const double min_neut_fitness = 0.99;
const double max_neut_fitness = 1.01;
-
+
// Loop through the entries printing them and doing additional
// calculations.
int total_pos_found = 0;
@@ -365,7 +365,7 @@
double max_found_fitness = 0.0;
double total_fitness = 0.0;
double total_sqr_fitness = 0.0;
-
+
for (int row = 0; row < genome_size; row++) {
double max_line_fitness = 1.0;
int base_inst = base_genome[row].GetOp();
@@ -378,36 +378,36 @@
if (cur_fitness > max_neut_fitness) total_pos_found++;
else if (cur_fitness > min_neut_fitness) total_neut_found++;
else if (cur_fitness > 0.0) total_neg_found++;
-
+
if (cur_fitness > max_line_fitness) max_line_fitness = cur_fitness;
}
max_fitness *= max_line_fitness;
if (max_line_fitness > max_found_fitness) max_found_fitness = max_line_fitness;
}
-
+
const int total_tests = genome_size * inst_size;
total_live_found = total_pos_found + total_neut_found + total_neg_found;
total_dead_found = total_tests - total_live_found;
fp << update << " "
- << "1 "
- << ((double) total_dead_found / (double) total_tests) << " "
- << ((double) total_neg_found / (double) total_tests) << " "
- << ((double) total_neut_found / (double) total_tests) << " "
- << ((double) total_pos_found / (double) total_tests) << " "
- << total_tests << " "
- << total_live_found << " "
- << total_fitness / (double) total_tests << " "
- << total_sqr_fitness / (double) total_tests << " "
- << max_found_fitness << " "
- << endl;
+ << "1 "
+ << ((double) total_dead_found / (double) total_tests) << " "
+ << ((double) total_neg_found / (double) total_tests) << " "
+ << ((double) total_neut_found / (double) total_tests) << " "
+ << ((double) total_pos_found / (double) total_tests) << " "
+ << total_tests << " "
+ << total_live_found << " "
+ << total_fitness / (double) total_tests << " "
+ << total_sqr_fitness / (double) total_tests << " "
+ << max_found_fitness << " "
+ << endl;
fp.flush();
-
+
// Sample the table out to 10 mutations
const int max_muts = 10;
const int min_found = 100;
const int min_tests = 10000;
const int max_tests = 1000000000;
-
+
double test_fitness;
for (int num_muts = 2; num_muts <= max_muts; num_muts++) {
total_pos_found = 0;
@@ -417,53 +417,53 @@
total_sqr_fitness = 0.0;
max_found_fitness = 0.0;
tArray<int> mut_lines(num_muts);
-
+
int test_id = 0;
while ((test_id < min_tests) ||
- (test_id < max_tests && (total_neg_found + total_neut_found + total_pos_found) < min_found)) {
+ (test_id < max_tests && (total_neg_found + total_neut_found + total_pos_found) < min_found)) {
m_world->GetRandom().Choose(genome_size, mut_lines);
test_fitness = 1.0;
for (int j = 0; j < num_muts && test_fitness != 0.0; j++) {
- int base_inst = base_genome[ mut_lines[j] ].GetOp();
- int mut_inst = m_world->GetRandom().GetUInt(inst_size);
- while (mut_inst == base_inst) mut_inst = m_world->GetRandom().GetUInt(inst_size);
- test_fitness *= fitness_chart(mut_lines[j], mut_inst);
- if (test_fitness == 0.0) break;
+ int base_inst = base_genome[ mut_lines[j] ].GetOp();
+ int mut_inst = m_world->GetRandom().GetUInt(inst_size);
+ while (mut_inst == base_inst) mut_inst = m_world->GetRandom().GetUInt(inst_size);
+ test_fitness *= fitness_chart(mut_lines[j], mut_inst);
+ if (test_fitness == 0.0) break;
}
total_fitness += test_fitness;
total_sqr_fitness += test_fitness * test_fitness;
if (test_fitness > max_found_fitness) max_found_fitness = test_fitness;
-
+
if (test_fitness > max_neut_fitness) total_pos_found++;
else if (test_fitness > min_neut_fitness) total_neut_found++;
else if (test_fitness > 0.0) total_neg_found++;
-
+
test_id++;
}
-
+
total_live_found = total_neg_found + total_neut_found + total_pos_found;
total_dead_found = test_id - total_live_found;
-
-
+
+
fp << update << " " // 1
- << num_muts << " " // 2
- << ((double) total_dead_found / (double) test_id) << " " // 3
- << ((double) total_neg_found / (double) test_id) << " " // 4
- << ((double) total_neut_found / (double) test_id) << " " // 5
- << ((double) total_pos_found / (double) test_id) << " " // 6
- << test_id << " " // 7
- << total_live_found << " " // 8
- << total_fitness / (double) test_id << " " // 9
- << total_sqr_fitness / (double) test_id << " " // 10
- << max_found_fitness << " " // 11
- << endl;
+ << num_muts << " " // 2
+ << ((double) total_dead_found / (double) test_id) << " " // 3
+ << ((double) total_neg_found / (double) test_id) << " " // 4
+ << ((double) total_neut_found / (double) test_id) << " " // 5
+ << ((double) total_pos_found / (double) test_id) << " " // 6
+ << test_id << " " // 7
+ << total_live_found << " " // 8
+ << total_fitness / (double) test_id << " " // 9
+ << total_sqr_fitness / (double) test_id << " " // 10
+ << max_found_fitness << " " // 11
+ << endl;
fp.flush();
-
+
if (total_live_found < min_found / 2) break;
}
-
+
// Calculate the complexity...
-
+
double max_ent = log((double) inst_set.GetSize());
total_entropy = 0;
for (int i = 0; i < base_genome.GetSize(); i++) {
@@ -477,86 +477,86 @@
{
trials = in_trials; // Trials _per line_
distance = 1;
-
+
cGenome mod_genome(base_genome);
int genome_size = base_genome.GetSize();
-
+
ProcessBase();
-
+
// Loop through all the lines of genome, testing each line.
for (int line_num = 0; line_num < genome_size; line_num++) {
cInstruction cur_inst( base_genome[line_num] );
-
+
for (int i = 0; i < trials; i++) {
// Choose the new instruction for that line...
cInstruction new_inst( inst_set.GetRandomInst() );
if (cur_inst == new_inst) { i--; continue; }
-
+
// Make the change, and test it!
mod_genome[line_num] = new_inst;
ProcessGenome(mod_genome);
}
-
+
mod_genome[line_num] = cur_inst;
}
}
int cLandscape::RandomProcess(int in_trials, int in_distance, int min_found,
- int max_trials, bool print_if_found)
+ int max_trials, bool print_if_found)
{
distance = in_distance;
-
+
cGenome mod_genome(base_genome);
int genome_size = base_genome.GetSize();
-
+
ProcessBase();
-
+
int mut_num;
tArray<int> mut_lines(distance);
-
+
// Loop through all the lines of genome, testing many combinations.
int cur_trial = 0;
int total_found = 0;
-
-// for (cur_trial = 0;
-// (cur_trial < in_trials) ||
-// (total_found < min_found && cur_trial < max_trials);
-// cur_trial++) {
-// Way too confusing and not being used, commented it out DM
-
+
+ // for (cur_trial = 0;
+ // (cur_trial < in_trials) ||
+ // (total_found < min_found && cur_trial < max_trials);
+ // cur_trial++) {
+ // Way too confusing and not being used, commented it out DM
+
for (cur_trial = 0; cur_trial < in_trials; cur_trial++) {
-
+
// Choose the lines to mutate...
m_world->GetRandom().Choose(genome_size, mut_lines);
-
+
// Choose the new instructions for those lines...
for (mut_num = 0; mut_num < distance; mut_num++) {
const cInstruction new_inst( inst_set.GetRandomInst() );
const cInstruction & cur_inst = base_genome[ mut_lines[mut_num] ];
if (cur_inst == new_inst) {
- mut_num--;
- continue;
+ mut_num--;
+ continue;
}
-
+
mod_genome[ mut_lines[mut_num] ] = new_inst;
}
-
+
// And test it!
-
+
ProcessGenome(mod_genome);
-
-
+
+
// And reset the genome.
for (mut_num = 0; mut_num < distance; mut_num++) {
mod_genome[ mut_lines[mut_num] ] = base_genome[ mut_lines[mut_num] ];
}
}
-
+
trials = cur_trial;
-
+
return total_found;
-}
+ }
void cLandscape::BuildFitnessChart()
{
@@ -564,67 +564,67 @@
const int max_line = base_genome.GetSize();
const int inst_size = inst_set.GetSize();
fitness_chart.ResizeClear(max_line, inst_size);
-
+
cGenome mod_genome(base_genome);
-
+
// Loop through all the lines of genome, testing trying all combinations.
for (int line_num = 0; line_num < max_line; line_num++) {
int cur_inst = base_genome[line_num].GetOp();
-
+
// Loop through all instructions...
for (int inst_num = 0; inst_num < inst_size; inst_num++) {
if (cur_inst == inst_num) {
- fitness_chart(line_num, inst_num) = base_fitness;
- continue;
+ fitness_chart(line_num, inst_num) = base_fitness;
+ continue;
}
-
+
mod_genome[line_num].SetOp(inst_num);
ProcessGenome(mod_genome);
fitness_chart(line_num, inst_num) = test_info.GetColonyFitness();
}
-
+
mod_genome[line_num].SetOp(cur_inst);
}
-
+
}
void cLandscape::TestPairs(int in_trials, ostream& fp)
{
trials = in_trials;
-
+
ProcessBase();
if (base_fitness == 0.0) return;
-
+
BuildFitnessChart();
-
+
cGenome mod_genome(base_genome);
const int genome_size = base_genome.GetSize();
-
+
tArray<int> mut_lines(2);
tArray<cInstruction> mut_insts(2);
-
+
// Loop through all the lines of genome, testing many combinations.
for (int i = 0; i < trials; i++) {
// Choose the lines to mutate...
m_world->GetRandom().Choose(genome_size, mut_lines);
-
+
// Choose the new instructions for those lines...
for (int mut_num = 0; mut_num < 2; mut_num++) {
const cInstruction new_inst( inst_set.GetRandomInst() );
const cInstruction & cur_inst = base_genome[ mut_lines[mut_num] ];
if (cur_inst == new_inst) {
- mut_num--;
- continue;
+ mut_num--;
+ continue;
}
-
+
mut_insts[mut_num] = new_inst;
}
-
+
TestMutPair(mod_genome, mut_lines[0], mut_lines[1], mut_insts[0],
- mut_insts[1], fp);
-
+ mut_insts[1], fp);
+
}
-
+
}
@@ -632,32 +632,32 @@
{
ProcessBase();
if (base_fitness == 0.0) return;
-
+
BuildFitnessChart();
-
+
const int max_line = base_genome.GetSize();
const int inst_size = inst_set.GetSize();
cGenome mod_genome(base_genome);
cInstruction inst1, inst2;
-
+
// Loop through all the lines of genome, testing trying all combinations.
for (int line1_num = 0; line1_num < max_line - 1; line1_num++) {
for (int line2_num = line1_num + 1; line2_num < max_line; line2_num++) {
-
+
// Loop through all instructions...
for (int inst1_num = 0; inst1_num < inst_size; inst1_num++) {
- inst1.SetOp(inst1_num);
- if (inst1 == base_genome[line1_num]) continue;
- for (int inst2_num = 0; inst2_num < inst_size; inst2_num++) {
- inst2.SetOp(inst2_num);
- if (inst2 == base_genome[line2_num]) continue;
- TestMutPair(mod_genome, line1_num, line2_num, inst1, inst2, fp);
- } // inst2_num loop
+ inst1.SetOp(inst1_num);
+ if (inst1 == base_genome[line1_num]) continue;
+ for (int inst2_num = 0; inst2_num < inst_size; inst2_num++) {
+ inst2.SetOp(inst2_num);
+ if (inst2 == base_genome[line2_num]) continue;
+ TestMutPair(mod_genome, line1_num, line2_num, inst1, inst2, fp);
+ } // inst2_num loop
} //inst1_num loop;
-
+
} // line2_num loop
} // line1_num loop.
-
+
}
@@ -669,51 +669,51 @@
}
void cLandscape::HillClimb_Body(ofstream& fp, cGenome & cur_genome,
- int & gen)
+ int & gen)
{
cCPUMemory mod_genome(base_genome);
-
+
const int inst_size = inst_set.GetSize();
-
+
double pos_frac = 1.0;
-
+
bool finished = false;
while (finished == false) {
if (pos_frac == 0.0) finished = true;
-
+
// Search the landscape for the next best.
Reset(cur_genome);
const int max_line = cur_genome.GetSize();
-
+
// Try all Mutations...
Process(1);
-
+
// Try Insertion Mutations.
-
+
mod_genome = cur_genome;
for (int line_num = 0; line_num <= max_line; line_num++) {
// Loop through all instructions...
for (int inst_num = 0; inst_num < inst_size; inst_num++) {
- mod_genome.Insert(line_num, cInstruction(inst_num));
- ProcessGenome(mod_genome);
- mod_genome.Remove(line_num);
+ mod_genome.Insert(line_num, cInstruction(inst_num));
+ ProcessGenome(mod_genome);
+ mod_genome.Remove(line_num);
}
}
-
+
// Try all deletion mutations.
-
+
for (int line_num = 0; line_num < max_line; line_num++) {
int cur_inst = cur_genome[line_num].GetOp();
mod_genome.Remove(line_num);
ProcessGenome(mod_genome);
mod_genome.Insert(line_num, cInstruction(cur_inst));
}
-
+
pos_frac = GetProbPos();
-
+
// Print the information on the current best.
HillClimb_Print(fp, cur_genome, gen);
-
+
// Move on to the peak genome found.
cur_genome = GetPeakGenome();
gen++;
@@ -734,43 +734,43 @@
m_world->GetTestCPU().TestGenome(test_info, _genome);
cPhenotype &colony_phenotype = test_info.GetColonyOrganism()->GetPhenotype();
fp << gen << " "
- << colony_phenotype.GetMerit().GetDouble() << " "
- << colony_phenotype.GetGestationTime() << " "
- << colony_phenotype.GetFitness() << " "
- << _genome.GetSize() << " "
- << GetProbDead() << " "
- << GetProbNeg() << " "
- << GetProbNeut() << " "
- << GetProbPos() << " "
- << endl;
+ << colony_phenotype.GetMerit().GetDouble() << " "
+ << colony_phenotype.GetGestationTime() << " "
+ << colony_phenotype.GetFitness() << " "
+ << _genome.GetSize() << " "
+ << GetProbDead() << " "
+ << GetProbNeg() << " "
+ << GetProbNeut() << " "
+ << GetProbPos() << " "
+ << endl;
}
double cLandscape::TestMutPair(cGenome & mod_genome, int line1, int line2,
- const cInstruction & mut1, const cInstruction & mut2, ostream& fp)
+ const cInstruction & mut1, const cInstruction & mut2, ostream& fp)
{
mod_genome[line1] = mut1;
mod_genome[line2] = mut2;
m_world->GetTestCPU().TestGenome(test_info, mod_genome);
double combo_fitness = test_info.GetColonyFitness() / base_fitness;
-
+
mod_genome[line1] = base_genome[line1];
mod_genome[line2] = base_genome[line2];
-
+
double mut1_fitness = fitness_chart(line1, mut1.GetOp()) / base_fitness;
double mut2_fitness = fitness_chart(line2, mut2.GetOp()) / base_fitness;
double mult_combo = mut1_fitness * mut2_fitness;
-
+
/*
- fp << line1 << " "
- << line2 << " "
- << ( (int) mut1.GetOp() ) << " "
- << ( (int) mut2.GetOp() ) << " ";
-
- fp << ( fitness_chart(line1, mut1.GetOp()) / base_fitness ) << " "
- << ( fitness_chart(line2, mut2.GetOp()) / base_fitness ) << " "
- << combo_fitness << endl;
- */
-
+ fp << line1 << " "
+ << line2 << " "
+ << ( (int) mut1.GetOp() ) << " "
+ << ( (int) mut2.GetOp() ) << " ";
+
+ fp << ( fitness_chart(line1, mut1.GetOp()) / base_fitness ) << " "
+ << ( fitness_chart(line2, mut2.GetOp()) / base_fitness ) << " "
+ << combo_fitness << endl;
+ */
+
total_epi_count++;
if ((mut1_fitness==0 || mut2_fitness==0)&&(combo_fitness==0)) {
dead_epi_count++;
@@ -783,7 +783,7 @@
} else {
no_epi_count++;
no_epi_size = no_epi_size + combo_fitness;
- }
+ }
return combo_fitness;
}
@@ -792,36 +792,36 @@
void cLandscape::PrintStats(ofstream& fp, int update)
{
fp << update << " " // 1
- << GetProbDead() << " " // 2
- << GetProbNeg() << " " // 3
- << GetProbNeut() << " " // 4
- << GetProbPos() << " " // 5
-// << pos_size << " " // 6
-// << pos_count << " " // 6
- << GetAvPosSize() << " " // 6
- << GetAvNegSize() << " " // 7
- << total_count << " " // 8
- << distance << " " // 9
-// << neut_min << " " // 10
-// << neut_max << " " // 10
-// << nHardware::FITNESS_NEUTRAL_MIN << " " // 10
-// << nHardware::FITNESS_NEUTRAL_MAX << " " // 10
- << base_fitness << " " // 10
- << base_merit << " " // 11
- << base_gestation << " " // 12
- << peak_fitness << " " // 13
- << GetAveFitness() << " " // 14
- << GetAveSqrFitness() << " " // 15
- << total_entropy << " " // 16
- << complexity << " " // 17
- << GetProbEpiDead() << " " // 18
- << GetProbEpiPos() << " " // 19
- << GetProbEpiNeg() << " " // 20
- << GetProbNoEpi() << " " // 21
- << GetAvPosEpiSize() << " " // 22
- << GetAvNegEpiSize() << " " // 23
- << GetAvNoEpiSize() << " " // 24
- << total_epi_count << endl; // 25
+ << GetProbDead() << " " // 2
+ << GetProbNeg() << " " // 3
+ << GetProbNeut() << " " // 4
+ << GetProbPos() << " " // 5
+ // << pos_size << " " // 6
+ // << pos_count << " " // 6
+ << GetAvPosSize() << " " // 6
+ << GetAvNegSize() << " " // 7
+ << total_count << " " // 8
+ << distance << " " // 9
+ // << neut_min << " " // 10
+ // << neut_max << " " // 10
+ // << nHardware::FITNESS_NEUTRAL_MIN << " " // 10
+ // << nHardware::FITNESS_NEUTRAL_MAX << " " // 10
+ << base_fitness << " " // 10
+ << base_merit << " " // 11
+ << base_gestation << " " // 12
+ << peak_fitness << " " // 13
+ << GetAveFitness() << " " // 14
+ << GetAveSqrFitness() << " " // 15
+ << total_entropy << " " // 16
+ << complexity << " " // 17
+ << GetProbEpiDead() << " " // 18
+ << GetProbEpiPos() << " " // 19
+ << GetProbEpiNeg() << " " // 20
+ << GetProbNoEpi() << " " // 21
+ << GetAvPosEpiSize() << " " // 22
+ << GetAvNegEpiSize() << " " // 23
+ << GetAvNoEpiSize() << " " // 24
+ << total_epi_count << endl; // 25
fp.flush();
}
Modified: development/source/main/cMxCodeArray.cc
===================================================================
--- development/source/main/cMxCodeArray.cc 2006-03-03 16:53:20 UTC (rev 494)
+++ development/source/main/cMxCodeArray.cc 2006-03-05 00:35:01 UTC (rev 495)
@@ -17,6 +17,7 @@
#include "cOrganism.h"
#include "cTestCPU.h"
#include "cTools.h"
+#include "cWorld.h"
#include <iomanip>
Added: development/source/main/cOrgInterface.h
===================================================================
--- development/source/main/cOrgInterface.h 2006-03-03 16:53:20 UTC (rev 494)
+++ development/source/main/cOrgInterface.h 2006-03-05 00:35:01 UTC (rev 495)
@@ -0,0 +1,50 @@
+/*
+ * cOrgInterface.h
+ * Avida
+ *
+ * Created by David on 3/4/06.
+ * Copyright 2006 Michigan State University. All rights reserved.
+ *
+ */
+
+#ifndef cOrgInterface_h
+#define cOrgInterface_h
+
+class cOrganism;
+class cGenome;
+template <class T> class tArray;
+class cOrgMessage;
+
+class cOrgInterface
+{
+private:
+ cOrgInterface(const cOrgInterface&); // @not_implemented
+ cOrgInterface& operator=(const cOrgInterface&); // @not_implemented
+
+public:
+ cOrgInterface() { ; }
+ virtual ~cOrgInterface() { ; }
+
+ virtual int GetCellID() = 0;
+ virtual void SetCellID(int in_id) = 0;
+
+ virtual bool Divide(cOrganism* parent, cGenome& child_genome) = 0;
+ virtual cOrganism* GetNeighbor() = 0;
+ virtual int GetNumNeighbors() = 0;
+ virtual void Rotate(int direction = 1) = 0;
+ virtual void Breakpoint() = 0;
+ virtual double TestFitness() = 0;
+ virtual int GetInput() = 0;
+ virtual int GetInputAt(int& input_pointer) = 0;
+ virtual int Debug() = 0;
+ virtual const tArray<double>& GetResources() = 0;
+ virtual void UpdateResources(const tArray<double>& res_change) = 0;
+ virtual void Die() = 0;
+ virtual void Kaboom() = 0;
+ virtual bool SendMessage(cOrgMessage& mess) = 0;
+ virtual int ReceiveValue() = 0;
+ virtual bool InjectParasite(cOrganism* parent, const cGenome& injected_code) = 0;
+ virtual bool UpdateMerit(double new_merit) = 0;
+};
+
+#endif
Modified: development/source/main/cOrganism.cc
===================================================================
--- development/source/main/cOrganism.cc 2006-03-03 16:53:20 UTC (rev 494)
+++ development/source/main/cOrganism.cc 2006-03-05 00:35:01 UTC (rev 495)
@@ -16,6 +16,7 @@
#include "cGenome.h"
#include "cGenomeUtil.h"
#include "cHardwareBase.h"
+#include "cHardwareManager.h"
#include "cInjectGenotype.h"
#include "cInstSet.h"
#include "cInstUtil.h"
@@ -23,6 +24,7 @@
#include "cStringUtil.h"
#include "tArray.h"
#include "cTools.h"
+#include "cWorld.h"
#include "tList.h"
#include <iomanip>
@@ -30,14 +32,14 @@
using namespace std;
-cOrganism::cOrganism(cWorld* world, const cGenome & in_genome)
+cOrganism::cOrganism(cWorld* world, const cGenome& in_genome)
: m_world(world)
, genotype(NULL)
, phenotype(world)
, initial_genome(in_genome)
, mut_rates(world)
, mut_info(world->GetEnvironment().GetMutationLib(), in_genome.GetSize())
- , pop_interface(world)
+ , m_interface(NULL)
, input_pointer(0)
, input_buf(INPUT_BUF_SIZE)
, output_buf(OUTPUT_BUF_SIZE)
@@ -54,9 +56,8 @@
, is_running(false)
{
// Initialization of structures...
- hardware = pop_interface.NewHardware(this);
+ hardware = m_world->GetHardwareManager().Create(this);
cpu_stats.Setup();
- pop_interface.SetCellID(-1); // No cell at the moment...
if (m_world->GetConfig().DEATH_METHOD.Get() > 0) {
max_executed = m_world->GetConfig().AGE_LIMIT.Get();
@@ -77,17 +78,26 @@
{
assert(is_running == false);
delete hardware;
+ delete m_interface;
}
+void cOrganism::SetOrgInterface(cOrgInterface* interface)
+{
+ delete m_interface;
+ m_interface = interface;
+}
+
double cOrganism::GetTestFitness()
{
- return pop_interface.TestFitness();
+ assert(m_interface);
+ return m_interface->TestFitness();
}
int cOrganism::ReceiveValue()
{
- const int out_value = pop_interface.ReceiveValue();
+ assert(m_interface);
+ const int out_value = m_interface->ReceiveValue();
receive_buf.Add(out_value);
return out_value;
}
@@ -101,17 +111,18 @@
void cOrganism::DoOutput(const int value)
{
- const tArray<double> & resource_count = pop_interface.GetResources();
+ assert(m_interface);
+ const tArray<double> & resource_count = m_interface->GetResources();
tList<tBuffer<int> > other_input_list;
tList<tBuffer<int> > other_output_list;
// If tasks require us to consider neighbor inputs, collect them...
if (m_world->GetEnvironment().GetTaskLib().UseNeighborInput() == true) {
- const int num_neighbors = pop_interface.GetNumNeighbors();
+ const int num_neighbors = m_interface->GetNumNeighbors();
for (int i = 0; i < num_neighbors; i++) {
- pop_interface.Rotate();
- cOrganism * cur_neighbor = pop_interface.GetNeighbor();
+ m_interface->Rotate();
+ cOrganism * cur_neighbor = m_interface->GetNeighbor();
if (cur_neighbor == NULL) continue;
other_input_list.Push( &(cur_neighbor->input_buf) );
@@ -120,10 +131,10 @@
// If tasks require us to consider neighbor outputs, collect them...
if (m_world->GetEnvironment().GetTaskLib().UseNeighborOutput() == true) {
- const int num_neighbors = pop_interface.GetNumNeighbors();
+ const int num_neighbors = m_interface->GetNumNeighbors();
for (int i = 0; i < num_neighbors; i++) {
- pop_interface.Rotate();
- cOrganism * cur_neighbor = pop_interface.GetNeighbor();
+ m_interface->Rotate();
+ cOrganism * cur_neighbor = m_interface->GetNeighbor();
if (cur_neighbor == NULL) continue;
other_output_list.Push( &(cur_neighbor->output_buf) );
@@ -137,7 +148,7 @@
phenotype.TestOutput(input_buf, output_buf, send_buf, receive_buf,
resource_count, res_change, insts_triggered,
other_input_list, other_output_list);
- pop_interface.UpdateResources(res_change);
+ m_interface->UpdateResources(res_change);
for (int i = 0; i < insts_triggered.GetSize(); i++) {
const int cur_inst = insts_triggered[i];
@@ -147,7 +158,8 @@
void cOrganism::SendMessage(cOrgMessage & mess)
{
- if(pop_interface.SendMessage(mess))
+ assert(m_interface);
+ if(m_interface->SendMessage(mess))
sent.Add(mess);
else
{
@@ -163,7 +175,8 @@
bool cOrganism::InjectParasite(const cGenome & injected_code)
{
- return pop_interface.InjectParasite(this, injected_code);
+ assert(m_interface);
+ return m_interface->InjectParasite(this, injected_code);
}
bool cOrganism::InjectHost(const cCodeLabel & label, const cGenome & injected_code)
@@ -208,7 +221,7 @@
}
-bool cOrganism::GetTestOnDivide() const { return pop_interface.TestOnDivide();}
+bool cOrganism::GetTestOnDivide() const { return m_world->GetTestOnDivide();}
bool cOrganism::GetFailImplicit() const { return m_world->GetConfig().FAIL_IMPLICIT.Get(); }
bool cOrganism::GetRevertFatal() const { return m_world->GetConfig().REVERT_FATAL.Get(); }
@@ -268,8 +281,9 @@
bool cOrganism::ActivateDivide()
{
+ assert(m_interface);
// Activate the child! (Keep Last: may kill this organism!)
- return pop_interface.Divide(this, child_genome);
+ return m_interface->Divide(this, child_genome);
}
Modified: development/source/main/cOrganism.h
===================================================================
--- development/source/main/cOrganism.h 2006-03-03 16:53:20 UTC (rev 494)
+++ development/source/main/cOrganism.h 2006-03-05 00:35:01 UTC (rev 495)
@@ -32,8 +32,8 @@
#ifndef cPhenotype_h
#include "cPhenotype.h"
#endif
-#ifndef cPopulationInterface_h
-#include "cPopulationInterface.h"
+#ifndef cOrgInterface_h
+#include "cOrgInterface.h"
#endif
#ifndef tBuffer_h
#include "tBuffer.h"
@@ -64,7 +64,7 @@
// this organism.
cMutationRates mut_rates; // Rate of all possible mutations.
cLocalMutations mut_info; // Info about possible mutations;
- cPopulationInterface pop_interface; // Interface back to the population.
+ cOrgInterface* m_interface; // Interface back to the population.
// Input and Output with the environment
int input_pointer;
@@ -105,22 +105,22 @@
~cOrganism();
cHardwareBase& GetHardware() { return *hardware; }
- cOrganism* GetNeighbor() { return pop_interface.GetNeighbor(); }
- int GetNeighborhoodSize() { return pop_interface.GetNumNeighbors(); }
- void Rotate(int direction) { pop_interface.Rotate(direction); }
- void DoBreakpoint() { pop_interface.Breakpoint(); }
- int GetNextInput() { return pop_interface.GetInputAt(input_pointer); }
- void Die() { pop_interface.Die(); }
- void Kaboom() {pop_interface.Kaboom();}
- int GetCellID() { return pop_interface.GetCellID(); }
- int GetDebugInfo() { return pop_interface.Debug(); }
+ cOrganism* GetNeighbor() { assert(m_interface); return m_interface->GetNeighbor(); }
+ int GetNeighborhoodSize() { assert(m_interface); return m_interface->GetNumNeighbors(); }
+ void Rotate(int direction) { assert(m_interface); m_interface->Rotate(direction); }
+ void DoBreakpoint() { assert(m_interface); m_interface->Breakpoint(); }
+ int GetNextInput() { assert(m_interface); return m_interface->GetInputAt(input_pointer); }
+ void Die() { assert(m_interface); m_interface->Die(); }
+ void Kaboom() { assert(m_interface); m_interface->Kaboom();}
+ int GetCellID() { assert(m_interface); return m_interface->GetCellID(); }
+ int GetDebugInfo() { assert(m_interface); return m_interface->Debug(); }
bool GetSentActive() { return sent_active; }
void SendValue(int value) { sent_active = true; sent_value = value; }
int RetrieveSentValue() { sent_active = false; return sent_value; }
int ReceiveValue();
- void UpdateMerit(double new_merit) { pop_interface.UpdateMerit(new_merit); }
+ void UpdateMerit(double new_merit) { assert(m_interface); m_interface->UpdateMerit(new_merit); }
// Input & Output Testing
void DoInput(const int value);
@@ -194,11 +194,13 @@
cMutationRates & MutationRates() { return mut_rates; }
const cLocalMutations & GetLocalMutations() const { return mut_info; }
cLocalMutations & GetLocalMutations() { return mut_info; }
- const cPopulationInterface& PopInterface() const { return pop_interface; }
- cPopulationInterface& PopInterface() { return pop_interface; }
- const cGenome & GetGenome() const { return initial_genome; }
+ const cOrgInterface& GetOrgInterface() const { assert(m_interface); return *m_interface; }
+ cOrgInterface& GetOrgInterface() { assert(m_interface); return *m_interface; }
+ void SetOrgInterface(cOrgInterface* interface);
+ const cGenome& GetGenome() const { return initial_genome; }
+
/*
int GetCurGestation() const;
*/
Modified: development/source/main/cPopulation.cc
===================================================================
--- development/source/main/cPopulation.cc 2006-03-03 16:53:20 UTC (rev 494)
+++ development/source/main/cPopulation.cc 2006-03-05 00:35:01 UTC (rev 495)
@@ -322,7 +322,7 @@
// First, setup the genotype of all of the offspring.
cGenotype * parent_genotype = parent_organism.GetGenotype();
- const int parent_id = parent_organism.PopInterface().GetCellID();
+ const int parent_id = parent_organism.GetOrgInterface().GetCellID();
assert(parent_id >= 0 && parent_id < cell_array.GetSize());
cPopulationCell & parent_cell = cell_array[ parent_id ];
@@ -395,7 +395,7 @@
cHardwareBase& parent_cpu = parent.GetHardware();
cInjectGenotype * parent_genotype = parent_cpu.GetCurThreadOwner();
- const int parent_id = parent.PopInterface().GetCellID();
+ const int parent_id = parent.GetOrgInterface().GetCellID();
assert(parent_id >= 0 && parent_id < cell_array.GetSize());
cPopulationCell & parent_cell = cell_array[ parent_id ];
@@ -455,6 +455,8 @@
assert(in_organism != NULL);
assert(in_organism->GetGenome().GetSize() > 1);
+ in_organism->SetOrgInterface(new cPopulationInterface(m_world));
+
// If the organism does not have a genotype, give it one! No parent
// information is provided so we must set parents to NULL.
if (in_organism->GetGenotype() == NULL) {
Modified: development/source/main/cPopulation.h
===================================================================
--- development/source/main/cPopulation.h 2006-03-03 16:53:20 UTC (rev 494)
+++ development/source/main/cPopulation.h 2006-03-05 00:35:01 UTC (rev 495)
@@ -16,6 +16,9 @@
#ifndef cBirthChamber_h
#include "cBirthChamber.h"
#endif
+#ifndef cOrgInterface_h
+#include "cOrgInterface.h"
+#endif
#ifndef cPopulationInterface_h
#include "cPopulationInterface.h"
#endif
Modified: development/source/main/cPopulationCell.cc
===================================================================
--- development/source/main/cPopulationCell.cc 2006-03-03 16:53:20 UTC (rev 494)
+++ development/source/main/cPopulationCell.cc 2006-03-05 00:35:01 UTC (rev 495)
@@ -114,7 +114,7 @@
organism_count++;
// Adjust the organism's attributes to match this cell.
- organism->PopInterface().SetCellID(cell_id);
+ organism->GetOrgInterface().SetCellID(cell_id);
}
cOrganism * cPopulationCell::RemoveOrganism()
Modified: development/source/main/cPopulationInterface.cc
===================================================================
--- development/source/main/cPopulationInterface.cc 2006-03-03 16:53:20 UTC (rev 494)
+++ development/source/main/cPopulationInterface.cc 2006-03-05 00:35:01 UTC (rev 495)
@@ -26,28 +26,15 @@
#endif
-cHardwareBase* cPopulationInterface::NewHardware(cOrganism * owner)
-{
- return m_world->GetHardwareManager().Create(owner);
-}
-
bool cPopulationInterface::Divide(cOrganism * parent, cGenome & child_genome)
{
- if (InTestPop()) {
- parent->GetPhenotype().TestDivideReset(parent->GetGenome().GetSize());
- // @CAO in the future, we probably want to pass this child the test_cpu!
- return true;
- } else {
- assert(parent != NULL);
- assert(m_world->GetPopulation().GetCell(cell_id).GetOrganism() == parent);
- return m_world->GetPopulation().ActivateOffspring(child_genome, *parent);
- }
+ assert(parent != NULL);
+ assert(m_world->GetPopulation().GetCell(cell_id).GetOrganism() == parent);
+ return m_world->GetPopulation().ActivateOffspring(child_genome, *parent);
}
cOrganism * cPopulationInterface::GetNeighbor()
{
- if (InTestPop()) return NULL;
-
cPopulationCell & cell = m_world->GetPopulation().GetCell(cell_id);
assert(cell.IsOccupied());
@@ -56,7 +43,6 @@
int cPopulationInterface::GetNumNeighbors()
{
- if (InTestPop()) return 0;
cPopulationCell & cell = m_world->GetPopulation().GetCell(cell_id);
assert(cell.IsOccupied());
@@ -65,8 +51,6 @@
void cPopulationInterface::Rotate(int direction)
{
- if (InTestPop()) return;
-
cPopulationCell & cell = m_world->GetPopulation().GetCell(cell_id);
assert(cell.IsOccupied());
@@ -76,8 +60,6 @@
double cPopulationInterface::TestFitness()
{
- if (InTestPop()) return -1.0;
-
cPopulationCell & cell = m_world->GetPopulation().GetCell(cell_id);
assert(cell.IsOccupied());
@@ -86,8 +68,6 @@
int cPopulationInterface::GetInput()
{
- if (InTestPop()) return m_world->GetTestCPU().GetInput();
-
cPopulationCell & cell = m_world->GetPopulation().GetCell(cell_id);
assert(cell.IsOccupied());
return cell.GetInput();
@@ -95,8 +75,6 @@
int cPopulationInterface::GetInputAt(int& input_pointer)
{
- if (InTestPop()) return m_world->GetTestCPU().GetInputAt(input_pointer);
-
cPopulationCell& cell = m_world->GetPopulation().GetCell(cell_id);
assert(cell.IsOccupied());
return cell.GetInputAt(input_pointer);
@@ -104,8 +82,6 @@
int cPopulationInterface::Debug()
{
- if (InTestPop()) return -1;
-
cPopulationCell & cell = m_world->GetPopulation().GetCell(cell_id);
assert(cell.IsOccupied());
return cell.GetOrganism()->GetGenotype()->GetID();
@@ -113,36 +89,28 @@
const tArray<double> & cPopulationInterface::GetResources()
{
- if (InTestPop()) return m_world->GetTestCPU().GetResources();
return m_world->GetPopulation().GetCellResources(cell_id);
}
void cPopulationInterface::UpdateResources(const tArray<double> & res_change)
{
- if (InTestPop()) return;
return m_world->GetPopulation().UpdateCellResources(res_change, cell_id);
}
void cPopulationInterface::Die()
{
- if (InTestPop()) return;
-
cPopulationCell & cell = m_world->GetPopulation().GetCell(cell_id);
m_world->GetPopulation().KillOrganism(cell);
}
void cPopulationInterface::Kaboom()
{
- if (InTestPop()) return;
-
cPopulationCell & cell = m_world->GetPopulation().GetCell(cell_id);
m_world->GetPopulation().Kaboom(cell);
}
bool cPopulationInterface::SendMessage(cOrgMessage & mess)
{
- if (InTestPop()) return false;
-
mess.SetSenderID(cell_id);
mess.SetTime(m_world->GetStats().GetUpdate());
cPopulationCell& cell = m_world->GetPopulation().GetCell(cell_id);
@@ -154,8 +122,6 @@
int cPopulationInterface::ReceiveValue()
{
- if (InTestPop()) return m_world->GetTestCPU().GetReceiveValue();
-
cPopulationCell & cell = m_world->GetPopulation().GetCell(cell_id);
assert(cell.IsOccupied());
@@ -177,8 +143,6 @@
bool cPopulationInterface::InjectParasite(cOrganism * parent, const cGenome & injected_code)
{
- if (InTestPop()) return false;
-
assert(parent != NULL);
assert(m_world->GetPopulation().GetCell(cell_id).GetOrganism() == parent);
@@ -187,7 +151,6 @@
bool cPopulationInterface::UpdateMerit(double new_merit)
{
- if (InTestPop()) return false;
return m_world->GetPopulation().UpdateMerit(cell_id, new_merit);
}
Modified: development/source/main/cPopulationInterface.h
===================================================================
--- development/source/main/cPopulationInterface.h 2006-03-03 16:53:20 UTC (rev 494)
+++ development/source/main/cPopulationInterface.h 2006-03-05 00:35:01 UTC (rev 495)
@@ -11,6 +11,9 @@
#ifndef cPopulationInterface_h
#define cPopulationInterface_h
+#ifndef cOrgInterface_h
+#include "cOrgInterface.h"
+#endif
#ifndef cWorld_h
#include "cWorld.h"
#endif
@@ -18,19 +21,17 @@
#include "cWorldDriver.h"
#endif
-class cHardwareBase;
class cPopulation;
class cOrganism;
class cGenome;
template <class T> class tArray;
class cOrgMessage;
-class cPopulationInterface {
+class cPopulationInterface : public cOrgInterface {
private:
cWorld* m_world;
int cell_id;
-
cPopulationInterface(); // @not_implemented
cPopulationInterface(const cPopulationInterface&); // @not_implemented
cPopulationInterface operator=(const cPopulationInterface&); // @not_implemented
@@ -42,27 +43,22 @@
int GetCellID() { return cell_id; }
void SetCellID(int in_id) { cell_id = in_id; }
- bool InTestPop() { return (cell_id == -1); }
-
- // Activate callbacks...
- cHardwareBase* NewHardware(cOrganism * owner);
- bool Divide(cOrganism * parent, cGenome & child_genome);
- bool TestOnDivide() const { return m_world->GetTestOnDivide(); }
- cOrganism * GetNeighbor();
+ bool Divide(cOrganism* parent, cGenome& child_genome);
+ cOrganism* GetNeighbor();
int GetNumNeighbors();
- void Rotate(int direction=1);
+ void Rotate(int direction = 1);
void Breakpoint() { m_world->GetDriver().SignalBreakpoint(); }
double TestFitness();
int GetInput();
- int GetInputAt(int & input_pointer);
+ int GetInputAt(int& input_pointer);
int Debug();
- const tArray<double> & GetResources();
- void UpdateResources(const tArray<double> & res_change);
+ const tArray<double>& GetResources();
+ void UpdateResources(const tArray<double>& res_change);
void Die();
void Kaboom();
- bool SendMessage(cOrgMessage & mess);
+ bool SendMessage(cOrgMessage& mess);
int ReceiveValue();
- bool InjectParasite(cOrganism * parent, const cGenome & injected_code);
+ bool InjectParasite(cOrganism* parent, const cGenome& injected_code);
bool UpdateMerit(double new_merit);
};
More information about the Avida-cvs
mailing list