[Avida-SVN] r2898 - in branches/collect/source: actions analyze cpu drivers main script tools
blwalker at myxo.css.msu.edu
blwalker at myxo.css.msu.edu
Thu Oct 30 13:25:55 PDT 2008
Author: blwalker
Date: 2008-10-30 16:25:54 -0400 (Thu, 30 Oct 2008)
New Revision: 2898
Modified:
branches/collect/source/actions/PrintActions.cc
branches/collect/source/analyze/cAnalyze.cc
branches/collect/source/analyze/cAnalyze.h
branches/collect/source/analyze/cAnalyzeGenotype.cc
branches/collect/source/analyze/cAnalyzeGenotype.h
branches/collect/source/cpu/cCPUTestInfo.h
branches/collect/source/cpu/cHardwareCPU.cc
branches/collect/source/cpu/cHardwareCPU.h
branches/collect/source/cpu/cHardwareManager.cc
branches/collect/source/cpu/cTestCPUInterface.h
branches/collect/source/drivers/cDriverStatusConduit.cc
branches/collect/source/drivers/cDriverStatusConduit.h
branches/collect/source/main/cAvidaConfig.cc
branches/collect/source/main/cAvidaConfig.h
branches/collect/source/main/cDeme.cc
branches/collect/source/main/cDeme.h
branches/collect/source/main/cOrgInterface.h
branches/collect/source/main/cOrganism.cc
branches/collect/source/main/cOrganism.h
branches/collect/source/main/cPhenotype.cc
branches/collect/source/main/cPhenotype.h
branches/collect/source/main/cPopulationInterface.cc
branches/collect/source/main/cPopulationInterface.h
branches/collect/source/main/cStats.cc
branches/collect/source/main/cStats.h
branches/collect/source/script/ASAnalyzeLib.cc
branches/collect/source/tools/cDataFile.cc
branches/collect/source/tools/cDataFile.h
branches/collect/source/tools/cFlexVar.h
branches/collect/source/tools/cStringList.h
branches/collect/source/tools/tDataEntry.h
branches/collect/source/tools/tDataEntryCommand.h
branches/collect/source/tools/tDataManager.h
Log:
Porting r2877:2890 from development to collect branch.
Resolved one textual conflict. Updated inst.n stuff in cAnalyzeGenotype::BuildDEDict to the even-newer format introduced in r2882.
Modified: branches/collect/source/actions/PrintActions.cc
===================================================================
--- branches/collect/source/actions/PrintActions.cc 2008-10-30 19:24:03 UTC (rev 2897)
+++ branches/collect/source/actions/PrintActions.cc 2008-10-30 20:25:54 UTC (rev 2898)
@@ -75,6 +75,7 @@
STATS_OUT_FILE(PrintDominantData, dominant.dat );
STATS_OUT_FILE(PrintStatsData, stats.dat );
STATS_OUT_FILE(PrintCountData, count.dat );
+STATS_OUT_FILE(PrintMessageData, message.dat );
STATS_OUT_FILE(PrintTotalsData, totals.dat );
STATS_OUT_FILE(PrintTasksData, tasks.dat );
STATS_OUT_FILE(PrintTasksExeData, tasks_exe.dat );
@@ -2666,6 +2667,7 @@
action_lib->Register<cActionPrintDominantData>("PrintDominantData");
action_lib->Register<cActionPrintStatsData>("PrintStatsData");
action_lib->Register<cActionPrintCountData>("PrintCountData");
+ action_lib->Register<cActionPrintMessageData>("PrintMessageData");
action_lib->Register<cActionPrintTotalsData>("PrintTotalsData");
action_lib->Register<cActionPrintTasksData>("PrintTasksData");
action_lib->Register<cActionPrintTasksExeData>("PrintTasksExeData");
Modified: branches/collect/source/analyze/cAnalyze.cc
===================================================================
--- branches/collect/source/analyze/cAnalyze.cc 2008-10-30 19:24:03 UTC (rev 2897)
+++ branches/collect/source/analyze/cAnalyze.cc 2008-10-30 20:25:54 UTC (rev 2898)
@@ -959,7 +959,7 @@
// Construct a linked list of data types that can be loaded...
tList< tDataEntryCommand<cAnalyzeGenotype> > output_list;
tListIterator< tDataEntryCommand<cAnalyzeGenotype> > output_it(output_list);
- LoadGenotypeDataList(input_file.GetFormat(), output_list);
+ cAnalyzeGenotype::LoadDataCommandList(m_world, input_file.GetFormat(), output_list);
bool id_inc = input_file.GetFormat().HasString("id");
// Setup the genome...
@@ -974,7 +974,6 @@
output_it.Reset();
tDataEntryCommand<cAnalyzeGenotype>* data_command = NULL;
while ((data_command = output_it.Next()) != NULL) {
- // genotype->SetSpecialArgs(data_command->GetArgs());
data_command->SetValue(genotype, cur_line.PopWord());
}
@@ -1011,7 +1010,7 @@
cString test_value = cur_string.PopWord();
// Get the dynamic command to look up the stat we need.
- tDataEntryCommand<cAnalyzeGenotype> * stat_command = GetGenotypeDataCommand(stat_name);
+ tDataEntryCommand<cAnalyzeGenotype> * stat_command = cAnalyzeGenotype::GetDataCommand(m_world, stat_name);
// Check for various possible errors before moving on...
@@ -1963,7 +1962,7 @@
// Construct a linked list of details needed...
tList< tDataEntryCommand<cAnalyzeGenotype> > output_list;
tListIterator< tDataEntryCommand<cAnalyzeGenotype> > output_it(output_list);
- LoadGenotypeDataList(cur_string, output_list);
+ cAnalyzeGenotype::LoadDataCommandList(m_world, cur_string, output_list);
// Determine the file type...
int file_type = FILE_TYPE_TEXT;
@@ -2009,7 +2008,7 @@
// Construct a linked list of details needed...
tList< tDataEntryCommand<cAnalyzeGenotype> > output_list;
tListIterator< tDataEntryCommand<cAnalyzeGenotype> > output_it(output_list);
- LoadGenotypeDataList(cur_string, output_list);
+ cAnalyzeGenotype::LoadDataCommandList(m_world, cur_string, output_list);
// Determine the file type...
int file_type = FILE_TYPE_TEXT;
@@ -2033,16 +2032,18 @@
void cAnalyze::CommandDetail_Header(ostream& fp, int format_type,
- tListIterator< tDataEntryCommand<cAnalyzeGenotype> > & output_it,
+ tListIterator< tDataEntryCommand<cAnalyzeGenotype> >& output_it,
int time_step)
{
+ cAnalyzeGenotype* cur_genotype = batch[cur_batch].List().GetFirst();
+
// Write out the header on the file
if (format_type == FILE_TYPE_TEXT) {
fp << "#filetype genotype_data" << endl;
fp << "#format ";
if (time_step > 0) fp << "update ";
while (output_it.Next() != NULL) {
- const cString & entry_name = output_it.Get()->GetName();
+ const cString& entry_name = output_it.Get()->GetName();
fp << entry_name << " ";
}
fp << endl << endl;
@@ -2052,7 +2053,7 @@
int count = 0;
if (time_step > 0) fp << "# " << ++count << ": Update" << endl;
while (output_it.Next() != NULL) {
- const cString & entry_desc = output_it.Get()->GetDesc();
+ const cString& entry_desc = output_it.Get()->GetDesc(cur_genotype);
fp << "# " << ++count << ": " << entry_desc << endl;
}
fp << endl;
@@ -2071,7 +2072,7 @@
if (time_step > 0) fp << "<th bgcolor=\"#AAAAFF\">Update ";
while (output_it.Next() != NULL) {
- const cString & entry_desc = output_it.Get()->GetDesc();
+ const cString& entry_desc = output_it.Get()->GetDesc(cur_genotype);
fp << "<th bgcolor=\"#AAAAFF\">" << entry_desc << " ";
}
fp << "</tr>" << endl;
@@ -2109,12 +2110,10 @@
tDataEntryCommand<cAnalyzeGenotype> * data_command = NULL;
while ((data_command = output_it.Next()) != NULL) {
- cur_genotype->SetSpecialArgs(data_command->GetArgs());
cFlexVar cur_value = data_command->GetValue(cur_genotype);
if (format_type == FILE_TYPE_HTML) {
int compare = 0;
if (prev_genotype) {
- prev_genotype->SetSpecialArgs(data_command->GetArgs());
cFlexVar prev_value = data_command->GetValue(prev_genotype);
int compare_type = data_command->GetCompareType();
compare = CompareFlexStat(cur_value, prev_value, compare_type);
@@ -2169,7 +2168,6 @@
output_it.Reset();
tDataEntryCommand<cAnalyzeGenotype> * data_command = NULL;
while ((data_command = output_it.Next()) != NULL) {
- cur_genotype->SetSpecialArgs(data_command->GetArgs());
for (int j = 0; j < cur_genotype->GetNumCPUs(); j++) {
output_counts[count].Add( data_command->GetValue(cur_genotype).AsDouble() );
}
@@ -2199,7 +2197,7 @@
// Construct a linked list of details needed...
tList< tDataEntryCommand<cAnalyzeGenotype> > output_list;
tListIterator< tDataEntryCommand<cAnalyzeGenotype> > output_it(output_list);
- LoadGenotypeDataList(cur_string, output_list);
+ cAnalyzeGenotype::LoadDataCommandList(m_world, cur_string, output_list);
// check if file is already in use.
bool file_active = m_world->GetDataFileManager().IsOpen(filename);
@@ -2228,7 +2226,7 @@
else cout << "Detailing Batches..." << endl;
// Find its associated command...
- tDataEntryCommand<cAnalyzeGenotype>* cur_command = GetGenotypeDataCommand(keyword);
+ tDataEntryCommand<cAnalyzeGenotype>* cur_command = cAnalyzeGenotype::GetDataCommand(m_world, keyword);
if (!cur_command) {
cout << "error: no data entry, unable to detail batches" << endl;
return;
@@ -2242,6 +2240,7 @@
if (file_extension == "html") file_type = FILE_TYPE_HTML;
ofstream& fp = m_world->GetDataFileOFStream(filename);
+ cAnalyzeGenotype* first_genotype = batch[cur_batch].List().GetFirst();
// Write out the header on the file
if (file_type == FILE_TYPE_TEXT) {
@@ -2252,7 +2251,7 @@
// Give the more human-readable legend.
fp << "# Legend:" << endl
<< "# Column 1 = Batch ID" << endl
- << "# Remaining entries: " << cur_command->GetDesc() << endl
+ << "# Remaining entries: " << cur_command->GetDesc(first_genotype) << endl
<< endl;
} else { // if (file_type == FILE_TYPE_HTML) {
@@ -2263,11 +2262,11 @@
<< " alink=\"#0000FF\"" << endl
<< " vlink=\"#000044\">" << endl
<< endl
- << "<h1 align=center> Distribution of " << cur_command->GetDesc()
+ << "<h1 align=center> Distribution of " << cur_command->GetDesc(first_genotype)
<< endl << endl
<< "<center>" << endl
<< "<table border=1 cellpadding=2>" << endl
- << "<tr><th bgcolor=\"#AAAAFF\">" << cur_command->GetDesc() << "</tr>"
+ << "<tr><th bgcolor=\"#AAAAFF\">" << cur_command->GetDesc(first_genotype) << "</tr>"
<< endl;
}
@@ -2284,7 +2283,6 @@
while ((genotype = batch_it.Next()) != NULL) {
if (file_type == FILE_TYPE_HTML) fp << "<td>";
- genotype->SetSpecialArgs(cur_command->GetArgs());
if (file_type == FILE_TYPE_HTML) {
HTMLPrintStat(cur_command->GetValue(genotype), fp, 0, cur_command->GetHtmlCellFlags(), cur_command->GetNull());
}
@@ -2331,11 +2329,12 @@
// Construct a linked list of details needed...
tList<tDataEntryCommand<cAnalyzeGenotype> > output_list;
tListIterator<tDataEntryCommand<cAnalyzeGenotype> > output_it(output_list);
- LoadGenotypeDataList(cStringList(cur_string), output_list);
+ cAnalyzeGenotype::LoadDataCommandList(m_world, cStringList(cur_string), output_list);
// Setup the file...
ofstream& fp = m_world->GetDataFileOFStream(filename);
+ cAnalyzeGenotype* first_genotype = batch[cur_batch].List().GetFirst();
// Determine the file type...
int file_type = FILE_TYPE_TEXT;
@@ -2357,7 +2356,7 @@
fp << "# 1: Batch Name" << endl;
int count = 1;
while (output_it.Next() != NULL) {
- const cString & entry_desc = output_it.Get()->GetDesc();
+ const cString& entry_desc = output_it.Get()->GetDesc(first_genotype);
fp << "# " << ++count << ": " << entry_desc << endl;
}
fp << endl;
@@ -2376,7 +2375,7 @@
fp << "<th bgcolor=\"#AAAAFF\">Batch ";
while (output_it.Next() != NULL) {
- const cString & entry_desc = output_it.Get()->GetDesc();
+ const cString& entry_desc = output_it.Get()->GetDesc(first_genotype);
fp << "<th bgcolor=\"#AAAAFF\">" << entry_desc << " ";
}
fp << "</tr>" << endl;
@@ -2429,7 +2428,7 @@
// Construct a linked list of details needed...
tList< tDataEntryCommand<cAnalyzeGenotype> > output_list;
tListIterator< tDataEntryCommand<cAnalyzeGenotype> > output_it(output_list);
- LoadGenotypeDataList(cur_string, output_list);
+ cAnalyzeGenotype::LoadDataCommandList(m_world, cur_string, output_list);
// Determine the file type...
int file_type = FILE_TYPE_TEXT;
@@ -2454,6 +2453,8 @@
void cAnalyze::CommandHistogram_Header(ostream& fp, int format_type,
tListIterator< tDataEntryCommand<cAnalyzeGenotype> > & output_it)
{
+ cAnalyzeGenotype* first_genotype = batch[cur_batch].List().GetFirst();
+
// Write out the header on the file
if (format_type == FILE_TYPE_TEXT) {
fp << "#filetype histogram_data" << endl;
@@ -2468,7 +2469,7 @@
fp << "# Histograms:" << endl;
int count = 0;
while (output_it.Next() != NULL) {
- const cString & entry_desc = output_it.Get()->GetDesc();
+ const cString & entry_desc = output_it.Get()->GetDesc(first_genotype);
fp << "# " << ++count << ": " << entry_desc << endl;
}
fp << endl;
@@ -2487,7 +2488,7 @@
<< "<table border=1 cellpadding=2><tr>" << endl;
while (output_it.Next() != NULL) {
- const cString & entry_desc = output_it.Get()->GetDesc();
+ const cString & entry_desc = output_it.Get()->GetDesc(first_genotype);
const cString & entry_name = output_it.Get()->GetName();
fp << "<tr><th bgcolor=\"#AAAAFF\"><a href=\"#"
<< entry_name << "\">"
@@ -2499,18 +2500,19 @@
void cAnalyze::CommandHistogram_Body(ostream& fp, int format_type,
- tListIterator< tDataEntryCommand<cAnalyzeGenotype> > & output_it)
+ tListIterator< tDataEntryCommand<cAnalyzeGenotype> >& output_it)
{
output_it.Reset();
tDataEntryCommand<cAnalyzeGenotype> * data_command = NULL;
+ cAnalyzeGenotype* first_genotype = batch[cur_batch].List().GetFirst();
while ((data_command = output_it.Next()) != NULL) {
if (format_type == FILE_TYPE_TEXT) {
- fp << "# --- " << data_command->GetDesc() << " ---" << endl;
+ fp << "# --- " << data_command->GetDesc(first_genotype) << " ---" << endl;
} else {
fp << "<table cellpadding=3>" << endl
<< "<tr><th colspan=3><a name=\"" << data_command->GetName() << "\">"
- << data_command->GetDesc() << "</th></tr>" << endl;
+ << data_command->GetDesc(first_genotype) << "</th></tr>" << endl;
}
tDictionary<int> count_dict;
@@ -4697,7 +4699,7 @@
msg.Set("There are %d column args.", arg_list.GetSize());
m_world->GetDriver().NotifyComment(msg);
- LoadGenotypeDataList(arg_list, output_list);
+ cAnalyzeGenotype::LoadDataCommandList(m_world, arg_list, output_list);
m_world->GetDriver().NotifyComment("Args are loaded.");
@@ -4820,7 +4822,7 @@
fp << "<tr><td colspan=3> ";
output_it.Reset();
while (output_it.Next() != NULL) {
- fp << "<th>" << output_it.Get()->GetDesc() << " ";
+ fp << "<th>" << output_it.Get()->GetDesc(genotype) << " ";
}
fp << "</tr>" << endl;
@@ -4829,7 +4831,6 @@
tDataEntryCommand<cAnalyzeGenotype> * data_command = NULL;
cAnalyzeGenotype null_genotype(m_world, "a", inst_set);
while ((data_command = output_it.Next()) != NULL) {
- genotype->SetSpecialArgs(data_command->GetArgs());
const cFlexVar cur_value = data_command->GetValue(genotype);
const cFlexVar null_value = data_command->GetValue(&null_genotype);
int compare = CompareFlexStat(cur_value, null_value, data_command->GetCompareType());
@@ -4888,7 +4889,6 @@
tDataEntryCommand<cAnalyzeGenotype>* data_command = NULL;
int cur_col = 0;
while ((data_command = output_it.Next()) != NULL) {
- test_genotype.SetSpecialArgs(data_command->GetArgs());
const cFlexVar test_value = data_command->GetValue(&test_genotype);
int compare = CompareFlexStat(test_value, data_command->GetValue(genotype), data_command->GetCompareType());
@@ -4959,7 +4959,7 @@
cout << "There are " << arg_list.GetSize() << " column args." << endl;
- LoadGenotypeDataList(arg_list, output_list);
+ cAnalyzeGenotype::LoadDataCommandList(m_world, arg_list, output_list);
cout << "Args are loaded." << endl;
@@ -5119,13 +5119,11 @@
tDataEntryCommand<cAnalyzeGenotype> * data_command = NULL;
int cur_col = 0;
while ((data_command = output_it.Next()) != NULL) {
- test_genotype.SetSpecialArgs(data_command->GetArgs());
const cFlexVar test_value = data_command->GetValue(&test_genotype);
// This is done so that under 'binary' option it marks
// the task as being influenced by the mutation iff
// it is completely knocked out, not just decreased
- genotype->SetSpecialArgs(data_command->GetArgs());
int compare_type = data_command->GetCompareType();
int compare = CompareFlexStat(test_value, data_command->GetValue(genotype), compare_type);
@@ -5305,7 +5303,7 @@
tList< tDataEntryCommand<cAnalyzeGenotype> > output_list;
tListIterator< tDataEntryCommand<cAnalyzeGenotype> > output_it(output_list);
cStringList arg_list(cur_string);
- LoadGenotypeDataList(arg_list, output_list);
+ cAnalyzeGenotype::LoadDataCommandList(m_world, arg_list, output_list);
const int num_traits = output_list.GetSize();
// Setup the map_inst_set with the NULL instruction
@@ -5343,7 +5341,6 @@
tDataEntryCommand<cAnalyzeGenotype> * data_command = NULL;
int cur_trait = 0;
while ((data_command = output_it.Next()) != NULL) {
- test_genotype.SetSpecialArgs(data_command->GetArgs());
const cFlexVar test_value = data_command->GetValue(&test_genotype);
int compare_type = data_command->GetCompareType();
@@ -9135,51 +9132,8 @@
-// Find a data entry bassed on a keyword
-tDataEntryCommand<cAnalyzeGenotype>* cAnalyze::GetGenotypeDataCommand(const cString& stat_entry)
-{
- cString arg_list = stat_entry;
- cString stat_name = arg_list.Pop(':');
- tDataEntry<cAnalyzeGenotype>* data_entry;
- if (m_world->GetGenotypeDEDict().Find(stat_name, data_entry)) {
- return new tDataEntryCommand<cAnalyzeGenotype>(data_entry, arg_list);
- }
-
- cerr << "warning: Format entry \"" << stat_name << "\" not found. Best match is \""
- << m_world->GetGenotypeDEDict().NearMatch(stat_name) << "\"." << endl;
- return NULL;
-}
-
-
-// Pass in the arguments for a command and fill out the entries in list format....
-void cAnalyze::LoadGenotypeDataList(cStringList arg_list,
- tList<tDataEntryCommand<cAnalyzeGenotype> >& output_list)
-{
- // If no args were given, load all of the stats.
- if (arg_list.GetSize() == 0) {
- tArray<tDataEntry<cAnalyzeGenotype>*> data_entries;
- m_world->GetGenotypeDEDict().GetValues(data_entries);
- for (int i = 0; i < data_entries.GetSize(); i++)
- output_list.PushRear(new tDataEntryCommand<cAnalyzeGenotype>(data_entries[i], ""));
- }
- // Otherwise, load only those listed.
- else {
- while (arg_list.GetSize() != 0) {
- // Setup the next entry
- cString cur_entry = arg_list.Pop();
-
- tDataEntryCommand<cAnalyzeGenotype>* cur_command = GetGenotypeDataCommand(cur_entry);
- if (cur_command) output_list.PushRear(cur_command);
- }
- }
-}
-
-
-
-
-
void cAnalyze::AddLibraryDef(const cString & name,
void (cAnalyze::*_fun)(cString))
{
Modified: branches/collect/source/analyze/cAnalyze.h
===================================================================
--- branches/collect/source/analyze/cAnalyze.h 2008-10-30 19:24:03 UTC (rev 2897)
+++ branches/collect/source/analyze/cAnalyze.h 2008-10-30 20:25:54 UTC (rev 2898)
@@ -186,9 +186,6 @@
const cString& cell_flags="align=center", const cString& null_text = "0", bool print_text = true);
int CompareFlexStat(const cFlexVar& org_stat, const cFlexVar& parent_stat, int compare_type = FLEX_COMPARE_MAX);
- // Deal with genotype data list (linking keywords to stats)
- tDataEntryCommand<cAnalyzeGenotype>* GetGenotypeDataCommand(const cString & stat_entry);
- void LoadGenotypeDataList(cStringList arg_list, tList<tDataEntryCommand<cAnalyzeGenotype> > & output_list);
void AddLibraryDef(const cString & name, void (cAnalyze::*_fun)(cString));
void AddLibraryDef(const cString & name, void (cAnalyze::*_fun)(cString, tList<cAnalyzeCommand> &));
Modified: branches/collect/source/analyze/cAnalyzeGenotype.cc
===================================================================
--- branches/collect/source/analyze/cAnalyzeGenotype.cc 2008-10-30 19:24:03 UTC (rev 2897)
+++ branches/collect/source/analyze/cAnalyzeGenotype.cc 2008-10-30 20:25:54 UTC (rev 2898)
@@ -27,6 +27,8 @@
#include "cAvidaContext.h"
#include "cCPUTestInfo.h"
+#include "cDriverManager.h"
+#include "cDriverStatusConduit.h"
#include "cHardwareBase.h"
#include "cHardwareManager.h"
#include "cInstSet.h"
@@ -42,8 +44,10 @@
#include "tArray.h"
#include "tAutoRelease.h"
-#include "tDataManager.h"
+#include "tDataEntry.h"
+#include "tDataEntryCommand.h"
+
#include <cmath>
using namespace std;
@@ -236,102 +240,84 @@
// FLEX_COMPARE_MAX2 = 5 -- Same as FLEX_COMPARE_MAX, and 0 indicates trait is off.
// FLEX_COMPARE_MIN2 = 6 -- Same as FLEX_COMPARE_MIN, BUT 0 still indicates off.
- ADD_GDATA(const cString&, "name", "Genotype Name", GetName, SetName, 0, 0, 0);
- ADD_GDATA(bool, "viable", "Is Viable (0/1)", GetViable, SetViable, 5, 0, 0);
- ADD_GDATA(int, "id", "Genotype ID", GetID, SetID, 0, 0, 0);
- ADD_GDATA(const cString &, "tag", "Genotype Tag", GetTag, SetTag, 0, "(none)","");
- ADD_GDATA(int, "parent_id", "Parent ID", GetParentID, SetParentID, 0, 0, 0);
- ADD_GDATA(int, "parent2_id", "Second Parent ID (sexual orgs)",GetParent2ID, SetParent2ID, 0, 0, 0);
- ADD_GDATA(int, "parent_dist", "Parent Distance", GetParentDist, SetParentDist, 0, 0, 0);
- ADD_GDATA(int, "ancestor_dist","Ancestor Distance", GetAncestorDist, SetAncestorDist, 0, 0, 0);
- ADD_GDATA(int, "lineage", "Unique Lineage Label", GetLineageLabel, SetLineageLabel, 0, 0, 0);
- ADD_GDATA(int, "num_cpus", "Number of CPUs", GetNumCPUs, SetNumCPUs, 0, 0, 0);
- ADD_GDATA(int, "total_cpus", "Total CPUs Ever", GetTotalCPUs, SetTotalCPUs, 0, 0, 0);
- ADD_GDATA(int, "length", "Genome Length", GetLength, SetLength, 4, 0, 0);
- ADD_GDATA(int, "copy_length", "Copied Length", GetCopyLength, SetCopyLength, 0, 0, 0);
- ADD_GDATA(int, "exe_length", "Executed Length", GetExeLength, SetExeLength, 0, 0, 0);
- ADD_GDATA(double, "merit", "Merit", GetMerit, SetMerit, 5, 0, 0);
- ADD_GDATA(double, "comp_merit", "Computational Merit", GetCompMerit, SetNULL, 5, 0, 0);
- ADD_GDATA(double, "comp_merit_ratio", "Computational Merit Ratio", GetCompMeritRatio, SetNULL, 5, 0, 0);
- ADD_GDATA(int, "gest_time", "Gestation Time", GetGestTime, SetGestTime, 6, "Inf", 0);
- ADD_GDATA(double, "efficiency", "Rep. Efficiency", GetEfficiency, SetNULL, 5, 0, 0);
- ADD_GDATA(double, "efficiency_ratio", "Rep. Efficiency Ratio", GetEfficiencyRatio,SetNULL, 5, 0, 0);
- ADD_GDATA(double, "fitness", "Fitness", GetFitness, SetFitness, 5, 0, 0);
- ADD_GDATA(double, "div_type", "Divide Type", GetDivType, SetDivType, 0, 0, 0);
- ADD_GDATA(int, "mate_id", "Mate Selection ID Number", GetMateID, SetMateID, 0, 0, 0);
- ADD_GDATA(double, "fitness_ratio","Fitness Ratio", GetFitnessRatio, SetNULL, 5, 0, 0);
- ADD_GDATA(int, "update_born", "Update Born", GetUpdateBorn, SetUpdateBorn, 0, 0, 0);
- ADD_GDATA(int, "update_dead", "Update Dead", GetUpdateDead, SetUpdateDead, 0, 0, 0);
- ADD_GDATA(int, "depth", "Tree Depth", GetDepth, SetDepth, 0, 0, 0);
- ADD_GDATA(double, "frac_dead", "Fraction Mutations Lethal", GetFracDead, SetNULL, 0, 0, 0);
- ADD_GDATA(double, "frac_neg", "Fraction Mutations Detrimental",GetFracNeg, SetNULL, 0, 0, 0);
- ADD_GDATA(double, "frac_neut", "Fraction Mutations Neutral", GetFracNeut, SetNULL, 0, 0, 0);
- ADD_GDATA(double, "frac_pos", "Fraction Mutations Beneficial", GetFracPos, SetNULL, 0, 0, 0);
- ADD_GDATA(double, "complexity", "Basic Complexity (beneficial muts are neutral)", GetComplexity, SetNULL, 0, 0, 0);
- ADD_GDATA(double, "land_fitness", "Average Lanscape Fitness", GetLandscapeFitness, SetNULL, 0, 0, 0);
+ ADD_GDATA(const cString& (), "name", "Genotype Name", GetName, SetName, 0, 0, 0);
+ ADD_GDATA(bool (), "viable", "Is Viable (0/1)", GetViable, SetViable, 5, 0, 0);
+ ADD_GDATA(int (), "id", "Genotype ID", GetID, SetID, 0, 0, 0);
+ ADD_GDATA(const cString& (), "tag", "Genotype Tag", GetTag, SetTag, 0, "(none)","");
+ ADD_GDATA(int (), "parent_id", "Parent ID", GetParentID, SetParentID, 0, 0, 0);
+ ADD_GDATA(int (), "parent2_id", "Second Parent ID (sexual orgs)",GetParent2ID, SetParent2ID, 0, 0, 0);
+ ADD_GDATA(int (), "parent_dist", "Parent Distance", GetParentDist, SetParentDist, 0, 0, 0);
+ ADD_GDATA(int (), "ancestor_dist","Ancestor Distance", GetAncestorDist, SetAncestorDist, 0, 0, 0);
+ ADD_GDATA(int (), "lineage", "Unique Lineage Label", GetLineageLabel, SetLineageLabel, 0, 0, 0);
+ ADD_GDATA(int (), "num_cpus", "Number of CPUs", GetNumCPUs, SetNumCPUs, 0, 0, 0);
+ ADD_GDATA(int (), "total_cpus", "Total CPUs Ever", GetTotalCPUs, SetTotalCPUs, 0, 0, 0);
+ ADD_GDATA(int (), "length", "Genome Length", GetLength, SetLength, 4, 0, 0);
+ ADD_GDATA(int (), "copy_length", "Copied Length", GetCopyLength, SetCopyLength, 0, 0, 0);
+ ADD_GDATA(int (), "exe_length", "Executed Length", GetExeLength, SetExeLength, 0, 0, 0);
+ ADD_GDATA(double (), "merit", "Merit", GetMerit, SetMerit, 5, 0, 0);
+ ADD_GDATA(double (), "comp_merit", "Computational Merit", GetCompMerit, SetNULL, 5, 0, 0);
+ ADD_GDATA(double (), "comp_merit_ratio", "Computational Merit Ratio", GetCompMeritRatio, SetNULL, 5, 0, 0);
+ ADD_GDATA(int (), "gest_time", "Gestation Time", GetGestTime, SetGestTime, 6, "Inf", 0);
+ ADD_GDATA(double (), "efficiency", "Rep. Efficiency", GetEfficiency, SetNULL, 5, 0, 0);
+ ADD_GDATA(double (), "efficiency_ratio", "Rep. Efficiency Ratio", GetEfficiencyRatio,SetNULL, 5, 0, 0);
+ ADD_GDATA(double (), "fitness", "Fitness", GetFitness, SetFitness, 5, 0, 0);
+ ADD_GDATA(double (), "div_type", "Divide Type", GetDivType, SetDivType, 0, 0, 0);
+ ADD_GDATA(int (), "mate_id", "Mate Selection ID Number", GetMateID, SetMateID, 0, 0, 0);
+ ADD_GDATA(double (), "fitness_ratio","Fitness Ratio", GetFitnessRatio, SetNULL, 5, 0, 0);
+ ADD_GDATA(int (), "update_born", "Update Born", GetUpdateBorn, SetUpdateBorn, 0, 0, 0);
+ ADD_GDATA(int (), "update_dead", "Update Dead", GetUpdateDead, SetUpdateDead, 0, 0, 0);
+ ADD_GDATA(int (), "depth", "Tree Depth", GetDepth, SetDepth, 0, 0, 0);
+ ADD_GDATA(double (), "frac_dead", "Fraction Mutations Lethal", GetFracDead, SetNULL, 0, 0, 0);
+ ADD_GDATA(double (), "frac_neg", "Fraction Mutations Detrimental",GetFracNeg, SetNULL, 0, 0, 0);
+ ADD_GDATA(double (), "frac_neut", "Fraction Mutations Neutral", GetFracNeut, SetNULL, 0, 0, 0);
+ ADD_GDATA(double (), "frac_pos", "Fraction Mutations Beneficial", GetFracPos, SetNULL, 0, 0, 0);
+ ADD_GDATA(double (), "complexity", "Basic Complexity (beneficial muts are neutral)", GetComplexity, SetNULL, 0, 0, 0);
+ ADD_GDATA(double (), "land_fitness", "Average Lanscape Fitness", GetLandscapeFitness, SetNULL, 0, 0, 0);
- ADD_GDATA(int, "num_phen", "Number of Plastic Phenotypes", GetNumPhenotypes, SetNULL, 0, 0, 0);
- ADD_GDATA(int, "num_trials", "Number of Recalculation Trials", GetNumTrials, SetNULL, 0, 0, 0);
- ADD_GDATA(double, "phen_entropy", "Phenotpyic Entropy", GetPhenotypicEntropy, SetNULL, 0, 0, 0);
- ADD_GDATA(double, "phen_max_fitness", "Phen Plast Maximum Fitness", GetMaximumFitness, SetNULL, 0, 0, 0);
- ADD_GDATA(double, "phen_max_fit_freq", "Phen Plast Maximum Fitness Frequency", GetMaximumFitnessFrequency,SetNULL, 0, 0, 0);
- ADD_GDATA(double, "phen_min_fitness", "Phen Plast Minimum Fitness", GetMinimumFitness, SetNULL, 0, 0, 0);
- ADD_GDATA(double, "phen_min_freq", "Phen Plast Minimum Fitness Frequency", GetMinimumFitnessFrequency,SetNULL, 0, 0, 0);
- ADD_GDATA(double, "phen_avg_fitness", "Phen Plast Wtd Avg Fitness", GetAverageFitness, SetNULL, 0, 0, 0);
- ADD_GDATA(double, "phen_likely_freq", "Freq of Most Likely Phenotype", GetLikelyFrequency, SetNULL, 0, 0, 0);
- ADD_GDATA(double, "phen_likely_fitness","Fitness of Most Likely Phenotype", GetLikelyFitness, SetNULL, 0, 0, 0);
+ ADD_GDATA(int (), "num_phen", "Number of Plastic Phenotypes", GetNumPhenotypes, SetNULL, 0, 0, 0);
+ ADD_GDATA(int (), "num_trials", "Number of Recalculation Trials", GetNumTrials, SetNULL, 0, 0, 0);
+ ADD_GDATA(double (), "phen_entropy", "Phenotpyic Entropy", GetPhenotypicEntropy, SetNULL, 0, 0, 0);
+ ADD_GDATA(double (), "phen_max_fitness", "Phen Plast Maximum Fitness", GetMaximumFitness, SetNULL, 0, 0, 0);
+ ADD_GDATA(double (), "phen_max_fit_freq", "Phen Plast Maximum Fitness Frequency", GetMaximumFitnessFrequency,SetNULL, 0, 0, 0);
+ ADD_GDATA(double (), "phen_min_fitness", "Phen Plast Minimum Fitness", GetMinimumFitness, SetNULL, 0, 0, 0);
+ ADD_GDATA(double (), "phen_min_freq", "Phen Plast Minimum Fitness Frequency", GetMinimumFitnessFrequency,SetNULL, 0, 0, 0);
+ ADD_GDATA(double (), "phen_avg_fitness", "Phen Plast Wtd Avg Fitness", GetAverageFitness, SetNULL, 0, 0, 0);
+ ADD_GDATA(double (), "phen_likely_freq", "Freq of Most Likely Phenotype", GetLikelyFrequency, SetNULL, 0, 0, 0);
+ ADD_GDATA(double (), "phen_likely_fitness","Fitness of Most Likely Phenotype", GetLikelyFitness, SetNULL, 0, 0, 0);
- ADD_GDATA(const cString &, "parent_muts", "Mutations from Parent", GetParentMuts, SetParentMuts, 0, "(none)", "");
- ADD_GDATA(const cString &, "task_order", "Task Performance Order", GetTaskOrder, SetTaskOrder, 0, "(none)", "");
- ADD_GDATA(cString, "sequence", "Genome Sequence", GetSequence, SetSequence, 0, "(N/A)", "");
- ADD_GDATA(const cString &, "alignment", "Aligned Sequence", GetAlignedSequence, SetAlignedSequence, 0, "(N/A)", "");
+ ADD_GDATA(const cString& (), "parent_muts", "Mutations from Parent", GetParentMuts, SetParentMuts, 0, "(none)", "");
+ ADD_GDATA(const cString& (), "task_order", "Task Performance Order", GetTaskOrder, SetTaskOrder, 0, "(none)", "");
+ ADD_GDATA(cString (), "sequence", "Genome Sequence", GetSequence, SetSequence, 0, "(N/A)", "");
+ ADD_GDATA(const cString& (), "alignment", "Aligned Sequence", GetAlignedSequence, SetAlignedSequence, 0, "(N/A)", "");
- ADD_GDATA(cString, "executed_flags", "Executed Flags", GetExecutedFlags, SetNULL, 0, "(N/A)", "");
- ADD_GDATA(cString, "alignment_executed_flags", "Alignment Executed Flags", GetAlignmentExecutedFlags, SetNULL, 0, "(N/A)", "");
- ADD_GDATA(cString, "task_list", "List of all tasks performed", GetTaskList, SetNULL, 0, "(N/A)", "");
- ADD_GDATA(cString, "link.tasksites", "Phenotype Map", GetMapLink, SetNULL, 0, 0, 0);
- ADD_GDATA(cString, "html.sequence", "Genome Sequence", GetHTMLSequence, SetNULL, 0, "(N/A)", "");
+ ADD_GDATA(cString (), "executed_flags", "Executed Flags", GetExecutedFlags, SetNULL, 0, "(N/A)", "");
+ ADD_GDATA(cString (), "alignment_executed_flags", "Alignment Executed Flags", GetAlignmentExecutedFlags, SetNULL, 0, "(N/A)", "");
+ ADD_GDATA(cString (), "task_list", "List of all tasks performed", GetTaskList, SetNULL, 0, "(N/A)", "");
+ ADD_GDATA(cString (), "link.tasksites", "Phenotype Map", GetMapLink, SetNULL, 0, 0, 0);
+ ADD_GDATA(cString (), "html.sequence", "Genome Sequence", GetHTMLSequence, SetNULL, 0, "(N/A)", "");
- for (int i = 0; i < world->GetHardwareManager().GetInstSet().GetSize(); i++) {
- cString i_name, i_desc;
- i_name.Set("inst.%d", i);
- i_desc.Set("# Times ");
- i_desc += world->GetHardwareManager().GetInstSet().GetName(i);
- i_desc += " Executed";
- dedict->Add(i_name, new tDataEntryWithArg<cAnalyzeGenotype, int, int>
- (i_name, i_desc, &cAnalyzeGenotype::GetInstExecutedCount, i));
- }
+ dedict->Add("inst", new tDataEntryOfType<cAnalyzeGenotype, int (int)>
+ ("inst", &cAnalyzeGenotype::DescInstExe, &cAnalyzeGenotype::GetInstExecutedCount));
// coarse-grained task stats
- ADD_GDATA(int, "total_task_count","# Different Tasks", GetTotalTaskCount, SetNULL, 1, 0, 0);
- ADD_GDATA(int, "total_task_performance_count", "Total Tasks Performed", GetTotalTaskPerformanceCount, SetNULL, 1, 0, 0);
+ ADD_GDATA(int (), "total_task_count","# Different Tasks", GetTotalTaskCount, SetNULL, 1, 0, 0);
+ ADD_GDATA(int (), "total_task_performance_count", "Total Tasks Performed", GetTotalTaskPerformanceCount, SetNULL, 1, 0, 0);
- const cEnvironment& environment = world->GetEnvironment();
- for (int i = 0; i < environment.GetNumTasks(); i++) {
- cString t_name, t_desc;
- t_name.Set("task.%d", i);
- t_desc = environment.GetTask(i).GetDesc();
- dedict->Add(t_name,
- new tDataEntryWithArg<cAnalyzeGenotype, int, int>(t_name, t_desc, &cAnalyzeGenotype::GetTaskCount, i, 5));
- }
- for (int i = 0; i < environment.GetInputSize(); i++){
- cString t_name, t_desc;
- t_name.Set("env_input.%d", i);
- t_desc.Set("env_input.%d", i);
- dedict->Add(t_name,
- new tDataEntryWithArg<cAnalyzeGenotype, int, int>(t_name, t_desc, &cAnalyzeGenotype::GetEnvInput, i, 0));
- }
-
+ dedict->Add("task", new tDataEntryOfType<cAnalyzeGenotype, int (int, const cStringList&)>
+ ("task", &cAnalyzeGenotype::DescTask, &cAnalyzeGenotype::GetTaskCount, 5));
+ dedict->Add("env_input", new tDataEntryOfType<cAnalyzeGenotype, int (int)>
+ ("env_input", &cAnalyzeGenotype::DescEnvInput, &cAnalyzeGenotype::GetEnvInput));
+
// The remaining values should actually go in a seperate list called
// "population_data_list", but for the moment we're going to put them
// here so that we only need to worry about a single system to load and
// save genotype information.
- ADD_GDATA(int, "update", "Update Output", GetUpdateDead, SetUpdateDead, 0, 0, 0);
- ADD_GDATA(int, "dom_num_cpus", "Number of Dominant Organisms", GetNumCPUs, SetNumCPUs, 0, 0, 0);
- ADD_GDATA(int, "dom_depth", "Tree Depth of Dominant Genotype", GetDepth, SetDepth, 0, 0, 0);
- ADD_GDATA(int, "dom_id", "Dominant Genotype ID", GetID, SetID, 0, 0, 0);
- ADD_GDATA(cString, "dom_sequence", "Dominant Genotype Sequence", GetSequence, SetSequence, 0, "(N/A)", "");
+ ADD_GDATA(int (), "update", "Update Output", GetUpdateDead, SetUpdateDead, 0, 0, 0);
+ ADD_GDATA(int (), "dom_num_cpus", "Number of Dominant Organisms", GetNumCPUs, SetNumCPUs, 0, 0, 0);
+ ADD_GDATA(int (), "dom_depth", "Tree Depth of Dominant Genotype", GetDepth, SetDepth, 0, 0, 0);
+ ADD_GDATA(int (), "dom_id", "Dominant Genotype ID", GetID, SetID, 0, 0, 0);
+ ADD_GDATA(cString (), "dom_sequence", "Dominant Genotype Sequence", GetSequence, SetSequence, 0, "(N/A)", "");
return dedict;
@@ -348,6 +334,54 @@
+// Find a data entry bassed on a keyword
+tDataEntryCommand<cAnalyzeGenotype>* cAnalyzeGenotype::GetDataCommand(cWorld* world, const cString& cmd)
+{
+ cString arg_list = cmd;
+ cString idx = arg_list.Pop(':');
+ cString entry_name = idx.Pop('.');
+
+ tDataEntry<cAnalyzeGenotype>* data_entry;
+ if (world->GetGenotypeDEDict().Find(entry_name, data_entry)) {
+ return new tDataEntryCommand<cAnalyzeGenotype>(data_entry, idx, arg_list);
+ }
+
+ cDriverManager::Status().NotifyWarning(cStringUtil::Stringf("data entry '%s' not found, best match is '%s'", *entry_name,
+ *(world->GetGenotypeDEDict().NearMatch(entry_name))));
+
+ return NULL;
+}
+
+
+// Pass in the arguments for a command and fill out the entries in list format....
+void cAnalyzeGenotype::LoadDataCommandList(cWorld* world, cStringList arg_list,
+ tList<tDataEntryCommand<cAnalyzeGenotype> >& output_list)
+{
+ if (arg_list.GetSize() == 0) {
+ // If no args were given, load all of the stats.
+ // @TODO - handle indexed items... under this scheme only the first task and env_input value will be output
+
+ tArray<tDataEntry<cAnalyzeGenotype>*> data_entries;
+ world->GetGenotypeDEDict().GetValues(data_entries);
+ for (int i = 0; i < data_entries.GetSize(); i++)
+ output_list.PushRear(new tDataEntryCommand<cAnalyzeGenotype>(data_entries[i]));
+ } else {
+ while (arg_list.GetSize() != 0) {
+ tDataEntryCommand<cAnalyzeGenotype>* cur_command = GetDataCommand(world, arg_list.Pop());
+ if (cur_command) output_list.PushRear(cur_command);
+ }
+ }
+}
+
+
+cString cAnalyzeGenotype::DescTask(int task_id) const
+{
+ if (task_id > task_counts.GetSize()) return "";
+ return m_world->GetEnvironment().GetTask(task_id).GetDesc();
+}
+
+
+
int cAnalyzeGenotype::CalcMaxGestation() const
{
return m_world->GetConfig().TEST_CPU_TIME_MOD.Get() * genome.GetSize();
@@ -675,6 +709,16 @@
return 0;
}
+cString cAnalyzeGenotype::DescInstExe(int _inst_id) const
+{
+ if(_inst_id > inst_executed_counts.GetSize() || _inst_id < 0) return "";
+
+ cString desc("# Times ");
+ desc += GetInstructionSet().GetName(_inst_id);
+ desc += " Executed";
+ return desc;
+}
+
int cAnalyzeGenotype::GetKO_DeadCount() const
{
CalcKnockouts(false); // Make sure knockouts are calculated
Modified: branches/collect/source/analyze/cAnalyzeGenotype.h
===================================================================
--- branches/collect/source/analyze/cAnalyzeGenotype.h 2008-10-30 19:24:03 UTC (rev 2897)
+++ branches/collect/source/analyze/cAnalyzeGenotype.h 2008-10-30 20:25:54 UTC (rev 2898)
@@ -66,6 +66,7 @@
class cTestCPU;
class cWorld;
template<class T> class tDataEntry;
+template<class T> class tDataEntryCommand;
template<class T> class tDictionary;
@@ -215,8 +216,6 @@
};
mutable cAnalyzePhenPlast* m_phenplast_stats;
- cStringList special_args; // These are args placed after a ':' in details...
-
int NumCompare(double new_val, double old_val) const {
if (new_val == old_val) return 0;
else if (new_val == 0) return -2;
@@ -242,10 +241,10 @@
static tDictionary<tDataEntry<cAnalyzeGenotype>*>* BuildDEDict(cWorld* world);
static void DestroyDEDict(tDictionary<tDataEntry<cAnalyzeGenotype>*>* dedict);
+
+ static tDataEntryCommand<cAnalyzeGenotype>* GetDataCommand(cWorld* world, const cString& cmd);
+ static void LoadDataCommandList(cWorld* world, cStringList arg_list, tList<tDataEntryCommand<cAnalyzeGenotype> >& output_list);
- const cStringList & GetSpecialArgs() { return special_args; }
- void SetSpecialArgs(const cStringList & _args) { special_args = _args; }
-
void Recalculate(cAvidaContext& ctx, cCPUTestInfo* test_info = NULL, cAnalyzeGenotype* parent_genotype = NULL, int num_trials = 1);
void PrintTasks(std::ofstream& fp, int min_task = 0, int max_task = -1);
void PrintTasksQuality(std::ofstream& fp, int min_task = 0, int max_task = -1);
@@ -292,6 +291,7 @@
// void SetFracPos(double in_frac);
// A set of NULL accessors to simplyfy automated accesses.
+ void SetNULL(int idx, int dummy) { (void) dummy; }
void SetNULL(int dummy) { (void) dummy; }
void SetNULL(char dummy) { (void) dummy; }
void SetNULL(double dummy) { (void) dummy; }
@@ -307,6 +307,7 @@
cString GetAlignmentExecutedFlags() const;
const tArray<int>& GetInstExecutedCounts() const { return inst_executed_counts; }
int GetInstExecutedCount(int _inst_num) const;
+ cString DescInstExe(int _inst_id) const;
const cString & GetTag() const { return tag; }
bool GetViable() const { return viable; }
@@ -389,12 +390,17 @@
int GetNumTasks() const { return task_counts.GetSize(); }
int GetTaskCount(int task_id) const {
if (task_id >= task_counts.GetSize()) return 0;
- if (special_args.HasString("binary")) return (task_counts[task_id] > 0);
return task_counts[task_id];
}
- const tArray<int> & GetTaskCounts() const {
+ int GetTaskCount(int task_id, const cStringList& args) const {
+ if (task_id >= task_counts.GetSize()) return 0;
+ if (args.HasString("binary")) return (task_counts[task_id] > 0);
+ return task_counts[task_id];
+ }
+ const tArray<int>& GetTaskCounts() const {
return task_counts;
}
+ cString DescTask(int task_id) const;
double GetTaskQuality(int task_id) const {
if (task_id >= task_counts.GetSize()) return 0;
@@ -427,6 +433,7 @@
const tArray<int>& GetEnvInputs() const{
return m_env_inputs;
}
+ cString DescEnvInput(int input_id) const { return cStringUtil::Stringf("task.%d", input_id); }
// Comparisons... Compares a genotype to the "previous" one, which is
// passed in, in one specified phenotype.
Modified: branches/collect/source/cpu/cCPUTestInfo.h
===================================================================
--- branches/collect/source/cpu/cCPUTestInfo.h 2008-10-30 19:24:03 UTC (rev 2897)
+++ branches/collect/source/cpu/cCPUTestInfo.h 2008-10-30 20:25:54 UTC (rev 2898)
@@ -93,8 +93,8 @@
// Input Setup
void TraceTaskOrder(bool _trace=true) { trace_task_order = _trace; }
void UseRandomInputs(bool _rand=true) { use_random_inputs = _rand; use_manual_inputs = false; }
- void UseManualInputs(tArray<int> inputs) {use_manual_inputs = true; use_random_inputs = false; manual_inputs = inputs;}
- void ResetInputMode() {use_manual_inputs = false; use_random_inputs = false;}
+ void UseManualInputs(tArray<int> inputs) {use_manual_inputs = true; use_random_inputs = false; manual_inputs = inputs;}
+ void ResetInputMode() {use_manual_inputs = false; use_random_inputs = false;}
void SetTraceExecution(cHardwareTracer* tracer = NULL) { m_tracer = tracer; }
void SetInstSet(cInstSet* inst_set = NULL) { m_inst_set = inst_set; }
void SetResourceOptions(int res_method = RES_INITIAL, std::vector<std::pair<int, std::vector<double> > > * res = NULL, int update = 0, int cpu_cycle_offset = 0)
Modified: branches/collect/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/collect/source/cpu/cHardwareCPU.cc 2008-10-30 19:24:03 UTC (rev 2897)
+++ branches/collect/source/cpu/cHardwareCPU.cc 2008-10-30 20:25:54 UTC (rev 2898)
@@ -221,6 +221,8 @@
tInstLibEntry<tMethod>("donate-quantagb", &cHardwareCPU::Inst_DonateQuantaThreshGreenBeard),
tInstLibEntry<tMethod>("donate-NUL", &cHardwareCPU::Inst_DonateNULL),
tInstLibEntry<tMethod>("donate-facing", &cHardwareCPU::Inst_DonateFacing),
+ tInstLibEntry<tMethod>("receive-donated-energy", &cHardwareCPU::Inst_ReceiveDonatedEnergy, nInstFlag::STALL),
+ tInstLibEntry<tMethod>("donate-energy", &cHardwareCPU::Inst_DonateEnergy, nInstFlag::STALL),
tInstLibEntry<tMethod>("IObuf-add1", &cHardwareCPU::Inst_IOBufAdd1, nInstFlag::STALL),
tInstLibEntry<tMethod>("IObuf-add0", &cHardwareCPU::Inst_IOBufAdd0, nInstFlag::STALL),
@@ -234,7 +236,6 @@
tInstLibEntry<tMethod>("rotate-to-occupied-cell", &cHardwareCPU::Inst_RotateOccupiedCell, nInstFlag::STALL),
tInstLibEntry<tMethod>("rotate-to-event-cell", &cHardwareCPU::Inst_RotateEventCell, nInstFlag::STALL),
-
tInstLibEntry<tMethod>("set-cmut", &cHardwareCPU::Inst_SetCopyMut),
tInstLibEntry<tMethod>("mod-cmut", &cHardwareCPU::Inst_ModCopyMut),
tInstLibEntry<tMethod>("get-cell-xy", &cHardwareCPU::Inst_GetCellPosition),
@@ -368,7 +369,15 @@
tInstLibEntry<tMethod>("relinquishEnergyToNeighborOrganisms", &cHardwareCPU::Inst_RelinquishEnergyToNeighborOrganisms, nInstFlag::STALL),
tInstLibEntry<tMethod>("relinquishEnergyToOrganismsInDeme", &cHardwareCPU::Inst_RelinquishEnergyToOrganismsInDeme, nInstFlag::STALL),
-
+ // Energy level detection
+ tInstLibEntry<tMethod>("if-energy-low", &cHardwareCPU::Inst_IfEnergyLow, nInstFlag::STALL),
+ tInstLibEntry<tMethod>("if-energy-not-low", &cHardwareCPU::Inst_IfEnergyNotLow, nInstFlag::STALL),
+ tInstLibEntry<tMethod>("if-energy-high", &cHardwareCPU::Inst_IfEnergyHigh, nInstFlag::STALL),
+ tInstLibEntry<tMethod>("if-energy-not-high", &cHardwareCPU::Inst_IfEnergyNotHigh, nInstFlag::STALL),
+ tInstLibEntry<tMethod>("if-energy-med", &cHardwareCPU::Inst_IfEnergyMed, nInstFlag::STALL),
+ tInstLibEntry<tMethod>("if-energy-in-buffer", &cHardwareCPU::Inst_IfEnergyInBuffer, nInstFlag::STALL),
+ tInstLibEntry<tMethod>("if-energy-not-in-buffer", &cHardwareCPU::Inst_IfEnergyNotInBuffer, nInstFlag::STALL),
+
// Sleep and time
tInstLibEntry<tMethod>("sleep", &cHardwareCPU::Inst_Sleep, nInstFlag::STALL),
tInstLibEntry<tMethod>("sleep1", &cHardwareCPU::Inst_Sleep, nInstFlag::STALL),
@@ -3453,11 +3462,14 @@
// Plug the current merit back into this organism and notify the scheduler.
organism->UpdateMerit(cur_merit);
+ organism->GetPhenotype().SetIsEnergyDonor();
// Update the merit of the organism being donated to...
double other_merit = to_org->GetPhenotype().GetMerit().GetDouble();
other_merit += merit_received;
to_org->UpdateMerit(other_merit);
+ to_org->GetPhenotype().SetIsEnergyReceiver();
+
}
void cHardwareCPU::DoEnergyDonate(cOrganism* to_org)
@@ -3471,15 +3483,59 @@
//update energy store and merit of donor
organism->GetPhenotype().ReduceEnergy(energy_given);
+ organism->GetPhenotype().IncreaseEnergyDonated(energy_given);
double senderMerit = cMerit::EnergyToMerit(organism->GetPhenotype().GetStoredEnergy() * organism->GetPhenotype().GetEnergyUsageRatio(), m_world);
organism->UpdateMerit(senderMerit);
+ organism->GetPhenotype().SetIsEnergyDonor();
// update energy store and merit of donee
to_org->GetPhenotype().ReduceEnergy(-1.0*energy_given);
+ to_org->GetPhenotype().IncreaseEnergyReceived(energy_given);
double receiverMerit = cMerit::EnergyToMerit(to_org->GetPhenotype().GetStoredEnergy() * to_org->GetPhenotype().GetEnergyUsageRatio(), m_world);
to_org->UpdateMerit(receiverMerit);
+ to_org->GetPhenotype().SetIsEnergyReceiver();
}
+
+// The difference between this version and the previous is that this one allows energy to be placed
+// into the recipient's incoming energy buffer and not be applied immediately. Also, some of the
+// energy may be lost in transfer
+void cHardwareCPU::DoEnergyDonatePercent(cOrganism* to_org, const double frac_energy_given)
+{
+ double losspct = m_world->GetConfig().ENERGY_SHARING_LOSS.Get();
+
+ assert(to_org != NULL);
+ assert(frac_energy_given >= 0);
+ assert(frac_energy_given <= 1);
+ assert(losspct >= 0);
+ assert(losspct <= 1);
+
+ double cur_energy = organism->GetPhenotype().GetStoredEnergy();
+ double energy_given = cur_energy * frac_energy_given;
+
+ //update energy store and merit of donor
+ organism->GetPhenotype().ReduceEnergy(energy_given);
+ organism->GetPhenotype().IncreaseEnergyDonated(energy_given);
+ double senderMerit = cMerit::EnergyToMerit(organism->GetPhenotype().GetStoredEnergy() * organism->GetPhenotype().GetEnergyUsageRatio(), m_world);
+ organism->UpdateMerit(senderMerit);
+
+ //apply loss in transfer
+ energy_given *= (1 - losspct);
+
+ //place energy into receiver's incoming energy buffer
+ to_org->GetPhenotype().ReceiveDonatedEnergy(energy_given);
+ to_org->GetPhenotype().IncreaseEnergyReceived(energy_given);
+
+ //if we are using the push energy method, pass the new energy into the receiver's energy store and recalculate merit
+ if(m_world->GetConfig().ENERGY_SHARING_METHOD.Get() == 1) {
+ to_org->GetPhenotype().ApplyDonatedEnergy();
+ double receiverMerit = cMerit::EnergyToMerit(to_org->GetPhenotype().GetStoredEnergy() * to_org->GetPhenotype().GetEnergyUsageRatio(), m_world);
+ to_org->UpdateMerit(receiverMerit);
+ }
+
+} //End DoEnergyDonatePercent()
+
+
bool cHardwareCPU::Inst_DonateFacing(cAvidaContext& ctx) {
if (organism->GetPhenotype().GetCurNumDonates() > m_world->GetConfig().MAX_DONATES.Get()) {
return false;
@@ -3980,6 +4036,72 @@
}
+//Move energy from an organism's received energy buffer into their energy store, recalculate merit
+bool cHardwareCPU::Inst_ReceiveDonatedEnergy(cAvidaContext& ctx)
+{
+ if(organism->GetCellID() < 0) {
+ return false;
+ }
+
+ if(organism->GetPhenotype().GetEnergyInBufferAmount() > 0) {
+ organism->GetPhenotype().ApplyDonatedEnergy();
+ organism->GetPhenotype().SetHasUsedDonatedEnergy();
+ double receiverMerit = cMerit::EnergyToMerit(organism->GetPhenotype().GetStoredEnergy() * organism->GetPhenotype().GetEnergyUsageRatio(), m_world);
+ organism->UpdateMerit(receiverMerit);
+ }
+
+ return true;
+
+} //End Inst_ReceiveDonatedEnergy()
+
+
+//Donate a fraction of organism's energy to the organism that last requested it.
+bool cHardwareCPU::Inst_DonateEnergy(cAvidaContext& ctx)
+{
+ if(organism->GetCellID() < 0) {
+ return false;
+ }
+
+ const cOrgMessage* msg = organism->RetrieveMessage();
+ if(msg == 0) {
+ return false;
+ }
+
+ cOrganism* receiver = msg->GetSender();
+
+ // If the requestor no longer exists, should the donor still lose energy???
+ if( (receiver == NULL) && (receiver->IsDead()) ) {
+ return false;
+ }
+
+ //Note: could get fancier about fraction of energy to send
+ DoEnergyDonatePercent(receiver, m_world->GetConfig().MERIT_GIVEN.Get());
+ organism->GetPhenotype().IncDonates();
+
+ return true;
+
+} //End Inst_DonateEnergy()
+
+
+//Broadcast a request for energy
+bool cHardwareCPU::Inst_RequestEnergy(cAvidaContext& ctx)
+{
+ if(organism->GetCellID() < 0) {
+ return false;
+ }
+
+ //TODO: BDC: somehow use nop modifiers to pick a multiplier for the amount of energy to request
+
+ cOrgMessage msg = cOrgMessage(organism);
+ // Could set the data field of the message to be the multiplier
+
+ organism->BroadcastMessage(ctx, msg);
+
+ return true;
+
+} //End Inst_RequestEnergy()
+
+
bool cHardwareCPU::Inst_SearchF(cAvidaContext& ctx)
{
ReadLabel();
@@ -4746,6 +4868,120 @@
return true;
}
+
+/* Execute the next instruction if the organism's energy level is low */
+bool cHardwareCPU::Inst_IfEnergyLow(cAvidaContext& ctx) {
+
+ if(organism->GetCellID() < 0) {
+ return false;
+ }
+
+ // Note: these instructions should probably also make sure the returned energy level is not -1.
+ if(organism->GetPhenotype().GetDiscreteEnergyLevel() != cPhenotype::ENERGY_LEVEL_LOW) {
+ IP().Advance();
+ }
+
+ return true;
+
+} //End Inst_IfEnergyLow()
+
+
+/* Execute the next instruction if the organism's energy level is not low */
+bool cHardwareCPU::Inst_IfEnergyNotLow(cAvidaContext& ctx) {
+
+ if(organism->GetCellID() < 0) {
+ return false;
+ }
+
+ if(organism->GetPhenotype().GetDiscreteEnergyLevel() == cPhenotype::ENERGY_LEVEL_LOW) {
+ IP().Advance();
+ }
+
+ return true;
+
+} //End Inst_IfEnergyNotLow()
+
+
+/* Execute the next instruction if the organism's energy level is high */
+bool cHardwareCPU::Inst_IfEnergyHigh(cAvidaContext& ctx) {
+
+ if(organism->GetCellID() < 0) {
+ return false;
+ }
+
+ if(organism->GetPhenotype().GetDiscreteEnergyLevel() != cPhenotype::ENERGY_LEVEL_HIGH) {
+ IP().Advance();
+ }
+
+ return true;
+
+} //End Inst_IfEnergyHigh()
+
+
+/* Execute the next instruction if the organism's energy level is not high */
+bool cHardwareCPU::Inst_IfEnergyNotHigh(cAvidaContext& ctx) {
+
+ if(organism->GetCellID() < 0) {
+ return false;
+ }
+
+ if(organism->GetPhenotype().GetDiscreteEnergyLevel() == cPhenotype::ENERGY_LEVEL_HIGH) {
+ IP().Advance();
+ }
+
+ return true;
+
+} //End Inst_IfEnergyNotHigh()
+
+
+/* Execute the next instruction if the organism's energy level is medium */
+bool cHardwareCPU::Inst_IfEnergyMed(cAvidaContext& ctx) {
+
+ if(organism->GetCellID() < 0) {
+ return false;
+ }
+
+ if(organism->GetPhenotype().GetDiscreteEnergyLevel() != cPhenotype::ENERGY_LEVEL_MEDIUM) {
+ IP().Advance();
+ }
+
+ return true;
+
+} //End Inst_IfEnergyMed()
+
+
+/* Execute the next instruction if the organism has received energy */
+bool cHardwareCPU::Inst_IfEnergyInBuffer(cAvidaContext& ctx) {
+
+ if(organism->GetCellID() < 0) {
+ return false;
+ }
+
+ if(organism->GetPhenotype().GetEnergyInBufferAmount() == 0) {
+ IP().Advance();
+ }
+
+ return true;
+
+} //End Inst_IfEnergyInBuffer()
+
+
+/* Execute the next instruction if the organism has not received energy */
+bool cHardwareCPU::Inst_IfEnergyNotInBuffer(cAvidaContext& ctx) {
+
+ if(organism->GetCellID() < 0) {
+ return false;
+ }
+
+ if(organism->GetPhenotype().GetEnergyInBufferAmount() > 0) {
+ IP().Advance();
+ }
+
+ return true;
+
+} //End Inst_IfEnergyNotInBuffer()
+
+
bool cHardwareCPU::Inst_Sleep(cAvidaContext& ctx) {
cPopulation& pop = m_world->GetPopulation();
int cellID = organism->GetCellID();
@@ -5441,7 +5677,7 @@
int cellid = organism->GetCellID();
if(cellid == -1) {
- return true;
+ return false;
}
cPopulationCell& mycell = pop.GetCell(cellid);
@@ -5497,7 +5733,7 @@
int cellid = organism->GetCellID(); //absolute id of current cell
if(cellid == -1) {
- return true;
+ return false;
}
return DoSensePheromone(ctx, cellid);
@@ -5508,7 +5744,7 @@
int cellid = organism->GetCellID(); //absolute id of current cell
if(cellid == -1) {
- return true;
+ return false;
}
cPopulation& pop = m_world->GetPopulation();
@@ -5529,7 +5765,7 @@
int cellid = organism->GetCellID();
if(cellid == -1) {
- return true;
+ return false;
}
cPopulationCell& mycell = pop.GetCell(cellid);
@@ -5667,7 +5903,7 @@
int cellid = organism->GetCellID();
if(cellid == -1) {
- return true;
+ return false;
}
cPopulationCell& mycell = pop.GetCell(cellid);
@@ -5811,7 +6047,7 @@
int cellid = organism->GetCellID();
if(cellid == -1) {
- return true;
+ return false;
}
cPopulationCell& mycell = pop.GetCell(cellid);
@@ -6179,7 +6415,7 @@
int cellid = organism->GetCellID();
if(cellid == -1) {
- return true;
+ return false;
}
cPopulationCell& mycell = pop.GetCell(cellid);
@@ -6311,7 +6547,7 @@
int cellid = organism->GetCellID();
if(cellid == -1) {
- return true;
+ return false;
}
cPopulationCell& mycell = pop.GetCell(cellid);
@@ -6439,7 +6675,7 @@
int cellid = organism->GetCellID();
if(cellid == -1) {
- return true;
+ return false;
}
cPopulationCell& mycell = pop.GetCell(cellid);
Modified: branches/collect/source/cpu/cHardwareCPU.h
===================================================================
--- branches/collect/source/cpu/cHardwareCPU.h 2008-10-30 19:24:03 UTC (rev 2897)
+++ branches/collect/source/cpu/cHardwareCPU.h 2008-10-30 20:25:54 UTC (rev 2898)
@@ -471,6 +471,7 @@
void DoDonate(cOrganism * to_org);
void DoEnergyDonate(cOrganism* to_org);
+ void DoEnergyDonatePercent(cOrganism* to_org, const double frac_energy_given);
bool Inst_DonateRandom(cAvidaContext& ctx);
bool Inst_DonateKin(cAvidaContext& ctx);
bool Inst_DonateEditDist(cAvidaContext& ctx);
@@ -480,7 +481,11 @@
bool Inst_DonateQuantaThreshGreenBeard(cAvidaContext& ctx);
bool Inst_DonateNULL(cAvidaContext& ctx);
bool Inst_DonateFacing(cAvidaContext& ctx);
+ bool Inst_ReceiveDonatedEnergy(cAvidaContext& ctx);
+ bool Inst_DonateEnergy(cAvidaContext& ctx);
+ bool Inst_RequestEnergy(cAvidaContext& ctx);
+
bool Inst_SearchF(cAvidaContext& ctx);
bool Inst_SearchB(cAvidaContext& ctx);
bool Inst_MemSize(cAvidaContext& ctx);
@@ -581,6 +586,14 @@
bool Inst_HeadDivide0_01(cAvidaContext& ctx);
bool Inst_HeadDivide0_001(cAvidaContext& ctx);
+ bool Inst_IfEnergyLow(cAvidaContext& ctx);
+ bool Inst_IfEnergyNotLow(cAvidaContext& ctx);
+ bool Inst_IfEnergyHigh(cAvidaContext& ctx);
+ bool Inst_IfEnergyNotHigh(cAvidaContext& ctx);
+ bool Inst_IfEnergyMed(cAvidaContext& ctx);
+ bool Inst_IfEnergyInBuffer(cAvidaContext& ctx);
+ bool Inst_IfEnergyNotInBuffer(cAvidaContext& ctx);
+
bool Inst_Sleep(cAvidaContext& ctx);
bool Inst_GetUpdate(cAvidaContext& ctx);
Modified: branches/collect/source/cpu/cHardwareManager.cc
===================================================================
--- branches/collect/source/cpu/cHardwareManager.cc 2008-10-30 19:24:03 UTC (rev 2897)
+++ branches/collect/source/cpu/cHardwareManager.cc 2008-10-30 20:25:54 UTC (rev 2898)
@@ -68,7 +68,7 @@
default_filename = cHardwareGX::GetDefaultInstFilename();
break;
default:
- cDriverManager::Status().SignalFatalError(1, "Unknown/Unsupported HARDWARE_TYPE specified");
+ cDriverManager::Status().SignalError("Unknown/Unsupported HARDWARE_TYPE specified", -1);
}
if (filename == "" || filename == "-") {
@@ -106,7 +106,7 @@
hw = new cHardwareGX(m_world, in_org, m_inst_set);
break;
default:
- cDriverManager::Status().SignalFatalError(1, "Unknown/Unsupported HARDWARE_TYPE specified");
+ cDriverManager::Status().SignalError("Unknown/Unsupported HARDWARE_TYPE specified", -1);
break;
}
Modified: branches/collect/source/cpu/cTestCPUInterface.h
===================================================================
--- branches/collect/source/cpu/cTestCPUInterface.h 2008-10-30 19:24:03 UTC (rev 2897)
+++ branches/collect/source/cpu/cTestCPUInterface.h 2008-10-30 20:25:54 UTC (rev 2898)
@@ -88,6 +88,8 @@
bool TestOnDivide() { return false; }
int GetFacing() { return 0; }
bool SendMessage(cOrgMessage& msg) { return false; }
+ bool SendMessage(cOrganism* recvr, cOrgMessage& msg) { return false; }
+ bool BroadcastMessage(cOrgMessage& msg) { return false; }
bool BcastAlarm(int jump_label, int bcast_range) { return false; }
void DivideOrgTestamentAmongDeme(double value) {;}
void SendFlash() { }
Modified: branches/collect/source/drivers/cDriverStatusConduit.cc
===================================================================
--- branches/collect/source/drivers/cDriverStatusConduit.cc 2008-10-30 19:24:03 UTC (rev 2897)
+++ branches/collect/source/drivers/cDriverStatusConduit.cc 2008-10-30 20:25:54 UTC (rev 2898)
@@ -33,17 +33,15 @@
using namespace std;
-void cDriverStatusConduit::SignalError(const cString& msg)
+void cDriverStatusConduit::SignalError(const cString& msg, int exit_code)
{
cerr << "error: " << msg << endl;
+ if (exit_code) {
+ cerr << "exiting..." << endl;
+ Avida::Exit(exit_code);
+ }
}
-void cDriverStatusConduit::SignalFatalError(int exit_code, const cString& msg)
-{
- cerr << "error: " << msg << endl << "exiting..." << endl;
- Avida::Exit(exit_code);
-}
-
void cDriverStatusConduit::NotifyWarning(const cString& msg)
{
cout << "warning: " << msg << endl;
Modified: branches/collect/source/drivers/cDriverStatusConduit.h
===================================================================
--- branches/collect/source/drivers/cDriverStatusConduit.h 2008-10-30 19:24:03 UTC (rev 2897)
+++ branches/collect/source/drivers/cDriverStatusConduit.h 2008-10-30 20:25:54 UTC (rev 2898)
@@ -39,8 +39,7 @@
virtual ~cDriverStatusConduit() { ; }
// Signals
- virtual void SignalError(const cString& msg);
- virtual void SignalFatalError(int exit_code, const cString& msg);
+ virtual void SignalError(const cString& msg, int exit_code = 0);
// Notifications
virtual void NotifyWarning(const cString& msg);
Modified: branches/collect/source/main/cAvidaConfig.cc
===================================================================
--- branches/collect/source/main/cAvidaConfig.cc 2008-10-30 19:24:03 UTC (rev 2897)
+++ branches/collect/source/main/cAvidaConfig.cc 2008-10-30 20:25:54 UTC (rev 2898)
@@ -73,10 +73,10 @@
while ((errstr = err_it.Next())) cDriverManager::Status().SignalError(*errstr);
if (init_file.WasFound()) {
// exit the program if the requested configuration was found but could not be loaded
- cDriverManager::Status().SignalFatalError(-1, cString("unable to open configuration file '") + filename + "'");
+ cDriverManager::Status().SignalError(cString("unable to open configuration file '") + filename + "'", -1);
} else if (crash_if_not_found) {
// exit the program if the requested configuration file is not found
- cDriverManager::Status().SignalFatalError(-1, cString("configuration file '") + filename + "' not found");
+ cDriverManager::Status().SignalError(cString("configuration file '") + filename + "' not found", -1);
} else {
// If we failed to open the config file, try creating it.
cDriverManager::Status().NotifyWarning(
Modified: branches/collect/source/main/cAvidaConfig.h
===================================================================
--- branches/collect/source/main/cAvidaConfig.h 2008-10-30 19:24:03 UTC (rev 2897)
+++ branches/collect/source/main/cAvidaConfig.h 2008-10-30 20:25:54 UTC (rev 2898)
@@ -463,6 +463,10 @@
CONFIG_ADD_VAR(NET_MUT_PROB, double, 0.0, "Message corruption probability");
CONFIG_ADD_VAR(NET_MUT_TYPE, int, 0, "Type of message corruption. 0 = Random Single Bit, 1 = Always Flip Last");
CONFIG_ADD_VAR(NET_STYLE, int, 0, "Communication Style. 0 = Random Next, 1 = Receiver Facing");
+
+ CONFIG_ADD_GROUP(ORGANISM_MESSAGING_GROUP, "Organism Message-Based Communication");
+ CONFIG_ADD_VAR(MESSAGE_TYPE, int, 0, "Messaging Stle. 0=Receiver Facing, 1=Broadcast");
+ CONFIG_ADD_VAR(MESSAGE_BCAST_RADIUS, int, 1, "Broadcast message radius (cells)");
CONFIG_ADD_GROUP(BUY_SELL_GROUP, "Buying and Selling Parameters");
CONFIG_ADD_VAR(SAVE_RECEIVED, bool, 0, "Enable storage of all inputs bought from other orgs");
@@ -499,7 +503,13 @@
CONFIG_ADD_VAR(ENERGY_PASSED_ON_DEME_REPLICATION_METHOD, int, 0, "Who get energy passed from a parent deme\n0 = Energy divided among organisms injected to offspring deme\n1 = Energy divided among cells in offspring deme");
CONFIG_ADD_VAR(INHERIT_EXE_RATE, int, 0, "Inherit energy rate from parent? 0=no 1=yes");
CONFIG_ADD_VAR(ATTACK_DECAY_RATE, double, 0.0, "Percent of cell's energy decayed by attack");
-
+ CONFIG_ADD_VAR(ENERGY_THRESH_LOW, double, .33, "Threshold percent below which energy level is considered low. Requires ENERGY_CAP.");
+ CONFIG_ADD_VAR(ENERGY_THRESH_HIGH, double, .75, "Threshold percent above which energy level is considered high. Requires ENERGY_CAP.");
+
+ CONFIG_ADD_GROUP(ENERGY_SHARING_GROUP, "Energy Sharing Settings");
+ CONFIG_ADD_VAR(ENERGY_SHARING_METHOD, int, 0, "Method for sharing energy. 0=receiver must actively receive, 1=energy pushed on receiver");
+ CONFIG_ADD_VAR(ENERGY_SHARING_LOSS, double, 0.0, "Percent of shared energy lost in transfer");
+
CONFIG_ADD_GROUP(SECOND_PASS_GROUP, "Tracking metrics known after the running experiment previously");
CONFIG_ADD_VAR(TRACK_CCLADES, int, 0, "Enable tracking of coalescence clades");
CONFIG_ADD_VAR(TRACK_CCLADES_IDS, cString, "coalescence.ids", "File storing coalescence IDs");
Modified: branches/collect/source/main/cDeme.cc
===================================================================
--- branches/collect/source/main/cDeme.cc 2008-10-30 19:24:03 UTC (rev 2897)
+++ branches/collect/source/main/cDeme.cc 2008-10-30 20:25:54 UTC (rev 2898)
@@ -266,7 +266,11 @@
eventKillAttempts = 0;
eventKillAttemptsThisSlot = 0;
sleeping_count = 0;
-
+ MSG_sendFailed = 0;
+ MSG_dropped = 0;
+ MSG_SuccessfullySent = 0;
+ MSG_sent = 0;
+
consecutiveSuccessfulEventPeriods = 0;
cur_task_exe_count.SetAll(0);
@@ -795,3 +799,62 @@
// assert(false); // slots must be of equal size and fit perfectally in deme lifetime
return 0;
}
+
+/* Place the absolute IDs of all cells surrounding the given cell id within the given radius into vector cells */
+void cDeme::GetSurroundingCellIds(tVector<int> &cells, const int absolute_cell_id, const int radius) {
+ assert(cell_ids[0] <= absolute_cell_id);
+ assert(absolute_cell_id <= cell_ids[cell_ids.GetSize()-1]);
+ assert(radius >= 0);
+
+ const int relative_cell_id = GetRelativeCellID(absolute_cell_id);
+ const int geometry = m_world->GetConfig().WORLD_GEOMETRY.Get();
+ const int width = GetWidth();
+ const int height = GetHeight();
+ const std::pair<int, int> coords = GetCellPosition(absolute_cell_id);
+ const int curr_x = coords.first;
+ const int curr_y = coords.second;
+ int cid, acid;
+ int x2, y2;
+
+ //Note: this code currently supports a grid or torus
+ assert(geometry == nGeometry::GRID || geometry == nGeometry::TORUS);
+
+ if(geometry == nGeometry::GRID) {
+ for(int y = curr_y - radius; y <= curr_y + radius; y++) {
+ for(int x = curr_x - radius; x <= curr_x + radius; x++) {
+ cid = y * width + x;
+ acid = GetAbsoluteCellID(cid);
+ if(y >= 0 && y < height && x >= 0 && x < width && cid != relative_cell_id) {
+ cells.Add(acid);
+ }
+ }
+ }
+ } //End if world is a grid
+ else if(geometry == nGeometry::TORUS) {
+ for(int y = curr_y - radius; y <= curr_y + radius; y++) {
+ for(int x = curr_x - radius; x <= curr_x + radius; x++) {
+ x2 = x; y2 = y;
+
+ if(x2 < 0) {
+ x2 = x2 + width;
+ } else if(x2 >= width) {
+ x2 = x2 - width;
+ }
+
+ if(y2 < 0) {
+ y2 = y2 + height;
+ } else if(y2 >= height) {
+ y2 = y2 - height;
+ }
+
+ cid = y2 * width + x2;
+ acid = GetAbsoluteCellID(cid);
+
+ if(cid != relative_cell_id) {
+ cells.Add(acid);
+ }
+ }
+ }
+ } //End if world is a torus
+
+} //End GetSurroundingCellIds()
Modified: branches/collect/source/main/cDeme.h
===================================================================
--- branches/collect/source/main/cDeme.h 2008-10-30 19:24:03 UTC (rev 2897)
+++ branches/collect/source/main/cDeme.h 2008-10-30 20:25:54 UTC (rev 2898)
@@ -70,6 +70,10 @@
int gestation_time; // Time used during last generation
double cur_normalized_time_used; // normalized by merit and number of orgs
double last_normalized_time_used;
+ unsigned int MSG_sendFailed;
+ unsigned int MSG_dropped;
+ unsigned int MSG_SuccessfullySent;
+ unsigned int MSG_sent;
double total_energy_testament; //! total amount of energy from suicide organisms for offspring deme
int eventsTotal;
unsigned int eventsKilled;
@@ -121,7 +125,8 @@
public:
cDeme() : _id(0), width(0), cur_birth_count(0), last_birth_count(0), cur_org_count(0), last_org_count(0), injected_count(0), birth_count_perslot(0),
_age(0), generation(0), total_org_energy(0.0),
- time_used(0), gestation_time(0), cur_normalized_time_used(0.0), last_normalized_time_used(0.0), total_energy_testament(0.0),
+ time_used(0), gestation_time(0), cur_normalized_time_used(0.0), last_normalized_time_used(0.0),
+ MSG_sendFailed(0), MSG_dropped(0), MSG_SuccessfullySent(0), MSG_sent(0), total_energy_testament(0.0),
eventsTotal(0), eventsKilled(0), eventsKilledThisSlot(0), eventKillAttempts(0), eventKillAttemptsThisSlot(0),
consecutiveSuccessfulEventPeriods(0), sleeping_count(0),
avg_founder_generation(0.0), generations_per_lifetime(0.0),
@@ -233,7 +238,8 @@
void UpdateDemeRes() { deme_resource_count.GetResources(); }
void Update(double time_step) { deme_resource_count.Update(time_step); }
int GetRelativeCellID(int absolute_cell_id) const { return absolute_cell_id % GetSize(); } //!< assumes all demes are the same size
-
+ int GetAbsoluteCellID(int relative_cell_id) const { return relative_cell_id + (_id * GetSize()); } //!< assumes all demes are the same size
+
void SetCellEventGradient(int x1, int y1, int x2, int y2, int delay, int duration, bool static_pos, int time_to_live);
int GetNumEvents();
void SetCellEvent(int x1, int y1, int x2, int y2, int delay, int duration, bool static_position, int total_events);
@@ -283,9 +289,22 @@
void AddEventMoveBetweenTargetsPred(int times);
void AddEventMigrateToTargetsPred(int times);
void AddEventEventNUniqueIndividualsMovedIntoTargetPred(int times);
+
+ // --- Messaging stats --- //
+ void IncMessageSent() { ++MSG_sent; }
+ void MessageSuccessfullySent() { ++MSG_SuccessfullySent; }
+ void messageDropped() { ++MSG_dropped; }
+ void messageSendFailed() { ++MSG_sendFailed; }
+ unsigned int GetMessagesSent() { return MSG_sent; }
+ unsigned int GetMessageSuccessfullySent() { return MSG_SuccessfullySent; }
+ unsigned int GetMessageDropped() { return MSG_dropped; }
+ unsigned int GetMessageSendFailed() { return MSG_sendFailed; }
+
// --- Pheromones --- //
void AddPheromone(int absolute_cell_id, double value);
+
+ void GetSurroundingCellIds(tVector<int> &cells, const int absolute_cell_id, const int radius);
};
#endif
Modified: branches/collect/source/main/cOrgInterface.h
===================================================================
--- branches/collect/source/main/cOrgInterface.h 2008-10-30 19:24:03 UTC (rev 2897)
+++ branches/collect/source/main/cOrgInterface.h 2008-10-30 20:25:54 UTC (rev 2898)
@@ -98,6 +98,7 @@
virtual bool UpdateMerit(double new_merit) = 0;
virtual bool TestOnDivide() = 0;
virtual bool SendMessage(cOrgMessage& msg) = 0;
+ virtual bool BroadcastMessage(cOrgMessage& msg) = 0;
virtual bool BcastAlarm(int jump_jabel, int bcast_range) = 0;
virtual void DivideOrgTestamentAmongDeme(double value) = 0;
virtual void SendFlash() = 0;
Modified: branches/collect/source/main/cOrganism.cc
===================================================================
--- branches/collect/source/main/cOrganism.cc 2008-10-30 19:24:03 UTC (rev 2897)
+++ branches/collect/source/main/cOrganism.cc 2008-10-30 20:25:54 UTC (rev 2898)
@@ -708,12 +708,14 @@
assert(m_interface);
InitMessaging();
+ m_interface->GetDeme()->IncMessageSent();
// If we're able to succesfully send the message...
if(m_interface->SendMessage(msg)) {
// save it...
m_msg->sent.push_back(msg);
// stat-tracking...
m_world->GetStats().SentMessage(msg);
+ m_interface->GetDeme()->MessageSuccessfullySent();
// check to see if we've performed any tasks...
DoOutput(ctx);
// and set the receiver-pointer of this message to NULL. We don't want to
@@ -721,11 +723,36 @@
m_msg->sent.back().SetReceiver(0);
return true;
}
-
+ m_interface->GetDeme()->messageSendFailed();
return false;
}
+// Broadcast a message - slightly modified version of SendMessage
+bool cOrganism::BroadcastMessage(cAvidaContext& ctx, cOrgMessage& msg)
+{
+ assert(m_interface);
+ InitMessaging();
+
+ // If we're able to succesfully send the message...
+ if(m_interface->BroadcastMessage(msg)) {
+ // save it...
+ m_msg->sent.push_back(msg);
+ // and set the receiver-pointer of this message to NULL. We don't want to
+ // walk this list later thinking that the receivers are still around.
+ // Also, a broadcast message may have >1 receiver
+ m_msg->sent.back().SetReceiver(0);
+ // stat-tracking... NOTE: this has receiver not specified, so may be a problem for predicates
+ m_world->GetStats().SentMessage(msg);
+ // check to see if we've performed any tasks...NOTE: this has receiver not specified, so may be a problem for tasks that care
+ DoOutput(ctx);
+ return true;
+ }
+
+ return false;
+} //End BroadcastMessage()
+
+
void cOrganism::ReceiveMessage(cOrgMessage& msg)
{
InitMessaging();
@@ -745,7 +772,7 @@
return 0;
}
-// Brian Movement
+
void cOrganism::Move(cAvidaContext& ctx)
{
assert(m_interface);
Modified: branches/collect/source/main/cOrganism.h
===================================================================
--- branches/collect/source/main/cOrganism.h 2008-10-30 19:24:03 UTC (rev 2897)
+++ branches/collect/source/main/cOrganism.h 2008-10-30 20:25:54 UTC (rev 2898)
@@ -353,6 +353,7 @@
//! Called when this organism attempts to send a message.
bool SendMessage(cAvidaContext& ctx, cOrgMessage& msg);
+ bool BroadcastMessage(cAvidaContext& ctx, cOrgMessage& msg);
//! Called when this organism has been sent a message.
void ReceiveMessage(cOrgMessage& msg);
//! Called when this organism attempts to move a received message into its CPU.
Modified: branches/collect/source/main/cPhenotype.cc
===================================================================
--- branches/collect/source/main/cPhenotype.cc 2008-10-30 19:24:03 UTC (rev 2897)
+++ branches/collect/source/main/cPhenotype.cc 2008-10-30 20:25:54 UTC (rev 2898)
@@ -96,6 +96,7 @@
energy_store = in_phen.energy_store;
energy_tobe_applied = in_phen.energy_tobe_applied;
energy_testament = in_phen.energy_testament;
+ energy_received_buffer = in_phen.energy_received_buffer;
genome_length = in_phen.genome_length;
bonus_instruction_count = in_phen.bonus_instruction_count;
copied_size = in_phen.copied_size;
@@ -158,6 +159,8 @@
last_sense_count = in_phen.last_sense_count;
last_fitness = in_phen.last_fitness;
last_child_germline_propensity = in_phen.last_child_germline_propensity;
+ total_energy_donated = in_phen.total_energy_donated;
+ total_energy_received = in_phen.total_energy_received;
// 4. Records from this organisms life...
num_divides = in_phen.num_divides;
@@ -218,6 +221,12 @@
parent_true = in_phen.parent_true;
parent_sex = in_phen.parent_sex;
parent_cross_num = in_phen.parent_cross_num;
+
+ is_energy_donor = in_phen.is_energy_donor;
+ is_energy_receiver = in_phen.is_energy_receiver;
+ has_used_donated_energy = in_phen.has_used_donated_energy;
+ total_energy_donated = in_phen.total_energy_donated;
+ total_energy_received = in_phen.total_energy_received;
// 6. Child information...
copy_true = in_phen.copy_true;
@@ -256,6 +265,7 @@
assert(time_used >= 0);
assert(age >= 0);
assert(child_copied_size >= 0);
+ assert(energy_received_buffer >= 0);
// assert(to_die == false);
return (m_world);
}
@@ -283,6 +293,7 @@
energy_store = min(energy_store, (double) m_world->GetConfig().ENERGY_CAP.Get());
energy_tobe_applied = 0.0;
energy_testament = 0.0;
+ energy_received_buffer = 0.0;
genome_length = _genome.GetSize();
copied_size = parent_phenotype.child_copied_size;
executed_size = parent_phenotype.executed_size;
@@ -406,6 +417,12 @@
to_die = false;
to_delete = false;
+ is_energy_donor = false;
+ is_energy_receiver = false;
+ has_used_donated_energy = false;
+ total_energy_donated = 0.0;
+ total_energy_received = 0.0;
+
// Setup child info...
copy_true = false;
divide_sex = false;
@@ -441,6 +458,7 @@
energy_store = min(m_world->GetConfig().ENERGY_GIVEN_ON_INJECT.Get(), m_world->GetConfig().ENERGY_CAP.Get());
energy_tobe_applied = 0.0;
energy_testament = 0.0;
+ energy_received_buffer = 0.0;
executionRatio = 1.0;
gestation_time = 0;
gestation_start = 0;
@@ -551,6 +569,12 @@
parent_cross_num = 0;
to_die = false;
to_delete = false;
+
+ is_energy_donor = false;
+ is_energy_receiver = false;
+ has_used_donated_energy = false;
+ total_energy_donated = 0.0;
+ total_energy_received = 0.0;
// Setup child info...
copy_true = false;
@@ -590,7 +614,7 @@
SetEnergy(energy_store + cur_energy_bonus);
m_world->GetStats().SumEnergyTestamentAcceptedByOrganisms().Add(energy_testament);
energy_testament = 0.0;
-
+ energy_received_buffer = 0.0; // If donated energy not applied, it's lost here
genome_length = _genome.GetSize();
(void) copied_size; // Unchanged
@@ -881,6 +905,7 @@
energy_store = clone_phenotype.energy_store;
energy_tobe_applied = 0.0;
energy_testament = 0.0;
+ energy_received_buffer = 0.0;
if(m_world->GetConfig().INHERIT_EXE_RATE.Get() == 0)
executionRatio = 1.0;
@@ -1003,6 +1028,9 @@
parent_cross_num = clone_phenotype.cross_num;
to_die = false;
to_delete = false;
+ is_energy_donor = false;
+ is_energy_receiver = false;
+ has_used_donated_energy = false;
// Setup child info...
copy_true = false;
@@ -1327,6 +1355,20 @@
energy_testament += value;
} //! external energy given to organism
+
+void cPhenotype::ApplyDonatedEnergy() {
+ SetEnergy(energy_store + energy_received_buffer);
+ energy_received_buffer = 0.0;
+} //End AppplyDonatedEnergy()
+
+
+void cPhenotype::ReceiveDonatedEnergy(const double donation) {
+ assert(donation >= 0.0);
+ energy_received_buffer += donation;
+ is_energy_receiver = true;
+} //End ReceiveDonatedEnergy()
+
+
double cPhenotype::ExtractParentEnergy() {
assert(m_world->GetConfig().ENERGY_ENABLED.Get() > 0);
// energy model config variables
@@ -1492,6 +1534,8 @@
is_receiver_threshgb = false;
is_receiver_quanta_threshgb_last = is_receiver_quanta_threshgb;
is_receiver_quanta_threshgb = false;
+ is_energy_donor = false;
+ is_energy_receiver = false;
(void) is_modifier;
(void) is_modified;
(void) is_fertile;
@@ -1607,3 +1651,28 @@
return false;
}
+
+// Return an integer classifying the organism's energy level as -1=error,0=low,1=med,2=high
+int cPhenotype::GetDiscreteEnergyLevel() const {
+ double max_energy = m_world->GetConfig().ENERGY_CAP.Get();
+ double high_pct = m_world->GetConfig().ENERGY_THRESH_HIGH.Get();
+ double low_pct = m_world->GetConfig().ENERGY_THRESH_LOW.Get();
+
+ assert(max_energy >= 0);
+ assert(high_pct <= 1);
+ assert(high_pct >= 0);
+ assert(low_pct <= 1);
+ assert(low_pct >= 0);
+ assert(low_pct <= high_pct);
+
+ if (energy_store < (low_pct * max_energy)) {
+ return ENERGY_LEVEL_LOW;
+ } else if ( (energy_store >= (low_pct * max_energy)) && (energy_store <= (high_pct * max_energy)) ) {
+ return ENERGY_LEVEL_MEDIUM;
+ } else if (energy_store > (high_pct * max_energy)) {
+ return ENERGY_LEVEL_HIGH;
+ } else {
+ return -1;
+ }
+
+} //End GetDiscreteEnergyLevel()
Modified: branches/collect/source/main/cPhenotype.h
===================================================================
--- branches/collect/source/main/cPhenotype.h 2008-10-30 19:24:03 UTC (rev 2897)
+++ branches/collect/source/main/cPhenotype.h 2008-10-30 20:25:54 UTC (rev 2898)
@@ -110,6 +110,9 @@
double cur_energy_bonus; // Current energy bonus
double energy_tobe_applied; // Energy that has not yet been added to energy store.
double energy_testament;
+ double energy_received_buffer; // Energy received through donation, but not yet applied to energy store
+ double total_energy_donated; // Tota amount of energy that has been donated
+ double total_energy_received; // Total amount of energy received through donations
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
@@ -188,6 +191,9 @@
bool is_donor_threshgb_last;// Did this org's parent threshgbg_donate?
bool is_donor_quanta_threshgb; // Has this organism quanta_threshgb_donated (true green beard)?
bool is_donor_quanta_threshgb_last;// Did this org's parent quanta_threshgbg_donate?
+ bool is_energy_donor; // Has this organism donated energy?
+ bool is_energy_receiver; // Has this organism received an energy donation?
+ bool has_used_donated_energy; // Has the organism actively used an energy donation?
int num_thresh_gb_donations; // Num times this organism threshgb_donated (thresh green beard)?
int num_thresh_gb_donations_last; // Num times this org's parent thresh_donated?
int num_quanta_thresh_gb_donations; // Num times this organism threshgb_donated (thresh green beard)?
@@ -241,7 +247,8 @@
cPhenotype& operator=(const cPhenotype&);
~cPhenotype();
-
+ enum energy_levels {ENERGY_LEVEL_LOW = 0, ENERGY_LEVEL_MEDIUM, ENERGY_LEVEL_HIGH};
+
bool OK();
// Run when being setup *as* and offspring.
@@ -303,6 +310,8 @@
double GetCurMeritBase() const { assert(initialized == true); return CalcSizeMerit(); }
double GetStoredEnergy() const { return energy_store; }
double GetEnergyBonus() const { assert(initialized == true); return cur_energy_bonus; }
+ int GetDiscreteEnergyLevel() const;
+ double GetEnergyInBufferAmount() const { return energy_received_buffer; }
bool GetToDie() const { assert(initialized == true); return to_die; }
bool GetToDelete() const { assert(initialized == true); return to_delete; }
@@ -379,6 +388,9 @@
bool IsDonorThreshGbLast() const { assert(initialized == true); return is_donor_threshgb_last; }
bool IsDonorQuantaThreshGb() const { assert(initialized == true); return is_donor_quanta_threshgb; }
bool IsDonorQuantaThreshGbLast() const { assert(initialized == true); return is_donor_quanta_threshgb_last; }
+ bool IsEnergyDonor() const { assert(initialized == true); return is_energy_donor; }
+ bool IsEnergyReceiver() const { assert(initialized == true); return is_energy_receiver; }
+ bool HasUsedEnergyDonation() const { assert(initialized == true); return has_used_donated_energy; }
bool IsReceiver() const { assert(initialized == true); return is_receiver; }
bool IsReceiverLast() const { assert(initialized == true); return is_receiver_last; }
bool IsReceiverRand() const { assert(initialized == true); return is_receiver_rand; }
@@ -431,6 +443,8 @@
void SetCrossNum(int _cross_num) { cross_num = _cross_num; }
void SetToDie() { to_die = true; }
void SetToDelete() { to_delete = true; }
+ void IncreaseEnergyDonated(double amount) { assert(amount >=0); total_energy_donated += amount; }
+ void IncreaseEnergyReceived(double amount) { assert(amount >=0); total_energy_received += amount; }
void SetCurRBinsAvail(const tArray<double>& in_avail) { cur_rbins_avail = in_avail; }
void SetCurRbinsTotal(const tArray<double>& in_total) { cur_rbins_total = in_total; }
@@ -456,6 +470,9 @@
void SetIsReceiverTrueGb() { SetIsReceiver(); is_receiver_truegb = true; }
void SetIsReceiverThreshGb() { SetIsReceiver(); is_receiver_threshgb = true; }
void SetIsReceiverQuantaThreshGb() { SetIsReceiver(); is_receiver_quanta_threshgb = true; }
+ void SetIsEnergyDonor() { is_energy_donor = true; }
+ void SetIsEnergyReceiver() { is_energy_receiver = true; }
+ void SetHasUsedDonatedEnergy() {has_used_donated_energy = true; }
void SetCurBonus(double _bonus) { cur_bonus = _bonus; }
void SetCurBonusInstCount(int _num_bonus_inst) {bonus_instruction_count = _num_bonus_inst;}
@@ -496,6 +513,8 @@
void RefreshEnergy();
void ApplyToEnergyStore();
void EnergyTestament(const double value); //! external energy given to organism
+ void ApplyDonatedEnergy();
+ void ReceiveDonatedEnergy(const double value);
double ExtractParentEnergy();
bool operator<(const cPhenotype& rhs) const;
Modified: branches/collect/source/main/cPopulationInterface.cc
===================================================================
--- branches/collect/source/main/cPopulationInterface.cc 2008-10-30 19:24:03 UTC (rev 2897)
+++ branches/collect/source/main/cPopulationInterface.cc 2008-10-30 20:25:54 UTC (rev 2898)
@@ -261,6 +261,12 @@
/*! Send a message to the faced organism, failing if this cell does not have
neighbors or if the cell currently faced is not occupied. */
bool cPopulationInterface::SendMessage(cOrgMessage& msg) {
+ static const double drop_prob = m_world->GetConfig().NET_DROP_PROB.Get();
+ if (drop_prob > 0.0 && m_world->GetRandom().P(drop_prob)) {
+ GetDeme()->messageDropped();
+ return false; // message dropped
+ }
+
cPopulationCell& cell = m_world->GetPopulation().GetCell(m_cell_id);
assert(cell.IsOccupied()); // This organism; sanity.
cPopulationCell* rcell = cell.ConnectionList().GetFirst();
@@ -275,7 +281,42 @@
return true;
}
+/* Send a message to the given organism */
+bool cPopulationInterface::SendMessage(cOrganism* recvr, cOrgMessage& msg) {
+ assert(recvr != NULL);
+ recvr->ReceiveMessage(msg);
+ return true;
+} //End SendMessage()
+
+// Broadcast the message to all living organisms within range
+bool cPopulationInterface::BroadcastMessage(cOrgMessage& msg) {
+ bool all_sent = true;
+ const int bcast_range = m_world->GetConfig().MESSAGE_BCAST_RADIUS.Get();
+ assert(bcast_range >= 0);
+ tVector<int> neighbors;
+ neighbors.Clear();
+
+ cDeme& deme = m_world->GetPopulation().GetDeme(GetDemeID());
+ deme.GetSurroundingCellIds(neighbors, GetCellID(), bcast_range);
+
+ for(int i = 0; i < neighbors.Size(); i++) {
+ cPopulationCell& rcell = m_world->GetPopulation().GetCell(neighbors[i]);
+ if(rcell.IsOccupied()) {
+ cOrganism* neighbor = rcell.GetOrganism();
+ assert(neighbor != NULL);
+
+ if(!SendMessage(neighbor, msg)) {
+ all_sent = false;
+ }
+ }
+ }
+
+ return all_sent;
+
+} //End BroadcastMessage
+
+
bool cPopulationInterface::BcastAlarm(int jump_label, int bcast_range) {
bool successfully_sent(false);
cPopulationCell& scell = m_world->GetPopulation().GetCell(m_cell_id);
Modified: branches/collect/source/main/cPopulationInterface.h
===================================================================
--- branches/collect/source/main/cPopulationInterface.h 2008-10-30 19:24:03 UTC (rev 2897)
+++ branches/collect/source/main/cPopulationInterface.h 2008-10-30 20:25:54 UTC (rev 2898)
@@ -105,6 +105,8 @@
bool TestOnDivide();
//! Send a message to the faced organism.
bool SendMessage(cOrgMessage& msg);
+ bool SendMessage(cOrganism* recvr, cOrgMessage& msg);
+ bool BroadcastMessage(cOrgMessage& msg);
bool BcastAlarm(int jump_label, int bcast_range);
void DivideOrgTestamentAmongDeme(double value);
//! Send a flash to all neighboring organisms.
Modified: branches/collect/source/main/cStats.cc
===================================================================
--- branches/collect/source/main/cStats.cc 2008-10-30 19:24:03 UTC (rev 2897)
+++ branches/collect/source/main/cStats.cc 2008-10-30 20:25:54 UTC (rev 2898)
@@ -827,6 +827,35 @@
df.Endl();
}
+void cStats::PrintMessageData(const cString& filename) {
+ cDataFile& df = m_world->GetDataFile(filename);
+
+ df.WriteComment( "Number of organsism to organisms messages\n" );
+
+ df.Write( GetUpdate(), "update" );
+
+ cPopulation& pop = m_world->GetPopulation();
+ int numDemes = pop.GetNumDemes();
+
+ unsigned int totalMessagesSent(0);
+ unsigned int totalMessagesSuccessfullySent(0);
+ unsigned int totalMessagesDropped(0);
+ unsigned int totalMessagesFailed(0);
+
+ for( int i=0; i < numDemes; i++ ){
+ totalMessagesSent += pop.GetDeme(i).GetMessagesSent();
+ totalMessagesSuccessfullySent += pop.GetDeme(i).GetMessageSuccessfullySent();
+ totalMessagesDropped += pop.GetDeme(i).GetMessageDropped();
+ totalMessagesFailed += pop.GetDeme(i).GetMessageSendFailed();
+ }
+
+ df.Write(totalMessagesSent, "Totlal messages sent");
+ df.Write(totalMessagesSuccessfullySent, "Sent successfully");
+ df.Write(totalMessagesDropped, "Dropped");
+ df.Write(totalMessagesFailed, "Failed");
+
+ df.Endl();
+}
void cStats::PrintTotalsData(const cString& filename)
{
Modified: branches/collect/source/main/cStats.h
===================================================================
--- branches/collect/source/main/cStats.h 2008-10-30 19:24:03 UTC (rev 2897)
+++ branches/collect/source/main/cStats.h 2008-10-30 20:25:54 UTC (rev 2898)
@@ -751,6 +751,7 @@
void PrintParasiteData(const cString& filename);
void PrintStatsData(const cString& filename);
void PrintCountData(const cString& filename);
+ void PrintMessageData(const cString& filename);
void PrintTotalsData(const cString& filename);
void PrintTasksData(const cString& filename);
void PrintTasksExeData(const cString& filename);
Modified: branches/collect/source/script/ASAnalyzeLib.cc
===================================================================
--- branches/collect/source/script/ASAnalyzeLib.cc 2008-10-30 19:24:03 UTC (rev 2897)
+++ branches/collect/source/script/ASAnalyzeLib.cc 2008-10-30 20:25:54 UTC (rev 2898)
@@ -36,10 +36,14 @@
#include "cDriverStatusConduit.h"
#include "cGenome.h"
#include "cGenomeUtil.h"
+#include "cGenotypeBatch.h"
#include "cHardwareManager.h"
+#include "cInitFile.h"
#include "cWorld.h"
+#include "tDataEntryCommand.h"
+
class cWorld;
@@ -85,7 +89,71 @@
return new cAnalyzeGenotype(world, seq, world->GetHardwareManager().GetInstSet());
}
+ cGenotypeBatch* LoadBatchWithInstSet(cWorld* world, const cString& filename, cInstSet* inst_set)
+ {
+ cDriverStatusConduit& conduit = cDriverManager::Status();
+ conduit.NotifyComment(cString("Loading: ") + filename);
+
+ cInitFile input_file(filename);
+ if (!input_file.WasOpened()) {
+ tConstListIterator<cString> err_it(input_file.GetErrors());
+ const cString* errstr = NULL;
+ while ((errstr = err_it.Next())) conduit.SignalError(*errstr);
+ cString failstr(cStringUtil::Stringf("unable to load file: %s", *filename));
+ conduit.SignalError(failstr, 1);
+ }
+
+ const cString filetype = input_file.GetFiletype();
+ if (filetype != "genotype_data") {
+ conduit.SignalError(cStringUtil::Stringf("unable to load files of type '%s'", *filetype), 1);;
+ }
+
+ if (world->GetVerbosity() >= VERBOSE_ON) {
+ conduit.NotifyComment(cStringUtil::Stringf("Loading file of type: %s", *filetype));
+ }
+
+
+ // Construct a linked list of data types that can be loaded...
+ tList< tDataEntryCommand<cAnalyzeGenotype> > output_list;
+ tListIterator< tDataEntryCommand<cAnalyzeGenotype> > output_it(output_list);
+ cAnalyzeGenotype::LoadDataCommandList(world, input_file.GetFormat(), output_list);
+ bool id_inc = input_file.GetFormat().HasString("id");
+
+ // Setup the genome...
+ cGenome default_genome(1);
+ int load_count = 0;
+ cGenotypeBatch* batch = new cGenotypeBatch;
+
+ for (int line_id = 0; line_id < input_file.GetNumLines(); line_id++) {
+ cString cur_line = input_file.GetLine(line_id);
+
+ cAnalyzeGenotype* genotype = new cAnalyzeGenotype(world, default_genome, *inst_set);
+
+ output_it.Reset();
+ tDataEntryCommand<cAnalyzeGenotype>* data_command = NULL;
+ while ((data_command = output_it.Next())) data_command->SetValue(genotype, cur_line.PopWord());
+
+ // Give this genotype a name. Base it on the ID if possible.
+ if (id_inc == false) genotype->SetName(cStringUtil::Stringf("org-%d", load_count++));
+ else genotype->SetName(cStringUtil::Stringf("org-%d", genotype->GetID()));
+
+ // Add this genotype to the proper batch.
+ batch->List().PushRear(genotype);
+ }
+
+ // Adjust the flags on this batch
+ batch->SetLineage(false);
+ batch->SetAligned(false);
+
+ return batch;
+ }
+ cGenotypeBatch* LoadBatch(cWorld* world, const cString& filename)
+ {
+ return LoadBatchWithInstSet(world, filename, &world->GetHardwareManager().GetInstSet());
+ }
+
+
};
Modified: branches/collect/source/tools/cDataFile.cc
===================================================================
--- branches/collect/source/tools/cDataFile.cc 2008-10-30 19:24:03 UTC (rev 2897)
+++ branches/collect/source/tools/cDataFile.cc 2008-10-30 20:25:54 UTC (rev 2898)
@@ -70,7 +70,16 @@
m_fp << i << " ";
}
+void cDataFile::Write(unsigned int i, const char* descr)
+{
+ if (!m_descr_written) {
+ m_data += cStringUtil::Stringf("%u ", i);
+ WriteColumnDesc(descr);
+ } else
+ m_fp << i << " ";
+}
+
void cDataFile::Write(const char* data_str, const char* descr)
{
if (!m_descr_written) {
Modified: branches/collect/source/tools/cDataFile.h
===================================================================
--- branches/collect/source/tools/cDataFile.h 2008-10-30 19:24:03 UTC (rev 2897)
+++ branches/collect/source/tools/cDataFile.h 2008-10-30 20:25:54 UTC (rev 2898)
@@ -108,6 +108,7 @@
void Write(double x, const char* descr);
void Write(int i, const char* descr);
void Write(long i, const char* descr);
+ void Write(unsigned int i, const char* descr);
void Write(const char* data_str, const char* descr);
inline void WriteAnonymous(double x) { m_fp << x << " "; }
inline void WriteAnonymous(int i) { m_fp << i << " "; }
Modified: branches/collect/source/tools/cFlexVar.h
===================================================================
--- branches/collect/source/tools/cFlexVar.h 2008-10-30 19:24:03 UTC (rev 2897)
+++ branches/collect/source/tools/cFlexVar.h 2008-10-30 20:25:54 UTC (rev 2898)
@@ -228,6 +228,8 @@
double AsDouble() const { return m_var->AsDouble(); }
cString AsString() const { return m_var->AsString(); }
void SetString(cString & in_str) const { m_var->SetString(in_str); }
+
+ template<class Type> Type As() const;
// Setup a way to convert the native types
int MakeInt() { int val = AsInt(); delete m_var; m_var = new cFlexVar_Int(val); return val; }
@@ -273,6 +275,12 @@
};
+template<> inline int cFlexVar::As<int>() const { return m_var->AsInt(); }
+template<> inline char cFlexVar::As<char>() const { return m_var->AsChar(); }
+template<> inline double cFlexVar::As<double>() const { return m_var->AsDouble(); }
+template<> inline cString cFlexVar::As<cString>() const { return m_var->AsString(); }
+
+
inline std::ostream& operator << (std::ostream& out, const cFlexVar & entry)
{
entry.Print(out);
Modified: branches/collect/source/tools/cStringList.h
===================================================================
--- branches/collect/source/tools/cStringList.h 2008-10-30 19:24:03 UTC (rev 2897)
+++ branches/collect/source/tools/cStringList.h 2008-10-30 20:25:54 UTC (rev 2898)
@@ -48,7 +48,7 @@
private:
tList<cString> string_list;
- inline cString ReturnString(cString * out_string)
+ inline cString ReturnString(cString* out_string)
{
cString tmp_string(*out_string);
delete out_string;
@@ -65,15 +65,15 @@
int GetSize() const { return string_list.GetSize(); }
cString GetLine(int line_num) const { return *(string_list.GetPos(line_num)); }
- const tList<cString> & GetList() const { return string_list; }
+ const tList<cString>& GetList() const { return string_list; }
- bool HasString(const cString & test_string) const;
- cString PopString(const cString & test_string);
+ bool HasString(const cString& test_string) const;
+ cString PopString(const cString& test_string);
cString PopLine(int);
int LocateString(const cString& test_string) const;
- void Push(const cString & _in) { string_list.Push(new cString(_in));}
- void PushRear(const cString & _in) { string_list.PushRear(new cString(_in));}
+ void Push(const cString& _in) { string_list.Push(new cString(_in));}
+ void PushRear(const cString& _in) { string_list.PushRear(new cString(_in));}
cString Pop() { return ReturnString(string_list.Pop()); }
cString PopRear() { return ReturnString(string_list.PopRear()); }
Modified: branches/collect/source/tools/tDataEntry.h
===================================================================
--- branches/collect/source/tools/tDataEntry.h 2008-10-30 19:24:03 UTC (rev 2897)
+++ branches/collect/source/tools/tDataEntry.h 2008-10-30 20:25:54 UTC (rev 2898)
@@ -31,15 +31,17 @@
#ifndef cFlexVar_h
#include "cFlexVar.h"
#endif
-
#ifndef cString_h
#include "cString.h"
#endif
-
+#ifndef cStringList_h
+#include "cStringList.h"
+#endif
#ifndef cStringUtil_h
#include "cStringUtil.h"
#endif
+
template <class TargetType> class tDataEntry
{
private:
@@ -48,6 +50,7 @@
int m_compare_type; // ID to indicate how values should be compared.
cString m_null_value; // Value when "off", such as "0", "Inf.", or "N/A"
cString m_html_table_flags; // String to include in <td> entry in html mode.
+ cStringList m_default_args;
public:
tDataEntry(const cString& name, const cString& desc, int compare_type = 0,
@@ -56,17 +59,20 @@
virtual ~tDataEntry() { ; }
const cString& GetName() const { return m_name; }
- const cString& GetDesc() const { return m_desc; }
+ virtual cString GetDesc(const TargetType* target, const cFlexVar& idx) const { return m_desc; }
int GetCompareType() const { return m_compare_type; }
const cString& GetNull() const { return m_null_value; }
const cString& GetHtmlCellFlags() const { return m_html_table_flags; }
- virtual bool Set(TargetType* target, const cString& value) const { (void) value; return false; }
- virtual cFlexVar Get(const TargetType* target) const = 0;
+ virtual bool Set(TargetType* target, const cFlexVar&, const cStringList&, const cString&) const { return false; }
+ virtual cFlexVar Get(const TargetType* target, const cFlexVar& idx, const cStringList& args) const = 0;
+ virtual cFlexVar Get(const TargetType* target) const { return Get(target, 0, m_default_args); }
};
+template <class TargetType, class EntryType> class tDataEntryOfType;
-template <class TargetType, class EntryType> class tDataEntryOfType : public tDataEntry<TargetType>
+template <class TargetType, class EntryType>
+ class tDataEntryOfType<TargetType, EntryType ()> : public tDataEntry<TargetType>
{
protected:
EntryType (TargetType::*DataGet)() const;
@@ -78,7 +84,7 @@
int compare_type = 0, const cString& null = "0", const cString& html_cell = "align=center")
: tDataEntry<TargetType>(name, desc, compare_type, null, html_cell), DataGet(_funR), DataSet(_funS) { ; }
- bool Set(TargetType* target, const cString& value) const
+ bool Set(TargetType* target, const cFlexVar&, const cStringList&, const cString& value) const
{
assert(target != NULL);
EntryType new_value(0);
@@ -87,7 +93,7 @@
return true;
}
- cFlexVar Get(const TargetType* target) const
+ cFlexVar Get(const TargetType* target, const cFlexVar&, const cStringList&) const
{
assert(target != NULL);
return cFlexVar((target->*DataGet)());
@@ -95,23 +101,59 @@
};
-template <class TargetType, class EntryType, class ArgType> class tDataEntryWithArg : public tDataEntry<TargetType>
+template <class TargetType, class EntryType, class IdxType>
+ class tDataEntryOfType<TargetType, EntryType (IdxType)> : public tDataEntry<TargetType>
{
protected:
- EntryType (TargetType::*DataRetrieval)(ArgType) const;
- ArgType m_arg;
+ EntryType (TargetType::*DataRetrieval)(IdxType) const;
+ cString (TargetType::*DescFunction)(IdxType) const;
public:
- tDataEntryWithArg(const cString& name, const cString& desc, EntryType (TargetType::*_funR)(ArgType) const, ArgType arg,
- int compare_type = 0, const cString& null = "0", const cString& html_cell = "align=center")
- : tDataEntry<TargetType>(name, desc, compare_type, null, html_cell), DataRetrieval(_funR), m_arg(arg) { ; }
+ tDataEntryOfType(const cString& name,
+ cString (TargetType::*_funD)(IdxType) const,
+ EntryType (TargetType::*_funR)(IdxType) const,
+ int compare_type = 0, const cString& null = "0", const cString& html_cell = "align=center")
+ : tDataEntry<TargetType>(name, name, compare_type, null, html_cell), DataRetrieval(_funR), DescFunction(_funD) { ; }
- cFlexVar Get(const TargetType* target) const
+ cString GetDesc(const TargetType* target, const cFlexVar& idx) const
{
+ return (target->*DescFunction)(idx.As<IdxType>());
+ }
+
+
+ cFlexVar Get(const TargetType* target, const cFlexVar& idx, const cStringList&) const
+ {
assert(target != NULL);
- return cFlexVar((target->*DataRetrieval)(m_arg));
+ return cFlexVar((target->*DataRetrieval)(idx.As<IdxType>()));
}
};
+template <class TargetType, class EntryType, class IdxType>
+ class tDataEntryOfType<TargetType, EntryType (IdxType, const cStringList&)> : public tDataEntry<TargetType>
+{
+protected:
+ EntryType (TargetType::*DataRetrieval)(IdxType, const cStringList&) const;
+ cString (TargetType::*DescFunction)(IdxType) const;
+
+public:
+ tDataEntryOfType(const cString& name,
+ cString (TargetType::*_funD)(IdxType) const,
+ EntryType (TargetType::*_funR)(IdxType, const cStringList&) const,
+ int compare_type = 0, const cString& null = "0", const cString& html_cell = "align=center")
+ : tDataEntry<TargetType>(name, name, compare_type, null, html_cell), DataRetrieval(_funR), DescFunction(_funD) { ; }
+
+ cString GetDesc(const TargetType* target, const cFlexVar& idx) const
+ {
+ return (target->*DescFunction)(idx.As<IdxType>());
+ }
+
+ cFlexVar Get(const TargetType* target, const cFlexVar& idx, const cStringList& args) const
+ {
+ assert(target != NULL);
+ return cFlexVar((target->*DataRetrieval)(idx.As<IdxType>(), args));
+ }
+};
+
+
#endif
Modified: branches/collect/source/tools/tDataEntryCommand.h
===================================================================
--- branches/collect/source/tools/tDataEntryCommand.h 2008-10-30 19:24:03 UTC (rev 2897)
+++ branches/collect/source/tools/tDataEntryCommand.h 2008-10-30 20:25:54 UTC (rev 2898)
@@ -29,7 +29,7 @@
#include <iostream>
#ifndef cFlexVar_h
-#define "cFlexVar.h"
+#include "cFlexVar.h"
#endif
#ifndef cStringList_h
@@ -47,21 +47,23 @@
{
private:
tDataEntry<T>* m_data_entry;
+ cFlexVar m_idx;
cStringList m_args;
+
public:
- tDataEntryCommand(tDataEntry<T>* entry, const cString& args = "") : m_data_entry(entry), m_args(args, ':') { ; }
+ tDataEntryCommand(tDataEntry<T>* entry, const cString& idx = "", const cString& args = "")
+ : m_data_entry(entry), m_idx(idx), m_args(args, ':') { ; }
- const cStringList& GetArgs() const { return m_args; }
bool HasArg(const cString& test_arg) const { return m_args.HasString(test_arg); }
-
+
const cString& GetName() const { return m_data_entry->GetName(); }
- const cString& GetDesc() const { return m_data_entry->GetDesc(); }
+ cString GetDesc(const T* target) const { return m_data_entry->GetDesc(target, m_idx); }
int GetCompareType() const { return m_data_entry->GetCompareType(); }
const cString& GetNull() const { return m_data_entry->GetNull(); }
const cString& GetHtmlCellFlags() const { return m_data_entry->GetHtmlCellFlags(); }
- bool SetValue(T* target, const cString& value) const { return m_data_entry->Set(target, value); }
- cFlexVar GetValue(const T* target) const { return m_data_entry->Get(target); }
+ bool SetValue(T* target, const cString& value) const { return m_data_entry->Set(target, m_idx, m_args, value); }
+ cFlexVar GetValue(const T* target) const { return m_data_entry->Get(target, m_idx, m_args); }
};
#endif
Modified: branches/collect/source/tools/tDataManager.h
===================================================================
--- branches/collect/source/tools/tDataManager.h 2008-10-30 19:24:03 UTC (rev 2897)
+++ branches/collect/source/tools/tDataManager.h 2008-10-30 20:25:54 UTC (rev 2898)
@@ -50,8 +50,8 @@
{
private:
TargetType* m_target;
- tDictionary<tDataEntry<TargetType>*> m_entry_dict;
-
+ tDictionary<tDataEntry<TargetType>*> m_entry_dict;
+
public:
tDataManager(TargetType* target, const cString& filetype = "unknown") : cDataManager_Base(filetype), m_target(target) { ; }
~tDataManager() { ; }
@@ -61,7 +61,7 @@
int compare = 0, const cString& null = "0", const cString& html_cell = "align=center")
{
tDataEntry<TargetType>* new_entry =
- new tDataEntryOfType<TargetType, EntryType>(name, desc, funR, funS, compare, null, html_cell);
+ new tDataEntryOfType<TargetType, EntryType ()>(name, desc, funR, funS, compare, null, html_cell);
m_entry_dict.Add(name, new_entry);
return true;
}
@@ -78,7 +78,7 @@
{
tDataEntry<TargetType>* cur_entry = NULL;
if (m_entry_dict.Find(name, cur_entry) == false) return false;
- out_desc = cur_entry->GetDesc();
+ out_desc = cur_entry->GetDesc(m_target, 0);
return true;
}
More information about the Avida-cvs
mailing list