[Avida-SVN] r2147 - in branches/energy: Avida.xcodeproj source/cpu source/main
beckma24 at myxo.css.msu.edu
beckma24 at myxo.css.msu.edu
Mon Oct 22 08:03:09 PDT 2007
Author: beckma24
Date: 2007-10-22 11:03:09 -0400 (Mon, 22 Oct 2007)
New Revision: 2147
Added:
branches/energy/source/main/nRadioStatus.h
Modified:
branches/energy/Avida.xcodeproj/project.pbxproj
branches/energy/source/cpu/cHardwareCPU.cc
branches/energy/source/cpu/cHardwareCPU.h
branches/energy/source/main/cOrgMessagePredicate.h
branches/energy/source/main/cPopulationCell.cc
branches/energy/source/main/cPopulationCell.h
Log:
Added radio status namespace, and blocking receive and variable lenght sleep instructions. Also, fixed pred_sat_frac_dump.dat and replicate deme message predicate.
Modified: branches/energy/Avida.xcodeproj/project.pbxproj
===================================================================
--- branches/energy/Avida.xcodeproj/project.pbxproj 2007-10-22 13:35:03 UTC (rev 2146)
+++ branches/energy/Avida.xcodeproj/project.pbxproj 2007-10-22 15:03:09 UTC (rev 2147)
@@ -196,6 +196,7 @@
B4FA258A0C5EB65E0086D4B5 /* cPlasticPhenotype.cc in Sources */ = {isa = PBXBuildFile; fileRef = B4FA25810C5EB6510086D4B5 /* cPlasticPhenotype.cc */; };
B4FA25A90C5EB7880086D4B5 /* cPhenPlastGenotype.cc in Sources */ = {isa = PBXBuildFile; fileRef = B4FA259E0C5EB7600086D4B5 /* cPhenPlastGenotype.cc */; };
B516AF840C91E2D400023D53 /* cDemeCellEvent.cc in Sources */ = {isa = PBXBuildFile; fileRef = B516AF790C91E24600023D53 /* cDemeCellEvent.cc */; };
+ B59AA8650CC7D99E00469456 /* nRadioStatus.h in Headers */ = {isa = PBXBuildFile; fileRef = B59AA8640CC7D99E00469456 /* nRadioStatus.h */; };
DCD8AC1F0C8A7C30004CBE6F /* cAnalyzeGenotypeTreeStats.cc in Sources */ = {isa = PBXBuildFile; fileRef = DCA4BEC10C8A758800D81B58 /* cAnalyzeGenotypeTreeStats.cc */; };
/* End PBXBuildFile section */
@@ -838,6 +839,7 @@
B4FA259E0C5EB7600086D4B5 /* cPhenPlastGenotype.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = cPhenPlastGenotype.cc; sourceTree = "<group>"; };
B516AF790C91E24600023D53 /* cDemeCellEvent.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = cDemeCellEvent.cc; path = source/main/cDemeCellEvent.cc; sourceTree = SOURCE_ROOT; };
B516AF7A0C91E24600023D53 /* cDemeCellEvent.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = cDemeCellEvent.h; path = source/main/cDemeCellEvent.h; sourceTree = SOURCE_ROOT; };
+ B59AA8640CC7D99E00469456 /* nRadioStatus.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = nRadioStatus.h; sourceTree = "<group>"; };
DCA4BEC10C8A758800D81B58 /* cAnalyzeGenotypeTreeStats.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = cAnalyzeGenotypeTreeStats.cc; sourceTree = "<group>"; };
DCA4BEC20C8A758800D81B58 /* cAnalyzeGenotypeTreeStats.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = cAnalyzeGenotypeTreeStats.h; sourceTree = "<group>"; };
DCC30FCF0762539D008F7A48 /* Doxyfile */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text; path = Doxyfile; sourceTree = "<group>"; };
@@ -1465,6 +1467,7 @@
70B0875A08F5EC8900FC65FE /* nGeometry.h */,
70B0867208F499C100FC65FE /* nMutation.h */,
70B0875C08F5ECBC00FC65FE /* nReaction.h */,
+ B59AA8640CC7D99E00469456 /* nRadioStatus.h */,
7005A70909BA0FBE0007E16E /* cOrgInterface.h */,
701D51CB09C645F50009B4F8 /* cAvidaContext.h */,
7027621909D73E5900741717 /* cOrgSourceMessage.h */,
@@ -1649,6 +1652,7 @@
isa = PBXHeadersBuildPhase;
buildActionMask = 2147483647;
files = (
+ B59AA8650CC7D99E00469456 /* nRadioStatus.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Modified: branches/energy/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/energy/source/cpu/cHardwareCPU.cc 2007-10-22 13:35:03 UTC (rev 2146)
+++ branches/energy/source/cpu/cHardwareCPU.cc 2007-10-22 15:03:09 UTC (rev 2147)
@@ -375,6 +375,7 @@
// Messaging
tInstLibEntry<tMethod>("send-msg", &cHardwareCPU::Inst_SendMessage),
tInstLibEntry<tMethod>("send-msg-TX", &cHardwareCPU::Inst_SendMessage_TX),
+ tInstLibEntry<tMethod>("receive-msg-blocking", &cHardwareCPU::Inst_ReceiveMsg_Blocking),
tInstLibEntry<tMethod>("retrieve-msg", &cHardwareCPU::Inst_RetrieveMessage),
tInstLibEntry<tMethod>("retrieve-msg-RX-complete", &cHardwareCPU::Inst_RetrieveMessage_RXComplete),
tInstLibEntry<tMethod>("carrier-sense", &cHardwareCPU::Inst_CarrierSense),
@@ -406,7 +407,7 @@
}
cHardwareCPU::cHardwareCPU(cWorld* world, cOrganism* in_organism, cInstSet* in_m_inst_set)
-: cHardwareBase(world, in_organism, in_m_inst_set)
+: cHardwareBase(world, in_organism, in_m_inst_set), m_time_currently_sleeping(-1), m_lenght_of_sleep(-1)
{
/* FIXME: reorganize storage of m_functions. -- kgn */
m_functions = s_inst_slib->GetFunctions();
@@ -427,6 +428,8 @@
, m_mal_active(hardware_cpu.m_mal_active)
, m_advance_ip(hardware_cpu.m_advance_ip)
, m_executedmatchstrings(hardware_cpu.m_executedmatchstrings)
+, m_time_currently_sleeping(hardware_cpu.m_time_currently_sleeping)
+, m_lenght_of_sleep(hardware_cpu.m_lenght_of_sleep)
{
#if INSTRUCTION_COSTS
inst_cost = hardware_cpu.inst_cost;
@@ -4271,6 +4274,42 @@
return true;
}
+/*
+This method causes an organism to sleep for ?BX? cycles
+*/
+bool cHardwareCPU::Inst_SleepVariableLenght(cAvidaContext& ctx) {
+
+ if(m_time_currently_sleeping < m_lenght_of_sleep) { // continue sleeping
+ m_time_currently_sleeping++;
+ } else if(m_lenght_of_sleep == -1) { //begin sleeping
+ //set lenght of nap to ?BX?
+ m_lenght_of_sleep = GetRegister(FindModifiedRegister(REG_BX));
+ //set time sleeping to zero
+ m_time_currently_sleeping = 0;
+ } else { // wake up
+
+ // TODO : keep stats on how long organisms sleep for
+
+ cPopulation& pop = m_world->GetPopulation();
+ int cellID = organism->GetCellID();
+ if(m_world->GetConfig().LOG_SLEEP_TIMES.Get() == 1) {
+ pop.AddEndSleep(cellID, m_world->GetStats().GetUpdate());
+ }
+ organism->SetSleeping(false); //this instruction get executed at the end of a sleep cycle
+ m_world->GetStats().decNumAsleep(pop.GetCell(cellID).GetDemeID());
+ if(m_world->GetConfig().APPLY_ENERGY_METHOD.Get() == 2) {
+ organism->GetPhenotype().RefreshEnergy();
+ organism->GetPhenotype().ApplyToEnergyStore();
+ double newMerit = cMerit::EnergyToMerit(organism->GetPhenotype().GetStoredEnergy() * organism->GetPhenotype().GetEnergyUsageRatio(), m_world);
+ pop.UpdateMerit(cellID, newMerit);
+ }
+ m_lenght_of_sleep = -1;
+ m_time_currently_sleeping = 0;
+ }
+ return true;
+}
+
+
bool cHardwareCPU::Inst_GetUpdate(cAvidaContext& ctx) {
const int reg_used = FindModifiedRegister(REG_BX);
GetRegister(reg_used) = m_world->GetStats().GetUpdate();
@@ -4604,6 +4643,25 @@
return value;
}
+
+/*
+This method implements a blocking receive.
+It is continously executed, paying all costs for every execution, until a message is received.
+*/
+bool cHardwareCPU::Inst_ReceiveMsg_Blocking(cAvidaContext& ctx) {
+ const cOrgMessage* msg = organism->RetrieveMessage();
+ if(msg == 0) {
+ IP().Retreat();
+ return true;
+ }
+ 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;
+}
+
/*! This method /attempts/ to retrieve a message -- It may not be possible, as in
the case of an empty receive buffer.
Modified: branches/energy/source/cpu/cHardwareCPU.h
===================================================================
--- branches/energy/source/cpu/cHardwareCPU.h 2007-10-22 13:35:03 UTC (rev 2146)
+++ branches/energy/source/cpu/cHardwareCPU.h 2007-10-22 15:03:09 UTC (rev 2147)
@@ -159,6 +159,9 @@
tArray<cPromoter> m_promoters;
// Promoter Model -->
+ int m_time_currently_sleeping;
+ int m_lenght_of_sleep;
+
bool SingleProcess_ExecuteInst(cAvidaContext& ctx, const cInstruction& cur_inst);
// -------- Stack Manipulation... --------
@@ -548,6 +551,7 @@
bool Inst_HeadDivide0_001(cAvidaContext& ctx);
bool Inst_Sleep(cAvidaContext& ctx);
+ bool Inst_SleepVariableLenght(cAvidaContext& ctx);
bool Inst_GetUpdate(cAvidaContext& ctx);
//// Promoter Model ////
@@ -565,6 +569,7 @@
//// Messaging ////
bool Inst_SendMessage(cAvidaContext& ctx);
bool Inst_SendMessage_TX(cAvidaContext& ctx);
+ bool Inst_ReceiveMsg_Blocking(cAvidaContext& ctx);
bool Inst_RetrieveMessage(cAvidaContext& ctx);
bool Inst_RetrieveMessage_RXComplete(cAvidaContext& ctx);
bool Inst_CarrierSense(cAvidaContext& ctx);
Modified: branches/energy/source/main/cOrgMessagePredicate.h
===================================================================
--- branches/energy/source/main/cOrgMessagePredicate.h 2007-10-22 13:35:03 UTC (rev 2146)
+++ branches/energy/source/main/cOrgMessagePredicate.h 2007-10-22 15:03:09 UTC (rev 2147)
@@ -169,7 +169,7 @@
if(m_base_station == msg.GetReceiver()->GetCellID()) {
m_current_times++;
- if(m_current_times == m_total_times) {
+ if(m_current_times >= m_total_times) {
m_event_received = true;
}
}
@@ -185,13 +185,13 @@
}
out << "]\n";
- Reset();
+ m_cell_ids.clear();
}
virtual void Reset() {
m_event_received = false;
m_stats_updated = false;
- m_cell_ids.clear();
+ m_current_times = 0;
}
virtual bool PreviouslySatisfied() {
@@ -203,7 +203,7 @@
}
virtual void UpdateStats(cStats& stats) {
- if(m_event_received && m_stats_updated) {
+ if(m_event_received && !m_stats_updated) {
int eventCell = m_event->GetNextEventCellID();
while(eventCell != -1) {
stats.IncPredSat(eventCell);
@@ -250,7 +250,7 @@
// does receiver have x cordinate of zero
if(pos.first == 0) {
m_current_times++;
- if(m_current_times == m_total_times) {
+ if(m_current_times >= m_total_times) {
m_event_received = true;
}
}
@@ -265,12 +265,13 @@
}
out << "]\n";
- Reset();
+ m_cell_ids.clear();
}
virtual void Reset() {
m_event_received = false;
m_stats_updated = false;
+ m_current_times = 0;
m_cell_ids.clear();
}
@@ -283,7 +284,7 @@
}
virtual void UpdateStats(cStats& stats) {
- if(m_event_received && m_stats_updated) {
+ if(m_event_received && !m_stats_updated) {
int eventCell = m_event->GetNextEventCellID();
while(eventCell != -1) {
stats.IncPredSat(eventCell);
Modified: branches/energy/source/main/cPopulationCell.cc
===================================================================
--- branches/energy/source/main/cPopulationCell.cc 2007-10-22 13:35:03 UTC (rev 2146)
+++ branches/energy/source/main/cPopulationCell.cc 2007-10-22 15:03:09 UTC (rev 2147)
@@ -33,6 +33,7 @@
#include "cEnvironment.h"
#include "cPopulation.h"
#include "cDeme.h"
+#include "nRadioStatus.h"
using namespace std;
@@ -233,6 +234,24 @@
return !m_world->GetStats().TimeHasPassed(m_TX_until.first, m_TX_until.second);
}
+int cPopulationCell::GetRadioStatus() {
+ return m_radio_status;
+}
+
+void cPopulationCell::SetRadioStatus(int status) {
+ if(status == nRadioStatus::TX) {
+ m_radio_status = nRadioStatus::TX;
+ } else if(status == nRadioStatus::RX) {
+ m_radio_status = nRadioStatus::RX;
+ } else if(status == nRadioStatus::IDLE) {
+ m_radio_status = nRadioStatus::IDLE;
+ } else if(status == nRadioStatus::OFF) {
+ m_radio_status = nRadioStatus::OFF;
+ } else {//unknown status value
+ assert(false);
+ }
+}
+
bool cPopulationCell::OK()
{
// Nothing for the moment...
Modified: branches/energy/source/main/cPopulationCell.h
===================================================================
--- branches/energy/source/main/cPopulationCell.h 2007-10-22 13:35:03 UTC (rev 2146)
+++ branches/energy/source/main/cPopulationCell.h 2007-10-22 15:03:09 UTC (rev 2147)
@@ -67,6 +67,8 @@
std::pair<int, int> m_InTXRange_until; // receiving message until <update, subupdate>
std::pair<int, int> m_TX_until; // <update, subupdate>
+
+ int m_radio_status; // holds status of radio
void InsertOrganism(cOrganism* new_org);
cOrganism* RemoveOrganism();
@@ -118,6 +120,9 @@
void TX_until(int update, int subupdate);
bool IsTX();
+ int GetRadioStatus();
+ void SetRadioStatus(int status);
+
bool OK();
};
Added: branches/energy/source/main/nRadioStatus.h
===================================================================
--- branches/energy/source/main/nRadioStatus.h (rev 0)
+++ branches/energy/source/main/nRadioStatus.h 2007-10-22 15:03:09 UTC (rev 2147)
@@ -0,0 +1,13 @@
+/*
+ * nRadioStatus.h
+ * Avida
+ *
+ * Created by Benjamin Beckmann on 10/18/07.
+ * Copyright 2007 __MyCompanyName__. All rights reserved.
+ *
+ */
+
+
+namespace nRadioStatus {
+ enum {TX = 0, RX, IDLE, OFF};
+}
More information about the Avida-cvs
mailing list