[Avida-SVN] r1111 - branches/coopcomm/source/main
beckma24 at myxo.css.msu.edu
beckma24 at myxo.css.msu.edu
Tue Dec 5 12:35:35 PST 2006
Author: beckma24
Date: 2006-12-05 15:35:28 -0500 (Tue, 05 Dec 2006)
New Revision: 1111
Modified:
branches/coopcomm/source/main/cOrganism.cc
branches/coopcomm/source/main/cTaskLib.cc
branches/coopcomm/source/main/cTaskLib.h
Log:
Attempt to solve memory problem in send-toward-sink-multi-path
Modified: branches/coopcomm/source/main/cOrganism.cc
===================================================================
--- branches/coopcomm/source/main/cOrganism.cc 2006-12-04 18:44:10 UTC (rev 1110)
+++ branches/coopcomm/source/main/cOrganism.cc 2006-12-05 20:35:28 UTC (rev 1111)
@@ -556,9 +556,8 @@
last_cell_sent_to = msg.GetReceiver()->GetCellID();
// Stat-tracking.
m_world->GetStats().SentMessage(msg);
+ sent_to.insert(msg.GetReceiver()->GetCellID());
- sent_to.insert(last_cell_sent_to);
-
int old_size = m_sent_messages.size();
// store the message. yes, we're storing it twice. yes, we could save memory
Modified: branches/coopcomm/source/main/cTaskLib.cc
===================================================================
--- branches/coopcomm/source/main/cTaskLib.cc 2006-12-04 18:44:10 UTC (rev 1110)
+++ branches/coopcomm/source/main/cTaskLib.cc 2006-12-05 20:35:28 UTC (rev 1111)
@@ -358,6 +358,8 @@
NewTask(name, "Reward the sending of the sender's ID.", &cTaskLib::Task_SendSelf);
else if(name == "send-toward-sink")
NewTask(name, "Reward the sender for sending toward the sink", &cTaskLib::Task_SendTowardSink);
+ else if(name == "send-toward-sink-multi-path")
+ NewTask(name, "Reward the sender for sending multiple message toward the sink through different neighbors", &cTaskLib::Task_SendTowardSinkMultiPath);
else if(name == "send-not-toward-sink")
NewTask(name, "Reward the sender for not sending toward the sink", &cTaskLib::Task_SendNotTowardSink);
else if(name == "send-toward-sink-multi-path")
@@ -2003,7 +2005,7 @@
for(int i =0; i < BS_iter.Size(); i++) {
cPopulationCell& bsCell = m_world->GetPopulation().GetCell(BS_iter[i]);
if(nGeometry::GRID == m_world->GetConfig().WORLD_GEOMETRY.Get()) { //bounded grid
- if(hopWiseCloserGRID(ctx->GetMessage()->GetSender()->GetCell(), ctx->GetMessage()->GetReceiver()->GetCell(), &bsCell)) {
+ if(hopWiseCloserGRID(x_sender, y_sender, x_receiver, y_receiver, x_BS, y_BS)) {
//sent to closer organisms
return 1.0;
}
@@ -2044,16 +2046,17 @@
if(senderSentTo.size() <= 1) {
return 0.0;
}
-
+
tVector<int> BS_iter = m_world->GetPopulation().GetBaseStations();
- int orginalReceiver = ctx->GetMessage()->GetReceiver()->GetCellID();
+ int x_sender, y_sender, x_receiver, y_receiver, x_BS, y_BS;
bool sentToOrgCloser = false;
+ ctx->GetMessage()->GetSender()->GetPosition(x_sender,y_sender);
+ ctx->GetMessage()->GetReceiver()->GetPosition(x_receiver,y_receiver);
//check all base stations
for(int i =0; i < BS_iter.Size(); i++) {
- cPopulationCell& bsCell = m_world->GetPopulation().GetCell(BS_iter[i]);
if(nGeometry::GRID == m_world->GetConfig().WORLD_GEOMETRY.Get()) { //bounded grid
- if(hopWiseCloserGRID(ctx->GetMessage()->GetSender()->GetCell(), ctx->GetMessage()->GetReceiver()->GetCell(), &bsCell)) {
+ if(hopWiseCloserGRID(x_sender, y_sender, x_receiver, y_receiver, x_BS, y_BS)) {
//sent to closer organisms
sentToOrgCloser = true;
break;
@@ -2081,9 +2084,12 @@
if(nGeometry::GRID == m_world->GetConfig().WORLD_GEOMETRY.Get()) { //bounded grid
for(int i =0; i < BS_iter.Size(); i++) {
for(std::set<int>::iterator iter = senderSentTo.begin(); iter != senderSentTo.end(); iter++) {
- if(*iter != orginalReceiver) {
- cPopulationCell& bsCell = m_world->GetPopulation().GetCell(BS_iter[i]);
- if(hopWiseCloserGRID(ctx->GetMessage()->GetSender()->GetCell(), &(m_world->GetPopulation().GetCell(*iter)), &bsCell)) {
+ if(*iter != ctx->GetMessage()->GetReceiver()->GetID()) {
+ ctx->GetMessage()->GetSender()->GetPosition(x_sender,y_sender);
+ m_world->GetPopulation().GetCell(*iter).GetPosition(x_receiver,y_receiver);
+ m_world->GetPopulation().GetCell(BS_iter[i]).GetPosition(x_BS, y_BS);
+
+ if(hopWiseCloserGRID(x_sender, y_sender, x_receiver, y_receiver, x_BS, y_BS)) {
//sent to closer organisms
return 1.0;
}
@@ -2098,13 +2104,7 @@
return 0.0;
}
-bool cTaskLib::hopWiseCloserGRID(cPopulationCell* sender, cPopulationCell* receiver, cPopulationCell* baseStation) const {
- int x_sender, y_sender, x_receiver, y_receiver, x_BS, y_BS;
-
- sender->GetPosition(x_sender,y_sender);
- receiver->GetPosition(x_receiver,y_receiver);
- baseStation->GetPosition(x_BS,y_BS);
-
+bool cTaskLib::hopWiseCloserGRID(int x_sender, int y_sender, int x_receiver, int y_receiver, int x_BS, int y_BS) const{
if(max(abs(x_receiver-x_BS), abs(y_receiver-y_BS)) < max(abs(x_sender-x_BS), abs(y_sender-y_BS))) {
//sent to closer organisms
return true;
@@ -2116,8 +2116,6 @@
return false;
}
-
-
double cTaskLib::Task_SentNorth(cTaskContext* ctx) const {
if(ctx->GetMessage() == NULL)
return 0.0;
Modified: branches/coopcomm/source/main/cTaskLib.h
===================================================================
--- branches/coopcomm/source/main/cTaskLib.h 2006-12-04 18:44:10 UTC (rev 1110)
+++ branches/coopcomm/source/main/cTaskLib.h 2006-12-05 20:35:28 UTC (rev 1111)
@@ -259,8 +259,8 @@
double Task_GraphEquTree(cTaskContext* ctx) const;
//! helper functions
- bool hopWiseCloserGRID(cPopulationCell*, cPopulationCell*, cPopulationCell*) const;
- bool hopWiseCloserTORUS() const;
+ bool cTaskLib::hopWiseCloserGRID(int, int, int, int, int, int) const;
+ bool cTaskLib::hopWiseCloserTORUS() const;
};
More information about the Avida-cvs
mailing list