[Avida-SVN] r3237 - in development: Avida.xcodeproj source/actions source/main

beckma24 at myxo.css.msu.edu beckma24 at myxo.css.msu.edu
Mon May 18 09:17:38 PDT 2009


Author: beckma24
Date: 2009-05-18 12:17:37 -0400 (Mon, 18 May 2009)
New Revision: 3237

Modified:
   development/Avida.xcodeproj/project.pbxproj
   development/source/actions/PopulationActions.cc
   development/source/main/cDeme.cc
   development/source/main/cDeme.h
   development/source/main/cOrgMovementPredicate.h
   development/source/main/cPopulation.cc
Log:
Adding code for DemeResourceThresholdPredicate action, which replicates a deme when a named deme-level resource's value satisfies a comparison between it an a threshold.  Currently only >= and <= comparisons are available.

Modified: development/Avida.xcodeproj/project.pbxproj
===================================================================
--- development/Avida.xcodeproj/project.pbxproj	2009-05-18 15:14:36 UTC (rev 3236)
+++ development/Avida.xcodeproj/project.pbxproj	2009-05-18 16:17:37 UTC (rev 3237)
@@ -924,6 +924,7 @@
 		B4FA259E0C5EB7600086D4B5 /* cPhenPlastGenotype.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = cPhenPlastGenotype.cc; sourceTree = "<group>"; };
 		B516AF790C91E24600023D53 /* cDemeCellEvent.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = cDemeCellEvent.cc; path = source/main/cDemeCellEvent.cc; sourceTree = SOURCE_ROOT; };
 		B516AF7A0C91E24600023D53 /* cDemeCellEvent.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = cDemeCellEvent.h; path = source/main/cDemeCellEvent.h; sourceTree = SOURCE_ROOT; };
+		BBDE4FF80FC1B06600CC6170 /* cDemePredicate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = cDemePredicate.h; sourceTree = "<group>"; };
 		D7FB16D50ED62684002E939E /* cOrgMessage.cc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = cOrgMessage.cc; sourceTree = "<group>"; };
 		DCC30FCF0762539D008F7A48 /* Doxyfile */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = text; path = Doxyfile; sourceTree = "<group>"; };
 		DCC3109C0762539E008F7A48 /* avida.cc */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = avida.cc; sourceTree = "<group>"; };
@@ -1611,6 +1612,7 @@
 				70447CA60F83DB5600E1BF72 /* cBirthMateSelectHandler.cc */,
 				70447CA90F83DBC100E1BF72 /* cBirthDemeHandler.h */,
 				70447CAA0F83DBC100E1BF72 /* cBirthDemeHandler.cc */,
+				BBDE4FF80FC1B06600CC6170 /* cDemePredicate.h */,
 			);
 			path = main;
 			sourceTree = "<group>";

Modified: development/source/actions/PopulationActions.cc
===================================================================
--- development/source/actions/PopulationActions.cc	2009-05-18 15:14:36 UTC (rev 3236)
+++ development/source/actions/PopulationActions.cc	2009-05-18 16:17:37 UTC (rev 3237)
@@ -1939,6 +1939,7 @@
     'sat-mov-pred'  - ...demes whose movement predicate was previously satisfied
     'events-killed' ...demes that have killed a certian number of events
     'sat-msg-pred'  - ...demes whose message predicate was previously satisfied
+		'sat-deme-predicate'...demes whose predicate has been satisfied; does not include movement or message predicates as those are organisms-level
 */
 
 class cActionReplicateDemes : public cAction
@@ -1960,6 +1961,7 @@
     else if (in_trigger == "sat-mov-pred") m_rep_trigger = 5;
     else if (in_trigger == "events-killed") m_rep_trigger = 6;
     else if (in_trigger == "sat-msg-pred") m_rep_trigger = 7;
+    else if (in_trigger == "sat-deme-predicate") m_rep_trigger = 8;
     else {
       cString err("Unknown replication trigger '");
       err += in_trigger;
@@ -2541,6 +2543,34 @@
   }
 };
 
+class cActionPred_DemeResourceThresholdPredicate : public cAction {
+private:
+  cString resourceName;
+	cString comparisonOperator;
+	double threasholdValue;
+	
+public:
+  cActionPred_DemeResourceThresholdPredicate(cWorld* world, const cString& args) : cAction(world, args) {
+    cString largs(args);
+		assert(largs.GetSize() == 3);
+    if (largs.GetSize()) resourceName = largs.PopWord();
+		if (largs.GetSize()) comparisonOperator = largs.PopWord();
+		if (largs.GetSize()) threasholdValue = largs.PopWord().AsDouble();
+  }
+  
+  static const cString GetDescription() { return "Arguments: cString resourceName, cString comparisonOperator, double threasholdValue"; }
+  
+  void Process(cAvidaContext& ctx)
+  {
+    cPopulation& pop = m_world->GetPopulation();
+		const int numDemes = pop.GetNumDemes();
+    for (int deme_id = 0; deme_id < numDemes; deme_id++) {
+			pop.GetDeme(deme_id).AddDemeResourceThresholdPredicate(resourceName, comparisonOperator, threasholdValue);
+    }
+  }
+	
+};
+
 /*
  Added predicate to all demes that is satisified when an organism reaches the center of an event
 */
@@ -2774,6 +2804,16 @@
   action_lib->Register<cActionCompeteDemesByTaskCountAndEfficiency>("CompeteDemesByTaskCountAndEfficiency");
   action_lib->Register<cActionCompeteDemesByEnergyDistribution>("CompeteDemesByEnergyDistribution");	
 
+/* deme predicate*/
+	action_lib->Register<cActionPred_DemeEventMoveCenter>("Pred_DemeEventMoveCenter");
+  action_lib->Register<cActionPred_DemeEventMoveBetweenTargets>("Pred_DemeEventMoveBetweenTargets");
+  action_lib->Register<cActionPred_DemeEventEventNUniqueIndividualsMovedIntoTarget>("Pred_DemeEventNUniqueIndividualsMovedIntoTarget");
+	action_lib->Register<cActionPred_DemeResourceThresholdPredicate>("DemeResourceThresholdPredicate");
+  
+  action_lib->Register<cActionKillNBelowResourceThreshold>("KillNBelowResourceThreshold");
+  action_lib->Register<cActionKillNAboveResourceThreshold>("KillNAboveResourceThreshold");
+	
+	
   // @DMB - The following actions are DEPRECATED aliases - These will be removed in 2.7.
   action_lib->Register<cActionInject>("inject");
   action_lib->Register<cActionInjectRandom>("inject_random");
@@ -2805,11 +2845,4 @@
   action_lib->Register<cActionConnectCells>("connect_cells");
   action_lib->Register<cActionDisconnectCells>("disconnect_cells");
   action_lib->Register<cActionSwapCells>("swap_cells");
-
-  action_lib->Register<cActionPred_DemeEventMoveCenter>("Pred_DemeEventMoveCenter");
-  action_lib->Register<cActionPred_DemeEventMoveBetweenTargets>("Pred_DemeEventMoveBetweenTargets");
-  action_lib->Register<cActionPred_DemeEventEventNUniqueIndividualsMovedIntoTarget>("Pred_DemeEventNUniqueIndividualsMovedIntoTarget");
-  
-  action_lib->Register<cActionKillNBelowResourceThreshold>("KillNBelowResourceThreshold");
-  action_lib->Register<cActionKillNAboveResourceThreshold>("KillNAboveResourceThreshold");
 }

Modified: development/source/main/cDeme.cc
===================================================================
--- development/source/main/cDeme.cc	2009-05-18 15:14:36 UTC (rev 3236)
+++ development/source/main/cDeme.cc	2009-05-18 16:17:37 UTC (rev 3237)
@@ -34,6 +34,7 @@
 #include "cWorld.h"
 #include "cOrgMessagePredicate.h"
 #include "cOrgMovementPredicate.h"
+#include "cDemePredicate.h"
 
 void cDeme::Setup(int id, const tArray<int> & in_cells, int in_width, cWorld* world)
 {
@@ -269,7 +270,11 @@
 	
   cur_task_exe_count.SetAll(0);
   cur_reaction_count.SetAll(0);
-  
+
+	//reset remaining deme predicates
+  for (int i = 0; i < deme_pred_list.Size(); i++) {
+    (*deme_pred_list[i]).Reset();
+  }	
   //reset remaining message predicates
   for (int i = 0; i < message_pred_list.Size(); i++) {
     (*message_pred_list[i]).Reset();
@@ -656,6 +661,16 @@
   
 }
 
+bool cDeme::DemePredSatisfiedPreviously() {
+	for(int i = 0; i < deme_pred_list.Size(); i++) {
+    if(deme_pred_list[i]->PreviouslySatisfied()) {
+      deme_pred_list[i]->UpdateStats(m_world->GetStats());
+      return true;
+    }
+  }
+  return false;
+}
+
 bool cDeme::MsgPredSatisfiedPreviously() {
   for(int i = 0; i < message_pred_list.Size(); i++) {
     if(message_pred_list[i]->PreviouslySatisfied()) {
@@ -676,6 +691,10 @@
   return false;
 }
 
+int cDeme::GetNumDemePredicates() {
+  return deme_pred_list.Size();
+}
+
 int cDeme::GetNumMessagePredicates() {
   return message_pred_list.Size();
 }
@@ -684,6 +703,11 @@
   return movement_pred_list.Size();
 }
 
+cDemePredicate* cDeme::GetDemePredicate(int i) {
+  assert(i < deme_pred_list.Size());
+  return deme_pred_list[i];
+}
+
 cOrgMessagePredicate* cDeme::GetMsgPredicate(int i) {
   assert(i < message_pred_list.Size());
   return message_pred_list[i];
@@ -694,6 +718,12 @@
   return movement_pred_list[i];
 }
 
+void cDeme::AddDemeResourceThresholdPredicate(cString resourceName, cString comparisonOperator, double threasholdValue) {
+	cDemeResourceThresholdPredicate* pred = new cDemeResourceThresholdPredicate(resourceName, comparisonOperator, threasholdValue);
+	deme_pred_list.Add(pred);
+	
+}
+
 void cDeme::AddEventReceivedCenterPred(int times) {
   if(cell_events.Size() == 0) {
     cerr<<"Error: An EventReceivedCenterPred cannot be created until a CellEvent is added.\n";

Modified: development/source/main/cDeme.h
===================================================================
--- development/source/main/cDeme.h	2009-05-18 15:14:36 UTC (rev 3236)
+++ development/source/main/cDeme.h	2009-05-18 16:17:37 UTC (rev 3237)
@@ -43,6 +43,7 @@
 class cOrganism;
 class cOrgMovementPredicate;
 class cOrgMessagePredicate;
+class cDemePredicate;
 
 /*! Demes are groups of cells in the population that are somehow bound together
 as a unit.  The deme object is used from within cPopulation to manage these 
@@ -127,6 +128,7 @@
   cMerit _current_merit; //!< Deme merit applied to all organisms living in this deme.
   cMerit _next_merit; //!< Deme merit that will be inherited upon deme replication.
 
+  tVector<cDemePredicate*> deme_pred_list; // Deme Predicates
   tVector<cOrgMessagePredicate*> message_pred_list; // Message Predicates
   tVector<cOrgMovementPredicate*> movement_pred_list;  // Movement Predicates
 	
@@ -298,14 +300,18 @@
   void ReplaceGermline(cGenotype& _in_genotype);
   int GetGermlineGenotypeID() { return m_germline_genotype_id; }
 
-  // --- Message/Movement predicates --- //
+  // --- Deme/Message/Movement predicates --- //
+	bool DemePredSatisfiedPreviously();
   bool MsgPredSatisfiedPreviously();
   bool MovPredSatisfiedPreviously();
+  int GetNumDemePredicates();
   int GetNumMessagePredicates();
   int GetNumMovementPredicates();
+  cDemePredicate* GetDemePredicate(int i);
   cOrgMessagePredicate* GetMsgPredicate(int i);
   cOrgMovementPredicate* GetMovPredicate(int i);
 
+	void AddDemeResourceThresholdPredicate(cString resourceName, cString comparisonOperator, double threasholdValue);
   void AddEventReceivedCenterPred(int times);
   void AddEventReceivedLeftSidePred(int times);
   void AddEventMoveCenterPred(int times);

Modified: development/source/main/cOrgMovementPredicate.h
===================================================================
--- development/source/main/cOrgMovementPredicate.h	2009-05-18 15:14:36 UTC (rev 3236)
+++ development/source/main/cOrgMovementPredicate.h	2009-05-18 16:17:37 UTC (rev 3237)
@@ -43,10 +43,9 @@
 #include "cStats.h"
 
 
-/*! \brief An STL-compatible predicate on cOrgMessages.  The intent here is to
-provide a straightforward way to track arbitrary messages *wherever* they appear
-in the population.  The most utility can be had from message predicates if they're
-installed into cStats (since every message goes through cStats). */
+/*! \brief An STL-compatible predicate on movement.  The intent here is to
+provide a straightforward way to track arbitrary movement *wherever* they appear
+in the population.  */
 struct cOrgMovementPredicate : public std::unary_function<cOrganism, bool> 
 {
   virtual ~cOrgMovementPredicate() { }

Modified: development/source/main/cPopulation.cc
===================================================================
--- development/source/main/cPopulation.cc	2009-05-18 15:14:36 UTC (rev 3236)
+++ development/source/main/cPopulation.cc	2009-05-18 16:17:37 UTC (rev 3237)
@@ -1237,6 +1237,7 @@
 5: 'sat-mov-pred'...demes whose movement predicate was previously satisfied
 6: 'events-killed' ...demes that have killed a certian number of events
 7: 'sat-msg-pred'...demes whose movement predicate was previously satisfied
+8: 'sat-deme-predicate'...demes whose predicate has been satisfied; does not include movement or message predicates as those are organisms-level
 
 */
 
@@ -1305,6 +1306,10 @@
         if(!(source_deme.MsgPredSatisfiedPreviously())) continue;
         break;
       }
+			case 8: {
+        if(!(source_deme.DemePredSatisfiedPreviously())) continue;
+        break;
+			}
       default: {
         cerr << "ERROR: Invalid replication trigger " << rep_trigger
         << " in cPopulation::ReplicateDemes()" << endl;




More information about the Avida-cvs mailing list