[Avida-SVN] r3012 - in development/source: cpu main
connel42 at myxo.css.msu.edu
connel42 at myxo.css.msu.edu
Mon Dec 8 10:43:36 PST 2008
Author: connel42
Date: 2008-12-08 13:43:36 -0500 (Mon, 08 Dec 2008)
New Revision: 3012
Modified:
development/source/cpu/cHardwareCPU.cc
development/source/cpu/cHardwareCPU.h
development/source/main/cAvidaConfig.h
development/source/main/cOrganism.cc
development/source/main/cOrganism.h
Log:
* Added update-metabolic-rate instruction, allowing organisms to re-calculate their current metabolic rate.\n* Added increase- and decrease-energy-donation instructions to allow organisms to modify the amount of energy that they donate
Modified: development/source/cpu/cHardwareCPU.cc
===================================================================
--- development/source/cpu/cHardwareCPU.cc 2008-12-08 17:57:55 UTC (rev 3011)
+++ development/source/cpu/cHardwareCPU.cc 2008-12-08 18:43:36 UTC (rev 3012)
@@ -226,11 +226,14 @@
tInstLibEntry<tMethod>("donate-facing", &cHardwareCPU::Inst_DonateFacing),
tInstLibEntry<tMethod>("receive-donated-energy", &cHardwareCPU::Inst_ReceiveDonatedEnergy, nInstFlag::STALL),
tInstLibEntry<tMethod>("donate-energy", &cHardwareCPU::Inst_DonateEnergy, nInstFlag::STALL),
+ tInstLibEntry<tMethod>("update-metabolic-rate", &cHardwareCPU::Inst_UpdateMetabolicRate, nInstFlag::STALL),
tInstLibEntry<tMethod>("donate-energy-faced", &cHardwareCPU::Inst_DonateEnergyFaced, nInstFlag::STALL),
tInstLibEntry<tMethod>("rotate-to-most-needy", &cHardwareCPU::Inst_RotateToMostNeedy, nInstFlag::STALL),
tInstLibEntry<tMethod>("request-energy", &cHardwareCPU::Inst_RequestEnergy, nInstFlag::STALL),
tInstLibEntry<tMethod>("request-energy-on", &cHardwareCPU::Inst_RequestEnergyFlagOn, nInstFlag::STALL),
tInstLibEntry<tMethod>("request-energy-off", &cHardwareCPU::Inst_RequestEnergyFlagOff, nInstFlag::STALL),
+ tInstLibEntry<tMethod>("increase-energy-donation", &cHardwareCPU::Inst_IncreaseEnergyDonation, nInstFlag::STALL),
+ tInstLibEntry<tMethod>("decrease-energy-donation", &cHardwareCPU::Inst_DecreaseEnergyDonation, nInstFlag::STALL),
tInstLibEntry<tMethod>("IObuf-add1", &cHardwareCPU::Inst_IOBufAdd1, nInstFlag::STALL),
tInstLibEntry<tMethod>("IObuf-add0", &cHardwareCPU::Inst_IOBufAdd0, nInstFlag::STALL),
@@ -3488,7 +3491,7 @@
{
assert(to_org != NULL);
- const double frac_energy_given = m_world->GetConfig().MERIT_GIVEN.Get();
+ const double frac_energy_given = m_organism->GetFracEnergyDonating();
double cur_energy = m_organism->GetPhenotype().GetStoredEnergy();
double energy_given = cur_energy * frac_energy_given;
@@ -3526,9 +3529,6 @@
double energy_given = cur_energy * frac_energy_given;
//update energy store and merit of donor
-#ifdef DEBUG_ENERGY_DONATION
- cout << " donating " << energy_given << " energy to organism " << to_org->GetID() << endl;
-#endif
m_organism->GetPhenotype().ReduceEnergy(energy_given);
m_organism->GetPhenotype().IncreaseEnergyDonated(energy_given);
double senderMerit = cMerit::EnergyToMerit(m_organism->GetPhenotype().GetStoredEnergy() * m_organism->GetPhenotype().GetEnergyUsageRatio(), m_world);
@@ -4058,24 +4058,13 @@
if(m_organism->GetCellID() < 0) {
return false;
}
-#ifdef DEBUG_ENERGY_DONATION
- cout << "organism " << m_organism->GetCellID() << " receiving donated energy (if any)" << endl;
-#endif
if(m_organism->GetPhenotype().GetEnergyInBufferAmount() > 0) {
-#ifdef DEBUG_ENERGY_DONATION
- cout << " received " << m_organism->GetPhenotype().GetEnergyInBufferAmount() << endl;
-#endif
m_organism->GetPhenotype().ApplyDonatedEnergy();
m_organism->GetPhenotype().SetHasUsedDonatedEnergy();
double receiverMerit = cMerit::EnergyToMerit(m_organism->GetPhenotype().GetStoredEnergy() * m_organism->GetPhenotype().GetEnergyUsageRatio(), m_world);
m_organism->UpdateMerit(receiverMerit);
}
-#ifdef DEBUG_ENERGY_DONATION
- else {
- cout << " no energy to receive!" << endl;
- }
-#endif
return true;
@@ -4088,15 +4077,9 @@
if(m_organism->GetCellID() < 0) {
return false;
}
-#ifdef DEBUG_ENERGY_DONATION
- cout << "organism " << m_organism->GetCellID() << " donating energy..." << endl;
-#endif
const cOrgMessage* msg = m_organism->RetrieveMessage();
if(msg == 0) {
-#ifdef DEBUG_ENERGY_DONATION
- cout << " no energy requests" << endl;
-#endif
return false;
}
@@ -4104,33 +4087,20 @@
* be any good. Instead, we should use the cell and organism ID of the
* message sender to get hold of the sender (if it still exists and hasn't moved)
*/
- /*
- cOrganism* receiver = msg->GetSender();
- // If the requestor no longer exists, should the donor still lose energy???
- if( (receiver == NULL) || (receiver->IsDead()) ) {
- return false;
- }
- */
cPopulationCell senderCell = m_world->GetPopulation().GetCell(msg->GetSenderCellID());
if (!senderCell.IsOccupied()) {
-#ifdef DEBUG_ENERGY_DONATION
- cout << " requestor has died!" << endl;
-#endif
// the organism that made the request is gone, we can't donate...
return false;
}
cOrganism* energyReceiver = senderCell.GetOrganism();
if (energyReceiver->GetID() != msg->GetSenderOrgID()) {
-#ifdef DEBUG_ENERGY_DONATION
- cout << " requestor has been replaced!" << endl;
-#endif
// some other organism has occupied this cell since the msg was sent,
// we can't donate...
return false;
}
- DoEnergyDonatePercent(energyReceiver, m_world->GetConfig().ENERGY_SHARING_PCT.Get());
+ DoEnergyDonatePercent(energyReceiver, m_organism->GetFracEnergyDonating());
m_organism->GetPhenotype().IncDonates();
m_organism->GetOrgInterface().GetDeme()->IncEnergyDonationsMade();
m_organism->GetPhenotype().SetIsEnergyDonor();
@@ -4140,6 +4110,16 @@
} //End Inst_DonateEnergy()
+//Update the organism's metabolic rate
+bool cHardwareCPU::Inst_UpdateMetabolicRate(cAvidaContext& ctx)
+{
+ double newmerit = cMerit::EnergyToMerit(m_organism->GetPhenotype().GetStoredEnergy() * m_organism->GetPhenotype().GetEnergyUsageRatio(), m_world);
+ m_organism->UpdateMerit(newmerit);
+
+ return true;
+} //End Inst_UpdateMetabolocRate()
+
+
//Donate a fraction of organism's energy to faced organism.
bool cHardwareCPU::Inst_DonateEnergyFaced(cAvidaContext& ctx)
{
@@ -4152,9 +4132,9 @@
if ( (neighbor != NULL) && (!neighbor->IsDead()) ) {
// If the neighbor has requested energy or if we're allowing push sharing, share energy
- if ( (neighbor->GetPhenotype().HasOpenEnergyRequest()) || (m_world->GetConfig().ENERGY_SHARING_PCT.Get() == 1) )
+ if ( (neighbor->GetPhenotype().HasOpenEnergyRequest()) || (m_world->GetConfig().ENERGY_SHARING_METHOD.Get() == 1) )
{
- DoEnergyDonatePercent(neighbor, m_world->GetConfig().ENERGY_SHARING_PCT.Get());
+ DoEnergyDonatePercent(neighbor, m_organism->GetFracEnergyDonating());
m_organism->GetPhenotype().IncDonates();
m_organism->GetOrgInterface().GetDeme()->IncEnergyDonationsMade();
m_organism->GetPhenotype().SetIsEnergyDonor();
@@ -4214,12 +4194,7 @@
if(m_organism->GetCellID() < 0) {
return false;
}
-#ifdef DEBUG_ENERGY_DONATION
- cout << "organism " << m_organism->GetCellID() << " requesting energy!" << endl;
-#endif
-
- //TODO: BDC: somehow use nop modifiers to pick a multiplier for the amount of energy to request
-
+
cOrgMessage msg(m_organism);
// Could set the data field of the message to be the multiplier
@@ -4258,6 +4233,32 @@
} //End Inst_RequestEnergyFlagOff()
+// Increase the amount of energy to be donated
+bool cHardwareCPU::Inst_IncreaseEnergyDonation(cAvidaContext& ctx)
+{
+ double curr_amount = m_organism->GetFracEnergyDonating();
+ double increment = m_world->GetConfig().ENERGY_SHARING_INCREMENT.Get();
+
+ m_organism->SetFracEnergyDonating(min(1.0, curr_amount + increment));
+
+ return true;
+
+} //End Inst_IncreaseEnergyDonation()
+
+
+// Decrease the amount of energy to be donated
+bool cHardwareCPU::Inst_DecreaseEnergyDonation(cAvidaContext& ctx)
+{
+ double curr_amount = m_organism->GetFracEnergyDonating();
+ double increment = m_world->GetConfig().ENERGY_SHARING_INCREMENT.Get();
+
+ m_organism->SetFracEnergyDonating(max(0.0, curr_amount - increment));
+
+ return true;
+
+} //End Inst_DecreaseEnergyDonation()
+
+
bool cHardwareCPU::Inst_SearchF(cAvidaContext& ctx)
{
ReadLabel();
Modified: development/source/cpu/cHardwareCPU.h
===================================================================
--- development/source/cpu/cHardwareCPU.h 2008-12-08 17:57:55 UTC (rev 3011)
+++ development/source/cpu/cHardwareCPU.h 2008-12-08 18:43:36 UTC (rev 3012)
@@ -488,12 +488,15 @@
bool Inst_DonateFacing(cAvidaContext& ctx);
bool Inst_ReceiveDonatedEnergy(cAvidaContext& ctx);
bool Inst_DonateEnergy(cAvidaContext& ctx);
+ bool Inst_UpdateMetabolicRate(cAvidaContext& ctx);
bool Inst_DonateEnergyFaced(cAvidaContext& ctx);
bool Inst_RotateToMostNeedy(cAvidaContext& ctx);
bool Inst_RequestEnergy(cAvidaContext& ctx);
bool Inst_RequestEnergyFlagOn(cAvidaContext& ctx);
bool Inst_RequestEnergyFlagOff(cAvidaContext& ctx);
-
+ bool Inst_IncreaseEnergyDonation(cAvidaContext& ctx);
+ bool Inst_DecreaseEnergyDonation(cAvidaContext& ctx);
+
bool Inst_SearchF(cAvidaContext& ctx);
bool Inst_SearchB(cAvidaContext& ctx);
bool Inst_MemSize(cAvidaContext& ctx);
Modified: development/source/main/cAvidaConfig.h
===================================================================
--- development/source/main/cAvidaConfig.h 2008-12-08 17:57:55 UTC (rev 3011)
+++ development/source/main/cAvidaConfig.h 2008-12-08 18:43:36 UTC (rev 3012)
@@ -514,6 +514,7 @@
CONFIG_ADD_GROUP(ENERGY_SHARING_GROUP, "Energy Sharing Settings");
CONFIG_ADD_VAR(ENERGY_SHARING_METHOD, int, 0, "Method for sharing energy. 0=receiver must actively receive/request, 1=energy pushed on receiver");
CONFIG_ADD_VAR(ENERGY_SHARING_PCT, double, 0.0, "Percent of energy to share");
+ CONFIG_ADD_VAR(ENERGY_SHARING_INCREMENT, double, 0.01, "Amount to change percent energy shared");
CONFIG_ADD_VAR(ENERGY_SHARING_LOSS, double, 0.0, "Percent of shared energy lost in transfer");
CONFIG_ADD_GROUP(SECOND_PASS_GROUP, "Tracking metrics known after the running experiment previously");
Modified: development/source/main/cOrganism.cc
===================================================================
--- development/source/main/cOrganism.cc 2008-12-08 17:57:55 UTC (rev 3011)
+++ development/source/main/cOrganism.cc 2008-12-08 18:43:36 UTC (rev 3012)
@@ -71,6 +71,7 @@
, m_sent_active(false)
, m_test_receive_pos(0)
, m_pher_drop(false)
+ , frac_energy_donating(m_world->GetConfig().ENERGY_SHARING_PCT.Get())
, m_max_executed(-1)
, m_is_running(false)
, m_is_sleeping(false)
@@ -104,6 +105,7 @@
, m_sent_active(false)
, m_test_receive_pos(0)
, m_pher_drop(false)
+ , frac_energy_donating(m_world->GetConfig().ENERGY_SHARING_PCT.Get())
, m_max_executed(-1)
, m_is_running(false)
, m_is_sleeping(false)
Modified: development/source/main/cOrganism.h
===================================================================
--- development/source/main/cOrganism.h 2008-12-08 17:57:55 UTC (rev 3011)
+++ development/source/main/cOrganism.h 2008-12-08 18:43:36 UTC (rev 3012)
@@ -124,6 +124,7 @@
double m_gradient_movement; // TEMP. Remove once movement tasks are implemented.
bool m_pher_drop; // Is the organism dropping pheromone?
+ double frac_energy_donating; // What fraction of the organism's energy is it donating
int m_max_executed; // Max number of instruction executed before death.
bool m_is_running; // Does this organism have the CPU?
@@ -221,6 +222,9 @@
void TogglePheromone() { m_pher_drop = (m_pher_drop == true) ? false : true; }
void SetPheromone(bool newval) { m_pher_drop = newval; }
+ double GetFracEnergyDonating() { return frac_energy_donating; }
+ void SetFracEnergyDonating(double newval) { assert(newval >= 0); assert(newval <= 1); frac_energy_donating = newval; }
+
const cStateGrid& GetStateGrid() const;
More information about the Avida-cvs
mailing list