[Avida-SVN] r2092 - in branches/energy/source: actions main
beckma24 at myxo.css.msu.edu
beckma24 at myxo.css.msu.edu
Fri Sep 14 10:24:12 PDT 2007
Author: beckma24
Date: 2007-09-14 13:24:12 -0400 (Fri, 14 Sep 2007)
New Revision: 2092
Modified:
branches/energy/source/actions/PrintActions.cc
branches/energy/source/main/cDeme.cc
branches/energy/source/main/cDeme.h
branches/energy/source/main/cOrgMessagePredicate.h
branches/energy/source/main/cPopulation.cc
branches/energy/source/main/cPopulation.h
Log:
Added PrintDemeSatPredicate and PrintEventReceivedPred print actions. Also, added hook for PrintMessageData
Modified: branches/energy/source/actions/PrintActions.cc
===================================================================
--- branches/energy/source/actions/PrintActions.cc 2007-09-14 13:54:05 UTC (rev 2091)
+++ branches/energy/source/actions/PrintActions.cc 2007-09-14 17:24:12 UTC (rev 2092)
@@ -109,8 +109,10 @@
void Process(cAvidaContext& ctx) { m_world->GetPopulation().METHOD(m_filename); } /* 12 */ \
} /* 13 */ \
-POP_OUT_FILE(PrintPhenotypeData, phenotype_count.dat );
-POP_OUT_FILE(PrintPhenotypeStatus, phenotype_status.dat);
+POP_OUT_FILE(PrintPhenotypeData, phenotype_count.dat );
+POP_OUT_FILE(PrintPhenotypeStatus, phenotype_status.dat );
+POP_OUT_FILE(PrintDemeSatPredicate, deme_sat_predicate.dat );
+POP_OUT_FILE(PrintEventReceivedPred, pred_event_received.dat );
class cActionPrintData : public cAction
@@ -2630,10 +2632,14 @@
action_lib->Register<cActionPrintSenseData>("PrintSenseData");
action_lib->Register<cActionPrintSenseExeData>("PrintSenseExeData");
action_lib->Register<cActionPrintSleepData>("PrintSleepData");
+ action_lib->Register<cActionPrintMessageData>("PrintMessageData");
+
// Population Out Files
action_lib->Register<cActionPrintPhenotypeData>("PrintPhenotypeData");
action_lib->Register<cActionPrintPhenotypeStatus>("PrintPhenotypeStatus");
+ action_lib->Register<cActionPrintDemeSatPredicate>("PrintDemeSatPredicate");
+ action_lib->Register<cActionPrintEventReceivedPred>("PrintEventReceivedPred");
// deme output files
action_lib->Register<cActionPrintDemeAllStats>("PrintDemeAllStats");
Modified: branches/energy/source/main/cDeme.cc
===================================================================
--- branches/energy/source/main/cDeme.cc 2007-09-14 13:54:05 UTC (rev 2091)
+++ branches/energy/source/main/cDeme.cc 2007-09-14 17:24:12 UTC (rev 2092)
@@ -183,7 +183,7 @@
bool cDeme::MsgPredSatisfiedPreviously() {
for(int i = 0; i < message_pred_list.GetSize(); i++) {
- if(message_pred_list[i]->previouslySatisfied())
+ if(message_pred_list[i]->PreviouslySatisfied())
return true;
}
return false;
Modified: branches/energy/source/main/cDeme.h
===================================================================
--- branches/energy/source/main/cDeme.h 2007-09-14 13:54:05 UTC (rev 2091)
+++ branches/energy/source/main/cDeme.h 2007-09-14 17:24:12 UTC (rev 2092)
@@ -111,6 +111,10 @@
void SetCellEvent(int x1, int y1, int x2, int y2, int delay, int duration, bool static_pos);
bool MsgPredSatisfiedPreviously();
void AddEventReceivedCenterPred();
+ int GetNumPredicates() { return message_pred_list.GetSize(); }
+ bool PredicatePreviouslySatisfied(int pred_id) { return message_pred_list[pred_id]->PreviouslySatisfied(); }
+ cString GetPredicateName(int pred_id) { return message_pred_list[pred_id]->GetName(); }
+ void PrintPredicate(int pred_id, std::ostream& out) { message_pred_list[pred_id]->Print(out); }
};
#endif
Modified: branches/energy/source/main/cOrgMessagePredicate.h
===================================================================
--- branches/energy/source/main/cOrgMessagePredicate.h 2007-09-14 13:54:05 UTC (rev 2091)
+++ branches/energy/source/main/cOrgMessagePredicate.h 2007-09-14 17:24:12 UTC (rev 2092)
@@ -43,7 +43,8 @@
virtual bool operator()(const cOrgMessage& msg) = 0;
virtual void Print(std::ostream& out) { }
virtual void Reset() { }
- virtual bool previouslySatisfied() = 0;
+ virtual bool PreviouslySatisfied() = 0;
+ virtual cString GetName() = 0;
};
@@ -73,10 +74,14 @@
m_cell_ids.clear();
}
- virtual bool previouslySatisfied() {
+ virtual bool PreviouslySatisfied() {
return false;
}
+ virtual cString GetName() {
+ return "DataEQU";
+ }
+
unsigned int m_data;
std::set<int> m_cell_ids;
};
@@ -100,7 +105,7 @@
return true;
}
- virtual void print(std::ostream& out) {
+ virtual void Print(std::ostream& out) {
// cPopulationCell::t_id_map& ids = cPopulationCell::GetRandomCellIDMap();
// int badMSGs = 0;
//
@@ -127,9 +132,13 @@
m_cell_ids.clear();
}
- virtual bool previouslySatisfied() {
+ virtual bool PreviouslySatisfied() {
return false;
}
+
+ virtual cString GetName() {
+ return "SinkReceiverEQU";
+ }
unsigned int m_data;
std::set<int> m_cell_ids;
@@ -147,27 +156,43 @@
~cOrgMessagePred_EventReceived() { }
virtual bool operator()(const cOrgMessage& msg) {
- if(m_event->IsActive() && m_base_station == msg.GetReceiver()->GetCellID() &&
- ((unsigned int)m_event->GetEventID() == msg.GetData() || (unsigned int)m_event->GetEventID() == msg.GetLabel())) {
- m_event_received = true;
+ if(m_event->IsActive() &&
+ ((unsigned int)m_event->GetEventID() == msg.GetData() ||
+ (unsigned int)m_event->GetEventID() == msg.GetLabel())) {
+ m_cell_ids.insert(msg.GetSender()->GetCellID());
+ if(m_base_station == msg.GetReceiver()->GetCellID()) {
+ m_event_received = true;
+ }
}
return m_event_received;
}
- virtual void print(std::ostream& out) {
+ //need to print update!!!
+ virtual void Print(std::ostream& out) {
+ out << m_event << " [ ";
+ for(std::set<int>::iterator i=m_cell_ids.begin(); i!=m_cell_ids.end(); i++) {
+ out << *i << " ";
+ }
+ out << "]\n";
}
virtual void Reset() {
m_event_received = false;
+ m_cell_ids.clear();
}
- virtual bool previouslySatisfied() {
+ virtual bool PreviouslySatisfied() {
return m_event_received;
}
-
+
+ virtual cString GetName() {
+ return "EventReceived";
+ }
+
int m_base_station;
bool m_event_received;
cDemeCellEvent* m_event;
+ std::set<int> m_cell_ids;
};
#endif
Modified: branches/energy/source/main/cPopulation.cc
===================================================================
--- branches/energy/source/main/cPopulation.cc 2007-09-14 13:54:05 UTC (rev 2091)
+++ branches/energy/source/main/cPopulation.cc 2007-09-14 17:24:12 UTC (rev 2092)
@@ -1773,6 +1773,32 @@
df_resources.Endl();
}
+void cPopulation::PrintDemeSatPredicate(const cString& filename) {
+ int num_predicates = GetDeme(1).GetNumPredicates();
+ tArray<int> predicateTotals(num_predicates);
+ tArray<cString> predicateNames(num_predicates);
+ predicateTotals.SetAll(0);
+
+ for(int i = 0; i < GetNumDemes(); i++) {
+ cDeme& deme = GetDeme(i);
+ for(int j = 0; j < num_predicates; j++) {
+ predicateNames[j] = deme.GetPredicateName(j);
+ if(deme.PredicatePreviouslySatisfied(j)) {
+ predicateTotals[j]++;
+ }
+ }
+ }
+
+ cDataFile& df = m_world->GetDataFile(filename);
+ df.WriteComment("Number of demes satisfying predicates");
+ df.WriteTimeStamp();
+ df.Write(m_world->GetStats().GetUpdate(), "Update");
+ for(int i = 0; i < predicateTotals.GetSize(); i++) {
+ df.Write(predicateTotals[i], predicateNames[i]);
+ }
+ df.Endl();
+}
+
// Write spatial energy data to a file that can easily be read into Matlab
void cPopulation::PrintDemeSpatialEnergyData() const {
int cellID = 0;
@@ -1884,6 +1910,21 @@
df_task.Endl();
}
+// predicate-related stats methods
+void cPopulation::PrintEventReceivedPred(const cString& filename) {
+ cDataFile & df = m_world->GetDataFile(filename);
+ for(int i = 0; i < GetNumDemes(); i++) {
+ cDeme& deme = GetDeme(i);
+ for(int j = 0; j < deme.GetNumPredicates(); j++) {
+ if(deme.GetPredicateName(j) == "EventReceived") {
+ df.GetOFStream() << m_world->GetStats().GetUpdate() << " ";
+ deme.PrintPredicate(j, df.GetOFStream());
+ }
+ }
+ }
+}
+
+
/**
* This function is responsible for adding an organism to a given lineage,
* and setting the organism's lineage label and the lineage pointer.
Modified: branches/energy/source/main/cPopulation.h
===================================================================
--- branches/energy/source/main/cPopulation.h 2007-09-14 13:54:05 UTC (rev 2091)
+++ branches/energy/source/main/cPopulation.h 2007-09-14 17:24:12 UTC (rev 2092)
@@ -196,11 +196,14 @@
void PrintDemeMutationRate();
void PrintDemeReceiver();
void PrintDemeResource();
+ void PrintDemeSatPredicate(const cString& filename);
void PrintDemeSpatialResData(cResourceCount res, const int i, const int deme_id) const;
void PrintDemeSpatialEnergyData() const;
void PrintDemeSpatialSleepData() const;
void PrintDemeTasks();
+ // predicate-related stats methods
+ void PrintEventReceivedPred(const cString& filename);
// Print donation stats
void PrintDonationStats();
More information about the Avida-cvs
mailing list