[Avida-SVN] r2936 - in branches/movement/source: actions main

grabow38 at myxo.css.msu.edu grabow38 at myxo.css.msu.edu
Tue Nov 11 17:37:19 PST 2008


Author: grabow38
Date: 2008-11-11 20:37:19 -0500 (Tue, 11 Nov 2008)
New Revision: 2936

Modified:
   branches/movement/source/actions/PopulationActions.cc
   branches/movement/source/main/cDeme.cc
   branches/movement/source/main/cDeme.h
   branches/movement/source/main/cPopulation.cc
   branches/movement/source/main/cPopulation.h
   branches/movement/source/main/cResourceCount.cc
   branches/movement/source/main/cResourceCount.h
   branches/movement/source/main/cSpatialCountElem.cc
   branches/movement/source/main/cSpatialCountElem.h
   branches/movement/source/main/cSpatialResCount.cc
   branches/movement/source/main/cSpatialResCount.h
Log:
Bug fix for spatial resource initialization, plus some cleanup and optimization (by David Bryson) in some deme-related code.

Modified: branches/movement/source/actions/PopulationActions.cc
===================================================================
--- branches/movement/source/actions/PopulationActions.cc	2008-11-11 22:15:08 UTC (rev 2935)
+++ branches/movement/source/actions/PopulationActions.cc	2008-11-12 01:37:19 UTC (rev 2936)
@@ -1708,10 +1708,11 @@
     virtual double Fitness(const cDeme& deme) {    
 	
 	
-	double current_res = 0.0;										// Current total resource in deme
-	double initial_res = 0.0;										// Current initial resource in deme
+	double current_res = 0.0;                   // Current total resource in deme
+	double initial_res = 0.0;                   // Current initial resource in deme
 	tArray<double> init_counts = deme.GetDemeInitCellResSum();		// Initial counts of all resources
-	tArray<double> curr_counts = deme.GetDemeCurrentCellResSum();	// Current counts of all resources
+  tArray<double> curr_counts;
+  deme.GetDemeCurrentCellResSum(curr_counts); // Current counts of all resources
 		
 	// Total all initial resources and current resources (if there are multiple resources)
 	for (int i = 0; i< curr_counts.GetSize(); i++) { 
@@ -1743,7 +1744,8 @@
 	
 	  cResourceCount res = deme.GetDemeResourceCount();				// Deme resource count
 	  tArray<double> init_counts = deme.GetDemeInitCellResSum();	// Initial counts of all resources
-	  tArray<double> curr_counts = deme.GetDemeCurrentCellResSum();	// Current counts of all resources
+    tArray<double> curr_counts;
+    deme.GetDemeCurrentCellResSum(curr_counts);   // Current counts of all resources
 	  double current_good_res = 0.0;								// Current total good resource in deme                                                                                                            
 	  double initial_good_res = 0.0;								// Initial total good resource in deme
 	  double current_poison = 0.0;									// Current total poison in deme

Modified: branches/movement/source/main/cDeme.cc
===================================================================
--- branches/movement/source/main/cDeme.cc	2008-11-11 22:15:08 UTC (rev 2935)
+++ branches/movement/source/main/cDeme.cc	2008-11-12 01:37:19 UTC (rev 2936)
@@ -45,7 +45,7 @@
   last_org_count = 0;
   birth_count_perslot = 0;
   m_world = world;
-
+  
   _current_merit = 1.0;
   _next_merit = 1.0;
   
@@ -60,7 +60,7 @@
   last_task_exe_count.SetAll(0);
   last_reaction_count.ResizeClear(num_reactions);
   last_reaction_count.SetAll(0);
-
+  
   cur_org_task_count.Resize(num_tasks);
   cur_org_task_count.SetAll(0);
   cur_org_task_exe_count.Resize(num_tasks);
@@ -76,7 +76,7 @@
   
   energy_requests_made = 0;
   energy_donations_made = 0;
-
+  
   // If width is negative, set it to the full number of cells.
   width = in_width;
   if (width < 1) width = cell_ids.GetSize();
@@ -89,20 +89,20 @@
 {
   assert(x >= 0 && x < GetWidth());
   assert(y >= 0 && y < GetHeight());
-
+  
   const int pos = y * width + x;
   return cell_ids[pos];
 }
 
 
 /*! Note that for this method to work, we blatantly assume that IDs are in
-monotonically increasing order!! */
+ monotonically increasing order!! */
 std::pair<int, int> cDeme::GetCellPosition(int cellid) const 
 {
   assert(cell_ids.GetSize()>0);
   assert(GetWidth() > 0);
-//  cellid -= cell_ids[0];
-//  return std::make_pair(cellid % GetWidth(), cellid / GetWidth());
+  //  cellid -= cell_ids[0];
+  //  return std::make_pair(cellid % GetWidth(), cellid / GetWidth());
   return std::make_pair(cellid % GetWidth(), ( cellid % cell_ids.GetSize() ) / GetWidth());
 }
 
@@ -120,19 +120,19 @@
 
 void cDeme::ProcessUpdate() {
   energyUsage.Clear();
-
+  
   if(IsEmpty()) {  // deme is not processed if no organisms are present
     total_energy_testament = 0.0;
     return;
   }
-
+  
   for(int i = 0; i < GetSize(); i++) {
     cPopulationCell& cell = GetCell(i);
     if(cell.IsOccupied()) {
       energyUsage.Add(cell.GetOrganism()->GetPhenotype().GetEnergyUsageRatio());
     }
   }  
-
+  
   for(int i = 0; i < cell_events.Size(); i++) {
     cDemeCellEvent& event = cell_events[i];
     
@@ -175,8 +175,8 @@
         // record activation of each cell in stats
         std::pair<int, int> pos = GetCellPosition(eventCell);
         m_world->GetStats().IncEventCount(pos.first, pos.second);
-
-
+        
+        
         //TODO // increase outflow of energy from these cells if not event currently present
         
         
@@ -188,9 +188,9 @@
         if(event.GetEventID() == m_world->GetPopulation().GetCell(GetCellID(eventCell)).GetCellData()) { // eventID == CellData
           //set cell data to 0
           m_world->GetPopulation().GetCell(GetCellID(eventCell)).SetCellData(0);
-
-        //  TODO // remove energy outflow from these cells
-
+          
+          //  TODO // remove energy outflow from these cells
+          
         }
         eventCell = event.GetNextEventCellID();
       }
@@ -208,7 +208,7 @@
       
       // update stats.flow_rate_tuples
       std::map<int, flow_rate_tuple>& flowRateTuples = m_world->GetStats().FlowRateTuples();
-
+      
       flowRateTuples[(*iter).second].orgCount.Add(GetOrgCount());
       flowRateTuples[(*iter).second].eventsKilled.Add(GetEventsKilledThisSlot());
       flowRateTuples[(*iter).second].attemptsToKillEvents.Add(GetEventKillAttemptsThisSlot());
@@ -238,7 +238,7 @@
       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);
@@ -278,7 +278,7 @@
   
   cur_task_exe_count.SetAll(0);
   cur_reaction_count.SetAll(0);
-
+  
   //reset remaining message predicates
   for(int i = 0; i < message_pred_list.Size(); i++) {
     (*message_pred_list[i]).Reset();
@@ -287,14 +287,14 @@
   for(int i = 0; i < movement_pred_list.Size(); i++) {
     (*movement_pred_list[i]).Reset();
   }
-
+  
   if(resetResources) {
     deme_resource_count.ReinitializeResources(additional_resource);
-	
-	// @ LMG
-	if ( m_world->GetConfig().DEMES_SUM_INIT_CELL_RES.Get() ) {
-	   DoSumDemeCellResources(deme_init_spatial_res_count);
-	}
+    
+    // @ LMG
+    if ( m_world->GetConfig().DEMES_SUM_INIT_CELL_RES.Get() ) {
+      DoSumDemeCellResources(deme_init_spatial_res_count);
+    }
   }
 }
 
@@ -303,7 +303,7 @@
 {
   // the parent might be us, so save this value...
   double old_avg_founder_generation = parent_deme.GetAvgFounderGeneration();
-
+  
   // update our average founder generation
   cDoubleSum gen;  
   for (int i=0; i< m_founder_phenotypes.GetSize(); i++) {
@@ -313,7 +313,7 @@
   
   // update our generations per lifetime based on current founders and parents generation
   generations_per_lifetime = avg_founder_generation - old_avg_founder_generation;
-
+  
   //Save statistics according to parent before reset.
   generation = parent_deme.GetGeneration() + 1;
   gestation_time = parent_deme.GetTimeUsed();
@@ -321,14 +321,14 @@
   
   last_task_exe_count = parent_deme.GetCurTaskExeCount();
   last_reaction_count = parent_deme.GetCurReactionCount();
-
+  
   last_org_task_count = parent_deme.GetCurOrgTaskCount();
   last_org_task_exe_count = parent_deme.GetCurOrgTaskExeCount();
   last_org_reaction_count = parent_deme.GetCurOrgReactionCount();
   
   last_org_count = parent_deme.GetLastOrgCount(); // Org count was updated upon KillAll()....
   last_birth_count = parent_deme.GetBirthCount();
-
+  
   Reset(resetResources, deme_energy);
 }
 
@@ -369,7 +369,7 @@
       if(m_world->GetPopulation().GetCell(cellid).IsOccupied()) {
         count += (m_world->GetPopulation().GetCell(cellid).GetOrganism()->GetPhenotype().GetLastTaskCount()[j] > 0);
       }
-     cur_org_task_count[j] = count; 
+      cur_org_task_count[j] = count; 
     }
   }
   
@@ -380,35 +380,35 @@
       if(m_world->GetPopulation().GetCell(cellid).IsOccupied()) {
         count += m_world->GetPopulation().GetCell(cellid).GetOrganism()->GetPhenotype().GetLastTaskCount()[j];
       }
-     cur_org_task_exe_count[j] = count; 
+      cur_org_task_exe_count[j] = count; 
     }
   }
-
- for(int j = 0; j < cur_org_reaction_count.GetSize(); j++) {
+  
+  for(int j = 0; j < cur_org_reaction_count.GetSize(); j++) {
     int count = 0;
     for(int k=0; k<GetSize(); k++) {
       int cellid = GetCellID(k);
       if(m_world->GetPopulation().GetCell(cellid).IsOccupied()) {
         count += m_world->GetPopulation().GetCell(cellid).GetOrganism()->GetPhenotype().GetLastReactionCount()[j];
       }
-     cur_org_reaction_count[j] = count; 
+      cur_org_reaction_count[j] = count; 
     }
   }
 }
 
 
 /*! Replacing this deme's germline has the effect of changing the deme's lineage.
-There's still some work to do here; the lineage labels of the Genomes in the germline
-are all messed up.
-*/
+ There's still some work to do here; the lineage labels of the Genomes in the germline
+ are all messed up.
+ */
 void cDeme::ReplaceGermline(const cGermline& germline) {
 	_germline = germline;
 }
 
 
 /*! If this method is called, this is the "parent" deme.  As with individuals,
-we need to rotate the heritable merit to the current merit.
-*/
+ we need to rotate the heritable merit to the current merit.
+ */
 void cDeme::UpdateDemeMerit() {
   assert(_next_merit.GetDouble()>=1.0);
   _current_merit = _next_merit;
@@ -417,7 +417,7 @@
 
 
 /*! Update this deme's merit from the given source.
-*/
+ */
 void cDeme::UpdateDemeMerit(cDeme& source) {
   _current_merit = source.GetHeritableDemeMerit();
   _next_merit = 1.0;
@@ -436,16 +436,16 @@
   //addjust the resources cell list pointer here if we want CELL env. commands to be replicated in each deme
   
   deme_resource_count.Setup(id, res->GetName(), res->GetInitial(), 
-                           res->GetInflow(), decay,
-                           res->GetGeometry(), res->GetXDiffuse(),
-                           res->GetXGravity(), res->GetYDiffuse(), 
-                           res->GetYGravity(), res->GetInflowX1(), 
-                           res->GetInflowX2(), res->GetInflowY1(), 
-                           res->GetInflowY2(), res->GetOutflowX1(), 
-                           res->GetOutflowX2(), res->GetOutflowY1(), 
-                           res->GetOutflowY2(), res->GetCellListPtr(),
-                           verbosity);
-                           
+                            res->GetInflow(), decay,
+                            res->GetGeometry(), res->GetXDiffuse(),
+                            res->GetXGravity(), res->GetYDiffuse(), 
+                            res->GetYGravity(), res->GetInflowX1(), 
+                            res->GetInflowX2(), res->GetInflowY1(), 
+                            res->GetInflowY2(), res->GetOutflowX1(), 
+                            res->GetOutflowX2(), res->GetOutflowY1(), 
+                            res->GetOutflowY2(), res->GetCellListPtr(),
+                            verbosity);
+  
   if(res->GetEnergyResource()) {
     energy_res_ids.Push(id);
   }  
@@ -468,52 +468,51 @@
   deme_res_count_array.Resize(deme_resource_count.GetSize());
   deme_res_count_array.SetAll(0.0);
   
- // cout << "Cell resource array size: " << cell_res_counts.GetSize() << endl;
- // cout << "Deme resource array size: " << deme_res_count_array.GetSize() << endl;
+  // cout << "Cell resource array size: " << cell_res_counts.GetSize() << endl;
+  // cout << "Deme resource array size: " << deme_res_count_array.GetSize() << endl;
   
   for (int i = 0; i < cell_ids.GetSize(); i++) {
     cell_res_counts = deme_resource_count.GetCellResources(i);
-//	cout << "Deme res count " << deme_resource_count.GetSize() << endl;
+    //	cout << "Deme res count " << deme_resource_count.GetSize() << endl;
     for (int j = 0; j < deme_resource_count.GetSize(); j++) {
-	  if ( cell_res_counts[j] > 0.0 ) {
-		deme_res_count_array[j] += cell_res_counts[j];
-		//cout << "Deme resource array position " << j << " Res name " << deme_resource_count.GetResName(j)
-		//	 << " res amount " << deme_res_count_array[j] << " Cell res amt " << cell_res_counts[j] << endl;
-	  }
-	}
+      if ( cell_res_counts[j] > 0.0 ) {
+        deme_res_count_array[j] += cell_res_counts[j];
+        //cout << "Deme resource array position " << j << " Res name " << deme_resource_count.GetResName(j)
+        //	 << " res amount " << deme_res_count_array[j] << " Cell res amt " << cell_res_counts[j] << endl;
+      }
+    }
   }
 }
-  
-const tArray<double>& cDeme::GetDemeCurrentCellResSum() const
+
+void cDeme::GetDemeCurrentCellResSum(tArray<double>& deme_res_count_array) const
 {
-   tArray<double> cell_res_counts;
-   tArray<double> deme_res_count_array;
+  tArray<double> cell_res_counts;
+  
   cell_res_counts.Resize(deme_resource_count.GetSize());
   deme_res_count_array.Resize(deme_resource_count.GetSize());
   deme_res_count_array.SetAll(0.0);
   cell_res_counts.Resize(deme_resource_count.GetSize());
- 
+  
   deme_res_count_array.SetAll(0.0);
   
   for (int i = 0; i < cell_ids.GetSize(); i++) {
     cell_res_counts = deme_resource_count.GetCellResources(i);
     for (int j = 0; j < deme_resource_count.GetSize(); j++) {
-	  if ( cell_res_counts[j] > 0.0 ) {
-	    deme_res_count_array[j] += cell_res_counts[j];
-	  }
-	}
+      if ( cell_res_counts[j] > 0.0 ) {
+        deme_res_count_array[j] += cell_res_counts[j];
+      }
+    }
   }
-		return deme_res_count_array;
 }
 
 double cDeme::GetAndClearCellEnergy(int absolute_cell_id) {
   assert(cell_ids[0] <= absolute_cell_id);
   assert(absolute_cell_id <= cell_ids[cell_ids.GetSize()-1]);
-
+  
   double total_energy = 0.0;
   int relative_cell_id = GetRelativeCellID(absolute_cell_id);
   tArray<double> cell_resources = deme_resource_count.GetCellResources(relative_cell_id);
-
+  
   // sum all energy resources
   for(int i = 0; i < energy_res_ids.GetSize(); i++) {
     if(cell_resources[energy_res_ids[i]] > 0.0) {
@@ -529,10 +528,10 @@
 void cDeme::GiveBackCellEnergy(int absolute_cell_id, double value) {
   assert(cell_ids[0] <= absolute_cell_id);
   assert(absolute_cell_id <= cell_ids[cell_ids.GetSize()-1]);
-
+  
   int relative_cell_id = GetRelativeCellID(absolute_cell_id);
   tArray<double> cell_resources = deme_resource_count.GetCellResources(relative_cell_id);
-
+  
   double amount_per_resource = value / energy_res_ids.GetSize();
   
   // put back energy resources evenly
@@ -550,10 +549,10 @@
 }
 
 /*void cDeme::SetCellEventGradient(int x1, int y1, int x2, int y2, int delay, int duration, bool static_pos, int time_to_live) {
-  cDemeCellEvent demeEvent = cDemeCellEvent(x1, y1, x2, y2, delay, duration, width, GetHeight(), static_pos, time_to_live, this);
-  demeEvent.DecayEventIDFromCenter();
-  cell_events.Add(demeEvent);
-}*/
+ cDemeCellEvent demeEvent = cDemeCellEvent(x1, y1, x2, y2, delay, duration, width, GetHeight(), static_pos, time_to_live, this);
+ demeEvent.DecayEventIDFromCenter();
+ cell_events.Add(demeEvent);
+ }*/
 
 int cDeme::GetNumEvents() {
   return cell_events.Size();
@@ -567,24 +566,24 @@
   
   int flow_level_increment = (m_total_events_per_slot_max - m_total_events_per_slot_min) / (m_tolal_event_flow_levels-1);
   int slot_length = m_world->GetConfig().DEMES_MAX_AGE.Get() / m_total_slots;
-
+  
   // setup stats tuples
-
+  
   for(int i = 0; i < m_total_slots; i++) {
     int slot_flow_level = flow_level_increment * m_world->GetRandom().GetInt(m_tolal_event_flow_levels) + m_total_events_per_slot_min; // number of event during this slot
     int slot_delay = i * slot_length;
     event_slot_end_points.push_back(make_pair(slot_delay+slot_length, slot_flow_level)); // last slot is never reached it is == to MAX_AGE
-
+    
     for(int k = 0; k < slot_flow_level; k++) {
       cDemeCellEvent demeEvent = cDemeCellEvent(x1, y1, x2, y2, delay, duration, width, GetHeight(), static_position, this, m_world);
       demeEvent.ConfineToTimeSlot(slot_delay, slot_delay+slot_length);
       cell_events.Add(demeEvent);
     }
   }
-    
+  
   // setup stats.flow_rate_tuples
   std::map<int, flow_rate_tuple>& flowRateTuples = m_world->GetStats().FlowRateTuples();
-
+  
   for(int i = m_total_events_per_slot_min; i <= m_total_events_per_slot_max; i+=flow_level_increment) {
     flowRateTuples[i].orgCount.Clear();
     flowRateTuples[i].eventsKilled.Clear();
@@ -597,7 +596,7 @@
 
 bool cDeme::KillCellEvent(const int eventID) {
   eventKillAttemptsThisSlot++;
-
+  
   if(eventID <= 0)
     return false;
   for(int i = 0; i < cell_events.Size(); i++) {
@@ -610,8 +609,8 @@
           //set cell data to 0
           m_world->GetPopulation().GetCell(GetCellID(eventCell)).SetCellData(0);
           
-        //  TODO // remove energy outflow from these cells
-
+          //  TODO // remove energy outflow from these cells
+          
         }
         eventCell = event.GetNextEventCellID();
       }
@@ -627,7 +626,7 @@
 
 double cDeme::CalculateTotalEnergy() const {
   assert(m_world->GetConfig().ENERGY_ENABLED.Get());
-    
+  
   double energy_sum = 0.0;
   for (int i=0; i<GetSize(); i++) {
     int cellid = GetCellID(i);
@@ -646,7 +645,7 @@
 
 double cDeme::CalculateTotalInitialEnergyResources() const {
   assert(m_world->GetConfig().ENERGY_ENABLED.Get());
-    
+  
   double energy_sum = 0.0;
   for(int i = 0; i < energy_res_ids.GetSize(); i++) {
     energy_sum += deme_resource_count.GetInitialResourceValue(i);
@@ -658,13 +657,13 @@
 // --- Founder list management --- //
 
 void cDeme::AddFounder(cGenotype& _in_genotype, cPhenotype * _in_phenotype) {
-
+  
   // save genotype id
   m_founder_genotype_ids.Push( _in_genotype.GetID() );
   cPhenotype phenotype;
   if (_in_phenotype) phenotype = *_in_phenotype;
   m_founder_phenotypes.Push( phenotype );
-
+  
   // defer adjusting this genotype until we are done with it
   _in_genotype.IncDeferAdjust();
   
@@ -688,19 +687,19 @@
   
   // same genotype, no changes
   if (m_germline_genotype_id == _in_genotype.GetID()) return;
-    
+  
   // first, save and put a hold on new germline genotype
   int prev_germline_genotype_id = m_germline_genotype_id;
   m_germline_genotype_id = _in_genotype.GetID();
   _in_genotype.IncDeferAdjust();  
-      
+  
   // next, if we previously were saving a germline genotype, free it
   cGenotype * genotype = m_world->GetClassificationManager().FindGenotype(prev_germline_genotype_id);
   if (genotype) {
     genotype->DecDeferAdjust();
     m_world->GetClassificationManager().AdjustGenotype(*genotype);
   }
-
+  
 }
 
 bool cDeme::MsgPredSatisfiedPreviously() {
@@ -790,15 +789,15 @@
     cerr<<"Error: An EventMoveBetweenTargets cannot be created until at least one CellEvent is added.\n";
     exit(1);
   }
-
+  
   tVector<cDemeCellEvent *> alive_events;
-
+  
   for(int i = 0; i < cell_events.Size(); i++) {
     if(!cell_events[i].IsDead()) {
       alive_events.Add(&cell_events[i]);
     }
   }
-
+  
   cOrgMovementPred_EventMovedBetweenTargets* pred = new cOrgMovementPred_EventMovedBetweenTargets(alive_events, m_world->GetPopulation(), times);
   m_world->GetStats().AddMovementPredicate(pred);
   movement_pred_list.Add(pred);
@@ -823,12 +822,12 @@
 {
   assert(cell_ids[0] <= absolute_cell_id);
   assert(absolute_cell_id <= cell_ids[cell_ids.GetSize()-1]);
-
-//  cPopulation& pop = m_world->GetPopulation();
-
+  
+  //  cPopulation& pop = m_world->GetPopulation();
+  
   int relative_cell_id = GetRelativeCellID(absolute_cell_id);
   tArray<double> cell_resources = deme_resource_count.GetCellResources(relative_cell_id);
-
+  
   for (int i = 0; i < deme_resource_count.GetSize(); i++) {
     if(strcmp(deme_resource_count.GetResName(i), "pheromone") == 0) {
       // There should only be one "pheromone" resource, so no need to divvy value up
@@ -838,17 +837,17 @@
       cell_resources[i] = 0;
     }
   }
-
-//It appears that ModifyCell adds the amount of resources specified in the cell_resources array, so I'm just
-//settign the element to the value I want to add instead of setting the element to the current value plus the amount to add
-// Ask Ben why he does it differently in GiveBackCellEnergy()
-
+  
+  //It appears that ModifyCell adds the amount of resources specified in the cell_resources array, so I'm just
+  //settign the element to the value I want to add instead of setting the element to the current value plus the amount to add
+  // Ask Ben why he does it differently in GiveBackCellEnergy()
+  
   deme_resource_count.ModifyCell(cell_resources, relative_cell_id);
-
+  
   // CellData-based version
   //const int newval = pop.GetCell(absolute_cell_id).GetCellData() + (int) round(value);
   //pop.GetCell(absolute_cell_id).SetCellData(newval);
-
+  
 } //End AddPheromone()
 
 int cDeme::GetSlotFlowRate() const {
@@ -859,7 +858,7 @@
     }
     iter++;
   }
-//  assert(false); // slots must be of equal size and fit perfectally in deme lifetime
+  //  assert(false); // slots must be of equal size and fit perfectally in deme lifetime
   return 0;
 }
 

Modified: branches/movement/source/main/cDeme.h
===================================================================
--- branches/movement/source/main/cDeme.h	2008-11-11 22:15:08 UTC (rev 2935)
+++ branches/movement/source/main/cDeme.h	2008-11-12 01:37:19 UTC (rev 2936)
@@ -242,7 +242,7 @@
   void UpdateDemeRes() { deme_resource_count.GetResources(); }
   void DoSumDemeCellResources(tArray<double>& deme_res_count_array);// @ LMG Sums spatial resources in the deme
   const tArray<double>& GetDemeInitCellResSum() const { return deme_init_spatial_res_count; }	// Returns sum of initial spatial resources
-  const tArray<double>& GetDemeCurrentCellResSum() const; // { return deme_sum_spatial_res_count; } // Returns sum of current spatial resources
+  void GetDemeCurrentCellResSum(tArray<double>& deme_res_count_array) const;
   void Update(double time_step) { deme_resource_count.Update(time_step); }
   int GetRelativeCellID(int absolute_cell_id) const { return absolute_cell_id % GetSize(); } //!< assumes all demes are the same size
   int GetAbsoluteCellID(int relative_cell_id) const { return relative_cell_id + (_id * GetSize()); } //!< assumes all demes are the same size

Modified: branches/movement/source/main/cPopulation.cc
===================================================================
--- branches/movement/source/main/cPopulation.cc	2008-11-11 22:15:08 UTC (rev 2935)
+++ branches/movement/source/main/cPopulation.cc	2008-11-12 01:37:19 UTC (rev 2936)
@@ -2897,7 +2897,7 @@
   int update = m_world->GetStats().GetUpdate();
   
   for(int i = 0; i < m_world->GetPopulation().GetNumDemes(); i++) {
-    cString tmpfilename = cStringUtil::Stringf( "deme_%07i_spacial_energy.m", i);  // moved here for easy movie making
+    cString tmpfilename = cStringUtil::Stringf( "deme_%07i_spatial_energy.m", i);  // moved here for easy movie making
     cDataFile& df = m_world->GetDataFile(tmpfilename);
     cString UpdateStr = cStringUtil::Stringf( "deme_%07i_energy_%07i = [ ...", i, update );
     df.WriteRaw(UpdateStr);
@@ -2921,15 +2921,15 @@
 }
 
 // Write spatial data to a file that can easily be read into Matlab
-void cPopulation::PrintDemeSpatialResData( cResourceCount res, const int i, const int deme_id) const {
+void cPopulation::PrintDemeSpatialResData(const cResourceCount& res, const int i, const int deme_id) const {
   const char* tmpResName = res.GetResName(i);
-  cString tmpfilename = cStringUtil::Stringf( "deme_spacial_resource_%s.m", tmpResName );
+  cString tmpfilename = cStringUtil::Stringf( "deme_spatial_resource_%s.m", tmpResName );
   cDataFile& df = m_world->GetDataFile(tmpfilename);
   cString UpdateStr = cStringUtil::Stringf( "deme_%07i_%s_%07i = [ ...", deme_id, static_cast<const char*>(res.GetResName(i)), m_world->GetStats().GetUpdate() );
   
   df.WriteRaw(UpdateStr);
   
-  cSpatialResCount sp_res = res.GetSpatialResource(i);
+  const cSpatialResCount& sp_res = res.GetSpatialResource(i);
   int gridsize = sp_res.GetSize();
   
   int xsize = m_world->GetConfig().WORLD_X.Get();
@@ -2944,7 +2944,7 @@
 // Write spatial energy data to a file that can easily be read into Matlab
 void cPopulation::PrintDemeSpatialSleepData() const {
   int cellID = 0;
-  cString tmpfilename = "deme_spacial_sleep.m";
+  cString tmpfilename = "deme_spatial_sleep.m";
   cDataFile& df = m_world->GetDataFile(tmpfilename);
   int update = m_world->GetStats().GetUpdate();
   

Modified: branches/movement/source/main/cPopulation.h
===================================================================
--- branches/movement/source/main/cPopulation.h	2008-11-11 22:15:08 UTC (rev 2935)
+++ branches/movement/source/main/cPopulation.h	2008-11-12 01:37:19 UTC (rev 2936)
@@ -238,7 +238,7 @@
   void PrintDemeMutationRate();
   void PrintDemeReceiver();
   void PrintDemeResource();
-  void PrintDemeSpatialResData(cResourceCount res, const int i, const int deme_id) const;
+  void PrintDemeSpatialResData(const cResourceCount& res, const int i, const int deme_id) const;
   void PrintDemeSpatialEnergyData() const;
   void PrintDemeSpatialSleepData() const;
   void PrintDemeTasks();

Modified: branches/movement/source/main/cResourceCount.cc
===================================================================
--- branches/movement/source/main/cResourceCount.cc	2008-11-11 22:15:08 UTC (rev 2935)
+++ branches/movement/source/main/cResourceCount.cc	2008-11-12 01:37:19 UTC (rev 2936)
@@ -492,26 +492,13 @@
   }
 }
 
-void cResourceCount::ReinitializeResources(double additional_resource){
-  cSpatialResCount src;
-  double c_curr_amount;
-  double c_initial_amount;
-  double c_new_amount;
-
+void cResourceCount::ReinitializeResources(double additional_resource)
+{
   for(int i = 0; i < resource_name.GetSize(); i++) {
-    Set(i, resource_initial[i]+additional_resource); //will cause problem if more than one resource is used. -- why?  each resource is stored separately (BDC)
+    Set(i, resource_initial[i] + additional_resource); //will cause problem if more than one resource is used. -- why?  each resource is stored separately (BDC)
 
     // Additionally, set any initial values given by the CELL command
-    src = GetSpatialResource(i);
-    for(int j = 0; j < src.GetSize(); j++) {
-      c_initial_amount = src.Element(j).GetInitial();
-      if(c_initial_amount > 0) {
-        c_curr_amount = spatial_resource_count[i].GetAmount(j);
-        c_new_amount = c_curr_amount + c_initial_amount + additional_resource;
-        spatial_resource_count[i].SetCellAmount(j, c_new_amount);
-      }
-    }
+    spatial_resource_count[i].ResetResourceCounts();
 
   } //End going through the resources
-
-} //End ReinitializeResources()
+}

Modified: branches/movement/source/main/cResourceCount.h
===================================================================
--- branches/movement/source/main/cResourceCount.h	2008-11-11 22:15:08 UTC (rev 2935)
+++ branches/movement/source/main/cResourceCount.h	2008-11-12 01:37:19 UTC (rev 2936)
@@ -105,9 +105,10 @@
   double Get(int id) const;
   void ResizeSpatialGrids(int in_x, int in_y);
   cSpatialResCount GetSpatialResource(int id) { return spatial_resource_count[id]; }
+  const cSpatialResCount& GetSpatialResource(int id) const { return spatial_resource_count[id]; }
   void ReinitializeResources(double additional_resource);
   double GetInitialResourceValue(int resourceID) const { return resource_initial[resourceID]; }
-  cString GetResName(int id) { return resource_name[id]; }
+  const cString& GetResName(int id) const { return resource_name[id]; }
 };
 
 

Modified: branches/movement/source/main/cSpatialCountElem.cc
===================================================================
--- branches/movement/source/main/cSpatialCountElem.cc	2008-11-11 22:15:08 UTC (rev 2935)
+++ branches/movement/source/main/cSpatialCountElem.cc	2008-11-12 01:37:19 UTC (rev 2936)
@@ -37,6 +37,7 @@
 {
   amount = initamount;
   delta = 0.0;
+  initial = initamount;
   elempt.Resize(MAXFLOWPTS);
   xdist.Resize(MAXFLOWPTS);
   ydist.Resize(MAXFLOWPTS);
@@ -49,6 +50,7 @@
 {
   amount = 0.0;
   delta = 0.0;
+  initial = 0.0;
   elempt.Resize(MAXFLOWPTS);
   xdist.Resize(MAXFLOWPTS);
   ydist.Resize(MAXFLOWPTS);

Modified: branches/movement/source/main/cSpatialCountElem.h
===================================================================
--- branches/movement/source/main/cSpatialCountElem.h	2008-11-11 22:15:08 UTC (rev 2935)
+++ branches/movement/source/main/cSpatialCountElem.h	2008-11-12 01:37:19 UTC (rev 2936)
@@ -54,6 +54,8 @@
                          int, int, double);
   void SetInitial(double init) { initial = init; }
   double GetInitial() { return initial; }
+  
+  inline void ResetResourceCount() { amount = initial; }
 };
 
 

Modified: branches/movement/source/main/cSpatialResCount.cc
===================================================================
--- branches/movement/source/main/cSpatialResCount.cc	2008-11-11 22:15:08 UTC (rev 2935)
+++ branches/movement/source/main/cSpatialResCount.cc	2008-11-12 01:37:19 UTC (rev 2936)
@@ -430,3 +430,9 @@
     Element(cell_id).SetAmount(res);
   }
 }
+
+
+void cSpatialResCount::ResetResourceCounts()
+{
+  for (int i = 0; i < grid.GetSize(); i++) grid[i].ResetResourceCount();
+}

Modified: branches/movement/source/main/cSpatialResCount.h
===================================================================
--- branches/movement/source/main/cSpatialResCount.h	2008-11-11 22:15:08 UTC (rev 2935)
+++ branches/movement/source/main/cSpatialResCount.h	2008-11-12 01:37:19 UTC (rev 2936)
@@ -62,10 +62,10 @@
   void SetPointers();
   void CheckRanges();
   void SetCellList(tArray<cCellResource> *in_cell_list_ptr);
-  int GetSize() { return grid.GetSize(); }
-  int GetX() { return world_x; }
-  int GetY() { return world_y; }
-  int GetCellListSize() { return cell_list_ptr->GetSize(); }
+  int GetSize() const { return grid.GetSize(); }
+  int GetX() const { return world_x; }
+  int GetY() const { return world_y; }
+  int GetCellListSize() const { return cell_list_ptr->GetSize(); }
   cSpatialCountElem& Element(int x) { return grid[x]; }
   void Rate(int x, double ratein) const;
   void Rate(int x, int y, double ratein) const;
@@ -95,6 +95,8 @@
   void SetOutflowX2(int in_outflowX2) { outflowX2 = in_outflowX2; }
   void SetOutflowY1(int in_outflowY1) { outflowY1 = in_outflowY1; }
   void SetOutflowY2(int in_outflowY2) { outflowY2 = in_outflowY2; }
+  
+  void ResetResourceCounts();
 };
 
 




More information about the Avida-cvs mailing list