[Avida-SVN] r2563 - in branches/energy/source: cpu main
connel42 at myxo.css.msu.edu
connel42 at myxo.css.msu.edu
Wed Apr 30 11:07:36 PDT 2008
Author: connel42
Date: 2008-04-30 14:07:36 -0400 (Wed, 30 Apr 2008)
New Revision: 2563
Modified:
branches/energy/source/cpu/cHardwareCPU.cc
branches/energy/source/main/cOrganism.cc
Log:
* re-enabled dropping of pheromones from movement-related instructions (move, movetarget, explore, exploit, supermove)
* explicitly setting m_pher_drop of cOrgansim to false in constructor
Modified: branches/energy/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/energy/source/cpu/cHardwareCPU.cc 2008-04-30 16:43:19 UTC (rev 2562)
+++ branches/energy/source/cpu/cHardwareCPU.cc 2008-04-30 18:07:36 UTC (rev 2563)
@@ -3180,6 +3180,10 @@
// This could be changed in the future.
const int stepsize = m_world->GetConfig().BIOMIMETIC_MOVEMENT_STEP.Get();
+ // Pheromone drop stuff
+ double pher_amount = 0;
+ int drop_mode = -1;
+
// Find if any neighbor is a target
for(int i = 0; i < mycell.ConnectionList().GetSize(); i++) {
cell_data = m_world->GetPopulation().GetCell(organism->GetCellID()).GetCellData();
@@ -3223,16 +3227,14 @@
m_world->GetStats().Move(*organism);
-/*
- // If organism is dropping pheromones, mark the appropriate cell
+
+ // If organism is dropping pheromones, mark the appropriate cell(s)
if( (m_world->GetConfig().PHEROMONE_ENABLED.Get() == 1) &&
(organism->GetPheromoneStatus() == true) ) {
-
- const double pher_amount = m_world->GetConfig().PHEROMONE_AMOUNT.Get();
- const int drop_mode = m_world->GetConfig().PHEROMONE_DROP_MODE.Get();
- cDeme &deme = pop.GetDeme(pop.GetCell(organism->GetCellID()).GetDemeID());
-
+ pher_amount = m_world->GetConfig().PHEROMONE_AMOUNT.Get();
+ drop_mode = m_world->GetConfig().PHEROMONE_DROP_MODE.Get();
+
if(drop_mode == 0) {
deme.AddPheromone(fromcellID, pher_amount/2);
deme.AddPheromone(destcellID, pher_amount/2);
@@ -3243,8 +3245,11 @@
deme.AddPheromone(destcellID, pher_amount);
}
+ // Old CellData-based version
+ //const int newval = pop.GetCell(destcellID).GetCellData() + 1;
+ //pop.GetCell(destcellID).SetCellData(newval);
+
} //End laying pheromone
-*/
// Write some logging information if LOG_PHEROMONE is set. This is done
@@ -3256,17 +3261,7 @@
int rel_srcid = deme.GetRelativeCellID(fromcellID);
int rel_destid = deme.GetRelativeCellID(destcellID);
- double pher_amount;
- const int drop_mode = m_world->GetConfig().PHEROMONE_DROP_MODE.Get();
- // By columns: update ID, org ID, source cell (relative), destination cell (relative), amount dropped, drop mode
- if( (m_world->GetConfig().PHEROMONE_ENABLED.Get() == 1) &&
- (organism->GetPheromoneStatus() == true) ) {
- pher_amount = m_world->GetConfig().PHEROMONE_AMOUNT.Get();
- } else {
- pher_amount = 0;
- }
-
cString UpdateStr = cStringUtil::Stringf("%d,%d,%d,%d,%d,%f,%d,1", m_world->GetStats().GetUpdate(), organism->GetID(), deme.GetDemeID(), rel_srcid, rel_destid, pher_amount, drop_mode);
df.WriteRaw(UpdateStr);
}
@@ -3307,6 +3302,9 @@
// This could be changed in the future.
const int stepsize = m_world->GetConfig().BIOMIMETIC_MOVEMENT_STEP.Get();
+ // Pheromone drop stuff
+ double pher_amount = 0;
+ int drop_mode = -1;
// Set num_rotations to a random number for explore -- lowest priority
const int num_neighbors = organism->GetNeighborhoodSize();
@@ -3375,16 +3373,13 @@
m_world->GetStats().Move(*organism);
-/*
- // If organism is dropping pheromones, mark the appropriate cell
+ // If organism is dropping pheromones, mark the appropriate cell(s)
if( (m_world->GetConfig().PHEROMONE_ENABLED.Get() == 1) &&
(organism->GetPheromoneStatus() == true) ) {
-
- const double pher_amount = m_world->GetConfig().PHEROMONE_AMOUNT.Get();
- const int drop_mode = m_world->GetConfig().PHEROMONE_DROP_MODE.Get();
- cDeme &deme = pop.GetDeme(pop.GetCell(organism->GetCellID()).GetDemeID());
-
+ pher_amount = m_world->GetConfig().PHEROMONE_AMOUNT.Get();
+ drop_mode = m_world->GetConfig().PHEROMONE_DROP_MODE.Get();
+
if(drop_mode == 0) {
deme.AddPheromone(fromcellID, pher_amount/2);
deme.AddPheromone(destcellID, pher_amount/2);
@@ -3395,8 +3390,11 @@
deme.AddPheromone(destcellID, pher_amount);
}
+ // Old CellData-based version
+ //const int newval = pop.GetCell(destcellID).GetCellData() + 1;
+ //pop.GetCell(destcellID).SetCellData(newval);
+
} //End laying pheromone
-*/
// Write some logging information if LOG_PHEROMONE is set. This is done
@@ -3408,17 +3406,7 @@
int rel_srcid = deme.GetRelativeCellID(fromcellID);
int rel_destid = deme.GetRelativeCellID(destcellID);
- double pher_amount;
- const int drop_mode = m_world->GetConfig().PHEROMONE_DROP_MODE.Get();
- // By columns: update ID, org ID, source cell (relative), destination cell (relative), amount dropped, drop mode
- if( (m_world->GetConfig().PHEROMONE_ENABLED.Get() == 1) &&
- (organism->GetPheromoneStatus() == true) ) {
- pher_amount = m_world->GetConfig().PHEROMONE_AMOUNT.Get();
- } else {
- pher_amount = 0;
- }
-
cString UpdateStr = cStringUtil::Stringf("%d,%d,%d,%d,%d,%f,%d,4", m_world->GetStats().GetUpdate(), organism->GetID(), deme.GetDemeID(), rel_srcid, rel_destid, pher_amount, drop_mode);
df.WriteRaw(UpdateStr);
}
@@ -3448,14 +3436,18 @@
int fromcellID, destcellID;
int cell_data;
-
+
+ // Pheromone drop stuff
+ double pher_amount = 0;
+ int drop_mode = -1;
+
// Get stepsize. Currently, all moves are one cell regardless of stepsize.
// This could be changed in the future.
const int stepsize = m_world->GetConfig().BIOMIMETIC_MOVEMENT_STEP.Get();
// Rotate randomly. Code taken from tumble.
const int num_neighbors = organism->GetNeighborhoodSize();
- for(int i = 0; i < ctx.GetRandom().GetUInt(num_neighbors); i++) {
+ for(unsigned int i = 0; i < ctx.GetRandom().GetUInt(num_neighbors); i++) {
organism->Rotate(1); // Rotate doesn't rotate N times, just once.
}
@@ -3486,16 +3478,13 @@
m_world->GetStats().Move(*organism);
-/*
- // If organism is dropping pheromones, mark the appropriate cell
+ // If organism is dropping pheromones, mark the cells appropriately
if( (m_world->GetConfig().PHEROMONE_ENABLED.Get() == 1) &&
(organism->GetPheromoneStatus() == true) ) {
-
- const double pher_amount = m_world->GetConfig().PHEROMONE_AMOUNT.Get();
- const int drop_mode = m_world->GetConfig().PHEROMONE_DROP_MODE.Get();
- cDeme &deme = pop.GetDeme(pop.GetCell(organism->GetCellID()).GetDemeID());
-
+ pher_amount = m_world->GetConfig().PHEROMONE_AMOUNT.Get();
+ drop_mode = m_world->GetConfig().PHEROMONE_DROP_MODE.Get();
+
if(drop_mode == 0) {
deme.AddPheromone(fromcellID, pher_amount/2);
deme.AddPheromone(destcellID, pher_amount/2);
@@ -3506,8 +3495,11 @@
deme.AddPheromone(destcellID, pher_amount);
}
+ // Old CellData-based version
+ //const int newval = pop.GetCell(destcellID).GetCellData() + 1;
+ //pop.GetCell(destcellID).SetCellData(newval);
+
} //End laying pheromone
-*/
// Write some logging information if LOG_PHEROMONE is set. This is done
@@ -3519,17 +3511,7 @@
int rel_srcid = deme.GetRelativeCellID(fromcellID);
int rel_destid = deme.GetRelativeCellID(destcellID);
- double pher_amount;
- const int drop_mode = m_world->GetConfig().PHEROMONE_DROP_MODE.Get();
- // By columns: update ID, org ID, source cell (relative), destination cell (relative), amount dropped, drop mode
- if( (m_world->GetConfig().PHEROMONE_ENABLED.Get() == 1) &&
- (organism->GetPheromoneStatus() == true) ) {
- pher_amount = m_world->GetConfig().PHEROMONE_AMOUNT.Get();
- } else {
- pher_amount = 0;
- }
-
cString UpdateStr = cStringUtil::Stringf("%d,%d,%d,%d,%d,%f,%d,2", m_world->GetStats().GetUpdate(), organism->GetID(), deme.GetDemeID(), rel_srcid, rel_destid, pher_amount, drop_mode);
df.WriteRaw(UpdateStr);
}
@@ -3567,6 +3549,9 @@
// This could be changed in the future.
const int stepsize = m_world->GetConfig().BIOMIMETIC_MOVEMENT_STEP.Get();
+ // Pheromone drop stuff
+ double pher_amount = 0;
+ int drop_mode = -1;
// Find which neighbor has the strongest pheromone
for(int i = 0; i < mycell.ConnectionList().GetSize(); i++) {
@@ -3619,16 +3604,13 @@
m_world->GetStats().Move(*organism);
-/*
- // If organism is dropping pheromones, mark the appropriate cell
+ // If organism is dropping pheromones, mark the appropriate cell(s)
if( (m_world->GetConfig().PHEROMONE_ENABLED.Get() == 1) &&
(organism->GetPheromoneStatus() == true) ) {
-
- const double pher_amount = m_world->GetConfig().PHEROMONE_AMOUNT.Get();
- const int drop_mode = m_world->GetConfig().PHEROMONE_DROP_MODE.Get();
- cDeme &deme = pop.GetDeme(pop.GetCell(organism->GetCellID()).GetDemeID());
-
+ pher_amount = m_world->GetConfig().PHEROMONE_AMOUNT.Get();
+ drop_mode = m_world->GetConfig().PHEROMONE_DROP_MODE.Get();
+
if(drop_mode == 0) {
deme.AddPheromone(fromcellID, pher_amount/2);
deme.AddPheromone(destcellID, pher_amount/2);
@@ -3639,9 +3621,13 @@
deme.AddPheromone(destcellID, pher_amount);
}
+ // Old CellData-based version
+ //const int newval = pop.GetCell(destcellID).GetCellData() + 1;
+ //pop.GetCell(destcellID).SetCellData(newval);
+
} //End laying pheromone
-*/
+
// Write some logging information if LOG_PHEROMONE is set. This is done
// out here so that non-pheromone moves are recorded.
if( (m_world->GetConfig().LOG_PHEROMONE.Get() == 1) &&
@@ -3651,17 +3637,7 @@
int rel_srcid = deme.GetRelativeCellID(fromcellID);
int rel_destid = deme.GetRelativeCellID(destcellID);
- double pher_amount;
- const int drop_mode = m_world->GetConfig().PHEROMONE_DROP_MODE.Get();
- // By columns: update ID, org ID, source cell (relative), destination cell (relative), amount dropped, drop mode
- if( (m_world->GetConfig().PHEROMONE_ENABLED.Get() == 1) &&
- (organism->GetPheromoneStatus() == true) ) {
- pher_amount = m_world->GetConfig().PHEROMONE_AMOUNT.Get();
- } else {
- pher_amount = 0;
- }
-
cString UpdateStr = cStringUtil::Stringf("%d,%d,%d,%d,%d,%f,%d,3", m_world->GetStats().GetUpdate(), organism->GetID(), deme.GetDemeID(), rel_srcid, rel_destid, pher_amount, drop_mode);
df.WriteRaw(UpdateStr);
}
@@ -4758,11 +4734,16 @@
// Get population
cPopulation& pop = m_world->GetPopulation();
+ cDeme &deme = pop.GetDeme(pop.GetCell(organism->GetCellID()).GetDemeID());
// Get stepsize. Currently, all moves are one cell regardless of stepsize.
// This could be changed in the future.
const int stepsize = m_world->GetConfig().BIOMIMETIC_MOVEMENT_STEP.Get();
+ // Pheromone stuff
+ double pher_amount = 0;
+ int drop_mode = -1;
+
// Code
if (0 < stepsize) {
// Current cell
@@ -4792,17 +4773,13 @@
// updates movement predicates
m_world->GetStats().Move(*organism);
-/*
- // BDC
- // If organism is dropping pheromones, mark the destination cell
+ // If organism is dropping pheromones, mark the appropriate cell(s)
if( (m_world->GetConfig().PHEROMONE_ENABLED.Get() == 1) &&
(organism->GetPheromoneStatus() == true) ) {
-
- const double pher_amount = m_world->GetConfig().PHEROMONE_AMOUNT.Get();
- const int drop_mode = m_world->GetConfig().PHEROMONE_DROP_MODE.Get();
- cDeme &deme = pop.GetDeme(pop.GetCell(organism->GetCellID()).GetDemeID());
-
+ pher_amount = m_world->GetConfig().PHEROMONE_AMOUNT.Get();
+ drop_mode = m_world->GetConfig().PHEROMONE_DROP_MODE.Get();
+
if(drop_mode == 0) {
deme.AddPheromone(fromcellID, pher_amount/2);
deme.AddPheromone(destcellID, pher_amount/2);
@@ -4818,7 +4795,6 @@
//pop.GetCell(destcellID).SetCellData(newval);
} //End laying pheromone
-*/
// Write some logging information if LOG_PHEROMONE is set. This is done
// out here so that non-pheromone moves are recorded.
@@ -4827,20 +4803,9 @@
cString tmpfilename = cStringUtil::Stringf("movelog.dat");
cDataFile& df = m_world->GetDataFile(tmpfilename);
- cDeme &deme = pop.GetDeme(pop.GetCell(organism->GetCellID()).GetDemeID());
int rel_srcid = deme.GetRelativeCellID(fromcellID);
int rel_destid = deme.GetRelativeCellID(destcellID);
- double pher_amount;
- const int drop_mode = m_world->GetConfig().PHEROMONE_DROP_MODE.Get();
- // By columns: update ID, org ID, source cell (relative), destination cell (relative), amount dropped, drop mode
- if( (m_world->GetConfig().PHEROMONE_ENABLED.Get() == 1) &&
- (organism->GetPheromoneStatus() == true) ) {
- pher_amount = m_world->GetConfig().PHEROMONE_AMOUNT.Get();
- } else {
- pher_amount = 0;
- }
-
cString UpdateStr = cStringUtil::Stringf("%d,%d,%d,%d,%d,%f,%d,5", m_world->GetStats().GetUpdate(), organism->GetID(), deme.GetDemeID(), rel_srcid, rel_destid, pher_amount, drop_mode);
df.WriteRaw(UpdateStr);
}
Modified: branches/energy/source/main/cOrganism.cc
===================================================================
--- branches/energy/source/main/cOrganism.cc 2008-04-30 16:43:19 UTC (rev 2562)
+++ branches/energy/source/main/cOrganism.cc 2008-04-30 18:07:36 UTC (rev 2563)
@@ -73,6 +73,7 @@
, m_is_dead(false)
, m_net(NULL)
, m_msg(0)
+ , m_pher_drop(false)
{
// Initialization of structures...
m_hardware = m_world->GetHardwareManager().Create(this);
More information about the Avida-cvs
mailing list