[Avida-SVN] r2531 - in branches/jobScheduling/source: cpu main
beckma24 at myxo.css.msu.edu
beckma24 at myxo.css.msu.edu
Fri Apr 11 08:18:51 PDT 2008
Author: beckma24
Date: 2008-04-11 11:18:51 -0400 (Fri, 11 Apr 2008)
New Revision: 2531
Modified:
branches/jobScheduling/source/cpu/cHardwareCPU.cc
branches/jobScheduling/source/cpu/cHardwareCPU.h
branches/jobScheduling/source/main/cAvidaConfig.h
branches/jobScheduling/source/main/cDeme.cc
branches/jobScheduling/source/main/cDeme.h
branches/jobScheduling/source/main/cPopulation.cc
branches/jobScheduling/source/main/cResourceCount.cc
branches/jobScheduling/source/main/cResourceCount.h
Log:
more instructions and energy passing code
Modified: branches/jobScheduling/source/cpu/cHardwareCPU.cc
===================================================================
--- branches/jobScheduling/source/cpu/cHardwareCPU.cc 2008-04-10 20:28:21 UTC (rev 2530)
+++ branches/jobScheduling/source/cpu/cHardwareCPU.cc 2008-04-11 15:18:51 UTC (rev 2531)
@@ -232,7 +232,10 @@
tInstLibEntry<tMethod>("rotate-left-one", &cHardwareCPU::Inst_RotateLeftOne, nInstFlag::STALL),
tInstLibEntry<tMethod>("rotate-right-one", &cHardwareCPU::Inst_RotateRightOne, nInstFlag::STALL),
tInstLibEntry<tMethod>("rotate-label", &cHardwareCPU::Inst_RotateLabel, nInstFlag::STALL),
+ tInstLibEntry<tMethod>("rotate-to-unoccupied-cell", &cHardwareCPU::Inst_RotateUnoccupiedCell, nInstFlag::STALL),
+ tInstLibEntry<tMethod>("rotate-to-occupied-cell", &cHardwareCPU::Inst_RotateOccupiedCell, nInstFlag::STALL),
+
tInstLibEntry<tMethod>("set-cmut", &cHardwareCPU::Inst_SetCopyMut),
tInstLibEntry<tMethod>("mod-cmut", &cHardwareCPU::Inst_ModCopyMut),
tInstLibEntry<tMethod>("get-cell-xy", &cHardwareCPU::Inst_GetCellPosition),
@@ -3939,6 +3942,39 @@
return true;
}
+bool cHardwareCPU::Inst_RotateUnoccupiedCell(cAvidaContext& ctx) {
+ const int reg_used = FindModifiedRegister(REG_BX);
+
+ for(int i = 0; i < organism->GetNeighborhoodSize(); i++) {
+ if(organism->IsNeighborCellOccupied()) // continue to rotate
+ continue;
+ else {
+ GetRegister(reg_used) = 1;
+ return true;
+ }
+ organism->Rotate(1);
+ }
+ GetRegister(reg_used) = 0;
+ return true;
+}
+
+bool cHardwareCPU::Inst_RotateOccupiedCell(cAvidaContext& ctx) {
+ const int reg_used = FindModifiedRegister(REG_BX);
+
+ for(int i = 0; i < organism->GetNeighborhoodSize(); i++) {
+ if(organism->IsNeighborCellOccupied()) { // continue to rotate
+ GetRegister(reg_used) = 1;
+ return true;
+ } else {
+ continue;
+ }
+ organism->Rotate(1);
+ }
+ GetRegister(reg_used) = 0;
+ return true;
+}
+
+
bool cHardwareCPU::Inst_SetCopyMut(cAvidaContext& ctx)
{
const int reg_used = FindModifiedRegister(REG_BX);
Modified: branches/jobScheduling/source/cpu/cHardwareCPU.h
===================================================================
--- branches/jobScheduling/source/cpu/cHardwareCPU.h 2008-04-10 20:28:21 UTC (rev 2530)
+++ branches/jobScheduling/source/cpu/cHardwareCPU.h 2008-04-11 15:18:51 UTC (rev 2531)
@@ -490,6 +490,8 @@
bool Inst_RotateLeftOne(cAvidaContext& ctx);
bool Inst_RotateRightOne(cAvidaContext& ctx);
bool Inst_RotateLabel(cAvidaContext& ctx);
+ bool Inst_RotateOccupiedCell(cAvidaContext& ctx);
+ bool Inst_RotateUnoccupiedCell(cAvidaContext& ctx);
bool Inst_SetCopyMut(cAvidaContext& ctx);
bool Inst_ModCopyMut(cAvidaContext& ctx);
bool Inst_GetCellPosition(cAvidaContext& ctx);
Modified: branches/jobScheduling/source/main/cAvidaConfig.h
===================================================================
--- branches/jobScheduling/source/main/cAvidaConfig.h 2008-04-10 20:28:21 UTC (rev 2530)
+++ branches/jobScheduling/source/main/cAvidaConfig.h 2008-04-11 15:18:51 UTC (rev 2531)
@@ -305,7 +305,8 @@
CONFIG_ADD_VAR(DEMES_ORGANISM_FACING, int, 0, "How organisms are facing during deme replication.\n0=unchanged (default).\n1=northwest.\n2=random.");
CONFIG_ADD_VAR(DEMES_MAX_AGE, int, 500, "The maximum age of a deme (in updates) to be\nused for age-based replication (default=500).");
CONFIG_ADD_VAR(DEMES_MAX_BIRTHS, int, 100, "The maximum number of births that can occur\nwithin a deme; used with birth-count\nreplication (default=100).");
- CONFIG_ADD_VAR(DEMES_MAX_EVENTS_KILLED, int, 100, "The maximum number of event that must be killed\nwithin a deme; used with events-killed\nreplication (default=100).");
+ CONFIG_ADD_VAR(DEMES_MIM_EVENTS_KILLED_RATIO, double, 0.7, "Minimum ratio of events killed required for event period to be a success.");
+ CONFIG_ADD_VAR(DEMES_MIM_SUCCESSFUL_EVENT_PERIODS, int, 1, "Minimum number of consecutive event periods that must be a success.");
CONFIG_ADD_VAR(GERMLINE_COPY_MUT, double, 0.0075, "Prob. of copy mutations occuring during\ngermline replication (default=0.0075).");
CONFIG_ADD_VAR(GERMLINE_INS_MUT, double, 0.05, "Prob. of an insertion mutation occuring\nduring germline replication (default=0.05).");
CONFIG_ADD_VAR(GERMLINE_DEL_MUT, double, 0.05, "Prob. of a deletion mutation occuring\nduring germline replication (default=0.05).");
@@ -472,6 +473,7 @@
CONFIG_ADD_VAR(FRAC_ENERGY_TRANSFER, double, 0.0, "Fraction of replaced organism's energy take by new resident");
CONFIG_ADD_VAR(LOG_SLEEP_TIMES, bool, 0, "Log sleep start and end times. 0/1 (off/on)\nWARNING: may use lots of memory.");
CONFIG_ADD_VAR(FRAC_ENERGY_RELINQUISH, double, 1.0, "Fraction of organisms energy to relinquish");
+ CONFIG_ADD_VAR(ENERGY_PASSED_ON_DEME_REPLICATION_METHOD, int, 0, "Who get energy passed from a parent deme\n0 = Energy divided among organisms injected to offspring deme\n1 = Energy divided among cells in offspring deme");
CONFIG_ADD_GROUP(SECOND_PASS_GROUP, "Tracking metrics known after the running experiment previously");
CONFIG_ADD_VAR(TRACK_CCLADES, int, 0, "Enable tracking of coalescence clades");
Modified: branches/jobScheduling/source/main/cDeme.cc
===================================================================
--- branches/jobScheduling/source/main/cDeme.cc 2008-04-10 20:28:21 UTC (rev 2530)
+++ branches/jobScheduling/source/main/cDeme.cc 2008-04-11 15:18:51 UTC (rev 2531)
@@ -108,6 +108,11 @@
for(vector<pair<int, int> >::iterator iter = event_slot_end_points.begin(); iter < event_slot_end_points.end(); iter++) {
if(_age == (*iter).first) {
// at end point
+ if(GetEventsKilledThisSlot() >= m_world->GetConfig().DEMES_MIM_EVENTS_KILLED_RATIO.Get() * (*iter).second)
+ consecutiveSuccessfulEventPeriods++;
+ else
+ consecutiveSuccessfulEventPeriods = 0;
+
(m_world->GetStats().FlowRateTuple())[(*iter).second].first.Add(GetOrgCount());
(m_world->GetStats().FlowRateTuple())[(*iter).second].second.Add(GetEventsKilledThisSlot());
eventsKilledThisSlot = 0;
@@ -119,6 +124,7 @@
void cDeme::Reset(bool resetResources, double deme_energy)
{
+ double additional_resource = 0.0;
// Handle energy model
if (m_world->GetConfig().ENERGY_ENABLED.Get())
{
@@ -126,20 +132,25 @@
total_energy_testament = 0.0;
- total_org_energy = deme_energy;
- if(total_org_energy < 0.0)
- total_org_energy = 0.0;
+ if(m_world->GetConfig().ENERGY_PASSED_ON_DEME_REPLICATION_METHOD.Get() == 0) {
+ total_org_energy = deme_energy;
+ if(total_org_energy < 0.0)
+ total_org_energy = 0.0;
- // split deme energy evenly between organisms in deme
- for (int i=0; i<GetSize(); i++) {
- int cellid = GetCellID(i);
- cPopulationCell& cell = m_world->GetPopulation().GetCell(cellid);
- if(cell.IsOccupied()) {
- cOrganism* organism = cell.GetOrganism();
- cPhenotype& phenotype = organism->GetPhenotype();
- phenotype.SetEnergy(phenotype.GetStoredEnergy() + total_org_energy/static_cast<double>(org_count));
- phenotype.SetMerit(cMerit(cMerit::EnergyToMerit(phenotype.GetStoredEnergy() * phenotype.GetEnergyUsageRatio(), m_world)));
+ // split deme energy evenly between organisms in deme
+ for (int i=0; i<GetSize(); i++) {
+ int cellid = GetCellID(i);
+ cPopulationCell& cell = m_world->GetPopulation().GetCell(cellid);
+ if(cell.IsOccupied()) {
+ cOrganism* organism = cell.GetOrganism();
+ cPhenotype& phenotype = organism->GetPhenotype();
+ phenotype.SetEnergy(phenotype.GetStoredEnergy() + total_org_energy/static_cast<double>(org_count));
+ phenotype.SetMerit(cMerit(cMerit::EnergyToMerit(phenotype.GetStoredEnergy() * phenotype.GetEnergyUsageRatio(), m_world)));
+ }
}
+ } else if(m_world->GetConfig().ENERGY_PASSED_ON_DEME_REPLICATION_METHOD.Get() == 1) {
+ // split deme energy evenly between cell in deme
+ additional_resource = deme_energy; // spacial resource handles resource division
}
}
@@ -151,7 +162,8 @@
eventsKilled = 0;
eventsKilledThisSlot = 0;
- if(resetResources) deme_resource_count.ReinitializeResources();
+ if(resetResources)
+ deme_resource_count.ReinitializeResources(additional_resource);
}
@@ -342,6 +354,9 @@
cOrganism* organism = cell.GetOrganism();
cPhenotype& phenotype = organism->GetPhenotype();
energy_sum += phenotype.GetStoredEnergy();
+ } else {
+ double energy_in_cell = cell.UptakeCellEnergy(1.0);
+ energy_sum += energy_in_cell * m_world->GetConfig().FRAC_ENERGY_TRANSFER.Get();
}
}
return energy_sum;
@@ -389,3 +404,14 @@
}
+int cDeme::GetSlotFlowRate() const {
+ vector<pair<int, int> >::const_iterator iter = event_slot_end_points.begin();
+ while(iter != event_slot_end_points.end()) {
+ if(GetAge() <= (*iter).first) {
+ return (*iter).second;
+ }
+ iter++;
+ }
+ assert(false); // slots must be of equal size and fit perfectally in deme lifetime
+ return 0;
+}
Modified: branches/jobScheduling/source/main/cDeme.h
===================================================================
--- branches/jobScheduling/source/main/cDeme.h 2008-04-10 20:28:21 UTC (rev 2530)
+++ branches/jobScheduling/source/main/cDeme.h 2008-04-11 15:18:51 UTC (rev 2531)
@@ -63,6 +63,7 @@
double last_normalized_time_used;
unsigned int eventsKilled;
unsigned int eventsKilledThisSlot;
+ unsigned int consecutiveSuccessfulEventPeriods;
// End of phenotypic traits
@@ -86,7 +87,7 @@
public:
cDeme() : _id(0), width(0), birth_count(0), org_count(0), _age(0), generation(0), total_org_energy(0.0), total_energy_testament(0.0),
time_used(0), gestation_time(0), cur_normalized_time_used(0.0), last_normalized_time_used(0.0),
- eventsKilled(0), eventsKilledThisSlot(0), deme_resource_count(0), m_germline_genotype_id(0) { ; }
+ eventsKilled(0), eventsKilledThisSlot(0), consecutiveSuccessfulEventPeriods(0), deme_resource_count(0), m_germline_genotype_id(0) { ; }
~cDeme() { ; }
void Setup(int id, const tArray<int>& in_cells, int in_width = -1, cWorld* world = NULL);
@@ -116,8 +117,10 @@
int GetGeneration() const { return generation; }
+ int GetSlotFlowRate() const;
int GetEventsKilled() const { return eventsKilled; }
int GetEventsKilledThisSlot() const { return eventsKilledThisSlot;}
+ int GetConsecutiveSuccessfulEventPeriods() const { return consecutiveSuccessfulEventPeriods;}
bool IsEmpty() const { return org_count == 0; }
bool IsFull() const { return org_count == cell_ids.GetSize(); }
Modified: branches/jobScheduling/source/main/cPopulation.cc
===================================================================
--- branches/jobScheduling/source/main/cPopulation.cc 2008-04-10 20:28:21 UTC (rev 2530)
+++ branches/jobScheduling/source/main/cPopulation.cc 2008-04-11 15:18:51 UTC (rev 2531)
@@ -1148,8 +1148,13 @@
break;
}
case 5: {
+ int currentSlotSuccessful = 0;
+ double kill_ratio = static_cast<double>(source_deme.GetEventsKilledThisSlot()) / static_cast<double>(source_deme.GetSlotFlowRate());
+ if(kill_ratio >= m_world->GetConfig().DEMES_MIM_EVENTS_KILLED_RATIO.Get())
+ currentSlotSuccessful = 1;
+
// Replicate demes that have killed a certain number of event.
- if(source_deme.GetEventsKilled() < m_world->GetConfig().DEMES_MAX_EVENTS_KILLED.Get()) continue;
+ if(source_deme.GetConsecutiveSuccessfulEventPeriods()+currentSlotSuccessful < m_world->GetConfig().DEMES_MIM_SUCCESSFUL_EVENT_PERIODS.Get()) continue;
break;
}
default: {
@@ -1174,7 +1179,7 @@
if(m_world->GetConfig().DEMES_PREVENT_STERILE.Get() && (source_deme.GetBirthCount() == 0)) {
return;
}
-
+
//Option to bridge between kin and group selection.
if (m_world->GetConfig().DEMES_REPLICATION_ONLY_RESETS.Get())
{
Modified: branches/jobScheduling/source/main/cResourceCount.cc
===================================================================
--- branches/jobScheduling/source/main/cResourceCount.cc 2008-04-10 20:28:21 UTC (rev 2530)
+++ branches/jobScheduling/source/main/cResourceCount.cc 2008-04-11 15:18:51 UTC (rev 2531)
@@ -492,8 +492,8 @@
}
}
-void cResourceCount::ReinitializeResources(){
+void cResourceCount::ReinitializeResources(double additional_resource){
for(int i = 0; i < resource_name.GetSize(); i++) {
- Set(i, resource_initial[i]);
+ Set(i, resource_initial[i]+additional_resource);
}
}
Modified: branches/jobScheduling/source/main/cResourceCount.h
===================================================================
--- branches/jobScheduling/source/main/cResourceCount.h 2008-04-10 20:28:21 UTC (rev 2530)
+++ branches/jobScheduling/source/main/cResourceCount.h 2008-04-11 15:18:51 UTC (rev 2531)
@@ -105,7 +105,7 @@
double Get(int id) const;
void ResizeSpatialGrids(int in_x, int in_y);
cSpatialResCount GetSpatialResource(int id) { return spatial_resource_count[id]; }
- void ReinitializeResources();
+ void ReinitializeResources(double additional_resource);
cString GetResName(int id) { return resource_name[id]; }
};
More information about the Avida-cvs
mailing list