[Avida-SVN] r3053 - in development: source/cpu source/main tests

goingssh at myxo.css.msu.edu goingssh at myxo.css.msu.edu
Tue Dec 16 14:39:19 PST 2008


Author: goingssh
Date: 2008-12-16 17:39:19 -0500 (Tue, 16 Dec 2008)
New Revision: 3053

Removed:
   development/tests/string_match_embed3/
Modified:
   development/source/cpu/cTestCPU.h
   development/source/cpu/cTestCPUInterface.cc
   development/source/cpu/cTestCPUInterface.h
   development/source/main/cDeme.cc
   development/source/main/cEnvironment.cc
   development/source/main/cOrgInterface.h
   development/source/main/cOrganism.cc
   development/source/main/cPopulation.cc
   development/source/main/cPopulation.h
   development/source/main/cPopulationInterface.cc
   development/source/main/cPopulationInterface.h
   development/source/main/cResource.cc
   development/source/main/cResource.h
   development/source/main/cResourceCount.cc
   development/source/main/cResourceCount.h
   development/source/main/cStats.cc
   development/source/main/cTaskLib.cc
   development/source/main/nGeometry.h
Log:
1. updated how string match test works (breaking old consistency test, will add new one, I and Heather are only ones who have used this code I believe)
2. added possibility of associating global resource with list of connected cells, only these cells may access this resource. To use create a global resource in the normal way, but add 2 parameters, geometry=partial, and cells=list of cells, this list is read in the same way as spatial resource cell lists, so for example 1..100 gives you all cells 1 to 100.
The error checking isn't great yet, so if you use this check your config files well, I will work on this more soon.



Modified: development/source/cpu/cTestCPU.h
===================================================================
--- development/source/cpu/cTestCPU.h	2008-12-16 20:07:39 UTC (rev 3052)
+++ development/source/cpu/cTestCPU.h	2008-12-16 22:39:19 UTC (rev 3053)
@@ -109,6 +109,7 @@
   inline int GetReceiveValue();
   inline const tArray<double>& GetResources();
   inline const tArray<double>& GetDemeResources(int deme_id);
+  inline const tArray< tArray<int> >& GetCellIdLists();
   
   // Used by cTestCPUInterface to get/update resources
   void ModifyResources(const tArray<double>& res_change);
@@ -158,6 +159,11 @@
     return m_deme_resource_count.GetResources();
 }
 
+inline const tArray< tArray<int> >& cTestCPU::GetCellIdLists()
+{
+	return m_resource_count.GetCellIdLists();
+}
+
 inline void cTestCPU::SetResource(int id, double new_level)
 {
   m_resource_count.Set(id, new_level);

Modified: development/source/cpu/cTestCPUInterface.cc
===================================================================
--- development/source/cpu/cTestCPUInterface.cc	2008-12-16 20:07:39 UTC (rev 3052)
+++ development/source/cpu/cTestCPUInterface.cc	2008-12-16 22:39:19 UTC (rev 3053)
@@ -83,6 +83,11 @@
   return m_testcpu->GetDemeResources(deme_id);
 }
 
+const tArray< tArray<int> >& cTestCPUInterface::GetCellIdLists()
+{
+	return m_testcpu->GetCellIdLists();
+}
+
 void cTestCPUInterface::UpdateResources(const tArray<double>& res_change)
 {
    m_testcpu->ModifyResources(res_change);

Modified: development/source/cpu/cTestCPUInterface.h
===================================================================
--- development/source/cpu/cTestCPUInterface.h	2008-12-16 20:07:39 UTC (rev 3052)
+++ development/source/cpu/cTestCPUInterface.h	2008-12-16 22:39:19 UTC (rev 3053)
@@ -75,6 +75,7 @@
   int Debug();
   const tArray<double>& GetResources();
   const tArray<double>& GetDemeResources(int deme_id);
+  const tArray< tArray<int> >& GetCellIdLists();  
   void UpdateResources(const tArray<double>& res_change);
   void UpdateDemeResources(const tArray<double>& res_change) {;}
   void Die();

Modified: development/source/main/cDeme.cc
===================================================================
--- development/source/main/cDeme.cc	2008-12-16 20:07:39 UTC (rev 3052)
+++ development/source/main/cDeme.cc	2008-12-16 22:39:19 UTC (rev 3053)
@@ -416,7 +416,7 @@
   const double decay = 1.0 - res->GetOutflow();
   //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(), 
+    deme_resource_count.Setup(id, res->GetName(), res->GetInitial(), 
                             res->GetInflow(), decay,
                             res->GetGeometry(), res->GetXDiffuse(),
                             res->GetXGravity(), res->GetYDiffuse(), 
@@ -425,7 +425,7 @@
                             res->GetInflowY2(), res->GetOutflowX1(), 
                             res->GetOutflowX2(), res->GetOutflowY1(), 
                             res->GetOutflowY2(), res->GetCellListPtr(),
-                            verbosity);
+                            res->GetCellIdListPtr(), verbosity);
   
   if(res->GetEnergyResource()) {
     energy_res_ids.Push(id);

Modified: development/source/main/cEnvironment.cc
===================================================================
--- development/source/main/cEnvironment.cc	2008-12-16 20:07:39 UTC (rev 3052)
+++ development/source/main/cEnvironment.cc	2008-12-16 22:39:19 UTC (rev 3053)
@@ -369,6 +369,11 @@
           return false;
         }
       }
+	  else if (var_name == "cells")
+	  {
+		  tArray<int> cell_list = cStringUtil::ReturnArray(var_value);
+		  new_resource->SetCellIdList(cell_list);
+	  }
       else if (var_name == "inflowx1" || var_name == "inflowx") {
         if (!AssertInputInt(var_value, "inflowX1", var_type)) return false;
         new_resource->SetInflowX1( var_value.AsInt() );
@@ -1143,40 +1148,44 @@
     } else {
       // Otherwise we're using a finite resource      
       const int res_id = in_resource->GetID();
-      
-      assert(resource_count[res_id] >= 0);
-      assert(result.GetConsumed(res_id) >= 0);
-      consumed = resource_count[res_id] - result.GetConsumed(res_id);
-      consumed *= cur_process->GetMaxFraction();
-      assert(consumed >= 0.0);
-      
-      bool may_use_rbins = m_world->GetConfig().USE_RESOURCE_BINS.Get();
-      bool using_rbins = false;  //default: not using resource bins
-      
-      if (may_use_rbins) {
-      	assert(rbins_count.GetSize() > res_id);
-      }
-      
-      /* Check to see if we do want to use this resource from a bin instead of the environment:
-       * - Can we use the resource bins?
-       * - Is there anything in the bin for this resource?
-       * - Is the usable fraction in the bin strictly greater than the threshold fraction
-       *   of what we could consume from the outside environment?
-       */
-      if (may_use_rbins && rbins_count[res_id] > 0 && 
-           (m_world->GetConfig().USE_STORED_FRACTION.Get() * rbins_count[res_id]) > 
-           (m_world->GetConfig().ENV_FRACTION_THRESHOLD.Get() * consumed)
-           ) {
-        consumed = m_world->GetConfig().USE_STORED_FRACTION.Get() * rbins_count[res_id];
-        using_rbins = true;
-      }
-      
-      // Make sure we're not above the maximum consumption.
-      if (consumed > max_consumed) consumed = max_consumed;
 
-      assert((task_quality >= 0.0) && (task_quality <= 1.0));
-      consumed *= task_quality;  // modify consumed based on task quality
-      
+	  bool may_use_rbins = m_world->GetConfig().USE_RESOURCE_BINS.Get();
+	  bool using_rbins = false;  //default: not using resource bins
+
+	  // check to see if the value of this resource was set to 0 for this cell
+      if (resource_count[res_id]==0)
+		  consumed=0;
+	  else {
+		  assert(resource_count[res_id] >= 0);
+		  assert(result.GetConsumed(res_id) >= 0);
+		  consumed = resource_count[res_id] - result.GetConsumed(res_id);
+		  consumed *= cur_process->GetMaxFraction();
+		  assert(consumed >= 0.0);
+		 
+		  if (may_use_rbins) {
+			  assert(rbins_count.GetSize() > res_id);
+		  }
+
+		  /* Check to see if we do want to use this resource from a bin instead of the environment:
+		  * - Can we use the resource bins?
+		  * - Is there anything in the bin for this resource?
+		  * - Is the usable fraction in the bin strictly greater than the threshold fraction
+		  *   of what we could consume from the outside environment?
+		  */
+		  if (may_use_rbins && rbins_count[res_id] > 0 && 
+			  (m_world->GetConfig().USE_STORED_FRACTION.Get() * rbins_count[res_id]) > 
+			  (m_world->GetConfig().ENV_FRACTION_THRESHOLD.Get() * consumed)
+			  ) {
+				  consumed = m_world->GetConfig().USE_STORED_FRACTION.Get() * rbins_count[res_id];
+				  using_rbins = true;
+		  }
+
+		  // Make sure we're not above the maximum consumption.
+		  if (consumed > max_consumed) consumed = max_consumed;
+
+		  assert((task_quality >= 0.0) && (task_quality <= 1.0));
+		  consumed *= task_quality;  // modify consumed based on task quality
+	  }
       // Test if we are below the minimum consumption.
       if (consumed < min_consumed) consumed = 0.0;
       
@@ -1194,7 +1203,7 @@
       	if (may_use_rbins && using_rbins)
       	{rbins_count[res_id] -= consumed;}
       }
-    }
+	}
     
     // Mark the reaction as having been performed if we get here.
     result.MarkReaction(reaction_id);
@@ -1278,7 +1287,7 @@
           assert(false);  // Should not get here!
           break;
       }
-    }
+	}
     
     // Determine detection events
     cResource* detected = cur_process->GetDetect();
@@ -1309,7 +1318,7 @@
     
     result.Lethal(cur_process->GetLethal());
     result.Sterilize(cur_process->GetSterilize());
-    } 
+	} 
 }
 
 const cString& cEnvironment::GetReactionName(int reaction_id) const

Modified: development/source/main/cOrgInterface.h
===================================================================
--- development/source/main/cOrgInterface.h	2008-12-16 20:07:39 UTC (rev 3052)
+++ development/source/main/cOrgInterface.h	2008-12-16 22:39:19 UTC (rev 3053)
@@ -87,6 +87,7 @@
   virtual int Debug() = 0;
   virtual const tArray<double>& GetResources() = 0;
   virtual const tArray<double>& GetDemeResources(int deme_id) = 0;  
+  virtual const tArray< tArray<int> >& GetCellIdLists() = 0; 
   virtual void UpdateResources(const tArray<double>& res_change) = 0;
   virtual void UpdateDemeResources(const tArray<double>& res_change) = 0;
   virtual void Die() = 0;

Modified: development/source/main/cOrganism.cc
===================================================================
--- development/source/main/cOrganism.cc	2008-12-16 20:07:39 UTC (rev 3052)
+++ development/source/main/cOrganism.cc	2008-12-16 22:39:19 UTC (rev 3053)
@@ -13,7 +13,7 @@
  *  of the License.
  *
  *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty ofcout
  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  *  GNU General Public License for more details.
  *
@@ -291,6 +291,7 @@
   const int deme_id = m_interface->GetDemeID();
   const tArray<double> & global_resource_count = m_interface->GetResources();
   const tArray<double> & deme_resource_count = m_interface->GetDemeResources(deme_id);
+  const tArray< tArray<int> > & cell_id_lists = m_interface->GetCellIdLists();
   
   tList<tBuffer<int> > other_input_list;
   tList<tBuffer<int> > other_output_list;
@@ -334,9 +335,29 @@
                        m_hardware->GetExtendedMemory(), on_divide, received_messages_point);
                        
   //combine global and deme resource counts
-  const tArray<double> globalAndDeme_resource_count = global_resource_count + deme_resource_count;
+  tArray<double> globalAndDeme_resource_count = global_resource_count + deme_resource_count;
   tArray<double> globalAndDeme_res_change = global_res_change + deme_res_change;
   
+  // set any resource amount to 0 if a cell cannot access this resource
+  int cell_id=GetCellID();
+  if (cell_id_lists.GetSize())
+  {
+	  for (int i=0; i<cell_id_lists.GetSize(); i++)
+	  {
+		  // if cell_id_lists have been set then we have to check if this cell is in the list
+		  if (cell_id_lists[i].GetSize()) {
+			  int j;
+			  for (j=0; j<cell_id_lists[i].GetSize(); j++)
+			  {
+				  if (cell_id==cell_id_lists[i][j])
+					  break;
+			  }
+			  if (j==cell_id_lists[i].GetSize())
+				  globalAndDeme_resource_count[i]=0;
+		  }
+	  }
+  }
+
   bool task_completed = m_phenotype.TestOutput(ctx, taskctx, globalAndDeme_resource_count, m_rbins, globalAndDeme_res_change,
                                                insts_triggered);
   

Modified: development/source/main/cPopulation.cc
===================================================================
--- development/source/main/cPopulation.cc	2008-12-16 20:07:39 UTC (rev 3052)
+++ development/source/main/cPopulation.cc	2008-12-16 22:39:19 UTC (rev 3053)
@@ -110,7 +110,8 @@
       case nGeometry::TORUS: { cout << "Geometry: Torus" << endl; break; }
       case nGeometry::CLIQUE: { cout << "Geometry: Clique" << endl; break; }
       case nGeometry::HEX: { cout << "Geometry: Hex" << endl; break; }
-			case nGeometry::LATTICE: { cout << "Geometry: Lattice" << endl; break; }
+	  case nGeometry::LATTICE: { cout << "Geometry: Lattice" << endl; break; }
+	  case nGeometry::PARTIAL: { cout << "Geometry: Partial" << endl; break; }
       default:
         cout << "Unknown geometry!" << endl;
         assert(false);
@@ -248,7 +249,7 @@
                            res->GetInflowY2(), res->GetOutflowX1(), 
                            res->GetOutflowX2(), res->GetOutflowY1(), 
                            res->GetOutflowY2(), res->GetCellListPtr(),
-                           world->GetVerbosity() );
+                           res->GetCellIdListPtr(), world->GetVerbosity() );
       m_world->GetStats().SetResourceName(global_res_index, res->GetName());
     } else if(res->GetDemeResource()) {
       deme_res_index++;
@@ -1405,9 +1406,7 @@
   // used to pass energy to offspring demes (set to zero if energy model is not enabled)
   double source_deme_energy(0.0), deme_energy_decay(0.0), parent_deme_energy(0.0), offspring_deme_energy(0.0);
   if(m_world->GetConfig().ENERGY_ENABLED.Get()) {
-		double energyRemainingInSourceDeme = source_deme.CalculateTotalEnergy();
-		source_deme.SetEnergyRemainingInDemeAtReplication(energyRemainingInSourceDeme);
-    source_deme_energy = energyRemainingInSourceDeme + source_deme.GetTotalEnergyTestament();
+    source_deme_energy = source_deme.CalculateTotalEnergy() + source_deme.GetTotalEnergyTestament();
     m_world->GetStats().SumEnergyTestamentAcceptedByDeme().Add(source_deme.GetTotalEnergyTestament());
     deme_energy_decay = 1.0 - m_world->GetConfig().FRAC_ENERGY_DECAY_AT_DEME_BIRTH.Get();
     parent_deme_energy = source_deme_energy * deme_energy_decay * (1.0 - m_world->GetConfig().FRAC_PARENT_ENERGY_GIVEN_TO_DEME_AT_BIRTH.Get());
@@ -1439,10 +1438,7 @@
 
   // Reset both demes, in case they have any cleanup work to do.
   // Must reset target first for stats to be correctly updated!
-  if(m_world->GetConfig().ENERGY_ENABLED.Get() == 1) {
-//		if(m_world->GetConfig().ENERGY_PASSED_ON_DEME_REPLICATION_METHOD.Get() == 0) {
-//			offspring_deme_energy = parent_deme_energy = 0.0;
-//		}
+  if(m_world->GetConfig().ENERGY_ENABLED.Get()) {
     // Transfer energy from source to target if we're using the energy model.
     if (target_successfully_seeded) target_deme.DivideReset(source_deme, target_deme_resource_reset, offspring_deme_energy);
     source_deme.DivideReset(source_deme, source_deme_resource_reset, parent_deme_energy);
@@ -1548,38 +1544,34 @@
 	// split energy from parent deme evenly among orgs in child deme
 	if(m_world->GetConfig().ENERGY_ENABLED.Get() == 1 && m_world->GetConfig().ENERGY_PASSED_ON_DEME_REPLICATION_METHOD.Get() == 0) {
 		assert(source_deme.GetOrgCount() > 0 && target_deme.GetOrgCount() > 0);
-		if(offspring_deme_energy > 0.0) {
-			// split deme energy evenly between organisms in target deme
-			double totalEnergyInjectedIntoOrganisms(0.0);
-			for (int i=0; i < target_deme.GetSize(); i++) {
-				int cellid = target_deme.GetCellID(i);
-				cPopulationCell& cell = m_world->GetPopulation().GetCell(cellid);
-				if(cell.IsOccupied()) {
-					cOrganism* organism = cell.GetOrganism();
-					cPhenotype& phenotype = organism->GetPhenotype();
-					phenotype.SetEnergy(phenotype.GetStoredEnergy() + offspring_deme_energy/static_cast<double>(target_deme.GetOrgCount()));
-					phenotype.SetMerit(cMerit(cMerit::EnergyToMerit(phenotype.GetStoredEnergy() * phenotype.GetEnergyUsageRatio(), m_world)));
-					totalEnergyInjectedIntoOrganisms += phenotype.GetStoredEnergy();
-				}
+		if(offspring_deme_energy < 0.0)
+			offspring_deme_energy = 0.0;
+		if(parent_deme_energy < 0.0)
+			parent_deme_energy = 0.0;	
+	 
+		// split deme energy evenly between organisms in source deme
+		for (int i=0; i < source_deme.GetSize(); i++) {
+			int cellid = source_deme.GetCellID(i);
+			cPopulationCell& cell = m_world->GetPopulation().GetCell(cellid);
+			if(cell.IsOccupied()) {
+				cOrganism* organism = cell.GetOrganism();
+				cPhenotype& phenotype = organism->GetPhenotype();
+				phenotype.SetEnergy(phenotype.GetStoredEnergy() + parent_deme_energy/static_cast<double>(source_deme.GetOrgCount()));
+				phenotype.SetMerit(cMerit(cMerit::EnergyToMerit(phenotype.GetStoredEnergy() * phenotype.GetEnergyUsageRatio(), m_world)));
 			}
-			target_deme.SetEnergyInjectedIntoOrganisms(totalEnergyInjectedIntoOrganisms);
 		}
-		if(parent_deme_energy > 0.0) {
-			// split deme energy evenly between organisms in source deme
-			double totalEnergyInjectedIntoOrganisms(0.0);
-			for (int i=0; i < source_deme.GetSize(); i++) {
-				int cellid = source_deme.GetCellID(i);
-				cPopulationCell& cell = m_world->GetPopulation().GetCell(cellid);
-				if(cell.IsOccupied()) {
-					cOrganism* organism = cell.GetOrganism();
-					cPhenotype& phenotype = organism->GetPhenotype();
-					phenotype.SetEnergy(phenotype.GetStoredEnergy() + parent_deme_energy/static_cast<double>(source_deme.GetOrgCount()));
-					phenotype.SetMerit(cMerit(cMerit::EnergyToMerit(phenotype.GetStoredEnergy() * phenotype.GetEnergyUsageRatio(), m_world)));
-					totalEnergyInjectedIntoOrganisms += phenotype.GetStoredEnergy();
-				}
+		
+		// split deme energy evenly between organisms in target deme
+		for (int i=0; i < target_deme.GetSize(); i++) {
+			int cellid = target_deme.GetCellID(i);
+			cPopulationCell& cell = m_world->GetPopulation().GetCell(cellid);
+			if(cell.IsOccupied()) {
+				cOrganism* organism = cell.GetOrganism();
+				cPhenotype& phenotype = organism->GetPhenotype();
+				phenotype.SetEnergy(phenotype.GetStoredEnergy() + offspring_deme_energy/static_cast<double>(target_deme.GetOrgCount()));
+				phenotype.SetMerit(cMerit(cMerit::EnergyToMerit(phenotype.GetStoredEnergy() * phenotype.GetEnergyUsageRatio(), m_world)));
 			}
-			source_deme.SetEnergyInjectedIntoOrganisms(totalEnergyInjectedIntoOrganisms);
-		}
+		}		
 	}
 
 	
@@ -2584,9 +2576,7 @@
   else if (m_world->GetConfig().DEMES_REPLICATE_BIRTHS.Get() 
            && (deme.GetBirthCount() >= m_world->GetConfig().DEMES_REPLICATE_BIRTHS.Get())) ReplicateDeme(deme); 
   else if (m_world->GetConfig().DEMES_REPLICATE_ORGS.Get() 
-           && (deme.GetOrgCount() >= m_world->GetConfig().DEMES_REPLICATE_ORGS.Get())) ReplicateDeme(deme); 
-	else if(deme.TestReplication())
-		ReplicateDeme(deme); 
+           && (deme.GetOrgCount() >= m_world->GetConfig().DEMES_REPLICATE_ORGS.Get())) ReplicateDeme(deme);      
 }
 
 // Print out all statistics about individual demes
@@ -2729,21 +2719,12 @@
   df_fit.WriteTimeStamp();
   df_fit.Write(stats.GetUpdate(), "update");
 	cDoubleSum avg_energy;
-	cDoubleSum avg_injected;
-	cDoubleSum avg_remainAtReplation;
-	avg_energy.Clear();
-	avg_injected.Clear();
-	avg_remainAtReplation.Clear();
   
   for (int deme_id = 0; deme_id < num_demes; deme_id++) {
     const cDeme & cur_deme = deme_array[deme_id];    
 		avg_energy.Add(cur_deme.CalculateTotalEnergy());
-		avg_injected.Add(cur_deme.CalculateTotalInitialEnergyResources() + cur_deme.GetEnergyInjectedIntoOrganisms());
-		avg_remainAtReplation.Add(cur_deme.GetEnergyRemainingInDemeAtReplication());
 	}
 	df_fit.Write(avg_energy.Ave(), "Total Average Energy");
-	df_fit.Write(avg_injected.Ave(), "Average Energy Injected");
-	df_fit.Write(avg_remainAtReplation.Ave(), "Average Energy Remaining at Replication");
 	df_fit.Endl();
 }
 
@@ -2927,8 +2908,8 @@
     for(int j = 0; j < res.GetSize(); j++) {
       const char * tmp = res.GetResName(j);
       df_resources.Write(res.Get(j), cStringUtil::Stringf("Deme %d Resource %s", deme_id, tmp)); //comment);
-      if((res.GetResourcesGeometry())[j] != nGeometry::GLOBAL) {
-        PrintDemeSpatialResData(res, j, deme_id);
+	  if((res.GetResourcesGeometry())[j] != nGeometry::GLOBAL && (res.GetResourcesGeometry())[j] != nGeometry::PARTIAL) {
+           PrintDemeSpatialResData(res, j, deme_id);
       }
     }
   }
@@ -3556,10 +3537,7 @@
   cell.GetHardware()->SingleProcess(ctx);    
   
   double merit = cur_org->GetPhenotype().GetMerit().GetDouble();
-  if (cur_org->GetPhenotype().GetToDelete() == true) {
-		delete cur_org;
-		cur_org = NULL;
-	}
+  if (cur_org->GetPhenotype().GetToDelete() == true) delete cur_org;
   
   m_world->GetStats().IncExecuted();
   resource_count.Update(step_size);
@@ -3608,11 +3586,7 @@
     }
   }
   
-	double merit = cur_org->GetPhenotype().GetMerit().GetDouble();
-  if (cur_org->GetPhenotype().GetToDelete() == true) {
-		delete cur_org;
-		cur_org = NULL;
-	}
+  if (cur_org->GetPhenotype().GetToDelete() == true) delete cur_org;
   
   m_world->GetStats().IncExecuted();
   resource_count.Update(step_size);
@@ -3623,7 +3597,7 @@
     for(int i = 0; i < GetNumDemes(); i++) GetDeme(i).Update(step_size);
     
     cDeme & deme = GetDeme(GetCell(cell_id).GetDemeID());
-    deme.IncTimeUsed(merit);
+    deme.IncTimeUsed(cur_org->GetPhenotype().GetMerit().GetDouble());
     CheckImplicitDemeRepro(deme);
   }
   
@@ -5242,7 +5216,7 @@
                            res->GetInflowY2(), res->GetOutflowX1(), 
                            res->GetOutflowX2(), res->GetOutflowY1(), 
                            res->GetOutflowY2(), res->GetCellListPtr(),
-                           Verbosity);
+                           res->GetCellIdListPtr(), Verbosity);
       m_world->GetStats().SetResourceName(global_res_index, res->GetName());
     } else if(res->GetDemeResource()) {
       deme_res_index++;

Modified: development/source/main/cPopulation.h
===================================================================
--- development/source/main/cPopulation.h	2008-12-16 20:07:39 UTC (rev 3052)
+++ development/source/main/cPopulation.h	2008-12-16 22:39:19 UTC (rev 3053)
@@ -282,6 +282,7 @@
   const tArray<double>& GetCellResources(int cell_id) const { return resource_count.GetCellResources(cell_id); }
   const tArray<double>& GetDemeResources(int deme_id) { return GetDeme(deme_id).GetDemeResourceCount().GetResources(); }
   const tArray<double>& GetDemeCellResources(int deme_id, int cell_id) { return GetDeme(deme_id).GetDemeResourceCount().GetCellResources( GetDeme(deme_id).GetRelativeCellID(cell_id) ); }
+  const tArray< tArray<int> >& GetCellIdLists() const { return resource_count.GetCellIdLists(); }
 
   cBirthChamber& GetBirthChamber(int id) { (void) id; return birth_chamber; }
 

Modified: development/source/main/cPopulationInterface.cc
===================================================================
--- development/source/main/cPopulationInterface.cc	2008-12-16 20:07:39 UTC (rev 3052)
+++ development/source/main/cPopulationInterface.cc	2008-12-16 22:39:19 UTC (rev 3053)
@@ -138,6 +138,11 @@
   return m_world->GetPopulation().GetDemeCellResources(deme_id, m_cell_id);
 }
 
+const tArray< tArray<int> >& cPopulationInterface::GetCellIdLists()
+{
+	return m_world->GetPopulation().GetCellIdLists();
+}
+
 void cPopulationInterface::UpdateResources(const tArray<double> & res_change)
 {
   return m_world->GetPopulation().UpdateCellResources(res_change, m_cell_id);

Modified: development/source/main/cPopulationInterface.h
===================================================================
--- development/source/main/cPopulationInterface.h	2008-12-16 20:07:39 UTC (rev 3052)
+++ development/source/main/cPopulationInterface.h	2008-12-16 22:39:19 UTC (rev 3053)
@@ -90,6 +90,7 @@
   int Debug();
   const tArray<double>& GetResources();
   const tArray<double>& GetDemeResources(int deme_id);
+  const tArray< tArray<int> >& GetCellIdLists();
   void UpdateResources(const tArray<double>& res_change);
   void UpdateDemeResources(const tArray<double>& res_change);
   void Die();

Modified: development/source/main/cResource.cc
===================================================================
--- development/source/main/cResource.cc	2008-12-16 20:07:39 UTC (rev 3052)
+++ development/source/main/cResource.cc	2008-12-16 22:39:19 UTC (rev 3053)
@@ -85,10 +85,19 @@
      } else if (_geometry == "torus") {
           geometry = nGeometry::TORUS;
           return true;
-     } else {
+     } 
+	 else if (_geometry == "partial") {
+          geometry = nGeometry::PARTIAL;
+          return true;
+	 }
+	 else {
           return false;
      }
 }
+void cResource::SetCellIdList(tArray<int>& id_list) {
+	cell_id_list.ResizeClear(id_list.GetSize());
+	cell_id_list=id_list;
+}
 
 /* Set if the resource is going to be accessable by demes */
 bool cResource::SetDemeResource(cString _deme_resource) {

Modified: development/source/main/cResource.h
===================================================================
--- development/source/main/cResource.h	2008-12-16 20:07:39 UTC (rev 3052)
+++ development/source/main/cResource.h	2008-12-16 22:39:19 UTC (rev 3053)
@@ -84,6 +84,7 @@
   bool deme_resource;
   bool energy_resource;  // only implemented for spacial resource
   tArray<cCellResource> cell_list;
+  tArray<int> cell_id_list;  
  
   
   cResource(); // @not_implemented
@@ -113,6 +114,7 @@
   bool GetDemeResource() const { return deme_resource; }
   bool GetEnergyResource() const { return energy_resource; }
   tArray<cCellResource> *GetCellListPtr() { return &cell_list; }
+  tArray<int> *GetCellIdListPtr() { return &cell_id_list; }
 
 
   void SetInitial(double _initial) { initial = _initial; }
@@ -137,6 +139,7 @@
   cCellResource *GetCellResourcePtr(int _id);
   void UpdateCellResource(cCellResource *_CellResoucePtr, double _initial, 
                           double _inflow, double _outflow);
+  void SetCellIdList(tArray<int>& id_list); //SLG partial resources
 };
 
 

Modified: development/source/main/cResourceCount.cc
===================================================================
--- development/source/main/cResourceCount.cc	2008-12-16 20:07:39 UTC (rev 3052)
+++ development/source/main/cResourceCount.cc	2008-12-16 22:39:19 UTC (rev 3053)
@@ -128,6 +128,7 @@
   curr_spatial_res_cnt = rc.curr_spatial_res_cnt;
   update_time = rc.update_time;
   spatial_update_time = rc.spatial_update_time;
+  cell_lists = rc.cell_lists;
 
   return *this;
 }
@@ -147,6 +148,7 @@
   spatial_resource_count.ResizeClear(num_resources);
   curr_grid_res_cnt.ResizeClear(num_resources);
   curr_spatial_res_cnt.ResizeClear(num_resources);
+  cell_lists.ResizeClear(num_resources);
 
   resource_name.SetAll("");
   resource_initial.SetAll(0.0);
@@ -169,8 +171,8 @@
   assert(resource_count.GetSize() == res.GetSize());
 
   for (int i = 0; i < resource_count.GetSize(); i++) {
-    if (geometry[i] == nGeometry::GLOBAL) {
-      // Set global quantity of resource
+     if (geometry[i] == nGeometry::GLOBAL || geometry[i]==nGeometry::PARTIAL) {
+        // Set global quantity of resource
     } else {
       spatial_resource_count[i].SetCellAmount(cell_id, res[i]);
 
@@ -191,7 +193,7 @@
                            int in_inflowY2, int in_outflowX1, 
                            int in_outflowX2, int in_outflowY1, 
                            int in_outflowY2, tArray<cCellResource> *in_cell_list_ptr,
-                           int verbosity_level)
+                           tArray<int> *in_cell_id_list_ptr, int verbosity_level)
 {
   assert(id >= 0 && id < resource_count.GetSize());
   assert(initial >= 0.0);
@@ -206,7 +208,11 @@
     geo_name = "GRID";
   } else if (in_geometry == nGeometry::TORUS) {
     geo_name = "TORUS";
-  } else {
+  } 
+	else if (in_geometry == nGeometry::PARTIAL) {
+	geo_name = "PARTIAL";
+  }
+  else {
     cerr << "[cResourceCount::Setup] Unknown resource geometry " << in_geometry << ".  Exiting.";
     exit(2);
   }
@@ -246,7 +252,19 @@
   resource_initial[id] = initial;
   if (in_geometry == nGeometry::GLOBAL) {
     resource_count[id] = initial;
-  } else {
+	spatial_resource_count[id].RateAll(0);
+  } 
+  else if (in_geometry == nGeometry::PARTIAL) {
+	  resource_count[id]=initial;
+
+	  spatial_resource_count[id].RateAll(0);
+	  // want to set list of cell ids here
+	   cell_lists[id].Resize(in_cell_id_list_ptr->GetSize());
+	  for (int i = 0; i < in_cell_id_list_ptr->GetSize(); i++)
+		  cell_lists[id][i] = (*in_cell_id_list_ptr)[i];
+
+  }
+  else {
     resource_count[id] = 0;
     spatial_resource_count[id].SetInitial(initial / spatial_resource_count[id].GetSize());
     spatial_resource_count[id].RateAll(spatial_resource_count[id].GetInitial());
@@ -342,8 +360,8 @@
   DoUpdates();
 
   for (int i = 0; i < num_resources; i++) {
-    if (geometry[i] == nGeometry::GLOBAL) {
-      curr_grid_res_cnt[i] = resource_count[i];
+     if (geometry[i] == nGeometry::GLOBAL || geometry[i]==nGeometry::PARTIAL) {
+         curr_grid_res_cnt[i] = resource_count[i];
     } else {
       curr_grid_res_cnt[i] = spatial_resource_count[i].GetAmount(cell_id);
     }
@@ -397,8 +415,8 @@
   assert(resource_count.GetSize() == res_change.GetSize());
 
   for (int i = 0; i < resource_count.GetSize(); i++) {
-    if (geometry[i] == nGeometry::GLOBAL) {
-      resource_count[i] += res_change[i];
+  if (geometry[i] == nGeometry::GLOBAL || geometry[i]==nGeometry::PARTIAL) {
+        resource_count[i] += res_change[i];
       assert(resource_count[i] >= 0.0);
     } else {
       spatial_resource_count[i].Rate(cell_id, res_change[i]);
@@ -418,8 +436,8 @@
 double cResourceCount::Get(int id) const
 {
   assert(id < resource_count.GetSize());
-  if(geometry[id] == nGeometry::GLOBAL) {
-    return resource_count[id];
+  if (geometry[id] == nGeometry::GLOBAL || geometry[id]==nGeometry::PARTIAL) {
+      return resource_count[id];
   } //else return spacial resource sum
   return spatial_resource_count[id].SumAll();
 }
@@ -427,8 +445,8 @@
 void cResourceCount::Set(int id, double new_level)
 {
   assert(id < resource_count.GetSize());
-  if(geometry[id] == nGeometry::GLOBAL) {
-    resource_count[id] = new_level;
+  if (geometry[id] == nGeometry::GLOBAL || geometry[id]==nGeometry::PARTIAL) {
+     resource_count[id] = new_level;
   } else {
     for(int i = 0; i < spatial_resource_count[id].GetSize(); i++) {
       spatial_resource_count[id].SetCellAmount(i, new_level/spatial_resource_count[id].GetSize());
@@ -456,7 +474,7 @@
 
   while (num_steps > PRECALC_DISTANCE) {
     for (int i = 0; i < resource_count.GetSize(); i++) {
-      if (geometry[i] == nGeometry::GLOBAL) {
+      if (geometry[i] == nGeometry::GLOBAL || geometry[i]==nGeometry::PARTIAL) {
         resource_count[i] *= decay_precalc(i, PRECALC_DISTANCE);
         resource_count[i] += inflow_precalc(i, PRECALC_DISTANCE);
       }
@@ -465,7 +483,7 @@
   }
 
   for (int i = 0; i < resource_count.GetSize(); i++) {
-    if (geometry[i] == nGeometry::GLOBAL) {
+    if (geometry[i] == nGeometry::GLOBAL || geometry[i]==nGeometry::PARTIAL) {
       resource_count[i] *= decay_precalc(i, num_steps);
       resource_count[i] += inflow_precalc(i, num_steps);
     }
@@ -476,7 +494,7 @@
   while (spatial_update_time >= 1.0) { 
     spatial_update_time -= 1.0;
     for (int i = 0; i < resource_count.GetSize(); i++) {
-      if (geometry[i] != nGeometry::GLOBAL) {
+     if (geometry[i] != nGeometry::GLOBAL && geometry[i] != nGeometry::PARTIAL) {
         spatial_resource_count[i].Source(inflow_rate[i]);
         spatial_resource_count[i].Sink(decay_rate[i]);
         if (spatial_resource_count[i].GetCellListSize() > 0) {

Modified: development/source/main/cResourceCount.h
===================================================================
--- development/source/main/cResourceCount.h	2008-12-16 20:07:39 UTC (rev 3052)
+++ development/source/main/cResourceCount.h	2008-12-16 22:39:19 UTC (rev 3053)
@@ -57,6 +57,7 @@
   mutable tArray<double> curr_grid_res_cnt;
   mutable tArray< tArray<double> > curr_spatial_res_cnt;
   int verbosity;
+  tArray< tArray<int> > cell_lists;	
 
   // Setup the update process to use lazy evaluation...
   mutable double update_time;     // Portion of an update compleated...
@@ -84,7 +85,7 @@
              int in_inflowX1, int in_inflowX2, int in_inflowY1, int in_inflowY2,
              int in_outflowX1, int in_outflowX2, int in_outflowY1, 
              int in_outflowY, tArray<cCellResource> *in_cell_list_ptr,
-             int verbosity_level);
+             tArray<int> *in_cell_id_list_ptr, int verbosity_level);
              
   int GetResourceCountID(const cString& res_name);
   void SetInflow(const cString& name, const double _inflow);
@@ -98,6 +99,7 @@
   const tArray<double>& GetCellResources(int cell_id) const;
   const tArray<int>& GetResourcesGeometry() const;
   const tArray<tArray<double> >& GetSpatialRes();
+  const tArray<tArray<int> >& GetCellIdLists() const { return cell_lists; }
   void Modify(const tArray<double>& res_change);
   void Modify(int id, double change);
   void ModifyCell(const tArray<double> & res_change, int cell_id);

Modified: development/source/main/cStats.cc
===================================================================
--- development/source/main/cStats.cc	2008-12-16 20:07:39 UTC (rev 3052)
+++ development/source/main/cStats.cc	2008-12-16 22:39:19 UTC (rev 3053)
@@ -1045,8 +1045,8 @@
   // maps for each spatial resource 
   
   for (int i = 0; i < resource_count.GetSize(); i++) {
-    if (resource_geometry[i] != nGeometry::GLOBAL) {
-      double sum_spa_resource = 0;
+   if (resource_geometry[i] != nGeometry::GLOBAL && resource_geometry[i] != nGeometry::PARTIAL) {
+         double sum_spa_resource = 0;
       for (int j = 0; j < spatial_res_count[i].GetSize(); j++) {
          sum_spa_resource += spatial_res_count[i][j];
       }

Modified: development/source/main/cTaskLib.cc
===================================================================
--- development/source/main/cTaskLib.cc	2008-12-16 20:07:39 UTC (rev 3052)
+++ development/source/main/cTaskLib.cc	2008-12-16 22:39:19 UTC (rev 3053)
@@ -1908,7 +1908,11 @@
 {
   cArgSchema schema;
   schema.AddEntry("string", 0, cArgSchema::SCHEMA_STRING);
+  schema.AddEntry("partial",0, 0);
+  schema.AddEntry("binary",1,1);
+  schema.AddEntry("pow",0,2.0);
   cArgContainer* args = cArgContainer::Load(argstr, schema, errors);
+  envreqs.SetMinOutputs(args->GetString(0).GetSize());
   if (args) NewTask(name, "MatchStr", &cTaskLib::Task_MatchStr, 0, args);
 }
 
@@ -1920,23 +1924,40 @@
   //  temp_buf.Pop(); // pop the signal value off of the buffer
   
   const cString& string_to_match = ctx.GetTaskEntry()->GetArguments().GetString(0);
+  int partial = ctx.GetTaskEntry()->GetArguments().GetInt(0);
+  int binary = ctx.GetTaskEntry()->GetArguments().GetInt(1);
+  double mypow = ctx.GetTaskEntry()->GetArguments().GetDouble(0);
   int string_index;
   int num_matched = 0;
   int test_output;
   int max_num_matched = 0;
-  
-  if (temp_buf.GetNumStored() > 0) {
-    test_output = temp_buf[0];
-    
-    for (int j = 0; j < string_to_match.GetSize(); j++) {  
-      string_index = string_to_match.GetSize() - j - 1; // start with last char in string
-      int k = 1 << j;
-      if ((string_to_match[string_index] == '0' && !(test_output & k)) ||
-          (string_to_match[string_index] == '1' && (test_output & k))) num_matched++;
+  int num_real=0;
+
+  if (!binary) {
+    if (temp_buf.GetNumStored() > 0) {
+      test_output = temp_buf[0];
+      
+      for (int j = 0; j < string_to_match.GetSize(); j++) {  
+	string_index = string_to_match.GetSize() - j - 1; // start with last char in string
+	int k = 1 << j;
+	if ((string_to_match[string_index] == '0' && !(test_output & k)) ||
+	    (string_to_match[string_index] == '1' && (test_output & k))) num_matched++;
+      }
+      max_num_matched = num_matched;
     }
+  }
+  else {
+    for (int j = 0; j < string_to_match.GetSize(); j++)
+      {
+        if (string_to_match[j]!='9')
+          num_real++;
+        if (string_to_match[j]=='0' && temp_buf[j]==0 ||
+            string_to_match[j]=='1' && temp_buf[j]==1)
+          num_matched++;
+      }
     max_num_matched = num_matched;
+
   }
-  
   bool used_received = false;
   if (ctx.GetReceivedMessages()) {
     tBuffer<int> received(*(ctx.GetReceivedMessages()));
@@ -1961,7 +1982,12 @@
   double bonus = 0.0;
   // return value between 0 & 1 representing the percentage of string that was matched
   double base_bonus = static_cast<double>(max_num_matched) * 2.0 / static_cast<double>(string_to_match.GetSize()) - 1;
-  
+
+  if (partial)
+    {
+      base_bonus=double(max_num_matched)*2/double(num_real) -1;
+    }
+
   if (base_bonus > 0.0) {
     bonus = pow(base_bonus, 2);
     if (used_received)
@@ -1973,6 +1999,7 @@
 }
 
 
+
 void cTaskLib::Load_MatchNumber(const cString& name, const cString& argstr, cEnvReqs& envreqs, tList<cString>* errors)
 {
   cArgSchema schema;
@@ -2249,7 +2276,71 @@
   double Fx = 0.0;
   
   // some of the problems don't need double variables but use the bit string as a bit string
-  if (function==18)
+  // string match, Fx=length - num_matched (0 best, length worst)
+  if (function==20)
+    {
+      const cString& string_to_match = args.GetString(0);
+      int matched=0;
+      for (int i=0; i<args.GetInt(2); i++)
+        {
+          if ((string_to_match[i] == '0' && ctx.GetOutputBuffer()[i]==0)  ||
+              (string_to_match[i] == '1' && ctx.GetOutputBuffer()[i]==1))
+            matched++;
+        }
+      Fx=args.GetInt(2) - matched;
+    }
+  // string with all 1's at beginning until pattern 0101, reward for # 1's
+  else if (function==21)
+    {
+      int numOnes=0;
+      int patFound=0;
+      for (int i=0; i<args.GetInt(2)-4; i++)
+        {
+          if (ctx.GetOutputBuffer()[i]==1)
+            numOnes++;
+          else
+            {
+              if (ctx.GetOutputBuffer()[i+1]==1
+                  && ctx.GetOutputBuffer()[i+2]==0 && ctx.GetOutputBuffer()[i+3]==1)
+                patFound=1;
+              break;
+            }
+        }
+      if (patFound)
+        Fx=args.GetInt(2)-4-numOnes;
+      else
+        Fx=args.GetInt(2);
+    }
+  // simply rewared for number of 1's at beginning of string, maxFx=length of string
+  else if (function==22)
+    {
+      int numOnes=0;
+      for (int i=0; i<args.GetInt(2); i++)
+        {
+          if (ctx.GetOutputBuffer()[i]==1)
+            numOnes++;
+          else
+            break;
+        }
+      Fx=args.GetInt(2)-numOnes;
+    }
+
+  // simply reward for number 0's in string
+  else if (function==23)
+    {
+      int numZeros=0;
+      for (int i=0; i<args.GetInt(2); i++)
+        {
+          if (ctx.GetOutputBuffer()[i]==0)
+            numZeros++;
+          else
+            break;
+        }
+      Fx=args.GetInt(2)-numZeros;
+    }
+
+
+  else if (function==18)
   {
     int tot=0;
     for (int i=0; i<30; i++)

Modified: development/source/main/nGeometry.h
===================================================================
--- development/source/main/nGeometry.h	2008-12-16 20:07:39 UTC (rev 3052)
+++ development/source/main/nGeometry.h	2008-12-16 22:39:19 UTC (rev 3053)
@@ -34,7 +34,8 @@
     TORUS,
     CLIQUE,
     HEX,
-		LATTICE
+	PARTIAL,
+	LATTICE
   };
 }
 




More information about the Avida-cvs mailing list