[Avida-cvs] [avida-svn] r870 - in branches/developers/avida-edward/source: bindings/Boost.Python event main tools

kaben at myxo.css.msu.edu kaben at myxo.css.msu.edu
Mon Aug 14 10:42:11 PDT 2006


Author: kaben
Date: 2006-08-14 13:42:11 -0400 (Mon, 14 Aug 2006)
New Revision: 870

Added:
   branches/developers/avida-edward/source/bindings/Boost.Python/cRandom.pyste
   branches/developers/avida-edward/source/bindings/Boost.Python/cTools.pyste
Removed:
   branches/developers/avida-edward/source/bindings/Boost.Python/random.pyste
   branches/developers/avida-edward/source/bindings/Boost.Python/tools.pyste
Modified:
   branches/developers/avida-edward/source/bindings/Boost.Python/CMakeLists.txt
   branches/developers/avida-edward/source/event/cPopulationEventFactory.cc
   branches/developers/avida-edward/source/main/cPopulation.cc
   branches/developers/avida-edward/source/main/cPopulation.h
   branches/developers/avida-edward/source/tools/cRandom.cc
   branches/developers/avida-edward/source/tools/cRandom.h
   branches/developers/avida-edward/source/tools/cTools.h
Log:

Support for saving and reloading random number generator; Broken support
for injecting organism with fitness and gestation time.



Modified: branches/developers/avida-edward/source/bindings/Boost.Python/CMakeLists.txt
===================================================================
--- branches/developers/avida-edward/source/bindings/Boost.Python/CMakeLists.txt	2006-08-10 19:18:05 UTC (rev 869)
+++ branches/developers/avida-edward/source/bindings/Boost.Python/CMakeLists.txt	2006-08-14 17:42:11 UTC (rev 870)
@@ -41,6 +41,9 @@
 #
 SET(PyAvida_Pyste_Bases
 
+  cRandom::
+  cTools::
+
   # XXX I can't figure out how it works.
   tArray::${SourceDir}/organism.pyste:${SourceDir}/merit.pyste:${SourceDir}/mutation.pyste:${SourceDir}/int_sum.pyste:
 

Copied: branches/developers/avida-edward/source/bindings/Boost.Python/cRandom.pyste (from rev 824, branches/developers/avida-edward/source/bindings/Boost.Python/random.pyste)
===================================================================
--- branches/developers/avida-edward/source/bindings/Boost.Python/random.pyste	2006-07-11 16:40:38 UTC (rev 824)
+++ branches/developers/avida-edward/source/bindings/Boost.Python/cRandom.pyste	2006-08-14 17:42:11 UTC (rev 870)
@@ -0,0 +1,7 @@
+
+Include("tList.h")
+Include("tArray.h")
+
+cRandom = Class("cRandom", "cRandom.h")
+
+# vim: set ft=python:

Copied: branches/developers/avida-edward/source/bindings/Boost.Python/cTools.pyste (from rev 825, branches/developers/avida-edward/source/bindings/Boost.Python/tools.pyste)
===================================================================
--- branches/developers/avida-edward/source/bindings/Boost.Python/tools.pyste	2006-07-11 16:54:13 UTC (rev 825)
+++ branches/developers/avida-edward/source/bindings/Boost.Python/cTools.pyste	2006-08-14 17:42:11 UTC (rev 870)
@@ -0,0 +1,10 @@
+
+Include("cString.h")
+
+Import("cRandom.pyste")
+
+cTools = Class("cTools", "cTools.h")
+#Var("g_random", "cTools.h")
+set_policy(cTools.globalRandom, return_value_policy(reference_existing_object))
+
+# vim: set ft=python:

Deleted: branches/developers/avida-edward/source/bindings/Boost.Python/random.pyste
===================================================================
--- branches/developers/avida-edward/source/bindings/Boost.Python/random.pyste	2006-08-10 19:18:05 UTC (rev 869)
+++ branches/developers/avida-edward/source/bindings/Boost.Python/random.pyste	2006-08-14 17:42:11 UTC (rev 870)
@@ -1,6 +0,0 @@
-
-Include("tList.h")
-
-cRandom = Class("cRandom", "cRandom.h")
-
-# vim: set ft=python:

Deleted: branches/developers/avida-edward/source/bindings/Boost.Python/tools.pyste
===================================================================
--- branches/developers/avida-edward/source/bindings/Boost.Python/tools.pyste	2006-08-10 19:18:05 UTC (rev 869)
+++ branches/developers/avida-edward/source/bindings/Boost.Python/tools.pyste	2006-08-14 17:42:11 UTC (rev 870)
@@ -1,6 +0,0 @@
-
-Include("cString.h")
-
-cTools = Class("cTools", "cTools.h")
-
-# vim: set ft=python:

Modified: branches/developers/avida-edward/source/event/cPopulationEventFactory.cc
===================================================================
--- branches/developers/avida-edward/source/event/cPopulationEventFactory.cc	2006-08-10 19:18:05 UTC (rev 869)
+++ branches/developers/avida-edward/source/event/cPopulationEventFactory.cc	2006-08-14 17:42:11 UTC (rev 870)
@@ -5,82 +5,32 @@
 // before continuing.  SOME RESTRICTIONS MAY APPLY TO USE OF THIS FILE.     //
 //////////////////////////////////////////////////////////////////////////////
 
-#ifndef POPULATION_EVENT_FACTORY_HH
 #include "cPopulationEventFactory.h"
-#endif
 
-#ifndef ANALYZE_UTIL_HH
+#include "avida.h"
 #include "cAnalyzeUtil.h"
-#endif
-#ifndef avida_h
-#include "avida.h"
-#endif
-#ifndef AVIDA_DRIVER_BASE_HH
 #include "cAvidaDriver_Base.h"
-#endif
-#ifndef CONFIG_HH
 #include "cConfig.h"
-#endif
-#ifndef ENVIRONMENT_HH
 #include "cEnvironment.h"
-#endif
-#ifndef EVENT_HH
 #include "cEvent.h"
-#endif
-#ifndef GENEBANK_HH
 #include "cGenebank.h"
-#endif
-#ifndef GENOTYPE_HH
 #include "cGenotype.h"
-#endif
-#ifndef INJECT_GENEBANK_HH
 #include "cInjectGenebank.h"
-#endif
-#ifndef INJECT_GENOTYPE_HH
 #include "cInjectGenotype.h"
-#endif
-#ifndef INST_UTIL_HH
 #include "cInstUtil.h"
-#endif
-#ifndef LANDSCAPE_HH
 #include "cLandscape.h"
-#endif
-#ifndef LINEAGE_CONTROL_HH
 #include "cLineageControl.h"
-#endif
-#ifndef ORGANISM_HH
 #include "cOrganism.h"
-#endif
-#ifndef PHENOTYPE_HH
 #include "cPhenotype.h"
-#endif
-#ifndef POPULATION_HH
 #include "cPopulation.h"
-#endif
-#ifndef POPULATION_CELL_HH
 #include "cPopulationCell.h"
-#endif
-#ifndef POPULATION_EVENT_HH
 #include "cPopulationEvent.h"
-#endif
-#ifndef RESOURCE_HH
 #include "cResource.h"
-#endif
-#ifndef STATS_HH
 #include "cStats.h"
-#endif
-#ifndef STRING_UTIL_HH
 #include "cStringUtil.h"
-#endif
-#ifndef TEST_CPU_HH
 #include "cTestCPU.h"
-#endif
-#ifndef TEST_UTIL_HH
 #include "cTestUtil.h"
-#endif
-#ifndef TOOLS_HH
 #include "cTools.h"
-#endif
 
 #include <ctype.h>           // for isdigit
 
@@ -1781,10 +1731,88 @@
     }
   };
   
+  ///// inject_sequence_with_stats /////
+  
+  /**
+   * Injects identical organisms into a range of cells of the population.
+   *
+   * Parameters:
+   * sequence (string)
+   *   The genome sequence for this organism.  This is a mandatory argument.
+   * start_cell (int)
+   *   First cell to inject into.
+   * stop_cell (int)
+   *   First cell *not* to inject into.
+   * merit (double) default: -1
+   *   The initial merit of the organism. If set to -1, this is ignored.
+   * lineage label (integer) default: 0
+   *   An integer that marks all descendants of this organism.
+   * neutral metric (double) default: 0
+   *   A double value that randomly drifts over time.
+   * gestation time (integer) default: -1
+   *   The initial gestation of the organism. If set to -1, this is ignored.
+   * life fitness (double) default: -1
+   *   The initial fitness of the organism. If set to -1, this is ignored.
+   *
+   * Example:
+   *   inject_sequence_with_stats ckdfhgklsahnfsaggdsgajfg 0 10 100
+   *
+   * Will inject 10 organisms into cells 0 through 9 with a merit of 100.
+   **/
+  
+  
+  class cEvent_inject_sequence_with_stats : public cPopulationEvent {
+  private:
+    cString seq;
+    int start_cell;
+    int end_cell;
+    double merit;
+    int lineage_label;
+    double neutral_metric;
+    int gestation_time;
+    double life_fitness;
+  public:
+      const cString GetName() const { return "inject_sequence_with_stats"; }
+    const cString GetDescription() const { return
+    "inject_sequence_with_stats  <cString seq> [int start_cell=0] [int end_cell=-1] [double merit=-1] [int lineage_label=0] [double neutral_metric=0] [int gestation_time=-1] [double life_fitness=-1]"; }
+    
+    void Configure(const cString& in_args)
+    {
+      m_args = in_args;
+      cString args(in_args);
+      seq = args.PopWord();
+      if (args == "") start_cell=0; else start_cell=args.PopWord().AsInt();
+      if (args == "") end_cell=-1; else end_cell=args.PopWord().AsInt();
+      if (args == "") merit=-1; else merit=args.PopWord().AsDouble();
+      if (args == "") lineage_label=0; else lineage_label=args.PopWord().AsInt();
+      if (args == "") neutral_metric=0; else neutral_metric=args.PopWord().AsDouble();
+      if (args == "") gestation_time=-1; else gestation_time=args.PopWord().AsInt();
+      if (args == "") life_fitness=-1; else life_fitness=args.PopWord().AsDouble();
+    }
+    ///// inject_sequence_with_stats /////
+    void Process(){
+      if (end_cell == -1) end_cell = start_cell + 1;
+      if (start_cell < 0 ||
+          end_cell > population->GetSize() ||
+          start_cell >= end_cell) {
+            cout << "Warning: inject_sequence_with_stats has invalid range!" << endl;
+            cout << "start=" << start_cell << "  end=" << end_cell
+              << "genome length=" << seq.GetSize() << endl;
+      }
+      else {
+        cGenome genome(seq);
+        for (int i = start_cell; i < end_cell; i++) {
+          population->Inject(genome, i, merit, lineage_label, neutral_metric, 0, gestation_time, life_fitness);
+        }
+        population->SetSyncEvents(true);
+      }
+    }
+  };
+  
   ///// inject_sequence /////
   
   /**
-    * Injects identical organisms into a range of cells of the population.
+   * Injects identical organisms into a range of cells of the population.
    *
    * Parameters:
    * sequence (string)
@@ -1794,17 +1822,17 @@
    * stop_cell (int)
    *   First cell *not* to inject into.
    * merit (double) default: -1
-     *   The initial merit of the organism. If set to -1, this is ignored.
-     * lineage label (integer) default: 0
-       *   An integer that marks all descendants of this organism.
-       * neutral metric (double) default: 0
-         *   A double value that randomly drifts over time.
-         *
-         * Example:
-         *   inject_range ckdfhgklsahnfsaggdsgajfg 0 10 100
-         *
-         * Will inject 10 organisms into cells 0 through 9 with a merit of 100.
-         **/
+   *   The initial merit of the organism. If set to -1, this is ignored.
+   * lineage label (integer) default: 0
+   *   An integer that marks all descendants of this organism.
+   * neutral metric (double) default: 0
+   *   A double value that randomly drifts over time.
+   *
+   * Example:
+   *   inject_range ckdfhgklsahnfsaggdsgajfg 0 10 100
+   *
+   * Will inject 10 organisms into cells 0 through 9 with a merit of 100.
+   **/
   
   
   class cEvent_inject_sequence : public cPopulationEvent {

Modified: branches/developers/avida-edward/source/main/cPopulation.cc
===================================================================
--- branches/developers/avida-edward/source/main/cPopulation.cc	2006-08-10 19:18:05 UTC (rev 869)
+++ branches/developers/avida-edward/source/main/cPopulation.cc	2006-08-14 17:42:11 UTC (rev 870)
@@ -1762,9 +1762,16 @@
  * this organism.
  **/
 
-void cPopulation::Inject(const cGenome & genome, int cell_id, double merit, 
-                         int lineage_label, double neutral, int mem_space )
-{
+void cPopulation::Inject(
+  const cGenome & genome,
+  int cell_id,
+  double merit, 
+  int lineage_label,
+  double neutral,
+  int mem_space,
+  int gestation_time,
+  double life_fitness
+){
   // If an invalid cell was given, choose a new ID for it.
   if (cell_id < 0) {
     switch (cConfig::GetBirthMethod()) {
@@ -1781,6 +1788,8 @@
     phenotype.SetNeutralMetric(neutral);
     
     if (merit > 0) phenotype.SetMerit( cMerit(merit) );
+    if (gestation_time > 0) phenotype.SetGestationTime( gestation_time );
+    if (life_fitness > 0) phenotype.SetLifeFitness( life_fitness );
     schedule->Adjust(cell_id, phenotype.GetMerit());
     
     LineageSetupOrganism(GetCell(cell_id).GetOrganism(), 0, lineage_label);

Modified: branches/developers/avida-edward/source/main/cPopulation.h
===================================================================
--- branches/developers/avida-edward/source/main/cPopulation.h	2006-08-10 19:18:05 UTC (rev 869)
+++ branches/developers/avida-edward/source/main/cPopulation.h	2006-08-14 17:42:11 UTC (rev 870)
@@ -134,8 +134,16 @@
   bool ActivateInject(const int cell_id, const cGenome & injected_code);
 
   // Inject an organism from the outside world.
-  void Inject(const cGenome & genome, int cell_id=-1, double merit=-1,
-	      int lineage_label=0, double neutral_metric=0, int mem_space=0 );
+  void Inject(
+    const cGenome & genome,
+    int cell_id=-1,
+    double merit=-1,
+	  int lineage_label=0,
+    double neutral_metric=0,
+    int mem_space=0,
+    int gestation_time=-1,
+    double life_fitness=-1
+  );
 
   // Deactivate an organism in the population (required for deactivations)
   void KillOrganism(cPopulationCell & in_cell);

Modified: branches/developers/avida-edward/source/tools/cRandom.cc
===================================================================
--- branches/developers/avida-edward/source/tools/cRandom.cc	2006-08-10 19:18:05 UTC (rev 869)
+++ branches/developers/avida-edward/source/tools/cRandom.cc	2006-08-14 17:42:11 UTC (rev 870)
@@ -9,8 +9,8 @@
 #include "cRandom.h"
 #endif
 
-#ifndef TARRAY_HH
-#include "tArray.h"
+#ifndef TLIST_H
+#include "tList.h"
 #endif
 
 /* FIXME this is not defined in Visual Studio.net. -- kgn */
@@ -46,6 +46,7 @@
  original_seed(0),
  inext(0),
  inextp(0),
+ ma(56),
  use_count(0),
  expRV(0)
   {

Modified: branches/developers/avida-edward/source/tools/cRandom.h
===================================================================
--- branches/developers/avida-edward/source/tools/cRandom.h	2006-08-10 19:18:05 UTC (rev 869)
+++ branches/developers/avida-edward/source/tools/cRandom.h	2006-08-14 17:42:11 UTC (rev 870)
@@ -17,10 +17,15 @@
 #ifndef cRandom_h
 #define cRandom_h
 
+
 #include <time.h>
 #include <limits.h>
 #include <math.h>
 
+#ifndef TARRAY_HH
+#include "tArray.h"
+#endif
+
 #ifndef UINT
 #define UINT unsigned int
 #endif
@@ -40,6 +45,13 @@
    * seed from the actual system time.
    **/
   cRandom(const int in_seed=-1);
+
+  /**
+   * Makes this random number generator's state match the original.
+   *
+   * @param orig The random number generator whose state to copy.
+   **/
+  void Clone(const cRandom &orig){ *this = orig; }
   
   inline int GetUseCount() { return use_count; }
   
@@ -198,15 +210,17 @@
   
   
   // Internals ////////////////////////////////////////////////////////////////
-private:
+public:
   // Internal memebers
   int seed;
   int original_seed;
   int inext;
   int inextp;
-  int ma[56];
+  //int ma[56];
+  tArray<int> ma;
   int use_count;
 
+private:
   // Constants ////////////////////////////////////////////////////////////////
   // Statistical Approximation
   static const unsigned int _BINOMIAL_TO_NORMAL;  //if < n*p*(1-p)

Modified: branches/developers/avida-edward/source/tools/cTools.h
===================================================================
--- branches/developers/avida-edward/source/tools/cTools.h	2006-08-10 19:18:05 UTC (rev 869)
+++ branches/developers/avida-edward/source/tools/cTools.h	2006-08-14 17:42:11 UTC (rev 870)
@@ -25,6 +25,7 @@
 class cTools {
 public:
   static bool MkDir(const cString & dirname, bool verbose=false);
+  static cRandom &globalRandom(void){ return g_random; }
 };
 
 #endif




More information about the Avida-cvs mailing list