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

baerb at myxo.css.msu.edu baerb at myxo.css.msu.edu
Wed Nov 29 06:57:23 PST 2006


Author: baerb
Date: 2006-11-29 09:57:15 -0500 (Wed, 29 Nov 2006)
New Revision: 1105

Modified:
   development/source/cpu/cTestCPU.cc
   development/source/main/cEnvironment.cc
   development/source/main/cPopulation.cc
   development/source/main/cResource.h
   development/source/main/cResourceCount.cc
   development/source/main/cResourceCount.h
   development/source/main/cSpatialResCount.cc
   development/source/main/cSpatialResCount.h
Log:

Added code to allow user to enter spatial resources one cell at a time



Modified: development/source/cpu/cTestCPU.cc
===================================================================
--- development/source/cpu/cTestCPU.cc	2006-11-29 04:29:50 UTC (rev 1104)
+++ development/source/cpu/cTestCPU.cc	2006-11-29 14:57:15 UTC (rev 1105)
@@ -61,7 +61,8 @@
                            res->GetInflowX2(), res->GetInflowY1(), 
                            res->GetInflowY2(), res->GetOutflowX1(), 
                            res->GetOutflowX2(), res->GetOutflowY1(), 
-                           res->GetOutflowY2(), world->GetVerbosity() );
+                           res->GetOutflowY2(), res->GetCellList(),
+                           world->GetVerbosity() );
   }
 }
 

Modified: development/source/main/cEnvironment.cc
===================================================================
--- development/source/main/cEnvironment.cc	2006-11-29 04:29:50 UTC (rev 1104)
+++ development/source/main/cEnvironment.cc	2006-11-29 14:57:15 UTC (rev 1105)
@@ -462,7 +462,6 @@
       cCellResource tmp_cell_resource(cell_list[i],tmp_initial,
                                       tmp_inflow, tmp_outflow);
       this_resource->AddCellResource(tmp_cell_resource);
-      cout << "cell_list[" << i << "] = " << cell_list[i] << endl;
     }
     
   }

Modified: development/source/main/cPopulation.cc
===================================================================
--- development/source/main/cPopulation.cc	2006-11-29 04:29:50 UTC (rev 1104)
+++ development/source/main/cPopulation.cc	2006-11-29 14:57:15 UTC (rev 1105)
@@ -153,7 +153,8 @@
                          res->GetInflowX2(), res->GetInflowY1(), 
                          res->GetInflowY2(), res->GetOutflowX1(), 
                          res->GetOutflowX2(), res->GetOutflowY1(), 
-                         res->GetOutflowY2(), world->GetVerbosity() );
+                         res->GetOutflowY2(), res->GetCellList(),
+                         world->GetVerbosity() );
     m_world->GetStats().SetResourceName(i, res->GetName());
   }
  

Modified: development/source/main/cResource.h
===================================================================
--- development/source/main/cResource.h	2006-11-29 04:29:50 UTC (rev 1104)
+++ development/source/main/cResource.h	2006-11-29 14:57:15 UTC (rev 1105)
@@ -32,6 +32,10 @@
 public:
   cCellResource();
   cCellResource(int _cell_id, double _initial, double _inflow, double _outflow);
+  int GetId() const { return cell_id; }
+  double GetInitial() const { return initial; }
+  double GetInflow() const { return inflow; }
+  double GetOutflow() const { return outflow; }
 };
 
 /* class to hold all infromation for a single resource */
@@ -84,6 +88,7 @@
   double GetXGravity() const { return xgravity; }
   double GetYDiffuse() const { return ydiffuse; }
   double GetYGravity() const { return ygravity; }
+  tArray<cCellResource> GetCellList() const { return cell_list; }
 
 
   void SetInitial(double _initial) { initial = _initial; }

Modified: development/source/main/cResourceCount.cc
===================================================================
--- development/source/main/cResourceCount.cc	2006-11-29 04:29:50 UTC (rev 1104)
+++ development/source/main/cResourceCount.cc	2006-11-29 14:57:15 UTC (rev 1105)
@@ -150,7 +150,8 @@
                            int in_inflowX2, int in_inflowY1, 
                            int in_inflowY2, int in_outflowX1, 
                            int in_outflowX2, int in_outflowY1, 
-                           int in_outflowY2, int verbosity_level)
+                           int in_outflowY2, tArray<cCellResource> in_cell_list,
+                           int verbosity_level)
 {
   assert(id >= 0 && id < resource_count.GetSize());
   assert(initial >= 0.0);
@@ -204,6 +205,7 @@
   geometry[id] = in_geometry;
   spatial_resource_count[id].SetGeometry(in_geometry);
   spatial_resource_count[id].SetPointers();
+  spatial_resource_count[id].SetCellList(in_cell_list);
 
   double step_decay = pow(decay, UPDATE_STEP);
   double step_inflow = inflow * UPDATE_STEP;
@@ -316,7 +318,7 @@
          the end of the update so that all processes (inflow, outflow, 
          diffision, gravity and organism demand) have the same weight.  However
          waiting can cause problems with negative resources so we allow
-         the organism demand work immediately on the state of the resource */ 
+         the organism demand to work immediately on the state of the resource */ 
     
       spatial_resource_count[i].State(cell_id);
     }
@@ -374,6 +376,10 @@
       if (geometry[i] != nGeometry::GLOBAL) {
         spatial_resource_count[i].Source(inflow_rate[i]);
         spatial_resource_count[i].Sink(decay_rate[i]);
+        if (spatial_resource_count[i].GetCellListSize() > 0) {
+          spatial_resource_count[i].CellInflow();
+          spatial_resource_count[i].CellOutflow();
+        }
         spatial_resource_count[i].FlowAll();
         spatial_resource_count[i].StateAll();
         resource_count[i] = spatial_resource_count[i].SumAll();

Modified: development/source/main/cResourceCount.h
===================================================================
--- development/source/main/cResourceCount.h	2006-11-29 04:29:50 UTC (rev 1104)
+++ development/source/main/cResourceCount.h	2006-11-29 14:57:15 UTC (rev 1105)
@@ -64,7 +64,8 @@
              double in_ydiffuse, double in_ygravity,
              int in_inflowX1, int in_inflowX2, int in_inflowY1, int in_inflowY2,
              int in_outflowX1, int in_outflowX2, int in_outflowY1, 
-             int in_outflowY, int verbosity_level);
+             int in_outflowY, tArray<cCellResource> in_cell_list,
+             int verbosity_level);
   void Update(double in_time);
 
   int GetSize(void) const { return resource_count.GetSize(); }

Modified: development/source/main/cSpatialResCount.cc
===================================================================
--- development/source/main/cSpatialResCount.cc	2006-11-29 04:29:50 UTC (rev 1104)
+++ development/source/main/cSpatialResCount.cc	2006-11-29 14:57:15 UTC (rev 1105)
@@ -13,6 +13,7 @@
 #include "functions.h"
 #include "nGeometry.h"
 
+using namespace std;
 
 /* Setup a single spatial resource with known flows */
 
@@ -196,6 +197,14 @@
 
 }
 
+void cSpatialResCount::SetCellList(tArray<cCellResource> in_cell_list) {
+  cell_list = in_cell_list;
+  for (int i = 0; i < cell_list.GetSize(); i++) {
+    Rate(cell_list[i].GetId(), cell_list[i].GetInitial());
+    State(cell_list[i].GetId());
+  }
+}
+
 void cSpatialResCount::RateAll(double ratein) {
 
   int i;
@@ -253,6 +262,8 @@
   return sum;
 }
 
+/* Take a given amount of resource and spread it among all the cells in the 
+   inflow rectange */
 
 void cSpatialResCount::Source(double amount) const {
   int     i, j, elem;
@@ -269,6 +280,16 @@
   }
 }
 
+/* Handle the inflow for a list of individual cells */
+
+void cSpatialResCount::CellInflow() const {
+  for (int i=0; i < cell_list.GetSize(); i++) {
+    Rate(cell_list[i].GetId(), cell_list[i].GetInflow());
+  }
+}
+
+/* Take away a give percentage of a resource from outflow rectangle */
+
 void cSpatialResCount::Sink(double decay) const {
 
   int     i, j, elem;
@@ -283,3 +304,16 @@
     }
   }
 }
+
+/* Take away a give percentage of a resource from individual cells */
+
+void cSpatialResCount::CellOutflow() const {
+
+  double  deltaamount;
+
+  for (int i=0; i < cell_list.GetSize(); i++) {
+    deltaamount = Max((GetAmount(cell_list[i].GetId()) *
+                       cell_list[i].GetOutflow()), 0.0);
+    Rate(cell_list[i].GetId(), -deltaamount); 
+  }
+}

Modified: development/source/main/cSpatialResCount.h
===================================================================
--- development/source/main/cSpatialResCount.h	2006-11-29 04:29:50 UTC (rev 1104)
+++ development/source/main/cSpatialResCount.h	2006-11-29 14:57:15 UTC (rev 1105)
@@ -31,6 +31,7 @@
   int    outflowX1, outflowX2, outflowY1, outflowY2;
   int    geometry;
   int    world_x, world_y, num_cells;
+  tArray<cCellResource> cell_list;
   
 public:
   cSpatialResCount();
@@ -42,24 +43,30 @@
   void ResizeClear(int inworld_x, int inworld_y, int ingeometry);
   void SetPointers();
   void CheckRanges();
+  void SetCellList(tArray<cCellResource> in_cell_list);
   int GetSize() { return grid.GetSize(); }
   int GetX() { return world_x; }
   int GetY() { return world_y; }
+  int GetCellListSize() { return cell_list.GetSize(); }
   cSpatialCountElem Element(int x) { return grid[x]; }
   void Rate(int x, double ratein) const { grid[x].Rate(ratein); }
-  void Rate(int x, int y, double ratein) const { grid[y * world_x + x].Rate(ratein); }
+  void Rate(int x, int y, double ratein) const 
+     { grid[y * world_x + x].Rate(ratein); }
   void State(int x) { grid[x].State(); }
   void State(int x, int y) { grid[y*world_x + x].State(); }
   const double GetAmount(int x) const { return grid[x].GetAmount(); }
-  const double GetAmount(int x, int y) const { return grid[y*world_x + x].GetAmount(); }
+  const double GetAmount(int x, int y) const 
+     { return grid[y*world_x + x].GetAmount(); }
   void RateAll(double ratein);
   void StateAll();
   void FlowAll();
   const double SumAll() const;
   void Source(double amount) const;
-  // void Source(tArray<cCellReource> cell_list) const;
+  // void CellInflow(tArray<cCellResource> cell_list) const;
+  void CellInflow() const;
   void Sink(double percent) const;
-  // void Sink(tArray<cCellReource> cell_list) const;
+  // void CellOutflow(tArray<cCellResource> cell_list) const;
+  void CellOutflow() const;
   void SetGeometry(int in_geometry) { geometry = in_geometry; }
   void SetXdiffuse(double in_xdiffuse) { xdiffuse = in_xdiffuse; }
   void SetXgravity(double in_xgravity) { xgravity = in_xgravity; }




More information about the Avida-cvs mailing list