[Avida-SVN] r2135 - in branches/energy/source: cpu main
beckma24 at myxo.css.msu.edu
beckma24 at myxo.css.msu.edu
Thu Oct 11 06:58:56 PDT 2007
Author: beckma24
Date: 2007-10-11 09:58:56 -0400 (Thu, 11 Oct 2007)
New Revision: 2135
Modified:
branches/energy/source/cpu/cHardwareCPU.cc
branches/energy/source/cpu/cHardwareCPU.h
branches/energy/source/main/cOrgMessage.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 instructions get-cell-x and get-cell-y. Also, modified instruction send-msg-TX so that it fails if a message is currently being TX or RX by organism
Modified: branches/energy/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/energy/source/cpu/cHardwareCPU.cc 2007-10-10 19:31:08 UTC (rev 2134)
+++ branches/energy/source/cpu/cHardwareCPU.cc 2007-10-11 13:58:56 UTC (rev 2135)
@@ -228,7 +228,10 @@
tInstLibEntry<tMethod>("set-cmut", &cHardwareCPU::Inst_SetCopyMut),
tInstLibEntry<tMethod>("mod-cmut", &cHardwareCPU::Inst_ModCopyMut),
tInstLibEntry<tMethod>("get-cell-xy", &cHardwareCPU::Inst_GetCellPosition),
+ tInstLibEntry<tMethod>("get-cell-x", &cHardwareCPU::Inst_GetCellX),
+ tInstLibEntry<tMethod>("get-cell-y", &cHardwareCPU::Inst_GetCellY),
tInstLibEntry<tMethod>("dist-from-diag", &cHardwareCPU::Inst_GetDistanceFromDiagonal),
+
// @WRE additions for movement
tInstLibEntry<tMethod>("tumble", &cHardwareCPU::Inst_Tumble),
tInstLibEntry<tMethod>("move", &cHardwareCPU::Inst_Move),
@@ -371,7 +374,7 @@
// Messaging
tInstLibEntry<tMethod>("send-msg", &cHardwareCPU::Inst_SendMessage),
- tInstLibEntry<tMethod>("send-msg-CSMA", &cHardwareCPU::Inst_SendMessage_CSMA),
+ tInstLibEntry<tMethod>("send-msg-TX", &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),
@@ -4285,6 +4288,26 @@
return true;
}
+// stores a cell's X position, within its deme, in ?BX?
+bool cHardwareCPU::Inst_GetCellX(cAvidaContext& ctx) {
+ int absolute_cell_ID = organism->GetCellID();
+ int deme_id = organism->GetOrgInterface().GetDemeID();
+ std::pair<int, int> pos = m_world->GetPopulation().GetDeme(deme_id).GetCellPosition(absolute_cell_ID);
+ const int xreg = FindModifiedRegister(REG_BX);
+ GetRegister(xreg) = pos.first;
+ return true;
+}
+
+// stores a cell's X position, within its deme, in ?BX?
+bool cHardwareCPU::Inst_GetCellY(cAvidaContext& ctx) {
+ int absolute_cell_ID = organism->GetCellID();
+ int deme_id = organism->GetOrgInterface().GetDemeID();
+ std::pair<int, int> pos = m_world->GetPopulation().GetDeme(deme_id).GetCellPosition(absolute_cell_ID);
+ const int yreg = FindModifiedRegister(REG_BX);
+ GetRegister(yreg) = pos.second;
+ return true;
+}
+
bool cHardwareCPU::Inst_GetDistanceFromDiagonal(cAvidaContext& ctx) {
int absolute_cell_ID = organism->GetOrgInterface().GetCellID();
int deme_id = organism->GetOrgInterface().GetDemeID();
@@ -4536,14 +4559,32 @@
int cell_id = organism->GetCellID();
cPopulationCell& sending_cell = pop.GetCell(cell_id);
- if(!sending_cell.IsRX() && !sending_cell.IsTX()) {
- // block neighbors in connection list and track
+ if(sending_cell.IsTX()) { //if TX then fail
+ // tell organism about failure?
+ m_world->GetStats().IncRadioBusy();
+ return false;
+ } else if(sending_cell.InTXRange()) { // if in range of TXer
+ if(organism->NumMsgInInbox() > 0) {
+ if(organism->GetReceivedMessages().size() > 0) {
+ int last_msg_update = 0;
+ int last_msg_subupdate = 0;
+ 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?
+ 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->RX_until(currentUpdate+1, currentSubupdate);
+ neighbor->InTXRange_until(currentUpdate+1, currentSubupdate);
}
int newFacing = sending_cell.GetFacing();
assert(oldFacing == newFacing);
@@ -4555,14 +4596,11 @@
msg.SetLabel(GetRegister(label_reg));
msg.SetData(GetRegister(data_reg));
msg.SetTXComplete(currentUpdate+1, currentSubupdate);
- bool value = organism->SendMessage(ctx, msg);
+ bool value = organism->SendMessage(ctx, msg);
// pause self
sending_cell.TX_until(currentUpdate+1, currentSubupdate);
return value;
- } else {
- // msg blocked by CSMA
- m_world->GetStats().IncMsgBlocked();
}
return false;
}
@@ -4607,7 +4645,7 @@
const int reg = FindModifiedRegister(REG_BX);
cPopulationCell& cell = m_world->GetPopulation().GetCell(organism->GetCellID());
- GetRegister(reg) = (cell.IsRX() || cell.IsTX());
+ GetRegister(reg) = (cell.InTXRange() || cell.IsTX());
return true;
}
Modified: branches/energy/source/cpu/cHardwareCPU.h
===================================================================
--- branches/energy/source/cpu/cHardwareCPU.h 2007-10-10 19:31:08 UTC (rev 2134)
+++ branches/energy/source/cpu/cHardwareCPU.h 2007-10-11 13:58:56 UTC (rev 2135)
@@ -472,6 +472,8 @@
bool Inst_SetCopyMut(cAvidaContext& ctx);
bool Inst_ModCopyMut(cAvidaContext& ctx);
bool Inst_GetCellPosition(cAvidaContext& ctx);
+ bool Inst_GetCellX(cAvidaContext& ctx);
+ bool Inst_GetCellY(cAvidaContext& ctx);
bool Inst_GetDistanceFromDiagonal(cAvidaContext& ctx);
// @WRE additions for movement
bool Inst_Tumble(cAvidaContext& ctx);
Modified: branches/energy/source/main/cOrgMessage.h
===================================================================
--- branches/energy/source/main/cOrgMessage.h 2007-10-10 19:31:08 UTC (rev 2134)
+++ branches/energy/source/main/cOrgMessage.h 2007-10-11 13:58:56 UTC (rev 2135)
@@ -56,7 +56,7 @@
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; }
+ void GetTXComplete(int& update, int& subupdate) const { update = m_TX_complete.first; subupdate = m_TX_complete.second; }
private:
//! Default constructor is only used internally, to support message predicates.
Modified: branches/energy/source/main/cPopulationCell.cc
===================================================================
--- branches/energy/source/main/cPopulationCell.cc 2007-10-10 19:31:08 UTC (rev 2134)
+++ branches/energy/source/main/cPopulationCell.cc 2007-10-11 13:58:56 UTC (rev 2135)
@@ -46,7 +46,7 @@
, 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_RX_until(in_cell.m_RX_until)
+ , m_InTXRange_until(in_cell.m_InTXRange_until)
, m_TX_until(in_cell.m_TX_until)
{
// Copy the mutation rates into a new structure
@@ -68,7 +68,7 @@
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_RX_until = in_cell.m_RX_until;
+ m_InTXRange_until = in_cell.m_InTXRange_until;
m_TX_until = in_cell.m_TX_until;
// Copy the mutation rates, constructing the structure as necessary
@@ -217,12 +217,12 @@
return uptakeAmount;
}
-void cPopulationCell::RX_until(int update, int subupdate) {
- m_RX_until = make_pair(update, subupdate);
+void cPopulationCell::InTXRange_until(int update, int subupdate) {
+ m_InTXRange_until = make_pair(update, subupdate);
}
-bool cPopulationCell::IsRX() {
- return !m_world->GetStats().TimeHasPassed(m_RX_until.first, m_RX_until.second);
+bool cPopulationCell::InTXRange() {
+ return !m_world->GetStats().TimeHasPassed(m_InTXRange_until.first, m_InTXRange_until.second);
}
void cPopulationCell::TX_until(int update, int subupdate) {
Modified: branches/energy/source/main/cPopulationCell.h
===================================================================
--- branches/energy/source/main/cPopulationCell.h 2007-10-10 19:31:08 UTC (rev 2134)
+++ branches/energy/source/main/cPopulationCell.h 2007-10-11 13:58:56 UTC (rev 2135)
@@ -65,7 +65,7 @@
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_RX_until; // receiving message until <update, subupdate>
+ std::pair<int, int> m_InTXRange_until; // receiving message until <update, subupdate>
std::pair<int, int> m_TX_until; // <update, subupdate>
void InsertOrganism(cOrganism* new_org);
@@ -74,7 +74,7 @@
public:
cPopulationCell() : m_world(NULL), m_organism(NULL), m_hardware(NULL), m_mut_rates(NULL),
m_organism_count(0) {
- m_RX_until = std::make_pair(0,0);
+ m_InTXRange_until = std::make_pair(0,0);
m_TX_until = std::make_pair(0,0);
}
@@ -112,8 +112,8 @@
double UptakeCellEnergy(double frac_to_uptake);
- void RX_until(int update, int subupdate);
- bool IsRX();
+ void InTXRange_until(int update, int subupdate);
+ bool InTXRange();
void TX_until(int update, int subupdate);
bool IsTX();
Modified: branches/energy/source/main/cStats.cc
===================================================================
--- branches/energy/source/main/cStats.cc 2007-10-10 19:31:08 UTC (rev 2134)
+++ branches/energy/source/main/cStats.cc 2007-10-11 13:58:56 UTC (rev 2135)
@@ -505,10 +505,10 @@
// message
num_msg_sent_no_one = 0;
num_msg_sent = 0;
+ num_radio_busy = 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();
}
@@ -1045,10 +1045,10 @@
df.WriteTimeStamp();
df.Write(GetUpdate(), "update");
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_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");
@@ -1061,7 +1061,7 @@
int width = pop.GetWorldX();
for(int i = 0; i < pop.GetSize(); i++) {
int data;
- if(pop.GetCell(i).IsRX()) { // cell blocked
+ if(pop.GetCell(i).InTXRange()) { // cell blocked
data = -1;
} else if(pop.GetCell(i).IsTX()) { //sent msg, cell paused
if(from_to_message_list.find(i) == from_to_message_list.end()) {
Modified: branches/energy/source/main/cStats.h
===================================================================
--- branches/energy/source/main/cStats.h 2007-10-10 19:31:08 UTC (rev 2134)
+++ branches/energy/source/main/cStats.h 2007-10-11 13:58:56 UTC (rev 2135)
@@ -270,10 +270,10 @@
// message stats
int num_msg_sent_no_one;
int num_msg_sent;
+ int num_radio_busy;
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,11 +414,11 @@
cIntSum& SumDemeOrgCount() { return sum_deme_org_count; }
// message
+ void IncRadioBusy() { num_radio_busy++; }
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