[Avida-SVN] r1326 - in development: Avida.xcodeproj source/actions source/analyze source/cpu source/main
brysonda at myxo.css.msu.edu
brysonda at myxo.css.msu.edu
Thu Feb 15 08:38:08 PST 2007
Author: brysonda
Date: 2007-02-15 11:38:07 -0500 (Thu, 15 Feb 2007)
New Revision: 1326
Added:
development/source/cpu/cInstLibBase.h
development/source/cpu/cInstSet.cc
development/source/cpu/cInstSet.h
development/source/cpu/tInstLibEntry.h
Removed:
development/source/main/cInstLibBase.h
development/source/main/cInstSet.cc
development/source/main/cInstSet.h
development/source/main/cInstUtil.cc
development/source/main/cInstUtil.h
Modified:
development/Avida.xcodeproj/project.pbxproj
development/source/actions/PopulationActions.cc
development/source/actions/PrintActions.cc
development/source/analyze/cAnalyze.cc
development/source/cpu/CMakeLists.txt
development/source/cpu/SConscript
development/source/cpu/cHardwareBase.h
development/source/cpu/cHardwareCPU.h
development/source/cpu/cHardwareExperimental.cc
development/source/cpu/cHardwareExperimental.h
development/source/cpu/cHardwareManager.h
development/source/cpu/cHardwareSMT.cc
development/source/cpu/cHardwareSMT.h
development/source/cpu/cHardwareTransSMT.cc
development/source/cpu/cHardwareTransSMT.h
development/source/cpu/cInstLibCPU.h
development/source/cpu/cTestCPU.cc
development/source/cpu/cTestCPUInterface.cc
development/source/cpu/cTestCPUInterface.h
development/source/cpu/tInstLib.h
development/source/main/CMakeLists.txt
development/source/main/SConscript
development/source/main/cGenomeUtil.cc
development/source/main/cGenomeUtil.h
development/source/main/cOrgInterface.h
development/source/main/cOrganism.cc
development/source/main/cOrganism.h
development/source/main/cPopulation.cc
development/source/main/cPopulation.h
development/source/main/cPopulationInterface.cc
development/source/main/cPopulationInterface.h
Log:
Remove GetLabel from the public interface of cHardware* classes, as label behaviors will vary between hardware types.
Move InstLib and InstSet classes from main/ to cpu/.
Merge cInstUtil functions into cGenomeUtil, as the functions are really genome related (LoadGenome, etc.).
Add tInstLibEntry, a first step towards a more flexible InstLib/InstSet design.
Modified: development/Avida.xcodeproj/project.pbxproj
===================================================================
--- development/Avida.xcodeproj/project.pbxproj 2007-02-15 15:08:27 UTC (rev 1325)
+++ development/Avida.xcodeproj/project.pbxproj 2007-02-15 16:38:07 UTC (rev 1326)
@@ -93,6 +93,9 @@
705ACD630A1403A5002D5BA0 /* PrintActions.cc in Sources */ = {isa = PBXBuildFile; fileRef = 705ACD4D0A13FED4002D5BA0 /* PrintActions.cc */; };
705ACD640A1403AA002D5BA0 /* PrintActions.cc in Sources */ = {isa = PBXBuildFile; fileRef = 705ACD4D0A13FED4002D5BA0 /* PrintActions.cc */; };
70658C5A085DF67D00486BED /* libncurses.5.4.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 70658C59085DF67D00486BED /* libncurses.5.4.dylib */; };
+ 706C6FFF0B83F265003174C1 /* cInstSet.cc in Sources */ = {isa = PBXBuildFile; fileRef = 706C6FFE0B83F265003174C1 /* cInstSet.cc */; };
+ 706C70000B83F265003174C1 /* cInstSet.cc in Sources */ = {isa = PBXBuildFile; fileRef = 706C6FFE0B83F265003174C1 /* cInstSet.cc */; };
+ 706C70010B83F265003174C1 /* cInstSet.cc in Sources */ = {isa = PBXBuildFile; fileRef = 706C6FFE0B83F265003174C1 /* cInstSet.cc */; };
7073165D097C6C8F00815164 /* cParser.cc in Sources */ = {isa = PBXBuildFile; fileRef = 7073165B097C6C8F00815164 /* cParser.cc */; };
70731665097C6DF500815164 /* cASLibrary.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70731663097C6DF500815164 /* cASLibrary.cc */; };
7073166B097C6E0C00815164 /* cASSymbol.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70731669097C6E0C00815164 /* cASSymbol.cc */; };
@@ -245,14 +248,10 @@
70CA6EC408DB7F8200068AC2 /* cGenome.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70CA6EB408DB7F8200068AC2 /* cGenome.cc */; };
70CA6EC508DB7F8200068AC2 /* cGenomeUtil.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70CA6EB508DB7F8200068AC2 /* cGenomeUtil.cc */; };
70CA6ECF08DB7F8200068AC2 /* cInstruction.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70CA6EBF08DB7F8200068AC2 /* cInstruction.cc */; };
- 70CA6ED008DB7F8200068AC2 /* cInstSet.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70CA6EC008DB7F8200068AC2 /* cInstSet.cc */; };
- 70CA6ED108DB7F8200068AC2 /* cInstUtil.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70CA6EC108DB7F8200068AC2 /* cInstUtil.cc */; };
70CA6ED208DB7F8200068AC2 /* cFitnessMatrix.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70CA6EB208DB7F8200068AC2 /* cFitnessMatrix.cc */; };
70CA6ED408DB7F8200068AC2 /* cGenome.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70CA6EB408DB7F8200068AC2 /* cGenome.cc */; };
70CA6ED508DB7F8200068AC2 /* cGenomeUtil.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70CA6EB508DB7F8200068AC2 /* cGenomeUtil.cc */; };
70CA6EDF08DB7F8200068AC2 /* cInstruction.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70CA6EBF08DB7F8200068AC2 /* cInstruction.cc */; };
- 70CA6EE008DB7F8200068AC2 /* cInstSet.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70CA6EC008DB7F8200068AC2 /* cInstSet.cc */; };
- 70CA6EE108DB7F8200068AC2 /* cInstUtil.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70CA6EC108DB7F8200068AC2 /* cInstUtil.cc */; };
70DCAC7A097AF731002F8733 /* cBarScreen.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70DCAC59097AF730002F8733 /* cBarScreen.cc */; };
70DCAC7D097AF731002F8733 /* cEnvironmentScreen.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70DCAC5C097AF730002F8733 /* cEnvironmentScreen.cc */; };
70DCAC7F097AF731002F8733 /* cHistScreen.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70DCAC5E097AF730002F8733 /* cHistScreen.cc */; };
@@ -289,8 +288,6 @@
70DCACB9097AF7CC002F8733 /* cGenome.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70CA6EB408DB7F8200068AC2 /* cGenome.cc */; };
70DCACBA097AF7CC002F8733 /* cGenomeUtil.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70CA6EB508DB7F8200068AC2 /* cGenomeUtil.cc */; };
70DCACBB097AF7CC002F8733 /* cInstruction.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70CA6EBF08DB7F8200068AC2 /* cInstruction.cc */; };
- 70DCACBC097AF7CC002F8733 /* cInstSet.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70CA6EC008DB7F8200068AC2 /* cInstSet.cc */; };
- 70DCACBD097AF7CC002F8733 /* cInstUtil.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70CA6EC108DB7F8200068AC2 /* cInstUtil.cc */; };
70DCACBE097AF7CC002F8733 /* cLandscape.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70B0865108F4974300FC65FE /* cLandscape.cc */; };
70DCACBF097AF7CC002F8733 /* cLocalMutations.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70B0865408F4974300FC65FE /* cLocalMutations.cc */; };
70DCACC0097AF7CC002F8733 /* cMutationLib.cc in Sources */ = {isa = PBXBuildFile; fileRef = 70B0865608F4974300FC65FE /* cMutationLib.cc */; };
@@ -552,6 +549,11 @@
705ACD4C0A13FED4002D5BA0 /* PrintActions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PrintActions.h; sourceTree = "<group>"; };
705ACD4D0A13FED4002D5BA0 /* PrintActions.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PrintActions.cc; sourceTree = "<group>"; };
70658C59085DF67D00486BED /* libncurses.5.4.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libncurses.5.4.dylib; path = /usr/lib/libncurses.5.4.dylib; sourceTree = "<absolute>"; };
+ 706C6F480B83E69D003174C1 /* cSaleItem.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cSaleItem.h; sourceTree = "<group>"; };
+ 706C6FD40B83EF96003174C1 /* cInstLibBase.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cInstLibBase.h; sourceTree = "<group>"; };
+ 706C6FFD0B83F254003174C1 /* cInstSet.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cInstSet.h; sourceTree = "<group>"; };
+ 706C6FFE0B83F265003174C1 /* cInstSet.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = cInstSet.cc; sourceTree = "<group>"; };
+ 706C703E0B83FB95003174C1 /* tInstLibEntry.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = tInstLibEntry.h; sourceTree = "<group>"; };
706D30CC0852328F00D7DC8F /* tInstLib.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = tInstLib.h; sourceTree = "<group>"; };
7073165A097C6C8F00815164 /* cParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = cParser.h; sourceTree = "<group>"; };
7073165B097C6C8F00815164 /* cParser.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = cParser.cc; sourceTree = "<group>"; };
@@ -827,15 +829,10 @@
70CA6EB408DB7F8200068AC2 /* cGenome.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = cGenome.cc; sourceTree = "<group>"; };
70CA6EB508DB7F8200068AC2 /* cGenomeUtil.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = cGenomeUtil.cc; sourceTree = "<group>"; };
70CA6EBF08DB7F8200068AC2 /* cInstruction.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = cInstruction.cc; sourceTree = "<group>"; };
- 70CA6EC008DB7F8200068AC2 /* cInstSet.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = cInstSet.cc; sourceTree = "<group>"; };
- 70CA6EC108DB7F8200068AC2 /* cInstUtil.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = cInstUtil.cc; sourceTree = "<group>"; };
70CA6EE208DB7F9E00068AC2 /* cFitnessMatrix.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cFitnessMatrix.h; sourceTree = "<group>"; };
70CA6EE408DB7F9E00068AC2 /* cGenome.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cGenome.h; sourceTree = "<group>"; };
70CA6EE608DB7F9E00068AC2 /* cGenomeUtil.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cGenomeUtil.h; sourceTree = "<group>"; };
- 70CA6EF108DB7F9E00068AC2 /* cInstLibBase.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cInstLibBase.h; sourceTree = "<group>"; };
70CA6EF208DB7F9E00068AC2 /* cInstruction.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cInstruction.h; sourceTree = "<group>"; };
- 70CA6EF308DB7F9E00068AC2 /* cInstSet.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cInstSet.h; sourceTree = "<group>"; };
- 70CA6EF408DB7F9E00068AC2 /* cInstUtil.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cInstUtil.h; sourceTree = "<group>"; };
70DA5E9D09DA1A8D00FFF42B /* cOrgSeqMessage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = cOrgSeqMessage.h; sourceTree = "<group>"; };
70DCAC57097AF730002F8733 /* main.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = main.cc; sourceTree = "<group>"; };
70DCAC59097AF730002F8733 /* cBarScreen.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = cBarScreen.cc; sourceTree = "<group>"; };
@@ -1384,6 +1381,10 @@
DCC30F7C0762539D008F7A48 /* cpu */ = {
isa = PBXGroup;
children = (
+ 706C703E0B83FB95003174C1 /* tInstLibEntry.h */,
+ 706C6FFE0B83F265003174C1 /* cInstSet.cc */,
+ 706C6FFD0B83F254003174C1 /* cInstSet.h */,
+ 706C6FD40B83EF96003174C1 /* cInstLibBase.h */,
70B1A6530B7E238F00067486 /* cHardwareExperimental.h */,
70B1A64F0B7E237F00067486 /* cHardwareExperimental.cc */,
7049F2D70A66859300640512 /* cHardwareTransSMT.cc */,
@@ -1426,6 +1427,7 @@
DCC310040762539D008F7A48 /* main */ = {
isa = PBXGroup;
children = (
+ 706C6F480B83E69D003174C1 /* cSaleItem.h */,
708BF3010AB65DD300A923BF /* cEventList.h */,
708BF2FD0AB65DC700A923BF /* cEventList.cc */,
703CA36F0A5072B700AB4DB4 /* SConscript */,
@@ -1445,13 +1447,8 @@
70CA6EE408DB7F9E00068AC2 /* cGenome.h */,
70CA6EB508DB7F8200068AC2 /* cGenomeUtil.cc */,
70CA6EE608DB7F9E00068AC2 /* cGenomeUtil.h */,
- 70CA6EF108DB7F9E00068AC2 /* cInstLibBase.h */,
70CA6EBF08DB7F8200068AC2 /* cInstruction.cc */,
70CA6EF208DB7F9E00068AC2 /* cInstruction.h */,
- 70CA6EC008DB7F8200068AC2 /* cInstSet.cc */,
- 70CA6EF308DB7F9E00068AC2 /* cInstSet.h */,
- 70CA6EC108DB7F8200068AC2 /* cInstUtil.cc */,
- 70CA6EF408DB7F9E00068AC2 /* cInstUtil.h */,
70B0865108F4974300FC65FE /* cLandscape.cc */,
70B0864808F4972600FC65FE /* cLandscape.h */,
70B0865408F4974300FC65FE /* cLocalMutations.cc */,
@@ -1926,8 +1923,6 @@
70CA6ED408DB7F8200068AC2 /* cGenome.cc in Sources */,
70CA6ED508DB7F8200068AC2 /* cGenomeUtil.cc in Sources */,
70CA6EDF08DB7F8200068AC2 /* cInstruction.cc in Sources */,
- 70CA6EE008DB7F8200068AC2 /* cInstSet.cc in Sources */,
- 70CA6EE108DB7F8200068AC2 /* cInstUtil.cc in Sources */,
70B0866108F4974300FC65FE /* cLandscape.cc in Sources */,
70B0866408F4974300FC65FE /* cLocalMutations.cc in Sources */,
70B0866608F4974300FC65FE /* cMutationLib.cc in Sources */,
@@ -2031,6 +2026,7 @@
7099EF560B2FBC86001269F6 /* cTextViewerAnalyzeDriver.cc in Sources */,
7099EF580B2FBC86001269F6 /* cTextViewerDriver_Base.cc in Sources */,
70B1A6520B7E237F00067486 /* cHardwareExperimental.cc in Sources */,
+ 706C70010B83F265003174C1 /* cInstSet.cc in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -2068,8 +2064,6 @@
70DCACB9097AF7CC002F8733 /* cGenome.cc in Sources */,
70DCACBA097AF7CC002F8733 /* cGenomeUtil.cc in Sources */,
70DCACBB097AF7CC002F8733 /* cInstruction.cc in Sources */,
- 70DCACBC097AF7CC002F8733 /* cInstSet.cc in Sources */,
- 70DCACBD097AF7CC002F8733 /* cInstUtil.cc in Sources */,
70DCACBE097AF7CC002F8733 /* cLandscape.cc in Sources */,
70DCACBF097AF7CC002F8733 /* cLocalMutations.cc in Sources */,
70DCACC0097AF7CC002F8733 /* cMutationLib.cc in Sources */,
@@ -2162,6 +2156,7 @@
703D4E2E0ABCAC4A0032C8A0 /* cArgContainer.cc in Sources */,
109746410AE9606E00929ED6 /* cDeme.cc in Sources */,
70B1A6510B7E237F00067486 /* cHardwareExperimental.cc in Sources */,
+ 706C70000B83F265003174C1 /* cInstSet.cc in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -2186,8 +2181,6 @@
70CA6EC408DB7F8200068AC2 /* cGenome.cc in Sources */,
70CA6EC508DB7F8200068AC2 /* cGenomeUtil.cc in Sources */,
70CA6ECF08DB7F8200068AC2 /* cInstruction.cc in Sources */,
- 70CA6ED008DB7F8200068AC2 /* cInstSet.cc in Sources */,
- 70CA6ED108DB7F8200068AC2 /* cInstUtil.cc in Sources */,
70B0865908F4974300FC65FE /* cLandscape.cc in Sources */,
70B0865C08F4974300FC65FE /* cLocalMutations.cc in Sources */,
70B0865E08F4974300FC65FE /* cMutationLib.cc in Sources */,
@@ -2274,6 +2267,7 @@
703D4D6E0ABA374A0032C8A0 /* cArgSchema.cc in Sources */,
1097463F0AE9606E00929ED6 /* cDeme.cc in Sources */,
70B1A6500B7E237F00067486 /* cHardwareExperimental.cc in Sources */,
+ 706C6FFF0B83F265003174C1 /* cInstSet.cc in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Modified: development/source/actions/PopulationActions.cc
===================================================================
--- development/source/actions/PopulationActions.cc 2007-02-15 15:08:27 UTC (rev 1325)
+++ development/source/actions/PopulationActions.cc 2007-02-15 16:38:07 UTC (rev 1326)
@@ -28,8 +28,8 @@
#include "cActionLibrary.h"
#include "cCodeLabel.h"
#include "cGenome.h"
+#include "cGenomeUtil.h"
#include "cHardwareManager.h"
-#include "cInstUtil.h"
#include "cPopulation.h"
#include "cPopulationCell.h"
#include "cStats.h"
@@ -78,7 +78,7 @@
void Process(cAvidaContext& ctx)
{
- cGenome genome = cInstUtil::LoadGenome(m_filename, m_world->GetHardwareManager().GetInstSet());
+ cGenome genome = cGenomeUtil::LoadGenome(m_filename, m_world->GetHardwareManager().GetInstSet());
m_world->GetPopulation().Inject(genome, m_cell_id, m_merit, m_lineage_label, m_neutral_metric);
}
};
@@ -122,7 +122,7 @@
void Process(cAvidaContext& ctx)
{
- cGenome genome = cInstUtil::RandomGenome(ctx, m_length, m_world->GetHardwareManager().GetInstSet());
+ cGenome genome = cGenomeUtil::RandomGenome(ctx, m_length, m_world->GetHardwareManager().GetInstSet());
m_world->GetPopulation().Inject(genome, m_cell_id, m_merit, m_lineage_label, m_neutral_metric);
}
};
@@ -166,7 +166,7 @@
void Process(cAvidaContext& ctx)
{
- cGenome genome = cInstUtil::LoadGenome(m_filename, m_world->GetHardwareManager().GetInstSet());
+ cGenome genome = cGenomeUtil::LoadGenome(m_filename, m_world->GetHardwareManager().GetInstSet());
for (int i = 0; i < m_world->GetPopulation().GetSize(); i++)
m_world->GetPopulation().Inject(genome, i, m_merit, m_lineage_label, m_neutral_metric);
}
@@ -223,7 +223,7 @@
if (m_cell_start < 0 || m_cell_end > m_world->GetPopulation().GetSize() || m_cell_start >= m_cell_end) {
m_world->GetDriver().NotifyWarning("InjectRange has invalid range!");
} else {
- cGenome genome = cInstUtil::LoadGenome(m_filename, m_world->GetHardwareManager().GetInstSet());
+ cGenome genome = cGenomeUtil::LoadGenome(m_filename, m_world->GetHardwareManager().GetInstSet());
for (int i = m_cell_start; i < m_cell_end; i++) {
m_world->GetPopulation().Inject(genome, i, m_merit, m_lineage_label, m_neutral_metric);
}
@@ -330,7 +330,7 @@
if (m_cell_start < 0 || m_cell_end > m_world->GetPopulation().GetSize() || m_cell_start >= m_cell_end) {
m_world->GetDriver().NotifyWarning("InjectParasite has invalid range!");
} else {
- cGenome genome = cInstUtil::LoadGenome(m_filename, m_world->GetHardwareManager().GetInstSet());
+ cGenome genome = cGenomeUtil::LoadGenome(m_filename, m_world->GetHardwareManager().GetInstSet());
for (int i = m_cell_start; i < m_cell_end; i++) {
m_world->GetPopulation().InjectParasite(m_label, genome, i);
}
@@ -396,8 +396,8 @@
if (m_cell_start < 0 || m_cell_end > m_world->GetPopulation().GetSize() || m_cell_start >= m_cell_end) {
m_world->GetDriver().NotifyWarning("InjectParasitePair has invalid range!");
} else {
- cGenome genome = cInstUtil::LoadGenome(m_filename_genome, m_world->GetHardwareManager().GetInstSet());
- cGenome parasite = cInstUtil::LoadGenome(m_filename_parasite, m_world->GetHardwareManager().GetInstSet());
+ cGenome genome = cGenomeUtil::LoadGenome(m_filename_genome, m_world->GetHardwareManager().GetInstSet());
+ cGenome parasite = cGenomeUtil::LoadGenome(m_filename_parasite, m_world->GetHardwareManager().GetInstSet());
for (int i = m_cell_start; i < m_cell_end; i++) {
m_world->GetPopulation().Inject(genome, i, m_merit, m_lineage_label, m_neutral_metric);
m_world->GetPopulation().InjectParasite(m_label, parasite, i);
Modified: development/source/actions/PrintActions.cc
===================================================================
--- development/source/actions/PrintActions.cc 2007-02-15 15:08:27 UTC (rev 1325)
+++ development/source/actions/PrintActions.cc 2007-02-15 16:38:07 UTC (rev 1326)
@@ -37,7 +37,6 @@
#include "cHistogram.h"
#include "cInjectGenotype.h"
#include "cInstSet.h"
-#include "cInstUtil.h"
#include "cOrganism.h"
#include "cPopulation.h"
#include "cPopulationCell.h"
@@ -708,7 +707,7 @@
creature_file = largs.PopWord();
else
creature_file = m_world->GetConfig().START_CREATURE.Get();
- m_reference = cInstUtil::LoadGenome(creature_file, world->GetHardwareManager().GetInstSet());
+ m_reference = cGenomeUtil::LoadGenome(creature_file, world->GetHardwareManager().GetInstSet());
if (largs.GetSize()) m_filename = largs.PopWord();
}
@@ -815,7 +814,7 @@
int sum_num_organisms = 0;
// load the reference genome
- cGenome reference_genome(cInstUtil::LoadGenome(m_creature, m_world->GetHardwareManager().GetInstSet()));
+ cGenome reference_genome(cGenomeUtil::LoadGenome(m_creature, m_world->GetHardwareManager().GetInstSet()));
// cycle over all genotypes
cGenotype* cur_genotype = m_world->GetClassificationManager().GetBestGenotype();
Modified: development/source/analyze/cAnalyze.cc
===================================================================
--- development/source/analyze/cAnalyze.cc 2007-02-15 15:08:27 UTC (rev 1325)
+++ development/source/analyze/cAnalyze.cc 2007-02-15 16:38:07 UTC (rev 1326)
@@ -52,7 +52,6 @@
#include "cHelpManager.h"
#include "cInitFile.h"
#include "cInstSet.h"
-#include "cInstUtil.h"
#include "cLandscape.h"
#include "cPhenotype.h"
#include "cProbSchedule.h"
@@ -170,7 +169,7 @@
cout << "Loading: " << filename << '\n';
// Setup the genome...
- cGenome genome( cInstUtil::LoadGenome(filename, inst_set) );
+ cGenome genome( cGenomeUtil::LoadGenome(filename, inst_set) );
// Construct the new genotype..
cAnalyzeGenotype * genotype = new cAnalyzeGenotype(m_world, genome, inst_set);
Modified: development/source/cpu/CMakeLists.txt
===================================================================
--- development/source/cpu/CMakeLists.txt 2007-02-15 15:08:27 UTC (rev 1325)
+++ development/source/cpu/CMakeLists.txt 2007-02-15 16:38:07 UTC (rev 1326)
@@ -11,6 +11,7 @@
cHardwareStatusPrinter.cc
cHardwareTransSMT.cc
cHeadCPU.cc
+ cInstSet.cc
cTestCPU.cc
cTestCPUInterface.cc
)
Modified: development/source/cpu/SConscript
===================================================================
--- development/source/cpu/SConscript 2007-02-15 15:08:27 UTC (rev 1325)
+++ development/source/cpu/SConscript 2007-02-15 16:38:07 UTC (rev 1326)
@@ -17,7 +17,9 @@
'cHardwareTracer.h',
'cHardwareTrans.h',
'cHeadCPU.h',
+ 'cInstLibBase.h',
'cInstLibCPU.h',
+ 'cInstSet.h',
'cTestCPU.h',
'cTestCPUInterface.h',
'nHardware.h',
@@ -38,6 +40,7 @@
'cHardwareStatusPrinter.cc',
'cHardwareTransSMT.cc',
'cHeadCPU.cc',
+ 'cInstSet.cc',
'cTestCPU.cc',
'cTestCPUInterface.cc',
]
Modified: development/source/cpu/cHardwareBase.h
===================================================================
--- development/source/cpu/cHardwareBase.h 2007-02-15 15:08:27 UTC (rev 1325)
+++ development/source/cpu/cHardwareBase.h 2007-02-15 16:38:07 UTC (rev 1326)
@@ -120,11 +120,6 @@
cHeadCPU FindLabelFull(const cCodeLabel& label);
- // -------- Label Manipulation -------
- virtual const cCodeLabel& GetLabel() const = 0;
- virtual cCodeLabel& GetLabel() = 0;
-
-
// -------- Memory Manipulation --------
virtual const cCPUMemory& GetMemory() const = 0;
virtual cCPUMemory& GetMemory() = 0;
Modified: development/source/cpu/cHardwareCPU.h
===================================================================
--- development/source/cpu/cHardwareCPU.h 2007-02-15 15:08:27 UTC (rev 1325)
+++ development/source/cpu/cHardwareCPU.h 2007-02-15 16:38:07 UTC (rev 1326)
@@ -158,6 +158,8 @@
// -------- Label Manipulation -------
+ const cCodeLabel& GetLabel() const { return m_threads[m_cur_thread].next_label; }
+ cCodeLabel& GetLabel() { return m_threads[m_cur_thread].next_label; }
void ReadLabel(int max_size=nHardware::MAX_LABEL_SIZE);
cHeadCPU FindLabel(int direction);
int FindLabel_Forward(const cCodeLabel & search_label, const cGenome& search_genome, int pos);
@@ -239,11 +241,6 @@
cHeadCPU& IP(int thread) { return m_threads[thread].heads[nHardware::HEAD_IP]; }
- // -------- Label Manipulation -------
- const cCodeLabel& GetLabel() const { return m_threads[m_cur_thread].next_label; }
- cCodeLabel& GetLabel() { return m_threads[m_cur_thread].next_label; }
-
-
// -------- Memory Manipulation --------
const cCPUMemory& GetMemory() const { return m_memory; }
cCPUMemory& GetMemory() { return m_memory; }
Modified: development/source/cpu/cHardwareExperimental.cc
===================================================================
--- development/source/cpu/cHardwareExperimental.cc 2007-02-15 15:08:27 UTC (rev 1325)
+++ development/source/cpu/cHardwareExperimental.cc 2007-02-15 16:38:07 UTC (rev 1326)
@@ -44,6 +44,7 @@
#include "cTestCPU.h"
#include "cWorldDriver.h"
#include "cWorld.h"
+#include "tInstLibEntry.h"
#include <limits.h>
#include <fstream>
@@ -70,102 +71,58 @@
cNOPEntry("nop-F", REG_FX)
};
- struct cInstEntry {
- const cString name;
- const tMethod function;
- const bool is_default;
- const cString desc;
-
- cInstEntry(const cString & _name, tMethod _fun,
- bool _def=false, const cString & _desc="")
- : name(_name), function(_fun), is_default(_def), desc(_desc) {}
- };
- static const cInstEntry s_f_array[] = {
+ static const tInstLibEntry<tMethod> s_f_array[] = {
/*
Note: all entries of cNOPEntryCPU s_n_array must have corresponding
- in the same order in cInstEntry s_f_array, and these entries must
+ in the same order in tInstLibEntry<tMethod> s_f_array, and these entries must
be the first elements of s_f_array.
*/
- cInstEntry("nop-A", &cHardwareExperimental::Inst_Nop, true,
- "No-operation instruction; modifies other instructions"),
- cInstEntry("nop-B", &cHardwareExperimental::Inst_Nop, true,
- "No-operation instruction; modifies other instructions"),
- cInstEntry("nop-C", &cHardwareExperimental::Inst_Nop, true,
- "No-operation instruction; modifies other instructions"),
- cInstEntry("nop-D", &cHardwareExperimental::Inst_Nop, true,
- "No-operation instruction; modifies other instructions"),
- cInstEntry("nop-E", &cHardwareExperimental::Inst_Nop, true,
- "No-operation instruction; modifies other instructions"),
- cInstEntry("nop-F", &cHardwareExperimental::Inst_Nop, true,
- "No-operation instruction; modifies other instructions"),
+ tInstLibEntry<tMethod>("nop-A", &cHardwareExperimental::Inst_Nop, (nInstFlag::DEFAULT & nInstFlag::NOP), "No-operation instruction; modifies other instructions"),
+ tInstLibEntry<tMethod>("nop-B", &cHardwareExperimental::Inst_Nop, (nInstFlag::DEFAULT & nInstFlag::NOP), "No-operation instruction; modifies other instructions"),
+ tInstLibEntry<tMethod>("nop-C", &cHardwareExperimental::Inst_Nop, (nInstFlag::DEFAULT & nInstFlag::NOP), "No-operation instruction; modifies other instructions"),
+ tInstLibEntry<tMethod>("nop-D", &cHardwareExperimental::Inst_Nop, (nInstFlag::DEFAULT & nInstFlag::NOP), "No-operation instruction; modifies other instructions"),
+ tInstLibEntry<tMethod>("nop-E", &cHardwareExperimental::Inst_Nop, (nInstFlag::DEFAULT & nInstFlag::NOP), "No-operation instruction; modifies other instructions"),
+ tInstLibEntry<tMethod>("nop-F", &cHardwareExperimental::Inst_Nop, (nInstFlag::DEFAULT & nInstFlag::NOP), "No-operation instruction; modifies other instructions"),
- cInstEntry("NULL", &cHardwareExperimental::Inst_Nop, false,
- "True no-operation instruction: does nothing"),
- cInstEntry("nop-X", &cHardwareExperimental::Inst_Nop, false,
- "True no-operation instruction: does nothing"),
+ tInstLibEntry<tMethod>("NULL", &cHardwareExperimental::Inst_Nop, 0, "True no-operation instruction: does nothing"),
+ tInstLibEntry<tMethod>("nop-X", &cHardwareExperimental::Inst_Nop, 0, "True no-operation instruction: does nothing"),
- cInstEntry("if-n-equ", &cHardwareExperimental::Inst_IfNEqu, true,
- "Execute next instruction if ?BX?!=?CX?, else skip it"),
- cInstEntry("if-less", &cHardwareExperimental::Inst_IfLess, true,
- "Execute next instruction if ?BX? < ?CX?, else skip it"),
+ tInstLibEntry<tMethod>("if-n-equ", &cHardwareExperimental::Inst_IfNEqu, nInstFlag::DEFAULT, "Execute next instruction if ?BX?!=?CX?, else skip it"),
+ tInstLibEntry<tMethod>("if-less", &cHardwareExperimental::Inst_IfLess, nInstFlag::DEFAULT, "Execute next instruction if ?BX? < ?CX?, else skip it"),
-
- cInstEntry("label", &cHardwareExperimental::Inst_Label),
+ tInstLibEntry<tMethod>("label", &cHardwareExperimental::Inst_Label),
- cInstEntry("pop", &cHardwareExperimental::Inst_Pop, true,
- "Remove top number from stack and place into ?BX?"),
- cInstEntry("push", &cHardwareExperimental::Inst_Push, true,
- "Copy number from ?BX? and place it into the stack"),
- cInstEntry("swap-stk", &cHardwareExperimental::Inst_SwitchStack, true,
- "Toggle which stack is currently being used"),
- cInstEntry("swap", &cHardwareExperimental::Inst_Swap, true,
- "Swap the contents of ?BX? with ?CX?"),
+ tInstLibEntry<tMethod>("pop", &cHardwareExperimental::Inst_Pop, nInstFlag::DEFAULT, "Remove top number from stack and place into ?BX?"),
+ tInstLibEntry<tMethod>("push", &cHardwareExperimental::Inst_Push, nInstFlag::DEFAULT, "Copy number from ?BX? and place it into the stack"),
+ tInstLibEntry<tMethod>("swap-stk", &cHardwareExperimental::Inst_SwitchStack, nInstFlag::DEFAULT, "Toggle which stack is currently being used"),
+ tInstLibEntry<tMethod>("swap", &cHardwareExperimental::Inst_Swap, nInstFlag::DEFAULT, "Swap the contents of ?BX? with ?CX?"),
- cInstEntry("shift-r", &cHardwareExperimental::Inst_ShiftR, true,
- "Shift bits in ?BX? right by one (divide by two)"),
- cInstEntry("shift-l", &cHardwareExperimental::Inst_ShiftL, true,
- "Shift bits in ?BX? left by one (multiply by two)"),
- cInstEntry("inc", &cHardwareExperimental::Inst_Inc, true,
- "Increment ?BX? by one"),
- cInstEntry("dec", &cHardwareExperimental::Inst_Dec, true,
- "Decrement ?BX? by one"),
+ tInstLibEntry<tMethod>("shift-r", &cHardwareExperimental::Inst_ShiftR, nInstFlag::DEFAULT, "Shift bits in ?BX? right by one (divide by two)"),
+ tInstLibEntry<tMethod>("shift-l", &cHardwareExperimental::Inst_ShiftL, nInstFlag::DEFAULT, "Shift bits in ?BX? left by one (multiply by two)"),
+ tInstLibEntry<tMethod>("inc", &cHardwareExperimental::Inst_Inc, nInstFlag::DEFAULT, "Increment ?BX? by one"),
+ tInstLibEntry<tMethod>("dec", &cHardwareExperimental::Inst_Dec, nInstFlag::DEFAULT, "Decrement ?BX? by one"),
- cInstEntry("add", &cHardwareExperimental::Inst_Add, true,
- "Add BX to CX and place the result in ?BX?"),
- cInstEntry("sub", &cHardwareExperimental::Inst_Sub, true,
- "Subtract CX from BX and place the result in ?BX?"),
- cInstEntry("mult", &cHardwareExperimental::Inst_Mult, false,
- "Multiple BX by CX and place the result in ?BX?"),
- cInstEntry("div", &cHardwareExperimental::Inst_Div, false,
- "Divide BX by CX and place the result in ?BX?"),
- cInstEntry("mod", &cHardwareExperimental::Inst_Mod),
- cInstEntry("nand", &cHardwareExperimental::Inst_Nand, true,
- "Nand BX by CX and place the result in ?BX?"),
+ tInstLibEntry<tMethod>("add", &cHardwareExperimental::Inst_Add, nInstFlag::DEFAULT, "Add BX to CX and place the result in ?BX?"),
+ tInstLibEntry<tMethod>("sub", &cHardwareExperimental::Inst_Sub, nInstFlag::DEFAULT, "Subtract CX from BX and place the result in ?BX?"),
+ tInstLibEntry<tMethod>("mult", &cHardwareExperimental::Inst_Mult, 0, "Multiple BX by CX and place the result in ?BX?"),
+ tInstLibEntry<tMethod>("div", &cHardwareExperimental::Inst_Div, 0, "Divide BX by CX and place the result in ?BX?"),
+ tInstLibEntry<tMethod>("mod", &cHardwareExperimental::Inst_Mod),
+ tInstLibEntry<tMethod>("nand", &cHardwareExperimental::Inst_Nand, nInstFlag::DEFAULT, "Nand BX by CX and place the result in ?BX?"),
- cInstEntry("IO", &cHardwareExperimental::Inst_TaskIO, true,
- "Output ?BX?, and input new number back into ?BX?"),
+ tInstLibEntry<tMethod>("IO", &cHardwareExperimental::Inst_TaskIO, nInstFlag::DEFAULT, "Output ?BX?, and input new number back into ?BX?"),
// Head-based instructions
- cInstEntry("h-alloc", &cHardwareExperimental::Inst_MaxAlloc, true,
- "Allocate maximum allowed space"),
- cInstEntry("h-divide", &cHardwareExperimental::Inst_HeadDivide, true,
- "Divide code between read and write heads."),
- cInstEntry("h-read", &cHardwareExperimental::Inst_HeadRead),
- cInstEntry("h-write", &cHardwareExperimental::Inst_HeadWrite),
- cInstEntry("h-copy", &cHardwareExperimental::Inst_HeadCopy, true,
- "Copy from read-head to write-head; advance both"),
- cInstEntry("h-search", &cHardwareExperimental::Inst_HeadSearch, true,
- "Find complement template and make with flow head"),
- cInstEntry("mov-head", &cHardwareExperimental::Inst_MoveHead, true,
- "Move head ?IP? to the flow head"),
- cInstEntry("jmp-head", &cHardwareExperimental::Inst_JumpHead, true,
- "Move head ?IP? by amount in CX register; CX = old pos."),
- cInstEntry("get-head", &cHardwareExperimental::Inst_GetHead, true,
- "Copy the position of the ?IP? head into CX"),
- cInstEntry("if-label", &cHardwareExperimental::Inst_IfLabel, true,
- "Execute next if we copied complement of attached label"),
- cInstEntry("set-flow", &cHardwareExperimental::Inst_SetFlow, true,
- "Set flow-head to position in ?CX?"),
+ tInstLibEntry<tMethod>("h-alloc", &cHardwareExperimental::Inst_MaxAlloc, nInstFlag::DEFAULT, "Allocate maximum allowed space"),
+ tInstLibEntry<tMethod>("h-divide", &cHardwareExperimental::Inst_HeadDivide, nInstFlag::DEFAULT, "Divide code between read and write heads."),
+ tInstLibEntry<tMethod>("h-read", &cHardwareExperimental::Inst_HeadRead),
+ tInstLibEntry<tMethod>("h-write", &cHardwareExperimental::Inst_HeadWrite),
+ tInstLibEntry<tMethod>("h-copy", &cHardwareExperimental::Inst_HeadCopy, nInstFlag::DEFAULT, "Copy from read-head to write-head; advance both"),
+ tInstLibEntry<tMethod>("h-search", &cHardwareExperimental::Inst_HeadSearch, nInstFlag::DEFAULT, "Find complement template and make with flow head"),
+ tInstLibEntry<tMethod>("mov-head", &cHardwareExperimental::Inst_MoveHead, nInstFlag::DEFAULT, "Move head ?IP? to the flow head"),
+ tInstLibEntry<tMethod>("jmp-head", &cHardwareExperimental::Inst_JumpHead, nInstFlag::DEFAULT, "Move head ?IP? by amount in CX register; CX = old pos."),
+ tInstLibEntry<tMethod>("get-head", &cHardwareExperimental::Inst_GetHead, nInstFlag::DEFAULT, "Copy the position of the ?IP? head into CX"),
+ tInstLibEntry<tMethod>("if-label", &cHardwareExperimental::Inst_IfLabel, nInstFlag::DEFAULT, "Execute next if we copied complement of attached label"),
+ tInstLibEntry<tMethod>("set-flow", &cHardwareExperimental::Inst_SetFlow, nInstFlag::DEFAULT, "Set flow-head to position in ?CX?"),
};
const int n_size = sizeof(s_n_array)/sizeof(cNOPEntry);
@@ -177,7 +134,7 @@
nop_mods[i] = s_n_array[i].nop_mod;
}
- const int f_size = sizeof(s_f_array)/sizeof(cInstEntry);
+ const int f_size = sizeof(s_f_array)/sizeof(tInstLibEntry<tMethod>);
static cString f_names[f_size];
static tMethod functions[f_size];
for (int i = 0; i < f_size; i++){
Modified: development/source/cpu/cHardwareExperimental.h
===================================================================
--- development/source/cpu/cHardwareExperimental.h 2007-02-15 15:08:27 UTC (rev 1325)
+++ development/source/cpu/cHardwareExperimental.h 2007-02-15 16:38:07 UTC (rev 1326)
@@ -160,6 +160,8 @@
// -------- Label Manipulation -------
+ const cCodeLabel& GetLabel() const { return m_threads[m_cur_thread].next_label; }
+ cCodeLabel& GetLabel() { return m_threads[m_cur_thread].next_label; }
void ReadLabel(int max_size=nHardware::MAX_LABEL_SIZE);
cHeadCPU FindLabel(int direction);
int FindLabel_Forward(const cCodeLabel & search_label, const cGenome& search_genome, int pos);
@@ -235,11 +237,6 @@
cHeadCPU& IP(int thread) { return m_threads[thread].heads[nHardware::HEAD_IP]; }
- // -------- Label Manipulation -------
- const cCodeLabel& GetLabel() const { return m_threads[m_cur_thread].next_label; }
- cCodeLabel& GetLabel() { return m_threads[m_cur_thread].next_label; }
-
-
// -------- Memory Manipulation --------
const cCPUMemory& GetMemory() const { return m_memory; }
cCPUMemory& GetMemory() { return m_memory; }
Modified: development/source/cpu/cHardwareManager.h
===================================================================
--- development/source/cpu/cHardwareManager.h 2007-02-15 15:08:27 UTC (rev 1325)
+++ development/source/cpu/cHardwareManager.h 2007-02-15 16:38:07 UTC (rev 1326)
@@ -54,10 +54,13 @@
int m_type;
// cTestResources m_testres;
+ void LoadInstSet(cString filename);
+
cHardwareManager(); // @not_implemented
cHardwareManager(const cHardwareManager&); // @not_implemented
cHardwareManager& operator=(const cHardwareManager&); // @not_implemented
+
public:
cHardwareManager(cWorld* world);
~cHardwareManager() { ; }
@@ -65,8 +68,6 @@
cHardwareBase* Create(cOrganism* in_org);
cTestCPU* CreateTestCPU() { return new cTestCPU(m_world /*, &m_testres*/); }
- void LoadInstSet(cString filename);
-
const cInstSet& GetInstSet() const { return m_inst_set; }
cInstSet& GetInstSet() { return m_inst_set; }
};
Modified: development/source/cpu/cHardwareSMT.cc
===================================================================
--- development/source/cpu/cHardwareSMT.cc 2007-02-15 15:08:27 UTC (rev 1325)
+++ development/source/cpu/cHardwareSMT.cc 2007-02-15 16:38:07 UTC (rev 1326)
@@ -674,7 +674,7 @@
Inject_DoMutations(ctx, mut_multiplier, injected_code);
bool inject_signal = false;
- if (injected_code.GetSize() > 0) inject_signal = organism->InjectParasite(injected_code);
+ if (injected_code.GetSize() > 0) inject_signal = organism->InjectParasite(GetLabel(), injected_code);
// reset the memory space that was injected
m_mem_array[mem_space_used] = cGenome("a");
Modified: development/source/cpu/cHardwareSMT.h
===================================================================
--- development/source/cpu/cHardwareSMT.h 2007-02-15 15:08:27 UTC (rev 1325)
+++ development/source/cpu/cHardwareSMT.h 2007-02-15 16:38:07 UTC (rev 1326)
@@ -158,6 +158,8 @@
// -------- Label Manipulation -------
+ const cCodeLabel& GetLabel() const { return m_threads[m_cur_thread].next_label; }
+ cCodeLabel& GetLabel() { return m_threads[m_cur_thread].next_label; }
void ReadLabel(int max_size=nHardware::MAX_LABEL_SIZE);
cHeadCPU FindLabel(int direction);
int FindLabel_Forward(const cCodeLabel& search_label, const cGenome& search_genome, int pos);
@@ -236,11 +238,6 @@
cHeadCPU& IP(int thread) { return m_threads[thread].heads[nHardware::HEAD_IP]; }
- // -------- Label Manipulation -------
- const cCodeLabel& GetLabel() const { return m_threads[m_cur_thread].next_label; }
- cCodeLabel& GetLabel() { return m_threads[m_cur_thread].next_label; }
-
-
// -------- Memory Manipulation --------
cCPUMemory& GetMemory() { return m_mem_array[0]; }
const cCPUMemory& GetMemory() const { return m_mem_array[0]; }
Modified: development/source/cpu/cHardwareTransSMT.cc
===================================================================
--- development/source/cpu/cHardwareTransSMT.cc 2007-02-15 15:08:27 UTC (rev 1325)
+++ development/source/cpu/cHardwareTransSMT.cc 2007-02-15 16:38:07 UTC (rev 1326)
@@ -677,7 +677,7 @@
Inject_DoMutations(ctx, mut_multiplier, injected_code);
bool inject_signal = false;
- if (injected_code.GetSize() > 0) inject_signal = organism->InjectParasite(injected_code);
+ if (injected_code.GetSize() > 0) inject_signal = organism->InjectParasite(GetLabel(), injected_code);
// reset the memory space that was injected
m_mem_array[mem_space_used] = cGenome("a");
Modified: development/source/cpu/cHardwareTransSMT.h
===================================================================
--- development/source/cpu/cHardwareTransSMT.h 2007-02-15 15:08:27 UTC (rev 1325)
+++ development/source/cpu/cHardwareTransSMT.h 2007-02-15 16:38:07 UTC (rev 1326)
@@ -157,6 +157,8 @@
// -------- Label Manipulation -------
+ const cCodeLabel& GetLabel() const { return m_threads[m_cur_thread].next_label; }
+ cCodeLabel& GetLabel() { return m_threads[m_cur_thread].next_label; }
void ReadLabel(int max_size=nHardware::MAX_LABEL_SIZE);
cHeadCPU FindLabel(int direction);
int FindLabel_Forward(const cCodeLabel& search_label, const cGenome& search_genome, int pos);
@@ -235,11 +237,6 @@
cHeadCPU& IP(int thread) { return m_threads[thread].heads[nHardware::HEAD_IP]; }
- // -------- Label Manipulation -------
- const cCodeLabel& GetLabel() const { return m_threads[m_cur_thread].next_label; }
- cCodeLabel& GetLabel() { return m_threads[m_cur_thread].next_label; }
-
-
// -------- Memory Manipulation --------
cCPUMemory& GetMemory() { return m_mem_array[0]; }
const cCPUMemory& GetMemory() const { return m_mem_array[0]; }
Copied: development/source/cpu/cInstLibBase.h (from rev 1324, development/source/main/cInstLibBase.h)
===================================================================
--- development/source/main/cInstLibBase.h 2007-02-13 18:36:42 UTC (rev 1324)
+++ development/source/cpu/cInstLibBase.h 2007-02-15 16:38:07 UTC (rev 1326)
@@ -0,0 +1,51 @@
+/*
+ * cInstLibBase.h
+ * Avida
+ *
+ * Called "inst_lib_base.hh" prior to 12/5/05.
+ * Copyright 1999-2007 Michigan State University. All rights reserved.
+ * Copyright 1993-2003 California Institute of Technology.
+ *
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; version 2
+ * of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef cInstLibBase_h
+#define cInstLibBase_h
+
+#ifndef cInstruction_h
+#include "cInstruction.h"
+#endif
+
+class cString;
+
+class cInstLibBase
+{
+public:
+ cInstLibBase() { ; }
+ virtual ~cInstLibBase() { ; }
+ virtual const cString& GetName(const unsigned int id) = 0;
+ virtual const cString& GetNopName(const unsigned int id) = 0;
+ virtual int GetNopMod(const unsigned int id) = 0;
+ virtual int GetNopMod(const cInstruction& inst) = 0;
+ virtual int GetSize() = 0;
+ virtual int GetNumNops() = 0;
+ virtual cInstruction GetInst(const cString& in_name) = 0;
+ virtual const cInstruction GetInstDefault() = 0;
+ virtual const cInstruction GetInstError() = 0;
+};
+
+#endif
Modified: development/source/cpu/cInstLibCPU.h
===================================================================
--- development/source/cpu/cInstLibCPU.h 2007-02-15 15:08:27 UTC (rev 1325)
+++ development/source/cpu/cInstLibCPU.h 2007-02-15 16:38:07 UTC (rev 1326)
@@ -92,8 +92,8 @@
}
return cInstLibCPU::GetInstError();
}
- const cInstruction & GetInstDefault(){ return inst_default; }
- const cInstruction & GetInstError(){ return inst_error; }
+ const cInstruction GetInstDefault(){ return inst_default; }
+ const cInstruction GetInstError(){ return inst_error; }
};
Copied: development/source/cpu/cInstSet.cc (from rev 1324, development/source/main/cInstSet.cc)
Copied: development/source/cpu/cInstSet.h (from rev 1324, development/source/main/cInstSet.h)
Modified: development/source/cpu/cTestCPU.cc
===================================================================
--- development/source/cpu/cTestCPU.cc 2007-02-15 15:08:27 UTC (rev 1325)
+++ development/source/cpu/cTestCPU.cc 2007-02-15 16:38:07 UTC (rev 1326)
@@ -29,13 +29,13 @@
#include "cCPUTestInfo.h"
#include "cEnvironment.h"
#include "functions.h"
+#include "cGenomeUtil.h"
#include "cGenotype.h"
#include "cHardwareBase.h"
#include "cHardwareManager.h"
#include "cHardwareStatusPrinter.h"
#include "cInjectGenotype.h"
#include "cInstSet.h"
-#include "cInstUtil.h"
#include "cOrganism.h"
#include "cPhenotype.h"
#include "cTestCPUInterface.h"
@@ -452,7 +452,7 @@
df.Endl();
// Display the genome
- cInstUtil::SaveGenome(df.GetOFStream(), test_info.GetTestOrganism()->GetHardware().GetInstSet(), genome);
+ cGenomeUtil::SaveGenome(df.GetOFStream(), test_info.GetTestOrganism()->GetHardware().GetInstSet(), genome);
m_world->GetDataFileManager().Remove(filename);
}
@@ -493,7 +493,7 @@
fp << endl;
// Display the genome
- cInstUtil::SaveGenome(fp, test_info.GetTestOrganism()->GetHardware().GetInstSet(), genome);
+ cGenomeUtil::SaveGenome(fp, test_info.GetTestOrganism()->GetHardware().GetInstSet(), genome);
m_world->GetDataFileManager().Remove(filename);
}
Modified: development/source/cpu/cTestCPUInterface.cc
===================================================================
--- development/source/cpu/cTestCPUInterface.cc 2007-02-15 15:08:27 UTC (rev 1325)
+++ development/source/cpu/cTestCPUInterface.cc 2007-02-15 16:38:07 UTC (rev 1326)
@@ -105,7 +105,7 @@
return m_testcpu->GetReceiveValue();
}
-bool cTestCPUInterface::InjectParasite(cOrganism* parent, const cGenome& injected_code)
+bool cTestCPUInterface::InjectParasite(cOrganism* parent, const cCodeLabel& label, const cGenome& injected_code)
{
return false;
}
Modified: development/source/cpu/cTestCPUInterface.h
===================================================================
--- development/source/cpu/cTestCPUInterface.h 2007-02-15 15:08:27 UTC (rev 1325)
+++ development/source/cpu/cTestCPUInterface.h 2007-02-15 16:38:07 UTC (rev 1326)
@@ -65,7 +65,7 @@
int ReceiveValue();
void SellValue(const int data, const int label, const int sell_price, const int org_id);
int BuyValue(const int label, const int buy_price);
- bool InjectParasite(cOrganism* parent, const cGenome& injected_code);
+ bool InjectParasite(cOrganism* parent, const cCodeLabel& label, const cGenome& injected_code);
bool UpdateMerit(double new_merit);
bool TestOnDivide() { return false; }
};
Modified: development/source/cpu/tInstLib.h
===================================================================
--- development/source/cpu/tInstLib.h 2007-02-15 15:08:27 UTC (rev 1325)
+++ development/source/cpu/tInstLib.h 2007-02-15 16:38:07 UTC (rev 1326)
@@ -46,51 +46,56 @@
const cInstruction inst_error;
const cInstruction inst_default;
+
public:
- tInstLib(
- size_t nopmod_array_size,
- size_t function_array_size,
- cString* nopmod_names,
- cString* function_names,
- const int* nopmods,
- MethodType* functions,
- const cInstruction& error,
- const cInstruction& def
- ):m_nopmods_array_size(nopmod_array_size),
+ tInstLib(size_t nopmod_array_size, size_t function_array_size, cString* nopmod_names,
+ cString* function_names, const int* nopmods, MethodType* functions,
+ const cInstruction& error, const cInstruction& def)
+ : m_nopmods_array_size(nopmod_array_size),
m_function_array_size(function_array_size),
m_nopmod_names(nopmod_names),
m_function_names(function_names),
m_nopmods(nopmods),
m_functions(functions),
- inst_error(error),
- inst_default(def)
- {}
+ inst_error(error),
+ inst_default(def)
+ {
+ }
+
MethodType* GetFunctions(void){ return m_functions; }
- const cString &GetName(const unsigned int id) {
+
+ const cString& GetName(const unsigned int id)
+ {
assert(id < m_function_array_size);
return m_function_names[id];
}
- const cString &GetNopName(const unsigned int id) {
+ const cString& GetNopName(const unsigned int id)
+ {
assert(id < m_nopmods_array_size);
return m_nopmod_names[id];
- }
- int GetNopMod(const unsigned int id){
+ }
+ int GetNopMod(const unsigned int id)
+ {
assert(id < m_nopmods_array_size);
return m_nopmods[id];
}
- int GetNopMod(const cInstruction & inst){
+ int GetNopMod(const cInstruction& inst)
+ {
return GetNopMod(inst.GetOp());
}
- int GetSize(){ return m_function_array_size; }
- int GetNumNops(){ return m_nopmods_array_size; }
- cInstruction GetInst(const cString & in_name){
+
+ int GetSize() { return m_function_array_size; }
+ int GetNumNops() { return m_nopmods_array_size; }
+
+ cInstruction GetInst(const cString& in_name)
+ {
for (unsigned int i = 0; i < m_function_array_size; i++) {
if (m_function_names[i] == in_name) return cInstruction(i);
}
return tInstLib::GetInstError();
}
- const cInstruction & GetInstDefault(){ return inst_default; }
- const cInstruction & GetInstError(){ return inst_error; }
+ const cInstruction GetInstDefault() { return inst_default; }
+ const cInstruction GetInstError() { return inst_error; }
};
#endif
Added: development/source/cpu/tInstLibEntry.h
===================================================================
--- development/source/cpu/tInstLibEntry.h 2007-02-15 15:08:27 UTC (rev 1325)
+++ development/source/cpu/tInstLibEntry.h 2007-02-15 16:38:07 UTC (rev 1326)
@@ -0,0 +1,51 @@
+/*
+ * cInstLibEntry.h
+ * Avida
+ *
+ * Created by David Bryson on 2/14/07.
+ * Copyright 2007 Michigan State University. All rights reserved.
+ *
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; version 2
+ * of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef cInstLibEntry_h
+#define cInstLibEntry_h
+
+namespace nInstFlag {
+ const unsigned int DEFAULT = 0x1;
+ const unsigned int NOP = 0x2;
+ const unsigned int LABEL = 0x4;
+}
+
+template <class FUN> class tInstLibEntry
+{
+public:
+ const cString name;
+ const FUN function;
+ const unsigned int flags;
+ const cString description;
+
+ bool IsDefault() const { return (flags & nInstFlag::DEFAULT); }
+ bool IsNop() const { return (flags & nInstFlag::NOP); }
+ bool IsLabel() const { return (flags & nInstFlag::LABEL); }
+
+ tInstLibEntry(const cString& in_name, FUN in_fun, unsigned int in_flags = 0, const cString& in_desc = "")
+ : name(in_name), function(in_fun), flags(in_flags), description(in_desc) { ; }
+};
+
+
+#endif
Modified: development/source/main/CMakeLists.txt
===================================================================
--- development/source/main/CMakeLists.txt 2007-02-15 15:08:27 UTC (rev 1325)
+++ development/source/main/CMakeLists.txt 2007-02-15 16:38:07 UTC (rev 1326)
@@ -11,8 +11,6 @@
cGenome.cc
cGenomeUtil.cc
cInstruction.cc
- cInstSet.cc
- cInstUtil.cc
cLandscape.cc
cLocalMutations.cc
cMutationLib.cc
Modified: development/source/main/SConscript
===================================================================
--- development/source/main/SConscript 2007-02-15 15:08:27 UTC (rev 1325)
+++ development/source/main/SConscript 2007-02-15 16:38:07 UTC (rev 1326)
@@ -14,10 +14,7 @@
'cFitnessMatrix.h',
'cGenome.h',
'cGenomeUtil.h',
- 'cInstLibBase.h',
'cInstruction.h',
- 'cInstSet.h',
- 'cInstUtil.h',
'cLandscape.h',
'cLocalMutations.h',
'cMutation.h',
@@ -66,8 +63,6 @@
'cGenome.cc',
'cGenomeUtil.cc',
'cInstruction.cc',
- 'cInstSet.cc',
- 'cInstUtil.cc',
'cLandscape.cc',
'cLocalMutations.cc',
'cMutationLib.cc',
Modified: development/source/main/cGenomeUtil.cc
===================================================================
--- development/source/main/cGenomeUtil.cc 2007-02-15 15:08:27 UTC (rev 1325)
+++ development/source/main/cGenomeUtil.cc 2007-02-15 16:38:07 UTC (rev 1326)
@@ -25,8 +25,11 @@
#include "cGenomeUtil.h"
+#include "cAvidaContext.h"
+#include "cGenome.h"
+#include "cInitFile.h"
+#include "cInstSet.h"
#include "functions.h"
-#include "cGenome.h"
using namespace std;
@@ -230,3 +233,99 @@
return out_genome;
}
+
+cGenome cGenomeUtil::LoadGenome(const cString& filename, const cInstSet& inst_set)
+{
+ cGenome new_genome(0);
+ if (!LoadGenome(filename, inst_set, new_genome)) {
+ cerr << "Error: Unable to load genome" << endl;
+ exit(1);
+ }
+ return new_genome;
+}
+
+bool cGenomeUtil::LoadGenome(const cString& filename, const cInstSet& inst_set, cGenome& out_genome)
+{
+ cInitFile input_file(filename);
+ bool success = true;
+
+ if (!input_file.IsOpen()) return false;
+
+ input_file.Load();
+ input_file.Compress();
+ input_file.Close();
+
+ // Setup the code array...
+ cGenome new_genome(input_file.GetNumLines());
+
+ for (int line_num = 0; line_num < new_genome.GetSize(); line_num++) {
+ cString cur_line = input_file.GetLine(line_num);
+ new_genome[line_num] = inst_set.GetInst(cur_line);
+
+ if (new_genome[line_num] == cInstSet::GetInstError()) {
+ // You're using the wrong instruction set! YOU FOOL!
+ if (success) {
+ cerr << "Error: Cannot load organism '" << filename << "'" << endl;
+ success = false;
+ }
+ cerr << " Unknown line: " << cur_line << " (best match is '" << inst_set.FindBestMatch(cur_line) << "')" << endl;
+ }
+ }
+
+ if (new_genome.GetSize() == 0) cerr << "Warning: Genome size is 0!" << endl;
+ if (success) out_genome = new_genome;
+ return success;
+}
+
+cGenome cGenomeUtil::LoadInternalGenome(istream& fp, const cInstSet& inst_set)
+{
+ assert(fp.good()); // Invalid stream to load genome from!
+
+ int num_lines = -1;
+ fp >> num_lines;
+
+ if (num_lines <= 0) { return cGenome(1); }
+
+ // Setup the code array...
+ cGenome new_genome(num_lines);
+ cString cur_line;
+
+ for (int line_num = 0; line_num < new_genome.GetSize(); line_num++) {
+ fp >> cur_line;
+ new_genome[line_num] = inst_set.GetInst(cur_line);
+
+ if (new_genome[line_num] == cInstSet::GetInstError()) {
+ // You're using the wrong instruction set! YOU FOOL!
+ cerr << "Cannot load creature from stream:" << endl
+ << " Unknown line: " << cur_line << endl;
+ }
+ }
+ return new_genome;
+}
+
+void cGenomeUtil::SaveGenome(ostream& fp, const cInstSet& inst_set,
+ const cGenome & gen)
+{
+ for (int i = 0; i < gen.GetSize(); i++) {
+ fp << inst_set.GetName(gen[i]) << endl;
+ }
+}
+
+void cGenomeUtil::SaveInternalGenome(ostream& fp, const cInstSet& inst_set,
+ const cGenome & gen)
+{
+ fp << gen.GetSize() << endl;
+ SaveGenome(fp, inst_set, gen);
+}
+
+
+cGenome cGenomeUtil::RandomGenome(cAvidaContext& ctx, int length, const cInstSet& inst_set)
+{
+ cGenome genome(length);
+ for (int i = 0; i < length; i++) {
+ genome[i] = inst_set.GetRandomInst(ctx);
+ }
+ return genome;
+}
+
+
Modified: development/source/main/cGenomeUtil.h
===================================================================
--- development/source/main/cGenomeUtil.h 2007-02-15 15:08:27 UTC (rev 1325)
+++ development/source/main/cGenomeUtil.h 2007-02-15 16:38:07 UTC (rev 1326)
@@ -30,7 +30,9 @@
#include "cGenome.h"
#endif
+class cAvidaContext;
class cInstruction;
+class cInstSet;
class cGenomeUtil
{
@@ -56,6 +58,20 @@
static cGenome Crop(const cGenome& genome, int start, int end);
static cGenome Cut(const cGenome& genome, int start, int end);
static cGenome Join(const cGenome& genome1, const cGenome& genome2);
+
+ // ========= Genome-File Interaction =========
+ // Saving and loading of files. These functions assume that the genome is
+ // the only thing in the file unless 'Internal' is in the function name
+ // (Internal genomes must begin with a number that indicates genome length)
+
+ static bool LoadGenome(const cString& filename, const cInstSet& inst_set, cGenome& out_genome);
+ static cGenome LoadGenome(const cString& filename, const cInstSet& inst_set);
+ static cGenome LoadInternalGenome(std::istream& fp, const cInstSet& inst_set);
+ static void SaveGenome(std::ostream& fp, const cInstSet& inst_set, const cGenome& gen);
+ static void SaveInternalGenome(std::ostream& fp, const cInstSet& inst_set, const cGenome& gen);
+
+ // ========= Genome Construction =========
+ static cGenome RandomGenome(cAvidaContext& ctx, int length, const cInstSet& inst_set);
};
Deleted: development/source/main/cInstLibBase.h
===================================================================
--- development/source/main/cInstLibBase.h 2007-02-15 15:08:27 UTC (rev 1325)
+++ development/source/main/cInstLibBase.h 2007-02-15 16:38:07 UTC (rev 1326)
@@ -1,51 +0,0 @@
-/*
- * cInstLibBase.h
- * Avida
- *
- * Called "inst_lib_base.hh" prior to 12/5/05.
- * Copyright 1999-2007 Michigan State University. All rights reserved.
- * Copyright 1993-2003 California Institute of Technology.
- *
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; version 2
- * of the License.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-#ifndef cInstLibBase_h
-#define cInstLibBase_h
-
-#ifndef cInstruction_h
-#include "cInstruction.h"
-#endif
-
-class cString;
-
-class cInstLibBase
-{
-public:
- cInstLibBase() { ; }
- virtual ~cInstLibBase() { ; }
- virtual const cString &GetName(const unsigned int id) = 0;
- virtual const cString &GetNopName(const unsigned int id) = 0;
- virtual int GetNopMod(const unsigned int id) = 0;
- virtual int GetNopMod(const cInstruction & inst) = 0;
- virtual int GetSize() = 0;
- virtual int GetNumNops() = 0;
- virtual cInstruction GetInst(const cString & in_name) = 0;
- virtual const cInstruction & GetInstDefault() = 0;
- virtual const cInstruction & GetInstError() = 0;
-};
-
-#endif
Deleted: development/source/main/cInstSet.cc
===================================================================
--- development/source/main/cInstSet.cc 2007-02-15 15:08:27 UTC (rev 1325)
+++ development/source/main/cInstSet.cc 2007-02-15 16:38:07 UTC (rev 1326)
@@ -1,134 +0,0 @@
-/*
- * cInstSet.cc
- * Avida
- *
- * Called "inst_set.cc" prior to 12/5/05.
- * Copyright 1999-2007 Michigan State University. All rights reserved.
- * Copyright 1993-2001 California Institute of Technology.
- *
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; version 2
- * of the License.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-#include "cInstSet.h"
-
-#include "cAvidaContext.h"
-#include "cStringUtil.h"
-#include "cWorld.h"
-
-using namespace std;
-
-
-// Initialize static variables
-const cInstruction cInstSet::inst_default(0);
-cInstruction cInstSet::inst_default2(0);
-cInstruction cInstSet::inst_error2(255);
-
-
-bool cInstSet::OK() const
-{
- assert(m_lib_name_map.GetSize() < 256);
- assert(m_lib_nopmod_map.GetSize() < m_lib_name_map.GetSize());
-
- // Make sure that all of the redundancies are represented the appropriate
- // number of times.
- tArray<int> test_redundancy2(m_lib_name_map.GetSize());
- test_redundancy2.SetAll(0);
- for (int i = 0; i < m_mutation_chart.GetSize(); i++) {
- int test_id = m_mutation_chart[i];
- test_redundancy2[test_id]++;
- }
- for (int i = 0; i < m_lib_name_map.GetSize(); i++) {
- assert(m_lib_name_map[i].redundancy == test_redundancy2[i]);
- }
-
- return true;
-}
-
-cInstruction cInstSet::GetRandomInst(cAvidaContext& ctx) const
-{
- int inst_op = m_mutation_chart[ctx.GetRandom().GetUInt(m_mutation_chart.GetSize())];
- return cInstruction(inst_op);
-}
-
-int cInstSet::AddInst(int lib_fun_id, int redundancy, int ft_cost, int cost, double prob_fail, int addl_time_cost)
-{
- const int inst_id = m_lib_name_map.GetSize();
-
- assert(inst_id < 255);
-
- // Increase the size of the array...
- m_lib_name_map.Resize(inst_id + 1);
-
- // Setup the new function...
- m_lib_name_map[inst_id].lib_fun_id = lib_fun_id;
- m_lib_name_map[inst_id].redundancy = redundancy;
- m_lib_name_map[inst_id].cost = cost;
- m_lib_name_map[inst_id].ft_cost = ft_cost;
- m_lib_name_map[inst_id].prob_fail = prob_fail;
- m_lib_name_map[inst_id].addl_time_cost = addl_time_cost;
-
- const int total_redundancy = m_mutation_chart.GetSize();
- m_mutation_chart.Resize(total_redundancy + redundancy);
- for (int i = 0; i < redundancy; i++) {
- m_mutation_chart[total_redundancy + i] = inst_id;
- }
-
- return inst_id;
-}
-
-int cInstSet::AddNop(int lib_nopmod_id, int redundancy, int ft_cost, int cost, double prob_fail, int addl_time_cost)
-{
- // Assert nops are at the _beginning_ of an inst_set.
- assert(m_lib_name_map.GetSize() == m_lib_nopmod_map.GetSize());
-
- const int inst_id = AddInst(lib_nopmod_id, redundancy, ft_cost, cost, prob_fail, addl_time_cost);
-
- m_lib_nopmod_map.Resize(inst_id + 1);
- m_lib_nopmod_map[inst_id] = lib_nopmod_id;
-
- return inst_id;
-}
-
-cString cInstSet::FindBestMatch(const cString& in_name) const
-{
- int best_dist = 1024;
- cString best_name("");
-
- for (int i = 0; i < m_lib_name_map.GetSize(); i++) {
- const cString & cur_name = m_inst_lib->GetName(m_lib_name_map[i].lib_fun_id);
- const int cur_dist = cStringUtil::EditDistance(cur_name, in_name);
- if (cur_dist < best_dist) {
- best_dist = cur_dist;
- best_name = cur_name;
- }
- if (cur_dist == 0) break;
- }
-
- return best_name;
-}
-
-bool cInstSet::InstInSet(const cString& in_name) const
-{
- cString best_name("");
-
- for (int i = 0; i < m_lib_name_map.GetSize(); i++) {
- const cString & cur_name = m_inst_lib->GetName(m_lib_name_map[i].lib_fun_id);
- if (cur_name == in_name) return true;
- }
- return false;
-}
-
Deleted: development/source/main/cInstSet.h
===================================================================
--- development/source/main/cInstSet.h 2007-02-15 15:08:27 UTC (rev 1325)
+++ development/source/main/cInstSet.h 2007-02-15 16:38:07 UTC (rev 1326)
@@ -1,189 +0,0 @@
-/*
- * cInstSet.h
- * Avida
- *
- * Called "inst_set.hh" prior to 12/5/05.
- * Copyright 1999-2007 Michigan State University. All rights reserved.
- * Copyright 1993-2001 California Institute of Technology.
- *
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; version 2
- * of the License.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-#ifndef cInstSet_h
-#define cInstSet_h
-
-#include <iostream>
-
-#ifndef cString_h
-#include "cString.h"
-#endif
-#ifndef tArray_h
-#include "tArray.h"
-#endif
-#ifndef cInstruction_h
-#include "cInstruction.h"
-#endif
-#ifndef cInstLibBase_h
-#include "cInstLibBase.h"
-#endif
-
-using namespace std;
-
-/**
- * This class is used to create a mapping from the command strings in
- * an organism's genome into real methods in one of the hardware objects. This
- * object has been designed to allow easy manipulation of the instruction
- * sets, as well as multiple instruction sets within a single soup (just
- * attach different cInstSet objects to different hardware.
- **/
-
-class cAvidaContext;
-class cWorld;
-
-class cInstSet
-{
-public:
- cWorld* m_world;
- cInstLibBase *m_inst_lib;
- class cInstEntry {
- public:
- int lib_fun_id;
- int redundancy; // Weight in instruction set (not impl.)
- int cost; // additional time spent to exectute inst.
- int ft_cost; // time spent first time exec (in add to cost)
- double prob_fail; // probability of failing to execute inst
- int addl_time_cost; // additional time added to age for executing instruction
- };
- tArray<cInstEntry> m_lib_name_map;
- tArray<int> m_lib_nopmod_map;
- tArray<int> m_mutation_chart; // ID's represented by redundancy values.
-
- // Static components...
- static cInstruction inst_error2;
- static cInstruction inst_default2;
- static const cInstruction inst_default;
-
-
- cInstSet(); // @not_implemented
-
-public:
- inline cInstSet(cWorld* world) : m_world(world) { ; }
- inline cInstSet(const cInstSet& is);
- inline ~cInstSet() { ; }
-
- inline cInstSet& operator=(const cInstSet& _in);
-
- bool OK() const;
-
- // Accessors
- const cString& GetName(int id) const { return m_inst_lib->GetName(m_lib_name_map[id].lib_fun_id); }
- const cString& GetName(const cInstruction& inst) const { return GetName(inst.GetOp()); }
- int GetCost(const cInstruction& inst) const { return m_lib_name_map[inst.GetOp()].cost; }
- int GetFTCost(const cInstruction& inst) const { return m_lib_name_map[inst.GetOp()].ft_cost; }
- int GetAddlTimeCost(const cInstruction& inst) const { return m_lib_name_map[inst.GetOp()].addl_time_cost; }
- double GetProbFail(const cInstruction& inst) const { return m_lib_name_map[inst.GetOp()].prob_fail; }
- int GetRedundancy(const cInstruction& inst) const { return m_lib_name_map[inst.GetOp()].redundancy; }
- int GetLibFunctionIndex(const cInstruction& inst) const { return m_lib_name_map[inst.GetOp()].lib_fun_id; }
-
- int GetNopMod(const cInstruction& inst) const
- {
- int nopmod = m_lib_nopmod_map[inst.GetOp()];
- return m_inst_lib->GetNopMod(nopmod);
- }
-
- cInstruction GetRandomInst(cAvidaContext& ctx) const;
- int GetRandFunctionIndex(cAvidaContext& ctx) const { return m_lib_name_map[ GetRandomInst(ctx).GetOp() ].lib_fun_id; }
-
- int GetSize() const { return m_lib_name_map.GetSize(); }
- int GetNumNops() const { return m_lib_nopmod_map.GetSize(); }
-
- // Instruction Analysis.
- int IsNop(const cInstruction& inst) const { return (inst.GetOp() < m_lib_nopmod_map.GetSize()); }
-
- // Insertion of new instructions...
- int AddInst(int lib_fun_id, int redundancy = 1, int ft_cost = 0, int cost = 0, double prob_fail = 0.0, int addl_time_cost = 0);
- int AddNop(int lib_nopmod_id, int redundancy = 1, int ft_cost = 0, int cost = 0, double prob_fail = 0.0, int addl_time_cost = 0);
-
- // accessors for instruction library
- cInstLibBase* GetInstLib() { return m_inst_lib; }
- void SetInstLib(cInstLibBase* inst_lib)
- {
- m_inst_lib = inst_lib;
- inst_error2 = inst_lib->GetInstError();
- inst_default2 = inst_lib->GetInstDefault();
- }
-
- inline cInstruction GetInst(const cString& in_name) const;
- cString FindBestMatch(const cString& in_name) const;
- bool InstInSet(const cString& in_name) const;
-
- // Static methods..
- static const cInstruction& GetInstDefault() { return inst_default2; }
- static const cInstruction & GetInstError() { return inst_error2; }
-};
-
-
-#ifdef ENABLE_UNIT_TESTS
-namespace nInstSet {
- /**
- * Run unit tests
- *
- * @param full Run full test suite; if false, just the fast tests.
- **/
- void UnitTests(bool full = false);
-}
-#endif
-
-
-inline cInstSet::cInstSet(const cInstSet& is)
-: m_world(is.m_world), m_inst_lib(is.m_inst_lib), m_lib_name_map(is.m_lib_name_map)
-,m_lib_nopmod_map(is.m_lib_nopmod_map), m_mutation_chart(is.m_mutation_chart)
-{
-}
-
-inline cInstSet& cInstSet::operator=(const cInstSet& _in)
-{
- m_inst_lib = _in.m_inst_lib;
- m_lib_name_map = _in.m_lib_name_map;
- m_lib_nopmod_map = _in.m_lib_nopmod_map;
- m_mutation_chart = _in.m_mutation_chart;
- return *this;
-}
-
-inline cInstruction cInstSet::GetInst(const cString & in_name) const
-{
- for (int i = 0; i < m_lib_name_map.GetSize(); i++) {
- if (m_inst_lib->GetName(m_lib_name_map[i].lib_fun_id) == in_name) {
- return cInstruction(i);
- }
- }
-
- // @CAO Hacking this to make sure we don't have defaults...
- cerr << "Error: Unknown instruction '" << in_name << "'. Exiting..." << endl;
- exit(1);
-
-
- // Adding default answer if nothing is found...
- /*
- FIXME: this return value is supposed to be cInstSet::GetInstError
- which should be the same as m_inst_lib->GetInstError().
- -- kgn
- */
- return cInstruction(0);
-}
-
-#endif
Deleted: development/source/main/cInstUtil.cc
===================================================================
--- development/source/main/cInstUtil.cc 2007-02-15 15:08:27 UTC (rev 1325)
+++ development/source/main/cInstUtil.cc 2007-02-15 16:38:07 UTC (rev 1326)
@@ -1,135 +0,0 @@
-/*
- * cInstUtil.cc
- * Avida
- *
- * Called "inst_util.cc" prior to 12/5/05.
- * Copyright 1999-2007 Michigan State University. All rights reserved.
- * Copyright 1993-2003 California Institute of Technology.
- *
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; version 2
- * of the License.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-#include "cInstUtil.h"
-
-#include "cString.h"
-#include "cFile.h"
-
-#ifndef INIT_FILE_HH
-#include "cInitFile.h"
-#endif
-
-#include "cInstSet.h"
-#include "cGenome.h"
-
-
-using namespace std;
-
-
-cGenome cInstUtil::LoadGenome(const cString& filename, const cInstSet& inst_set)
-{
- cGenome new_genome(0);
- if (!LoadGenome(filename, inst_set, new_genome)) {
- cerr << "Error: Unable to load genome" << endl;
- exit(1);
- }
- return new_genome;
-}
-
-bool cInstUtil::LoadGenome(const cString& filename, const cInstSet& inst_set, cGenome& out_genome)
-{
- cInitFile input_file(filename);
- bool success = true;
-
- if (!input_file.IsOpen()) return false;
-
- input_file.Load();
- input_file.Compress();
- input_file.Close();
-
- // Setup the code array...
- cGenome new_genome(input_file.GetNumLines());
-
- for (int line_num = 0; line_num < new_genome.GetSize(); line_num++) {
- cString cur_line = input_file.GetLine(line_num);
- new_genome[line_num] = inst_set.GetInst(cur_line);
-
- if (new_genome[line_num] == cInstSet::GetInstError()) {
- // You're using the wrong instruction set! YOU FOOL!
- if (success) {
- cerr << "Error: Cannot load organism '" << filename << "'" << endl;
- success = false;
- }
- cerr << " Unknown line: " << cur_line << " (best match is '" << inst_set.FindBestMatch(cur_line) << "')" << endl;
- }
- }
-
- if (new_genome.GetSize() == 0) cerr << "Warning: Genome size is 0!" << endl;
- if (success) out_genome = new_genome;
- return success;
-}
-
-cGenome cInstUtil::LoadInternalGenome(istream& fp, const cInstSet& inst_set)
-{
- assert(fp.good()); // Invalid stream to load genome from!
-
- int num_lines = -1;
- fp >> num_lines;
-
- if (num_lines <= 0) { return cGenome(1); }
-
- // Setup the code array...
- cGenome new_genome(num_lines);
- cString cur_line;
-
- for (int line_num = 0; line_num < new_genome.GetSize(); line_num++) {
- fp >> cur_line;
- new_genome[line_num] = inst_set.GetInst(cur_line);
-
- if (new_genome[line_num] == cInstSet::GetInstError()) {
- // You're using the wrong instruction set! YOU FOOL!
- cerr << "Cannot load creature from stream:" << endl
- << " Unknown line: " << cur_line << endl;
- }
- }
- return new_genome;
-}
-
-void cInstUtil::SaveGenome(ostream& fp, const cInstSet& inst_set,
- const cGenome & gen)
-{
- for (int i = 0; i < gen.GetSize(); i++) {
- fp << inst_set.GetName(gen[i]) << endl;
- }
-}
-
-void cInstUtil::SaveInternalGenome(ostream& fp, const cInstSet& inst_set,
- const cGenome & gen)
-{
- fp << gen.GetSize() << endl;
- SaveGenome(fp, inst_set, gen);
-}
-
-
-cGenome cInstUtil::RandomGenome(cAvidaContext& ctx, int length, const cInstSet& inst_set)
-{
- cGenome genome(length);
- for (int i = 0; i < length; i++) {
- genome[i] = inst_set.GetRandomInst(ctx);
- }
- return genome;
-}
-
Deleted: development/source/main/cInstUtil.h
===================================================================
--- development/source/main/cInstUtil.h 2007-02-15 15:08:27 UTC (rev 1325)
+++ development/source/main/cInstUtil.h 2007-02-15 16:38:07 UTC (rev 1326)
@@ -1,76 +0,0 @@
-/*
- * cInstUtil.h
- * Avida
- *
- * Called "inst_util.hh" prior to 12/5/05.
- * Copyright 1999-2007 Michigan State University. All rights reserved.
- * Copyright 1993-2003 California Institute of Technology.
- *
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; version 2
- * of the License.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-#ifndef cInstUtil_h
-#define cInstUtil_h
-
-#include <iostream>
-
-#ifndef cGenome_h
-#include "cGenome.h"
-#endif
-
-class cAvidaContext;
-class cInitFile;
-class cInstSet;
-class cString;
-
-class cInstUtil
-{
-private:
- cInstUtil(); // @not_implemented
-
-public:
-
- // ========= Genome-File Interaction =========
- // Saving and loading of files. These functions assume that the genome is
- // the only thing in the file unless 'Internal' is in the function name
- // (Internal genomes must begin with a number that indicates genome length)
-
- static bool LoadGenome(const cString &filename, const cInstSet &inst_set, cGenome& out_genome);
- static cGenome LoadGenome(const cString &filename, const cInstSet &inst_set);
- static cGenome LoadInternalGenome(std::istream & fp, const cInstSet &inst_set);
- static void SaveGenome(std::ostream& fp, const cInstSet & inst_set,
- const cGenome &gen);
- static void SaveInternalGenome(std::ostream& fp, const cInstSet &inst_set,
- const cGenome &gen);
-
- // ========= Genome Construction =========
- static cGenome RandomGenome(cAvidaContext& ctx, int length, const cInstSet & inst_set);
-};
-
-
-#ifdef ENABLE_UNIT_TESTS
-namespace nInstUtil {
- /**
- * Run unit tests
- *
- * @param full Run full test suite; if false, just the fast tests.
- **/
- void UnitTests(bool full = false);
-}
-#endif
-
-#endif
Modified: development/source/main/cOrgInterface.h
===================================================================
--- development/source/main/cOrgInterface.h 2007-02-15 15:08:27 UTC (rev 1325)
+++ development/source/main/cOrgInterface.h 2007-02-15 16:38:07 UTC (rev 1326)
@@ -73,7 +73,7 @@
virtual int ReceiveValue() = 0;
virtual void SellValue(const int data, const int label, const int sell_price, const int org_id) = 0;
virtual int BuyValue(const int label, const int buy_price) = 0;
- virtual bool InjectParasite(cOrganism* parent, const cGenome& injected_code) = 0;
+ virtual bool InjectParasite(cOrganism* parent, const cCodeLabel& label, const cGenome& injected_code) = 0;
virtual bool UpdateMerit(double new_merit) = 0;
virtual bool TestOnDivide() = 0;
};
Modified: development/source/main/cOrganism.cc
===================================================================
--- development/source/main/cOrganism.cc 2007-02-15 15:08:27 UTC (rev 1325)
+++ development/source/main/cOrganism.cc 2007-02-15 16:38:07 UTC (rev 1326)
@@ -36,7 +36,6 @@
#include "cHardwareManager.h"
#include "cInjectGenotype.h"
#include "cInstSet.h"
-#include "cInstUtil.h"
#include "cOrgSinkMessage.h"
#include "cStringUtil.h"
#include "cTaskContext.h"
@@ -398,10 +397,10 @@
}
-bool cOrganism::InjectParasite(const cGenome& injected_code)
+bool cOrganism::InjectParasite(const cCodeLabel& label, const cGenome& injected_code)
{
assert(m_interface);
- return m_interface->InjectParasite(this, injected_code);
+ return m_interface->InjectParasite(this, label, injected_code);
}
bool cOrganism::InjectHost(const cCodeLabel& label, const cGenome& injected_code)
Modified: development/source/main/cOrganism.h
===================================================================
--- development/source/main/cOrganism.h 2007-02-15 15:08:27 UTC (rev 1325)
+++ development/source/main/cOrganism.h 2007-02-15 16:38:07 UTC (rev 1326)
@@ -215,7 +215,7 @@
// -------- Parasite Interactions --------
- bool InjectParasite(const cGenome& genome);
+ bool InjectParasite(const cCodeLabel& label, const cGenome& genome);
bool InjectHost(const cCodeLabel& in_label, const cGenome& genome);
void AddParasite(cInjectGenotype* cur) { m_parasites.Push(cur); }
cInjectGenotype& GetParasite(int x) { return *m_parasites[x]; }
Modified: development/source/main/cPopulation.cc
===================================================================
--- development/source/main/cPopulation.cc 2007-02-15 15:08:27 UTC (rev 1325)
+++ development/source/main/cPopulation.cc 2007-02-15 16:38:07 UTC (rev 1326)
@@ -39,7 +39,6 @@
#include "cHardwareManager.h"
#include "cInitFile.h"
#include "cInjectGenotype.h"
-#include "cInstUtil.h"
#include "cIntegratedSchedule.h"
#include "cLineage.h"
#include "cOrganism.h"
@@ -179,7 +178,7 @@
const cString& filename = m_world->GetConfig().START_CREATURE.Get();
if (filename != "-" && filename != "") {
- if (!cInstUtil::LoadGenome(filename, world->GetHardwareManager().GetInstSet(), start_org)) {
+ if (!cGenomeUtil::LoadGenome(filename, world->GetHardwareManager().GetInstSet(), start_org)) {
cerr << "Error: Unable to load start creature" << endl;
exit(-1);
}
@@ -373,7 +372,7 @@
return parent_alive;
}
-bool cPopulation::ActivateParasite(cOrganism& parent, const cGenome& injected_code)
+bool cPopulation::ActivateParasite(cOrganism& parent, const cCodeLabel& label, const cGenome& injected_code)
{
assert(&parent != NULL);
@@ -397,7 +396,7 @@
if (child_cpu.GetNumThreads() == m_world->GetConfig().MAX_CPU_THREADS.Get()) return false;
- if (target_organism->InjectHost(parent_cpu.GetLabel(), injected_code)) {
+ if (target_organism->InjectHost(label, injected_code)) {
cInjectGenotype* child_genotype = parent_genotype;
// If the parent genotype is not correct for the child, adjust it.
Modified: development/source/main/cPopulation.h
===================================================================
--- development/source/main/cPopulation.h 2007-02-15 15:08:27 UTC (rev 1325)
+++ development/source/main/cPopulation.h 2007-02-15 16:38:07 UTC (rev 1326)
@@ -148,7 +148,7 @@
// Activate the offspring of an organism in the population
bool ActivateOffspring(cAvidaContext& ctx, cGenome& child_genome, cOrganism& parent_organism);
- bool ActivateParasite(cOrganism& parent, const cGenome& injected_code);
+ bool ActivateParasite(cOrganism& parent, const cCodeLabel& label, 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,
Modified: development/source/main/cPopulationInterface.cc
===================================================================
--- development/source/main/cPopulationInterface.cc 2007-02-15 15:08:27 UTC (rev 1325)
+++ development/source/main/cPopulationInterface.cc 2007-02-15 16:38:07 UTC (rev 1326)
@@ -194,12 +194,12 @@
return value;
}
-bool cPopulationInterface::InjectParasite(cOrganism* parent, const cGenome& injected_code)
+bool cPopulationInterface::InjectParasite(cOrganism* parent, const cCodeLabel& label, const cGenome& injected_code)
{
assert(parent != NULL);
assert(m_world->GetPopulation().GetCell(m_cell_id).GetOrganism() == parent);
- return m_world->GetPopulation().ActivateParasite(*parent, injected_code);
+ return m_world->GetPopulation().ActivateParasite(*parent, label, injected_code);
}
bool cPopulationInterface::UpdateMerit(double new_merit)
Modified: development/source/main/cPopulationInterface.h
===================================================================
--- development/source/main/cPopulationInterface.h 2007-02-15 15:08:27 UTC (rev 1325)
+++ development/source/main/cPopulationInterface.h 2007-02-15 16:38:07 UTC (rev 1326)
@@ -74,7 +74,7 @@
int ReceiveValue();
void SellValue(const int data, const int label, const int sell_price, const int org_id);
int BuyValue(const int label, const int buy_price);
- bool InjectParasite(cOrganism* parent, const cGenome& injected_code);
+ bool InjectParasite(cOrganism* parent, const cCodeLabel& label, const cGenome& injected_code);
bool UpdateMerit(double new_merit);
bool TestOnDivide();
};
More information about the Avida-cvs
mailing list