[Avida-SVN] r2138 - in branches/energy/source: actions cpu main
beckma24 at myxo.css.msu.edu
beckma24 at myxo.css.msu.edu
Fri Oct 12 12:40:21 PDT 2007
Author: beckma24
Date: 2007-10-12 15:40:21 -0400 (Fri, 12 Oct 2007)
New Revision: 2138
Modified:
branches/energy/source/actions/PrintActions.cc
branches/energy/source/cpu/cHardwareCPU.cc
branches/energy/source/cpu/cHardwareCPU.h
branches/energy/source/main/cDeme.cc
branches/energy/source/main/cDeme.h
branches/energy/source/main/cOrganism.cc
branches/energy/source/main/cPopulationInterface.cc
branches/energy/source/main/cStats.cc
branches/energy/source/main/cStats.h
branches/energy/source/main/cTaskLib.cc
branches/energy/source/main/cTaskLib.h
Log:
Added SentEventID task, PrintCurrentTasks print action, and fixed and changed ordering of output to message.dat
Modified: branches/energy/source/actions/PrintActions.cc
===================================================================
--- branches/energy/source/actions/PrintActions.cc 2007-10-11 19:14:59 UTC (rev 2137)
+++ branches/energy/source/actions/PrintActions.cc 2007-10-12 19:40:21 UTC (rev 2138)
@@ -78,6 +78,7 @@
STATS_OUT_FILE(PrintCountData, count.dat );
STATS_OUT_FILE(PrintTotalsData, totals.dat );
STATS_OUT_FILE(PrintTasksData, tasks.dat );
+STATS_OUT_FILE(PrintCurrentTasksData, tasksCURRENT.dat );
STATS_OUT_FILE(PrintTasksExeData, tasks_exe.dat );
STATS_OUT_FILE(PrintTasksQualData, tasks_quality.dat );
STATS_OUT_FILE(PrintResourceData, resource.dat );
@@ -2619,6 +2620,7 @@
action_lib->Register<cActionPrintCountData>("PrintCountData");
action_lib->Register<cActionPrintTotalsData>("PrintTotalsData");
action_lib->Register<cActionPrintTasksData>("PrintTasksData");
+ action_lib->Register<cActionPrintCurrentTasksData>("PrintCurrentTasksData");
action_lib->Register<cActionPrintTasksExeData>("PrintTasksExeData");
action_lib->Register<cActionPrintTasksQualData>("PrintTasksQualData");
action_lib->Register<cActionPrintResourceData>("PrintResourceData");
Modified: branches/energy/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/energy/source/cpu/cHardwareCPU.cc 2007-10-11 19:14:59 UTC (rev 2137)
+++ branches/energy/source/cpu/cHardwareCPU.cc 2007-10-12 19:40:21 UTC (rev 2138)
@@ -374,7 +374,7 @@
// Messaging
tInstLibEntry<tMethod>("send-msg", &cHardwareCPU::Inst_SendMessage),
- tInstLibEntry<tMethod>("send-msg-TX", &cHardwareCPU::Inst_SendMessage_CSMA),
+ tInstLibEntry<tMethod>("send-msg-TX", &cHardwareCPU::Inst_SendMessage_TX),
tInstLibEntry<tMethod>("retrieve-msg", &cHardwareCPU::Inst_RetrieveMessage),
tInstLibEntry<tMethod>("retrieve-msg-RX-complete", &cHardwareCPU::Inst_RetrieveMessage_RXComplete),
tInstLibEntry<tMethod>("carrier-sense", &cHardwareCPU::Inst_CarrierSense),
@@ -4554,7 +4554,7 @@
This method implements a transmission time for sent messages.
The sender and all neighbor cells are blocked from sending until the message transmission is over.
*/
-bool cHardwareCPU::Inst_SendMessage_CSMA(cAvidaContext& ctx) { //carrier sense, multiple access
+bool cHardwareCPU::Inst_SendMessage_TX(cAvidaContext& ctx) { //carrier sense, multiple access
cPopulation& pop = m_world->GetPopulation();
int cell_id = organism->GetCellID();
cPopulationCell& sending_cell = pop.GetCell(cell_id);
@@ -4571,38 +4571,37 @@
const cOrgMessage& last_msg = organism->GetReceivedMessages().back();
last_msg.GetTXComplete(last_msg_update, last_msg_subupdate);
if(!m_world->GetStats().TimeHasPassed(last_msg_update, last_msg_subupdate)) { // if receiving a msg
- //actually receiving a msg ?collision?
+ //actually receiving a msg
m_world->GetStats().IncRadioBusy();
return false;
}
}
}
- } else { // not TX or receiving a msg
- // tell neighbor cell about TX and track
- int oldFacing = sending_cell.GetFacing();
- int currentUpdate = m_world->GetStats().GetUpdate();
- int currentSubupdate = m_world->GetStats().GetSubUpdate();
- for(int i = 0; i < organism->GetNeighborhoodSize(); i++) {
- cPopulationCell* neighbor = sending_cell.ConnectionList().GetPos(i);
- neighbor->InTXRange_until(currentUpdate+1, currentSubupdate);
- }
- int newFacing = sending_cell.GetFacing();
- assert(oldFacing == newFacing);
-
- // send message
- const int label_reg = FindModifiedRegister(REG_BX);
- const int data_reg = FindNextRegister(label_reg);
- cOrgMessage msg = cOrgMessage(organism);
- msg.SetLabel(GetRegister(label_reg));
- msg.SetData(GetRegister(data_reg));
- msg.SetTXComplete(currentUpdate+1, currentSubupdate);
- bool value = organism->SendMessage(ctx, msg);
-
- // pause self
- sending_cell.TX_until(currentUpdate+1, currentSubupdate);
- return value;
}
- return false;
+ // not TX or receiving a msg
+ // tell neighbor cell about TX and track
+ int oldFacing = sending_cell.GetFacing();
+ int currentUpdate = m_world->GetStats().GetUpdate();
+ int currentSubupdate = m_world->GetStats().GetSubUpdate();
+ for(int i = 0; i < organism->GetNeighborhoodSize(); i++) {
+ cPopulationCell* neighbor = sending_cell.ConnectionList().GetPos(i);
+ neighbor->InTXRange_until(currentUpdate+1, currentSubupdate);
+ }
+ int newFacing = sending_cell.GetFacing();
+ assert(oldFacing == newFacing);
+
+ // send message
+ const int label_reg = FindModifiedRegister(REG_BX);
+ const int data_reg = FindNextRegister(label_reg);
+ cOrgMessage msg = cOrgMessage(organism);
+ msg.SetLabel(GetRegister(label_reg));
+ msg.SetData(GetRegister(data_reg));
+ msg.SetTXComplete(currentUpdate+1, currentSubupdate);
+ bool value = organism->SendMessage(ctx, msg);
+
+ // pause self
+ sending_cell.TX_until(currentUpdate+1, currentSubupdate);
+ return value;
}
/*! This method /attempts/ to retrieve a message -- It may not be possible, as in
Modified: branches/energy/source/cpu/cHardwareCPU.h
===================================================================
--- branches/energy/source/cpu/cHardwareCPU.h 2007-10-11 19:14:59 UTC (rev 2137)
+++ branches/energy/source/cpu/cHardwareCPU.h 2007-10-12 19:40:21 UTC (rev 2138)
@@ -564,7 +564,7 @@
//// Messaging ////
bool Inst_SendMessage(cAvidaContext& ctx);
- bool Inst_SendMessage_CSMA(cAvidaContext& ctx);
+ bool Inst_SendMessage_TX(cAvidaContext& ctx);
bool Inst_RetrieveMessage(cAvidaContext& ctx);
bool Inst_RetrieveMessage_RXComplete(cAvidaContext& ctx);
bool Inst_CarrierSense(cAvidaContext& ctx);
Modified: branches/energy/source/main/cDeme.cc
===================================================================
--- branches/energy/source/main/cDeme.cc 2007-10-11 19:14:59 UTC (rev 2137)
+++ branches/energy/source/main/cDeme.cc 2007-10-12 19:40:21 UTC (rev 2138)
@@ -203,6 +203,16 @@
cell_events.Push(demeEvent);
}
+int cDeme::GetNumEvents() {
+ return cell_events.GetSize();
+}
+
+cDemeCellEvent cDeme::GetEvent(int i) {
+ assert(i < cell_events.GetSize());
+ return cell_events[i];
+}
+
+
bool cDeme::MsgPredSatisfiedPreviously() {
for(int i = 0; i < message_pred_list.GetSize(); i++) {
if(message_pred_list[i]->PreviouslySatisfied()) {
Modified: branches/energy/source/main/cDeme.h
===================================================================
--- branches/energy/source/main/cDeme.h 2007-10-11 19:14:59 UTC (rev 2137)
+++ branches/energy/source/main/cDeme.h 2007-10-12 19:40:21 UTC (rev 2138)
@@ -117,6 +117,8 @@
int GetRelativeCellID(int absolute_cell_id) { return absolute_cell_id % GetSize(); } //!< assumes all demes are the same size
void SetCellEvent(int x1, int y1, int x2, int y2, int delay, int duration, bool static_pos);
+ int GetNumEvents();
+ cDemeCellEvent GetEvent(int i);
bool MsgPredSatisfiedPreviously();
void AddEventReceivedCenterPred(int times);
void AddEventReceivedLeftSidePred(int times);
Modified: branches/energy/source/main/cOrganism.cc
===================================================================
--- branches/energy/source/main/cOrganism.cc 2007-10-11 19:14:59 UTC (rev 2137)
+++ branches/energy/source/main/cOrganism.cc 2007-10-12 19:40:21 UTC (rev 2138)
@@ -258,9 +258,9 @@
m_interface->UpdateMerit(newMerit);
}
}
-
+
+ //update global resources
m_interface->UpdateResources(global_res_change);
-
//update deme resources
m_interface->UpdateDemeResources(deme_res_change);
Modified: branches/energy/source/main/cPopulationInterface.cc
===================================================================
--- branches/energy/source/main/cPopulationInterface.cc 2007-10-11 19:14:59 UTC (rev 2137)
+++ branches/energy/source/main/cPopulationInterface.cc 2007-10-12 19:40:21 UTC (rev 2138)
@@ -244,6 +244,8 @@
cPopulationCell* rcell = cell.ConnectionList().GetFirst();
assert(rcell != NULL); // Cells should never be null.
+ m_world->GetStats().IncMsgSent();
+
// Fail if the cell we're facing is not occupied.
if(!rcell->IsOccupied()) {
m_world->GetStats().IncMsgSentNoOne();
Modified: branches/energy/source/main/cStats.cc
===================================================================
--- branches/energy/source/main/cStats.cc 2007-10-11 19:14:59 UTC (rev 2137)
+++ branches/energy/source/main/cStats.cc 2007-10-12 19:40:21 UTC (rev 2138)
@@ -835,6 +835,24 @@
df.Endl();
}
+void cStats::PrintCurrentTasksData(const cString& filename)
+{
+ cString file = filename;
+
+ // print tasksCurrent.dat
+ cDataFile& df = m_world->GetDataFile(file);
+ df.WriteComment("Avida CURRENT tasks data");
+ df.WriteTimeStamp();
+ df.WriteComment("First column gives the current update, next columns give the number");
+ df.WriteComment("of organisms that have performed the task");
+
+ df.Write(m_update, "Update");
+ for(int i = 0; i < task_cur_count.GetSize(); i++) {
+ df.Write(task_cur_count[i], task_names[i] );
+ }
+ df.Endl();
+}
+
void cStats::PrintReactionData(const cString& filename)
{
cDataFile& df = m_world->GetDataFile(filename);
@@ -1044,13 +1062,13 @@
df.WriteComment( "Avida message data\n" );
df.WriteTimeStamp();
df.Write(GetUpdate(), "update");
+ df.Write(num_radio_busy, "total failed sends because of busy radio");
df.Write(num_msg_sent, "total sent");
- df.Write(num_radio_busy, "total failed sends because of busy radio");
df.Write(num_msg_received, "total received");
+ df.Write(num_msg_collision, "total collisions");
+ df.Write(num_msg_sent_no_one, "total sent to no one");
df.Write(num_msg_retrieved, "total retrieved");
df.Write(num_msg_retrieved_incomplete, "total attempts to retrieve incomplete message");
- df.Write(num_msg_collision, "total collisions");
- df.Write(num_msg_sent_no_one, "total sent to no one");
df.Write(inbox_size.Average(), "avg. inbox size");
df.Endl();
}
@@ -1134,7 +1152,6 @@
i!=m_message_predicates.end(); ++i) {
(**i)(msg); // Predicate is responsible for tracking info about messages.
}
- num_msg_sent++;
from_to_message_list[msg.GetSender()->GetCellID()] = msg.GetReceiver()->GetCellID();
}
Modified: branches/energy/source/main/cStats.h
===================================================================
--- branches/energy/source/main/cStats.h 2007-10-11 19:14:59 UTC (rev 2137)
+++ branches/energy/source/main/cStats.h 2007-10-12 19:40:21 UTC (rev 2138)
@@ -414,6 +414,7 @@
cIntSum& SumDemeOrgCount() { return sum_deme_org_count; }
// message
+ void IncMsgSent() { num_msg_sent++; }
void IncRadioBusy() { num_radio_busy++; }
void IncMsgSentNoOne() { num_msg_sent_no_one++; }
void IncMsgReceived() { num_msg_received++; }
@@ -664,6 +665,7 @@
void PrintCountData(const cString& filename);
void PrintTotalsData(const cString& filename);
void PrintTasksData(const cString& filename);
+ void PrintCurrentTasksData(const cString& filename);
void PrintTasksExeData(const cString& filename);
void PrintTasksQualData(const cString& filename);
void PrintReactionData(const cString& filename);
Modified: branches/energy/source/main/cTaskLib.cc
===================================================================
--- branches/energy/source/main/cTaskLib.cc 2007-10-11 19:14:59 UTC (rev 2137)
+++ branches/energy/source/main/cTaskLib.cc 2007-10-12 19:40:21 UTC (rev 2138)
@@ -27,7 +27,9 @@
#include "cTaskLib.h"
#include "cArgSchema.h"
+#include "cDeme.h"
#include "cEnvReqs.h"
+#include "cPopulation.h"
#include "tHashTable.h"
#include "cTaskState.h"
@@ -380,9 +382,9 @@
NewTask(name, "Successfully Sent Network Message", &cTaskLib::Task_NetSend);
else if (name == "net_receive")
NewTask(name, "Successfully Received Network Message", &cTaskLib::Task_NetReceive);
+ else if (name == "net_sentEventID")
+ NewTask(name, "Successfully sent an event ID in a network message", &cTaskLib::Task_SentEventID);
-
-
// Make sure we have actually found a task
if (task_array.GetSize() == start_size) {
if (errors != NULL && errors->GetSize() == 0) {
@@ -2687,9 +2689,6 @@
}
-
-
-
double cTaskLib::Task_CommEcho(cTaskContext& ctx) const
{
const int test_output = ctx.GetOutputBuffer()[0];
@@ -2738,19 +2737,16 @@
return 0.0;
}
-/*
+
double cTaskLib::Task_SentEventID(cTaskContext& ctx) const {
- cOrganism* org = ctx.GetOrganism();
- message_list_type sent_msg = org->GetSentMessages();
-
- cDeme& deme = ctx.GetOrgInterface()->GetDeme();
- for(int i = 0; i < deme.NumEvents(); i++) {
- for(int j = 0; j < sent_msg.size(); j++) {
- if(deme.GetEvent(i).GetEventID() == sent_msg[j]) {
- return 1.0;
- }
+ const cOrgMessage& last_sent_msg = ctx.GetOrganism()->GetSentMessages().back();
+ cDeme& deme = m_world->GetPopulation().GetDeme(ctx.GetOrgInterface()->GetDemeID());
+
+ for(int i = 0; i < deme.GetNumEvents(); i++) {
+ if((unsigned int)deme.GetEvent(i).GetEventID() == last_sent_msg.GetLabel() || (unsigned int)deme.GetEvent(i).GetEventID() == last_sent_msg.GetData()) {
+ return 1.0;
}
}
return 0.0;
}
-*/
+
Modified: branches/energy/source/main/cTaskLib.h
===================================================================
--- branches/energy/source/main/cTaskLib.h 2007-10-11 19:14:59 UTC (rev 2137)
+++ branches/energy/source/main/cTaskLib.h 2007-10-12 19:40:21 UTC (rev 2138)
@@ -275,6 +275,7 @@
// Network Tasks
double Task_NetSend(cTaskContext& ctx) const;
double Task_NetReceive(cTaskContext& ctx) const;
+ double Task_SentEventID(cTaskContext& ctx) const;
};
More information about the Avida-cvs
mailing list