[Avida-cvs] [Avida2-svn] r331 - in trunk: Avida2.xcodeproj source/bindings/Boost.Python source/cpu source/event source/main source/testsuites/unit_testsuites source/viewers

brysonda@myxo.css.msu.edu brysonda at myxo.css.msu.edu
Wed Oct 5 16:58:32 PDT 2005


Author: brysonda
Date: 2005-10-05 19:40:31 -0400 (Wed, 05 Oct 2005)
New Revision: 331

Added:
   trunk/source/main/cOrgMessage.cc
   trunk/source/main/cOrgMessage.h
   trunk/source/main/cOrganism.cc
   trunk/source/main/cOrganism.h
   trunk/source/main/cPhenotype.cc
   trunk/source/main/cPhenotype.h
   trunk/source/main/cPopulation.cc
   trunk/source/main/cPopulation.h
   trunk/source/main/cPopulationCell.cc
   trunk/source/main/cPopulationCell.h
Removed:
   trunk/source/main/org_message.cc
   trunk/source/main/org_message.hh
   trunk/source/main/organism.cc
   trunk/source/main/organism.hh
   trunk/source/main/phenotype.cc
   trunk/source/main/phenotype.hh
   trunk/source/main/population.cc
   trunk/source/main/population.hh
   trunk/source/main/population_cell.cc
   trunk/source/main/population_cell.hh
Modified:
   trunk/Avida2.xcodeproj/project.pbxproj
   trunk/source/bindings/Boost.Python/analyze_util.pyste
   trunk/source/bindings/Boost.Python/avida_driver_population.pyste
   trunk/source/bindings/Boost.Python/birth_chamber.pyste
   trunk/source/bindings/Boost.Python/cpu_test_info.pyste
   trunk/source/bindings/Boost.Python/hardware_4stack.pyste
   trunk/source/bindings/Boost.Python/hardware_base.pyste
   trunk/source/bindings/Boost.Python/hardware_cpu.pyste
   trunk/source/bindings/Boost.Python/hardware_factory.pyste
   trunk/source/bindings/Boost.Python/hardware_status_printer.pyste
   trunk/source/bindings/Boost.Python/lineage_control.pyste
   trunk/source/bindings/Boost.Python/org_message.pyste
   trunk/source/bindings/Boost.Python/organism.pyste
   trunk/source/bindings/Boost.Python/phenotype.pyste
   trunk/source/bindings/Boost.Python/population.pyste
   trunk/source/bindings/Boost.Python/population_cell.pyste
   trunk/source/bindings/Boost.Python/population_event_factory.pyste
   trunk/source/bindings/Boost.Python/population_interface.pyste
   trunk/source/bindings/Boost.Python/py_avida_driver-fixups.cc
   trunk/source/bindings/Boost.Python/tArray.pyste
   trunk/source/bindings/Boost.Python/tArray_instantiations.hh
   trunk/source/bindings/Boost.Python/tList_instantiations.hh
   trunk/source/cpu/cCPUTestInfo.cc
   trunk/source/cpu/cHardware4Stack.cc
   trunk/source/cpu/cHardwareCPU.cc
   trunk/source/cpu/cHardwareFactory.cc
   trunk/source/cpu/cHardwareSMT.cc
   trunk/source/cpu/cHardwareStatusPrinter.cc
   trunk/source/cpu/cTestCPU.cc
   trunk/source/cpu/cTestUtil.cc
   trunk/source/event/cPopulationEventFactory.cc
   trunk/source/main/CMakeLists.txt
   trunk/source/main/cAnalyze.cc
   trunk/source/main/cAnalyzeGenotype.cc
   trunk/source/main/cAnalyzeUtil.cc
   trunk/source/main/cAvidaDriver_Population.cc
   trunk/source/main/cBirthChamber.cc
   trunk/source/main/cCallbackUtil.cc
   trunk/source/main/cFitnessMatrix.h
   trunk/source/main/cGenotype.cc
   trunk/source/main/cLandscape.cc
   trunk/source/main/cLineageControl.cc
   trunk/source/main/cMxCodeArray.cc
   trunk/source/main/main_sub.pri
   trunk/source/main/primitive.cc
   trunk/source/testsuites/unit_testsuites/org_message.t.cc
   trunk/source/testsuites/unit_testsuites/organism.t.cc
   trunk/source/testsuites/unit_testsuites/phenotype.t.cc
   trunk/source/testsuites/unit_testsuites/population.t.cc
   trunk/source/testsuites/unit_testsuites/population_cell.t.cc
   trunk/source/viewers/bar_screen.cc
   trunk/source/viewers/environment_screen.cc
   trunk/source/viewers/map_screen.cc
   trunk/source/viewers/options_screen.cc
   trunk/source/viewers/stats_screen.cc
   trunk/source/viewers/symbol_util.cc
   trunk/source/viewers/text_screen.cc
   trunk/source/viewers/view.cc
   trunk/source/viewers/viewer.cc
   trunk/source/viewers/zoom_screen.cc
Log:
Rename main/o*, main/p*

Modified: trunk/Avida2.xcodeproj/project.pbxproj
===================================================================
--- trunk/Avida2.xcodeproj/project.pbxproj	2005-10-05 23:24:09 UTC (rev 330)
+++ trunk/Avida2.xcodeproj/project.pbxproj	2005-10-05 23:40:31 UTC (rev 331)
@@ -9,11 +9,6 @@
 /* Begin PBXBuildFile section */
 		700E2996085A1F6000CF158A /* primitive in CopyFiles */ = {isa = PBXBuildFile; fileRef = DCC3164D07626CF3008F7A48 /* primitive */; };
 		700E2AF8085DE50C00CF158A /* avida.cc in Sources */ = {isa = PBXBuildFile; fileRef = DCC3109C0762539E008F7A48 /* avida.cc */; };
-		700E2B19085DE50C00CF158A /* org_message.cc in Sources */ = {isa = PBXBuildFile; fileRef = DCC310FD0762539E008F7A48 /* org_message.cc */; };
-		700E2B1A085DE50C00CF158A /* organism.cc in Sources */ = {isa = PBXBuildFile; fileRef = DCC310FF0762539E008F7A48 /* organism.cc */; };
-		700E2B1B085DE50C00CF158A /* phenotype.cc in Sources */ = {isa = PBXBuildFile; fileRef = DCC311010762539E008F7A48 /* phenotype.cc */; };
-		700E2B1C085DE50C00CF158A /* population.cc in Sources */ = {isa = PBXBuildFile; fileRef = DCC311030762539E008F7A48 /* population.cc */; };
-		700E2B1E085DE50C00CF158A /* population_cell.cc in Sources */ = {isa = PBXBuildFile; fileRef = DCC311050762539E008F7A48 /* population_cell.cc */; };
 		700E2B1F085DE50C00CF158A /* reaction.cc in Sources */ = {isa = PBXBuildFile; fileRef = DCC3110B0762539E008F7A48 /* reaction.cc */; };
 		700E2B20085DE50C00CF158A /* reaction_lib.cc in Sources */ = {isa = PBXBuildFile; fileRef = DCC3110D0762539E008F7A48 /* reaction_lib.cc */; };
 		700E2B21085DE50C00CF158A /* reaction_process.cc in Sources */ = {isa = PBXBuildFile; fileRef = DCC311100762539E008F7A48 /* reaction_process.cc */; };
@@ -150,6 +145,16 @@
 		70B0866608F4974300FC65FE /* cMutationLib.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70B0865608F4974300FC65FE /* cMutationLib.cc */; };
 		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 */; };
+		70B0869008F49EA800FC65FE /* cOrgMessage.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70B0868808F49EA800FC65FE /* cOrgMessage.cc */; };
+		70B0869108F49EA800FC65FE /* cPopulation.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70B0868908F49EA800FC65FE /* cPopulation.cc */; };
+		70B0869208F49EA800FC65FE /* cPopulationCell.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70B0868A08F49EA800FC65FE /* cPopulationCell.cc */; };
+		70B0869D08F49F4800FC65FE /* cPhenotype.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70B0869C08F49F4800FC65FE /* cPhenotype.cc */; };
+		70B0869E08F49F4800FC65FE /* cPhenotype.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70B0869C08F49F4800FC65FE /* cPhenotype.cc */; };
 		70C1EF4808C393BA00F50912 /* cCodeLabel.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70C1EF4608C393BA00F50912 /* cCodeLabel.cc */; };
 		70C1EF4A08C393BA00F50912 /* cCodeLabel.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70C1EF4608C393BA00F50912 /* cCodeLabel.cc */; };
 		70C1EF5908C3948C00F50912 /* cCPUMemory.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70C1EF5808C3948C00F50912 /* cCPUMemory.cc */; };
@@ -233,11 +238,6 @@
 		70D46935085F61DD004C8409 /* trionan.c in Sources */ = {isa = PBXBuildFile; fileRef = DCC31471076253A1008F7A48 /* trionan.c */; };
 		70D46936085F61DF004C8409 /* triostr.c in Sources */ = {isa = PBXBuildFile; fileRef = DCC31474076253A1008F7A48 /* triostr.c */; };
 		DCC3166107628531008F7A48 /* avida.cc in Sources */ = {isa = PBXBuildFile; fileRef = DCC3109C0762539E008F7A48 /* avida.cc */; };
-		DCC316820762856F008F7A48 /* org_message.cc in Sources */ = {isa = PBXBuildFile; fileRef = DCC310FD0762539E008F7A48 /* org_message.cc */; };
-		DCC3168307628570008F7A48 /* organism.cc in Sources */ = {isa = PBXBuildFile; fileRef = DCC310FF0762539E008F7A48 /* organism.cc */; };
-		DCC3168407628571008F7A48 /* phenotype.cc in Sources */ = {isa = PBXBuildFile; fileRef = DCC311010762539E008F7A48 /* phenotype.cc */; };
-		DCC3168507628572008F7A48 /* population.cc in Sources */ = {isa = PBXBuildFile; fileRef = DCC311030762539E008F7A48 /* population.cc */; };
-		DCC3168707628574008F7A48 /* population_cell.cc in Sources */ = {isa = PBXBuildFile; fileRef = DCC311050762539E008F7A48 /* population_cell.cc */; };
 		DCC3168807628577008F7A48 /* reaction.cc in Sources */ = {isa = PBXBuildFile; fileRef = DCC3110B0762539E008F7A48 /* reaction.cc */; };
 		DCC3168907628578008F7A48 /* reaction_lib.cc in Sources */ = {isa = PBXBuildFile; fileRef = DCC3110D0762539E008F7A48 /* reaction_lib.cc */; };
 		DCC3168A0762857A008F7A48 /* reaction_process.cc in Sources */ = {isa = PBXBuildFile; fileRef = DCC311100762539E008F7A48 /* reaction_process.cc */; };
@@ -431,6 +431,16 @@
 		70B0865708F4974300FC65FE /* cMutationRates.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = cMutationRates.cc; sourceTree = "<group>"; };
 		70B0865808F4974300FC65FE /* cMxCodeArray.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = cMxCodeArray.cc; sourceTree = "<group>"; };
 		70B0867208F499C100FC65FE /* nMutation.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = nMutation.h; sourceTree = "<group>"; };
+		70B0868308F49E9700FC65FE /* cOrganism.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cOrganism.h; sourceTree = "<group>"; };
+		70B0868408F49E9700FC65FE /* cOrgMessage.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cOrgMessage.h; sourceTree = "<group>"; };
+		70B0868508F49E9700FC65FE /* cPopulation.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cPopulation.h; sourceTree = "<group>"; };
+		70B0868608F49E9700FC65FE /* cPopulationCell.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cPopulationCell.h; sourceTree = "<group>"; };
+		70B0868708F49EA800FC65FE /* cOrganism.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = cOrganism.cc; sourceTree = "<group>"; };
+		70B0868808F49EA800FC65FE /* cOrgMessage.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = cOrgMessage.cc; sourceTree = "<group>"; };
+		70B0868908F49EA800FC65FE /* cPopulation.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = cPopulation.cc; sourceTree = "<group>"; };
+		70B0868A08F49EA800FC65FE /* cPopulationCell.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = cPopulationCell.cc; sourceTree = "<group>"; };
+		70B0869B08F49F3900FC65FE /* cPhenotype.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cPhenotype.h; sourceTree = "<group>"; };
+		70B0869C08F49F4800FC65FE /* cPhenotype.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = cPhenotype.cc; sourceTree = "<group>"; };
 		70C1EF4608C393BA00F50912 /* cCodeLabel.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = cCodeLabel.cc; sourceTree = "<group>"; };
 		70C1EF4708C393BA00F50912 /* cCodeLabel.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cCodeLabel.h; sourceTree = "<group>"; };
 		70C1EF5808C3948C00F50912 /* cCPUMemory.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = cCPUMemory.cc; sourceTree = "<group>"; };
@@ -944,16 +954,6 @@
 		DCC310A90762539E008F7A48 /* CMakeLists.txt */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text; path = CMakeLists.txt; sourceTree = "<group>"; };
 		DCC310F00762539E008F7A48 /* main.pro */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text; path = main.pro; sourceTree = "<group>"; };
 		DCC310F10762539E008F7A48 /* main_sub.pri */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text; path = main_sub.pri; sourceTree = "<group>"; };
-		DCC310FD0762539E008F7A48 /* org_message.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = org_message.cc; sourceTree = "<group>"; };
-		DCC310FE0762539E008F7A48 /* org_message.hh */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.h; path = org_message.hh; sourceTree = "<group>"; };
-		DCC310FF0762539E008F7A48 /* organism.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = organism.cc; sourceTree = "<group>"; };
-		DCC311000762539E008F7A48 /* organism.hh */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.h; path = organism.hh; sourceTree = "<group>"; };
-		DCC311010762539E008F7A48 /* phenotype.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = phenotype.cc; sourceTree = "<group>"; };
-		DCC311020762539E008F7A48 /* phenotype.hh */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.h; path = phenotype.hh; sourceTree = "<group>"; };
-		DCC311030762539E008F7A48 /* population.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = population.cc; sourceTree = "<group>"; };
-		DCC311040762539E008F7A48 /* population.hh */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.h; path = population.hh; sourceTree = "<group>"; };
-		DCC311050762539E008F7A48 /* population_cell.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = population_cell.cc; sourceTree = "<group>"; };
-		DCC311060762539E008F7A48 /* population_cell.hh */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.h; path = population_cell.hh; sourceTree = "<group>"; };
 		DCC311090762539E008F7A48 /* primitive.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = primitive.cc; sourceTree = "<group>"; };
 		DCC3110A0762539E008F7A48 /* primitive.hh */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.h; path = primitive.hh; sourceTree = "<group>"; };
 		DCC3110B0762539E008F7A48 /* reaction.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = reaction.cc; sourceTree = "<group>"; };
@@ -2038,6 +2038,16 @@
 		DCC310040762539D008F7A48 /* main */ = {
 			isa = PBXGroup;
 			children = (
+				70B0869C08F49F4800FC65FE /* cPhenotype.cc */,
+				70B0869B08F49F3900FC65FE /* cPhenotype.h */,
+				70B0868708F49EA800FC65FE /* cOrganism.cc */,
+				70B0868808F49EA800FC65FE /* cOrgMessage.cc */,
+				70B0868908F49EA800FC65FE /* cPopulation.cc */,
+				70B0868A08F49EA800FC65FE /* cPopulationCell.cc */,
+				70B0868308F49E9700FC65FE /* cOrganism.h */,
+				70B0868408F49E9700FC65FE /* cOrgMessage.h */,
+				70B0868508F49E9700FC65FE /* cPopulation.h */,
+				70B0868608F49E9700FC65FE /* cPopulationCell.h */,
 				70B0867208F499C100FC65FE /* nMutation.h */,
 				70B0865108F4974300FC65FE /* cLandscape.cc */,
 				70B0865208F4974300FC65FE /* cLineage.cc */,
@@ -2128,16 +2138,6 @@
 				DCC310B00762539E008F7A48 /* functional_testsuites */,
 				DCC310F00762539E008F7A48 /* main.pro */,
 				DCC310F10762539E008F7A48 /* main_sub.pri */,
-				DCC310FD0762539E008F7A48 /* org_message.cc */,
-				DCC310FE0762539E008F7A48 /* org_message.hh */,
-				DCC310FF0762539E008F7A48 /* organism.cc */,
-				DCC311000762539E008F7A48 /* organism.hh */,
-				DCC311010762539E008F7A48 /* phenotype.cc */,
-				DCC311020762539E008F7A48 /* phenotype.hh */,
-				DCC311030762539E008F7A48 /* population.cc */,
-				DCC311040762539E008F7A48 /* population.hh */,
-				DCC311050762539E008F7A48 /* population_cell.cc */,
-				DCC311060762539E008F7A48 /* population_cell.hh */,
 				DCC311090762539E008F7A48 /* primitive.cc */,
 				DCC3110A0762539E008F7A48 /* primitive.hh */,
 				DCC3110B0762539E008F7A48 /* reaction.cc */,
@@ -3036,11 +3036,6 @@
 			buildActionMask = 2147483647;
 			files = (
 				700E2AF8085DE50C00CF158A /* avida.cc in Sources */,
-				700E2B19085DE50C00CF158A /* org_message.cc in Sources */,
-				700E2B1A085DE50C00CF158A /* organism.cc in Sources */,
-				700E2B1B085DE50C00CF158A /* phenotype.cc in Sources */,
-				700E2B1C085DE50C00CF158A /* population.cc in Sources */,
-				700E2B1E085DE50C00CF158A /* population_cell.cc in Sources */,
 				700E2B1F085DE50C00CF158A /* reaction.cc in Sources */,
 				700E2B20085DE50C00CF158A /* reaction_lib.cc in Sources */,
 				700E2B21085DE50C00CF158A /* reaction_process.cc in Sources */,
@@ -3166,6 +3161,11 @@
 				70B0866608F4974300FC65FE /* cMutationLib.cc in Sources */,
 				70B0866708F4974300FC65FE /* cMutationRates.cc in Sources */,
 				70B0866808F4974300FC65FE /* cMxCodeArray.cc in Sources */,
+				70B0868F08F49EA800FC65FE /* cOrganism.cc in Sources */,
+				70B0869008F49EA800FC65FE /* cOrgMessage.cc in Sources */,
+				70B0869108F49EA800FC65FE /* cPopulation.cc in Sources */,
+				70B0869208F49EA800FC65FE /* cPopulationCell.cc in Sources */,
+				70B0869E08F49F4800FC65FE /* cPhenotype.cc in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
@@ -3174,11 +3174,6 @@
 			buildActionMask = 2147483647;
 			files = (
 				DCC3166107628531008F7A48 /* avida.cc in Sources */,
-				DCC316820762856F008F7A48 /* org_message.cc in Sources */,
-				DCC3168307628570008F7A48 /* organism.cc in Sources */,
-				DCC3168407628571008F7A48 /* phenotype.cc in Sources */,
-				DCC3168507628572008F7A48 /* population.cc in Sources */,
-				DCC3168707628574008F7A48 /* population_cell.cc in Sources */,
 				DCC3168807628577008F7A48 /* reaction.cc in Sources */,
 				DCC3168907628578008F7A48 /* reaction_lib.cc in Sources */,
 				DCC3168A0762857A008F7A48 /* reaction_process.cc in Sources */,
@@ -3294,6 +3289,11 @@
 				70B0865E08F4974300FC65FE /* cMutationLib.cc in Sources */,
 				70B0865F08F4974300FC65FE /* cMutationRates.cc in Sources */,
 				70B0866008F4974300FC65FE /* cMxCodeArray.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 */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};

Modified: trunk/source/bindings/Boost.Python/analyze_util.pyste
===================================================================
--- trunk/source/bindings/Boost.Python/analyze_util.pyste	2005-10-05 23:24:09 UTC (rev 330)
+++ trunk/source/bindings/Boost.Python/analyze_util.pyste	2005-10-05 23:40:31 UTC (rev 331)
@@ -1,4 +1,4 @@
-Include("population.hh")
+Include("cPopulation.h")
 Include("cGenome.h")
 Include("cInstSet.h")
 

Modified: trunk/source/bindings/Boost.Python/avida_driver_population.pyste
===================================================================
--- trunk/source/bindings/Boost.Python/avida_driver_population.pyste	2005-10-05 23:24:09 UTC (rev 330)
+++ trunk/source/bindings/Boost.Python/avida_driver_population.pyste	2005-10-05 23:40:31 UTC (rev 331)
@@ -1,7 +1,7 @@
 
 Include("change_list.hh")
 Include("cEnvironment.h")
-Include("population.hh")
+Include("cPopulation.h")
 
 Import("avida_driver_base.pyste")
 

Modified: trunk/source/bindings/Boost.Python/birth_chamber.pyste
===================================================================
--- trunk/source/bindings/Boost.Python/birth_chamber.pyste	2005-10-05 23:24:09 UTC (rev 330)
+++ trunk/source/bindings/Boost.Python/birth_chamber.pyste	2005-10-05 23:40:31 UTC (rev 331)
@@ -1,5 +1,5 @@
 
-Include("organism.hh")
+Include("cOrganism.h")
 Include("cGenebank.h")
 
 cBirthChamber = Class("cBirthChamber", "cBirthChamber.h")

Modified: trunk/source/bindings/Boost.Python/cpu_test_info.pyste
===================================================================
--- trunk/source/bindings/Boost.Python/cpu_test_info.pyste	2005-10-05 23:24:09 UTC (rev 330)
+++ trunk/source/bindings/Boost.Python/cpu_test_info.pyste	2005-10-05 23:40:31 UTC (rev 331)
@@ -1,6 +1,6 @@
 
 Include("cHardwareTracer.h")
-Include("organism.hh")
+Include("cOrganism.h")
 
 cCPUTestInfo = Class("cCPUTestInfo", "cCPUTestInfo.h")
 # returns std::ofstream &, i.e., not the Python Way.

Modified: trunk/source/bindings/Boost.Python/hardware_4stack.pyste
===================================================================
--- trunk/source/bindings/Boost.Python/hardware_4stack.pyste	2005-10-05 23:24:09 UTC (rev 330)
+++ trunk/source/bindings/Boost.Python/hardware_4stack.pyste	2005-10-05 23:40:31 UTC (rev 331)
@@ -2,7 +2,7 @@
 Include("cMutation.h")
 Include("cInjectGenotype.h")
 Include("cInstSet.h")
-Include("organism.hh")
+Include("cOrganism.h")
 
 Import("hardware_base.pyste")
 

Modified: trunk/source/bindings/Boost.Python/hardware_base.pyste
===================================================================
--- trunk/source/bindings/Boost.Python/hardware_base.pyste	2005-10-05 23:24:09 UTC (rev 330)
+++ trunk/source/bindings/Boost.Python/hardware_base.pyste	2005-10-05 23:40:31 UTC (rev 331)
@@ -4,7 +4,7 @@
 Include("cGenome.h")
 Include("cHardwareTracer.h")
 Include("cInstSet.h")
-Include("organism.hh")
+Include("cOrganism.h")
 
 cHardwareBase = Class("cHardwareBase", "cHardwareBase.h")
 set_policy(cHardwareBase.GetOrganism, return_internal_reference())

Modified: trunk/source/bindings/Boost.Python/hardware_cpu.pyste
===================================================================
--- trunk/source/bindings/Boost.Python/hardware_cpu.pyste	2005-10-05 23:24:09 UTC (rev 330)
+++ trunk/source/bindings/Boost.Python/hardware_cpu.pyste	2005-10-05 23:40:31 UTC (rev 331)
@@ -2,7 +2,7 @@
 Include("cMutation.h")
 Include("cInstLibCPU.h")
 Include("cInstSet.h")
-Include("organism.hh")
+Include("cOrganism.h")
 
 Import("hardware_base.pyste")
 

Modified: trunk/source/bindings/Boost.Python/hardware_factory.pyste
===================================================================
--- trunk/source/bindings/Boost.Python/hardware_factory.pyste	2005-10-05 23:24:09 UTC (rev 330)
+++ trunk/source/bindings/Boost.Python/hardware_factory.pyste	2005-10-05 23:40:31 UTC (rev 331)
@@ -1,6 +1,6 @@
 
 Include("cHardwareBase.h")
-Include("organism.hh")
+Include("cOrganism.h")
 Include("cInstSet.h")
 
 cHardwareFactory = Class("cHardwareFactory", "cHardwareFactory.h")

Modified: trunk/source/bindings/Boost.Python/hardware_status_printer.pyste
===================================================================
--- trunk/source/bindings/Boost.Python/hardware_status_printer.pyste	2005-10-05 23:24:09 UTC (rev 330)
+++ trunk/source/bindings/Boost.Python/hardware_status_printer.pyste	2005-10-05 23:40:31 UTC (rev 331)
@@ -1,7 +1,7 @@
 
 Include("cHardwareCPU.h")
 Include("cHardware4Stack.h")
-Include("organism.hh")
+Include("cOrganism.h")
 
 Import("hardware_tracer.pyste")
 Import("hardware_tracer_cpu.pyste")

Modified: trunk/source/bindings/Boost.Python/lineage_control.pyste
===================================================================
--- trunk/source/bindings/Boost.Python/lineage_control.pyste	2005-10-05 23:24:09 UTC (rev 330)
+++ trunk/source/bindings/Boost.Python/lineage_control.pyste	2005-10-05 23:40:31 UTC (rev 331)
@@ -4,7 +4,7 @@
 Include("string.hh")
 Include("cGenotype.h")
 Include("cLineage.h")
-Include("organism.hh")
+Include("cOrganism.h")
 
 cLineageControl = Class("cLineageControl", "cLineageControl.h")
 set_policy(cLineageControl.AddCreature, return_internal_reference())

Modified: trunk/source/bindings/Boost.Python/org_message.pyste
===================================================================
--- trunk/source/bindings/Boost.Python/org_message.pyste	2005-10-05 23:24:09 UTC (rev 330)
+++ trunk/source/bindings/Boost.Python/org_message.pyste	2005-10-05 23:40:31 UTC (rev 331)
@@ -1,4 +1,4 @@
 
-cOrgMessage = Class("cOrgMessage", "org_message.hh")
+cOrgMessage = Class("cOrgMessage", "cOrgMessage.h")
 
 # vim: set ft=python:

Modified: trunk/source/bindings/Boost.Python/organism.pyste
===================================================================
--- trunk/source/bindings/Boost.Python/organism.pyste	2005-10-05 23:24:09 UTC (rev 330)
+++ trunk/source/bindings/Boost.Python/organism.pyste	2005-10-05 23:40:31 UTC (rev 331)
@@ -3,11 +3,11 @@
 Include("cInjectGenotype.h")
 Include("cHardwareBase.h")
 Include("cCodeLabel.h")
-Include("org_message.hh")
+Include("cOrgMessage.h")
 Include("cGenotype.h")
 Include("cLineage.h")
 
-cOrganism = Class("cOrganism", "organism.hh")
+cOrganism = Class("cOrganism", "cOrganism.h")
 set_policy(cOrganism.GetHardware, return_internal_reference())
 set_policy(cOrganism.GetNeighbor, return_internal_reference())
 set_policy(cOrganism.GetParasite, return_internal_reference())

Modified: trunk/source/bindings/Boost.Python/phenotype.pyste
===================================================================
--- trunk/source/bindings/Boost.Python/phenotype.pyste	2005-10-05 23:24:09 UTC (rev 330)
+++ trunk/source/bindings/Boost.Python/phenotype.pyste	2005-10-05 23:40:31 UTC (rev 331)
@@ -2,7 +2,7 @@
 Include("cEnvironment.h")
 Include("tBuffer.hh")
 
-cPhenotype = Class("cPhenotype", "phenotype.hh")
+cPhenotype = Class("cPhenotype", "cPhenotype.h")
 set_policy(cPhenotype.GetMerit, return_internal_reference())
 #set_policy(cPhenotype.IsInjected, return_internal_reference())
 #set_policy(cPhenotype.IsParasite, return_internal_reference())

Modified: trunk/source/bindings/Boost.Python/population.pyste
===================================================================
--- trunk/source/bindings/Boost.Python/population.pyste	2005-10-05 23:24:09 UTC (rev 330)
+++ trunk/source/bindings/Boost.Python/population.pyste	2005-10-05 23:40:31 UTC (rev 331)
@@ -4,10 +4,10 @@
 Include("cGenebank.h" )
 Include("cInjectGenebank.h")
 Include("cLineageControl.h")
-Include("organism.hh")
-Include("population_cell.hh")
+Include("cOrganism.h")
+Include("cPopulationCell.h")
 
-cPopulation = Class("cPopulation", "population.hh")
+cPopulation = Class("cPopulation", "cPopulation.h")
 
 set_policy(cPopulation.GetCell, return_internal_reference())
 set_policy(cPopulation.GetBirthChamber, return_internal_reference())

Modified: trunk/source/bindings/Boost.Python/population_cell.pyste
===================================================================
--- trunk/source/bindings/Boost.Python/population_cell.pyste	2005-10-05 23:24:09 UTC (rev 330)
+++ trunk/source/bindings/Boost.Python/population_cell.pyste	2005-10-05 23:40:31 UTC (rev 331)
@@ -1,7 +1,7 @@
 
-Include("organism.hh")
+Include("cOrganism.h")
 
-cPopulationCell = Class("cPopulationCell", "population_cell.hh")
+cPopulationCell = Class("cPopulationCell", "cPopulationCell.h")
 set_policy(cPopulationCell.GetOrganism, return_internal_reference())
 set_policy(cPopulationCell.ConnectionList, return_internal_reference())
 set_policy(cPopulationCell.MutationRates, return_internal_reference())

Modified: trunk/source/bindings/Boost.Python/population_event_factory.pyste
===================================================================
--- trunk/source/bindings/Boost.Python/population_event_factory.pyste	2005-10-05 23:24:09 UTC (rev 330)
+++ trunk/source/bindings/Boost.Python/population_event_factory.pyste	2005-10-05 23:40:31 UTC (rev 331)
@@ -3,7 +3,7 @@
 
 Include("cEvent.h")
 Include("string.hh")
-Include("population.hh")
+Include("cPopulation.h")
 
 cPopulationEventFactory = Class("cPopulationEventFactory", "cPopulationEventFactory.h")
 set_policy(cPopulationEventFactory.ConstructEvent, return_internal_reference())

Modified: trunk/source/bindings/Boost.Python/population_interface.pyste
===================================================================
--- trunk/source/bindings/Boost.Python/population_interface.pyste	2005-10-05 23:24:09 UTC (rev 330)
+++ trunk/source/bindings/Boost.Python/population_interface.pyste	2005-10-05 23:40:31 UTC (rev 331)
@@ -1,9 +1,9 @@
 
 Include("cGenome.h")
 Include("cHardwareBase.h")
-Include("organism.hh")
-Include("org_message.hh")
-Include("population.hh")
+Include("cOrganism.h")
+Include("cOrgMessage.h")
+Include("cPopulation.h")
 Include("tArray.hh")
 
 cPopulationInterface = Class("cPopulationInterface", "population_interface-fixups.hh")

Modified: trunk/source/bindings/Boost.Python/py_avida_driver-fixups.cc
===================================================================
--- trunk/source/bindings/Boost.Python/py_avida_driver-fixups.cc	2005-10-05 23:24:09 UTC (rev 330)
+++ trunk/source/bindings/Boost.Python/py_avida_driver-fixups.cc	2005-10-05 23:40:31 UTC (rev 331)
@@ -6,9 +6,9 @@
 #include "main/cConfig.h"
 #include "main/cGenebank.h"
 #include "main/cGenotype.h"
-#include "main/organism.hh"
-#include "main/population.hh"
-#include "main/population_cell.hh"
+#include "main/cOrganism.h"
+#include "main/cPopulation.h"
+#include "main/cPopulationCell.h"
 #include "tools/change_list.hh"
 #include "tools/string.hh"
 

Modified: trunk/source/bindings/Boost.Python/tArray.pyste
===================================================================
--- trunk/source/bindings/Boost.Python/tArray.pyste	2005-10-05 23:24:09 UTC (rev 330)
+++ trunk/source/bindings/Boost.Python/tArray.pyste	2005-10-05 23:40:31 UTC (rev 331)
@@ -76,7 +76,7 @@
 Import("mutation.pyste")
 Import("int_sum.pyste")
 
-Include("org_message.hh")
+Include("cOrgMessage.h")
 
 tArray = Template("tArray", "tArray_instantiations.hh")
 

Modified: trunk/source/bindings/Boost.Python/tArray_instantiations.hh
===================================================================
--- trunk/source/bindings/Boost.Python/tArray_instantiations.hh	2005-10-05 23:24:09 UTC (rev 330)
+++ trunk/source/bindings/Boost.Python/tArray_instantiations.hh	2005-10-05 23:40:31 UTC (rev 331)
@@ -1,4 +1,4 @@
-#include "organism.hh"
+#include "cOrganism.h"
 #include "merit.hh"
 #include "cMutation.h"
 #include "int_sum.hh"

Modified: trunk/source/bindings/Boost.Python/tList_instantiations.hh
===================================================================
--- trunk/source/bindings/Boost.Python/tList_instantiations.hh	2005-10-05 23:24:09 UTC (rev 330)
+++ trunk/source/bindings/Boost.Python/tList_instantiations.hh	2005-10-05 23:40:31 UTC (rev 331)
@@ -1,7 +1,7 @@
 #include "cAnalyzeCommand.h"
 #include "cAnalyzeGenotype.h"
 #include "cMutation.h"
-#include "population_cell.hh"
+#include "cPopulationCell.h"
 #include "reaction_process.hh"
 #include "reaction_requisite.hh"
 #include "reaction.hh"

Modified: trunk/source/cpu/cCPUTestInfo.cc
===================================================================
--- trunk/source/cpu/cCPUTestInfo.cc	2005-10-05 23:24:09 UTC (rev 330)
+++ trunk/source/cpu/cCPUTestInfo.cc	2005-10-05 23:40:31 UTC (rev 331)
@@ -8,8 +8,8 @@
 #include "cCPUTestInfo.h"
 
 #include "cHardwareStatusPrinter.h"
-#include "organism.hh"
-#include "phenotype.hh"
+#include "cOrganism.h"
+#include "cPhenotype.h"
 
 #include <assert.h>
 

Modified: trunk/source/cpu/cHardware4Stack.cc
===================================================================
--- trunk/source/cpu/cHardware4Stack.cc	2005-10-05 23:24:09 UTC (rev 330)
+++ trunk/source/cpu/cHardware4Stack.cc	2005-10-05 23:40:31 UTC (rev 331)
@@ -20,8 +20,8 @@
 #include "cMutation.h"
 #include "cMutationLib.h"
 #include "nMutation.h"
-#include "organism.hh"
-#include "phenotype.hh"
+#include "cOrganism.h"
+#include "cPhenotype.h"
 #include "random.hh"
 #include "string_util.hh"
 #include "cTestCPU.h"

Modified: trunk/source/cpu/cHardwareCPU.cc
===================================================================
--- trunk/source/cpu/cHardwareCPU.cc	2005-10-05 23:24:09 UTC (rev 330)
+++ trunk/source/cpu/cHardwareCPU.cc	2005-10-05 23:40:31 UTC (rev 331)
@@ -19,8 +19,8 @@
 #include "cMutation.h"
 #include "cMutationLib.h"
 #include "nMutation.h"
-#include "organism.hh"
-#include "phenotype.hh"
+#include "cOrganism.h"
+#include "cPhenotype.h"
 #include "string_util.hh"
 #include "cTestCPU.h"
 

Modified: trunk/source/cpu/cHardwareFactory.cc
===================================================================
--- trunk/source/cpu/cHardwareFactory.cc	2005-10-05 23:24:09 UTC (rev 330)
+++ trunk/source/cpu/cHardwareFactory.cc	2005-10-05 23:40:31 UTC (rev 331)
@@ -12,7 +12,7 @@
 #include "cHardware4Stack.h"
 #include "cHardwareSMT.h"
 #include "cInstSet.h"
-#include "organism.hh"
+#include "cOrganism.h"
 
 using namespace std;
 

Modified: trunk/source/cpu/cHardwareSMT.cc
===================================================================
--- trunk/source/cpu/cHardwareSMT.cc	2005-10-05 23:24:09 UTC (rev 330)
+++ trunk/source/cpu/cHardwareSMT.cc	2005-10-05 23:40:31 UTC (rev 331)
@@ -20,8 +20,8 @@
 #include "cMutation.h"
 #include "cMutationLib.h"
 #include "nMutation.h"
-#include "organism.hh"
-#include "phenotype.hh"
+#include "cOrganism.h"
+#include "cPhenotype.h"
 #include "random.hh"
 #include "string_util.hh"
 #include "cTestCPU.h"

Modified: trunk/source/cpu/cHardwareStatusPrinter.cc
===================================================================
--- trunk/source/cpu/cHardwareStatusPrinter.cc	2005-10-05 23:24:09 UTC (rev 330)
+++ trunk/source/cpu/cHardwareStatusPrinter.cc	2005-10-05 23:40:31 UTC (rev 331)
@@ -12,7 +12,7 @@
 #include "cHardwareSMT.h"
 #include "cHardwareStatusPrinter.h"
 #include "cInstSet.h"
-#include "organism.hh"
+#include "cOrganism.h"
 #include "string.hh"
 #include "string_util.hh"
 

Modified: trunk/source/cpu/cTestCPU.cc
===================================================================
--- trunk/source/cpu/cTestCPU.cc	2005-10-05 23:24:09 UTC (rev 330)
+++ trunk/source/cpu/cTestCPU.cc	2005-10-05 23:40:31 UTC (rev 331)
@@ -15,8 +15,8 @@
 #include "cHardwareStatusPrinter.h"
 #include "cInstSet.h"
 #include "cInstUtil.h"
-#include "organism.hh"
-#include "phenotype.hh"
+#include "cOrganism.h"
+#include "cPhenotype.h"
 #include "cPopulationInterface.h"
 #include "resource_count.hh"
 #include "resource_lib.hh"

Modified: trunk/source/cpu/cTestUtil.cc
===================================================================
--- trunk/source/cpu/cTestUtil.cc	2005-10-05 23:24:09 UTC (rev 330)
+++ trunk/source/cpu/cTestUtil.cc	2005-10-05 23:40:31 UTC (rev 331)
@@ -14,8 +14,8 @@
 #include "cHardwareBase.h"
 #include "cInjectGenotype.h"
 #include "cInstUtil.h"
-#include "organism.hh"
-#include "phenotype.hh"
+#include "cOrganism.h"
+#include "cPhenotype.h"
 #include "stats.hh"
 #include "task_entry.hh"
 #include "cTestCPU.h"

Modified: trunk/source/event/cPopulationEventFactory.cc
===================================================================
--- trunk/source/event/cPopulationEventFactory.cc	2005-10-05 23:24:09 UTC (rev 330)
+++ trunk/source/event/cPopulationEventFactory.cc	2005-10-05 23:40:31 UTC (rev 331)
@@ -49,16 +49,16 @@
 #include "cLineageControl.h"
 #endif
 #ifndef ORGANISM_HH
-#include "organism.hh"
+#include "cOrganism.h"
 #endif
 #ifndef PHENOTYPE_HH
-#include "phenotype.hh"
+#include "cPhenotype.h"
 #endif
 #ifndef POPULATION_HH
-#include "population.hh"
+#include "cPopulation.h"
 #endif
 #ifndef POPULATION_CELL_HH
-#include "population_cell.hh"
+#include "cPopulationCell.h"
 #endif
 #ifndef POPULATION_EVENT_HH
 #include "cPopulationEvent.h"

Modified: trunk/source/main/CMakeLists.txt
===================================================================
--- trunk/source/main/CMakeLists.txt	2005-10-05 23:24:09 UTC (rev 330)
+++ trunk/source/main/CMakeLists.txt	2005-10-05 23:40:31 UTC (rev 331)
@@ -36,11 +36,11 @@
   cMutationRates.cc
   cMutation.cc
   cMxCodeArray.cc
-  org_message.cc
-  organism.cc
-  phenotype.cc
-  population.cc
-  population_cell.cc
+  cOrgMessage.cc
+  cOrganism.cc
+  cPhenotype.cc
+  cPopulation.cc
+  cPopulationCell.cc
   cPopulationInterface.cc
   reaction.cc
   reaction_lib.cc

Modified: trunk/source/main/cAnalyze.cc
===================================================================
--- trunk/source/main/cAnalyze.cc	2005-10-05 23:24:09 UTC (rev 330)
+++ trunk/source/main/cAnalyze.cc	2005-10-05 23:40:31 UTC (rev 331)
@@ -33,7 +33,7 @@
 #include "cInstSet.h"
 #include "cInstUtil.h"
 #include "cLandscape.h"
-#include "phenotype.hh"
+#include "cPhenotype.h"
 #include "species.hh"
 #include "tArgDataEntry.hh"
 #include "task_entry.hh"

Modified: trunk/source/main/cAnalyzeGenotype.cc
===================================================================
--- trunk/source/main/cAnalyzeGenotype.cc	2005-10-05 23:24:09 UTC (rev 330)
+++ trunk/source/main/cAnalyzeGenotype.cc	2005-10-05 23:40:31 UTC (rev 331)
@@ -11,8 +11,8 @@
 #include "cCPUTestInfo.h"
 #include "cInstSet.h"
 #include "cLandscape.h"
-#include "organism.hh"
-#include "phenotype.hh"
+#include "cOrganism.h"
+#include "cPhenotype.h"
 #include "cTestCPU.h"
 #include "cEnvironment.h"
 using namespace std;

Modified: trunk/source/main/cAnalyzeUtil.cc
===================================================================
--- trunk/source/main/cAnalyzeUtil.cc	2005-10-05 23:24:09 UTC (rev 330)
+++ trunk/source/main/cAnalyzeUtil.cc	2005-10-05 23:40:31 UTC (rev 331)
@@ -46,16 +46,16 @@
 #include "cLandscape.h"
 #endif
 #ifndef ORGANISM_HH
-#include "organism.hh"
+#include "cOrganism.h"
 #endif
 #ifndef PHENOTYPE_HH
-#include "phenotype.hh"
+#include "cPhenotype.h"
 #endif
 #ifndef POPULATION_HH
-#include "population.hh"
+#include "cPopulation.h"
 #endif
 #ifndef POPULATION_CELL_HH
-#include "population_cell.hh"
+#include "cPopulationCell.h"
 #endif
 #ifndef SPECIES_HH
 #include "species.hh"

Modified: trunk/source/main/cAvidaDriver_Population.cc
===================================================================
--- trunk/source/main/cAvidaDriver_Population.cc	2005-10-05 23:24:09 UTC (rev 330)
+++ trunk/source/main/cAvidaDriver_Population.cc	2005-10-05 23:40:31 UTC (rev 331)
@@ -18,9 +18,9 @@
 #include "cHardwareBase.h"
 #include "cHardwareFactory.h"
 #include "init_file.hh"
-#include "organism.hh"
-#include "population.hh"
-#include "population_cell.hh"
+#include "cOrganism.h"
+#include "cPopulation.h"
+#include "cPopulationCell.h"
 #include "cPopulationEventFactory.h"
 #include "cPopulationInterface.h"
 #include "string.hh"

Modified: trunk/source/main/cBirthChamber.cc
===================================================================
--- trunk/source/main/cBirthChamber.cc	2005-10-05 23:24:09 UTC (rev 330)
+++ trunk/source/main/cBirthChamber.cc	2005-10-05 23:40:31 UTC (rev 331)
@@ -31,7 +31,7 @@
 #include "cGenotype.h"
 #endif
 #ifndef ORGANISM_HH
-#include "organism.hh"
+#include "cOrganism.h"
 #endif
 #ifndef TOOLS_HH
 #include "tools.hh"

Modified: trunk/source/main/cCallbackUtil.cc
===================================================================
--- trunk/source/main/cCallbackUtil.cc	2005-10-05 23:24:09 UTC (rev 330)
+++ trunk/source/main/cCallbackUtil.cc	2005-10-05 23:40:31 UTC (rev 331)
@@ -34,16 +34,16 @@
 #include "cHardwareFactory.h"
 #endif
 #ifndef ORG_MESSAGE_HH
-#include "org_message.hh"
+#include "cOrgMessage.h"
 #endif
 #ifndef ORGANISM_HH
-#include "organism.hh"
+#include "cOrganism.h"
 #endif
 #ifndef POPULATION_HH
-#include "population.hh"
+#include "cPopulation.h"
 #endif
 #ifndef POPULATION_CELL_HH
-#include "population_cell.hh"
+#include "cPopulationCell.h"
 #endif
 #ifndef POPULATION_INTERFACE_HH
 #include "cPopulationInterface.h"

Modified: trunk/source/main/cFitnessMatrix.h
===================================================================
--- trunk/source/main/cFitnessMatrix.h	2005-10-05 23:24:09 UTC (rev 330)
+++ trunk/source/main/cFitnessMatrix.h	2005-10-05 23:40:31 UTC (rev 331)
@@ -27,7 +27,7 @@
 #include "MyCodeArrayLessThan.h"
 #endif
 #ifndef ORGANISM_HH
-#include "organism.hh"
+#include "cOrganism.h"
 #endif
 #ifndef STATS_HH
 #include "stats.hh"

Modified: trunk/source/main/cGenotype.cc
===================================================================
--- trunk/source/main/cGenotype.cc	2005-10-05 23:24:09 UTC (rev 330)
+++ trunk/source/main/cGenotype.cc	2005-10-05 23:40:31 UTC (rev 331)
@@ -11,8 +11,8 @@
 #include "cCPUTestInfo.h"
 #include "cGenomeUtil.h"
 #include "merit.hh"
-#include "organism.hh"
-#include "phenotype.hh"
+#include "cOrganism.h"
+#include "cPhenotype.h"
 #include "cTestCPU.h"
 #include "tools.hh"
 

Modified: trunk/source/main/cLandscape.cc
===================================================================
--- trunk/source/main/cLandscape.cc	2005-10-05 23:24:09 UTC (rev 330)
+++ trunk/source/main/cLandscape.cc	2005-10-05 23:40:31 UTC (rev 331)
@@ -10,8 +10,8 @@
 #include "cCPUMemory.h"
 #include "cEnvironment.h"
 #include "cInstSet.h"
-#include "organism.hh"
-#include "phenotype.hh"
+#include "cOrganism.h"
+#include "cPhenotype.h"
 #include "stats.hh"             // For GetUpdate in outputs...
 #include "cTestCPU.h"
 #include "cTestUtil.h"

Modified: trunk/source/main/cLineageControl.cc
===================================================================
--- trunk/source/main/cLineageControl.cc	2005-10-05 23:24:09 UTC (rev 330)
+++ trunk/source/main/cLineageControl.cc	2005-10-05 23:40:31 UTC (rev 331)
@@ -14,7 +14,7 @@
 #include "cConfig.h"
 #include "cGenebank.h"
 #include "cGenotype.h"
-#include "organism.hh"
+#include "cOrganism.h"
 
 #include "nHardware.h"   // for macro nHardware::FITNESS_NEUTRAL_MAX
 

Modified: trunk/source/main/cMxCodeArray.cc
===================================================================
--- trunk/source/main/cMxCodeArray.cc	2005-10-05 23:24:09 UTC (rev 330)
+++ trunk/source/main/cMxCodeArray.cc	2005-10-05 23:40:31 UTC (rev 331)
@@ -25,7 +25,7 @@
 #include "MyCodeArrayLessThan.h"
 #endif
 #ifndef ORGANISM_HH
-#include "organism.hh"
+#include "cOrganism.h"
 #endif
 #ifndef TEST_CPU_HH
 #include "cTestCPU.h"

Copied: trunk/source/main/cOrgMessage.cc (from rev 329, trunk/source/main/org_message.cc)
===================================================================
--- trunk/source/main/org_message.cc	2005-10-04 02:37:32 UTC (rev 329)
+++ trunk/source/main/cOrgMessage.cc	2005-10-05 23:40:31 UTC (rev 331)
@@ -0,0 +1,27 @@
+#include "cOrgMessage.h"
+#include <string>
+#include <sstream>
+
+void cOrgMessage::SetData(int in_data)
+{
+  std::stringstream ss;
+  ss << in_data;
+  ss >> data;
+}
+
+void cOrgMessage::SetData(double in_data)
+{
+  std::stringstream ss;
+  ss << in_data;
+  ss >> data;
+}
+
+void cOrgMessage::GetData(int & in_data)
+{
+  in_data=atoi(data.c_str());
+}
+
+void cOrgMessage::GetData(double & in_data)
+{
+  in_data=atof(data.c_str());
+}

Copied: trunk/source/main/cOrgMessage.h (from rev 329, trunk/source/main/org_message.hh)

Copied: trunk/source/main/cOrganism.cc (from rev 329, trunk/source/main/organism.cc)
===================================================================
--- trunk/source/main/organism.cc	2005-10-04 02:37:32 UTC (rev 329)
+++ trunk/source/main/cOrganism.cc	2005-10-05 23:40:31 UTC (rev 331)
@@ -0,0 +1,410 @@
+//////////////////////////////////////////////////////////////////////////////
+// Copyright (C) 1993 - 2003 California Institute of Technology             //
+//                                                                          //
+// Read the COPYING and README files, or contact 'avida at alife.org',         //
+// before continuing.  SOME RESTRICTIONS MAY APPLY TO USE OF THIS FILE.     //
+//////////////////////////////////////////////////////////////////////////////
+
+#include "cOrganism.h"
+
+#include "cConfig.h"
+#include "nHardware.h"
+#include "cEnvironment.h"
+#include "functions.hh"
+#include "cGenome.h"
+#include "cGenomeUtil.h"
+#include "cHardwareBase.h"
+#include "cInjectGenotype.h"
+#include "cInstSet.h"
+#include "cInstUtil.h"
+#include "cOrgMessage.h"
+#include "string_util.hh"
+#include "tArray.hh"
+#include "tools.hh"
+#include "tList.hh"
+
+#include <iomanip>
+
+using namespace std;
+
+///////////////
+//  cOrganism
+///////////////
+
+int cOrganism::instance_count(0);
+
+
+cOrganism::cOrganism(const cGenome & in_genome,
+		     const cPopulationInterface & in_interface,
+		     const cEnvironment & in_environment)
+  : genotype(NULL)
+  , phenotype(in_environment)
+  , initial_genome(in_genome)
+  , mut_info(in_environment.GetMutationLib(), in_genome.GetSize())
+  , pop_interface(in_interface)
+  , input_pointer(0)
+  , input_buf(INPUT_BUF_SIZE)
+  , output_buf(OUTPUT_BUF_SIZE)
+  , send_buf(SEND_BUF_SIZE)
+  , receive_buf(RECEIVE_BUF_SIZE)
+  , sent_value(0)
+  , sent_active(false)
+  , test_receive_pos(0)
+  , max_executed(-1)
+  , lineage_label(-1)
+  , lineage(NULL)
+  , inbox(0)
+  , sent(0)
+  , is_running(false)
+{
+  // Initialization of structures...
+  hardware = pop_interface.NewHardware(this);
+  cpu_stats.Setup(hardware->GetNumInst());
+  instance_count++;
+  pop_interface.SetCellID(-1);  // No cell at the moment...
+
+  if (cConfig::GetDeathMethod() > 0) {
+    max_executed = cConfig::GetAgeLimit();
+    if (cConfig::GetAgeDeviation() > 0.0) {
+      max_executed +=
+	(int) (g_random.GetRandNormal() * cConfig::GetAgeDeviation());
+    }
+    if (cConfig::GetDeathMethod() == DEATH_METHOD_MULTIPLE) {
+      max_executed *= initial_genome.GetSize();
+    }
+
+    // max_executed must be positive or an organism will not die!
+    if (max_executed < 1) max_executed = 1;
+  }
+}
+
+
+cOrganism::~cOrganism()
+{
+  assert(is_running == false);
+  pop_interface.RecycleHardware(hardware);
+  instance_count--;
+}
+
+
+double cOrganism::GetTestFitness()
+{
+  return pop_interface.TestFitness();
+}
+  
+int cOrganism::ReceiveValue()
+{
+  const int out_value = pop_interface.ReceiveValue();
+  receive_buf.Add(out_value);
+  return out_value;
+}
+
+
+void cOrganism::DoInput(const int value)
+{
+  input_buf.Add(value);
+  phenotype.TestInput(input_buf, output_buf);
+}
+
+void cOrganism::DoOutput(const int value)
+{
+  const tArray<double> & resource_count = pop_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 (phenotype.GetEnvironment().GetTaskLib().UseNeighborInput() == true) {
+    const int num_neighbors = pop_interface.GetNumNeighbors();
+    for (int i = 0; i < num_neighbors; i++) {
+      pop_interface.Rotate();
+      cOrganism * cur_neighbor = pop_interface.GetNeighbor();
+      if (cur_neighbor == NULL) continue;
+
+      other_input_list.Push( &(cur_neighbor->input_buf) );
+    }
+  }
+
+  // If tasks require us to consider neighbor outputs, collect them...
+  if (phenotype.GetEnvironment().GetTaskLib().UseNeighborOutput() == true) {
+    const int num_neighbors = pop_interface.GetNumNeighbors();
+    for (int i = 0; i < num_neighbors; i++) {
+      pop_interface.Rotate();
+      cOrganism * cur_neighbor = pop_interface.GetNeighbor();
+      if (cur_neighbor == NULL) continue;
+
+      other_output_list.Push( &(cur_neighbor->output_buf) );
+    }
+  }
+
+  // Do the testing of tasks performed...
+  output_buf.Add(value);
+  tArray<double> res_change(resource_count.GetSize());
+  tArray<int> insts_triggered;
+  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);
+
+  for (int i = 0; i < insts_triggered.GetSize(); i++) {
+    const int cur_inst = insts_triggered[i];
+    hardware->ProcessBonusInst( cInstruction(cur_inst) );
+  }
+}
+
+void cOrganism::SendMessage(cOrgMessage & mess)
+{
+  if(pop_interface.SendMessage(mess))
+    sent.Add(mess);
+  else
+    {
+      //perhaps some kind of message error buffer?
+    }
+}
+
+bool cOrganism::ReceiveMessage(cOrgMessage & mess)
+{
+  inbox.Add(mess);
+  return true;
+}
+
+bool cOrganism::InjectParasite(const cGenome & injected_code)
+{
+  return pop_interface.InjectParasite(this, injected_code);
+}
+
+bool cOrganism::InjectHost(const cCodeLabel & label, const cGenome & injected_code)
+{
+  return hardware->InjectHost(label, injected_code);
+}
+
+void cOrganism::AddParasite(cInjectGenotype * in_genotype)
+{
+  parasites.push_back(in_genotype);
+}
+
+cInjectGenotype & cOrganism::GetParasite(int x)
+{
+  return *parasites[x];
+}
+
+int cOrganism::GetNumParasites()
+{
+  return parasites.size();
+}
+
+void cOrganism::ClearParasites()
+{
+  parasites.clear();
+}
+
+int cOrganism::OK()
+{
+  if (!hardware->OK()) return false;
+  if (!phenotype.OK()) return false;
+
+  return true;
+}
+
+
+double cOrganism::CalcMeritRatio()
+{
+  const double age = (double) phenotype.GetAge();
+  const double merit = phenotype.GetMerit().GetDouble();
+  return (merit > 0.0) ? (age / merit ) : age;
+}
+
+
+bool cOrganism::GetTestOnDivide() const { return pop_interface.TestOnDivide();}
+bool cOrganism::GetFailImplicit() const { return cConfig::GetFailImplicit(); }
+
+bool cOrganism::GetRevertFatal() const { return cConfig::GetRevertFatal(); }
+bool cOrganism::GetRevertNeg()   const { return cConfig::GetRevertNeg(); }
+bool cOrganism::GetRevertNeut()  const { return cConfig::GetRevertNeut(); }
+bool cOrganism::GetRevertPos()   const { return cConfig::GetRevertPos(); }
+
+bool cOrganism::GetSterilizeFatal() const{return cConfig::GetSterilizeFatal();}
+bool cOrganism::GetSterilizeNeg()  const { return cConfig::GetSterilizeNeg(); }
+bool cOrganism::GetSterilizeNeut() const { return cConfig::GetSterilizeNeut();}
+bool cOrganism::GetSterilizePos()  const { return cConfig::GetSterilizePos(); }
+
+
+void cOrganism::PrintStatus(ostream & fp, const cString & next_name)
+{
+  fp << "---------------------------" << endl;
+  hardware->PrintStatus(fp);
+  phenotype.PrintStatus(fp);
+  fp << "---------------------------" << endl;
+  fp << "ABOUT TO EXECUTE: " << next_name << endl;
+}
+
+
+bool cOrganism::Divide_CheckViable()
+{
+  // Make sure required task (if any) has been performed...
+  const int required_task = cConfig::GetRequiredTask();
+  const int immunity_task = cConfig::GetImmunityTask();
+//cout << "req=" << required_task << "," <<phenotype.GetCurTaskCount()[required_task]<< " "; 
+//cout << "im=" << immunity_task << "," <<phenotype.GetCurTaskCount()[immunity_task]<< endl; 
+  if (required_task != -1 &&
+      phenotype.GetCurTaskCount()[required_task] == 0) { 
+    if (immunity_task==-1 || 
+	phenotype.GetCurTaskCount()[immunity_task] == 0) {
+      Fault(FAULT_LOC_DIVIDE, FAULT_TYPE_ERROR,
+	    cStringUtil::Stringf("Lacks required task (%d)",
+			         cConfig::GetRequiredTask()));
+      return false; //  (divide fails)
+    } 
+  }
+
+  const int required_reaction = cConfig::GetRequiredReaction();
+  if (required_reaction != -1 &&
+      phenotype.GetCurTaskCount()[required_reaction] == 0) {
+    Fault(FAULT_LOC_DIVIDE, FAULT_TYPE_ERROR,
+	  cStringUtil::Stringf("Lacks required reaction (%d)",
+			       cConfig::GetRequiredReaction()));
+    return false; //  (divide fails)
+  }
+
+  // Make sure the parent is fertile
+  if ( phenotype.IsFertile() == false ) {
+    Fault(FAULT_LOC_DIVIDE, FAULT_TYPE_ERROR, "Infertile organism");
+    return false; //  (divide fails)
+  }
+
+  return true;  // Organism has no problem with divide...
+}
+
+
+// This gets called after a successful divide to deal with the child. 
+// Returns true if parent lives through this process.
+
+bool cOrganism::ActivateDivide()
+{
+  // Activate the child!  (Keep Last: may kill this organism!)
+  return pop_interface.Divide(this, child_genome);
+}
+
+
+void cOrganism::Fault(int fault_loc, int fault_type, cString fault_desc)
+{
+  (void) fault_loc;
+  (void) fault_type;
+  (void) fault_desc;
+
+#ifdef FATAL_ERRORS
+  if (fault_type == FAULT_TYPE_ERROR) {
+    phenotype.IsFertile() = false;
+  }
+#endif
+
+#ifdef FATAL_WARNINGS
+  if (fault_type == FAULT_TYPE_WARNING) {
+    phenotype.IsFertile() = false;
+  }
+#endif
+
+#ifdef BREAKPOINTS
+  phenotype.SetFault(fault_desc);
+#endif
+
+  phenotype.IncErrors();
+}
+
+
+//// Save and Load ////
+void cOrganism::SaveState(ofstream & fp)
+{
+  assert(fp.good());
+
+  fp <<"cOrganism"<<endl;
+
+  //// Save If it is alive ////
+  if( genotype == NULL ){
+    fp <<false<<endl;
+  }
+  else{  // if there is a genotype here (ie. not dead)
+    fp <<true<<endl;
+
+    fp << input_pointer;
+
+    // IO buffers
+    input_buf.SaveState(fp);
+    output_buf.SaveState(fp);
+
+    //// Save Genotype Genome ////
+//    fp << genotype->GetLength() << endl;
+    
+//      cInstUtil::SaveInternalGenome(fp, hardware->GetInstSet(),
+//  				  genotype->GetGenome());
+
+    //// Save Actual Creature Memory & MemFlags ////
+//   fp <<hardware->GetMemory().GetSize()<<endl;
+//   cInstUtil::PrintGenome(hardware->GetInstSet(), hardware->GetMemory(), fp);
+//      fp <<"|"; // marker
+//      for( int i=0; i<hardware->GetMemory().GetSize(); ++i ){
+//        fp << hardware->GetMemory().GetFlags(i);
+//      }
+//      fp <<endl;
+
+    //// Save Hardware (Inst_Pointer, Stacks, and the like)
+    hardware->SaveState(fp);
+
+    //// Save Phenotype  ////
+    phenotype.SaveState(fp);
+
+  }
+}
+
+
+void cOrganism::LoadState(ifstream & fp)
+{
+  hardware->Reset();
+
+  assert(fp.good());
+
+  cString foo;
+  fp >>foo;
+  assert( foo == "cOrganism" );
+
+  //// Is there a creature there ////
+  bool alive_flag = 0;
+  fp >>alive_flag;
+  if( alive_flag ){
+
+    // IO buffers
+    //    fp.get(input_pointer);
+    input_buf.LoadState(fp);
+    output_buf.LoadState(fp);
+
+    //// Load Genotype ////
+    cGenome in_code =
+      cInstUtil::LoadInternalGenome(fp, hardware->GetInstSet());
+//    cGenotype * new_genotype = environment->AddGenotype(in_code);
+//    ChangeGenotype(new_genotype);
+
+    //// Load Actual Creature Memory & MemFlags ////
+//    {	
+//      in_code = cInstUtil::LoadInternalGenome(fp, hardware->GetInstSet());
+//      hardware->GetMemory() = in_code;
+//      CA_FLAG_TYPE flags;
+//      char marker;  fp >>marker;  assert( marker == '|' );
+//      for( int i=0; i<hardware->GetMemory().GetSize(); ++i ){
+//    	  fp.get(flags);
+//  	  hardware->SetMemFlags(i, flags);
+//      }
+//    }
+
+    //// Load Hardware (Inst_Pointer, Stacks, and the like)
+    hardware->LoadState(fp);
+
+    //// Load Phenotype  ////
+    assert(fp.good());
+//      phenotype.Clear(genotype->GetLength());
+    phenotype.LoadState(fp);
+
+    //// Adjust Time Slice ////
+//    environment->AdjustTimeSlice();
+
+  } // end if not a dead creature
+}

Copied: trunk/source/main/cOrganism.h (from rev 330, trunk/source/main/organism.hh)
===================================================================
--- trunk/source/main/organism.hh	2005-10-05 23:24:09 UTC (rev 330)
+++ trunk/source/main/cOrganism.h	2005-10-05 23:40:31 UTC (rev 331)
@@ -0,0 +1,230 @@
+//////////////////////////////////////////////////////////////////////////////
+// Copyright (C) 1993 - 2003 California Institute of Technology             //
+//                                                                          //
+// Read the COPYING and README files, or contact 'avida at alife.org',         //
+// before continuing.  SOME RESTRICTIONS MAY APPLY TO USE OF THIS FILE.     //
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef ORGANISM_HH
+#define ORGANISM_HH
+
+#include <fstream>
+#include <deque>
+
+#ifndef CPU_MEMORY_HH
+#include "cCPUMemory.h"
+#endif
+#ifndef CPU_STATS_HH
+#include "sCPUStats.h"
+#endif
+#ifndef GENOME_HH
+#include "cGenome.h"
+#endif
+#ifndef LOCAL_MUTATIONS_HH
+#include "cLocalMutations.h"
+#endif
+#ifndef MUTATION_RATES_HH
+#include "cMutationRates.h"
+#endif
+#ifndef PHENOTYPE_HH
+#include "cPhenotype.h"
+#endif
+#ifndef POPULATION_INTERFACE_HH
+#include "cPopulationInterface.h"
+#endif
+#ifndef TBUFFER_HH
+#include "tBuffer.hh"
+#endif
+
+/**
+ * The cOrganism class controls the running and manages all the statistics
+ * about a creature.  Effectively the chemistry acting on the genome.
+ **/
+
+class cHardwareBase;
+class cGenotype;
+class cPhenotype; // aggregate
+class cGenome; // aggregate
+class cInjectGenotype;
+class cMutationRates; // aggregate
+class cLocalMutations; // aggregate
+class cPopulationInterface; // aggregate
+class cCPUMemory; // aggregate
+class sCPUStats; // aggregate
+class cLineage;
+template <class T> class tBuffer; // aggregate
+class cOrgMessage;
+class cEnvironment;
+class cOrganism;
+class cCodeLabel;
+
+class cOrganism {
+protected:
+  cHardwareBase * hardware;  // The actual machinary running this organism.
+  cGenotype * genotype;      // Information about organisms with this genome.
+  cPhenotype phenotype;      // Descriptive attributes of organism.
+  const cGenome initial_genome;        // Initial genome; can never be changed!
+  std::deque<cInjectGenotype *> parasites; // List of all parasites associated with
+                                    // 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.
+
+  // Input and Output with the environment
+  int input_pointer;
+  tBuffer<int> input_buf;
+  tBuffer<int> output_buf;
+  tBuffer<int> send_buf;
+  tBuffer<int> receive_buf;
+
+  // Communication
+  int sent_value;         // What number is this org sending?
+  bool sent_active;       // Has this org sent a number?
+  int test_receive_pos;   // In a test CPU, what message to receive next?
+
+  // Other stats
+  cCPUMemory child_genome; // Child genome, while under construction.
+  sCPUStats cpu_stats;     // Info for statistics
+
+  int max_executed;      // Max number of instruction executed before death.
+
+  int lineage_label;     // a lineages tag; inherited unchanged in offspring
+  cLineage * lineage;    // A lineage descriptor... (different from label)
+
+  tBuffer<cOrgMessage> inbox;
+  tBuffer<cOrgMessage> sent;
+
+#ifdef DEBUG
+  bool initialized;      // Has this CPU been initialized yet, w/hardware.
+#endif
+  bool is_running;       // Does this organism have the CPU?
+  static int instance_count;
+
+public:
+  void PrintStatus(std::ostream & fp, const cString & next_name);
+
+  // Divide functions
+  bool Divide_CheckViable();
+  bool ActivateDivide();
+
+  // Other Special Functions
+  void Fault(int fault_loc, int fault_type, cString fault_desc="");
+
+public:
+  cOrganism(const cGenome & in_genome,
+	    const cPopulationInterface & in_interface,
+	    const cEnvironment & in_environment);
+  ~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(); }
+
+  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); }
+  
+  // Input & Output Testing
+  void DoInput(const int value);
+  void DoOutput(const int value);
+
+  // Message stuff
+  void SendMessage(cOrgMessage & mess);
+  bool ReceiveMessage(cOrgMessage & mess);
+
+  bool InjectParasite(const cGenome & genome);
+  bool InjectHost(const cCodeLabel & in_label, const cGenome & genome);
+  void AddParasite(cInjectGenotype * cur);
+  cInjectGenotype & GetParasite(int x);
+  int GetNumParasites();
+  void ClearParasites();
+		      
+  int OK();
+
+  double GetTestFitness();
+  double CalcMeritRatio();
+
+  cCPUMemory & ChildGenome() { return child_genome; }
+  sCPUStats & CPUStats() { return cpu_stats; }
+
+  bool TestCopyMut() const { return MutationRates().TestCopyMut(); }
+  bool TestDivideMut() const { return MutationRates().TestDivideMut(); }
+  bool TestDivideIns() const { return MutationRates().TestDivideIns(); }
+  bool TestDivideDel() const { return MutationRates().TestDivideDel(); }
+  bool TestParentMut() const { return MutationRates().TestParentMut(); }
+  bool TestCrossover() const { return MutationRates().TestCrossover(); }
+  bool TestAlignedCrossover() const
+    { return MutationRates().TestAlignedCrossover(); }
+  
+  double GetCopyMutProb() const { return MutationRates().GetCopyMutProb(); }
+  void SetCopyMutProb(double _p) { return MutationRates().SetCopyMutProb(_p); }
+  void SetDivMutProb(double _p) { return MutationRates().SetDivMutProb(_p); }
+
+  double GetInsMutProb() const { return MutationRates().GetInsMutProb(); }
+  double GetDelMutProb() const { return MutationRates().GetDelMutProb(); }
+  double GetDivMutProb() const { return MutationRates().GetDivMutProb(); }
+  double GetParentMutProb() const { return MutationRates().GetParentMutProb();}
+
+
+  bool GetTestOnDivide() const;
+  bool GetFailImplicit() const;
+
+  bool GetRevertFatal() const;
+  bool GetRevertNeg() const;
+  bool GetRevertNeut() const;
+  bool GetRevertPos() const;
+
+  bool GetSterilizeFatal() const;
+  bool GetSterilizeNeg() const;
+  bool GetSterilizeNeut() const;
+  bool GetSterilizePos() const;
+
+
+  // Access to private variables
+  int GetMaxExecuted() const { return max_executed; }
+
+  void SetLineageLabel( int in_label ) { lineage_label = in_label; }
+  int GetLineageLabel() const { return lineage_label; }
+  
+  void SetLineage( cLineage * in_lineage ) { lineage = in_lineage; }
+  cLineage * GetLineage() const { return lineage; }
+
+  void SetGenotype(cGenotype * in_genotype) { genotype = in_genotype; }
+  cGenotype * GetGenotype() const { return genotype; }
+
+  const cMutationRates & MutationRates() const { return mut_rates; }
+  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; }
+  
+  /*
+  int GetCurGestation() const;
+  */
+  const cPhenotype & GetPhenotype() const { return phenotype; }
+  cPhenotype & GetPhenotype() { return phenotype; }
+
+  void SaveState(std::ofstream & fp);
+  void LoadState(std::ifstream & fp);
+
+  // --------  DEBUG ---------
+  static int GetInstanceCount() { return instance_count; }
+  void SetRunning(bool in_running) { is_running = in_running; }
+  bool GetIsRunning() { return is_running; }
+};
+
+#endif
+

Copied: trunk/source/main/cPhenotype.cc (from rev 329, trunk/source/main/phenotype.cc)
===================================================================
--- trunk/source/main/phenotype.cc	2005-10-04 02:37:32 UTC (rev 329)
+++ trunk/source/main/cPhenotype.cc	2005-10-05 23:40:31 UTC (rev 331)
@@ -0,0 +1,762 @@
+//////////////////////////////////////////////////////////////////////////////
+// Copyright (C) 1993 - 2003 California Institute of Technology             //
+//                                                                          //
+// Read the COPYING and README files, or contact 'avida at alife.org',         //
+// before continuing.  SOME RESTRICTIONS MAY APPLY TO USE OF THIS FILE.     //
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef PHENOTYPE_HH
+#include "cPhenotype.h"
+#endif
+
+#ifndef CONFIG_HH
+#include "cConfig.h"
+#endif
+#ifndef ENVIRONMENT_HH
+#include "cEnvironment.h"
+#endif
+#ifndef REACTION_RESULT_HH
+#include "reaction_result.hh"
+#endif
+#ifndef TOOLS_HH
+#include "tools.hh"
+#endif
+
+#include <fstream>
+
+using namespace std;
+
+
+cPhenotype::cPhenotype(const cEnvironment & _environment)
+  : environment(_environment)
+  , initialized(false)
+  , cur_task_count(environment.GetTaskLib().GetSize())
+  , cur_reaction_count(environment.GetReactionLib().GetSize())
+  , cur_inst_count(environment.GetInstSet().GetSize())
+  , sensed_resources(environment.GetResourceLib().GetSize())
+  , last_task_count(environment.GetTaskLib().GetSize())
+  , last_reaction_count(environment.GetReactionLib().GetSize())
+  , last_inst_count(environment.GetInstSet().GetSize())
+{
+}
+
+cPhenotype::~cPhenotype()
+{
+}
+
+bool cPhenotype::OK()
+{
+  assert(genome_length >= 0);
+  assert(copied_size >= 0);
+  assert(executed_size >= 0);
+  assert(gestation_time >= 0);
+  assert(gestation_start >= 0);
+  assert(fitness >= 0.0);
+  assert(div_type >= 0.0);
+  assert(cur_bonus >= 0.0);
+  assert(cur_num_errors >= 0);
+  assert(cur_num_donates >= 0);
+  assert(last_merit_base >= 0.0);
+  assert(last_bonus >= 0.0);
+  assert(last_num_errors >= 0);
+  assert(last_num_donates >= 0);
+  assert(last_fitness >= 0.0);
+  assert(num_divides >= 0);
+  assert(generation >= 0);
+  assert(time_used >= 0);
+  assert(age >= 0);
+  assert(child_copied_size >= 0);
+  // assert(to_die == false);
+  return true;
+}
+
+
+/**
+ * This function is run whenever a new organism is being constructed inside
+ * of its parent.
+ *
+ * Assumptions:
+ *     - parent_phenotype has had DivideReset run on it already!
+ *     - this is the first method run on an otherwise freshly built phenotype.
+ **/
+
+void cPhenotype::SetupOffspring(const cPhenotype & parent_phenotype,
+				int _length)
+{
+  // Copy divide values from parent, which should already be setup.
+  merit           = parent_phenotype.merit;
+  genome_length   = _length;
+  copied_size     = parent_phenotype.child_copied_size;
+  executed_size   = parent_phenotype.executed_size;
+  gestation_time  = parent_phenotype.gestation_time;
+  gestation_start = 0;
+  fitness         = parent_phenotype.fitness;
+  div_type        = parent_phenotype.div_type;
+
+  assert(genome_length > 0);
+  assert(copied_size > 0);
+  assert(executed_size > 0);
+  assert(gestation_time > 0);
+  assert(div_type > 0);
+
+  // Initialize current values, as neeeded.
+  cur_bonus       = cConfig::GetDefaultBonus();
+  cur_num_errors  = 0;
+  cur_num_donates  = 0;
+  cur_task_count.SetAll(0);
+  cur_reaction_count.SetAll(0);
+  cur_inst_count.SetAll(0);
+  for (int j = 0; j < sensed_resources.GetSize(); j++)
+	      sensed_resources[j] =  parent_phenotype.sensed_resources[j];
+
+
+  // Copy last values from parent
+  last_merit_base     = parent_phenotype.last_merit_base;
+  last_bonus          = parent_phenotype.last_bonus;
+  last_num_errors     = parent_phenotype.last_num_errors;
+  last_num_donates    = parent_phenotype.last_num_donates;
+  last_task_count     = parent_phenotype.last_task_count;
+  last_reaction_count = parent_phenotype.last_reaction_count;
+  last_inst_count     = parent_phenotype.last_inst_count;
+  last_fitness        = last_merit_base * last_bonus / gestation_time;
+
+  // Setup other miscellaneous values...
+  num_divides     = 0;
+  generation      = parent_phenotype.generation;
+  if (cConfig::GetGenerationIncMethod() != GENERATION_INC_BOTH) generation++;
+  time_used       = 0;
+  age             = 0;
+  fault_desc      = "";
+  neutral_metric  = parent_phenotype.neutral_metric + g_random.GetRandNormal();
+  life_fitness    = fitness; 
+
+  // Setup flags...
+  is_injected   = false;
+  is_parasite   = false;
+  is_donor_cur  = false;
+  is_donor_last = parent_phenotype.is_donor_last;
+  is_receiver   = false;
+  is_modifier   = false;
+  is_modified   = false;
+  is_fertile    = parent_phenotype.last_child_fertile;
+  is_mutated    = false;
+  is_multi_thread = parent_phenotype.is_multi_thread;
+  parent_true   = parent_phenotype.copy_true;
+  parent_sex    = parent_phenotype.divide_sex;
+  parent_cross_num    = parent_phenotype.cross_num;
+  to_die = false;
+  to_delete = false;
+
+  // Setup child info...
+  copy_true          = false;
+  divide_sex         = false;
+  mate_select_id     = -1;
+  cross_num          = 0;
+  last_child_fertile = is_fertile;
+  child_fertile      = true;
+  child_copied_size  = 0;
+
+  initialized = true;
+}
+
+
+/**
+ * This function is run whenever a new organism is being constructed via
+ * some form of injection into the population, or in a test environment.
+ *
+ * Assumptions:
+ *     - Updates to these values (i.e. resetting of merit) will occur afterward
+ *     - This is the first method run on an otherwise freshly built phenotype.
+ **/
+
+void cPhenotype::SetupInject(int _length)
+{
+  // Setup reasonable initial values injected organism...
+  merit           = _length;
+  genome_length   = _length;
+  copied_size     = _length;
+  executed_size   = _length;
+  gestation_time  = 0;
+  gestation_start = 0;
+  fitness         = 0;
+  div_type	  = 1;
+
+  // Initialize current values, as neeeded.
+  cur_bonus       = cConfig::GetDefaultBonus();
+  cur_num_errors  = 0;
+  cur_num_donates  = 0;
+  cur_task_count.SetAll(0);
+  cur_reaction_count.SetAll(0);
+  cur_inst_count.SetAll(0);
+  sensed_resources.SetAll(0);
+
+  // Copy last values from parent
+  last_merit_base = _length;
+  last_bonus      = 1;
+  last_num_errors = 0;
+  last_num_donates = 0;
+  last_task_count.SetAll(0);
+  last_reaction_count.SetAll(0);
+  last_inst_count.SetAll(0);
+
+  // Setup other miscellaneous values...
+  num_divides     = 0;
+  generation      = 0;
+  time_used       = 0;
+  age             = 0;
+  fault_desc      = "";
+  neutral_metric  = 0;
+  life_fitness    = 0; 
+
+  // Setup flags...
+  is_injected   = true;
+  is_parasite   = false;
+  is_donor_last = false;
+  is_donor_cur  = false;
+  is_receiver   = false;
+  is_modifier   = false;
+  is_modified   = false;
+  is_fertile    = true;
+  is_mutated    = false;
+  is_multi_thread = false;
+  parent_true   = true;
+  parent_sex    = false;
+  parent_cross_num    = 0;
+  to_die = false;
+  to_delete = false;
+
+  // Setup child info...
+  copy_true         = false;
+  divide_sex        = false;
+  mate_select_id    = 0;
+  cross_num         = 0;
+  child_fertile     = true;
+  last_child_fertile = true;
+  child_copied_size = 0;
+
+  initialized = true;
+}
+
+
+/**
+ * This function is run whenever an organism executes a successful divide.
+ **/
+
+void cPhenotype::DivideReset(int _length)
+{
+  assert(time_used > 0);
+  assert(initialized == true);
+
+  // Update these values as needed...
+  int cur_merit_base = CalcSizeMerit(genome_length,copied_size,executed_size);
+  merit = cur_merit_base * cur_bonus;
+
+  genome_length   = _length;
+  (void) copied_size;          // Unchanged
+  (void) executed_size;        // Unchanged
+  gestation_time  = time_used - gestation_start;
+  gestation_start = time_used;
+  fitness         = merit.GetDouble() / gestation_time;
+
+  // Lock in cur values as last values.
+  last_merit_base     = cur_merit_base;
+  last_bonus          = cur_bonus;
+  last_num_errors     = cur_num_errors;
+  last_num_donates    = cur_num_donates;
+  last_task_count     = cur_task_count;
+  last_reaction_count = cur_reaction_count;
+  last_inst_count     = cur_inst_count;
+
+  // Reset cur values.
+  cur_bonus       = cConfig::GetDefaultBonus();
+  cur_num_errors  = 0;
+  cur_num_donates  = 0;
+  cur_task_count.SetAll(0);
+  cur_reaction_count.SetAll(0);
+  cur_inst_count.SetAll(0);
+
+  // Setup other miscellaneous values...
+  num_divides++;
+  (void) generation;
+  (void) time_used;
+  age             = 0;
+  fault_desc      = "";
+  (void) neutral_metric;
+  life_fitness = fitness; 
+
+  // Leave flags alone...
+  (void) is_injected;
+  (void) is_parasite;
+  is_donor_last = is_donor_cur;
+  is_donor_cur = false;
+  is_receiver = false;
+  (void) is_modifier;
+  (void) is_modified;
+  (void) is_fertile;
+  (void) is_mutated;
+  (void) is_multi_thread;
+  (void) parent_true;
+  (void) parent_sex;
+  (void) parent_cross_num;
+
+  // Reset child info...
+  (void) copy_true;
+  (void) divide_sex;
+  (void) mate_select_id;
+  (void) cross_num;
+  last_child_fertile = child_fertile;
+  child_fertile     = true;
+  (void) child_copied_size;;
+
+  // A few final changes if the parent was supposed to be be considered
+  // a second child on the divide.
+  if (cConfig::GetDivideMethod() == DIVIDE_METHOD_SPLIT) {
+    gestation_start = 0;
+    time_used = 0;
+    neutral_metric += g_random.GetRandNormal();
+  }
+
+  if (cConfig::GetGenerationIncMethod() == GENERATION_INC_BOTH) generation++;
+}
+
+
+/**
+ * This function runs whenever a *test* CPU divides. It processes much of
+ * the information for that CPU in order to actively reflect its executed
+ * and copied size in its merit.
+ **/
+
+void cPhenotype::TestDivideReset(int _length)
+{
+  assert(time_used > 0);
+  assert(initialized == true);
+
+  // Update these values as needed...
+  int cur_merit_base = CalcSizeMerit(genome_length,copied_size,executed_size);
+  merit           = cur_merit_base * cur_bonus;
+
+  genome_length   = _length;
+  (void) copied_size;                            // Unchanged
+  (void) executed_size;                          // Unchanged
+  gestation_time  = time_used - gestation_start;
+  gestation_start = time_used;
+  fitness         = merit.GetDouble() / gestation_time;
+  (void) div_type; 				// Unchanged
+
+  // Lock in cur values as last values.
+  last_merit_base     = cur_merit_base;
+  last_bonus          = cur_bonus;
+  last_num_errors     = cur_num_errors;
+  last_num_donates    = cur_num_donates;
+  last_task_count     = cur_task_count;
+  last_reaction_count = cur_reaction_count;
+  last_inst_count     = cur_inst_count;
+
+  // Reset cur values.
+  cur_bonus       = cConfig::GetDefaultBonus();
+  cur_num_errors  = 0;
+  cur_num_donates  = 0;
+  cur_task_count.SetAll(0);
+  cur_reaction_count.SetAll(0);
+  cur_inst_count.SetAll(0);
+  sensed_resources.SetAll(-1.0);
+
+  // Setup other miscellaneous values...
+  num_divides++;
+  generation++;
+  (void) time_used;
+  (void) age;
+  (void) fault_desc;
+  (void) neutral_metric;
+  life_fitness = fitness; 
+
+  // Leave flags alone...
+  (void) is_injected;
+  (void) is_parasite;
+  is_donor_last = is_donor_cur;
+  is_donor_cur = false;
+  is_receiver = false;
+  (void) is_modifier;
+  (void) is_modified;
+  (void) is_fertile;
+  (void) is_mutated;
+  (void) is_multi_thread;
+  (void) parent_true;
+  (void) parent_sex;
+  (void) parent_cross_num;
+
+  // Reset child info...
+  (void) copy_true;
+  (void) divide_sex;
+  (void) mate_select_id;
+  (void) cross_num;
+  (void) child_fertile;
+  (void) last_child_fertile;
+  (void) child_copied_size;
+}
+
+
+/**
+ * This function is run when an organism is being forced to replicate, but
+ * not at the end of its replication cycle.
+ *
+ * Assumptions:
+ *   - new organism is an exact clone of the parent, with *same* last info.
+ *   - this is the first method run on an otherwise freshly built phenotype.
+ **/
+
+void cPhenotype::SetupClone(const cPhenotype & clone_phenotype)
+{
+  // Copy divide values from parent, which should already be setup.
+  merit           = clone_phenotype.merit;
+  genome_length   = clone_phenotype.genome_length;
+  copied_size     = clone_phenotype.copied_size;
+  // copied_size     = clone_phenotype.child_copied_size;
+  executed_size   = clone_phenotype.executed_size;
+  gestation_time  = clone_phenotype.gestation_time;
+  gestation_start = 0;
+  fitness         = clone_phenotype.fitness;
+  div_type        = clone_phenotype.div_type;
+
+  assert(genome_length > 0);
+  assert(copied_size > 0);
+  assert(executed_size > 0);
+  assert(gestation_time > 0);
+  assert(div_type > 0);
+
+  // Initialize current values, as neeeded.
+  cur_bonus       = cConfig::GetDefaultBonus();
+  cur_num_errors  = 0;
+  cur_num_donates  = 0;
+  cur_task_count.SetAll(0);
+  cur_reaction_count.SetAll(0);
+  cur_inst_count.SetAll(0);
+  for (int j = 0; j < sensed_resources.GetSize(); j++)
+	      sensed_resources[j] =  clone_phenotype.sensed_resources[j];
+
+
+  // Copy last values from parent
+  last_merit_base     = clone_phenotype.last_merit_base;
+  last_bonus          = clone_phenotype.last_bonus;
+  last_num_errors     = clone_phenotype.last_num_errors;
+  last_num_donates    = clone_phenotype.last_num_donates;
+  last_task_count     = clone_phenotype.last_task_count;
+  last_reaction_count = clone_phenotype.last_reaction_count;
+  last_inst_count     = clone_phenotype.last_inst_count;
+  last_fitness        = last_merit_base * last_bonus / gestation_time;
+
+  // Setup other miscellaneous values...
+  num_divides     = 0;
+  generation      = clone_phenotype.generation;
+  if (cConfig::GetGenerationIncMethod() != GENERATION_INC_BOTH) generation++;
+  time_used       = 0;
+  age             = 0;
+  fault_desc      = "";
+  neutral_metric  = clone_phenotype.neutral_metric + g_random.GetRandNormal();
+  life_fitness    = fitness; 
+
+  // Setup flags...
+  is_injected   = false;
+  is_parasite   = false;
+  is_donor_last = clone_phenotype.is_donor_last;
+  is_donor_cur  = clone_phenotype.is_donor_cur;
+  is_receiver = false;
+  is_modifier   = false;
+  is_modified   = false;
+  is_fertile    = clone_phenotype.last_child_fertile;
+  is_mutated    = false;
+  is_multi_thread = clone_phenotype.is_multi_thread;
+  parent_true   = clone_phenotype.copy_true;
+  parent_sex    = clone_phenotype.divide_sex;
+  parent_cross_num    = clone_phenotype.cross_num;
+  to_die = false;
+  to_delete = false;
+
+  // Setup child info...
+  copy_true          = false;
+  divide_sex         = false;
+  mate_select_id     = 0;
+  cross_num          = 0;
+  last_child_fertile = is_fertile;
+  child_fertile      = true;
+  child_copied_size  = 0;
+
+  initialized = true;
+}
+
+
+
+
+bool cPhenotype::TestInput(tBuffer<int> & inputs, tBuffer<int> & outputs)
+{
+  assert(initialized == true);
+  // For the moment, lets not worry about inputs...
+  return false; // Nothing happened...
+}
+
+bool cPhenotype::TestOutput(tBuffer<int> & input_buf, tBuffer<int> &output_buf,
+			    tBuffer<int> & send_buf, tBuffer<int> &receive_buf,
+			    const tArray<double> & res_in,
+			    tArray<double> & res_change,
+			    tArray<int> & insts_triggered,
+			    tList<tBuffer<int> > & other_inputs,
+			    tList<tBuffer<int> > & other_outputs)
+{
+  assert(initialized == true);
+
+  const int num_resources = environment.GetResourceLib().GetSize();
+  const int num_tasks = environment.GetTaskLib().GetSize();
+  const int num_reactions = environment.GetReactionLib().GetSize();
+
+  cReactionResult result(num_resources, num_tasks, num_reactions);
+			
+  // Run everything through the environment.
+  bool found = environment.TestOutput(result, input_buf, output_buf, send_buf,
+			      receive_buf, cur_task_count, cur_reaction_count,
+			      res_in, other_inputs, other_outputs);
+
+  // If nothing was found, stop here.
+  if (found == false) {
+    res_change.SetAll(0.0);
+    return false;  // Nothing happened.
+  }
+
+  // Update the phenotype with the results...
+  // Start with updating task and reaction counters
+  for (int i = 0; i < num_tasks; i++) {
+    if (result.TaskDone(i) == true) cur_task_count[i]++;
+  }
+  for (int i = 0; i < num_reactions; i++) {
+    if (result.ReactionTriggered(i) == true) cur_reaction_count[i]++;
+  }
+
+  // Update the merit bonus
+  cur_bonus *= result.GetMultBonus();
+  cur_bonus += result.GetAddBonus();
+
+  // Bonus should never go negative...
+  // if (cur_bonus < 0.0) cur_bonus = 0.0;
+
+  // Denote consumed resources...
+  for (int i = 0; i < res_in.GetSize(); i++) {
+    res_change[i] = result.GetProduced(i) - result.GetConsumed(i);
+  }
+
+  // Save the instructions that should be triggered...
+  insts_triggered = result.GetInstArray();
+
+  //Put in detected resources
+  for (int j = 0; j < res_in.GetSize(); j++)
+	  if(result.GetDetected(j) != -1.0)
+	      sensed_resources[j] = result.GetDetected(j);
+
+  //Kill any cells that did lethal reactions
+  to_die = result.GetLethal();
+
+  return true;
+}
+
+
+///// For Loading and Saving State: /////
+
+
+bool cPhenotype::SaveState(ofstream & fp)
+{
+  assert(fp.good());
+  fp << "cPhenotype" << endl;
+
+  fp << merit.GetDouble()   << " ";
+  fp << genome_length       << " ";
+  fp << copied_size         << " ";
+  fp << executed_size       << " ";
+  fp << gestation_time      << " ";
+  fp << gestation_start     << " ";
+  fp << fitness             << " ";
+  fp << div_type            << " ";
+
+  fp << cur_bonus           << " ";
+  fp << cur_num_errors      << " ";
+  fp << cur_num_donates      << " ";
+  for (int i = 0; i < cur_task_count.GetSize(); i++) {
+    fp << cur_task_count[i] << " ";
+  }
+  for (int i = 0; i < cur_reaction_count.GetSize(); i++) {
+    fp << cur_reaction_count[i] << " ";
+  }
+  for (int i = 0; i < cur_inst_count.GetSize(); i++) {
+    fp << cur_inst_count[i] << " ";
+  }
+
+  fp << last_merit_base     << " ";
+  fp << last_bonus          << " ";
+  fp << last_num_errors     << " ";
+  fp << last_num_donates    << " ";
+  for (int i = 0; i < last_task_count.GetSize(); i++) {
+    fp << last_task_count[i] << " ";
+  }
+  for (int i = 0; i < last_reaction_count.GetSize(); i++) {
+    fp << last_reaction_count[i] << " ";
+  }
+  for (int i = 0; i < last_inst_count.GetSize(); i++) {
+    fp << last_inst_count[i] << " ";
+  }
+
+  fp << num_divides         << " ";
+  fp << generation          << " ";
+  fp << time_used           << " ";
+  fp << age                 << " ";
+  fp << neutral_metric      << " ";
+  fp << life_fitness        << " ";
+
+  fp << is_injected         << " ";
+  fp << is_parasite         << " ";
+  fp << is_donor_last       << " ";
+  fp << is_donor_cur        << " ";
+
+  fp << is_receiver         << " ";
+  fp << is_modifier         << " ";
+  fp << is_modified         << " ";
+  fp << is_fertile          << " ";
+  fp << is_mutated          << " ";
+  fp << parent_true         << " ";
+  fp << parent_sex          << " ";
+  fp << parent_cross_num    << " ";
+
+  fp << copy_true           << " ";
+  fp << divide_sex          << " ";
+  fp << mate_select_id      << " ";
+  fp << cross_num           << " ";
+  fp << child_fertile       << " ";
+  fp << last_child_fertile  << " ";
+
+  fp << endl;
+  return true;
+}
+
+
+bool cPhenotype::LoadState(ifstream & fp)
+{
+  double tmp_merit;
+  assert(fp.good());
+  if( !fp.good() ) return false;
+
+  fp >> tmp_merit;  merit = tmp_merit;
+  fp >> genome_length;
+  fp >> copied_size;
+  fp >> executed_size;
+  fp >> gestation_time;
+  fp >> gestation_start;
+  fp >> fitness;
+  fp >> div_type;
+
+  fp >> cur_bonus;
+  fp >> cur_num_errors;
+  fp >> cur_num_donates;
+
+  for (int i = 0; i < cur_task_count.GetSize(); i++) {
+    fp >> cur_task_count[i];
+  }
+  for (int i = 0; i < cur_reaction_count.GetSize(); i++) {
+    fp >> cur_reaction_count[i];
+  }
+  for (int i = 0; i < cur_inst_count.GetSize(); i++) {
+    fp >> cur_inst_count[i];
+  }
+
+  fp >> last_merit_base;
+  fp >> last_bonus;
+  fp >> last_num_errors;
+  fp >> last_num_donates;
+  for (int i = 0; i < last_task_count.GetSize(); i++) {
+    fp >> last_task_count[i];
+  }
+  for (int i = 0; i < last_reaction_count.GetSize(); i++) {
+    fp >> last_reaction_count[i];
+  }
+  for (int i = 0; i < last_inst_count.GetSize(); i++) {
+    fp >> last_inst_count[i];
+  }
+
+  fp >> num_divides;
+  fp >> generation;
+  fp >> time_used;
+  fp >> age;
+  fp >> neutral_metric;
+  fp >> life_fitness;
+
+  fp >> is_injected;
+  fp >> is_parasite;
+  fp >> is_donor_last;
+  fp >> is_donor_cur;
+  fp >> is_receiver;
+  fp >> is_modifier;
+  fp >> is_modified;
+  fp >> is_fertile;
+  fp >> is_mutated;
+  fp >> parent_true;
+  fp >> parent_sex;
+  fp >> parent_cross_num;
+
+  fp >> copy_true;
+  fp >> divide_sex;
+  fp >> mate_select_id;
+  fp >> cross_num;
+  fp >> child_fertile;
+  fp >> last_child_fertile;
+
+  return true;
+}
+
+void cPhenotype::PrintStatus(ostream & fp)
+{
+  fp << "  MeritBase:"
+     << CalcSizeMerit(genome_length,copied_size,executed_size)
+     << " Bonus: " << cur_bonus
+     << " Errors:" << cur_num_errors
+     << " Donates:" << cur_num_donates
+     << " Tasks:";
+
+  for (int i = 0; i < cur_task_count.GetSize(); i++) {
+    fp << " " << cur_task_count[i];
+  }
+
+  fp << endl;
+}
+
+int cPhenotype::CalcSizeMerit(int full_size, int copied_size, int exe_size)
+{
+  assert(full_size > 0);
+  assert(exe_size > 0);
+  assert(copied_size > 0);
+
+  int out_size;
+
+  switch (cConfig::GetSizeMeritMethod()) {
+  case SIZE_MERIT_COPIED:
+    out_size = copied_size;
+    break;
+  case SIZE_MERIT_EXECUTED:
+    out_size = exe_size;
+    break;
+  case SIZE_MERIT_FULL:
+    out_size = full_size;
+    break;
+  case SIZE_MERIT_LEAST:
+    out_size = full_size;
+    if (out_size > copied_size) out_size = copied_size;
+    if (out_size > exe_size)    out_size = exe_size;
+    break;
+  case SIZE_MERIT_SQRT_LEAST:
+    out_size = full_size;
+    if (out_size > copied_size) out_size = copied_size;
+    if (out_size > exe_size)    out_size = exe_size;
+    out_size = (int) sqrt((double) out_size);
+    break;
+  case SIZE_MERIT_OFF:
+  default:
+    out_size = cConfig::GetBaseSizeMerit();
+    break;
+  }
+
+  return out_size;
+}

Copied: trunk/source/main/cPhenotype.h (from rev 329, trunk/source/main/phenotype.hh)

Copied: trunk/source/main/cPopulation.cc (from rev 330, trunk/source/main/population.cc)
===================================================================
--- trunk/source/main/population.cc	2005-10-05 23:24:09 UTC (rev 330)
+++ trunk/source/main/cPopulation.cc	2005-10-05 23:40:31 UTC (rev 331)
@@ -0,0 +1,2154 @@
+//////////////////////////////////////////////////////////////////////////////
+// Copyright (C) 1993 - 2003 California Institute of Technology             //
+//                                                                          //
+// Read the COPYING and README files, or contact 'avida at alife.org',         //
+// before continuing.  SOME RESTRICTIONS MAY APPLY TO USE OF THIS FILE.     //
+//////////////////////////////////////////////////////////////////////////////
+
+#include "cPopulation.h"
+
+#include "change_list.hh"
+#include "cConfig.h"
+#include "const_schedule.hh"
+#include "data_file.hh"
+#include "cEnvironment.h"
+#include "functions.hh"
+#include "cGenebank.h"
+#include "cGenomeUtil.h"
+#include "cGenotype.h"
+#include "cHardwareBase.h"
+#include "cHardwareFactory.h"
+#include "cHardware4Stack.h"
+#include "cHardwareUtil.h"
+#include "init_file.hh"
+#include "cInjectGenebank.h"
+#include "cInjectGenotype.h"
+#include "cInstUtil.h"
+#include "integrated_schedule.hh"
+#include "cLineage.h"
+#include "cLineageControl.h"
+#include "cOrganism.h"
+#include "cPhenotype.h"
+#include "cPopulationCell.h"
+#include "prob_schedule.hh"
+#include "resource.hh"
+#include "species.hh"
+#include "stats.hh"
+#include "task_entry.hh"
+
+#include <fstream>
+#include <vector>
+#include <algorithm>
+#include <set>
+
+#include <math.h>
+
+using namespace std;
+
+
+cPopulation::cPopulation(const cPopulationInterface & in_interface,
+                         cEnvironment & in_environment,
+                         cChangeList * change_list)
+: schedule(NULL)
+, resource_count(in_environment.GetResourceLib().GetSize())
+, environment(in_environment)
+, default_interface(in_interface)
+, num_organisms(0)
+, sync_events(false)
+{
+  // Setup the genebank.
+  genebank = new cGenebank(stats);
+  inject_genebank = new cInjectGenebank(stats);
+  birth_chamber.SetGenebank(genebank);
+  
+  // are we logging lineages?
+  if (cConfig::GetLogLineages()) {
+    lineage_control = new cLineageControl( *genebank, stats );
+  }
+  else lineage_control = NULL;    // no lineage logging
+  
+  // Setup the default mutation rates...
+  cMutationRates & default_mut_rates = environment.GetMutRates();
+  default_mut_rates.SetCopyMutProb  ( cConfig::GetCopyMutProb()   );
+  default_mut_rates.SetInsMutProb   ( cConfig::GetInsMutProb()    );
+  default_mut_rates.SetDelMutProb   ( cConfig::GetDelMutProb()    );
+  default_mut_rates.SetDivMutProb   ( cConfig::GetDivMutProb()    );
+  default_mut_rates.SetPointMutProb ( cConfig::GetPointMutProb()  );
+  default_mut_rates.SetDivideMutProb( cConfig::GetDivideMutProb() );
+  default_mut_rates.SetDivideInsProb( cConfig::GetDivideInsProb() );
+  default_mut_rates.SetDivideDelProb( cConfig::GetDivideDelProb() );
+  default_mut_rates.SetParentMutProb( cConfig::GetParentMutProb() );
+  
+  // Setup the default population interface...
+  default_interface.SetPopulation(this);
+  
+  // Avida specific information.
+  world_x = cConfig::GetWorldX();
+  world_y = cConfig::GetWorldY();
+  int geometry = cConfig::GetWorldGeometry();
+  const int num_cells = world_x * world_y;
+  cout << "Building world " << world_x << "x" << world_y
+    << " = " << num_cells << " organisms." << endl;
+  if (geometry == GEOMETRY_GRID) {
+    cout << "Geometry: Bounded grid" << endl;
+  } else if (geometry == GEOMETRY_TORUS) {
+    cout << "Geometry: Torus" << endl;
+  } else {
+    cout << "Geometry: Unknown" << endl;
+  }
+  cout << endl;
+  
+  cell_array.Resize(num_cells);
+  resource_count.ResizeSpatialGrids(world_x, world_y);
+  
+  bool bottom_flag, top_flag, right_flag, left_flag;
+  for (int cell_id = 0; cell_id < num_cells; cell_id++) {
+    int x = cell_id % world_x;
+    int y = cell_id / world_x;
+    cell_array[cell_id].Setup(cell_id, default_mut_rates);
+    
+    
+    if ((y == 0) && (geometry == GEOMETRY_GRID)) {
+      bottom_flag = false;
+    } else {
+      bottom_flag = true;
+    }
+    if ((y == world_y-1) && (geometry == GEOMETRY_GRID)) {
+      top_flag = false;
+    } else {
+      top_flag = true;
+    }
+    if ((x == 0) && (geometry == GEOMETRY_GRID)) {
+      left_flag = false;
+    } else {
+      left_flag = true;
+    }
+    if ((x == world_x-1) && (geometry == GEOMETRY_GRID)) {
+      right_flag = false;
+    } else {
+      right_flag = true;
+    }
+    
+    // Setup the connection list for each cell. (Clockwise from -1 to 1)
+    
+    tList<cPopulationCell> & conn_list=cell_array[cell_id].ConnectionList();
+    if (bottom_flag && left_flag) {
+      conn_list.Push(&(cell_array[GridNeighbor(cell_id,world_x,world_y, -1, -1)]));
+    }
+    if (bottom_flag) {
+      conn_list.Push(&(cell_array[GridNeighbor(cell_id,world_x,world_y,  0, -1)]));
+    }
+    if (bottom_flag && right_flag) {
+      conn_list.Push(&(cell_array[GridNeighbor(cell_id,world_x,world_y, +1, -1)]));
+    }
+    if (right_flag) {
+      conn_list.Push(&(cell_array[GridNeighbor(cell_id,world_x,world_y, +1,  0)]));
+    }
+    if (top_flag && right_flag) {
+      conn_list.Push(&(cell_array[GridNeighbor(cell_id,world_x,world_y, +1, +1)]));
+    }
+    if (top_flag) {
+      conn_list.Push(&(cell_array[GridNeighbor(cell_id,world_x,world_y,  0, +1)]));
+    }
+    if (top_flag && left_flag) {
+      conn_list.Push(&(cell_array[GridNeighbor(cell_id,world_x,world_y, -1, +1)]));
+    }
+    if (left_flag) {
+      conn_list.Push(&(cell_array[GridNeighbor(cell_id,world_x,world_y, -1,  0)]));
+    }
+    
+    // Setup the reaper queue...
+    if (cConfig::GetBirthMethod() == POSITION_CHILD_FULL_SOUP_ELDEST) {
+      reaper_queue.Push(&(cell_array[cell_id]));
+    }
+  }
+  
+  BuildTimeSlicer(change_list);
+  
+  if (SetupDemes() == false) {
+    cerr << "Error: Failed to setup demes.  Exiting..." << endl;
+    exit(1);
+  }
+  
+  // Setup the resources...
+  const cResourceLib & resource_lib = environment.GetResourceLib();
+  for (int i = 0; i < resource_lib.GetSize(); i++) {
+    cResource * res = resource_lib.GetResource(i);
+    const double decay = 1.0 - res->GetOutflow();
+    resource_count.Setup(i, res->GetName(), res->GetInitial(), 
+                         res->GetInflow(), decay,
+                         res->GetGeometry(), res->GetXDiffuse(),
+                         res->GetXGravity(), res->GetYDiffuse(), 
+                         res->GetYGravity(), res->GetInflowX1(), 
+                         res->GetInflowX2(), res->GetInflowY1(), 
+                         res->GetInflowY2(), res->GetOutflowX1(), 
+                         res->GetOutflowX2(), res->GetOutflowY1(), 
+                         res->GetOutflowY2() );
+    stats.SetResourceName(i, res->GetName());
+  }
+  
+  // Give stats information about the environment...
+  const cTaskLib & task_lib = environment.GetTaskLib();
+  for (int i = 0; i < task_lib.GetSize(); i++) {
+    const cTaskEntry & cur_task = task_lib.GetTask(i);
+    stats.SetTaskName(i, cur_task.GetDesc());
+  }
+  
+  const cInstSet & inst_set = environment.GetInstSet();
+  for (int i = 0; i < inst_set.GetSize(); i++) {
+    stats.SetInstName(i, inst_set.GetName(i));
+  }
+  
+  // Load a clone if one is provided, otherwise setup start organism.
+  if (cConfig::GetCloneFilename() == "") {
+    cGenome start_org = cInstUtil::LoadGenome(cConfig::GetStartCreature(), environment.GetInstSet());
+    if (start_org.GetSize() != 0) Inject(start_org);
+    else cerr << "Warning: Zero length start organism, not injecting into initial population." << endl;
+  } else {
+    ifstream fp(cConfig::GetCloneFilename()());
+    LoadClone(fp);
+  }
+  
+  // Load a saved population if one is provided.
+  cString fname(cConfig::GetLoadPopFilename());
+  if (fname != "") {
+    cout << "Loading Population from " <<  fname() << endl;
+    
+    // If last three chars of filename are ".gz" , gunzip it first
+    if (fname.Find(".gz") == fname.GetSize() - 3) {
+      cString cmd(fname);
+      cmd.Insert("gunzip ");
+      fname.ClipEnd(3);
+      system(cmd);
+      
+      ifstream fp(fname);
+      if( !fp.good() ){
+        cerr << "Error: Failed to load population file " << fname() << ". Exiting...\n" << endl;
+        exit(2);
+      }
+      LoadPopulation(fp);
+      
+      cmd = fname;
+      cmd.Insert("gzip ");
+      system(cmd);
+    } else {
+      // load normally
+      ifstream fp(fname);
+      LoadPopulation(fp);
+    }
+  }
+  
+}
+
+
+cPopulation::~cPopulation()
+{
+  for (int i = 0; i < cell_array.GetSize(); i++) KillOrganism(cell_array[i]);
+  
+  if ( lineage_control != NULL ) delete lineage_control;
+  delete genebank;
+  delete inject_genebank;
+  delete schedule;
+}
+
+
+// This method configures demes in the population.  Demes are subgroups of
+// organisms evolved together and used in group selection experiments.
+bool cPopulation::SetupDemes()
+{
+  num_demes = cConfig::GetNumDemes();
+  
+  // If we are not using demes, stop here.
+  if (num_demes == 0) {
+    if (cConfig::GetBirthMethod() == POSITION_CHILD_DEME_RANDOM) {
+      cerr << "Using position method that requires demes, but demes are off."
+      << endl;
+      return false;
+    }
+    return true;
+  }
+  
+  // Check to make sure all other settings are reasonable to have demes.
+  // ...make sure populaiton can be divided up evenly.
+  if (world_y % num_demes != 0) {
+    cerr << "World Y size of " << world_y
+    << " cannot be divided into " << num_demes << " demes." << endl;
+    return false;
+  }
+  
+  // ...make sure we are using a legal birth method.
+  if (cConfig::GetBirthMethod() == POSITION_CHILD_FULL_SOUP_ELDEST ||
+      cConfig::GetBirthMethod() == POSITION_CHILD_FULL_SOUP_RANDOM) {
+    cerr << "Illegal birth method " << cConfig::GetBirthMethod()
+    << " for use with demes." << endl;
+    return false;
+  }
+  
+  const int deme_size_x = world_x;
+  const int deme_size_y = world_y / num_demes;
+  deme_size = deme_size_x * deme_size_y;
+  
+  // Track birth counts...
+  deme_birth_count.Resize(num_demes);
+  deme_birth_count.SetAll(0);
+  
+  // Build walls in the population.
+  for (int row_id = 0; row_id < world_y; row_id += deme_size_y) {
+    // Loop through all of the cols and make the cut on each...
+    for (int col_id = 0; col_id < world_x; col_id++) {
+      int idA = row_id * world_x + col_id;
+      int idB  = GridNeighbor(idA, world_x, world_y,  0, -1);
+      int idA0 = GridNeighbor(idA, world_x, world_y, -1,  0);
+      int idA1 = GridNeighbor(idA, world_x, world_y,  1,  0);
+      int idB0 = GridNeighbor(idA, world_x, world_y, -1, -1);
+      int idB1 = GridNeighbor(idA, world_x, world_y,  1, -1);
+      cPopulationCell & cellA = GetCell(idA);
+      cPopulationCell & cellB = GetCell(idB);
+      tList<cPopulationCell> & cellA_list = cellA.ConnectionList();
+      tList<cPopulationCell> & cellB_list = cellB.ConnectionList();
+      cellA_list.Remove(&GetCell(idB));
+      cellA_list.Remove(&GetCell(idB0));
+      cellA_list.Remove(&GetCell(idB1));
+      cellB_list.Remove(&GetCell(idA));
+      cellB_list.Remove(&GetCell(idA0));
+      cellB_list.Remove(&GetCell(idA1));
+    }
+  }
+  
+  return true;
+}
+
+// Activate the child, given information from the parent.
+// Return true if parent lives through this process.
+
+bool cPopulation::ActivateOffspring(cGenome & child_genome,
+                                    cOrganism & parent_organism)
+{
+  assert(&parent_organism != NULL);
+  
+  tArray<cOrganism *> child_array;
+  tArray<cMerit> merit_array;
+  
+  // Update the parent's phenotype.
+  // This needs to be done before the parent goes into the brith chamber
+  // or the merit doesn't get passed onto the child correctly
+  cPhenotype & parent_phenotype = parent_organism.GetPhenotype();
+  parent_phenotype.DivideReset(parent_organism.GetGenome().GetSize());
+  
+  birth_chamber.SubmitOffspring(child_genome, parent_organism,
+                                child_array, merit_array);
+  
+  
+  // First, setup the genotype of all of the offspring.
+  cGenotype * parent_genotype = parent_organism.GetGenotype();
+  const int parent_id = parent_organism.PopInterface().GetCellID();
+  assert(parent_id >= 0 && parent_id < cell_array.GetSize());
+  cPopulationCell & parent_cell = cell_array[ parent_id ];
+  
+  
+  tArray<int> target_cells(child_array.GetSize());
+  
+  // Loop through choosing the later placement of each child in the population.
+  bool parent_alive = true;  // Will the parent live through this process?
+  for (int i = 0; i < child_array.GetSize(); i++) {
+    target_cells[i] = PositionChild( parent_cell ).GetID();
+    // If we replaced the parent, make a note of this.
+    if (target_cells[i] == parent_cell.GetID()) parent_alive = false;      
+    
+    // Update the mutation rates of each child....
+    child_array[i]->MutationRates().
+      Copy(GetCell(target_cells[i]).MutationRates());
+    
+    // Update the phenotypes of each child....
+    const int child_length = child_array[i]->GetGenome().GetSize();
+    child_array[i]->GetPhenotype().
+      SetupOffspring(parent_phenotype,child_length);
+    
+    child_array[i]->GetPhenotype().SetMerit(merit_array[i]);
+    
+    // Do lineage tracking for the new organisms.
+    LineageSetupOrganism( child_array[i], parent_organism.GetLineage(),
+                          parent_organism.GetLineageLabel(),
+                          parent_genotype );
+    
+  }
+  
+  
+  // 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());
+    
+    // In a local run, face the child toward the parent. 
+    if (cConfig::GetBirthMethod() < NUM_LOCAL_POSITION_CHILD) {
+      for (int i = 0; i < child_array.GetSize(); i++) {
+        GetCell(target_cells[i]).Rotate(parent_cell);
+      }
+    }
+  }
+  
+  // Do any statistics on the parent that just gave birth...
+  parent_genotype->AddGestationTime( parent_phenotype.GetGestationTime() );
+  parent_genotype->AddFitness(       parent_phenotype.GetFitness()       );
+  parent_genotype->AddMerit(         parent_phenotype.GetMerit()         );
+  parent_genotype->AddCopiedSize(    parent_phenotype.GetCopiedSize()    );
+  parent_genotype->AddExecutedSize(  parent_phenotype.GetExecutedSize()  );
+  
+  // Place all of the offspring...
+  for (int i = 0; i < child_array.GetSize(); i++) {
+    ActivateOrganism(child_array[i], GetCell(target_cells[i]));
+    cGenotype * child_genotype = child_array[i]->GetGenotype();
+    child_genotype->DecDeferAdjust();
+    genebank->AdjustGenotype(*child_genotype);
+  }
+  
+  return parent_alive;
+}
+
+bool cPopulation::ActivateInject(cOrganism & parent, const cGenome & injected_code)
+{
+  assert(&parent != NULL);
+  
+  if(injected_code.GetSize() ==0)
+    return false;
+  
+  cHardware4Stack & parent_cpu = (cHardware4Stack &) parent.GetHardware();
+  cInjectGenotype * parent_genotype = parent_cpu.GetCurThreadOwner();
+  
+  const int parent_id = parent.PopInterface().GetCellID();
+  assert(parent_id >= 0 && parent_id < cell_array.GetSize());
+  cPopulationCell & parent_cell = cell_array[ parent_id ];
+  
+  int num_neighbors = parent.GetNeighborhoodSize();
+  cOrganism * target_organism = 
+    parent_cell.connection_list.GetPos(g_random.GetUInt(num_neighbors))->GetOrganism();
+  
+  if(target_organism==NULL)
+    return false;
+  
+  cHardware4Stack & child_cpu = (cHardware4Stack &) target_organism->GetHardware();
+  
+  if(child_cpu.GetNumThreads()==cConfig::GetMaxCPUThreads())
+    return false;
+  
+  cInjectGenotype * child_genotype = parent_genotype;
+  
+  if(target_organism->InjectHost(parent_cpu.GetLabel(), injected_code)) {
+    // If the parent genotype is not correct for the child, adjust it.
+    if (parent_genotype == NULL || parent_genotype->GetGenome() != injected_code) {
+      child_genotype = inject_genebank->AddInjectGenotype(injected_code, parent_genotype);
+    }
+    
+    target_organism->AddParasite(child_genotype);
+    child_genotype->AddParasite();
+    child_cpu.SetThreadOwner(child_genotype);
+    //if(parent_genotype!=NULL)
+    //  parent_genotype->RemoveParasite();
+    inject_genebank->AdjustInjectGenotype(*child_genotype);
+  }
+  else
+    return false;
+  
+  return true;
+  
+  // And set the genotype now that we know it.
+  //child_array[i]->SetGenotype(child_genotype);
+  //parent_genotype->SetBreedStats(*child_genotype);
+  
+  // We want to make sure that the child's genotype is not deleted from the
+  // genebank before the child is placed.
+  //child_genotype->IncDeferAdjust();
+  
+  // **THIS WILL BE NECESSARY IF/WHEN WE IMPLEMENT PARASITE LINEAGES.**
+  // Do lineage tracking for the new creature, if necessary.  Must occur
+  // before old organism is removed.
+  //LineageSetupOrganism( child_array[i], parent_organism.GetLineage(),
+  //			  parent_organism.GetLineageLabel(), parent_genotype );
+  
+  // **THIS WILL BE NECESSARY ONCE WE IMPLEMENT PARASITE MUTATION RATES.**
+  //child_array[i]->MutationRates().
+  //  Copy(GetCell(target_cells[i]).MutationRates());
+  
+  // Do any statistics on the parent that just gave birth...
+  //parent_genotype->AddGestationTime( parent_phenotype.GetGestationTime() );
+  //parent_genotype->AddFitness(       parent_phenotype.GetFitness()       );
+  //parent_genotype->AddMerit(         parent_phenotype.GetMerit()         );
+  //parent_genotype->AddCopiedSize(    parent_phenotype.GetCopiedSize()    );
+  //parent_genotype->AddExecutedSize(  parent_phenotype.GetExecutedSize()  );
+  
+  // Place all of the offspring...
+  /*for (int i = 0; i < child_array.GetSize(); i++) {
+    ActivateOrganism(child_array[i], GetCell(target_cells[i]));
+  cGenotype * child_genotype = child_array[i]->GetGenotype();
+  child_genotype->DecDeferAdjust();
+  genebank->AdjustGenotype(*child_genotype);
+  }*/
+}
+
+bool cPopulation::ActivateInject(const int cell_id, const cGenome & injected_code)
+{
+  cInjectGenotype * child_genotype = inject_genebank->AddInjectGenotype(injected_code);
+  cHardware4Stack & child_cpu = (cHardware4Stack &) cell_array[cell_id].GetOrganism()->GetHardware();
+  if(cell_array[cell_id].GetOrganism()->InjectHost(cCodeLabel(), injected_code))
+  {
+    cell_array[cell_id].GetOrganism()->AddParasite(child_genotype);
+    child_genotype->AddParasite();
+    child_cpu.SetThreadOwner(child_genotype);
+    inject_genebank->AdjustInjectGenotype(*child_genotype);
+  }
+  else
+    return false;
+  
+  return true;
+}
+
+void cPopulation::ActivateOrganism(cOrganism * in_organism,
+                                   cPopulationCell & target_cell)
+{
+  assert(in_organism != NULL);
+  assert(in_organism->GetGenome().GetSize() > 1);
+  
+  // 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) {
+    cGenotype * new_genotype =
+    genebank->AddGenotype(in_organism->GetGenome(), NULL, NULL);
+    in_organism->SetGenotype(new_genotype);
+  }
+  cGenotype * in_genotype = in_organism->GetGenotype();
+  
+  // Save the old genotype from this cell...
+  cGenotype * old_genotype = NULL;
+  if (target_cell.IsOccupied()) {
+    old_genotype = target_cell.GetOrganism()->GetGenotype();
+    
+    // Sometimes a new organism will kill off the last member of its genotype
+    // in the population.  Normally this would remove the genotype, so we 
+    // want to defer adjusting that genotype until the new one is placed.
+    old_genotype->IncDeferAdjust();
+  }
+  
+  // Update the contents of the target cell.
+  KillOrganism(target_cell);
+  target_cell.InsertOrganism(*in_organism);
+  
+  // Setup the inputs in the target cell.
+  environment.SetupInputs(target_cell.input_array);
+  
+  // Update the genebank...
+  in_genotype->AddOrganism();
+  
+  if (old_genotype != NULL) {
+    old_genotype->DecDeferAdjust();
+    genebank->AdjustGenotype(*old_genotype);
+  }
+  genebank->AdjustGenotype(*in_genotype);
+  
+  // Initialize the time-slice for this new organism.
+  schedule->Adjust(target_cell.GetID(),in_organism->GetPhenotype().GetMerit());
+  
+  // Special handling for certain birth methods.
+  if (cConfig::GetBirthMethod() == POSITION_CHILD_FULL_SOUP_ELDEST) {
+    reaper_queue.Push(&target_cell);
+  }
+  
+  num_organisms++;
+  
+  // Statistics...
+  stats.RecordBirth(target_cell.GetID(), in_genotype->GetID(),
+                    in_organism->GetPhenotype().ParentTrue());
+}
+
+void cPopulation::KillOrganism(cPopulationCell & in_cell)
+{
+  // do we actually have something to kill?
+  if (in_cell.IsOccupied() == false) {
+    return;
+  }
+  
+  // Statistics...
+  cOrganism * organism = in_cell.GetOrganism();
+  cGenotype * genotype = organism->GetGenotype();
+  stats.RecordDeath(in_cell.GetID(), genotype->GetID(),
+                    organism->GetPhenotype().GetAge());
+  
+  
+  // Do the lineage handling
+  if (lineage_control != NULL) {
+    lineage_control->RemoveCreature( organism );
+  }
+  
+  // Do statistics
+  num_organisms--;
+  
+  //if (organism->GetPhenotype().IsParasite() == true) {
+  //  genotype->AddParasite();
+  //}
+  genotype->RemoveOrganism();
+
+for(int i=0; i<organism->GetNumParasites(); i++) {
+  organism->GetParasite(i).RemoveParasite();
+}
+
+// And clear it!
+in_cell.RemoveOrganism();
+if (organism->GetIsRunning() == false) delete organism;
+else organism->GetPhenotype().SetToDelete();
+
+// Alert the scheduler that this cell has a 0 merit.
+schedule->Adjust( in_cell.GetID(), cMerit(0) );
+
+// Update the genebank (note: genotype adjustment may be defered)
+genebank->AdjustGenotype(*genotype);
+}
+
+void cPopulation::Kaboom(cPopulationCell & in_cell)
+{
+  cOrganism * organism = in_cell.GetOrganism();
+  cGenotype * genotype = organism->GetGenotype();
+  cGenome genome = genotype->GetGenome();
+  int id = genotype->GetID();
+  
+  int radius = 2;
+  int distance = 0;
+  int count = 0;
+  
+  for (int i=-1*radius; i<=radius; i++) {
+    for (int j=-1*radius; j<=radius; j++) {
+      cPopulationCell & death_cell =
+      cell_array[GridNeighbor(in_cell.GetID(), world_x, world_y, i, j)];
+      //do we actually have something to kill?
+      if (death_cell.IsOccupied() == false) continue;
+      
+      cOrganism * org_temp = death_cell.GetOrganism();
+      cGenotype * gene_temp = org_temp->GetGenotype();
+      
+      if (distance == 0) {
+        int temp_id = gene_temp->GetID();
+        if (temp_id != id) {
+          KillOrganism(death_cell);
+          count++;
+        }
+      }
+      else {	
+        cGenome genome_temp = gene_temp->GetGenome();
+        int diff=0;
+        for (int i=0; i<genome_temp.GetSize(); i++)
+          if (genome_temp.AsString()[i] != genome.AsString()[i])
+            diff++;
+        if (diff > distance)
+        {
+          KillOrganism(death_cell);
+          count++;
+        }
+      }
+    }
+  }
+  KillOrganism(in_cell);
+  // @SLG my prediction = 92% and, 28 get equals
+}
+
+
+// CompeteDemes  probabilistically copies demes into the next generation
+// based on their fitness. How deme fitness is estimated is specified by 
+// competition_type input argument as by the birth count (1), average
+// fitness (2), or equal for all demes (3). For ease of use, each organism 
+// is setup as if it we just injected into the population.
+
+void cPopulation::CompeteDemes(int competition_type)
+{
+  
+  double total_fitness = 0; 
+  tArray<double> deme_fitness(num_demes); 
+  
+  switch(competition_type) {
+    case 0:    // deme fitness = 1; 
+      total_fitness = (double) num_demes;
+      deme_fitness.SetAll(1); 
+      break; 
+    case 1:     // deme fitness = number of births
+                // Determine the scale for fitness by totaling births across demes.
+      for (int cur_deme = 0; cur_deme < num_demes; cur_deme++) {
+        deme_fitness[cur_deme] = (double) deme_birth_count[cur_deme]; 
+        total_fitness += deme_birth_count[cur_deme];
+      }
+      break; 
+    case 2:    // deme fitness = average organism fitness at the current update
+      for (int cur_deme = 0; cur_deme < num_demes; cur_deme++) {
+        cDoubleSum single_deme_fitness;
+        for (int i = 0; i < deme_size; i++) {
+          int cur_cell = cur_deme * deme_size + i;
+          if (cell_array[cur_cell].IsOccupied() == false) continue;
+          cPhenotype & phenotype = GetCell(cur_cell).GetOrganism()->GetPhenotype();
+          single_deme_fitness.Add(phenotype.GetFitness());
+        } 
+        deme_fitness[cur_deme] = single_deme_fitness.Ave();
+        total_fitness += deme_fitness[cur_deme];
+      }
+      break; 
+    case 3: 	// deme fitness = average mutation rate at the current update 
+      for (int cur_deme = 0; cur_deme < num_demes; cur_deme++) {
+        cDoubleSum single_deme_div_type;
+        for (int i = 0; i < deme_size; i++) {
+          int cur_cell = cur_deme * deme_size + i;
+          if (cell_array[cur_cell].IsOccupied() == false) continue;
+          cPhenotype & phenotype = GetCell(cur_cell).GetOrganism()->GetPhenotype();
+          assert(phenotype.GetDivType()>0);
+          single_deme_div_type.Add(1/phenotype.GetDivType());
+        }
+        deme_fitness[cur_deme] = single_deme_div_type.Ave();
+        total_fitness += deme_fitness[cur_deme];
+      } 			 	      	
+      break; 
+    case 4: 	// deme fitness = 2^(-deme fitness rank) 
+              // first find all the deme fitness values ...
+    {      
+      for (int cur_deme = 0; cur_deme < num_demes; cur_deme++) {
+        cDoubleSum single_deme_fitness;
+        for (int i = 0; i < deme_size; i++) {
+          int cur_cell = cur_deme * deme_size + i; 
+          if (cell_array[cur_cell].IsOccupied() == false) continue;
+          cPhenotype & phenotype = GetCell(cur_cell).GetOrganism()->GetPhenotype();
+          single_deme_fitness.Add(phenotype.GetFitness());
+        }  
+        deme_fitness[cur_deme] = single_deme_fitness.Ave();
+      }
+      // ... then determine the rank of each deme based on its fitness
+      tArray<double> deme_rank(num_demes);
+      deme_rank.SetAll(1);
+      for (int cur_deme = 0; cur_deme < num_demes; cur_deme++) {
+        for (int test_deme = 0; test_deme < num_demes; test_deme++) {
+          if (deme_fitness[cur_deme] < deme_fitness[test_deme]) {
+            deme_rank[cur_deme]++;
+          } 
+        } 
+      } 
+      // ... finally, make deme fitness 2^(-deme rank)
+      deme_fitness.SetAll(1);	
+      for (int cur_deme = 0; cur_deme < num_demes; cur_deme++) {
+        for (int i = 0; i < deme_rank[cur_deme]; i++) { 
+          deme_fitness[cur_deme] = deme_fitness[cur_deme]/2;
+        } 
+        total_fitness += deme_fitness[cur_deme]; 
+      } 
+    }
+      break; 
+    case 5:    // deme fitness = average organism life fitness at the current update
+      for (int cur_deme = 0; cur_deme < num_demes; cur_deme++) {
+        cDoubleSum single_deme_life_fitness;
+        for (int i = 0; i < deme_size; i++) {
+          int cur_cell = cur_deme * deme_size + i;
+          if (cell_array[cur_cell].IsOccupied() == false) continue;
+          cPhenotype & phenotype = GetCell(cur_cell).GetOrganism()->GetPhenotype();
+          single_deme_life_fitness.Add(phenotype.GetLifeFitness());
+        }
+        deme_fitness[cur_deme] = single_deme_life_fitness.Ave();
+        total_fitness += deme_fitness[cur_deme];
+      }
+      break; 
+    case 6:     // deme fitness = 2^(-deme life fitness rank) (same as 4, but with life fitness)
+                // first find all the deme fitness values ...
+    {
+      for (int cur_deme = 0; cur_deme < num_demes; cur_deme++) {
+        cDoubleSum single_deme_life_fitness;
+        for (int i = 0; i < deme_size; i++) {
+          int cur_cell = cur_deme * deme_size + i;
+          if (cell_array[cur_cell].IsOccupied() == false) continue;
+          cPhenotype & phenotype = GetCell(cur_cell).GetOrganism()->GetPhenotype();
+          single_deme_life_fitness.Add(phenotype.GetLifeFitness());
+        }
+        deme_fitness[cur_deme] = single_deme_life_fitness.Ave();
+      }
+      // ... then determine the rank of each deme based on its fitness
+      tArray<double> deme_rank(num_demes);
+      deme_rank.SetAll(1);
+      for (int cur_deme = 0; cur_deme < num_demes; cur_deme++) {
+        for (int test_deme = 0; test_deme < num_demes; test_deme++) {
+          if (deme_fitness[cur_deme] < deme_fitness[test_deme]) {
+            deme_rank[cur_deme]++;
+          }
+        }
+      }
+      // ... finally, make deme fitness 2^(-deme rank)
+      deme_fitness.SetAll(1);
+      for (int cur_deme = 0; cur_deme < num_demes; cur_deme++) {
+        for (int i = 0; i < deme_rank[cur_deme]; i++) {
+          deme_fitness[cur_deme] = deme_fitness[cur_deme]/2;
+        }
+        total_fitness += deme_fitness[cur_deme];
+      }
+    }
+      break;
+  } 
+  
+  // Pick which demes should be in the next generation.
+  tArray<int> new_demes(num_demes);
+  for (int i = 0; i < num_demes; i++) {
+    double birth_choice = (double) g_random.GetDouble(total_fitness);
+    double test_total = 0;
+    for (int test_deme = 0; test_deme < num_demes; test_deme++) {
+      test_total += deme_fitness[test_deme];
+      if (birth_choice < test_total) {
+        new_demes[i] = test_deme;
+        break;
+      }
+    }
+  }
+  
+  // Track how many of each deme we should have.
+  tArray<int> deme_count(num_demes);
+  deme_count.SetAll(0);
+  for (int i = 0; i < num_demes; i++) {
+    deme_count[new_demes[i]]++;
+  }
+  
+  tArray<bool> is_init(num_demes); 
+  is_init.SetAll(false);
+  
+  // Copy demes until all deme counts are 1.
+  while (true) {
+    // Find the next deme to copy...
+    int from_deme, to_deme;
+    for (from_deme = 0; from_deme < num_demes; from_deme++) {
+      if (deme_count[from_deme] > 1) break;
+    }
+    if (from_deme == num_demes) break; // If we don't find another deme to copy
+    
+    for (to_deme = 0; to_deme < num_demes; to_deme++) {
+      if (deme_count[to_deme] == 0) break;
+    }
+    
+    // We now have both a from and a to deme....
+    deme_count[from_deme]--;
+    deme_count[to_deme]++;
+    
+    // Do the actual copy!
+    for (int i = 0; i < deme_size; i++) {
+      int from_cell = from_deme * deme_size + i;
+      int to_cell = to_deme * deme_size + i;
+      if (cell_array[from_cell].IsOccupied() == true) {
+        InjectClone( to_cell, *(cell_array[from_cell].GetOrganism()) );
+      }
+    }
+    is_init[to_deme] = true;
+  }
+  
+  // Now re-inject all remaining demes into themselves to reset them.
+  for (int cur_deme = 0; cur_deme < num_demes; cur_deme++) {
+    if (is_init[cur_deme] == true) continue;
+    for (int i = 0; i < deme_size; i++) {
+      int cur_cell = cur_deme * deme_size + i;
+      if (cell_array[cur_cell].IsOccupied() == false) continue;
+      InjectClone( cur_cell, *(cell_array[cur_cell].GetOrganism()) );
+    }
+  }
+  
+  deme_birth_count.SetAll(0);
+}
+
+
+// Reset Demes goes through each deme and resets the individual organisms as
+// if they were just injected into the population.
+
+void cPopulation::ResetDemes()
+{
+  // re-inject all demes into themselves to reset them.
+  for (int cur_deme = 0; cur_deme < num_demes; cur_deme++) {
+    for (int i = 0; i < deme_size; i++) {
+      int cur_cell = cur_deme * deme_size + i;
+      if (cell_array[cur_cell].IsOccupied() == false) continue;
+      InjectClone( cur_cell, *(cell_array[cur_cell].GetOrganism()) );
+    }
+  }
+}
+
+// Copy the contents of one deme into another.
+void cPopulation::CopyDeme(int deme1_id, int deme2_id)
+{
+  for (int i = 0; i < deme_size; i++) {
+    int from_cell = deme1_id * deme_size + i;
+    int to_cell = deme2_id * deme_size + i;
+    if (cell_array[from_cell].IsOccupied() == false) {
+      KillOrganism(cell_array[to_cell]);
+      continue;
+    }
+    InjectClone( to_cell, *(cell_array[from_cell].GetOrganism()) );    
+  }
+}
+
+
+// Print out statistics about individual demes
+
+void cPopulation::PrintDemeStats()
+{
+  cDataFile & df_fit = stats.GetDataFile("deme_fitness.dat");
+  cDataFile & df_life_fit = stats.GetDataFile("deme_lifetime_fitness.dat");
+  cDataFile & df_merit = stats.GetDataFile("deme_merit.dat");
+  cDataFile & df_gest = stats.GetDataFile("deme_gest_time.dat");
+  cDataFile & df_task = stats.GetDataFile("deme_task.dat");
+  cDataFile & df_donor = stats.GetDataFile("deme_donor.dat");
+  cDataFile & df_receiver = stats.GetDataFile("deme_receiver.dat");
+  
+  df_fit.WriteComment("Average fitnesses for each deme in the population");
+  df_life_fit.WriteComment("Average life fitnesses for each deme in the population");
+  df_merit.WriteComment("Average merits for each deme in population");
+  df_gest.WriteComment("Average gestation time for each deme in population");
+  df_task.WriteComment("Num orgs doing each task for each deme in population");
+  df_donor.WriteComment("Num orgs doing doing a donate for each deme in population");
+  df_receiver.WriteComment("Num orgs doing receiving a donate for each deme in population");
+  
+  df_fit.WriteTimeStamp();
+  df_life_fit.WriteTimeStamp();
+  df_merit.WriteTimeStamp();
+  df_gest.WriteTimeStamp();
+  df_task.WriteTimeStamp();
+  df_donor.WriteTimeStamp();
+  df_receiver.WriteTimeStamp();
+  
+  df_fit.Write(GetUpdate(), "update");
+  df_life_fit.Write(GetUpdate(), "update");
+  df_merit.Write(GetUpdate(), "update");
+  df_gest.Write(GetUpdate(), "update");
+  df_task.Write(GetUpdate(), "update");
+  df_donor.Write(GetUpdate(), "update");
+  df_receiver.Write(GetUpdate(), "update");
+  
+  const int num_inst = cConfig::GetNumInstructions();
+  const int num_task = environment.GetTaskLib().GetSize();
+  
+  for (int cur_deme = 0; cur_deme < num_demes; cur_deme++) {
+    cString filename;
+    filename.Set("deme_instruction-%d.dat", cur_deme);
+    cDataFile & df_inst = stats.GetDataFile(filename); 
+    cString comment;
+    comment.Set("Number of times each instruction is exectued in deme %d",
+                cur_deme);
+    df_inst.WriteComment(comment);
+    df_inst.WriteTimeStamp();
+    df_inst.Write(GetUpdate(), "update");
+    
+    cDoubleSum single_deme_fitness;
+    cDoubleSum single_deme_life_fitness;
+    cDoubleSum single_deme_merit;
+    cDoubleSum single_deme_gest_time;
+    cDoubleSum single_deme_donor;
+    cDoubleSum single_deme_receiver;
+    tArray<cIntSum> single_deme_task(num_task);
+    tArray<cIntSum> single_deme_inst(num_inst);
+    
+    for (int i = 0; i < deme_size; i++) {
+      int cur_cell = cur_deme * deme_size + i;
+      if (cell_array[cur_cell].IsOccupied() == false) continue;
+      cPhenotype & phenotype = GetCell(cur_cell).GetOrganism()->GetPhenotype();
+      single_deme_fitness.Add(phenotype.GetFitness()); 	
+      single_deme_life_fitness.Add(phenotype.GetLifeFitness()); 	
+      single_deme_merit.Add(phenotype.GetMerit().GetDouble()); 	
+      single_deme_gest_time.Add(phenotype.GetGestationTime()); 	
+      single_deme_donor.Add(phenotype.IsDonorLast()); 	
+      single_deme_receiver.Add(phenotype.IsReceiver()); 	
+      
+      for (int j = 0; j < num_inst; j++) {
+        single_deme_inst[j].Add(phenotype.GetLastInstCount()[j]);
+      } 
+      
+      for (int j = 0; j < num_task; j++) {
+        // only interested in tasks is done once! 
+        if (phenotype.GetLastTaskCount().ElementAt(j) > 0) {
+          single_deme_task[j].Add(1);
+        }
+      }
+    }
+    
+    comment.Set("Deme %d", cur_deme);
+    df_fit.Write(single_deme_fitness.Ave(), comment);
+    df_life_fit.Write(single_deme_life_fitness.Ave(), comment);
+    df_merit.Write(single_deme_merit.Ave(), comment);
+    df_gest.Write(single_deme_gest_time.Ave(), comment);
+    df_donor.Write(single_deme_donor.Sum(), comment);
+    df_receiver.Write(single_deme_receiver.Sum(), comment);
+    
+    for (int j = 0; j < num_task; j++) {
+      comment.Set("Deme %d, Task %d", cur_deme, j);
+      df_task.Write((int) single_deme_task[j].Sum(), comment);
+    }
+    
+    for (int j = 0; j < num_inst; j++) {
+      comment.Set("Inst %d", j);
+      df_inst.Write((int) single_deme_inst[j].Sum(), comment);
+    }
+    df_inst.Endl();
+  } 
+  
+  df_fit.Endl();
+  df_life_fit.Endl();
+  df_merit.Endl();
+  df_gest.Endl();
+  df_task.Endl();
+  df_donor.Endl();
+  df_receiver.Endl();
+}
+
+
+/**
+* This function is responsible for adding an organism to a given lineage,
+ * and setting the organism's lineage label and the lineage pointer.
+ **/
+
+void cPopulation::LineageSetupOrganism(cOrganism * organism, cLineage * lin,
+                                       int lin_label, cGenotype *parent_genotype)
+{
+  // If we have some kind of lineage control, adjust the default values
+  // passed in.
+  if ( lineage_control ){
+    lin = lineage_control->
+    AddCreature(organism->GetGenotype(), parent_genotype, lin, lin_label);
+    lin_label = lin->GetID();
+  }
+  
+  organism->SetLineageLabel( lin_label );
+  organism->SetLineage( lin );
+}
+
+
+/**
+* This function directs which position function should be used.  It
+ * could have also been done with a function pointer, but the dividing
+ * of an organism takes enough time that this will be a negligible addition,
+ * and it gives a centralized function to work with.  The parent_ok flag asks
+ * if it is okay to replace the parent.
+ **/
+
+cPopulationCell & cPopulation::PositionChild(cPopulationCell & parent_cell,
+                                             bool parent_ok)
+{
+  assert(parent_cell.IsOccupied());
+  
+  const int birth_method = cConfig::GetBirthMethod();
+  
+  // Try out global/full-deme birth methods first...
+  
+  if (birth_method == POSITION_CHILD_FULL_SOUP_RANDOM) {
+    int out_pos = g_random.GetUInt(cell_array.GetSize());
+    while (parent_ok == false && out_pos == parent_cell.GetID()) {
+      out_pos = g_random.GetUInt(cell_array.GetSize());
+    }
+    return GetCell(out_pos);
+  }
+  else if (birth_method == POSITION_CHILD_FULL_SOUP_ELDEST) {
+    cPopulationCell * out_cell = reaper_queue.PopRear();
+    if (parent_ok == false && out_cell->GetID() == parent_cell.GetID()) {
+      out_cell = reaper_queue.PopRear();
+      reaper_queue.PushRear(&parent_cell);
+    }
+    return *out_cell;
+  }
+  else if (birth_method == POSITION_CHILD_DEME_RANDOM) {
+    const int parent_id = parent_cell.GetID();
+    const int cur_deme = parent_id / deme_size;
+    int out_pos = g_random.GetUInt(deme_size) + deme_size * cur_deme;
+    while (parent_ok == false && out_pos == parent_cell.GetID()) {
+      out_pos = g_random.GetUInt(deme_size) + deme_size * cur_deme;
+    }
+    deme_birth_count[cur_deme]++;
+    return GetCell(out_pos);    
+  }
+  
+  // Construct a list of equally viable locations to place the child...
+  tList<cPopulationCell> found_list;
+  
+  // First, check if there is an empty organism to work with (always preferred)
+  tList<cPopulationCell> & conn_list = parent_cell.ConnectionList();
+  
+  if (cConfig::GetPreferEmpty() == false &&
+      birth_method == POSITION_CHILD_RANDOM) {
+    found_list.Append(conn_list);
+    if (parent_ok == true) found_list.Push(&parent_cell);
+  } else {
+    FindEmptyCell(conn_list, found_list);
+  }
+  
+  // If we have not found an empty organism, we must use the specified function
+  // to determine how to choose among the filled organisms.
+  if (found_list.GetSize() == 0) {
+    switch(birth_method) {
+      case POSITION_CHILD_AGE:
+        PositionAge(parent_cell, found_list, parent_ok);
+        break;
+      case POSITION_CHILD_MERIT:
+        PositionMerit(parent_cell, found_list, parent_ok);
+        break;
+      case POSITION_CHILD_RANDOM:
+        found_list.Append(conn_list);
+        if (parent_ok == true) found_list.Push(&parent_cell);
+          break;
+      case POSITION_CHILD_EMPTY:
+        // Nothing is in list if no empty cells are found...
+        break;
+    }
+  }
+  
+  if (num_demes > 0) {
+    const int parent_id = parent_cell.GetID();
+    const int cur_deme = parent_id / deme_size;
+    deme_birth_count[cur_deme]++;
+  }
+  
+  // If there are no possibilities, return parent.
+  if (found_list.GetSize() == 0) return parent_cell;
+  
+  // Choose the organism randomly from those in the list, and return it.
+  int choice = g_random.GetUInt(found_list.GetSize());
+  return *( found_list.GetPos(choice) );
+}
+
+
+int cPopulation::ScheduleOrganism()
+{
+  return schedule->GetNextID();
+}
+
+void cPopulation::ProcessStep(double step_size, int cell_id)
+{
+  assert(step_size > 0.0);
+  assert(cell_id < cell_array.GetSize());
+  
+  // If cell_id is negative, no cell could be found -- stop here.
+  if (cell_id < 0) return;
+  
+  cPopulationCell & cell = GetCell(cell_id);
+  assert(cell.IsOccupied()); // Unoccupied cell getting processor time!
+  
+  //    static ofstream debug_fp("debug.trace");
+  //    debug_fp << stats.GetUpdate() << " "
+  //  	   << cell.GetOrganism()->GetCellID() << " "
+  //  	   << cell.GetOrganism()->GetGenotype()->GetID() << " "
+  //  	   << g_random.GetDouble() << " "
+  //      	   << cell.GetOrganism()->GetHardware().GetMemory().AsString() << " "
+  //  	   << endl;
+  
+  cOrganism * cur_org = cell.GetOrganism();
+  cur_org->GetHardware().SingleProcess();
+  if (cur_org->GetPhenotype().GetToDelete() == true) {
+    delete cur_org;
+  }
+  stats.IncExecuted();
+  resource_count.Update(step_size);
+}
+
+
+void cPopulation::ProcessStep(double step_size)
+{
+  ProcessStep( step_size, ScheduleOrganism() );
+}
+
+
+void cPopulation::UpdateOrganismStats()
+{
+  // Loop through all the cells getting stats and doing calculations
+  // which must be done on a creature by creature basis.
+  
+  // Clear out organism sums...
+  stats.SumFitness().Clear();
+  stats.SumGestation().Clear();
+  stats.SumMerit().Clear();
+  stats.SumCreatureAge().Clear();
+  stats.SumGeneration().Clear();
+  stats.SumNeutralMetric().Clear();
+  stats.SumLineageLabel().Clear();
+  stats.SumCopyMutRate().Clear();
+  stats.SumDivMutRate().Clear();
+  stats.SumCopySize().Clear();
+  stats.SumExeSize().Clear();
+  stats.SumMemSize().Clear();
+  
+  
+  stats.ZeroTasks();
+  
+#ifdef INSTRUCTION_COUNT
+  stats.ZeroInst();
+#endif
+  
+  // Counts...
+  int num_breed_true = 0;
+  int num_parasites = 0;
+  int num_no_birth = 0;
+  int num_multi_thread = 0;
+  int num_single_thread = 0;
+  int num_modified = 0;
+  
+  // Maximums...
+  cMerit max_merit(0);
+  double max_fitness = 0;
+  int max_gestation_time = 0;
+  int max_genome_length = 0;
+  
+  // Minimums...
+  cMerit min_merit(HUGE_VAL);
+  double min_fitness = HUGE_VAL;
+  int min_gestation_time = INT_MAX;
+  int min_genome_length = INT_MAX;
+  
+  for (int i = 0; i < cell_array.GetSize(); i++) {
+    // Only look at cells with organisms in them.
+    if (cell_array[i].IsOccupied() == false) {
+
+      // Genotype map needs zero for all non-occupied cells
+
+      stats.SetGenoMapElement(i, 0);
+      continue;
+    }
+
+    cOrganism * organism = cell_array[i].GetOrganism();
+    const cPhenotype & phenotype = organism->GetPhenotype();
+    const cMerit cur_merit = phenotype.GetMerit();
+    const double cur_fitness = phenotype.GetFitness();
+    const int cur_gestation_time = phenotype.GetGestationTime();
+    const int cur_genome_length = phenotype.GetGenomeLength();
+    
+    stats.SumFitness().Add(cur_fitness);
+    stats.SumMerit().Add(cur_merit.GetDouble());
+    stats.SumGestation().Add(phenotype.GetGestationTime());
+    stats.SumCreatureAge().Add(phenotype.GetAge());
+    stats.SumGeneration().Add(phenotype.GetGeneration());
+    stats.SumNeutralMetric().Add(phenotype.GetNeutralMetric());
+    stats.SumLineageLabel().Add(organism->GetLineageLabel());
+    stats.SumCopyMutRate().Add(organism->MutationRates().GetCopyMutProb());
+    stats.SumLogCopyMutRate().Add(log(organism->MutationRates().GetCopyMutProb()));
+    stats.SumDivMutRate().Add(organism->MutationRates().GetDivMutProb() / organism->GetPhenotype().GetDivType());
+    stats.SumLogDivMutRate().Add(log(organism->MutationRates().GetDivMutProb() /organism->GetPhenotype().GetDivType()));
+    stats.SumCopySize().Add(phenotype.GetCopiedSize());
+    stats.SumExeSize().Add(phenotype.GetExecutedSize());
+    stats.SetGenoMapElement(i, organism->GetGenotype()->GetID());
+    
+#ifdef INSTRUCTION_COUNT
+    //    for (int j=0; j < environment.GetInstSet().GetSize(); j++) {
+    for (int j=0; j < cConfig::GetNumInstructions(); j++) {
+      stats.SumExeInst()[j].Add(organism->GetPhenotype().GetLastInstCount()[j]);
+    }
+#endif
+    
+    if (cur_merit > max_merit) max_merit = cur_merit;
+    if (cur_fitness > max_fitness) max_fitness = cur_fitness;
+    if (cur_gestation_time > max_gestation_time) max_gestation_time = cur_gestation_time;
+    if (cur_genome_length > max_genome_length) max_genome_length = cur_genome_length;
+    
+    if (cur_merit < min_merit) min_merit = cur_merit;
+    if (cur_fitness < min_fitness) min_fitness = cur_fitness;
+    if (cur_gestation_time < min_gestation_time) min_gestation_time = cur_gestation_time;
+    if (cur_genome_length < min_genome_length) min_genome_length = cur_genome_length;
+    
+    // Test what tasks this creatures has completed.
+    for (int j=0; j < phenotype.GetEnvironment().GetTaskLib().GetSize(); j++) {
+      if (phenotype.GetCurTaskCount()[j] > 0)  stats.AddCurTask(j);
+      if (phenotype.GetLastTaskCount()[j] > 0) stats.AddLastTask(j);
+      if (phenotype.GetLastTaskCount()[j] > 0) 
+        stats.IncTaskExeCount(j, phenotype.GetLastTaskCount()[j]);
+    }
+    
+    // Increment the counts for all qualities the organism has...
+    if (phenotype.ParentTrue()) num_breed_true++;
+    if (phenotype.IsParasite()) num_parasites++;
+    if( phenotype.GetNumDivides() == 0 ) num_no_birth++;
+    if(phenotype.IsMultiThread()) num_multi_thread++;
+    else num_single_thread++;
+    if(phenotype.IsModified()) num_modified++;
+    
+    // Hardware specific collections...
+    if (organism->GetHardware().GetType() == HARDWARE_TYPE_CPU_ORIGINAL) {
+      cHardwareBase & hardware = organism->GetHardware();
+      stats.SumMemSize().Add(hardware.GetMemory().GetSize());
+    }
+    
+    // Increment the age of this organism.
+    organism->GetPhenotype().IncAge();
+    }
+  
+  stats.SetBreedTrueCreatures(num_breed_true);
+  stats.SetNumNoBirthCreatures(num_no_birth);
+  stats.SetNumParasites(num_parasites);
+  stats.SetNumSingleThreadCreatures(num_single_thread);
+  stats.SetNumMultiThreadCreatures(num_multi_thread);
+  stats.SetNumModified(num_modified);
+  
+  stats.SetMaxMerit(max_merit.GetDouble());
+  stats.SetMaxFitness(max_fitness);
+  stats.SetMaxGestationTime(max_gestation_time);
+  stats.SetMaxGenomeLength(max_genome_length);
+  
+  stats.SetMinMerit(min_merit.GetDouble());
+  stats.SetMinFitness(min_fitness);
+  stats.SetMinGestationTime(min_gestation_time);
+  stats.SetMinGenomeLength(min_genome_length);
+  
+  stats.SetResources(resource_count.GetResources());
+  stats.SetSpatialRes(resource_count.GetSpatialRes());
+  stats.SetResourcesGeometry(resource_count.GetResourcesGeometry());
+  }
+
+
+void cPopulation::UpdateGenotypeStats()
+{
+  // Loop through all genotypes, finding stats and doing calcuations.
+  
+  // Clear out genotype sums...
+  stats.SumGenotypeAge().Clear();
+  stats.SumAbundance().Clear();
+  stats.SumGenotypeDepth().Clear();
+  stats.SumSize().Clear();
+  stats.SumThresholdAge().Clear();
+  
+  double entropy = 0.0;
+  
+  cGenotype * cur_genotype = genebank->GetBestGenotype();
+  for (int i = 0; i < genebank->GetSize(); i++) {
+    const int abundance = cur_genotype->GetNumOrganisms();
+    
+    // If we're at a dead genotype, we've hit the end of the list!
+    if (abundance == 0) break;
+    
+    // Update stats...
+    const int age = stats.GetUpdate() - cur_genotype->GetUpdateBorn();
+    stats.SumGenotypeAge().Add(age, abundance);
+    stats.SumAbundance().Add(abundance);
+    stats.SumGenotypeDepth().Add(cur_genotype->GetDepth(), abundance);
+    stats.SumSize().Add(cur_genotype->GetLength(), abundance);
+    
+    // Calculate this genotype's contribution to entropy
+    const double p = ((double) abundance) / (double) num_organisms;
+    const double partial_ent = -(p * Log(p));
+    entropy += partial_ent;
+    
+    // Do any special calculations for threshold genotypes.
+    if (cur_genotype->GetThreshold()) {
+      stats.SumThresholdAge().Add(age, abundance);
+    }
+    
+    // ...and advance to the next genotype...
+    cur_genotype = cur_genotype->GetNext();
+  }
+  
+  stats.SetEntropy(entropy);
+}
+
+
+void cPopulation::UpdateSpeciesStats()
+{
+  double species_entropy = 0.0;
+  
+  stats.SumSpeciesAge().Clear();
+  
+  // Loop through all species that need to be reset prior to calculations.
+  cSpecies * cur_species = genebank->GetFirstSpecies();
+  for (int i = 0; i < genebank->GetNumSpecies(); i++) {
+    cur_species->ResetStats();
+    cur_species = cur_species->GetNext();
+  }
+  
+  // Collect info from genotypes and send it to their species.
+  cGenotype * genotype = genebank->GetBestGenotype();
+  for (int i = 0; i < genebank->GetSize(); i++) {
+    if (genotype->GetSpecies() != NULL) {
+      genotype->GetSpecies()->AddOrganisms(genotype->GetNumOrganisms());
+    }
+    genotype = genotype->GetNext();
+  }
+  
+  // Loop through all of the species in the soup, taking info on them.
+  cur_species = genebank->GetFirstSpecies();
+  for (int i = 0; i < genebank->GetNumSpecies(); i++) {
+    const int abundance = cur_species->GetNumOrganisms();
+    // const int num_genotypes = cur_species->GetNumGenotypes();
+    
+    // Basic statistical collection...
+    const int species_age = stats.GetUpdate() - cur_species->GetUpdateBorn();
+    stats.SumSpeciesAge().Add(species_age, abundance);
+    
+    // Caculate entropy on the species level...
+    if (abundance > 0) {
+      double p = ((double) abundance) / (double) num_organisms;
+      double partial_ent = -(p * Log(p));
+      species_entropy += partial_ent;
+    }
+    
+    // ...and advance to the next species...
+    cur_species = cur_species->GetNext();
+  }
+  
+  stats.SetSpeciesEntropy(species_entropy);
+}
+
+void cPopulation::UpdateDominantStats()
+{
+  cGenotype * dom_genotype = genebank->GetBestGenotype();
+  if (dom_genotype == NULL) return;
+  
+  stats.SetDomGenotype(dom_genotype);
+  stats.SetDomMerit(dom_genotype->GetMerit());
+  stats.SetDomGestation(dom_genotype->GetGestationTime());
+  stats.SetDomReproRate(dom_genotype->GetReproRate());
+  stats.SetDomFitness(dom_genotype->GetFitness());
+  stats.SetDomCopiedSize(dom_genotype->GetCopiedSize());
+  stats.SetDomExeSize(dom_genotype->GetExecutedSize());
+  
+  stats.SetDomSize(dom_genotype->GetLength());
+  stats.SetDomID(dom_genotype->GetID());
+  stats.SetDomName(dom_genotype->GetName());
+  stats.SetDomBirths(dom_genotype->GetThisBirths());
+  stats.SetDomBreedTrue(dom_genotype->GetThisBreedTrue());
+  stats.SetDomBreedIn(dom_genotype->GetThisBreedIn());
+  stats.SetDomBreedOut(dom_genotype->GetThisBreedOut());
+  stats.SetDomAbundance(dom_genotype->GetNumOrganisms());
+  stats.SetDomGeneDepth(dom_genotype->GetDepth());
+  stats.SetDomSequence(dom_genotype->GetGenome().AsString());
+}
+
+void cPopulation::UpdateDominantParaStats()
+{
+  cInjectGenotype * dom_inj_genotype = inject_genebank->GetBestInjectGenotype();
+  if (dom_inj_genotype == NULL) return;
+  
+  stats.SetDomInjGenotype(dom_inj_genotype);
+  //stats.SetDomMerit(dom_genotype->GetMerit());
+  //stats.SetDomGestation(dom_genotype->GetGestationTime());
+  //stats.SetDomReproRate(dom_genotype->GetReproRate());
+  //stats.SetDomFitness(dom_genotype->GetFitness());
+  //stats.SetDomCopiedSize(dom_genotype->GetCopiedSize());
+  //stats.SetDomExeSize(dom_genotype->GetExecutedSize());
+  
+  stats.SetDomInjSize(dom_inj_genotype->GetLength());
+  stats.SetDomInjID(dom_inj_genotype->GetID());
+  stats.SetDomInjName(dom_inj_genotype->GetName());
+  //stats.SetDomInjBirths(dom_inj_genotype->GetThisBirths());
+  //stats.SetDomBreedTrue(dom_genotype->GetThisBreedTrue());
+  //stats.SetDomBreedIn(dom_genotype->GetThisBreedIn());
+  //stats.SetDomBreedOut(dom_genotype->GetThisBreedOut());
+  stats.SetDomInjAbundance(dom_inj_genotype->GetNumInjected());
+  //stats.SetDomInjGeneDepth(dom_inj_genotype->GetDepth());
+  stats.SetDomInjSequence(dom_inj_genotype->GetGenome().AsString());
+}
+
+void cPopulation::CalcUpdateStats()
+{
+  // Reset the Genebank to prepare it for stat collection.
+  genebank->UpdateReset();
+  
+  UpdateOrganismStats();
+  UpdateGenotypeStats();
+  UpdateSpeciesStats();
+  UpdateDominantStats();
+  UpdateDominantParaStats();
+  
+  // Do any final calculations...
+  stats.SetNumCreatures(GetNumOrganisms());
+  stats.SetNumGenotypes(genebank->GetSize());
+  stats.SetNumThreshSpecies(genebank->GetNumSpecies());
+  
+  // Have stats calculate anything it now can...
+  stats.CalcEnergy();
+  stats.CalcFidelity();
+}
+
+
+bool cPopulation::SaveClone(ofstream & fp)
+{
+  if (fp.good() == false) return false;
+  
+  // Save the current update
+  fp << stats.GetUpdate() << " ";
+  
+  // Save the genebank info.
+  genebank->SaveClone(fp);
+  
+  // Save the genotypes manually.
+  fp << genebank->GetSize() << " ";
+  
+  cGenotype * cur_genotype = genebank->GetBestGenotype();
+  for (int i = 0; i < genebank->GetSize(); i++) {
+    cur_genotype->SaveClone(fp);
+    
+    // Advance...
+    cur_genotype = cur_genotype->GetNext();
+  }
+  
+  // Save the organim layout...
+  fp << cell_array.GetSize() << " ";
+  for (int i = 0; i < cell_array.GetSize(); i++) {
+    if (cell_array[i].IsOccupied() == true) {
+      fp <<  cell_array[i].GetOrganism()->GetGenotype()->GetID() << " ";
+    }
+    else fp << "-1 ";
+  }
+  
+  return true;
+}
+
+
+bool cPopulation::LoadClone(ifstream & fp)
+{
+  if (fp.good() == false) return false;
+  
+  // Pick up the update where it was left off.
+  int cur_update;
+  fp >> cur_update;
+  
+  stats.SetCurrentUpdate(cur_update);
+  
+  // Clear out the population
+  for (int i = 0; i < cell_array.GetSize(); i++) KillOrganism(cell_array[i]);
+  
+  // Load the genebank info.
+  genebank->LoadClone(fp);
+  
+  // Load up the genotypes.
+  int num_genotypes = 0;
+  fp >> num_genotypes;
+  
+  cGenotype * genotype_array = new cGenotype[num_genotypes];
+  for (int i = 0; i < num_genotypes; i++) genotype_array[i].LoadClone(fp);
+  
+  // Now load them into the organims.  @CAO make sure cell_array.GetSize() is right!
+  int in_num_cells;
+  int genotype_id;
+  fp >> in_num_cells;
+  if (cell_array.GetSize() != in_num_cells) return false;
+  
+  for (int i = 0; i < cell_array.GetSize(); i++) {
+    fp >> genotype_id;
+    if (genotype_id == -1) continue;
+    int genotype_index = -1;
+    for (int j = 0; j < num_genotypes; j++) {
+      if (genotype_array[j].GetID() == genotype_id) {
+        genotype_index = j;
+        break;
+      }
+    }
+    
+    assert(genotype_index != -1);
+    InjectGenome(i, genotype_array[genotype_index].GetGenome(), 0);
+  }
+  
+  sync_events = true;
+  
+  return true;
+}
+
+// This class is needed for the next function
+class cTmpGenotype {
+public:
+  int id_num;
+  int parent_id;
+  int num_cpus;
+  int total_cpus;
+  double merit;
+  int update_born;
+  int update_dead;
+  
+  cGenotype *genotype;
+  
+  bool operator<( const cTmpGenotype rhs ) const {
+    return id_num < rhs.id_num; }
+};	
+
+
+bool cPopulation::LoadDumpFile(cString filename, int update)
+{
+  // set the update if requested
+  if ( update >= 0 )
+    stats.SetCurrentUpdate(update);
+  
+  // Clear out the population
+  for (int i = 0; i < cell_array.GetSize(); i++) KillOrganism(cell_array[i]);
+  
+  cout << "Loading: " << filename << endl;
+  
+  cInitFile input_file(filename);
+  if (!input_file.IsOpen()) {
+    cerr << "Error: Cannot load file: \"" << filename << "\"." << endl;
+    exit(1);
+  }
+  input_file.Load();
+  input_file.Compress();
+  input_file.Close();
+  
+  // First, we read in all the genotypes and store them in a list
+  
+  vector<cTmpGenotype> genotype_vect;
+  
+  for (int line_id = 0; line_id < input_file.GetNumLines(); line_id++) {
+    cString cur_line = input_file.GetLine(line_id);
+    
+    // Setup the genotype for this line...
+    cTmpGenotype tmp;
+    tmp.id_num      = cur_line.PopWord().AsInt();
+    tmp.parent_id   = cur_line.PopWord().AsInt();
+    /*parent_dist =*/          cur_line.PopWord().AsInt();
+    tmp.num_cpus    = cur_line.PopWord().AsInt();
+    tmp.total_cpus  = cur_line.PopWord().AsInt();
+    /*length      =*/          cur_line.PopWord().AsInt();
+    tmp.merit 	    = cur_line.PopWord().AsDouble();
+    /*gest_time   =*/ cur_line.PopWord().AsInt();
+    /*fitness     =*/ cur_line.PopWord().AsDouble();
+    tmp.update_born = cur_line.PopWord().AsInt();
+    tmp.update_dead = cur_line.PopWord().AsInt();
+    /*depth       =*/ cur_line.PopWord().AsInt();
+    cString name = cStringUtil::Stringf("org-%d", tmp.id_num);
+    cGenome genome( cur_line.PopWord() );
+    
+    // we don't allow birth or death times larger than the current update
+    if ( stats.GetUpdate() > tmp.update_born )
+      tmp.update_born = stats.GetUpdate();
+    if ( stats.GetUpdate() > tmp.update_dead )
+      tmp.update_dead = stats.GetUpdate();
+    
+    tmp.genotype =
+      new cGenotype(tmp.update_born, tmp.id_num);
+    tmp.genotype->SetGenome( genome );
+    tmp.genotype->SetName( name );
+    
+    genotype_vect.push_back( tmp );
+  }
+  
+  // now, we sort them in ascending order according to their id_num
+  sort( genotype_vect.begin(), genotype_vect.end() );
+  // set the parents correctly
+  
+  vector<cTmpGenotype>::const_iterator it = genotype_vect.begin();
+  for ( ; it != genotype_vect.end(); it++ ){
+    vector<cTmpGenotype>::const_iterator it2 = it;
+    cGenotype *parent = 0;
+    // search backwards till we find the parent
+    if ( it2 != genotype_vect.begin() )
+      do{
+        it2--;
+        if ( (*it).parent_id == (*it2).id_num ){
+          parent = (*it2).genotype;
+          break;
+        }	
+      }
+        while ( it2 != genotype_vect.begin() );
+    (*it).genotype->SetParent( parent, NULL );
+  }
+  
+  int cur_update = stats.GetUpdate(); 
+  int current_cell = 0;
+  bool soup_full = false;
+  it = genotype_vect.begin();
+  for ( ; it != genotype_vect.end(); it++ ){
+    genebank->AddGenotype( (*it).genotype );
+    if ( (*it).num_cpus == 0 ){ // historic organism
+                                // remove immediately, so that it gets transferred into the
+                                // historic database. We change the update temporarily to the
+                                // true death time of this organism, so that all stats are correct.
+      stats.SetCurrentUpdate( (*it).update_dead );
+      genebank->RemoveGenotype( *(*it).genotype );
+      stats.SetCurrentUpdate( cur_update );
+    }
+    else{ // otherwise, we insert as many organisms as we need
+      for ( int i=0; i<(*it).num_cpus; i++ ){
+        if ( current_cell >= cell_array.GetSize() ){
+          soup_full = true;
+          break;
+        }	  
+        InjectGenotype( current_cell, (*it).genotype );
+        cPhenotype & phenotype = GetCell(current_cell).GetOrganism()->GetPhenotype();
+        if ( (*it).merit > 0) phenotype.SetMerit( cMerit((*it).merit) );
+        schedule->Adjust(current_cell, phenotype.GetMerit());
+        
+        int lineage_label = 0;
+        LineageSetupOrganism(GetCell(current_cell).GetOrganism(),
+                             0, lineage_label,
+                             (*it).genotype->GetParentGenotype());
+        current_cell += 1;
+      }
+    }
+    cout << (*it).id_num << " "
+      << (*it).parent_id << " "
+      << (*it).genotype->GetParentID() << " "
+      << (*it).genotype->GetNumOffspringGenotypes() << " "
+      << (*it).num_cpus << " "
+      << (*it).genotype->GetNumOrganisms() << endl;
+    if (soup_full){
+      cout << "cPopulation::LoadDumpFile: You are trying to load more organisms than there is space!" << endl;
+      cout << "cPopulation::LoadDumpFile: Remaining organisms are ignored." << endl;
+      break;
+    }
+  }
+  sync_events = true;
+  
+  return true;
+}
+
+//// Save And Load Populations ////
+bool cPopulation::SavePopulation(ofstream & fp)
+{
+  if (fp.good() == false) return false;
+  
+  // Save the update
+  fp << stats.GetUpdate() << endl;
+  
+  // looping through all cells saving state.
+  for (int i = 0; i < cell_array.GetSize(); i++)  cell_array[i].SaveState(fp);
+  
+  return true;
+}
+
+
+bool cPopulation::LoadPopulation(ifstream & fp)
+{
+  if(fp.good() == false) return false;
+  
+  // Load Update...
+  int cur_update;
+  fp >> cur_update;
+  stats.SetCurrentUpdate(cur_update);
+  
+  // Clear out the current population
+  for (int i = 0; i < cell_array.GetSize(); i++) KillOrganism( cell_array[i] );
+  
+  // looping through all organims
+  for (int i = 0; i < cell_array.GetSize(); i++) cell_array[i].LoadState(fp);
+  
+  sync_events = true;
+  
+  return true;
+}
+
+
+bool cPopulation::DumpMemorySummary(ofstream & fp)
+{
+  if (fp.good() == false) return false;
+  
+  // Dump the memory...
+  
+  for (int i = 0; i < cell_array.GetSize(); i++) {
+    fp << i << " ";
+    if (cell_array[i].IsOccupied() == false) {
+      fp << "EMPTY" << endl;
+    }
+    else {
+      cGenome & mem = cell_array[i].GetOrganism()->GetHardware().GetMemory();
+      fp << mem.GetSize() << " "
+        << mem.AsString() << endl;
+    }
+  }
+  return true;
+}
+
+bool cPopulation::OK()
+{
+  // First check all sub-objects...
+  if (!genebank->OK() || !schedule->OK()) return false;
+  
+  // Next check organisms...
+  for (int i = 0; i < cell_array.GetSize(); i++) {
+    if (cell_array[i].OK() == false) return false;
+    assert(cell_array[i].GetID() == i);
+  }
+  
+  // And stats...
+  assert(world_x * world_y == cell_array.GetSize());
+  
+  return true;
+}
+
+
+/**
+* This function loads a genome from a given file, and initializes
+ * a cpu with it.
+ *
+ * @param filename The name of the file to load.
+ * @param in_cpu The grid-position into which the genome should be loaded.
+ * @param merit An initial merit value.
+ * @param lineage_label A value that allows to track the daughters of
+ * this organism.
+ **/
+
+void cPopulation::Inject(const cGenome & genome, int cell_id, double merit, 
+                         int lineage_label, double neutral, int mem_space )
+{
+  // If an invalid cell was given, choose a new ID for it.
+  if (cell_id < 0) {
+    switch (cConfig::GetBirthMethod()) {
+      case POSITION_CHILD_FULL_SOUP_ELDEST:
+        cell_id = reaper_queue.PopRear()->GetID();
+      default:
+        cell_id = 0;
+    }
+  }
+  
+  if(mem_space==0) {
+    InjectGenome( cell_id, genome, lineage_label );
+    cPhenotype & phenotype = GetCell(cell_id).GetOrganism()->GetPhenotype();
+    phenotype.SetNeutralMetric(neutral);
+    
+    if (merit > 0) phenotype.SetMerit( cMerit(merit) );
+    schedule->Adjust(cell_id, phenotype.GetMerit());
+    
+    LineageSetupOrganism(GetCell(cell_id).GetOrganism(), 0, lineage_label);
+  }
+  else
+  {
+    ActivateInject(cell_id, genome);
+  }
+  
+}
+
+cPopulationCell & cPopulation::GetCell(int in_num)
+{
+  return cell_array[in_num];
+}
+
+
+void cPopulation::UpdateResources(const tArray<double> & res_change)
+{
+  resource_count.Modify(res_change);
+}
+
+void cPopulation::UpdateResource(int id, double change)
+{
+  resource_count.Modify(id, change);
+}
+
+void cPopulation::UpdateCellResources(const tArray<double> & res_change, 
+                                      const int cell_id)
+{
+  resource_count.ModifyCell(res_change, cell_id);
+}
+
+void cPopulation::SetResource(int id, double new_level)
+{
+  resource_count.Set(id, new_level);
+}
+
+void cPopulation::BuildTimeSlicer(cChangeList * change_list)
+{
+  switch (cConfig::GetSlicingMethod()) {
+    case SLICE_CONSTANT:
+      schedule = new cConstSchedule(cell_array.GetSize());
+      break;
+    case SLICE_PROB_MERIT:
+      schedule = new cProbSchedule(cell_array.GetSize());
+      break;
+    case SLICE_INTEGRATED_MERIT:
+      schedule = new cIntegratedSchedule(cell_array.GetSize());
+      break;
+    default:
+      cout << "Warning: Requested Time Slicer not found, defaulting to Integrated." << endl;
+      schedule = new cIntegratedSchedule(cell_array.GetSize());
+      break;
+  }
+  schedule->SetChangeList(change_list);
+}
+
+
+void cPopulation::PositionAge(cPopulationCell & parent_cell,
+                              tList<cPopulationCell> & found_list,
+                              bool parent_ok)
+{
+  // Start with the parent organism as the replacement, and see if we can find
+  // anything equivilent or better.
+  
+  found_list.Push(&parent_cell);
+  int max_age = parent_cell.GetOrganism()->GetPhenotype().GetAge();
+  if (parent_ok == false) max_age = -1;
+  
+  // Now look at all of the neighbors.
+  tListIterator<cPopulationCell> conn_it( parent_cell.ConnectionList() );
+  
+  cPopulationCell * test_cell;
+  while ( (test_cell = conn_it.Next()) != NULL) {
+    const int cur_age = test_cell->GetOrganism()->GetPhenotype().GetAge();
+    if (cur_age > max_age) {
+      max_age = cur_age;
+      found_list.Clear();
+      found_list.Push(test_cell);
+    }
+    else if (cur_age == max_age) {
+      found_list.Push(test_cell);
+    }
+  }
+}
+
+void cPopulation::PositionMerit(cPopulationCell & parent_cell,
+                                tList<cPopulationCell> & found_list,
+                                bool parent_ok)
+{
+  // Start with the parent organism as the replacement, and see if we can find
+  // anything equivilent or better.
+  
+  found_list.Push(&parent_cell);
+  double max_ratio = parent_cell.GetOrganism()->CalcMeritRatio();
+  if (parent_ok == false) max_ratio = -1;
+  
+  // Now look at all of the neighbors.
+  tListIterator<cPopulationCell> conn_it( parent_cell.ConnectionList() );
+  
+  cPopulationCell * test_cell;
+  while ( (test_cell = conn_it.Next()) != NULL) {
+    const double cur_ratio = test_cell->GetOrganism()->CalcMeritRatio();
+    if (cur_ratio > max_ratio) {
+      max_ratio = cur_ratio;
+      found_list.Clear();
+      found_list.Push(test_cell);
+    }
+    else if (cur_ratio == max_ratio) {
+      found_list.Push(test_cell);
+    }
+  }
+}
+
+void cPopulation::FindEmptyCell(tList<cPopulationCell> & cell_list,
+                                tList<cPopulationCell> & found_list)
+{
+  tListIterator<cPopulationCell> cell_it(cell_list);
+  cPopulationCell * test_cell;
+  
+  while ( (test_cell = cell_it.Next()) != NULL) {
+    // If this cell is empty, add it to the list...
+    if (test_cell->IsOccupied() == false) found_list.Push(test_cell);
+  }
+}
+
+// This function injects a new organism into the population at cell_id based
+// on the genotype passed in.
+
+void cPopulation::InjectGenotype(int cell_id, cGenotype *new_genotype)
+{
+  assert(cell_id >= 0 && cell_id < cell_array.GetSize());
+  
+  cOrganism * new_organism = new cOrganism(new_genotype->GetGenome(),
+                                           default_interface,
+                                           environment);
+  
+  // Set the genotype...
+  new_organism->SetGenotype(new_genotype);
+  
+  // Setup the phenotype...
+  cPhenotype & phenotype = new_organism->GetPhenotype();
+  phenotype.SetupInject(new_genotype->GetLength());
+  phenotype.SetMerit( cMerit(new_genotype->GetTestMerit()) );
+  
+  // @CAO are these really needed?
+  phenotype.SetLinesCopied( new_genotype->GetTestCopiedSize() );
+  phenotype.SetLinesExecuted( new_genotype->GetTestExecutedSize() );
+  phenotype.SetGestationTime( new_genotype->GetTestGestationTime() );
+  
+  // Prep the cell..
+  if (cConfig::GetBirthMethod() == POSITION_CHILD_FULL_SOUP_ELDEST &&
+      cell_array[cell_id].IsOccupied() == true) {
+    // Have to manually take this cell out of the reaper Queue.
+    reaper_queue.Remove( &(cell_array[cell_id]) );
+  }
+  
+  // Setup the child's mutation rates.  Since this organism is being injected
+  // and has no parent, we should always take the rate from the environment.
+  new_organism->MutationRates().Copy(cell_array[cell_id].MutationRates());
+  
+  
+  // Activate the organism in the population...
+  ActivateOrganism(new_organism, cell_array[cell_id]);
+}
+
+
+// This function injects a new organism into the population at cell_id that
+// is an exact clone of the organism passed in.
+
+void cPopulation::InjectClone(int cell_id, cOrganism & orig_org)
+{
+  assert(cell_id >= 0 && cell_id < cell_array.GetSize());
+  
+  cOrganism * new_organism = new cOrganism(orig_org.GetGenome(),
+                                           default_interface, environment);
+  
+  // Set the genotype...
+  new_organism->SetGenotype(orig_org.GetGenotype());
+  
+  // Setup the phenotype...
+  new_organism->GetPhenotype().SetupClone(orig_org.GetPhenotype());
+  
+  // Prep the cell..
+  if (cConfig::GetBirthMethod() == POSITION_CHILD_FULL_SOUP_ELDEST &&
+      cell_array[cell_id].IsOccupied() == true) {
+    // Have to manually take this cell out of the reaper Queue.
+    reaper_queue.Remove( &(cell_array[cell_id]) );
+  }
+  
+  // Setup the mutation rate based on the population cell...
+  new_organism->MutationRates().Copy(cell_array[cell_id].MutationRates());
+  
+  // Activate the organism in the population...
+  ActivateOrganism(new_organism, cell_array[cell_id]);
+}
+
+
+void cPopulation::InjectGenome(int cell_id, const cGenome & genome,
+                               int lineage_label)
+{
+  // Setup the genotype...
+  cGenotype * new_genotype = genebank->InjectGenotype(genome, lineage_label);
+  
+  // The rest is done by InjectGenotype();
+  InjectGenotype( cell_id, new_genotype );
+}
+
+
+void cPopulation::SerialTransfer(int transfer_size, bool ignore_deads)
+{
+  assert(transfer_size > 0);
+  
+  // If we are ignoring all dead organisms, remove them from the population.
+  if (ignore_deads == true) {
+    for (int i = 0; i < GetSize(); i++) {
+      cPopulationCell & cell = cell_array[i];
+      if (cell.IsOccupied() && cell.GetOrganism()->GetTestFitness() == 0.0) {
+        KillOrganism(cell);
+      }
+    }
+  }
+  
+  // If removing the dead was enough, stop here.
+  if (num_organisms <= transfer_size) return;
+  
+  // Collect a vector of the occupied cells...
+  vector<int> transfer_pool;
+  transfer_pool.reserve(num_organisms);
+  for (int i = 0; i < GetSize(); i++) {
+    if (cell_array[i].IsOccupied()) transfer_pool.push_back(i);
+  }
+  
+  // Remove the proper number of cells.
+  const int removal_size = num_organisms - transfer_size;
+  for (int i = 0; i < removal_size; i++) {
+    int j = (int) g_random.GetUInt(transfer_pool.size());
+    KillOrganism(cell_array[transfer_pool[j]]);
+    transfer_pool[j] = transfer_pool.back();
+    transfer_pool.pop_back();
+  }
+}
+
+void cPopulation::ParasiteDebug()
+{
+  ofstream outfile;
+  outfile.open("debug.out", ofstream::app);
+  outfile << stats.GetUpdate() << endl;
+  int total=0;
+  cInjectGenotype * temp;
+  for(int x=0; x<cell_array.GetSize(); x++)
+  {
+    if(cell_array[x].GetOrganism()!=NULL)
+    {
+      assert(cell_array[x].GetOrganism()->GetNumParasites()>=0 && 
+             cell_array[x].GetOrganism()->GetNumParasites()<=1);
+      total+=cell_array[x].GetOrganism()->GetNumParasites();
+      if(cell_array[x].GetOrganism()->GetNumParasites())
+	    {
+	      cHardware4Stack & cpu = (cHardware4Stack &) cell_array[x].GetOrganism()->GetHardware();
+	      outfile << x << " ";
+	      outfile << cell_array[x].GetOrganism()->GetGenotype()->GetID() << " ";
+	      temp = cpu.GetThreadOwner(1);
+	      assert(temp!=NULL);
+	      outfile << temp->GetID() << endl;	      
+	    }
+    }
+  }
+  outfile << total << endl;
+  outfile.close();
+}
+
+void cPopulation::PrintPhenotypeData(const cString & filename)
+{
+  set<int> ids;
+  for (int i = 0; i < cell_array.GetSize(); i++) 
+  {
+    // Only look at cells with organisms in them.
+    if (cell_array[i].IsOccupied() == false) continue;
+    
+    cOrganism * organism = cell_array[i].GetOrganism();
+    const cPhenotype & phenotype = organism->GetPhenotype();
+    
+    int id = 0;
+    for (int j = 0; j < phenotype.GetLastTaskCount().GetSize(); j++)
+    {
+      if (phenotype.GetLastTaskCount().ElementAt(j) > 0)
+        id += (1 << j);
+    }
+    ids.insert(id);
+  }
+  ofstream outfile;
+  outfile.open(filename, ofstream::app);
+  outfile << stats.GetUpdate() << "\t" << ids.size() << endl;
+  outfile.close();
+}
+
+void cPopulation::PrintPhenotypeStatus(const cString & filename)
+{
+  cDataFile & df_phen = stats.GetDataFile(filename);
+  
+  df_phen.WriteComment("Num orgs doing each task for each deme in population");
+  df_phen.WriteTimeStamp();
+  df_phen.Write(GetUpdate(), "update");
+  
+  cString comment;
+  
+  for (int i = 0; i < cell_array.GetSize(); i++) 
+  {
+    // Only look at cells with organisms in them.
+    if (cell_array[i].IsOccupied() == false) continue;
+    
+    cOrganism * organism = cell_array[i].GetOrganism();
+    const cPhenotype & phenotype = organism->GetPhenotype();
+    
+    comment.Set("cur_merit %d;", i); 
+    df_phen.Write(phenotype.GetMerit().GetDouble(), comment); 
+    
+    comment.Set("cur_merit_base %d;", i); 
+    df_phen.Write(phenotype.GetCurMeritBase(), comment); 
+    
+    comment.Set("cur_merit_bonus %d;", i); 
+    df_phen.Write(phenotype.GetCurBonus(), comment); 
+    
+    //    comment.Set("last_merit %d", i); 
+    //    df_phen.Write(phenotype.GetLastMerit(), comment); 
+    
+    comment.Set("last_merit_base %d", i); 
+    df_phen.Write(phenotype.GetLastMeritBase(), comment); 
+    
+    comment.Set("last_merit_bonus %d", i); 
+    df_phen.Write(phenotype.GetLastBonus(), comment); 
+    
+    comment.Set("life_fitness %d", i); 
+    df_phen.Write(phenotype.GetLifeFitness(), comment); 
+    
+    comment.Set("*"); 
+    df_phen.Write("*", comment); 
+    
+  } 
+  df_phen.Endl();
+  
+}     
+
+
+bool cPopulation::UpdateMerit(int cell_id, double new_merit)
+{
+  assert( GetCell(cell_id).IsOccupied() == true);
+  assert( new_merit >= 0.0 );
+  
+  cPhenotype & phenotype = GetCell(cell_id).GetOrganism()->GetPhenotype();
+  double old_merit = phenotype.GetMerit().GetDouble(); 
+  
+  phenotype.SetMerit( cMerit(new_merit) );
+  phenotype.SetLifeFitness(new_merit/phenotype.GetGestationTime()); 
+  if (new_merit <= old_merit) {
+	  phenotype.SetIsDonorCur(); }  
+  else  { phenotype.SetIsReceiver(); } 
+  
+  schedule->Adjust(cell_id, phenotype.GetMerit());
+  
+  return true;
+}
+
+void cPopulation::SetChangeList(cChangeList *change_list){
+  schedule->SetChangeList(change_list);
+}
+cChangeList *cPopulation::GetChangeList(){
+  return schedule->GetChangeList();
+}

Copied: trunk/source/main/cPopulation.h (from rev 329, trunk/source/main/population.hh)

Copied: trunk/source/main/cPopulationCell.cc (from rev 329, trunk/source/main/population_cell.cc)
===================================================================
--- trunk/source/main/population_cell.cc	2005-10-04 02:37:32 UTC (rev 329)
+++ trunk/source/main/cPopulationCell.cc	2005-10-05 23:40:31 UTC (rev 331)
@@ -0,0 +1,146 @@
+//////////////////////////////////////////////////////////////////////////////
+// Copyright (C) 1993 - 2003 California Institute of Technology             //
+//                                                                          //
+// Read the COPYING and README files, or contact 'avida at alife.org',         //
+// before continuing.  SOME RESTRICTIONS MAY APPLY TO USE OF THIS FILE.     //
+//////////////////////////////////////////////////////////////////////////////
+
+#ifndef POPULATION_CELL_HH
+#include "cPopulationCell.h"
+#endif
+
+#ifndef CONFIG_HH
+#include "cConfig.h"
+#endif
+#ifndef nHardware_h
+#include "nHardware.h"
+#endif
+#ifndef ORGANISM_HH
+#include "cOrganism.h"
+#endif
+#ifndef TOOLS_HH
+#include "tools.hh"
+#endif
+
+using namespace std;
+
+cPopulationCell::cPopulationCell()
+  : organism(NULL)
+  , cur_input(0)
+  , organism_count(0)
+{
+}
+
+cPopulationCell::cPopulationCell(const cPopulationCell & in_cell)
+  : organism(in_cell.organism)
+  , cur_input(in_cell.cur_input)
+  , cell_id(in_cell.cell_id)
+  , organism_count(in_cell.organism_count)
+{
+  for (int i = 0; i < nHardware::IO_SIZE; i++) input_array[i] = in_cell.input_array[i];
+  mutation_rates.Copy(in_cell.mutation_rates);
+  tConstListIterator<cPopulationCell> conn_it(in_cell.connection_list);
+  cPopulationCell * test_cell;
+  while ( (test_cell = (cPopulationCell *) conn_it.Next()) != NULL) {
+    connection_list.PushRear(test_cell);
+  }
+}
+
+void cPopulationCell::operator=(const cPopulationCell & in_cell)
+{
+  organism = in_cell.organism;
+  for (int i = 0; i < nHardware::IO_SIZE; i++) input_array[i] = in_cell.input_array[i];
+  cur_input = in_cell.cur_input;
+  cell_id = in_cell.cell_id;
+  organism_count = in_cell.organism_count;
+  mutation_rates.Copy(in_cell.mutation_rates);
+  tConstListIterator<cPopulationCell> conn_it(in_cell.connection_list);
+  cPopulationCell * test_cell;
+  while ( (test_cell = (cPopulationCell *) conn_it.Next()) != NULL) {
+    connection_list.PushRear(test_cell);
+  }
+}
+
+void cPopulationCell::Setup(int in_id, const cMutationRates & in_rates)
+{
+  cell_id = in_id;
+  mutation_rates.Copy(in_rates);
+}
+
+void cPopulationCell::Rotate(cPopulationCell & new_facing)
+{
+  // @CAO Note, this breaks avida if new_facing is not in connection_list
+
+#ifdef DEBUG
+  int scan_count = 0;
+#endif
+  while (connection_list.GetFirst() != &new_facing) {
+    connection_list.CircNext();
+#ifdef DEBUG
+    assert(++scan_count < connection_list.GetSize());
+#endif
+  }
+}
+
+
+int cPopulationCell::GetInput()
+{
+  if (cur_input >= nHardware::IO_SIZE) cur_input = 0;
+  return input_array[cur_input++];
+}
+
+int cPopulationCell::GetInputAt(int & input_pointer)
+{
+  if (input_pointer >= nHardware::IO_SIZE) input_pointer = 0;
+  return input_array[input_pointer++];
+}
+
+int cPopulationCell::GetInput(int id)
+{
+  assert(id >= 0 && id < nHardware::IO_SIZE);
+  return input_array[id];
+}
+
+void cPopulationCell::InsertOrganism(cOrganism & new_org)
+{
+  assert(&new_org != NULL);
+  assert(new_org.GetGenotype() != NULL);
+  assert(organism == NULL);
+
+  // Adjust this cell's attributes to account for the new organism.
+  organism = &new_org;
+  organism_count++;
+
+  // Adjust the organism's attributes to match this cell.
+  organism->PopInterface().SetCellID(cell_id);
+}
+
+cOrganism * cPopulationCell::RemoveOrganism()
+{
+  if (organism == NULL) return NULL;   // Nothing to do!
+
+  // For the moment, the cell doesn't keep track of much...
+  cOrganism * out_organism = organism;
+  organism = NULL;
+  return out_organism;
+}
+
+
+bool cPopulationCell::OK()
+{
+  // Nothing for the moment...
+  return true;
+}
+
+bool cPopulationCell::SaveState(ofstream & fp)
+{
+  // Nothing for the moment...
+  return false;
+}
+
+
+bool cPopulationCell::LoadState(ifstream & fp)
+{
+  // Nothing for the moment...
+  return false;
+}

Copied: trunk/source/main/cPopulationCell.h (from rev 330, trunk/source/main/population_cell.hh)

Modified: trunk/source/main/main_sub.pri
===================================================================
--- trunk/source/main/main_sub.pri	2005-10-05 23:24:09 UTC (rev 330)
+++ trunk/source/main/main_sub.pri	2005-10-05 23:40:31 UTC (rev 331)
@@ -22,11 +22,11 @@
              $$MAIN_HH/cLandscape.h \
              $$MAIN_HH/cLineage.h \
              $$MAIN_HH/cLineageControl.h \
-             $$MAIN_HH/organism.hh \
-             $$MAIN_HH/phenotype.hh \
+             $$MAIN_HH/cOrganism.h \
+             $$MAIN_HH/cPhenotype.h \
              $$MAIN_HH/cPopulationInterface.h \
-             $$MAIN_HH/population.hh \
-             $$MAIN_HH/population_cell.hh \
+             $$MAIN_HH/cPopulation.h \
+             $$MAIN_HH/cPopulationCell.h \
              $$MAIN_HH/reaction.hh \
              $$MAIN_HH/reaction_result.hh \
              $$MAIN_HH/resource.hh \
@@ -71,11 +71,11 @@
              $$MAIN_CC/cMutationRates.cc \
              $$MAIN_CC/cMutation.cc \
              $$MAIN_CC/cMxCodeArray.cc \
-             $$MAIN_CC/organism.cc \
-             $$MAIN_CC/phenotype.cc \
+             $$MAIN_CC/cOrganism.cc \
+             $$MAIN_CC/cPhenotype.cc \
              $$MAIN_CC/cPopulationInterface.cc \
-             $$MAIN_CC/population.cc \
-             $$MAIN_CC/population_cell.cc \
+             $$MAIN_CC/cPopulation.cc \
+             $$MAIN_CC/cPopulationCell.cc \
              $$MAIN_CC/reaction.cc \
              $$MAIN_CC/reaction_lib.cc \
              $$MAIN_CC/reaction_process.cc \

Deleted: trunk/source/main/org_message.cc
===================================================================
--- trunk/source/main/org_message.cc	2005-10-05 23:24:09 UTC (rev 330)
+++ trunk/source/main/org_message.cc	2005-10-05 23:40:31 UTC (rev 331)
@@ -1,27 +0,0 @@
-#include "org_message.hh"
-#include <string>
-#include <sstream>
-
-void cOrgMessage::SetData(int in_data)
-{
-  std::stringstream ss;
-  ss << in_data;
-  ss >> data;
-}
-
-void cOrgMessage::SetData(double in_data)
-{
-  std::stringstream ss;
-  ss << in_data;
-  ss >> data;
-}
-
-void cOrgMessage::GetData(int & in_data)
-{
-  in_data=atoi(data.c_str());
-}
-
-void cOrgMessage::GetData(double & in_data)
-{
-  in_data=atof(data.c_str());
-}

Deleted: trunk/source/main/org_message.hh
===================================================================
--- trunk/source/main/org_message.hh	2005-10-05 23:24:09 UTC (rev 330)
+++ trunk/source/main/org_message.hh	2005-10-05 23:40:31 UTC (rev 331)
@@ -1,40 +0,0 @@
-//////////////////////////////////////////////////////////////////////////////
-// Copyright (C) 1993 - 2003 California Institute of Technology             //
-//                                                                          //
-// Read the COPYING and README files, or contact 'avida at alife.org',         //
-// before continuing.  SOME RESTRICTIONS MAY APPLY TO USE OF THIS FILE.     //
-//////////////////////////////////////////////////////////////////////////////
-
-#ifndef ORG_MESSAGE_HH
-#define ORG_MESSAGE_HH
-
-#include <string>
-
-class cOrgMessage {
-private:
-  int time;
-  int sender_id;
-  int recipient_id;
-  std::string label;
-  std::string data;
-
-public:
-  cOrgMessage() { time=sender_id=recipient_id=-1; label=data=""; }
-  cOrgMessage(std::string in_label, std::string in_data) 
-  { label = in_label; data = in_data; }
-  
-  void SetTime(int in_time) { time = in_time; }
-  void SetSenderID(int in_id) { sender_id = in_id; }
-  void SetRecipientID(int in_id) { recipient_id = in_id; }
-  void SetLabel(int in_label) { label = in_label; }
-  
-  void SetData(std::string in_data) { data = in_data; }
-  void SetData(int in_data);
-  void SetData(double in_data);
-
-  void GetData(std::string & in_data) { in_data=data; }
-  void GetData(int & in_data);
-  void GetData(double & in_data);
-};
-
-#endif

Deleted: trunk/source/main/organism.cc
===================================================================
--- trunk/source/main/organism.cc	2005-10-05 23:24:09 UTC (rev 330)
+++ trunk/source/main/organism.cc	2005-10-05 23:40:31 UTC (rev 331)
@@ -1,410 +0,0 @@
-//////////////////////////////////////////////////////////////////////////////
-// Copyright (C) 1993 - 2003 California Institute of Technology             //
-//                                                                          //
-// Read the COPYING and README files, or contact 'avida at alife.org',         //
-// before continuing.  SOME RESTRICTIONS MAY APPLY TO USE OF THIS FILE.     //
-//////////////////////////////////////////////////////////////////////////////
-
-#include "organism.hh"
-
-#include "cConfig.h"
-#include "nHardware.h"
-#include "cEnvironment.h"
-#include "functions.hh"
-#include "cGenome.h"
-#include "cGenomeUtil.h"
-#include "cHardwareBase.h"
-#include "cInjectGenotype.h"
-#include "cInstSet.h"
-#include "cInstUtil.h"
-#include "org_message.hh"
-#include "string_util.hh"
-#include "tArray.hh"
-#include "tools.hh"
-#include "tList.hh"
-
-#include <iomanip>
-
-using namespace std;
-
-///////////////
-//  cOrganism
-///////////////
-
-int cOrganism::instance_count(0);
-
-
-cOrganism::cOrganism(const cGenome & in_genome,
-		     const cPopulationInterface & in_interface,
-		     const cEnvironment & in_environment)
-  : genotype(NULL)
-  , phenotype(in_environment)
-  , initial_genome(in_genome)
-  , mut_info(in_environment.GetMutationLib(), in_genome.GetSize())
-  , pop_interface(in_interface)
-  , input_pointer(0)
-  , input_buf(INPUT_BUF_SIZE)
-  , output_buf(OUTPUT_BUF_SIZE)
-  , send_buf(SEND_BUF_SIZE)
-  , receive_buf(RECEIVE_BUF_SIZE)
-  , sent_value(0)
-  , sent_active(false)
-  , test_receive_pos(0)
-  , max_executed(-1)
-  , lineage_label(-1)
-  , lineage(NULL)
-  , inbox(0)
-  , sent(0)
-  , is_running(false)
-{
-  // Initialization of structures...
-  hardware = pop_interface.NewHardware(this);
-  cpu_stats.Setup(hardware->GetNumInst());
-  instance_count++;
-  pop_interface.SetCellID(-1);  // No cell at the moment...
-
-  if (cConfig::GetDeathMethod() > 0) {
-    max_executed = cConfig::GetAgeLimit();
-    if (cConfig::GetAgeDeviation() > 0.0) {
-      max_executed +=
-	(int) (g_random.GetRandNormal() * cConfig::GetAgeDeviation());
-    }
-    if (cConfig::GetDeathMethod() == DEATH_METHOD_MULTIPLE) {
-      max_executed *= initial_genome.GetSize();
-    }
-
-    // max_executed must be positive or an organism will not die!
-    if (max_executed < 1) max_executed = 1;
-  }
-}
-
-
-cOrganism::~cOrganism()
-{
-  assert(is_running == false);
-  pop_interface.RecycleHardware(hardware);
-  instance_count--;
-}
-
-
-double cOrganism::GetTestFitness()
-{
-  return pop_interface.TestFitness();
-}
-  
-int cOrganism::ReceiveValue()
-{
-  const int out_value = pop_interface.ReceiveValue();
-  receive_buf.Add(out_value);
-  return out_value;
-}
-
-
-void cOrganism::DoInput(const int value)
-{
-  input_buf.Add(value);
-  phenotype.TestInput(input_buf, output_buf);
-}
-
-void cOrganism::DoOutput(const int value)
-{
-  const tArray<double> & resource_count = pop_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 (phenotype.GetEnvironment().GetTaskLib().UseNeighborInput() == true) {
-    const int num_neighbors = pop_interface.GetNumNeighbors();
-    for (int i = 0; i < num_neighbors; i++) {
-      pop_interface.Rotate();
-      cOrganism * cur_neighbor = pop_interface.GetNeighbor();
-      if (cur_neighbor == NULL) continue;
-
-      other_input_list.Push( &(cur_neighbor->input_buf) );
-    }
-  }
-
-  // If tasks require us to consider neighbor outputs, collect them...
-  if (phenotype.GetEnvironment().GetTaskLib().UseNeighborOutput() == true) {
-    const int num_neighbors = pop_interface.GetNumNeighbors();
-    for (int i = 0; i < num_neighbors; i++) {
-      pop_interface.Rotate();
-      cOrganism * cur_neighbor = pop_interface.GetNeighbor();
-      if (cur_neighbor == NULL) continue;
-
-      other_output_list.Push( &(cur_neighbor->output_buf) );
-    }
-  }
-
-  // Do the testing of tasks performed...
-  output_buf.Add(value);
-  tArray<double> res_change(resource_count.GetSize());
-  tArray<int> insts_triggered;
-  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);
-
-  for (int i = 0; i < insts_triggered.GetSize(); i++) {
-    const int cur_inst = insts_triggered[i];
-    hardware->ProcessBonusInst( cInstruction(cur_inst) );
-  }
-}
-
-void cOrganism::SendMessage(cOrgMessage & mess)
-{
-  if(pop_interface.SendMessage(mess))
-    sent.Add(mess);
-  else
-    {
-      //perhaps some kind of message error buffer?
-    }
-}
-
-bool cOrganism::ReceiveMessage(cOrgMessage & mess)
-{
-  inbox.Add(mess);
-  return true;
-}
-
-bool cOrganism::InjectParasite(const cGenome & injected_code)
-{
-  return pop_interface.InjectParasite(this, injected_code);
-}
-
-bool cOrganism::InjectHost(const cCodeLabel & label, const cGenome & injected_code)
-{
-  return hardware->InjectHost(label, injected_code);
-}
-
-void cOrganism::AddParasite(cInjectGenotype * in_genotype)
-{
-  parasites.push_back(in_genotype);
-}
-
-cInjectGenotype & cOrganism::GetParasite(int x)
-{
-  return *parasites[x];
-}
-
-int cOrganism::GetNumParasites()
-{
-  return parasites.size();
-}
-
-void cOrganism::ClearParasites()
-{
-  parasites.clear();
-}
-
-int cOrganism::OK()
-{
-  if (!hardware->OK()) return false;
-  if (!phenotype.OK()) return false;
-
-  return true;
-}
-
-
-double cOrganism::CalcMeritRatio()
-{
-  const double age = (double) phenotype.GetAge();
-  const double merit = phenotype.GetMerit().GetDouble();
-  return (merit > 0.0) ? (age / merit ) : age;
-}
-
-
-bool cOrganism::GetTestOnDivide() const { return pop_interface.TestOnDivide();}
-bool cOrganism::GetFailImplicit() const { return cConfig::GetFailImplicit(); }
-
-bool cOrganism::GetRevertFatal() const { return cConfig::GetRevertFatal(); }
-bool cOrganism::GetRevertNeg()   const { return cConfig::GetRevertNeg(); }
-bool cOrganism::GetRevertNeut()  const { return cConfig::GetRevertNeut(); }
-bool cOrganism::GetRevertPos()   const { return cConfig::GetRevertPos(); }
-
-bool cOrganism::GetSterilizeFatal() const{return cConfig::GetSterilizeFatal();}
-bool cOrganism::GetSterilizeNeg()  const { return cConfig::GetSterilizeNeg(); }
-bool cOrganism::GetSterilizeNeut() const { return cConfig::GetSterilizeNeut();}
-bool cOrganism::GetSterilizePos()  const { return cConfig::GetSterilizePos(); }
-
-
-void cOrganism::PrintStatus(ostream & fp, const cString & next_name)
-{
-  fp << "---------------------------" << endl;
-  hardware->PrintStatus(fp);
-  phenotype.PrintStatus(fp);
-  fp << "---------------------------" << endl;
-  fp << "ABOUT TO EXECUTE: " << next_name << endl;
-}
-
-
-bool cOrganism::Divide_CheckViable()
-{
-  // Make sure required task (if any) has been performed...
-  const int required_task = cConfig::GetRequiredTask();
-  const int immunity_task = cConfig::GetImmunityTask();
-//cout << "req=" << required_task << "," <<phenotype.GetCurTaskCount()[required_task]<< " "; 
-//cout << "im=" << immunity_task << "," <<phenotype.GetCurTaskCount()[immunity_task]<< endl; 
-  if (required_task != -1 &&
-      phenotype.GetCurTaskCount()[required_task] == 0) { 
-    if (immunity_task==-1 || 
-	phenotype.GetCurTaskCount()[immunity_task] == 0) {
-      Fault(FAULT_LOC_DIVIDE, FAULT_TYPE_ERROR,
-	    cStringUtil::Stringf("Lacks required task (%d)",
-			         cConfig::GetRequiredTask()));
-      return false; //  (divide fails)
-    } 
-  }
-
-  const int required_reaction = cConfig::GetRequiredReaction();
-  if (required_reaction != -1 &&
-      phenotype.GetCurTaskCount()[required_reaction] == 0) {
-    Fault(FAULT_LOC_DIVIDE, FAULT_TYPE_ERROR,
-	  cStringUtil::Stringf("Lacks required reaction (%d)",
-			       cConfig::GetRequiredReaction()));
-    return false; //  (divide fails)
-  }
-
-  // Make sure the parent is fertile
-  if ( phenotype.IsFertile() == false ) {
-    Fault(FAULT_LOC_DIVIDE, FAULT_TYPE_ERROR, "Infertile organism");
-    return false; //  (divide fails)
-  }
-
-  return true;  // Organism has no problem with divide...
-}
-
-
-// This gets called after a successful divide to deal with the child. 
-// Returns true if parent lives through this process.
-
-bool cOrganism::ActivateDivide()
-{
-  // Activate the child!  (Keep Last: may kill this organism!)
-  return pop_interface.Divide(this, child_genome);
-}
-
-
-void cOrganism::Fault(int fault_loc, int fault_type, cString fault_desc)
-{
-  (void) fault_loc;
-  (void) fault_type;
-  (void) fault_desc;
-
-#ifdef FATAL_ERRORS
-  if (fault_type == FAULT_TYPE_ERROR) {
-    phenotype.IsFertile() = false;
-  }
-#endif
-
-#ifdef FATAL_WARNINGS
-  if (fault_type == FAULT_TYPE_WARNING) {
-    phenotype.IsFertile() = false;
-  }
-#endif
-
-#ifdef BREAKPOINTS
-  phenotype.SetFault(fault_desc);
-#endif
-
-  phenotype.IncErrors();
-}
-
-
-//// Save and Load ////
-void cOrganism::SaveState(ofstream & fp)
-{
-  assert(fp.good());
-
-  fp <<"cOrganism"<<endl;
-
-  //// Save If it is alive ////
-  if( genotype == NULL ){
-    fp <<false<<endl;
-  }
-  else{  // if there is a genotype here (ie. not dead)
-    fp <<true<<endl;
-
-    fp << input_pointer;
-
-    // IO buffers
-    input_buf.SaveState(fp);
-    output_buf.SaveState(fp);
-
-    //// Save Genotype Genome ////
-//    fp << genotype->GetLength() << endl;
-    
-//      cInstUtil::SaveInternalGenome(fp, hardware->GetInstSet(),
-//  				  genotype->GetGenome());
-
-    //// Save Actual Creature Memory & MemFlags ////
-//   fp <<hardware->GetMemory().GetSize()<<endl;
-//   cInstUtil::PrintGenome(hardware->GetInstSet(), hardware->GetMemory(), fp);
-//      fp <<"|"; // marker
-//      for( int i=0; i<hardware->GetMemory().GetSize(); ++i ){
-//        fp << hardware->GetMemory().GetFlags(i);
-//      }
-//      fp <<endl;
-
-    //// Save Hardware (Inst_Pointer, Stacks, and the like)
-    hardware->SaveState(fp);
-
-    //// Save Phenotype  ////
-    phenotype.SaveState(fp);
-
-  }
-}
-
-
-void cOrganism::LoadState(ifstream & fp)
-{
-  hardware->Reset();
-
-  assert(fp.good());
-
-  cString foo;
-  fp >>foo;
-  assert( foo == "cOrganism" );
-
-  //// Is there a creature there ////
-  bool alive_flag = 0;
-  fp >>alive_flag;
-  if( alive_flag ){
-
-    // IO buffers
-    //    fp.get(input_pointer);
-    input_buf.LoadState(fp);
-    output_buf.LoadState(fp);
-
-    //// Load Genotype ////
-    cGenome in_code =
-      cInstUtil::LoadInternalGenome(fp, hardware->GetInstSet());
-//    cGenotype * new_genotype = environment->AddGenotype(in_code);
-//    ChangeGenotype(new_genotype);
-
-    //// Load Actual Creature Memory & MemFlags ////
-//    {	
-//      in_code = cInstUtil::LoadInternalGenome(fp, hardware->GetInstSet());
-//      hardware->GetMemory() = in_code;
-//      CA_FLAG_TYPE flags;
-//      char marker;  fp >>marker;  assert( marker == '|' );
-//      for( int i=0; i<hardware->GetMemory().GetSize(); ++i ){
-//    	  fp.get(flags);
-//  	  hardware->SetMemFlags(i, flags);
-//      }
-//    }
-
-    //// Load Hardware (Inst_Pointer, Stacks, and the like)
-    hardware->LoadState(fp);
-
-    //// Load Phenotype  ////
-    assert(fp.good());
-//      phenotype.Clear(genotype->GetLength());
-    phenotype.LoadState(fp);
-
-    //// Adjust Time Slice ////
-//    environment->AdjustTimeSlice();
-
-  } // end if not a dead creature
-}

Deleted: trunk/source/main/organism.hh
===================================================================
--- trunk/source/main/organism.hh	2005-10-05 23:24:09 UTC (rev 330)
+++ trunk/source/main/organism.hh	2005-10-05 23:40:31 UTC (rev 331)
@@ -1,230 +0,0 @@
-//////////////////////////////////////////////////////////////////////////////
-// Copyright (C) 1993 - 2003 California Institute of Technology             //
-//                                                                          //
-// Read the COPYING and README files, or contact 'avida at alife.org',         //
-// before continuing.  SOME RESTRICTIONS MAY APPLY TO USE OF THIS FILE.     //
-//////////////////////////////////////////////////////////////////////////////
-
-#ifndef ORGANISM_HH
-#define ORGANISM_HH
-
-#include <fstream>
-#include <deque>
-
-#ifndef CPU_MEMORY_HH
-#include "cCPUMemory.h"
-#endif
-#ifndef CPU_STATS_HH
-#include "sCPUStats.h"
-#endif
-#ifndef GENOME_HH
-#include "cGenome.h"
-#endif
-#ifndef LOCAL_MUTATIONS_HH
-#include "cLocalMutations.h"
-#endif
-#ifndef MUTATION_RATES_HH
-#include "cMutationRates.h"
-#endif
-#ifndef PHENOTYPE_HH
-#include "phenotype.hh"
-#endif
-#ifndef POPULATION_INTERFACE_HH
-#include "cPopulationInterface.h"
-#endif
-#ifndef TBUFFER_HH
-#include "tBuffer.hh"
-#endif
-
-/**
- * The cOrganism class controls the running and manages all the statistics
- * about a creature.  Effectively the chemistry acting on the genome.
- **/
-
-class cHardwareBase;
-class cGenotype;
-class cPhenotype; // aggregate
-class cGenome; // aggregate
-class cInjectGenotype;
-class cMutationRates; // aggregate
-class cLocalMutations; // aggregate
-class cPopulationInterface; // aggregate
-class cCPUMemory; // aggregate
-class sCPUStats; // aggregate
-class cLineage;
-template <class T> class tBuffer; // aggregate
-class cOrgMessage;
-class cEnvironment;
-class cOrganism;
-class cCodeLabel;
-
-class cOrganism {
-protected:
-  cHardwareBase * hardware;  // The actual machinary running this organism.
-  cGenotype * genotype;      // Information about organisms with this genome.
-  cPhenotype phenotype;      // Descriptive attributes of organism.
-  const cGenome initial_genome;        // Initial genome; can never be changed!
-  std::deque<cInjectGenotype *> parasites; // List of all parasites associated with
-                                    // 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.
-
-  // Input and Output with the environment
-  int input_pointer;
-  tBuffer<int> input_buf;
-  tBuffer<int> output_buf;
-  tBuffer<int> send_buf;
-  tBuffer<int> receive_buf;
-
-  // Communication
-  int sent_value;         // What number is this org sending?
-  bool sent_active;       // Has this org sent a number?
-  int test_receive_pos;   // In a test CPU, what message to receive next?
-
-  // Other stats
-  cCPUMemory child_genome; // Child genome, while under construction.
-  sCPUStats cpu_stats;     // Info for statistics
-
-  int max_executed;      // Max number of instruction executed before death.
-
-  int lineage_label;     // a lineages tag; inherited unchanged in offspring
-  cLineage * lineage;    // A lineage descriptor... (different from label)
-
-  tBuffer<cOrgMessage> inbox;
-  tBuffer<cOrgMessage> sent;
-
-#ifdef DEBUG
-  bool initialized;      // Has this CPU been initialized yet, w/hardware.
-#endif
-  bool is_running;       // Does this organism have the CPU?
-  static int instance_count;
-
-public:
-  void PrintStatus(std::ostream & fp, const cString & next_name);
-
-  // Divide functions
-  bool Divide_CheckViable();
-  bool ActivateDivide();
-
-  // Other Special Functions
-  void Fault(int fault_loc, int fault_type, cString fault_desc="");
-
-public:
-  cOrganism(const cGenome & in_genome,
-	    const cPopulationInterface & in_interface,
-	    const cEnvironment & in_environment);
-  ~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(); }
-
-  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); }
-  
-  // Input & Output Testing
-  void DoInput(const int value);
-  void DoOutput(const int value);
-
-  // Message stuff
-  void SendMessage(cOrgMessage & mess);
-  bool ReceiveMessage(cOrgMessage & mess);
-
-  bool InjectParasite(const cGenome & genome);
-  bool InjectHost(const cCodeLabel & in_label, const cGenome & genome);
-  void AddParasite(cInjectGenotype * cur);
-  cInjectGenotype & GetParasite(int x);
-  int GetNumParasites();
-  void ClearParasites();
-		      
-  int OK();
-
-  double GetTestFitness();
-  double CalcMeritRatio();
-
-  cCPUMemory & ChildGenome() { return child_genome; }
-  sCPUStats & CPUStats() { return cpu_stats; }
-
-  bool TestCopyMut() const { return MutationRates().TestCopyMut(); }
-  bool TestDivideMut() const { return MutationRates().TestDivideMut(); }
-  bool TestDivideIns() const { return MutationRates().TestDivideIns(); }
-  bool TestDivideDel() const { return MutationRates().TestDivideDel(); }
-  bool TestParentMut() const { return MutationRates().TestParentMut(); }
-  bool TestCrossover() const { return MutationRates().TestCrossover(); }
-  bool TestAlignedCrossover() const
-    { return MutationRates().TestAlignedCrossover(); }
-  
-  double GetCopyMutProb() const { return MutationRates().GetCopyMutProb(); }
-  void SetCopyMutProb(double _p) { return MutationRates().SetCopyMutProb(_p); }
-  void SetDivMutProb(double _p) { return MutationRates().SetDivMutProb(_p); }
-
-  double GetInsMutProb() const { return MutationRates().GetInsMutProb(); }
-  double GetDelMutProb() const { return MutationRates().GetDelMutProb(); }
-  double GetDivMutProb() const { return MutationRates().GetDivMutProb(); }
-  double GetParentMutProb() const { return MutationRates().GetParentMutProb();}
-
-
-  bool GetTestOnDivide() const;
-  bool GetFailImplicit() const;
-
-  bool GetRevertFatal() const;
-  bool GetRevertNeg() const;
-  bool GetRevertNeut() const;
-  bool GetRevertPos() const;
-
-  bool GetSterilizeFatal() const;
-  bool GetSterilizeNeg() const;
-  bool GetSterilizeNeut() const;
-  bool GetSterilizePos() const;
-
-
-  // Access to private variables
-  int GetMaxExecuted() const { return max_executed; }
-
-  void SetLineageLabel( int in_label ) { lineage_label = in_label; }
-  int GetLineageLabel() const { return lineage_label; }
-  
-  void SetLineage( cLineage * in_lineage ) { lineage = in_lineage; }
-  cLineage * GetLineage() const { return lineage; }
-
-  void SetGenotype(cGenotype * in_genotype) { genotype = in_genotype; }
-  cGenotype * GetGenotype() const { return genotype; }
-
-  const cMutationRates & MutationRates() const { return mut_rates; }
-  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; }
-  
-  /*
-  int GetCurGestation() const;
-  */
-  const cPhenotype & GetPhenotype() const { return phenotype; }
-  cPhenotype & GetPhenotype() { return phenotype; }
-
-  void SaveState(std::ofstream & fp);
-  void LoadState(std::ifstream & fp);
-
-  // --------  DEBUG ---------
-  static int GetInstanceCount() { return instance_count; }
-  void SetRunning(bool in_running) { is_running = in_running; }
-  bool GetIsRunning() { return is_running; }
-};
-
-#endif
-

Deleted: trunk/source/main/phenotype.cc
===================================================================
--- trunk/source/main/phenotype.cc	2005-10-05 23:24:09 UTC (rev 330)
+++ trunk/source/main/phenotype.cc	2005-10-05 23:40:31 UTC (rev 331)
@@ -1,762 +0,0 @@
-//////////////////////////////////////////////////////////////////////////////
-// Copyright (C) 1993 - 2003 California Institute of Technology             //
-//                                                                          //
-// Read the COPYING and README files, or contact 'avida at alife.org',         //
-// before continuing.  SOME RESTRICTIONS MAY APPLY TO USE OF THIS FILE.     //
-//////////////////////////////////////////////////////////////////////////////
-
-#ifndef PHENOTYPE_HH
-#include "phenotype.hh"
-#endif
-
-#ifndef CONFIG_HH
-#include "cConfig.h"
-#endif
-#ifndef ENVIRONMENT_HH
-#include "cEnvironment.h"
-#endif
-#ifndef REACTION_RESULT_HH
-#include "reaction_result.hh"
-#endif
-#ifndef TOOLS_HH
-#include "tools.hh"
-#endif
-
-#include <fstream>
-
-using namespace std;
-
-
-cPhenotype::cPhenotype(const cEnvironment & _environment)
-  : environment(_environment)
-  , initialized(false)
-  , cur_task_count(environment.GetTaskLib().GetSize())
-  , cur_reaction_count(environment.GetReactionLib().GetSize())
-  , cur_inst_count(environment.GetInstSet().GetSize())
-  , sensed_resources(environment.GetResourceLib().GetSize())
-  , last_task_count(environment.GetTaskLib().GetSize())
-  , last_reaction_count(environment.GetReactionLib().GetSize())
-  , last_inst_count(environment.GetInstSet().GetSize())
-{
-}
-
-cPhenotype::~cPhenotype()
-{
-}
-
-bool cPhenotype::OK()
-{
-  assert(genome_length >= 0);
-  assert(copied_size >= 0);
-  assert(executed_size >= 0);
-  assert(gestation_time >= 0);
-  assert(gestation_start >= 0);
-  assert(fitness >= 0.0);
-  assert(div_type >= 0.0);
-  assert(cur_bonus >= 0.0);
-  assert(cur_num_errors >= 0);
-  assert(cur_num_donates >= 0);
-  assert(last_merit_base >= 0.0);
-  assert(last_bonus >= 0.0);
-  assert(last_num_errors >= 0);
-  assert(last_num_donates >= 0);
-  assert(last_fitness >= 0.0);
-  assert(num_divides >= 0);
-  assert(generation >= 0);
-  assert(time_used >= 0);
-  assert(age >= 0);
-  assert(child_copied_size >= 0);
-  // assert(to_die == false);
-  return true;
-}
-
-
-/**
- * This function is run whenever a new organism is being constructed inside
- * of its parent.
- *
- * Assumptions:
- *     - parent_phenotype has had DivideReset run on it already!
- *     - this is the first method run on an otherwise freshly built phenotype.
- **/
-
-void cPhenotype::SetupOffspring(const cPhenotype & parent_phenotype,
-				int _length)
-{
-  // Copy divide values from parent, which should already be setup.
-  merit           = parent_phenotype.merit;
-  genome_length   = _length;
-  copied_size     = parent_phenotype.child_copied_size;
-  executed_size   = parent_phenotype.executed_size;
-  gestation_time  = parent_phenotype.gestation_time;
-  gestation_start = 0;
-  fitness         = parent_phenotype.fitness;
-  div_type        = parent_phenotype.div_type;
-
-  assert(genome_length > 0);
-  assert(copied_size > 0);
-  assert(executed_size > 0);
-  assert(gestation_time > 0);
-  assert(div_type > 0);
-
-  // Initialize current values, as neeeded.
-  cur_bonus       = cConfig::GetDefaultBonus();
-  cur_num_errors  = 0;
-  cur_num_donates  = 0;
-  cur_task_count.SetAll(0);
-  cur_reaction_count.SetAll(0);
-  cur_inst_count.SetAll(0);
-  for (int j = 0; j < sensed_resources.GetSize(); j++)
-	      sensed_resources[j] =  parent_phenotype.sensed_resources[j];
-
-
-  // Copy last values from parent
-  last_merit_base     = parent_phenotype.last_merit_base;
-  last_bonus          = parent_phenotype.last_bonus;
-  last_num_errors     = parent_phenotype.last_num_errors;
-  last_num_donates    = parent_phenotype.last_num_donates;
-  last_task_count     = parent_phenotype.last_task_count;
-  last_reaction_count = parent_phenotype.last_reaction_count;
-  last_inst_count     = parent_phenotype.last_inst_count;
-  last_fitness        = last_merit_base * last_bonus / gestation_time;
-
-  // Setup other miscellaneous values...
-  num_divides     = 0;
-  generation      = parent_phenotype.generation;
-  if (cConfig::GetGenerationIncMethod() != GENERATION_INC_BOTH) generation++;
-  time_used       = 0;
-  age             = 0;
-  fault_desc      = "";
-  neutral_metric  = parent_phenotype.neutral_metric + g_random.GetRandNormal();
-  life_fitness    = fitness; 
-
-  // Setup flags...
-  is_injected   = false;
-  is_parasite   = false;
-  is_donor_cur  = false;
-  is_donor_last = parent_phenotype.is_donor_last;
-  is_receiver   = false;
-  is_modifier   = false;
-  is_modified   = false;
-  is_fertile    = parent_phenotype.last_child_fertile;
-  is_mutated    = false;
-  is_multi_thread = parent_phenotype.is_multi_thread;
-  parent_true   = parent_phenotype.copy_true;
-  parent_sex    = parent_phenotype.divide_sex;
-  parent_cross_num    = parent_phenotype.cross_num;
-  to_die = false;
-  to_delete = false;
-
-  // Setup child info...
-  copy_true          = false;
-  divide_sex         = false;
-  mate_select_id     = -1;
-  cross_num          = 0;
-  last_child_fertile = is_fertile;
-  child_fertile      = true;
-  child_copied_size  = 0;
-
-  initialized = true;
-}
-
-
-/**
- * This function is run whenever a new organism is being constructed via
- * some form of injection into the population, or in a test environment.
- *
- * Assumptions:
- *     - Updates to these values (i.e. resetting of merit) will occur afterward
- *     - This is the first method run on an otherwise freshly built phenotype.
- **/
-
-void cPhenotype::SetupInject(int _length)
-{
-  // Setup reasonable initial values injected organism...
-  merit           = _length;
-  genome_length   = _length;
-  copied_size     = _length;
-  executed_size   = _length;
-  gestation_time  = 0;
-  gestation_start = 0;
-  fitness         = 0;
-  div_type	  = 1;
-
-  // Initialize current values, as neeeded.
-  cur_bonus       = cConfig::GetDefaultBonus();
-  cur_num_errors  = 0;
-  cur_num_donates  = 0;
-  cur_task_count.SetAll(0);
-  cur_reaction_count.SetAll(0);
-  cur_inst_count.SetAll(0);
-  sensed_resources.SetAll(0);
-
-  // Copy last values from parent
-  last_merit_base = _length;
-  last_bonus      = 1;
-  last_num_errors = 0;
-  last_num_donates = 0;
-  last_task_count.SetAll(0);
-  last_reaction_count.SetAll(0);
-  last_inst_count.SetAll(0);
-
-  // Setup other miscellaneous values...
-  num_divides     = 0;
-  generation      = 0;
-  time_used       = 0;
-  age             = 0;
-  fault_desc      = "";
-  neutral_metric  = 0;
-  life_fitness    = 0; 
-
-  // Setup flags...
-  is_injected   = true;
-  is_parasite   = false;
-  is_donor_last = false;
-  is_donor_cur  = false;
-  is_receiver   = false;
-  is_modifier   = false;
-  is_modified   = false;
-  is_fertile    = true;
-  is_mutated    = false;
-  is_multi_thread = false;
-  parent_true   = true;
-  parent_sex    = false;
-  parent_cross_num    = 0;
-  to_die = false;
-  to_delete = false;
-
-  // Setup child info...
-  copy_true         = false;
-  divide_sex        = false;
-  mate_select_id    = 0;
-  cross_num         = 0;
-  child_fertile     = true;
-  last_child_fertile = true;
-  child_copied_size = 0;
-
-  initialized = true;
-}
-
-
-/**
- * This function is run whenever an organism executes a successful divide.
- **/
-
-void cPhenotype::DivideReset(int _length)
-{
-  assert(time_used > 0);
-  assert(initialized == true);
-
-  // Update these values as needed...
-  int cur_merit_base = CalcSizeMerit(genome_length,copied_size,executed_size);
-  merit = cur_merit_base * cur_bonus;
-
-  genome_length   = _length;
-  (void) copied_size;          // Unchanged
-  (void) executed_size;        // Unchanged
-  gestation_time  = time_used - gestation_start;
-  gestation_start = time_used;
-  fitness         = merit.GetDouble() / gestation_time;
-
-  // Lock in cur values as last values.
-  last_merit_base     = cur_merit_base;
-  last_bonus          = cur_bonus;
-  last_num_errors     = cur_num_errors;
-  last_num_donates    = cur_num_donates;
-  last_task_count     = cur_task_count;
-  last_reaction_count = cur_reaction_count;
-  last_inst_count     = cur_inst_count;
-
-  // Reset cur values.
-  cur_bonus       = cConfig::GetDefaultBonus();
-  cur_num_errors  = 0;
-  cur_num_donates  = 0;
-  cur_task_count.SetAll(0);
-  cur_reaction_count.SetAll(0);
-  cur_inst_count.SetAll(0);
-
-  // Setup other miscellaneous values...
-  num_divides++;
-  (void) generation;
-  (void) time_used;
-  age             = 0;
-  fault_desc      = "";
-  (void) neutral_metric;
-  life_fitness = fitness; 
-
-  // Leave flags alone...
-  (void) is_injected;
-  (void) is_parasite;
-  is_donor_last = is_donor_cur;
-  is_donor_cur = false;
-  is_receiver = false;
-  (void) is_modifier;
-  (void) is_modified;
-  (void) is_fertile;
-  (void) is_mutated;
-  (void) is_multi_thread;
-  (void) parent_true;
-  (void) parent_sex;
-  (void) parent_cross_num;
-
-  // Reset child info...
-  (void) copy_true;
-  (void) divide_sex;
-  (void) mate_select_id;
-  (void) cross_num;
-  last_child_fertile = child_fertile;
-  child_fertile     = true;
-  (void) child_copied_size;;
-
-  // A few final changes if the parent was supposed to be be considered
-  // a second child on the divide.
-  if (cConfig::GetDivideMethod() == DIVIDE_METHOD_SPLIT) {
-    gestation_start = 0;
-    time_used = 0;
-    neutral_metric += g_random.GetRandNormal();
-  }
-
-  if (cConfig::GetGenerationIncMethod() == GENERATION_INC_BOTH) generation++;
-}
-
-
-/**
- * This function runs whenever a *test* CPU divides. It processes much of
- * the information for that CPU in order to actively reflect its executed
- * and copied size in its merit.
- **/
-
-void cPhenotype::TestDivideReset(int _length)
-{
-  assert(time_used > 0);
-  assert(initialized == true);
-
-  // Update these values as needed...
-  int cur_merit_base = CalcSizeMerit(genome_length,copied_size,executed_size);
-  merit           = cur_merit_base * cur_bonus;
-
-  genome_length   = _length;
-  (void) copied_size;                            // Unchanged
-  (void) executed_size;                          // Unchanged
-  gestation_time  = time_used - gestation_start;
-  gestation_start = time_used;
-  fitness         = merit.GetDouble() / gestation_time;
-  (void) div_type; 				// Unchanged
-
-  // Lock in cur values as last values.
-  last_merit_base     = cur_merit_base;
-  last_bonus          = cur_bonus;
-  last_num_errors     = cur_num_errors;
-  last_num_donates    = cur_num_donates;
-  last_task_count     = cur_task_count;
-  last_reaction_count = cur_reaction_count;
-  last_inst_count     = cur_inst_count;
-
-  // Reset cur values.
-  cur_bonus       = cConfig::GetDefaultBonus();
-  cur_num_errors  = 0;
-  cur_num_donates  = 0;
-  cur_task_count.SetAll(0);
-  cur_reaction_count.SetAll(0);
-  cur_inst_count.SetAll(0);
-  sensed_resources.SetAll(-1.0);
-
-  // Setup other miscellaneous values...
-  num_divides++;
-  generation++;
-  (void) time_used;
-  (void) age;
-  (void) fault_desc;
-  (void) neutral_metric;
-  life_fitness = fitness; 
-
-  // Leave flags alone...
-  (void) is_injected;
-  (void) is_parasite;
-  is_donor_last = is_donor_cur;
-  is_donor_cur = false;
-  is_receiver = false;
-  (void) is_modifier;
-  (void) is_modified;
-  (void) is_fertile;
-  (void) is_mutated;
-  (void) is_multi_thread;
-  (void) parent_true;
-  (void) parent_sex;
-  (void) parent_cross_num;
-
-  // Reset child info...
-  (void) copy_true;
-  (void) divide_sex;
-  (void) mate_select_id;
-  (void) cross_num;
-  (void) child_fertile;
-  (void) last_child_fertile;
-  (void) child_copied_size;
-}
-
-
-/**
- * This function is run when an organism is being forced to replicate, but
- * not at the end of its replication cycle.
- *
- * Assumptions:
- *   - new organism is an exact clone of the parent, with *same* last info.
- *   - this is the first method run on an otherwise freshly built phenotype.
- **/
-
-void cPhenotype::SetupClone(const cPhenotype & clone_phenotype)
-{
-  // Copy divide values from parent, which should already be setup.
-  merit           = clone_phenotype.merit;
-  genome_length   = clone_phenotype.genome_length;
-  copied_size     = clone_phenotype.copied_size;
-  // copied_size     = clone_phenotype.child_copied_size;
-  executed_size   = clone_phenotype.executed_size;
-  gestation_time  = clone_phenotype.gestation_time;
-  gestation_start = 0;
-  fitness         = clone_phenotype.fitness;
-  div_type        = clone_phenotype.div_type;
-
-  assert(genome_length > 0);
-  assert(copied_size > 0);
-  assert(executed_size > 0);
-  assert(gestation_time > 0);
-  assert(div_type > 0);
-
-  // Initialize current values, as neeeded.
-  cur_bonus       = cConfig::GetDefaultBonus();
-  cur_num_errors  = 0;
-  cur_num_donates  = 0;
-  cur_task_count.SetAll(0);
-  cur_reaction_count.SetAll(0);
-  cur_inst_count.SetAll(0);
-  for (int j = 0; j < sensed_resources.GetSize(); j++)
-	      sensed_resources[j] =  clone_phenotype.sensed_resources[j];
-
-
-  // Copy last values from parent
-  last_merit_base     = clone_phenotype.last_merit_base;
-  last_bonus          = clone_phenotype.last_bonus;
-  last_num_errors     = clone_phenotype.last_num_errors;
-  last_num_donates    = clone_phenotype.last_num_donates;
-  last_task_count     = clone_phenotype.last_task_count;
-  last_reaction_count = clone_phenotype.last_reaction_count;
-  last_inst_count     = clone_phenotype.last_inst_count;
-  last_fitness        = last_merit_base * last_bonus / gestation_time;
-
-  // Setup other miscellaneous values...
-  num_divides     = 0;
-  generation      = clone_phenotype.generation;
-  if (cConfig::GetGenerationIncMethod() != GENERATION_INC_BOTH) generation++;
-  time_used       = 0;
-  age             = 0;
-  fault_desc      = "";
-  neutral_metric  = clone_phenotype.neutral_metric + g_random.GetRandNormal();
-  life_fitness    = fitness; 
-
-  // Setup flags...
-  is_injected   = false;
-  is_parasite   = false;
-  is_donor_last = clone_phenotype.is_donor_last;
-  is_donor_cur  = clone_phenotype.is_donor_cur;
-  is_receiver = false;
-  is_modifier   = false;
-  is_modified   = false;
-  is_fertile    = clone_phenotype.last_child_fertile;
-  is_mutated    = false;
-  is_multi_thread = clone_phenotype.is_multi_thread;
-  parent_true   = clone_phenotype.copy_true;
-  parent_sex    = clone_phenotype.divide_sex;
-  parent_cross_num    = clone_phenotype.cross_num;
-  to_die = false;
-  to_delete = false;
-
-  // Setup child info...
-  copy_true          = false;
-  divide_sex         = false;
-  mate_select_id     = 0;
-  cross_num          = 0;
-  last_child_fertile = is_fertile;
-  child_fertile      = true;
-  child_copied_size  = 0;
-
-  initialized = true;
-}
-
-
-
-
-bool cPhenotype::TestInput(tBuffer<int> & inputs, tBuffer<int> & outputs)
-{
-  assert(initialized == true);
-  // For the moment, lets not worry about inputs...
-  return false; // Nothing happened...
-}
-
-bool cPhenotype::TestOutput(tBuffer<int> & input_buf, tBuffer<int> &output_buf,
-			    tBuffer<int> & send_buf, tBuffer<int> &receive_buf,
-			    const tArray<double> & res_in,
-			    tArray<double> & res_change,
-			    tArray<int> & insts_triggered,
-			    tList<tBuffer<int> > & other_inputs,
-			    tList<tBuffer<int> > & other_outputs)
-{
-  assert(initialized == true);
-
-  const int num_resources = environment.GetResourceLib().GetSize();
-  const int num_tasks = environment.GetTaskLib().GetSize();
-  const int num_reactions = environment.GetReactionLib().GetSize();
-
-  cReactionResult result(num_resources, num_tasks, num_reactions);
-			
-  // Run everything through the environment.
-  bool found = environment.TestOutput(result, input_buf, output_buf, send_buf,
-			      receive_buf, cur_task_count, cur_reaction_count,
-			      res_in, other_inputs, other_outputs);
-
-  // If nothing was found, stop here.
-  if (found == false) {
-    res_change.SetAll(0.0);
-    return false;  // Nothing happened.
-  }
-
-  // Update the phenotype with the results...
-  // Start with updating task and reaction counters
-  for (int i = 0; i < num_tasks; i++) {
-    if (result.TaskDone(i) == true) cur_task_count[i]++;
-  }
-  for (int i = 0; i < num_reactions; i++) {
-    if (result.ReactionTriggered(i) == true) cur_reaction_count[i]++;
-  }
-
-  // Update the merit bonus
-  cur_bonus *= result.GetMultBonus();
-  cur_bonus += result.GetAddBonus();
-
-  // Bonus should never go negative...
-  // if (cur_bonus < 0.0) cur_bonus = 0.0;
-
-  // Denote consumed resources...
-  for (int i = 0; i < res_in.GetSize(); i++) {
-    res_change[i] = result.GetProduced(i) - result.GetConsumed(i);
-  }
-
-  // Save the instructions that should be triggered...
-  insts_triggered = result.GetInstArray();
-
-  //Put in detected resources
-  for (int j = 0; j < res_in.GetSize(); j++)
-	  if(result.GetDetected(j) != -1.0)
-	      sensed_resources[j] = result.GetDetected(j);
-
-  //Kill any cells that did lethal reactions
-  to_die = result.GetLethal();
-
-  return true;
-}
-
-
-///// For Loading and Saving State: /////
-
-
-bool cPhenotype::SaveState(ofstream & fp)
-{
-  assert(fp.good());
-  fp << "cPhenotype" << endl;
-
-  fp << merit.GetDouble()   << " ";
-  fp << genome_length       << " ";
-  fp << copied_size         << " ";
-  fp << executed_size       << " ";
-  fp << gestation_time      << " ";
-  fp << gestation_start     << " ";
-  fp << fitness             << " ";
-  fp << div_type            << " ";
-
-  fp << cur_bonus           << " ";
-  fp << cur_num_errors      << " ";
-  fp << cur_num_donates      << " ";
-  for (int i = 0; i < cur_task_count.GetSize(); i++) {
-    fp << cur_task_count[i] << " ";
-  }
-  for (int i = 0; i < cur_reaction_count.GetSize(); i++) {
-    fp << cur_reaction_count[i] << " ";
-  }
-  for (int i = 0; i < cur_inst_count.GetSize(); i++) {
-    fp << cur_inst_count[i] << " ";
-  }
-
-  fp << last_merit_base     << " ";
-  fp << last_bonus          << " ";
-  fp << last_num_errors     << " ";
-  fp << last_num_donates    << " ";
-  for (int i = 0; i < last_task_count.GetSize(); i++) {
-    fp << last_task_count[i] << " ";
-  }
-  for (int i = 0; i < last_reaction_count.GetSize(); i++) {
-    fp << last_reaction_count[i] << " ";
-  }
-  for (int i = 0; i < last_inst_count.GetSize(); i++) {
-    fp << last_inst_count[i] << " ";
-  }
-
-  fp << num_divides         << " ";
-  fp << generation          << " ";
-  fp << time_used           << " ";
-  fp << age                 << " ";
-  fp << neutral_metric      << " ";
-  fp << life_fitness        << " ";
-
-  fp << is_injected         << " ";
-  fp << is_parasite         << " ";
-  fp << is_donor_last       << " ";
-  fp << is_donor_cur        << " ";
-
-  fp << is_receiver         << " ";
-  fp << is_modifier         << " ";
-  fp << is_modified         << " ";
-  fp << is_fertile          << " ";
-  fp << is_mutated          << " ";
-  fp << parent_true         << " ";
-  fp << parent_sex          << " ";
-  fp << parent_cross_num    << " ";
-
-  fp << copy_true           << " ";
-  fp << divide_sex          << " ";
-  fp << mate_select_id      << " ";
-  fp << cross_num           << " ";
-  fp << child_fertile       << " ";
-  fp << last_child_fertile  << " ";
-
-  fp << endl;
-  return true;
-}
-
-
-bool cPhenotype::LoadState(ifstream & fp)
-{
-  double tmp_merit;
-  assert(fp.good());
-  if( !fp.good() ) return false;
-
-  fp >> tmp_merit;  merit = tmp_merit;
-  fp >> genome_length;
-  fp >> copied_size;
-  fp >> executed_size;
-  fp >> gestation_time;
-  fp >> gestation_start;
-  fp >> fitness;
-  fp >> div_type;
-
-  fp >> cur_bonus;
-  fp >> cur_num_errors;
-  fp >> cur_num_donates;
-
-  for (int i = 0; i < cur_task_count.GetSize(); i++) {
-    fp >> cur_task_count[i];
-  }
-  for (int i = 0; i < cur_reaction_count.GetSize(); i++) {
-    fp >> cur_reaction_count[i];
-  }
-  for (int i = 0; i < cur_inst_count.GetSize(); i++) {
-    fp >> cur_inst_count[i];
-  }
-
-  fp >> last_merit_base;
-  fp >> last_bonus;
-  fp >> last_num_errors;
-  fp >> last_num_donates;
-  for (int i = 0; i < last_task_count.GetSize(); i++) {
-    fp >> last_task_count[i];
-  }
-  for (int i = 0; i < last_reaction_count.GetSize(); i++) {
-    fp >> last_reaction_count[i];
-  }
-  for (int i = 0; i < last_inst_count.GetSize(); i++) {
-    fp >> last_inst_count[i];
-  }
-
-  fp >> num_divides;
-  fp >> generation;
-  fp >> time_used;
-  fp >> age;
-  fp >> neutral_metric;
-  fp >> life_fitness;
-
-  fp >> is_injected;
-  fp >> is_parasite;
-  fp >> is_donor_last;
-  fp >> is_donor_cur;
-  fp >> is_receiver;
-  fp >> is_modifier;
-  fp >> is_modified;
-  fp >> is_fertile;
-  fp >> is_mutated;
-  fp >> parent_true;
-  fp >> parent_sex;
-  fp >> parent_cross_num;
-
-  fp >> copy_true;
-  fp >> divide_sex;
-  fp >> mate_select_id;
-  fp >> cross_num;
-  fp >> child_fertile;
-  fp >> last_child_fertile;
-
-  return true;
-}
-
-void cPhenotype::PrintStatus(ostream & fp)
-{
-  fp << "  MeritBase:"
-     << CalcSizeMerit(genome_length,copied_size,executed_size)
-     << " Bonus: " << cur_bonus
-     << " Errors:" << cur_num_errors
-     << " Donates:" << cur_num_donates
-     << " Tasks:";
-
-  for (int i = 0; i < cur_task_count.GetSize(); i++) {
-    fp << " " << cur_task_count[i];
-  }
-
-  fp << endl;
-}
-
-int cPhenotype::CalcSizeMerit(int full_size, int copied_size, int exe_size)
-{
-  assert(full_size > 0);
-  assert(exe_size > 0);
-  assert(copied_size > 0);
-
-  int out_size;
-
-  switch (cConfig::GetSizeMeritMethod()) {
-  case SIZE_MERIT_COPIED:
-    out_size = copied_size;
-    break;
-  case SIZE_MERIT_EXECUTED:
-    out_size = exe_size;
-    break;
-  case SIZE_MERIT_FULL:
-    out_size = full_size;
-    break;
-  case SIZE_MERIT_LEAST:
-    out_size = full_size;
-    if (out_size > copied_size) out_size = copied_size;
-    if (out_size > exe_size)    out_size = exe_size;
-    break;
-  case SIZE_MERIT_SQRT_LEAST:
-    out_size = full_size;
-    if (out_size > copied_size) out_size = copied_size;
-    if (out_size > exe_size)    out_size = exe_size;
-    out_size = (int) sqrt((double) out_size);
-    break;
-  case SIZE_MERIT_OFF:
-  default:
-    out_size = cConfig::GetBaseSizeMerit();
-    break;
-  }
-
-  return out_size;
-}

Deleted: trunk/source/main/phenotype.hh
===================================================================
--- trunk/source/main/phenotype.hh	2005-10-05 23:24:09 UTC (rev 330)
+++ trunk/source/main/phenotype.hh	2005-10-05 23:40:31 UTC (rev 331)
@@ -1,311 +0,0 @@
-//////////////////////////////////////////////////////////////////////////////
-// Copyright (C) 1993 - 2004 California Institute of Technology             //
-//                                                                          //
-// Read the COPYING and README files, or contact 'avida at alife.org',         //
-// before continuing.  SOME RESTRICTIONS MAY APPLY TO USE OF THIS FILE.     //
-//////////////////////////////////////////////////////////////////////////////
-
-#ifndef PHENOTYPE_HH
-#define PHENOTYPE_HH
-
-#include <fstream>
-
-#ifndef MERIT_HH
-#include "merit.hh"
-#endif
-#ifndef STRING_HH
-#include "string.hh"
-#endif
-#ifndef TARRAY_HH
-#include "tArray.hh"
-#endif
-
-
-/*************************************************************************
- *
- * The cPhenotype object contains a general description of all the
- * phenotypic characteristics an organism has displayed.  That is, it
- * monitors all of the organisms behaviors.
- *
- * After a phenotype is created in organism and organism within a population,
- * it must have either SetupOffspring() or SetupInject() run on it to prime
- * it for that population.  After that, it must have DivideReset() run on it
- * whenever it produces an offspring.
- *
- * If the phenotype is part of an organism in a test cpu, no initial priming
- * is required, and SetupTestDivide() needs to be run once it finally has
- * produced an offspring in order to properly lock in any final values.
- *
- * In addition to a reference to the relevent environment, the data
- * contained within this class comes in six flavors:
- *   1. Calculations made at the previous divide.
- *   2. Stats which are accumulated over each gestation cycle.
- *   3. The final result of accumulations over the previous gestation cycle.
- *   4. Accumulations over the entire life of the genome.
- *   5. A collection of flags to indicate the presence of characteristics.
- *   6. Information about the child being constructed.
- *
- *************************************************************************/
-
-class cEnvironment;
-class cMerit;                    // aggregate
-template <class T> class tArray; // aggregate
-class cString;                   // aggregate
-template <class T> class tBuffer;
-template <class T> class tList;
-
-class cPhenotype {
-private:
-  const cEnvironment & environment;
-  bool initialized;
-
-  // 1. These are values calculated at the last divide (of self or offspring)
-  cMerit merit;          // Relative speed of CPU
-  int genome_length;     // Number of instructions in genome.
-  int copied_size;       // Instructions copied into genome.
-  int executed_size;     // Instructions executed from genome.
-  int gestation_time;    // CPU cycles to produce offspring (or be produced)
-  int gestation_start;   // Total instructions executed at last divide.
-  double fitness;        // Relative efective replication rate...
-  double div_type;	     // Type of the divide command used
-
-  // 2. These are "in progress" variables, updated as the organism operates
-  double cur_bonus;               // Current Bonus
-  int cur_num_errors;             // Total instructions executed illeagally.
-  int cur_num_donates;            // Number of donations so far
-  tArray<int> cur_task_count;     // Total times each task was performed
-  tArray<int> cur_reaction_count; // Total times each reaction was triggered.
-  tArray<int> cur_inst_count;	  // Intruction exection counter
-  tArray<double> sensed_resources; // Resources of which the organism is explictly aware
-  
-  // 3. These mark the status of "in progess" variables at the last divide.
-  double last_merit_base;         // Either constant or based on genome length.
-  double last_bonus;
-  int last_num_errors;
-  int last_num_donates;
-  tArray<int> last_task_count;
-  tArray<int> last_reaction_count;
-  tArray<int> last_inst_count;	  // Intruction exection counter
-  double last_fitness;            // Used to determine sterilization.
-
-  // 4. Records from this organisms life...
-  int num_divides;       // Total successful divides organism has produced.
-  int generation;        // Number of birth events to original ancestor.
-  int time_used;         // Total CPU cycles consumed.
-  int age;               // Number of updates organism has survived for.
-  cString fault_desc;    // A description of the most recent error.
-  double neutral_metric; // Undergoes drift (gausian 0,1) per generation
-  double life_fitness; 	 // Organism fitness during it's lifetime, 
-		         // calculated based on merit just before the divide
-
-  // 5. Status Flags...  (updated at each divide)
-  bool to_die;		 // Has organism has triggered something fatal?
-  bool to_delete;        // Should this organism be deleted when finished?
-  bool is_injected;      // Was this organism injected into the population?
-  bool is_parasite;      // Has this organism ever executed outside code?
-  bool is_donor_cur;     // Has this organism ever donated merit?  
-  bool is_donor_last;    // Did this organism's parent ever donate merit? 
-  bool is_receiver;      // Has this organism ever received merit donation?
-  bool is_modifier;      // Has this organism modified another?
-  bool is_modified;      // Has this organism been modified by another?
-  bool is_fertile;       // Do we allow this organisms to produce offspring?
-  bool is_mutated;       // Has this organism been subject to any mutations?
-  bool is_multi_thread;  // Does this organism have 2 or more threads?
-  bool parent_true;      // Is this genome an exact copy of its parent's?
-  bool parent_sex;       // Did the parent divide with sex?
-  int  parent_cross_num; // How many corssovers did the parent do? 
-
-  // 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 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.
-
-public:
-  cPhenotype(const cEnvironment & environment);
-  ~cPhenotype();
-
-  bool OK();
-
-  // Run when being setup *as* and offspring.
-  void SetupOffspring(const cPhenotype & parent_phenotype, int _length);
-
-  // Run when being setup as an injected organism.
-  void SetupInject(int _length);
-
-  // Run when this organism successfully executes a divide.
-  void DivideReset(int _length);
-  
-  // Same as DivideReset(), but only run in test CPUs.
-  void TestDivideReset(int _length);
-
-  // Run when an organism is being forced to replicate, but not at the end
-  // of its replication cycle.  Assume exact clone with no mutations.
-  void SetupClone(const cPhenotype & clone_phenotype);
-
-  // Input and Output Reaction Tests
-  bool TestInput(tBuffer<int> & inputs, tBuffer<int> & outputs);
-  bool TestOutput(tBuffer<int> & input_buf, tBuffer<int> & output_buf,
-		  tBuffer<int> & send_buf, tBuffer<int> & receive_buf,
-		  const tArray<double> & res_in, tArray<double> & res_change,
-		  tArray<int> & insts_triggered,
-		  tList<tBuffer<int> > & other_inputs,
-		  tList<tBuffer<int> > & other_outputs);
-
-  // State saving and loading, and printing...
-  bool SaveState(std::ofstream & fp);
-  bool LoadState(std::ifstream & fp);
-  void PrintStatus(std::ostream & fp);
-
-  // Some useful methods...
-  static int CalcSizeMerit(int full_size, int copied_size, int exe_size);
-  double CalcFitnessRatio() {
-    const int merit_base =
-      CalcSizeMerit(genome_length,copied_size,executed_size);
-    const double cur_fitness = merit_base * cur_bonus / time_used;
-    return cur_fitness / last_fitness;
-  }
-
-  /////////////////////  Accessors -- Retrieving  ////////////////////
-  const cEnvironment & GetEnvironment() const { return environment; };
-
-  const cMerit & GetMerit() const
-    { assert(initialized == true); return merit; }
-  int GetGenomeLength() const
-    { assert(initialized == true); return genome_length; }
-  int GetCopiedSize() const
-    { assert(initialized == true); return copied_size; }
-  int GetExecutedSize() const
-    { assert(initialized == true); return executed_size; }
-  int GetGestationTime() const
-    { assert(initialized == true); return gestation_time; }
-  int GetGestationStart() const
-    { assert(initialized == true); return gestation_start; }
-  double GetFitness() const
-    { assert(initialized == true); return fitness; }
-  double GetDivType() const
-    { assert(initialized == true); return div_type; }
-
-  double GetCurBonus() const
-    { assert(initialized == true); return cur_bonus; }
-  double GetCurMeritBase() const
-    { assert(initialized == true); return CalcSizeMerit(genome_length,copied_size,executed_size); }
-  bool GetToDie() const
-    { assert(initialized == true); return to_die; }
-  bool GetToDelete() const
-    { assert(initialized == true); return to_delete; }
-  int GetCurNumErrors() const
-    { assert(initialized == true); return cur_num_errors; }
-  int GetCurNumDonates() const
-    { assert(initialized == true); return cur_num_donates; }
-  const tArray<int> & GetCurTaskCount() const
-    { assert(initialized == true); return cur_task_count; }
-  const tArray<int> & GetCurReactionCount() const
-    { assert(initialized == true); return cur_reaction_count;}
-  const tArray<int> & GetCurInstCount() const
-    { assert(initialized == true); return cur_inst_count; }
-  
-  double GetSensedResource(int _in)
-  { assert(initialized == true); return sensed_resources[_in]; }
-
-  double GetLastMeritBase() const
-    { assert(initialized == true); return last_merit_base; }
-  double GetLastBonus() const
-    { assert(initialized == true); return last_bonus; }
-  const double GetLastMerit() const
-    { assert(initialized == true); return last_merit_base*last_bonus; }
-  int GetLastNumErrors() const
-    { assert(initialized == true); return last_num_errors; }
-  int GetLastNumDonates() const
-    { assert(initialized == true); return last_num_donates; }
-  const tArray<int> & GetLastTaskCount() const
-    { assert(initialized == true); return last_task_count; }
-  const tArray<int> & GetLastReactionCount() const
-    { assert(initialized == true); return last_reaction_count; }
-  const tArray<int> & GetLastInstCount() const
-    { assert(initialized == true); return last_inst_count; }
-  double GetLastFitness() const
-    { assert(initialized == true); return last_fitness; }
-
-  int GetNumDivides() const { assert(initialized == true); return num_divides;}
-  int GetGeneration() const { assert(initialized == true); return generation; }
-  int GetTimeUsed()   const { assert(initialized == true); return time_used; }
-  int GetAge()        const { assert(initialized == true); return age; }
-  const cString & GetFault() const
-    { assert(initialized == true); return fault_desc; }
-  double GetNeutralMetric() const
-    { assert(initialized == true); return neutral_metric; }
-  double GetLifeFitness() const
-    { assert(initialized == true); return life_fitness; }
-
-  bool IsInjected() const { assert(initialized == true); return is_injected; }
-  bool IsParasite() const { assert(initialized == true); return is_parasite; }
-  bool IsDonorCur() const { assert(initialized == true); return is_donor_cur; }
-  bool IsDonorLast() const { assert(initialized == true); return is_donor_last; }
-  bool IsReceiver() const { assert(initialized == true); return is_receiver; }
-  bool IsModifier() const { assert(initialized == true); return is_modifier; }
-  bool IsModified() const { assert(initialized == true); return is_modified; }
-  bool IsFertile() const  { assert(initialized == true); return is_fertile; }
-  bool IsMutated() const  { assert(initialized == true); return is_mutated; }
-  bool IsMultiThread() const { assert(initialized == true); return is_multi_thread; }
-  bool ParentTrue() const { assert(initialized == true); return parent_true; }
-  bool ParentSex() const  { assert(initialized == true); return parent_sex; }
-  int  ParentCrossNum() const  { assert(initialized == true); return parent_cross_num; }
-
-  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;}
-  int GetChildCopiedSize() const
-    { assert(initialized == true); return child_copied_size; }
-
-
-  ////////////////////  Accessors -- Modifying  ///////////////////
-  void SetMerit(const cMerit & in_merit) { merit = in_merit; }
-  void SetGestationTime(int in_time) { gestation_time = in_time; }
-  void SetFault(const cString & in_fault) { fault_desc = in_fault; }
-  void SetNeutralMetric(double _in){ neutral_metric = _in; }
-  void SetLifeFitness(double _in){ life_fitness = _in; }
-  void SetLinesExecuted(int _exe_size) { executed_size = _exe_size; }
-  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; }
-
-  void SetIsDonorCur() { is_donor_cur = true; } 
-  void SetIsReceiver() { is_receiver = true; } 
-  
-
-  void IncCurInstCount(int _inst_num)  { assert(initialized == true); cur_inst_count[_inst_num]++; } 
-  void DecCurInstCount(int _inst_num)  { assert(initialized == true); cur_inst_count[_inst_num]--; } 
-
-  void IncAge()      { assert(initialized == true); age++; }
-  void IncTimeUsed() { assert(initialized == true); time_used++; }
-  void IncErrors()   { assert(initialized == true); cur_num_errors++; }
-  void IncDonates()   { assert(initialized == true); cur_num_donates++; }
-  bool & IsInjected() { assert(initialized == true); return is_injected; }
-  bool & IsParasite() { assert(initialized == true); return is_parasite; }
-  bool & IsModifier() { assert(initialized == true); return is_modifier; }
-  bool & IsModified() { assert(initialized == true); return is_modified; }
-  bool & IsFertile()  { assert(initialized == true); return is_fertile; }
-  bool & IsMutated()  { assert(initialized == true); return is_mutated; }
-  bool & ParentTrue() { assert(initialized == true); return parent_true; }
-  bool & ParentSex()  { assert(initialized == true); return parent_sex; }
-  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; }
-};
-
-#endif

Deleted: trunk/source/main/population.cc
===================================================================
--- trunk/source/main/population.cc	2005-10-05 23:24:09 UTC (rev 330)
+++ trunk/source/main/population.cc	2005-10-05 23:40:31 UTC (rev 331)
@@ -1,2154 +0,0 @@
-//////////////////////////////////////////////////////////////////////////////
-// Copyright (C) 1993 - 2003 California Institute of Technology             //
-//                                                                          //
-// Read the COPYING and README files, or contact 'avida at alife.org',         //
-// before continuing.  SOME RESTRICTIONS MAY APPLY TO USE OF THIS FILE.     //
-//////////////////////////////////////////////////////////////////////////////
-
-#include "population.hh"
-
-#include "change_list.hh"
-#include "cConfig.h"
-#include "const_schedule.hh"
-#include "data_file.hh"
-#include "cEnvironment.h"
-#include "functions.hh"
-#include "cGenebank.h"
-#include "cGenomeUtil.h"
-#include "cGenotype.h"
-#include "cHardwareBase.h"
-#include "cHardwareFactory.h"
-#include "cHardware4Stack.h"
-#include "cHardwareUtil.h"
-#include "init_file.hh"
-#include "cInjectGenebank.h"
-#include "cInjectGenotype.h"
-#include "cInstUtil.h"
-#include "integrated_schedule.hh"
-#include "cLineage.h"
-#include "cLineageControl.h"
-#include "organism.hh"
-#include "phenotype.hh"
-#include "population_cell.hh"
-#include "prob_schedule.hh"
-#include "resource.hh"
-#include "species.hh"
-#include "stats.hh"
-#include "task_entry.hh"
-
-#include <fstream>
-#include <vector>
-#include <algorithm>
-#include <set>
-
-#include <math.h>
-
-using namespace std;
-
-
-cPopulation::cPopulation(const cPopulationInterface & in_interface,
-                         cEnvironment & in_environment,
-                         cChangeList * change_list)
-: schedule(NULL)
-, resource_count(in_environment.GetResourceLib().GetSize())
-, environment(in_environment)
-, default_interface(in_interface)
-, num_organisms(0)
-, sync_events(false)
-{
-  // Setup the genebank.
-  genebank = new cGenebank(stats);
-  inject_genebank = new cInjectGenebank(stats);
-  birth_chamber.SetGenebank(genebank);
-  
-  // are we logging lineages?
-  if (cConfig::GetLogLineages()) {
-    lineage_control = new cLineageControl( *genebank, stats );
-  }
-  else lineage_control = NULL;    // no lineage logging
-  
-  // Setup the default mutation rates...
-  cMutationRates & default_mut_rates = environment.GetMutRates();
-  default_mut_rates.SetCopyMutProb  ( cConfig::GetCopyMutProb()   );
-  default_mut_rates.SetInsMutProb   ( cConfig::GetInsMutProb()    );
-  default_mut_rates.SetDelMutProb   ( cConfig::GetDelMutProb()    );
-  default_mut_rates.SetDivMutProb   ( cConfig::GetDivMutProb()    );
-  default_mut_rates.SetPointMutProb ( cConfig::GetPointMutProb()  );
-  default_mut_rates.SetDivideMutProb( cConfig::GetDivideMutProb() );
-  default_mut_rates.SetDivideInsProb( cConfig::GetDivideInsProb() );
-  default_mut_rates.SetDivideDelProb( cConfig::GetDivideDelProb() );
-  default_mut_rates.SetParentMutProb( cConfig::GetParentMutProb() );
-  
-  // Setup the default population interface...
-  default_interface.SetPopulation(this);
-  
-  // Avida specific information.
-  world_x = cConfig::GetWorldX();
-  world_y = cConfig::GetWorldY();
-  int geometry = cConfig::GetWorldGeometry();
-  const int num_cells = world_x * world_y;
-  cout << "Building world " << world_x << "x" << world_y
-    << " = " << num_cells << " organisms." << endl;
-  if (geometry == GEOMETRY_GRID) {
-    cout << "Geometry: Bounded grid" << endl;
-  } else if (geometry == GEOMETRY_TORUS) {
-    cout << "Geometry: Torus" << endl;
-  } else {
-    cout << "Geometry: Unknown" << endl;
-  }
-  cout << endl;
-  
-  cell_array.Resize(num_cells);
-  resource_count.ResizeSpatialGrids(world_x, world_y);
-  
-  bool bottom_flag, top_flag, right_flag, left_flag;
-  for (int cell_id = 0; cell_id < num_cells; cell_id++) {
-    int x = cell_id % world_x;
-    int y = cell_id / world_x;
-    cell_array[cell_id].Setup(cell_id, default_mut_rates);
-    
-    
-    if ((y == 0) && (geometry == GEOMETRY_GRID)) {
-      bottom_flag = false;
-    } else {
-      bottom_flag = true;
-    }
-    if ((y == world_y-1) && (geometry == GEOMETRY_GRID)) {
-      top_flag = false;
-    } else {
-      top_flag = true;
-    }
-    if ((x == 0) && (geometry == GEOMETRY_GRID)) {
-      left_flag = false;
-    } else {
-      left_flag = true;
-    }
-    if ((x == world_x-1) && (geometry == GEOMETRY_GRID)) {
-      right_flag = false;
-    } else {
-      right_flag = true;
-    }
-    
-    // Setup the connection list for each cell. (Clockwise from -1 to 1)
-    
-    tList<cPopulationCell> & conn_list=cell_array[cell_id].ConnectionList();
-    if (bottom_flag && left_flag) {
-      conn_list.Push(&(cell_array[GridNeighbor(cell_id,world_x,world_y, -1, -1)]));
-    }
-    if (bottom_flag) {
-      conn_list.Push(&(cell_array[GridNeighbor(cell_id,world_x,world_y,  0, -1)]));
-    }
-    if (bottom_flag && right_flag) {
-      conn_list.Push(&(cell_array[GridNeighbor(cell_id,world_x,world_y, +1, -1)]));
-    }
-    if (right_flag) {
-      conn_list.Push(&(cell_array[GridNeighbor(cell_id,world_x,world_y, +1,  0)]));
-    }
-    if (top_flag && right_flag) {
-      conn_list.Push(&(cell_array[GridNeighbor(cell_id,world_x,world_y, +1, +1)]));
-    }
-    if (top_flag) {
-      conn_list.Push(&(cell_array[GridNeighbor(cell_id,world_x,world_y,  0, +1)]));
-    }
-    if (top_flag && left_flag) {
-      conn_list.Push(&(cell_array[GridNeighbor(cell_id,world_x,world_y, -1, +1)]));
-    }
-    if (left_flag) {
-      conn_list.Push(&(cell_array[GridNeighbor(cell_id,world_x,world_y, -1,  0)]));
-    }
-    
-    // Setup the reaper queue...
-    if (cConfig::GetBirthMethod() == POSITION_CHILD_FULL_SOUP_ELDEST) {
-      reaper_queue.Push(&(cell_array[cell_id]));
-    }
-  }
-  
-  BuildTimeSlicer(change_list);
-  
-  if (SetupDemes() == false) {
-    cerr << "Error: Failed to setup demes.  Exiting..." << endl;
-    exit(1);
-  }
-  
-  // Setup the resources...
-  const cResourceLib & resource_lib = environment.GetResourceLib();
-  for (int i = 0; i < resource_lib.GetSize(); i++) {
-    cResource * res = resource_lib.GetResource(i);
-    const double decay = 1.0 - res->GetOutflow();
-    resource_count.Setup(i, res->GetName(), res->GetInitial(), 
-                         res->GetInflow(), decay,
-                         res->GetGeometry(), res->GetXDiffuse(),
-                         res->GetXGravity(), res->GetYDiffuse(), 
-                         res->GetYGravity(), res->GetInflowX1(), 
-                         res->GetInflowX2(), res->GetInflowY1(), 
-                         res->GetInflowY2(), res->GetOutflowX1(), 
-                         res->GetOutflowX2(), res->GetOutflowY1(), 
-                         res->GetOutflowY2() );
-    stats.SetResourceName(i, res->GetName());
-  }
-  
-  // Give stats information about the environment...
-  const cTaskLib & task_lib = environment.GetTaskLib();
-  for (int i = 0; i < task_lib.GetSize(); i++) {
-    const cTaskEntry & cur_task = task_lib.GetTask(i);
-    stats.SetTaskName(i, cur_task.GetDesc());
-  }
-  
-  const cInstSet & inst_set = environment.GetInstSet();
-  for (int i = 0; i < inst_set.GetSize(); i++) {
-    stats.SetInstName(i, inst_set.GetName(i));
-  }
-  
-  // Load a clone if one is provided, otherwise setup start organism.
-  if (cConfig::GetCloneFilename() == "") {
-    cGenome start_org = cInstUtil::LoadGenome(cConfig::GetStartCreature(), environment.GetInstSet());
-    if (start_org.GetSize() != 0) Inject(start_org);
-    else cerr << "Warning: Zero length start organism, not injecting into initial population." << endl;
-  } else {
-    ifstream fp(cConfig::GetCloneFilename()());
-    LoadClone(fp);
-  }
-  
-  // Load a saved population if one is provided.
-  cString fname(cConfig::GetLoadPopFilename());
-  if (fname != "") {
-    cout << "Loading Population from " <<  fname() << endl;
-    
-    // If last three chars of filename are ".gz" , gunzip it first
-    if (fname.Find(".gz") == fname.GetSize() - 3) {
-      cString cmd(fname);
-      cmd.Insert("gunzip ");
-      fname.ClipEnd(3);
-      system(cmd);
-      
-      ifstream fp(fname);
-      if( !fp.good() ){
-        cerr << "Error: Failed to load population file " << fname() << ". Exiting...\n" << endl;
-        exit(2);
-      }
-      LoadPopulation(fp);
-      
-      cmd = fname;
-      cmd.Insert("gzip ");
-      system(cmd);
-    } else {
-      // load normally
-      ifstream fp(fname);
-      LoadPopulation(fp);
-    }
-  }
-  
-}
-
-
-cPopulation::~cPopulation()
-{
-  for (int i = 0; i < cell_array.GetSize(); i++) KillOrganism(cell_array[i]);
-  
-  if ( lineage_control != NULL ) delete lineage_control;
-  delete genebank;
-  delete inject_genebank;
-  delete schedule;
-}
-
-
-// This method configures demes in the population.  Demes are subgroups of
-// organisms evolved together and used in group selection experiments.
-bool cPopulation::SetupDemes()
-{
-  num_demes = cConfig::GetNumDemes();
-  
-  // If we are not using demes, stop here.
-  if (num_demes == 0) {
-    if (cConfig::GetBirthMethod() == POSITION_CHILD_DEME_RANDOM) {
-      cerr << "Using position method that requires demes, but demes are off."
-      << endl;
-      return false;
-    }
-    return true;
-  }
-  
-  // Check to make sure all other settings are reasonable to have demes.
-  // ...make sure populaiton can be divided up evenly.
-  if (world_y % num_demes != 0) {
-    cerr << "World Y size of " << world_y
-    << " cannot be divided into " << num_demes << " demes." << endl;
-    return false;
-  }
-  
-  // ...make sure we are using a legal birth method.
-  if (cConfig::GetBirthMethod() == POSITION_CHILD_FULL_SOUP_ELDEST ||
-      cConfig::GetBirthMethod() == POSITION_CHILD_FULL_SOUP_RANDOM) {
-    cerr << "Illegal birth method " << cConfig::GetBirthMethod()
-    << " for use with demes." << endl;
-    return false;
-  }
-  
-  const int deme_size_x = world_x;
-  const int deme_size_y = world_y / num_demes;
-  deme_size = deme_size_x * deme_size_y;
-  
-  // Track birth counts...
-  deme_birth_count.Resize(num_demes);
-  deme_birth_count.SetAll(0);
-  
-  // Build walls in the population.
-  for (int row_id = 0; row_id < world_y; row_id += deme_size_y) {
-    // Loop through all of the cols and make the cut on each...
-    for (int col_id = 0; col_id < world_x; col_id++) {
-      int idA = row_id * world_x + col_id;
-      int idB  = GridNeighbor(idA, world_x, world_y,  0, -1);
-      int idA0 = GridNeighbor(idA, world_x, world_y, -1,  0);
-      int idA1 = GridNeighbor(idA, world_x, world_y,  1,  0);
-      int idB0 = GridNeighbor(idA, world_x, world_y, -1, -1);
-      int idB1 = GridNeighbor(idA, world_x, world_y,  1, -1);
-      cPopulationCell & cellA = GetCell(idA);
-      cPopulationCell & cellB = GetCell(idB);
-      tList<cPopulationCell> & cellA_list = cellA.ConnectionList();
-      tList<cPopulationCell> & cellB_list = cellB.ConnectionList();
-      cellA_list.Remove(&GetCell(idB));
-      cellA_list.Remove(&GetCell(idB0));
-      cellA_list.Remove(&GetCell(idB1));
-      cellB_list.Remove(&GetCell(idA));
-      cellB_list.Remove(&GetCell(idA0));
-      cellB_list.Remove(&GetCell(idA1));
-    }
-  }
-  
-  return true;
-}
-
-// Activate the child, given information from the parent.
-// Return true if parent lives through this process.
-
-bool cPopulation::ActivateOffspring(cGenome & child_genome,
-                                    cOrganism & parent_organism)
-{
-  assert(&parent_organism != NULL);
-  
-  tArray<cOrganism *> child_array;
-  tArray<cMerit> merit_array;
-  
-  // Update the parent's phenotype.
-  // This needs to be done before the parent goes into the brith chamber
-  // or the merit doesn't get passed onto the child correctly
-  cPhenotype & parent_phenotype = parent_organism.GetPhenotype();
-  parent_phenotype.DivideReset(parent_organism.GetGenome().GetSize());
-  
-  birth_chamber.SubmitOffspring(child_genome, parent_organism,
-                                child_array, merit_array);
-  
-  
-  // First, setup the genotype of all of the offspring.
-  cGenotype * parent_genotype = parent_organism.GetGenotype();
-  const int parent_id = parent_organism.PopInterface().GetCellID();
-  assert(parent_id >= 0 && parent_id < cell_array.GetSize());
-  cPopulationCell & parent_cell = cell_array[ parent_id ];
-  
-  
-  tArray<int> target_cells(child_array.GetSize());
-  
-  // Loop through choosing the later placement of each child in the population.
-  bool parent_alive = true;  // Will the parent live through this process?
-  for (int i = 0; i < child_array.GetSize(); i++) {
-    target_cells[i] = PositionChild( parent_cell ).GetID();
-    // If we replaced the parent, make a note of this.
-    if (target_cells[i] == parent_cell.GetID()) parent_alive = false;      
-    
-    // Update the mutation rates of each child....
-    child_array[i]->MutationRates().
-      Copy(GetCell(target_cells[i]).MutationRates());
-    
-    // Update the phenotypes of each child....
-    const int child_length = child_array[i]->GetGenome().GetSize();
-    child_array[i]->GetPhenotype().
-      SetupOffspring(parent_phenotype,child_length);
-    
-    child_array[i]->GetPhenotype().SetMerit(merit_array[i]);
-    
-    // Do lineage tracking for the new organisms.
-    LineageSetupOrganism( child_array[i], parent_organism.GetLineage(),
-                          parent_organism.GetLineageLabel(),
-                          parent_genotype );
-    
-  }
-  
-  
-  // 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());
-    
-    // In a local run, face the child toward the parent. 
-    if (cConfig::GetBirthMethod() < NUM_LOCAL_POSITION_CHILD) {
-      for (int i = 0; i < child_array.GetSize(); i++) {
-        GetCell(target_cells[i]).Rotate(parent_cell);
-      }
-    }
-  }
-  
-  // Do any statistics on the parent that just gave birth...
-  parent_genotype->AddGestationTime( parent_phenotype.GetGestationTime() );
-  parent_genotype->AddFitness(       parent_phenotype.GetFitness()       );
-  parent_genotype->AddMerit(         parent_phenotype.GetMerit()         );
-  parent_genotype->AddCopiedSize(    parent_phenotype.GetCopiedSize()    );
-  parent_genotype->AddExecutedSize(  parent_phenotype.GetExecutedSize()  );
-  
-  // Place all of the offspring...
-  for (int i = 0; i < child_array.GetSize(); i++) {
-    ActivateOrganism(child_array[i], GetCell(target_cells[i]));
-    cGenotype * child_genotype = child_array[i]->GetGenotype();
-    child_genotype->DecDeferAdjust();
-    genebank->AdjustGenotype(*child_genotype);
-  }
-  
-  return parent_alive;
-}
-
-bool cPopulation::ActivateInject(cOrganism & parent, const cGenome & injected_code)
-{
-  assert(&parent != NULL);
-  
-  if(injected_code.GetSize() ==0)
-    return false;
-  
-  cHardware4Stack & parent_cpu = (cHardware4Stack &) parent.GetHardware();
-  cInjectGenotype * parent_genotype = parent_cpu.GetCurThreadOwner();
-  
-  const int parent_id = parent.PopInterface().GetCellID();
-  assert(parent_id >= 0 && parent_id < cell_array.GetSize());
-  cPopulationCell & parent_cell = cell_array[ parent_id ];
-  
-  int num_neighbors = parent.GetNeighborhoodSize();
-  cOrganism * target_organism = 
-    parent_cell.connection_list.GetPos(g_random.GetUInt(num_neighbors))->GetOrganism();
-  
-  if(target_organism==NULL)
-    return false;
-  
-  cHardware4Stack & child_cpu = (cHardware4Stack &) target_organism->GetHardware();
-  
-  if(child_cpu.GetNumThreads()==cConfig::GetMaxCPUThreads())
-    return false;
-  
-  cInjectGenotype * child_genotype = parent_genotype;
-  
-  if(target_organism->InjectHost(parent_cpu.GetLabel(), injected_code)) {
-    // If the parent genotype is not correct for the child, adjust it.
-    if (parent_genotype == NULL || parent_genotype->GetGenome() != injected_code) {
-      child_genotype = inject_genebank->AddInjectGenotype(injected_code, parent_genotype);
-    }
-    
-    target_organism->AddParasite(child_genotype);
-    child_genotype->AddParasite();
-    child_cpu.SetThreadOwner(child_genotype);
-    //if(parent_genotype!=NULL)
-    //  parent_genotype->RemoveParasite();
-    inject_genebank->AdjustInjectGenotype(*child_genotype);
-  }
-  else
-    return false;
-  
-  return true;
-  
-  // And set the genotype now that we know it.
-  //child_array[i]->SetGenotype(child_genotype);
-  //parent_genotype->SetBreedStats(*child_genotype);
-  
-  // We want to make sure that the child's genotype is not deleted from the
-  // genebank before the child is placed.
-  //child_genotype->IncDeferAdjust();
-  
-  // **THIS WILL BE NECESSARY IF/WHEN WE IMPLEMENT PARASITE LINEAGES.**
-  // Do lineage tracking for the new creature, if necessary.  Must occur
-  // before old organism is removed.
-  //LineageSetupOrganism( child_array[i], parent_organism.GetLineage(),
-  //			  parent_organism.GetLineageLabel(), parent_genotype );
-  
-  // **THIS WILL BE NECESSARY ONCE WE IMPLEMENT PARASITE MUTATION RATES.**
-  //child_array[i]->MutationRates().
-  //  Copy(GetCell(target_cells[i]).MutationRates());
-  
-  // Do any statistics on the parent that just gave birth...
-  //parent_genotype->AddGestationTime( parent_phenotype.GetGestationTime() );
-  //parent_genotype->AddFitness(       parent_phenotype.GetFitness()       );
-  //parent_genotype->AddMerit(         parent_phenotype.GetMerit()         );
-  //parent_genotype->AddCopiedSize(    parent_phenotype.GetCopiedSize()    );
-  //parent_genotype->AddExecutedSize(  parent_phenotype.GetExecutedSize()  );
-  
-  // Place all of the offspring...
-  /*for (int i = 0; i < child_array.GetSize(); i++) {
-    ActivateOrganism(child_array[i], GetCell(target_cells[i]));
-  cGenotype * child_genotype = child_array[i]->GetGenotype();
-  child_genotype->DecDeferAdjust();
-  genebank->AdjustGenotype(*child_genotype);
-  }*/
-}
-
-bool cPopulation::ActivateInject(const int cell_id, const cGenome & injected_code)
-{
-  cInjectGenotype * child_genotype = inject_genebank->AddInjectGenotype(injected_code);
-  cHardware4Stack & child_cpu = (cHardware4Stack &) cell_array[cell_id].GetOrganism()->GetHardware();
-  if(cell_array[cell_id].GetOrganism()->InjectHost(cCodeLabel(), injected_code))
-  {
-    cell_array[cell_id].GetOrganism()->AddParasite(child_genotype);
-    child_genotype->AddParasite();
-    child_cpu.SetThreadOwner(child_genotype);
-    inject_genebank->AdjustInjectGenotype(*child_genotype);
-  }
-  else
-    return false;
-  
-  return true;
-}
-
-void cPopulation::ActivateOrganism(cOrganism * in_organism,
-                                   cPopulationCell & target_cell)
-{
-  assert(in_organism != NULL);
-  assert(in_organism->GetGenome().GetSize() > 1);
-  
-  // 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) {
-    cGenotype * new_genotype =
-    genebank->AddGenotype(in_organism->GetGenome(), NULL, NULL);
-    in_organism->SetGenotype(new_genotype);
-  }
-  cGenotype * in_genotype = in_organism->GetGenotype();
-  
-  // Save the old genotype from this cell...
-  cGenotype * old_genotype = NULL;
-  if (target_cell.IsOccupied()) {
-    old_genotype = target_cell.GetOrganism()->GetGenotype();
-    
-    // Sometimes a new organism will kill off the last member of its genotype
-    // in the population.  Normally this would remove the genotype, so we 
-    // want to defer adjusting that genotype until the new one is placed.
-    old_genotype->IncDeferAdjust();
-  }
-  
-  // Update the contents of the target cell.
-  KillOrganism(target_cell);
-  target_cell.InsertOrganism(*in_organism);
-  
-  // Setup the inputs in the target cell.
-  environment.SetupInputs(target_cell.input_array);
-  
-  // Update the genebank...
-  in_genotype->AddOrganism();
-  
-  if (old_genotype != NULL) {
-    old_genotype->DecDeferAdjust();
-    genebank->AdjustGenotype(*old_genotype);
-  }
-  genebank->AdjustGenotype(*in_genotype);
-  
-  // Initialize the time-slice for this new organism.
-  schedule->Adjust(target_cell.GetID(),in_organism->GetPhenotype().GetMerit());
-  
-  // Special handling for certain birth methods.
-  if (cConfig::GetBirthMethod() == POSITION_CHILD_FULL_SOUP_ELDEST) {
-    reaper_queue.Push(&target_cell);
-  }
-  
-  num_organisms++;
-  
-  // Statistics...
-  stats.RecordBirth(target_cell.GetID(), in_genotype->GetID(),
-                    in_organism->GetPhenotype().ParentTrue());
-}
-
-void cPopulation::KillOrganism(cPopulationCell & in_cell)
-{
-  // do we actually have something to kill?
-  if (in_cell.IsOccupied() == false) {
-    return;
-  }
-  
-  // Statistics...
-  cOrganism * organism = in_cell.GetOrganism();
-  cGenotype * genotype = organism->GetGenotype();
-  stats.RecordDeath(in_cell.GetID(), genotype->GetID(),
-                    organism->GetPhenotype().GetAge());
-  
-  
-  // Do the lineage handling
-  if (lineage_control != NULL) {
-    lineage_control->RemoveCreature( organism );
-  }
-  
-  // Do statistics
-  num_organisms--;
-  
-  //if (organism->GetPhenotype().IsParasite() == true) {
-  //  genotype->AddParasite();
-  //}
-  genotype->RemoveOrganism();
-
-for(int i=0; i<organism->GetNumParasites(); i++) {
-  organism->GetParasite(i).RemoveParasite();
-}
-
-// And clear it!
-in_cell.RemoveOrganism();
-if (organism->GetIsRunning() == false) delete organism;
-else organism->GetPhenotype().SetToDelete();
-
-// Alert the scheduler that this cell has a 0 merit.
-schedule->Adjust( in_cell.GetID(), cMerit(0) );
-
-// Update the genebank (note: genotype adjustment may be defered)
-genebank->AdjustGenotype(*genotype);
-}
-
-void cPopulation::Kaboom(cPopulationCell & in_cell)
-{
-  cOrganism * organism = in_cell.GetOrganism();
-  cGenotype * genotype = organism->GetGenotype();
-  cGenome genome = genotype->GetGenome();
-  int id = genotype->GetID();
-  
-  int radius = 2;
-  int distance = 0;
-  int count = 0;
-  
-  for (int i=-1*radius; i<=radius; i++) {
-    for (int j=-1*radius; j<=radius; j++) {
-      cPopulationCell & death_cell =
-      cell_array[GridNeighbor(in_cell.GetID(), world_x, world_y, i, j)];
-      //do we actually have something to kill?
-      if (death_cell.IsOccupied() == false) continue;
-      
-      cOrganism * org_temp = death_cell.GetOrganism();
-      cGenotype * gene_temp = org_temp->GetGenotype();
-      
-      if (distance == 0) {
-        int temp_id = gene_temp->GetID();
-        if (temp_id != id) {
-          KillOrganism(death_cell);
-          count++;
-        }
-      }
-      else {	
-        cGenome genome_temp = gene_temp->GetGenome();
-        int diff=0;
-        for (int i=0; i<genome_temp.GetSize(); i++)
-          if (genome_temp.AsString()[i] != genome.AsString()[i])
-            diff++;
-        if (diff > distance)
-        {
-          KillOrganism(death_cell);
-          count++;
-        }
-      }
-    }
-  }
-  KillOrganism(in_cell);
-  // @SLG my prediction = 92% and, 28 get equals
-}
-
-
-// CompeteDemes  probabilistically copies demes into the next generation
-// based on their fitness. How deme fitness is estimated is specified by 
-// competition_type input argument as by the birth count (1), average
-// fitness (2), or equal for all demes (3). For ease of use, each organism 
-// is setup as if it we just injected into the population.
-
-void cPopulation::CompeteDemes(int competition_type)
-{
-  
-  double total_fitness = 0; 
-  tArray<double> deme_fitness(num_demes); 
-  
-  switch(competition_type) {
-    case 0:    // deme fitness = 1; 
-      total_fitness = (double) num_demes;
-      deme_fitness.SetAll(1); 
-      break; 
-    case 1:     // deme fitness = number of births
-                // Determine the scale for fitness by totaling births across demes.
-      for (int cur_deme = 0; cur_deme < num_demes; cur_deme++) {
-        deme_fitness[cur_deme] = (double) deme_birth_count[cur_deme]; 
-        total_fitness += deme_birth_count[cur_deme];
-      }
-      break; 
-    case 2:    // deme fitness = average organism fitness at the current update
-      for (int cur_deme = 0; cur_deme < num_demes; cur_deme++) {
-        cDoubleSum single_deme_fitness;
-        for (int i = 0; i < deme_size; i++) {
-          int cur_cell = cur_deme * deme_size + i;
-          if (cell_array[cur_cell].IsOccupied() == false) continue;
-          cPhenotype & phenotype = GetCell(cur_cell).GetOrganism()->GetPhenotype();
-          single_deme_fitness.Add(phenotype.GetFitness());
-        } 
-        deme_fitness[cur_deme] = single_deme_fitness.Ave();
-        total_fitness += deme_fitness[cur_deme];
-      }
-      break; 
-    case 3: 	// deme fitness = average mutation rate at the current update 
-      for (int cur_deme = 0; cur_deme < num_demes; cur_deme++) {
-        cDoubleSum single_deme_div_type;
-        for (int i = 0; i < deme_size; i++) {
-          int cur_cell = cur_deme * deme_size + i;
-          if (cell_array[cur_cell].IsOccupied() == false) continue;
-          cPhenotype & phenotype = GetCell(cur_cell).GetOrganism()->GetPhenotype();
-          assert(phenotype.GetDivType()>0);
-          single_deme_div_type.Add(1/phenotype.GetDivType());
-        }
-        deme_fitness[cur_deme] = single_deme_div_type.Ave();
-        total_fitness += deme_fitness[cur_deme];
-      } 			 	      	
-      break; 
-    case 4: 	// deme fitness = 2^(-deme fitness rank) 
-              // first find all the deme fitness values ...
-    {      
-      for (int cur_deme = 0; cur_deme < num_demes; cur_deme++) {
-        cDoubleSum single_deme_fitness;
-        for (int i = 0; i < deme_size; i++) {
-          int cur_cell = cur_deme * deme_size + i; 
-          if (cell_array[cur_cell].IsOccupied() == false) continue;
-          cPhenotype & phenotype = GetCell(cur_cell).GetOrganism()->GetPhenotype();
-          single_deme_fitness.Add(phenotype.GetFitness());
-        }  
-        deme_fitness[cur_deme] = single_deme_fitness.Ave();
-      }
-      // ... then determine the rank of each deme based on its fitness
-      tArray<double> deme_rank(num_demes);
-      deme_rank.SetAll(1);
-      for (int cur_deme = 0; cur_deme < num_demes; cur_deme++) {
-        for (int test_deme = 0; test_deme < num_demes; test_deme++) {
-          if (deme_fitness[cur_deme] < deme_fitness[test_deme]) {
-            deme_rank[cur_deme]++;
-          } 
-        } 
-      } 
-      // ... finally, make deme fitness 2^(-deme rank)
-      deme_fitness.SetAll(1);	
-      for (int cur_deme = 0; cur_deme < num_demes; cur_deme++) {
-        for (int i = 0; i < deme_rank[cur_deme]; i++) { 
-          deme_fitness[cur_deme] = deme_fitness[cur_deme]/2;
-        } 
-        total_fitness += deme_fitness[cur_deme]; 
-      } 
-    }
-      break; 
-    case 5:    // deme fitness = average organism life fitness at the current update
-      for (int cur_deme = 0; cur_deme < num_demes; cur_deme++) {
-        cDoubleSum single_deme_life_fitness;
-        for (int i = 0; i < deme_size; i++) {
-          int cur_cell = cur_deme * deme_size + i;
-          if (cell_array[cur_cell].IsOccupied() == false) continue;
-          cPhenotype & phenotype = GetCell(cur_cell).GetOrganism()->GetPhenotype();
-          single_deme_life_fitness.Add(phenotype.GetLifeFitness());
-        }
-        deme_fitness[cur_deme] = single_deme_life_fitness.Ave();
-        total_fitness += deme_fitness[cur_deme];
-      }
-      break; 
-    case 6:     // deme fitness = 2^(-deme life fitness rank) (same as 4, but with life fitness)
-                // first find all the deme fitness values ...
-    {
-      for (int cur_deme = 0; cur_deme < num_demes; cur_deme++) {
-        cDoubleSum single_deme_life_fitness;
-        for (int i = 0; i < deme_size; i++) {
-          int cur_cell = cur_deme * deme_size + i;
-          if (cell_array[cur_cell].IsOccupied() == false) continue;
-          cPhenotype & phenotype = GetCell(cur_cell).GetOrganism()->GetPhenotype();
-          single_deme_life_fitness.Add(phenotype.GetLifeFitness());
-        }
-        deme_fitness[cur_deme] = single_deme_life_fitness.Ave();
-      }
-      // ... then determine the rank of each deme based on its fitness
-      tArray<double> deme_rank(num_demes);
-      deme_rank.SetAll(1);
-      for (int cur_deme = 0; cur_deme < num_demes; cur_deme++) {
-        for (int test_deme = 0; test_deme < num_demes; test_deme++) {
-          if (deme_fitness[cur_deme] < deme_fitness[test_deme]) {
-            deme_rank[cur_deme]++;
-          }
-        }
-      }
-      // ... finally, make deme fitness 2^(-deme rank)
-      deme_fitness.SetAll(1);
-      for (int cur_deme = 0; cur_deme < num_demes; cur_deme++) {
-        for (int i = 0; i < deme_rank[cur_deme]; i++) {
-          deme_fitness[cur_deme] = deme_fitness[cur_deme]/2;
-        }
-        total_fitness += deme_fitness[cur_deme];
-      }
-    }
-      break;
-  } 
-  
-  // Pick which demes should be in the next generation.
-  tArray<int> new_demes(num_demes);
-  for (int i = 0; i < num_demes; i++) {
-    double birth_choice = (double) g_random.GetDouble(total_fitness);
-    double test_total = 0;
-    for (int test_deme = 0; test_deme < num_demes; test_deme++) {
-      test_total += deme_fitness[test_deme];
-      if (birth_choice < test_total) {
-        new_demes[i] = test_deme;
-        break;
-      }
-    }
-  }
-  
-  // Track how many of each deme we should have.
-  tArray<int> deme_count(num_demes);
-  deme_count.SetAll(0);
-  for (int i = 0; i < num_demes; i++) {
-    deme_count[new_demes[i]]++;
-  }
-  
-  tArray<bool> is_init(num_demes); 
-  is_init.SetAll(false);
-  
-  // Copy demes until all deme counts are 1.
-  while (true) {
-    // Find the next deme to copy...
-    int from_deme, to_deme;
-    for (from_deme = 0; from_deme < num_demes; from_deme++) {
-      if (deme_count[from_deme] > 1) break;
-    }
-    if (from_deme == num_demes) break; // If we don't find another deme to copy
-    
-    for (to_deme = 0; to_deme < num_demes; to_deme++) {
-      if (deme_count[to_deme] == 0) break;
-    }
-    
-    // We now have both a from and a to deme....
-    deme_count[from_deme]--;
-    deme_count[to_deme]++;
-    
-    // Do the actual copy!
-    for (int i = 0; i < deme_size; i++) {
-      int from_cell = from_deme * deme_size + i;
-      int to_cell = to_deme * deme_size + i;
-      if (cell_array[from_cell].IsOccupied() == true) {
-        InjectClone( to_cell, *(cell_array[from_cell].GetOrganism()) );
-      }
-    }
-    is_init[to_deme] = true;
-  }
-  
-  // Now re-inject all remaining demes into themselves to reset them.
-  for (int cur_deme = 0; cur_deme < num_demes; cur_deme++) {
-    if (is_init[cur_deme] == true) continue;
-    for (int i = 0; i < deme_size; i++) {
-      int cur_cell = cur_deme * deme_size + i;
-      if (cell_array[cur_cell].IsOccupied() == false) continue;
-      InjectClone( cur_cell, *(cell_array[cur_cell].GetOrganism()) );
-    }
-  }
-  
-  deme_birth_count.SetAll(0);
-}
-
-
-// Reset Demes goes through each deme and resets the individual organisms as
-// if they were just injected into the population.
-
-void cPopulation::ResetDemes()
-{
-  // re-inject all demes into themselves to reset them.
-  for (int cur_deme = 0; cur_deme < num_demes; cur_deme++) {
-    for (int i = 0; i < deme_size; i++) {
-      int cur_cell = cur_deme * deme_size + i;
-      if (cell_array[cur_cell].IsOccupied() == false) continue;
-      InjectClone( cur_cell, *(cell_array[cur_cell].GetOrganism()) );
-    }
-  }
-}
-
-// Copy the contents of one deme into another.
-void cPopulation::CopyDeme(int deme1_id, int deme2_id)
-{
-  for (int i = 0; i < deme_size; i++) {
-    int from_cell = deme1_id * deme_size + i;
-    int to_cell = deme2_id * deme_size + i;
-    if (cell_array[from_cell].IsOccupied() == false) {
-      KillOrganism(cell_array[to_cell]);
-      continue;
-    }
-    InjectClone( to_cell, *(cell_array[from_cell].GetOrganism()) );    
-  }
-}
-
-
-// Print out statistics about individual demes
-
-void cPopulation::PrintDemeStats()
-{
-  cDataFile & df_fit = stats.GetDataFile("deme_fitness.dat");
-  cDataFile & df_life_fit = stats.GetDataFile("deme_lifetime_fitness.dat");
-  cDataFile & df_merit = stats.GetDataFile("deme_merit.dat");
-  cDataFile & df_gest = stats.GetDataFile("deme_gest_time.dat");
-  cDataFile & df_task = stats.GetDataFile("deme_task.dat");
-  cDataFile & df_donor = stats.GetDataFile("deme_donor.dat");
-  cDataFile & df_receiver = stats.GetDataFile("deme_receiver.dat");
-  
-  df_fit.WriteComment("Average fitnesses for each deme in the population");
-  df_life_fit.WriteComment("Average life fitnesses for each deme in the population");
-  df_merit.WriteComment("Average merits for each deme in population");
-  df_gest.WriteComment("Average gestation time for each deme in population");
-  df_task.WriteComment("Num orgs doing each task for each deme in population");
-  df_donor.WriteComment("Num orgs doing doing a donate for each deme in population");
-  df_receiver.WriteComment("Num orgs doing receiving a donate for each deme in population");
-  
-  df_fit.WriteTimeStamp();
-  df_life_fit.WriteTimeStamp();
-  df_merit.WriteTimeStamp();
-  df_gest.WriteTimeStamp();
-  df_task.WriteTimeStamp();
-  df_donor.WriteTimeStamp();
-  df_receiver.WriteTimeStamp();
-  
-  df_fit.Write(GetUpdate(), "update");
-  df_life_fit.Write(GetUpdate(), "update");
-  df_merit.Write(GetUpdate(), "update");
-  df_gest.Write(GetUpdate(), "update");
-  df_task.Write(GetUpdate(), "update");
-  df_donor.Write(GetUpdate(), "update");
-  df_receiver.Write(GetUpdate(), "update");
-  
-  const int num_inst = cConfig::GetNumInstructions();
-  const int num_task = environment.GetTaskLib().GetSize();
-  
-  for (int cur_deme = 0; cur_deme < num_demes; cur_deme++) {
-    cString filename;
-    filename.Set("deme_instruction-%d.dat", cur_deme);
-    cDataFile & df_inst = stats.GetDataFile(filename); 
-    cString comment;
-    comment.Set("Number of times each instruction is exectued in deme %d",
-                cur_deme);
-    df_inst.WriteComment(comment);
-    df_inst.WriteTimeStamp();
-    df_inst.Write(GetUpdate(), "update");
-    
-    cDoubleSum single_deme_fitness;
-    cDoubleSum single_deme_life_fitness;
-    cDoubleSum single_deme_merit;
-    cDoubleSum single_deme_gest_time;
-    cDoubleSum single_deme_donor;
-    cDoubleSum single_deme_receiver;
-    tArray<cIntSum> single_deme_task(num_task);
-    tArray<cIntSum> single_deme_inst(num_inst);
-    
-    for (int i = 0; i < deme_size; i++) {
-      int cur_cell = cur_deme * deme_size + i;
-      if (cell_array[cur_cell].IsOccupied() == false) continue;
-      cPhenotype & phenotype = GetCell(cur_cell).GetOrganism()->GetPhenotype();
-      single_deme_fitness.Add(phenotype.GetFitness()); 	
-      single_deme_life_fitness.Add(phenotype.GetLifeFitness()); 	
-      single_deme_merit.Add(phenotype.GetMerit().GetDouble()); 	
-      single_deme_gest_time.Add(phenotype.GetGestationTime()); 	
-      single_deme_donor.Add(phenotype.IsDonorLast()); 	
-      single_deme_receiver.Add(phenotype.IsReceiver()); 	
-      
-      for (int j = 0; j < num_inst; j++) {
-        single_deme_inst[j].Add(phenotype.GetLastInstCount()[j]);
-      } 
-      
-      for (int j = 0; j < num_task; j++) {
-        // only interested in tasks is done once! 
-        if (phenotype.GetLastTaskCount().ElementAt(j) > 0) {
-          single_deme_task[j].Add(1);
-        }
-      }
-    }
-    
-    comment.Set("Deme %d", cur_deme);
-    df_fit.Write(single_deme_fitness.Ave(), comment);
-    df_life_fit.Write(single_deme_life_fitness.Ave(), comment);
-    df_merit.Write(single_deme_merit.Ave(), comment);
-    df_gest.Write(single_deme_gest_time.Ave(), comment);
-    df_donor.Write(single_deme_donor.Sum(), comment);
-    df_receiver.Write(single_deme_receiver.Sum(), comment);
-    
-    for (int j = 0; j < num_task; j++) {
-      comment.Set("Deme %d, Task %d", cur_deme, j);
-      df_task.Write((int) single_deme_task[j].Sum(), comment);
-    }
-    
-    for (int j = 0; j < num_inst; j++) {
-      comment.Set("Inst %d", j);
-      df_inst.Write((int) single_deme_inst[j].Sum(), comment);
-    }
-    df_inst.Endl();
-  } 
-  
-  df_fit.Endl();
-  df_life_fit.Endl();
-  df_merit.Endl();
-  df_gest.Endl();
-  df_task.Endl();
-  df_donor.Endl();
-  df_receiver.Endl();
-}
-
-
-/**
-* This function is responsible for adding an organism to a given lineage,
- * and setting the organism's lineage label and the lineage pointer.
- **/
-
-void cPopulation::LineageSetupOrganism(cOrganism * organism, cLineage * lin,
-                                       int lin_label, cGenotype *parent_genotype)
-{
-  // If we have some kind of lineage control, adjust the default values
-  // passed in.
-  if ( lineage_control ){
-    lin = lineage_control->
-    AddCreature(organism->GetGenotype(), parent_genotype, lin, lin_label);
-    lin_label = lin->GetID();
-  }
-  
-  organism->SetLineageLabel( lin_label );
-  organism->SetLineage( lin );
-}
-
-
-/**
-* This function directs which position function should be used.  It
- * could have also been done with a function pointer, but the dividing
- * of an organism takes enough time that this will be a negligible addition,
- * and it gives a centralized function to work with.  The parent_ok flag asks
- * if it is okay to replace the parent.
- **/
-
-cPopulationCell & cPopulation::PositionChild(cPopulationCell & parent_cell,
-                                             bool parent_ok)
-{
-  assert(parent_cell.IsOccupied());
-  
-  const int birth_method = cConfig::GetBirthMethod();
-  
-  // Try out global/full-deme birth methods first...
-  
-  if (birth_method == POSITION_CHILD_FULL_SOUP_RANDOM) {
-    int out_pos = g_random.GetUInt(cell_array.GetSize());
-    while (parent_ok == false && out_pos == parent_cell.GetID()) {
-      out_pos = g_random.GetUInt(cell_array.GetSize());
-    }
-    return GetCell(out_pos);
-  }
-  else if (birth_method == POSITION_CHILD_FULL_SOUP_ELDEST) {
-    cPopulationCell * out_cell = reaper_queue.PopRear();
-    if (parent_ok == false && out_cell->GetID() == parent_cell.GetID()) {
-      out_cell = reaper_queue.PopRear();
-      reaper_queue.PushRear(&parent_cell);
-    }
-    return *out_cell;
-  }
-  else if (birth_method == POSITION_CHILD_DEME_RANDOM) {
-    const int parent_id = parent_cell.GetID();
-    const int cur_deme = parent_id / deme_size;
-    int out_pos = g_random.GetUInt(deme_size) + deme_size * cur_deme;
-    while (parent_ok == false && out_pos == parent_cell.GetID()) {
-      out_pos = g_random.GetUInt(deme_size) + deme_size * cur_deme;
-    }
-    deme_birth_count[cur_deme]++;
-    return GetCell(out_pos);    
-  }
-  
-  // Construct a list of equally viable locations to place the child...
-  tList<cPopulationCell> found_list;
-  
-  // First, check if there is an empty organism to work with (always preferred)
-  tList<cPopulationCell> & conn_list = parent_cell.ConnectionList();
-  
-  if (cConfig::GetPreferEmpty() == false &&
-      birth_method == POSITION_CHILD_RANDOM) {
-    found_list.Append(conn_list);
-    if (parent_ok == true) found_list.Push(&parent_cell);
-  } else {
-    FindEmptyCell(conn_list, found_list);
-  }
-  
-  // If we have not found an empty organism, we must use the specified function
-  // to determine how to choose among the filled organisms.
-  if (found_list.GetSize() == 0) {
-    switch(birth_method) {
-      case POSITION_CHILD_AGE:
-        PositionAge(parent_cell, found_list, parent_ok);
-        break;
-      case POSITION_CHILD_MERIT:
-        PositionMerit(parent_cell, found_list, parent_ok);
-        break;
-      case POSITION_CHILD_RANDOM:
-        found_list.Append(conn_list);
-        if (parent_ok == true) found_list.Push(&parent_cell);
-          break;
-      case POSITION_CHILD_EMPTY:
-        // Nothing is in list if no empty cells are found...
-        break;
-    }
-  }
-  
-  if (num_demes > 0) {
-    const int parent_id = parent_cell.GetID();
-    const int cur_deme = parent_id / deme_size;
-    deme_birth_count[cur_deme]++;
-  }
-  
-  // If there are no possibilities, return parent.
-  if (found_list.GetSize() == 0) return parent_cell;
-  
-  // Choose the organism randomly from those in the list, and return it.
-  int choice = g_random.GetUInt(found_list.GetSize());
-  return *( found_list.GetPos(choice) );
-}
-
-
-int cPopulation::ScheduleOrganism()
-{
-  return schedule->GetNextID();
-}
-
-void cPopulation::ProcessStep(double step_size, int cell_id)
-{
-  assert(step_size > 0.0);
-  assert(cell_id < cell_array.GetSize());
-  
-  // If cell_id is negative, no cell could be found -- stop here.
-  if (cell_id < 0) return;
-  
-  cPopulationCell & cell = GetCell(cell_id);
-  assert(cell.IsOccupied()); // Unoccupied cell getting processor time!
-  
-  //    static ofstream debug_fp("debug.trace");
-  //    debug_fp << stats.GetUpdate() << " "
-  //  	   << cell.GetOrganism()->GetCellID() << " "
-  //  	   << cell.GetOrganism()->GetGenotype()->GetID() << " "
-  //  	   << g_random.GetDouble() << " "
-  //      	   << cell.GetOrganism()->GetHardware().GetMemory().AsString() << " "
-  //  	   << endl;
-  
-  cOrganism * cur_org = cell.GetOrganism();
-  cur_org->GetHardware().SingleProcess();
-  if (cur_org->GetPhenotype().GetToDelete() == true) {
-    delete cur_org;
-  }
-  stats.IncExecuted();
-  resource_count.Update(step_size);
-}
-
-
-void cPopulation::ProcessStep(double step_size)
-{
-  ProcessStep( step_size, ScheduleOrganism() );
-}
-
-
-void cPopulation::UpdateOrganismStats()
-{
-  // Loop through all the cells getting stats and doing calculations
-  // which must be done on a creature by creature basis.
-  
-  // Clear out organism sums...
-  stats.SumFitness().Clear();
-  stats.SumGestation().Clear();
-  stats.SumMerit().Clear();
-  stats.SumCreatureAge().Clear();
-  stats.SumGeneration().Clear();
-  stats.SumNeutralMetric().Clear();
-  stats.SumLineageLabel().Clear();
-  stats.SumCopyMutRate().Clear();
-  stats.SumDivMutRate().Clear();
-  stats.SumCopySize().Clear();
-  stats.SumExeSize().Clear();
-  stats.SumMemSize().Clear();
-  
-  
-  stats.ZeroTasks();
-  
-#ifdef INSTRUCTION_COUNT
-  stats.ZeroInst();
-#endif
-  
-  // Counts...
-  int num_breed_true = 0;
-  int num_parasites = 0;
-  int num_no_birth = 0;
-  int num_multi_thread = 0;
-  int num_single_thread = 0;
-  int num_modified = 0;
-  
-  // Maximums...
-  cMerit max_merit(0);
-  double max_fitness = 0;
-  int max_gestation_time = 0;
-  int max_genome_length = 0;
-  
-  // Minimums...
-  cMerit min_merit(HUGE_VAL);
-  double min_fitness = HUGE_VAL;
-  int min_gestation_time = INT_MAX;
-  int min_genome_length = INT_MAX;
-  
-  for (int i = 0; i < cell_array.GetSize(); i++) {
-    // Only look at cells with organisms in them.
-    if (cell_array[i].IsOccupied() == false) {
-
-      // Genotype map needs zero for all non-occupied cells
-
-      stats.SetGenoMapElement(i, 0);
-      continue;
-    }
-
-    cOrganism * organism = cell_array[i].GetOrganism();
-    const cPhenotype & phenotype = organism->GetPhenotype();
-    const cMerit cur_merit = phenotype.GetMerit();
-    const double cur_fitness = phenotype.GetFitness();
-    const int cur_gestation_time = phenotype.GetGestationTime();
-    const int cur_genome_length = phenotype.GetGenomeLength();
-    
-    stats.SumFitness().Add(cur_fitness);
-    stats.SumMerit().Add(cur_merit.GetDouble());
-    stats.SumGestation().Add(phenotype.GetGestationTime());
-    stats.SumCreatureAge().Add(phenotype.GetAge());
-    stats.SumGeneration().Add(phenotype.GetGeneration());
-    stats.SumNeutralMetric().Add(phenotype.GetNeutralMetric());
-    stats.SumLineageLabel().Add(organism->GetLineageLabel());
-    stats.SumCopyMutRate().Add(organism->MutationRates().GetCopyMutProb());
-    stats.SumLogCopyMutRate().Add(log(organism->MutationRates().GetCopyMutProb()));
-    stats.SumDivMutRate().Add(organism->MutationRates().GetDivMutProb() / organism->GetPhenotype().GetDivType());
-    stats.SumLogDivMutRate().Add(log(organism->MutationRates().GetDivMutProb() /organism->GetPhenotype().GetDivType()));
-    stats.SumCopySize().Add(phenotype.GetCopiedSize());
-    stats.SumExeSize().Add(phenotype.GetExecutedSize());
-    stats.SetGenoMapElement(i, organism->GetGenotype()->GetID());
-    
-#ifdef INSTRUCTION_COUNT
-    //    for (int j=0; j < environment.GetInstSet().GetSize(); j++) {
-    for (int j=0; j < cConfig::GetNumInstructions(); j++) {
-      stats.SumExeInst()[j].Add(organism->GetPhenotype().GetLastInstCount()[j]);
-    }
-#endif
-    
-    if (cur_merit > max_merit) max_merit = cur_merit;
-    if (cur_fitness > max_fitness) max_fitness = cur_fitness;
-    if (cur_gestation_time > max_gestation_time) max_gestation_time = cur_gestation_time;
-    if (cur_genome_length > max_genome_length) max_genome_length = cur_genome_length;
-    
-    if (cur_merit < min_merit) min_merit = cur_merit;
-    if (cur_fitness < min_fitness) min_fitness = cur_fitness;
-    if (cur_gestation_time < min_gestation_time) min_gestation_time = cur_gestation_time;
-    if (cur_genome_length < min_genome_length) min_genome_length = cur_genome_length;
-    
-    // Test what tasks this creatures has completed.
-    for (int j=0; j < phenotype.GetEnvironment().GetTaskLib().GetSize(); j++) {
-      if (phenotype.GetCurTaskCount()[j] > 0)  stats.AddCurTask(j);
-      if (phenotype.GetLastTaskCount()[j] > 0) stats.AddLastTask(j);
-      if (phenotype.GetLastTaskCount()[j] > 0) 
-        stats.IncTaskExeCount(j, phenotype.GetLastTaskCount()[j]);
-    }
-    
-    // Increment the counts for all qualities the organism has...
-    if (phenotype.ParentTrue()) num_breed_true++;
-    if (phenotype.IsParasite()) num_parasites++;
-    if( phenotype.GetNumDivides() == 0 ) num_no_birth++;
-    if(phenotype.IsMultiThread()) num_multi_thread++;
-    else num_single_thread++;
-    if(phenotype.IsModified()) num_modified++;
-    
-    // Hardware specific collections...
-    if (organism->GetHardware().GetType() == HARDWARE_TYPE_CPU_ORIGINAL) {
-      cHardwareBase & hardware = organism->GetHardware();
-      stats.SumMemSize().Add(hardware.GetMemory().GetSize());
-    }
-    
-    // Increment the age of this organism.
-    organism->GetPhenotype().IncAge();
-    }
-  
-  stats.SetBreedTrueCreatures(num_breed_true);
-  stats.SetNumNoBirthCreatures(num_no_birth);
-  stats.SetNumParasites(num_parasites);
-  stats.SetNumSingleThreadCreatures(num_single_thread);
-  stats.SetNumMultiThreadCreatures(num_multi_thread);
-  stats.SetNumModified(num_modified);
-  
-  stats.SetMaxMerit(max_merit.GetDouble());
-  stats.SetMaxFitness(max_fitness);
-  stats.SetMaxGestationTime(max_gestation_time);
-  stats.SetMaxGenomeLength(max_genome_length);
-  
-  stats.SetMinMerit(min_merit.GetDouble());
-  stats.SetMinFitness(min_fitness);
-  stats.SetMinGestationTime(min_gestation_time);
-  stats.SetMinGenomeLength(min_genome_length);
-  
-  stats.SetResources(resource_count.GetResources());
-  stats.SetSpatialRes(resource_count.GetSpatialRes());
-  stats.SetResourcesGeometry(resource_count.GetResourcesGeometry());
-  }
-
-
-void cPopulation::UpdateGenotypeStats()
-{
-  // Loop through all genotypes, finding stats and doing calcuations.
-  
-  // Clear out genotype sums...
-  stats.SumGenotypeAge().Clear();
-  stats.SumAbundance().Clear();
-  stats.SumGenotypeDepth().Clear();
-  stats.SumSize().Clear();
-  stats.SumThresholdAge().Clear();
-  
-  double entropy = 0.0;
-  
-  cGenotype * cur_genotype = genebank->GetBestGenotype();
-  for (int i = 0; i < genebank->GetSize(); i++) {
-    const int abundance = cur_genotype->GetNumOrganisms();
-    
-    // If we're at a dead genotype, we've hit the end of the list!
-    if (abundance == 0) break;
-    
-    // Update stats...
-    const int age = stats.GetUpdate() - cur_genotype->GetUpdateBorn();
-    stats.SumGenotypeAge().Add(age, abundance);
-    stats.SumAbundance().Add(abundance);
-    stats.SumGenotypeDepth().Add(cur_genotype->GetDepth(), abundance);
-    stats.SumSize().Add(cur_genotype->GetLength(), abundance);
-    
-    // Calculate this genotype's contribution to entropy
-    const double p = ((double) abundance) / (double) num_organisms;
-    const double partial_ent = -(p * Log(p));
-    entropy += partial_ent;
-    
-    // Do any special calculations for threshold genotypes.
-    if (cur_genotype->GetThreshold()) {
-      stats.SumThresholdAge().Add(age, abundance);
-    }
-    
-    // ...and advance to the next genotype...
-    cur_genotype = cur_genotype->GetNext();
-  }
-  
-  stats.SetEntropy(entropy);
-}
-
-
-void cPopulation::UpdateSpeciesStats()
-{
-  double species_entropy = 0.0;
-  
-  stats.SumSpeciesAge().Clear();
-  
-  // Loop through all species that need to be reset prior to calculations.
-  cSpecies * cur_species = genebank->GetFirstSpecies();
-  for (int i = 0; i < genebank->GetNumSpecies(); i++) {
-    cur_species->ResetStats();
-    cur_species = cur_species->GetNext();
-  }
-  
-  // Collect info from genotypes and send it to their species.
-  cGenotype * genotype = genebank->GetBestGenotype();
-  for (int i = 0; i < genebank->GetSize(); i++) {
-    if (genotype->GetSpecies() != NULL) {
-      genotype->GetSpecies()->AddOrganisms(genotype->GetNumOrganisms());
-    }
-    genotype = genotype->GetNext();
-  }
-  
-  // Loop through all of the species in the soup, taking info on them.
-  cur_species = genebank->GetFirstSpecies();
-  for (int i = 0; i < genebank->GetNumSpecies(); i++) {
-    const int abundance = cur_species->GetNumOrganisms();
-    // const int num_genotypes = cur_species->GetNumGenotypes();
-    
-    // Basic statistical collection...
-    const int species_age = stats.GetUpdate() - cur_species->GetUpdateBorn();
-    stats.SumSpeciesAge().Add(species_age, abundance);
-    
-    // Caculate entropy on the species level...
-    if (abundance > 0) {
-      double p = ((double) abundance) / (double) num_organisms;
-      double partial_ent = -(p * Log(p));
-      species_entropy += partial_ent;
-    }
-    
-    // ...and advance to the next species...
-    cur_species = cur_species->GetNext();
-  }
-  
-  stats.SetSpeciesEntropy(species_entropy);
-}
-
-void cPopulation::UpdateDominantStats()
-{
-  cGenotype * dom_genotype = genebank->GetBestGenotype();
-  if (dom_genotype == NULL) return;
-  
-  stats.SetDomGenotype(dom_genotype);
-  stats.SetDomMerit(dom_genotype->GetMerit());
-  stats.SetDomGestation(dom_genotype->GetGestationTime());
-  stats.SetDomReproRate(dom_genotype->GetReproRate());
-  stats.SetDomFitness(dom_genotype->GetFitness());
-  stats.SetDomCopiedSize(dom_genotype->GetCopiedSize());
-  stats.SetDomExeSize(dom_genotype->GetExecutedSize());
-  
-  stats.SetDomSize(dom_genotype->GetLength());
-  stats.SetDomID(dom_genotype->GetID());
-  stats.SetDomName(dom_genotype->GetName());
-  stats.SetDomBirths(dom_genotype->GetThisBirths());
-  stats.SetDomBreedTrue(dom_genotype->GetThisBreedTrue());
-  stats.SetDomBreedIn(dom_genotype->GetThisBreedIn());
-  stats.SetDomBreedOut(dom_genotype->GetThisBreedOut());
-  stats.SetDomAbundance(dom_genotype->GetNumOrganisms());
-  stats.SetDomGeneDepth(dom_genotype->GetDepth());
-  stats.SetDomSequence(dom_genotype->GetGenome().AsString());
-}
-
-void cPopulation::UpdateDominantParaStats()
-{
-  cInjectGenotype * dom_inj_genotype = inject_genebank->GetBestInjectGenotype();
-  if (dom_inj_genotype == NULL) return;
-  
-  stats.SetDomInjGenotype(dom_inj_genotype);
-  //stats.SetDomMerit(dom_genotype->GetMerit());
-  //stats.SetDomGestation(dom_genotype->GetGestationTime());
-  //stats.SetDomReproRate(dom_genotype->GetReproRate());
-  //stats.SetDomFitness(dom_genotype->GetFitness());
-  //stats.SetDomCopiedSize(dom_genotype->GetCopiedSize());
-  //stats.SetDomExeSize(dom_genotype->GetExecutedSize());
-  
-  stats.SetDomInjSize(dom_inj_genotype->GetLength());
-  stats.SetDomInjID(dom_inj_genotype->GetID());
-  stats.SetDomInjName(dom_inj_genotype->GetName());
-  //stats.SetDomInjBirths(dom_inj_genotype->GetThisBirths());
-  //stats.SetDomBreedTrue(dom_genotype->GetThisBreedTrue());
-  //stats.SetDomBreedIn(dom_genotype->GetThisBreedIn());
-  //stats.SetDomBreedOut(dom_genotype->GetThisBreedOut());
-  stats.SetDomInjAbundance(dom_inj_genotype->GetNumInjected());
-  //stats.SetDomInjGeneDepth(dom_inj_genotype->GetDepth());
-  stats.SetDomInjSequence(dom_inj_genotype->GetGenome().AsString());
-}
-
-void cPopulation::CalcUpdateStats()
-{
-  // Reset the Genebank to prepare it for stat collection.
-  genebank->UpdateReset();
-  
-  UpdateOrganismStats();
-  UpdateGenotypeStats();
-  UpdateSpeciesStats();
-  UpdateDominantStats();
-  UpdateDominantParaStats();
-  
-  // Do any final calculations...
-  stats.SetNumCreatures(GetNumOrganisms());
-  stats.SetNumGenotypes(genebank->GetSize());
-  stats.SetNumThreshSpecies(genebank->GetNumSpecies());
-  
-  // Have stats calculate anything it now can...
-  stats.CalcEnergy();
-  stats.CalcFidelity();
-}
-
-
-bool cPopulation::SaveClone(ofstream & fp)
-{
-  if (fp.good() == false) return false;
-  
-  // Save the current update
-  fp << stats.GetUpdate() << " ";
-  
-  // Save the genebank info.
-  genebank->SaveClone(fp);
-  
-  // Save the genotypes manually.
-  fp << genebank->GetSize() << " ";
-  
-  cGenotype * cur_genotype = genebank->GetBestGenotype();
-  for (int i = 0; i < genebank->GetSize(); i++) {
-    cur_genotype->SaveClone(fp);
-    
-    // Advance...
-    cur_genotype = cur_genotype->GetNext();
-  }
-  
-  // Save the organim layout...
-  fp << cell_array.GetSize() << " ";
-  for (int i = 0; i < cell_array.GetSize(); i++) {
-    if (cell_array[i].IsOccupied() == true) {
-      fp <<  cell_array[i].GetOrganism()->GetGenotype()->GetID() << " ";
-    }
-    else fp << "-1 ";
-  }
-  
-  return true;
-}
-
-
-bool cPopulation::LoadClone(ifstream & fp)
-{
-  if (fp.good() == false) return false;
-  
-  // Pick up the update where it was left off.
-  int cur_update;
-  fp >> cur_update;
-  
-  stats.SetCurrentUpdate(cur_update);
-  
-  // Clear out the population
-  for (int i = 0; i < cell_array.GetSize(); i++) KillOrganism(cell_array[i]);
-  
-  // Load the genebank info.
-  genebank->LoadClone(fp);
-  
-  // Load up the genotypes.
-  int num_genotypes = 0;
-  fp >> num_genotypes;
-  
-  cGenotype * genotype_array = new cGenotype[num_genotypes];
-  for (int i = 0; i < num_genotypes; i++) genotype_array[i].LoadClone(fp);
-  
-  // Now load them into the organims.  @CAO make sure cell_array.GetSize() is right!
-  int in_num_cells;
-  int genotype_id;
-  fp >> in_num_cells;
-  if (cell_array.GetSize() != in_num_cells) return false;
-  
-  for (int i = 0; i < cell_array.GetSize(); i++) {
-    fp >> genotype_id;
-    if (genotype_id == -1) continue;
-    int genotype_index = -1;
-    for (int j = 0; j < num_genotypes; j++) {
-      if (genotype_array[j].GetID() == genotype_id) {
-        genotype_index = j;
-        break;
-      }
-    }
-    
-    assert(genotype_index != -1);
-    InjectGenome(i, genotype_array[genotype_index].GetGenome(), 0);
-  }
-  
-  sync_events = true;
-  
-  return true;
-}
-
-// This class is needed for the next function
-class cTmpGenotype {
-public:
-  int id_num;
-  int parent_id;
-  int num_cpus;
-  int total_cpus;
-  double merit;
-  int update_born;
-  int update_dead;
-  
-  cGenotype *genotype;
-  
-  bool operator<( const cTmpGenotype rhs ) const {
-    return id_num < rhs.id_num; }
-};	
-
-
-bool cPopulation::LoadDumpFile(cString filename, int update)
-{
-  // set the update if requested
-  if ( update >= 0 )
-    stats.SetCurrentUpdate(update);
-  
-  // Clear out the population
-  for (int i = 0; i < cell_array.GetSize(); i++) KillOrganism(cell_array[i]);
-  
-  cout << "Loading: " << filename << endl;
-  
-  cInitFile input_file(filename);
-  if (!input_file.IsOpen()) {
-    cerr << "Error: Cannot load file: \"" << filename << "\"." << endl;
-    exit(1);
-  }
-  input_file.Load();
-  input_file.Compress();
-  input_file.Close();
-  
-  // First, we read in all the genotypes and store them in a list
-  
-  vector<cTmpGenotype> genotype_vect;
-  
-  for (int line_id = 0; line_id < input_file.GetNumLines(); line_id++) {
-    cString cur_line = input_file.GetLine(line_id);
-    
-    // Setup the genotype for this line...
-    cTmpGenotype tmp;
-    tmp.id_num      = cur_line.PopWord().AsInt();
-    tmp.parent_id   = cur_line.PopWord().AsInt();
-    /*parent_dist =*/          cur_line.PopWord().AsInt();
-    tmp.num_cpus    = cur_line.PopWord().AsInt();
-    tmp.total_cpus  = cur_line.PopWord().AsInt();
-    /*length      =*/          cur_line.PopWord().AsInt();
-    tmp.merit 	    = cur_line.PopWord().AsDouble();
-    /*gest_time   =*/ cur_line.PopWord().AsInt();
-    /*fitness     =*/ cur_line.PopWord().AsDouble();
-    tmp.update_born = cur_line.PopWord().AsInt();
-    tmp.update_dead = cur_line.PopWord().AsInt();
-    /*depth       =*/ cur_line.PopWord().AsInt();
-    cString name = cStringUtil::Stringf("org-%d", tmp.id_num);
-    cGenome genome( cur_line.PopWord() );
-    
-    // we don't allow birth or death times larger than the current update
-    if ( stats.GetUpdate() > tmp.update_born )
-      tmp.update_born = stats.GetUpdate();
-    if ( stats.GetUpdate() > tmp.update_dead )
-      tmp.update_dead = stats.GetUpdate();
-    
-    tmp.genotype =
-      new cGenotype(tmp.update_born, tmp.id_num);
-    tmp.genotype->SetGenome( genome );
-    tmp.genotype->SetName( name );
-    
-    genotype_vect.push_back( tmp );
-  }
-  
-  // now, we sort them in ascending order according to their id_num
-  sort( genotype_vect.begin(), genotype_vect.end() );
-  // set the parents correctly
-  
-  vector<cTmpGenotype>::const_iterator it = genotype_vect.begin();
-  for ( ; it != genotype_vect.end(); it++ ){
-    vector<cTmpGenotype>::const_iterator it2 = it;
-    cGenotype *parent = 0;
-    // search backwards till we find the parent
-    if ( it2 != genotype_vect.begin() )
-      do{
-        it2--;
-        if ( (*it).parent_id == (*it2).id_num ){
-          parent = (*it2).genotype;
-          break;
-        }	
-      }
-        while ( it2 != genotype_vect.begin() );
-    (*it).genotype->SetParent( parent, NULL );
-  }
-  
-  int cur_update = stats.GetUpdate(); 
-  int current_cell = 0;
-  bool soup_full = false;
-  it = genotype_vect.begin();
-  for ( ; it != genotype_vect.end(); it++ ){
-    genebank->AddGenotype( (*it).genotype );
-    if ( (*it).num_cpus == 0 ){ // historic organism
-                                // remove immediately, so that it gets transferred into the
-                                // historic database. We change the update temporarily to the
-                                // true death time of this organism, so that all stats are correct.
-      stats.SetCurrentUpdate( (*it).update_dead );
-      genebank->RemoveGenotype( *(*it).genotype );
-      stats.SetCurrentUpdate( cur_update );
-    }
-    else{ // otherwise, we insert as many organisms as we need
-      for ( int i=0; i<(*it).num_cpus; i++ ){
-        if ( current_cell >= cell_array.GetSize() ){
-          soup_full = true;
-          break;
-        }	  
-        InjectGenotype( current_cell, (*it).genotype );
-        cPhenotype & phenotype = GetCell(current_cell).GetOrganism()->GetPhenotype();
-        if ( (*it).merit > 0) phenotype.SetMerit( cMerit((*it).merit) );
-        schedule->Adjust(current_cell, phenotype.GetMerit());
-        
-        int lineage_label = 0;
-        LineageSetupOrganism(GetCell(current_cell).GetOrganism(),
-                             0, lineage_label,
-                             (*it).genotype->GetParentGenotype());
-        current_cell += 1;
-      }
-    }
-    cout << (*it).id_num << " "
-      << (*it).parent_id << " "
-      << (*it).genotype->GetParentID() << " "
-      << (*it).genotype->GetNumOffspringGenotypes() << " "
-      << (*it).num_cpus << " "
-      << (*it).genotype->GetNumOrganisms() << endl;
-    if (soup_full){
-      cout << "cPopulation::LoadDumpFile: You are trying to load more organisms than there is space!" << endl;
-      cout << "cPopulation::LoadDumpFile: Remaining organisms are ignored." << endl;
-      break;
-    }
-  }
-  sync_events = true;
-  
-  return true;
-}
-
-//// Save And Load Populations ////
-bool cPopulation::SavePopulation(ofstream & fp)
-{
-  if (fp.good() == false) return false;
-  
-  // Save the update
-  fp << stats.GetUpdate() << endl;
-  
-  // looping through all cells saving state.
-  for (int i = 0; i < cell_array.GetSize(); i++)  cell_array[i].SaveState(fp);
-  
-  return true;
-}
-
-
-bool cPopulation::LoadPopulation(ifstream & fp)
-{
-  if(fp.good() == false) return false;
-  
-  // Load Update...
-  int cur_update;
-  fp >> cur_update;
-  stats.SetCurrentUpdate(cur_update);
-  
-  // Clear out the current population
-  for (int i = 0; i < cell_array.GetSize(); i++) KillOrganism( cell_array[i] );
-  
-  // looping through all organims
-  for (int i = 0; i < cell_array.GetSize(); i++) cell_array[i].LoadState(fp);
-  
-  sync_events = true;
-  
-  return true;
-}
-
-
-bool cPopulation::DumpMemorySummary(ofstream & fp)
-{
-  if (fp.good() == false) return false;
-  
-  // Dump the memory...
-  
-  for (int i = 0; i < cell_array.GetSize(); i++) {
-    fp << i << " ";
-    if (cell_array[i].IsOccupied() == false) {
-      fp << "EMPTY" << endl;
-    }
-    else {
-      cGenome & mem = cell_array[i].GetOrganism()->GetHardware().GetMemory();
-      fp << mem.GetSize() << " "
-        << mem.AsString() << endl;
-    }
-  }
-  return true;
-}
-
-bool cPopulation::OK()
-{
-  // First check all sub-objects...
-  if (!genebank->OK() || !schedule->OK()) return false;
-  
-  // Next check organisms...
-  for (int i = 0; i < cell_array.GetSize(); i++) {
-    if (cell_array[i].OK() == false) return false;
-    assert(cell_array[i].GetID() == i);
-  }
-  
-  // And stats...
-  assert(world_x * world_y == cell_array.GetSize());
-  
-  return true;
-}
-
-
-/**
-* This function loads a genome from a given file, and initializes
- * a cpu with it.
- *
- * @param filename The name of the file to load.
- * @param in_cpu The grid-position into which the genome should be loaded.
- * @param merit An initial merit value.
- * @param lineage_label A value that allows to track the daughters of
- * this organism.
- **/
-
-void cPopulation::Inject(const cGenome & genome, int cell_id, double merit, 
-                         int lineage_label, double neutral, int mem_space )
-{
-  // If an invalid cell was given, choose a new ID for it.
-  if (cell_id < 0) {
-    switch (cConfig::GetBirthMethod()) {
-      case POSITION_CHILD_FULL_SOUP_ELDEST:
-        cell_id = reaper_queue.PopRear()->GetID();
-      default:
-        cell_id = 0;
-    }
-  }
-  
-  if(mem_space==0) {
-    InjectGenome( cell_id, genome, lineage_label );
-    cPhenotype & phenotype = GetCell(cell_id).GetOrganism()->GetPhenotype();
-    phenotype.SetNeutralMetric(neutral);
-    
-    if (merit > 0) phenotype.SetMerit( cMerit(merit) );
-    schedule->Adjust(cell_id, phenotype.GetMerit());
-    
-    LineageSetupOrganism(GetCell(cell_id).GetOrganism(), 0, lineage_label);
-  }
-  else
-  {
-    ActivateInject(cell_id, genome);
-  }
-  
-}
-
-cPopulationCell & cPopulation::GetCell(int in_num)
-{
-  return cell_array[in_num];
-}
-
-
-void cPopulation::UpdateResources(const tArray<double> & res_change)
-{
-  resource_count.Modify(res_change);
-}
-
-void cPopulation::UpdateResource(int id, double change)
-{
-  resource_count.Modify(id, change);
-}
-
-void cPopulation::UpdateCellResources(const tArray<double> & res_change, 
-                                      const int cell_id)
-{
-  resource_count.ModifyCell(res_change, cell_id);
-}
-
-void cPopulation::SetResource(int id, double new_level)
-{
-  resource_count.Set(id, new_level);
-}
-
-void cPopulation::BuildTimeSlicer(cChangeList * change_list)
-{
-  switch (cConfig::GetSlicingMethod()) {
-    case SLICE_CONSTANT:
-      schedule = new cConstSchedule(cell_array.GetSize());
-      break;
-    case SLICE_PROB_MERIT:
-      schedule = new cProbSchedule(cell_array.GetSize());
-      break;
-    case SLICE_INTEGRATED_MERIT:
-      schedule = new cIntegratedSchedule(cell_array.GetSize());
-      break;
-    default:
-      cout << "Warning: Requested Time Slicer not found, defaulting to Integrated." << endl;
-      schedule = new cIntegratedSchedule(cell_array.GetSize());
-      break;
-  }
-  schedule->SetChangeList(change_list);
-}
-
-
-void cPopulation::PositionAge(cPopulationCell & parent_cell,
-                              tList<cPopulationCell> & found_list,
-                              bool parent_ok)
-{
-  // Start with the parent organism as the replacement, and see if we can find
-  // anything equivilent or better.
-  
-  found_list.Push(&parent_cell);
-  int max_age = parent_cell.GetOrganism()->GetPhenotype().GetAge();
-  if (parent_ok == false) max_age = -1;
-  
-  // Now look at all of the neighbors.
-  tListIterator<cPopulationCell> conn_it( parent_cell.ConnectionList() );
-  
-  cPopulationCell * test_cell;
-  while ( (test_cell = conn_it.Next()) != NULL) {
-    const int cur_age = test_cell->GetOrganism()->GetPhenotype().GetAge();
-    if (cur_age > max_age) {
-      max_age = cur_age;
-      found_list.Clear();
-      found_list.Push(test_cell);
-    }
-    else if (cur_age == max_age) {
-      found_list.Push(test_cell);
-    }
-  }
-}
-
-void cPopulation::PositionMerit(cPopulationCell & parent_cell,
-                                tList<cPopulationCell> & found_list,
-                                bool parent_ok)
-{
-  // Start with the parent organism as the replacement, and see if we can find
-  // anything equivilent or better.
-  
-  found_list.Push(&parent_cell);
-  double max_ratio = parent_cell.GetOrganism()->CalcMeritRatio();
-  if (parent_ok == false) max_ratio = -1;
-  
-  // Now look at all of the neighbors.
-  tListIterator<cPopulationCell> conn_it( parent_cell.ConnectionList() );
-  
-  cPopulationCell * test_cell;
-  while ( (test_cell = conn_it.Next()) != NULL) {
-    const double cur_ratio = test_cell->GetOrganism()->CalcMeritRatio();
-    if (cur_ratio > max_ratio) {
-      max_ratio = cur_ratio;
-      found_list.Clear();
-      found_list.Push(test_cell);
-    }
-    else if (cur_ratio == max_ratio) {
-      found_list.Push(test_cell);
-    }
-  }
-}
-
-void cPopulation::FindEmptyCell(tList<cPopulationCell> & cell_list,
-                                tList<cPopulationCell> & found_list)
-{
-  tListIterator<cPopulationCell> cell_it(cell_list);
-  cPopulationCell * test_cell;
-  
-  while ( (test_cell = cell_it.Next()) != NULL) {
-    // If this cell is empty, add it to the list...
-    if (test_cell->IsOccupied() == false) found_list.Push(test_cell);
-  }
-}
-
-// This function injects a new organism into the population at cell_id based
-// on the genotype passed in.
-
-void cPopulation::InjectGenotype(int cell_id, cGenotype *new_genotype)
-{
-  assert(cell_id >= 0 && cell_id < cell_array.GetSize());
-  
-  cOrganism * new_organism = new cOrganism(new_genotype->GetGenome(),
-                                           default_interface,
-                                           environment);
-  
-  // Set the genotype...
-  new_organism->SetGenotype(new_genotype);
-  
-  // Setup the phenotype...
-  cPhenotype & phenotype = new_organism->GetPhenotype();
-  phenotype.SetupInject(new_genotype->GetLength());
-  phenotype.SetMerit( cMerit(new_genotype->GetTestMerit()) );
-  
-  // @CAO are these really needed?
-  phenotype.SetLinesCopied( new_genotype->GetTestCopiedSize() );
-  phenotype.SetLinesExecuted( new_genotype->GetTestExecutedSize() );
-  phenotype.SetGestationTime( new_genotype->GetTestGestationTime() );
-  
-  // Prep the cell..
-  if (cConfig::GetBirthMethod() == POSITION_CHILD_FULL_SOUP_ELDEST &&
-      cell_array[cell_id].IsOccupied() == true) {
-    // Have to manually take this cell out of the reaper Queue.
-    reaper_queue.Remove( &(cell_array[cell_id]) );
-  }
-  
-  // Setup the child's mutation rates.  Since this organism is being injected
-  // and has no parent, we should always take the rate from the environment.
-  new_organism->MutationRates().Copy(cell_array[cell_id].MutationRates());
-  
-  
-  // Activate the organism in the population...
-  ActivateOrganism(new_organism, cell_array[cell_id]);
-}
-
-
-// This function injects a new organism into the population at cell_id that
-// is an exact clone of the organism passed in.
-
-void cPopulation::InjectClone(int cell_id, cOrganism & orig_org)
-{
-  assert(cell_id >= 0 && cell_id < cell_array.GetSize());
-  
-  cOrganism * new_organism = new cOrganism(orig_org.GetGenome(),
-                                           default_interface, environment);
-  
-  // Set the genotype...
-  new_organism->SetGenotype(orig_org.GetGenotype());
-  
-  // Setup the phenotype...
-  new_organism->GetPhenotype().SetupClone(orig_org.GetPhenotype());
-  
-  // Prep the cell..
-  if (cConfig::GetBirthMethod() == POSITION_CHILD_FULL_SOUP_ELDEST &&
-      cell_array[cell_id].IsOccupied() == true) {
-    // Have to manually take this cell out of the reaper Queue.
-    reaper_queue.Remove( &(cell_array[cell_id]) );
-  }
-  
-  // Setup the mutation rate based on the population cell...
-  new_organism->MutationRates().Copy(cell_array[cell_id].MutationRates());
-  
-  // Activate the organism in the population...
-  ActivateOrganism(new_organism, cell_array[cell_id]);
-}
-
-
-void cPopulation::InjectGenome(int cell_id, const cGenome & genome,
-                               int lineage_label)
-{
-  // Setup the genotype...
-  cGenotype * new_genotype = genebank->InjectGenotype(genome, lineage_label);
-  
-  // The rest is done by InjectGenotype();
-  InjectGenotype( cell_id, new_genotype );
-}
-
-
-void cPopulation::SerialTransfer(int transfer_size, bool ignore_deads)
-{
-  assert(transfer_size > 0);
-  
-  // If we are ignoring all dead organisms, remove them from the population.
-  if (ignore_deads == true) {
-    for (int i = 0; i < GetSize(); i++) {
-      cPopulationCell & cell = cell_array[i];
-      if (cell.IsOccupied() && cell.GetOrganism()->GetTestFitness() == 0.0) {
-        KillOrganism(cell);
-      }
-    }
-  }
-  
-  // If removing the dead was enough, stop here.
-  if (num_organisms <= transfer_size) return;
-  
-  // Collect a vector of the occupied cells...
-  vector<int> transfer_pool;
-  transfer_pool.reserve(num_organisms);
-  for (int i = 0; i < GetSize(); i++) {
-    if (cell_array[i].IsOccupied()) transfer_pool.push_back(i);
-  }
-  
-  // Remove the proper number of cells.
-  const int removal_size = num_organisms - transfer_size;
-  for (int i = 0; i < removal_size; i++) {
-    int j = (int) g_random.GetUInt(transfer_pool.size());
-    KillOrganism(cell_array[transfer_pool[j]]);
-    transfer_pool[j] = transfer_pool.back();
-    transfer_pool.pop_back();
-  }
-}
-
-void cPopulation::ParasiteDebug()
-{
-  ofstream outfile;
-  outfile.open("debug.out", ofstream::app);
-  outfile << stats.GetUpdate() << endl;
-  int total=0;
-  cInjectGenotype * temp;
-  for(int x=0; x<cell_array.GetSize(); x++)
-  {
-    if(cell_array[x].GetOrganism()!=NULL)
-    {
-      assert(cell_array[x].GetOrganism()->GetNumParasites()>=0 && 
-             cell_array[x].GetOrganism()->GetNumParasites()<=1);
-      total+=cell_array[x].GetOrganism()->GetNumParasites();
-      if(cell_array[x].GetOrganism()->GetNumParasites())
-	    {
-	      cHardware4Stack & cpu = (cHardware4Stack &) cell_array[x].GetOrganism()->GetHardware();
-	      outfile << x << " ";
-	      outfile << cell_array[x].GetOrganism()->GetGenotype()->GetID() << " ";
-	      temp = cpu.GetThreadOwner(1);
-	      assert(temp!=NULL);
-	      outfile << temp->GetID() << endl;	      
-	    }
-    }
-  }
-  outfile << total << endl;
-  outfile.close();
-}
-
-void cPopulation::PrintPhenotypeData(const cString & filename)
-{
-  set<int> ids;
-  for (int i = 0; i < cell_array.GetSize(); i++) 
-  {
-    // Only look at cells with organisms in them.
-    if (cell_array[i].IsOccupied() == false) continue;
-    
-    cOrganism * organism = cell_array[i].GetOrganism();
-    const cPhenotype & phenotype = organism->GetPhenotype();
-    
-    int id = 0;
-    for (int j = 0; j < phenotype.GetLastTaskCount().GetSize(); j++)
-    {
-      if (phenotype.GetLastTaskCount().ElementAt(j) > 0)
-        id += (1 << j);
-    }
-    ids.insert(id);
-  }
-  ofstream outfile;
-  outfile.open(filename, ofstream::app);
-  outfile << stats.GetUpdate() << "\t" << ids.size() << endl;
-  outfile.close();
-}
-
-void cPopulation::PrintPhenotypeStatus(const cString & filename)
-{
-  cDataFile & df_phen = stats.GetDataFile(filename);
-  
-  df_phen.WriteComment("Num orgs doing each task for each deme in population");
-  df_phen.WriteTimeStamp();
-  df_phen.Write(GetUpdate(), "update");
-  
-  cString comment;
-  
-  for (int i = 0; i < cell_array.GetSize(); i++) 
-  {
-    // Only look at cells with organisms in them.
-    if (cell_array[i].IsOccupied() == false) continue;
-    
-    cOrganism * organism = cell_array[i].GetOrganism();
-    const cPhenotype & phenotype = organism->GetPhenotype();
-    
-    comment.Set("cur_merit %d;", i); 
-    df_phen.Write(phenotype.GetMerit().GetDouble(), comment); 
-    
-    comment.Set("cur_merit_base %d;", i); 
-    df_phen.Write(phenotype.GetCurMeritBase(), comment); 
-    
-    comment.Set("cur_merit_bonus %d;", i); 
-    df_phen.Write(phenotype.GetCurBonus(), comment); 
-    
-    //    comment.Set("last_merit %d", i); 
-    //    df_phen.Write(phenotype.GetLastMerit(), comment); 
-    
-    comment.Set("last_merit_base %d", i); 
-    df_phen.Write(phenotype.GetLastMeritBase(), comment); 
-    
-    comment.Set("last_merit_bonus %d", i); 
-    df_phen.Write(phenotype.GetLastBonus(), comment); 
-    
-    comment.Set("life_fitness %d", i); 
-    df_phen.Write(phenotype.GetLifeFitness(), comment); 
-    
-    comment.Set("*"); 
-    df_phen.Write("*", comment); 
-    
-  } 
-  df_phen.Endl();
-  
-}     
-
-
-bool cPopulation::UpdateMerit(int cell_id, double new_merit)
-{
-  assert( GetCell(cell_id).IsOccupied() == true);
-  assert( new_merit >= 0.0 );
-  
-  cPhenotype & phenotype = GetCell(cell_id).GetOrganism()->GetPhenotype();
-  double old_merit = phenotype.GetMerit().GetDouble(); 
-  
-  phenotype.SetMerit( cMerit(new_merit) );
-  phenotype.SetLifeFitness(new_merit/phenotype.GetGestationTime()); 
-  if (new_merit <= old_merit) {
-	  phenotype.SetIsDonorCur(); }  
-  else  { phenotype.SetIsReceiver(); } 
-  
-  schedule->Adjust(cell_id, phenotype.GetMerit());
-  
-  return true;
-}
-
-void cPopulation::SetChangeList(cChangeList *change_list){
-  schedule->SetChangeList(change_list);
-}
-cChangeList *cPopulation::GetChangeList(){
-  return schedule->GetChangeList();
-}

Deleted: trunk/source/main/population.hh
===================================================================
--- trunk/source/main/population.hh	2005-10-05 23:24:09 UTC (rev 330)
+++ trunk/source/main/population.hh	2005-10-05 23:40:31 UTC (rev 331)
@@ -1,211 +0,0 @@
-//////////////////////////////////////////////////////////////////////////////
-// Copyright (C) 1993 - 2003 California Institute of Technology             //
-//                                                                          //
-// Read the COPYING and README files, or contact 'avida at alife.org',         //
-// before continuing.  SOME RESTRICTIONS MAY APPLY TO USE OF THIS FILE.     //
-//////////////////////////////////////////////////////////////////////////////
-
-#ifndef POPULATION_HH
-#define POPULATION_HH
-
-#include <fstream>
-
-#ifndef BIRTH_CHAMBER_HH
-#include "cBirthChamber.h"
-#endif
-#ifndef POPULATION_INTERFACE_HH
-#include "cPopulationInterface.h"
-#endif
-#ifndef RESOURCE_COUNT_HH
-#include "resource_count.hh"
-#endif
-#ifndef STATS_HH
-#include "stats.hh"
-#endif
-#ifndef STRING_HH
-#include "string.hh"
-#endif
-#ifndef TARRAY_HH
-#include "tArray.hh"
-#endif
-#ifndef TLIST_HH
-#include "tList.hh"
-#endif
-
-class cSchedule;
-template <class T> class tArray; // aggregate
-
-class cBirthChamber; // aggregate
-class cChangeList;
-class cEnvironment;
-class cGenebank;
-class cGenome;
-class cGenotype;
-class cInjectGenebank;
-class cLineage;
-class cLineageControl;
-template <class T> class tList; // aggregate
-class cOrganism;
-class cPopulationInterface; // aggregate
-class cPopulationCell;
-class cResourceCount; // aggregate
-class cStats; // aggregate
-class cString; // aggregate
-
-class cPopulation {
-private:
-  cPopulation(const cPopulation &); // not implemented
-private:
-  // Components...
-  cSchedule * schedule;                // Handles allocation of CPU cycles
-  tArray<cPopulationCell> cell_array;  // Local cells composing the population
-  cResourceCount resource_count;       // Global resources available
-  cBirthChamber birth_chamber;         // Global birth chamber.
-
-  // Data Tracking...
-  cStats stats;                      // Main statistics object...
-  cGenebank * genebank;                // Tracks genotypes
-  cInjectGenebank * inject_genebank;   // Tracks all injected code
-  cLineageControl * lineage_control;   // Tracks Linages
-  tList<cPopulationCell> reaper_queue; // Death order in some mass-action runs
-
-  // Default organism setups...
-  cEnvironment & environment;          // Physics & Chemestry description
-  cPopulationInterface default_interface;  // Organism interface to population
-
-  // Other data...
-  int world_x;                         // Structured population width.
-  int world_y;                         // Structured population
-  int num_organisms;                   // Cell count with living organisms
-  int num_demes;                       // Number of sub-groups of organisms
-  int deme_size;                       // Number of organims in a deme.
-  tArray<int> deme_birth_count;        // Track number of births in each deme.
- 
-  // Outside interactions...
-  bool sync_events;   // Do we need to sync up the event list with population?
-
-  ///////////////// Private Methods ////////////////////
-  void BuildTimeSlicer(cChangeList * change_list); // Build the schedule object
-
-  // Methods to place offspring in the population.
-  cPopulationCell & PositionChild(cPopulationCell & parent_cell,
-				  bool parent_ok=true);
-  void PositionAge(cPopulationCell & parent_cell,
-		   tList<cPopulationCell> & found_list, bool parent_ok);
-  void PositionMerit(cPopulationCell & parent_cell,
-		     tList<cPopulationCell> & found_list, bool parent_ok);
-  void FindEmptyCell(tList<cPopulationCell> & cell_list,
-		     tList<cPopulationCell> & found_list);
-
-  // Update statistics collecting...
-  void UpdateOrganismStats();
-  void UpdateGenotypeStats();
-  void UpdateSpeciesStats();
-  void UpdateDominantStats();
-  void UpdateDominantParaStats();
-
-  /**
-   * Attention: InjectGenotype does *not* add the genotype to the genebank.
-   * It assumes thats where you got the genotype from.
-   **/
-  void InjectGenotype(int cell_id, cGenotype * genotype);
-  void InjectGenome(int cell_id, const cGenome & genome, int lineage_label);
-  void InjectClone(int cell_id, cOrganism & orig_org);
-
-  void LineageSetupOrganism(cOrganism * organism, cLineage * lineage,
-			    int lin_label, cGenotype * parent_genotype=NULL);
-
-  // Must be called to activate *any* organism in the population.
-  void ActivateOrganism(cOrganism * in_organism, cPopulationCell &target_cell);
-
-public:
-  cPopulation(const cPopulationInterface & in_interface,
-	      cEnvironment & in_environment,
-	      cChangeList * change_list = 0);
-  ~cPopulation();
-
-  // Extra Setup...
-  bool SetupDemes();
-
-  // Activate the offspring of an organism in the population
-  bool ActivateOffspring(cGenome & child_genome, cOrganism & parent_organism);
-
-  bool ActivateInject(cOrganism & parent, const cGenome & injected_code);
-  bool ActivateInject(const int cell_id, const cGenome & injected_code);
-
-  // Inject an organism from the outside world.
-  void Inject(const cGenome & genome, int cell_id=-1, double merit=-1,
-	      int lineage_label=0, double neutral_metric=0, int mem_space=0 );
-
-  // Deactivate an organism in the population (required for deactivations)
-  void KillOrganism(cPopulationCell & in_cell);
-  void Kaboom(cPopulationCell & in_cell);
-
-  // Deme-related methods
-  void CompeteDemes(int competition_type);
-  void ResetDemes();
-  void CopyDeme(int deme1_id, int deme2_id);
-  void PrintDemeStats();
-
-  // Process a single organism one instruction...
-  int ScheduleOrganism();          // Determine next organism to be processed.
-  void ProcessStep(double step_size);
-  void ProcessStep(double step_size, int cell_id);
-
-  // Calculate the statistics from the most recent update.
-  void CalcUpdateStats();
-
-  // Clear all but a subset of cells...
-  void SerialTransfer( int transfer_size, bool ignore_deads );
-
-  // Saving and loading...
-  bool SaveClone(std::ofstream & fp);
-  bool LoadClone(std::ifstream & fp);
-  bool LoadDumpFile(cString filename, int update);
-  bool SavePopulation(std::ofstream & fp);
-  bool LoadPopulation(std::ifstream & fp);
-  bool DumpMemorySummary(std::ofstream & fp);
-
-  bool OK();
-
-  int GetSize() { return cell_array.GetSize(); }
-  int GetWorldX() { return world_x; }
-  int GetWorldY() { return world_y; }
-  int GetUpdate() { return stats.GetUpdate(); }
-  double GetGeneration() { return stats.SumGeneration().Average(); }
-
-  cPopulationCell & GetCell(int in_num);
-  const tArray<double> & GetResources() const
-    { return resource_count.GetResources(); }
-  const tArray<double> & GetCellResources(int cell_id) const
-    { return resource_count.GetCellResources(cell_id); }
-  cBirthChamber & GetBirthChamber(int id) { (void) id; return birth_chamber; }
-
-  void UpdateResources(const tArray<double> & res_change);
-  void UpdateResource(int id, double change);
-  void UpdateCellResources(const tArray<double> & res_change,
-                           const int cell_id);
-  void SetResource(int id, double new_level);
-  double GetResource(int id) const {
-    return resource_count.Get(id); }
-
-  cStats & GetStats() { return stats; }
-  cGenebank & GetGenebank() { return *genebank; }
-  cInjectGenebank & GetInjectGenebank() { return *inject_genebank; }
-  cLineageControl * GetLineageControl() { return lineage_control; }
-  cEnvironment & GetEnvironment() { return environment; }
-  int GetNumOrganisms() { return num_organisms; }
-
-  bool GetSyncEvents() { return sync_events; }
-  void SetSyncEvents(bool _in) { sync_events = _in; }
-  void ParasiteDebug();
-  void PrintPhenotypeData(const cString & filename);
-  void PrintPhenotypeStatus(const cString & filename);
-
-  bool UpdateMerit(int cell_id, double new_merit);
-
-  void SetChangeList(cChangeList *change_list);
-  cChangeList *GetChangeList();
-};
-
-#endif

Deleted: trunk/source/main/population_cell.cc
===================================================================
--- trunk/source/main/population_cell.cc	2005-10-05 23:24:09 UTC (rev 330)
+++ trunk/source/main/population_cell.cc	2005-10-05 23:40:31 UTC (rev 331)
@@ -1,146 +0,0 @@
-//////////////////////////////////////////////////////////////////////////////
-// Copyright (C) 1993 - 2003 California Institute of Technology             //
-//                                                                          //
-// Read the COPYING and README files, or contact 'avida at alife.org',         //
-// before continuing.  SOME RESTRICTIONS MAY APPLY TO USE OF THIS FILE.     //
-//////////////////////////////////////////////////////////////////////////////
-
-#ifndef POPULATION_CELL_HH
-#include "population_cell.hh"
-#endif
-
-#ifndef CONFIG_HH
-#include "cConfig.h"
-#endif
-#ifndef nHardware_h
-#include "nHardware.h"
-#endif
-#ifndef ORGANISM_HH
-#include "organism.hh"
-#endif
-#ifndef TOOLS_HH
-#include "tools.hh"
-#endif
-
-using namespace std;
-
-cPopulationCell::cPopulationCell()
-  : organism(NULL)
-  , cur_input(0)
-  , organism_count(0)
-{
-}
-
-cPopulationCell::cPopulationCell(const cPopulationCell & in_cell)
-  : organism(in_cell.organism)
-  , cur_input(in_cell.cur_input)
-  , cell_id(in_cell.cell_id)
-  , organism_count(in_cell.organism_count)
-{
-  for (int i = 0; i < nHardware::IO_SIZE; i++) input_array[i] = in_cell.input_array[i];
-  mutation_rates.Copy(in_cell.mutation_rates);
-  tConstListIterator<cPopulationCell> conn_it(in_cell.connection_list);
-  cPopulationCell * test_cell;
-  while ( (test_cell = (cPopulationCell *) conn_it.Next()) != NULL) {
-    connection_list.PushRear(test_cell);
-  }
-}
-
-void cPopulationCell::operator=(const cPopulationCell & in_cell)
-{
-  organism = in_cell.organism;
-  for (int i = 0; i < nHardware::IO_SIZE; i++) input_array[i] = in_cell.input_array[i];
-  cur_input = in_cell.cur_input;
-  cell_id = in_cell.cell_id;
-  organism_count = in_cell.organism_count;
-  mutation_rates.Copy(in_cell.mutation_rates);
-  tConstListIterator<cPopulationCell> conn_it(in_cell.connection_list);
-  cPopulationCell * test_cell;
-  while ( (test_cell = (cPopulationCell *) conn_it.Next()) != NULL) {
-    connection_list.PushRear(test_cell);
-  }
-}
-
-void cPopulationCell::Setup(int in_id, const cMutationRates & in_rates)
-{
-  cell_id = in_id;
-  mutation_rates.Copy(in_rates);
-}
-
-void cPopulationCell::Rotate(cPopulationCell & new_facing)
-{
-  // @CAO Note, this breaks avida if new_facing is not in connection_list
-
-#ifdef DEBUG
-  int scan_count = 0;
-#endif
-  while (connection_list.GetFirst() != &new_facing) {
-    connection_list.CircNext();
-#ifdef DEBUG
-    assert(++scan_count < connection_list.GetSize());
-#endif
-  }
-}
-
-
-int cPopulationCell::GetInput()
-{
-  if (cur_input >= nHardware::IO_SIZE) cur_input = 0;
-  return input_array[cur_input++];
-}
-
-int cPopulationCell::GetInputAt(int & input_pointer)
-{
-  if (input_pointer >= nHardware::IO_SIZE) input_pointer = 0;
-  return input_array[input_pointer++];
-}
-
-int cPopulationCell::GetInput(int id)
-{
-  assert(id >= 0 && id < nHardware::IO_SIZE);
-  return input_array[id];
-}
-
-void cPopulationCell::InsertOrganism(cOrganism & new_org)
-{
-  assert(&new_org != NULL);
-  assert(new_org.GetGenotype() != NULL);
-  assert(organism == NULL);
-
-  // Adjust this cell's attributes to account for the new organism.
-  organism = &new_org;
-  organism_count++;
-
-  // Adjust the organism's attributes to match this cell.
-  organism->PopInterface().SetCellID(cell_id);
-}
-
-cOrganism * cPopulationCell::RemoveOrganism()
-{
-  if (organism == NULL) return NULL;   // Nothing to do!
-
-  // For the moment, the cell doesn't keep track of much...
-  cOrganism * out_organism = organism;
-  organism = NULL;
-  return out_organism;
-}
-
-
-bool cPopulationCell::OK()
-{
-  // Nothing for the moment...
-  return true;
-}
-
-bool cPopulationCell::SaveState(ofstream & fp)
-{
-  // Nothing for the moment...
-  return false;
-}
-
-
-bool cPopulationCell::LoadState(ifstream & fp)
-{
-  // Nothing for the moment...
-  return false;
-}

Deleted: trunk/source/main/population_cell.hh
===================================================================
--- trunk/source/main/population_cell.hh	2005-10-05 23:24:09 UTC (rev 330)
+++ trunk/source/main/population_cell.hh	2005-10-05 23:40:31 UTC (rev 331)
@@ -1,75 +0,0 @@
-//////////////////////////////////////////////////////////////////////////////
-// Copyright (C) 1993 - 2003 California Institute of Technology             //
-//                                                                          //
-// Read the COPYING and README files, or contact 'avida at alife.org',         //
-// before continuing.  SOME RESTRICTIONS MAY APPLY TO USE OF THIS FILE.     //
-//////////////////////////////////////////////////////////////////////////////
-
-#ifndef POPULATION_CELL_HH
-#define POPULATION_CELL_HH
-
-#include <fstream>
-
-#ifndef MUTATION_RATES_HH
-#include "cMutationRates.h"
-#endif
-#ifndef TARRAY_HH
-#include "tArray.hh"
-#endif
-#ifndef TLIST_HH
-#include "tList.hh"
-#endif
-
-class cPopulation;
-class cOrganism;
-template <class T> class tList; // aggregate
-class cPopulationCell;
-class cMutationRates; // aggregate
-template <class T> class tArray; // aggregate
-
-class cPopulationCell {
-  friend class cPopulation;
-private:
-  cOrganism * organism;                    // The occupent of this cell.
-  tList<cPopulationCell> connection_list;  // A list of neighboring cells.
-  cMutationRates mutation_rates;           // Mutation rates at this cell.
-  tArray<int> input_array;                 // Environmental Inputs...
-  int cur_input;                           // Next input to give organism.
-
-  int cell_id;           // Unique id for position of cell in population.
-  int organism_count;    // Total number of orgs to ever inhabit this cell.
-
-private:  // Organism changes should only occur through population...
-  void InsertOrganism(cOrganism & new_org);
-  cOrganism * RemoveOrganism();
-
-public:
-  cPopulationCell();
-  cPopulationCell(const cPopulationCell & in_cell);
-  ~cPopulationCell() { ; }
-
-  void operator=(const cPopulationCell & in_cell);
-
-  void Setup(int in_id, const cMutationRates & in_rates);
-  void Rotate(cPopulationCell & new_facing);
-
-  cOrganism * GetOrganism() const { return organism; }
-  tList<cPopulationCell> & ConnectionList() { return connection_list; }
-  const cMutationRates & MutationRates() const { return mutation_rates; }
-  cMutationRates & MutationRates() { return mutation_rates; }
-  int GetInput();
-  int GetInput(int);
-  int GetInputAt(int & input_pointer);
-
-  int GetID() const { return cell_id; }
-  int GetOrganismCount() const { return organism_count; }
-
-  bool IsOccupied() const { return organism != NULL; }
-
-  bool OK();
-
-  bool SaveState(std::ofstream & fp);
-  bool LoadState(std::ifstream & fp);
-};
-
-#endif

Modified: trunk/source/main/primitive.cc
===================================================================
--- trunk/source/main/primitive.cc	2005-10-05 23:24:09 UTC (rev 330)
+++ trunk/source/main/primitive.cc	2005-10-05 23:40:31 UTC (rev 331)
@@ -49,7 +49,7 @@
 #include "cInstLibCPU.h"
 #endif
 #ifndef POPULATION_HH
-#include "population.hh"
+#include "cPopulation.h"
 #endif
 #ifndef POPULATION_INTERFACE_HH
 #include "cPopulationInterface.h"

Modified: trunk/source/testsuites/unit_testsuites/org_message.t.cc
===================================================================
--- trunk/source/testsuites/unit_testsuites/org_message.t.cc	2005-10-05 23:24:09 UTC (rev 330)
+++ trunk/source/testsuites/unit_testsuites/org_message.t.cc	2005-10-05 23:40:31 UTC (rev 331)
@@ -1,5 +1,5 @@
 #ifndef ORG_MESSAGE_HH
-#include "org_message.hh"
+#include "cOrgMessage.h"
 #endif
 
 #ifndef TEST_CASE_H

Modified: trunk/source/testsuites/unit_testsuites/organism.t.cc
===================================================================
--- trunk/source/testsuites/unit_testsuites/organism.t.cc	2005-10-05 23:24:09 UTC (rev 330)
+++ trunk/source/testsuites/unit_testsuites/organism.t.cc	2005-10-05 23:40:31 UTC (rev 331)
@@ -1,5 +1,5 @@
 #ifndef ORGANISM_HH
-#include "organism.hh"
+#include "cOrganism.h"
 #endif
 
 #ifndef TEST_CASE_H

Modified: trunk/source/testsuites/unit_testsuites/phenotype.t.cc
===================================================================
--- trunk/source/testsuites/unit_testsuites/phenotype.t.cc	2005-10-05 23:24:09 UTC (rev 330)
+++ trunk/source/testsuites/unit_testsuites/phenotype.t.cc	2005-10-05 23:40:31 UTC (rev 331)
@@ -1,5 +1,5 @@
 #ifndef PHENOTYPE_HH
-#include "phenotype.hh"
+#include "cPhenotype.h"
 #endif
 
 #ifndef TEST_CASE_H

Modified: trunk/source/testsuites/unit_testsuites/population.t.cc
===================================================================
--- trunk/source/testsuites/unit_testsuites/population.t.cc	2005-10-05 23:24:09 UTC (rev 330)
+++ trunk/source/testsuites/unit_testsuites/population.t.cc	2005-10-05 23:40:31 UTC (rev 331)
@@ -1,5 +1,5 @@
 #ifndef POPULATION_HH
-#include "population.hh"
+#include "cPopulation.h"
 #endif
 
 #ifndef TEST_CASE_H

Modified: trunk/source/testsuites/unit_testsuites/population_cell.t.cc
===================================================================
--- trunk/source/testsuites/unit_testsuites/population_cell.t.cc	2005-10-05 23:24:09 UTC (rev 330)
+++ trunk/source/testsuites/unit_testsuites/population_cell.t.cc	2005-10-05 23:40:31 UTC (rev 331)
@@ -1,5 +1,5 @@
 #ifndef POPULATION_CELL_HH
-#include "population_cell.hh"
+#include "cPopulationCell.h"
 #endif
 
 #ifndef TEST_CASE_H

Modified: trunk/source/viewers/bar_screen.cc
===================================================================
--- trunk/source/viewers/bar_screen.cc	2005-10-05 23:24:09 UTC (rev 330)
+++ trunk/source/viewers/bar_screen.cc	2005-10-05 23:40:31 UTC (rev 331)
@@ -5,7 +5,7 @@
 // before continuing.  SOME RESTRICTIONS MAY APPLY TO USE OF THIS FILE.     //
 //////////////////////////////////////////////////////////////////////////////
 
-#include "population.hh"
+#include "cPopulation.h"
 #include "stats.hh"
 #include "cEnvironment.h"
 

Modified: trunk/source/viewers/environment_screen.cc
===================================================================
--- trunk/source/viewers/environment_screen.cc	2005-10-05 23:24:09 UTC (rev 330)
+++ trunk/source/viewers/environment_screen.cc	2005-10-05 23:40:31 UTC (rev 331)
@@ -9,7 +9,7 @@
 #include "cEnvironment.h"
 #include "cGenebank.h"
 #include "cGenotype.h"
-#include "population.hh"
+#include "cPopulation.h"
 #ifndef REACTION_HH
 #include "reaction.hh"
 #endif
@@ -21,8 +21,8 @@
 #endif
 #include "species.hh"
 #include "stats.hh"
-#include "population_cell.hh"
-#include "organism.hh"
+#include "cPopulationCell.h"
+#include "cOrganism.h"
 
 #include "environment_screen.hh"
 

Modified: trunk/source/viewers/map_screen.cc
===================================================================
--- trunk/source/viewers/map_screen.cc	2005-10-05 23:24:09 UTC (rev 330)
+++ trunk/source/viewers/map_screen.cc	2005-10-05 23:40:31 UTC (rev 331)
@@ -8,8 +8,8 @@
 #include <fstream>
 
 #include "cGenotype.h"
-#include "population.hh"
-#include "population_cell.hh"
+#include "cPopulation.h"
+#include "cPopulationCell.h"
 
 #include "map_screen.hh"
 

Modified: trunk/source/viewers/options_screen.cc
===================================================================
--- trunk/source/viewers/options_screen.cc	2005-10-05 23:24:09 UTC (rev 330)
+++ trunk/source/viewers/options_screen.cc	2005-10-05 23:40:31 UTC (rev 331)
@@ -6,7 +6,7 @@
 //////////////////////////////////////////////////////////////////////////////
 
 #include "cConfig.h"
-#include "population.hh"
+#include "cPopulation.h"
 
 #include "options_screen.hh"
 

Modified: trunk/source/viewers/stats_screen.cc
===================================================================
--- trunk/source/viewers/stats_screen.cc	2005-10-05 23:24:09 UTC (rev 330)
+++ trunk/source/viewers/stats_screen.cc	2005-10-05 23:40:31 UTC (rev 331)
@@ -9,7 +9,7 @@
 #include "cEnvironment.h"
 #include "cGenebank.h"
 #include "cGenotype.h"
-#include "population.hh"
+#include "cPopulation.h"
 #include "species.hh"
 #include "stats.hh"
 

Modified: trunk/source/viewers/symbol_util.cc
===================================================================
--- trunk/source/viewers/symbol_util.cc	2005-10-05 23:24:09 UTC (rev 330)
+++ trunk/source/viewers/symbol_util.cc	2005-10-05 23:40:31 UTC (rev 331)
@@ -10,8 +10,8 @@
 #include "symbol_util.hh"
 
 #include "cGenotype.h"
-#include "organism.hh"
-#include "population_cell.hh"
+#include "cOrganism.h"
+#include "cPopulationCell.h"
 #include "species.hh"
 #include "cConfig.h"
 #include "cHardwareBase.h"

Modified: trunk/source/viewers/text_screen.cc
===================================================================
--- trunk/source/viewers/text_screen.cc	2005-10-05 23:24:09 UTC (rev 330)
+++ trunk/source/viewers/text_screen.cc	2005-10-05 23:40:31 UTC (rev 331)
@@ -12,9 +12,9 @@
 #include "cGenebank.h"
 #include "cInjectGenotype.h"
 #include "cInjectGenebank.h"
-#include "population.hh"
-#include "population_cell.hh"
-#include "organism.hh"
+#include "cPopulation.h"
+#include "cPopulationCell.h"
+#include "cOrganism.h"
 
 #include "symbol_util.hh"
 #include "text_screen.hh"

Modified: trunk/source/viewers/view.cc
===================================================================
--- trunk/source/viewers/view.cc	2005-10-05 23:24:09 UTC (rev 330)
+++ trunk/source/viewers/view.cc	2005-10-05 23:40:31 UTC (rev 331)
@@ -11,10 +11,10 @@
 #include "cEnvironment.h"
 #endif
 #include "cGenotype.h"
-#include "organism.hh"
-#include "phenotype.hh"
-#include "population.hh"
-#include "population_cell.hh"
+#include "cOrganism.h"
+#include "cPhenotype.h"
+#include "cPopulation.h"
+#include "cPopulationCell.h"
 #include "stats.hh"
 
 #include "cTestUtil.h"

Modified: trunk/source/viewers/viewer.cc
===================================================================
--- trunk/source/viewers/viewer.cc	2005-10-05 23:24:09 UTC (rev 330)
+++ trunk/source/viewers/viewer.cc	2005-10-05 23:40:31 UTC (rev 331)
@@ -16,7 +16,7 @@
 #include "cEnvironment.h"
 #endif
 #ifndef POPULATION_HH
-#include "population.hh"
+#include "cPopulation.h"
 #endif
 #ifndef VIEW_HH
 #include "../viewers/view.hh"          // class cView

Modified: trunk/source/viewers/zoom_screen.cc
===================================================================
--- trunk/source/viewers/zoom_screen.cc	2005-10-05 23:24:09 UTC (rev 330)
+++ trunk/source/viewers/zoom_screen.cc	2005-10-05 23:40:31 UTC (rev 331)
@@ -13,10 +13,10 @@
 #include "cConfig.h"
 #include "cGenebank.h"
 #include "cGenotype.h"
-#include "organism.hh"
-#include "phenotype.hh"
-#include "population.hh"
-#include "population_cell.hh"
+#include "cOrganism.h"
+#include "cPhenotype.h"
+#include "cPopulation.h"
+#include "cPopulationCell.h"
 #ifndef STRING_UTIL_HH
 #include "string_util.hh"
 #endif




More information about the Avida-cvs mailing list