[Avida-SVN] r2132 - in branches/energy/source: cpu main
beckma24 at myxo.css.msu.edu
beckma24 at myxo.css.msu.edu
Tue Oct 9 12:09:57 PDT 2007
Author: beckma24
Date: 2007-10-09 15:09:57 -0400 (Tue, 09 Oct 2007)
New Revision: 2132
Modified:
branches/energy/source/cpu/cHardwareCPU.cc
branches/energy/source/cpu/cHardwareCPU.h
branches/energy/source/main/cOrgMessage.h
branches/energy/source/main/cOrganism.cc
branches/energy/source/main/cOrganism.h
branches/energy/source/main/cPopulationCell.cc
branches/energy/source/main/cPopulationCell.h
branches/energy/source/main/cStats.cc
branches/energy/source/main/cStats.h
Log:
Added send and retrieve message instructions that simulate a physical wireless media. Messages can not collide at receiver. Also, changed some associated function names to be more specific
Modified: branches/energy/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/energy/source/cpu/cHardwareCPU.cc 2007-10-08 20:36:51 UTC (rev 2131)
+++ branches/energy/source/cpu/cHardwareCPU.cc 2007-10-09 19:09:57 UTC (rev 2132)
@@ -371,8 +371,10 @@
// Messaging
tInstLibEntry<tMethod>("send-msg", &cHardwareCPU::Inst_SendMessage),
- tInstLibEntry<tMethod>("send-msg-block-neighbors", &cHardwareCPU::Inst_SendMessage_BlockNeighbors),
+ tInstLibEntry<tMethod>("send-msg-CSMA", &cHardwareCPU::Inst_SendMessage_CSMA),
tInstLibEntry<tMethod>("retrieve-msg", &cHardwareCPU::Inst_RetrieveMessage),
+ tInstLibEntry<tMethod>("retrieve-msg-RX-complete", &cHardwareCPU::Inst_RetrieveMessage_RXComplete),
+ tInstLibEntry<tMethod>("carrier-sense", &cHardwareCPU::Inst_CarrierSense),
// Placebo instructions
tInstLibEntry<tMethod>("skip", &cHardwareCPU::Inst_Skip),
@@ -4525,29 +4527,42 @@
return organism->SendMessage(ctx, msg);
}
-bool cHardwareCPU::Inst_SendMessage_BlockNeighbors(cAvidaContext& ctx) {
+/*!
+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
cPopulation& pop = m_world->GetPopulation();
int cell_id = organism->GetCellID();
cPopulationCell& sending_cell = pop.GetCell(cell_id);
-
- if(!sending_cell.SendingIsBlocked() && !sending_cell.SendingIsPaused()) {
+
+ if(!sending_cell.IsRX() && !sending_cell.IsTX()) {
// block neighbors in connection list 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->BlockSending(currentUpdate+1, currentSubupdate);
+ neighbor->RX_until(currentUpdate+1, currentSubupdate);
}
int newFacing = sending_cell.GetFacing();
assert(oldFacing == newFacing);
// send message
- Inst_SendMessage(ctx);
+ 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.PauseSending(currentUpdate+1, currentSubupdate);
- return true;
+ sending_cell.TX_until(currentUpdate+1, currentSubupdate);
+ return value;
+ } else {
+ // msg blocked by CSMA
+ m_world->GetStats().IncMsgBlocked();
}
return false;
}
@@ -4572,12 +4587,30 @@
return true;
}
-/*
-bool cHardwareCPU::Inst_carrer_sense(cAvidaContext& ctx) {
- //better name
+/*!
+Same as RetrieveMessage except a message cannot be retrieved until its transmission time has passed.
+*/
+bool cHardwareCPU::Inst_RetrieveMessage_RXComplete(cAvidaContext& ctx) {
+ const cOrgMessage* msg = organism->RetrieveMessage_RXComplete();
+ if(msg == 0)
+ return false;
+
+ const int label_reg = FindModifiedRegister(REG_BX);
+ const int data_reg = FindNextRegister(label_reg);
+
+ GetRegister(label_reg) = msg->GetLabel();
+ GetRegister(data_reg) = msg->GetData();
+ return true;
}
-*/
+bool cHardwareCPU::Inst_CarrierSense(cAvidaContext& ctx) {
+ const int reg = FindModifiedRegister(REG_BX);
+ cPopulationCell& cell = m_world->GetPopulation().GetCell(organism->GetCellID());
+
+ GetRegister(reg) = (cell.IsRX() || cell.IsTX());
+ return true;
+}
+
//// Placebo insts ////
bool cHardwareCPU::Inst_Skip(cAvidaContext& ctx)
{
Modified: branches/energy/source/cpu/cHardwareCPU.h
===================================================================
--- branches/energy/source/cpu/cHardwareCPU.h 2007-10-08 20:36:51 UTC (rev 2131)
+++ branches/energy/source/cpu/cHardwareCPU.h 2007-10-09 19:09:57 UTC (rev 2132)
@@ -562,8 +562,10 @@
//// Messaging ////
bool Inst_SendMessage(cAvidaContext& ctx);
- bool Inst_SendMessage_BlockNeighbors(cAvidaContext& ctx);
+ bool Inst_SendMessage_CSMA(cAvidaContext& ctx);
bool Inst_RetrieveMessage(cAvidaContext& ctx);
+ bool Inst_RetrieveMessage_RXComplete(cAvidaContext& ctx);
+ bool Inst_CarrierSense(cAvidaContext& ctx);
//// Placebo ////
bool Inst_Skip(cAvidaContext& ctx);
Modified: branches/energy/source/main/cOrgMessage.h
===================================================================
--- branches/energy/source/main/cOrgMessage.h 2007-10-08 20:36:51 UTC (rev 2131)
+++ branches/energy/source/main/cOrgMessage.h 2007-10-09 19:09:57 UTC (rev 2132)
@@ -42,6 +42,7 @@
cOrgMessage(cOrganism* sender) : m_pSender(sender), m_pReceiver(0), m_data(0), m_label(0)
{
assert(m_pSender);
+ m_TX_complete = std::make_pair(0,0);
}
cOrganism* GetSender() const { return m_pSender; }
@@ -54,16 +55,21 @@
void SetData(unsigned int data) { m_data = data; }
void SetLabel(unsigned int label) { m_label = label; }
+ void SetTXComplete(int update, int subupdate) { m_TX_complete = std::make_pair(update, subupdate); }
+ void GetTXComplete(int& update, int& subupdate) { update = m_TX_complete.first; subupdate = m_TX_complete.second; }
+
private:
//! Default constructor is only used internally, to support message predicates.
cOrgMessage() : m_pSender(0), m_pReceiver(0), m_data(0), m_label(0)
{
+ m_TX_complete = std::make_pair(0,0);
}
cOrganism* m_pSender;
cOrganism* m_pReceiver;
unsigned int m_data;
unsigned int m_label;
+ std::pair<int, int> m_TX_complete; // time when message has been received; <update, subupdate>
};
Modified: branches/energy/source/main/cOrganism.cc
===================================================================
--- branches/energy/source/main/cOrganism.cc 2007-10-08 20:36:51 UTC (rev 2131)
+++ branches/energy/source/main/cOrganism.cc 2007-10-09 19:09:57 UTC (rev 2132)
@@ -649,9 +649,26 @@
void cOrganism::ReceiveMessage(cOrgMessage& msg)
{
InitMessaging();
- msg.SetReceiver(this);
- m_msg->received.push_back(msg);
- m_world->GetStats().IncMsgReceived();
+
+ int last_msg_update = 0;
+ int last_msg_subupdate = 0;
+
+ if(m_msg->received.size() > 0) {
+ cerr<<m_msg->received.size()<<endl;
+ cOrgMessage& last_msg = m_msg->received.back();
+ cerr<<m_msg->received.size()<<endl;
+ last_msg.GetTXComplete(last_msg_update, last_msg_subupdate);
+ }
+
+ if(m_world->GetStats().TimeHasPassed(last_msg_update, last_msg_subupdate)) { // no collision
+ msg.SetReceiver(this);
+ m_msg->received.push_back(msg);
+ m_world->GetStats().IncMsgReceived();
+ } else {
+ // collision
+ m_msg->received.pop_back();
+ m_world->GetStats().IncMsgCollision();
+ }
}
@@ -665,3 +682,22 @@
}
return 0;
}
+
+const cOrgMessage* cOrganism::RetrieveMessage_RXComplete()
+{
+ InitMessaging();
+
+ if(m_msg->retrieve_index < m_msg->received.size()) {
+ int RX_update, RX_subupdate;
+ m_msg->received.at(m_msg->retrieve_index).GetTXComplete(RX_update, RX_subupdate);
+
+ if(m_world->GetStats().TimeHasPassed(RX_update, RX_subupdate)) {
+ m_world->GetStats().IncMsgRetrieved();
+ return &m_msg->received.at(m_msg->retrieve_index++);
+ } else {
+ // message TX is not complete
+ m_world->GetStats().IncMsgRetrievedIncomplete();
+ }
+ }
+ return 0;
+}
Modified: branches/energy/source/main/cOrganism.h
===================================================================
--- branches/energy/source/main/cOrganism.h 2007-10-08 20:36:51 UTC (rev 2131)
+++ branches/energy/source/main/cOrganism.h 2007-10-09 19:09:57 UTC (rev 2132)
@@ -323,6 +323,8 @@
void ReceiveMessage(cOrgMessage& msg);
//! Called when this organism attempts to move a received message into its CPU.
const cOrgMessage* RetrieveMessage();
+ //! Similar to RetrieveMessage, but TX must be complete for message to be available
+ const cOrgMessage* RetrieveMessage_RXComplete();
//! Returns the list of all messsages received by this organism.
const message_list_type& GetReceivedMessages() { InitMessaging(); return m_msg->received; }
//! Returns the list of all messages sent by this organism.
Modified: branches/energy/source/main/cPopulationCell.cc
===================================================================
--- branches/energy/source/main/cPopulationCell.cc 2007-10-08 20:36:51 UTC (rev 2131)
+++ branches/energy/source/main/cPopulationCell.cc 2007-10-09 19:09:57 UTC (rev 2132)
@@ -46,8 +46,8 @@
, m_deme_id(in_cell.m_deme_id)
, m_organism_count(in_cell.m_organism_count)
, m_cell_data(in_cell.m_cell_data)
- , m_blocked_from_sending_until(in_cell.m_blocked_from_sending_until)
- , m_sending_paused_until(in_cell.m_sending_paused_until)
+ , m_RX_until(in_cell.m_RX_until)
+ , m_TX_until(in_cell.m_TX_until)
{
// Copy the mutation rates into a new structure
m_mut_rates = new cMutationRates(*in_cell.m_mut_rates);
@@ -68,8 +68,8 @@
m_deme_id = in_cell.m_deme_id;
m_organism_count = in_cell.m_organism_count;
m_cell_data = in_cell.m_cell_data;
- m_blocked_from_sending_until = in_cell.m_blocked_from_sending_until;
- m_sending_paused_until = in_cell.m_sending_paused_until;
+ m_RX_until = in_cell.m_RX_until;
+ m_TX_until = in_cell.m_TX_until;
// Copy the mutation rates, constructing the structure as necessary
if (m_mut_rates == NULL)
@@ -217,20 +217,20 @@
return uptakeAmount;
}
-void cPopulationCell::BlockSending(int update, int subupdate) {
- m_blocked_from_sending_until = make_pair(update, subupdate);
+void cPopulationCell::RX_until(int update, int subupdate) {
+ m_RX_until = make_pair(update, subupdate);
}
-bool cPopulationCell::SendingIsBlocked() {
- return m_world->GetStats().TimeHasPassed(m_blocked_from_sending_until.first, m_blocked_from_sending_until.second);
+bool cPopulationCell::IsRX() {
+ return !m_world->GetStats().TimeHasPassed(m_RX_until.first, m_RX_until.second);
}
-void cPopulationCell::PauseSending(int update, int subupdate) {
- m_sending_paused_until = make_pair(update, subupdate);
+void cPopulationCell::TX_until(int update, int subupdate) {
+ m_TX_until = make_pair(update, subupdate);
}
-bool cPopulationCell::SendingIsPaused() {
- return m_world->GetStats().TimeHasPassed(m_sending_paused_until.first, m_sending_paused_until.second);
+bool cPopulationCell::IsTX() {
+ return !m_world->GetStats().TimeHasPassed(m_TX_until.first, m_TX_until.second);
}
bool cPopulationCell::OK()
Modified: branches/energy/source/main/cPopulationCell.h
===================================================================
--- branches/energy/source/main/cPopulationCell.h 2007-10-08 20:36:51 UTC (rev 2131)
+++ branches/energy/source/main/cPopulationCell.h 2007-10-09 19:09:57 UTC (rev 2132)
@@ -65,8 +65,8 @@
int m_x; //!< The x-coordinate of the position of this cell in the environment.
int m_y; //!< The y-coordinate of the position of this cell in the environment.
- std::pair<int, int> m_blocked_from_sending_until; // <update, subupdate>
- std::pair<int, int> m_sending_paused_until; // <update, subupdate>
+ std::pair<int, int> m_RX_until; // receiving message until <update, subupdate>
+ std::pair<int, int> m_TX_until; // <update, subupdate>
void InsertOrganism(cOrganism* new_org);
cOrganism* RemoveOrganism();
@@ -74,8 +74,8 @@
public:
cPopulationCell() : m_world(NULL), m_organism(NULL), m_hardware(NULL), m_mut_rates(NULL),
m_organism_count(0) {
- m_blocked_from_sending_until = std::make_pair(0,0);
- m_sending_paused_until = std::make_pair(0,0);
+ m_RX_until = std::make_pair(0,0);
+ m_TX_until = std::make_pair(0,0);
}
cPopulationCell(const cPopulationCell& in_cell);
@@ -112,11 +112,11 @@
double UptakeCellEnergy(double frac_to_uptake);
- void BlockSending(int update, int subupdate);
- bool SendingIsBlocked();
+ void RX_until(int update, int subupdate);
+ bool IsRX();
- void PauseSending(int update, int subupdate);
- bool SendingIsPaused();
+ void TX_until(int update, int subupdate);
+ bool IsTX();
bool OK();
};
Modified: branches/energy/source/main/cStats.cc
===================================================================
--- branches/energy/source/main/cStats.cc 2007-10-08 20:36:51 UTC (rev 2131)
+++ branches/energy/source/main/cStats.cc 2007-10-09 19:09:57 UTC (rev 2132)
@@ -507,6 +507,9 @@
num_msg_sent = 0;
num_msg_received = 0;
num_msg_retrieved = 0;
+ num_msg_retrieved_incomplete = 0;
+ num_msg_blocked = 0;
+ num_msg_collision = 0;
from_to_message_list.clear();
}
@@ -1044,6 +1047,9 @@
df.Write(num_msg_sent, "total sent");
df.Write(num_msg_received, "total received");
df.Write(num_msg_retrieved, "total retrieved");
+ df.Write(num_msg_retrieved_incomplete, "total attempts to retrieve incomplete message");
+ df.Write(num_msg_blocked, "total blocked");
+ 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();
@@ -1055,9 +1061,9 @@
int width = pop.GetWorldX();
for(int i = 0; i < pop.GetSize(); i++) {
int data;
- if(pop.GetCell(i).SendingIsBlocked()) { // cell blocked
+ if(pop.GetCell(i).IsRX()) { // cell blocked
data = -1;
- } else if(pop.GetCell(i).SendingIsPaused()) { //sent msg, cell paused
+ } else if(pop.GetCell(i).IsTX()) { //sent msg, cell paused
if(from_to_message_list.find(i) == from_to_message_list.end()) {
data = -2; // msg sent to no one
}
Modified: branches/energy/source/main/cStats.h
===================================================================
--- branches/energy/source/main/cStats.h 2007-10-08 20:36:51 UTC (rev 2131)
+++ branches/energy/source/main/cStats.h 2007-10-09 19:09:57 UTC (rev 2132)
@@ -272,6 +272,9 @@
int num_msg_sent;
int num_msg_received;
int num_msg_retrieved;
+ int num_msg_retrieved_incomplete; // CSMA
+ int num_msg_blocked; // CSMA
+ int num_msg_collision; // CSMA
cIntSum inbox_size;
std::map<int, int> from_to_message_list; //<int from, int to>
@@ -414,6 +417,9 @@
void IncMsgSentNoOne() { num_msg_sent_no_one++; }
void IncMsgReceived() { num_msg_received++; }
void IncMsgRetrieved() { num_msg_retrieved++; }
+ void IncMsgRetrievedIncomplete() { num_msg_retrieved_incomplete++; }
+ void IncMsgBlocked() { num_msg_blocked++; }
+ void IncMsgCollision() { num_msg_collision++; }
cIntSum& InboxSize() { return inbox_size; }
More information about the Avida-cvs
mailing list