[Avida-cvs] [avida-svn] r881 - in development/source: actions event

brysonda at myxo.css.msu.edu brysonda at myxo.css.msu.edu
Tue Aug 22 13:26:10 PDT 2006


Author: brysonda
Date: 2006-08-22 16:26:10 -0400 (Tue, 22 Aug 2006)
New Revision: 881

Modified:
   development/source/actions/PopulationActions.cc
   development/source/event/cEventManager.cc
Log:
Transition JoinGrid(Col/Row) into the actions framework.

Modified: development/source/actions/PopulationActions.cc
===================================================================
--- development/source/actions/PopulationActions.cc	2006-08-21 17:52:36 UTC (rev 880)
+++ development/source/actions/PopulationActions.cc	2006-08-22 20:26:10 UTC (rev 881)
@@ -952,16 +952,16 @@
   {
     const int world_x = m_world->GetPopulation().GetWorldX();
     const int world_y = m_world->GetPopulation().GetWorldY();
-    if (m_id == -1) m_id = world_x / 2;
-    if (m_max == -1) m_max = world_y;
-    if (m_id < 0 || m_id >= world_x) {
+    if (m_id == -1) m_id = world_y / 2;
+    if (m_max == -1) m_max = world_x;
+    if (m_id < 0 || m_id >= world_y) {
       cString err = cStringUtil::Stringf("Row ID %d out of range for SeverGridRow", m_id);
       m_world->GetDriver().RaiseException(err);
       return;
     }
     // Loop through all of the rows and make the cut on each...
     for (int col_id = m_min; col_id < m_max; col_id++) {
-      int idA = col_id * world_x + m_id;
+      int idA = col_id * world_y + m_id;
       int idB  = GridNeighbor(idA, world_x, world_y,  0, -1);
       int idA0 = GridNeighbor(idA, world_x, world_y, -1,  0);
       int idA1 = GridNeighbor(idA, world_x, world_y,  1,  0);
@@ -982,7 +982,131 @@
 };
 
 
+/*
+ Join the connections between cells along a column in an avida grid.
 
+ Arguments:
+   col_id:  indicates the number of columns to the left of the joining.
+            default (or -1) = join population halves.
+   min_row: First row to start joining from
+            default = 0
+   max_row: Last row to join to
+            default (or -1) = last row in population.
+*/
+class cActionJoinGridCol : public cAction
+{
+private:
+  int m_id;
+  int m_min;
+  int m_max;
+public:
+  cActionJoinGridCol(cWorld* world, const cString& args) : cAction(world, args), m_id(-1), m_min(0), m_max(-1)
+  {
+    cString largs(args);
+    if (largs.GetSize()) m_id = largs.PopWord().AsInt();
+    if (largs.GetSize()) m_min = largs.PopWord().AsInt();
+    if (largs.GetSize()) m_max = largs.PopWord().AsInt();
+  }
+  
+  const cString GetDescription() { return "JoinGridCol [int col_id=-1] [int min_col=0] [int max_col=-1]"; }
+  
+  void Process(cAvidaContext& ctx)
+  {
+    const int world_x = m_world->GetPopulation().GetWorldX();
+    const int world_y = m_world->GetPopulation().GetWorldY();
+    if (m_id == -1) m_id = world_x / 2;
+    if (m_max == -1) m_max = world_y;
+    if (m_id < 0 || m_id >= world_x) {
+      cString err = cStringUtil::Stringf("Column ID %d out of range for JoinGridCol", m_id);
+      m_world->GetDriver().RaiseException(err);
+      return;
+    }
+    // Loop through all of the rows and make the cut on each...
+    for (int row_id = m_min; row_id < m_max; row_id++) {
+      int idA = row_id * world_x + m_id;
+      int idB  = GridNeighbor(idA, world_x, world_y, -1,  0);
+      cPopulationCell& cellA = m_world->GetPopulation().GetCell(idA);
+      cPopulationCell& cellB = m_world->GetPopulation().GetCell(idB);
+      cPopulationCell& cellA0 = m_world->GetPopulation().GetCell(GridNeighbor(idA, world_x, world_y,  0, -1));
+      cPopulationCell& cellA1 = m_world->GetPopulation().GetCell(GridNeighbor(idA, world_x, world_y,  0,  1));
+      cPopulationCell& cellB0 = m_world->GetPopulation().GetCell(GridNeighbor(idA, world_x, world_y, -1, -1));
+      cPopulationCell& cellB1 = m_world->GetPopulation().GetCell(GridNeighbor(idA, world_x, world_y, -1,  1));
+      tList<cPopulationCell>& cellA_list = cellA.ConnectionList();
+      tList<cPopulationCell>& cellB_list = cellB.ConnectionList();
+      if (cellA_list.FindPtr(&cellB)  == NULL) cellA_list.Push(&cellB);
+      if (cellA_list.FindPtr(&cellB0) == NULL) cellA_list.Push(&cellB0);
+      if (cellA_list.FindPtr(&cellB1) == NULL) cellA_list.Push(&cellB1);
+      if (cellB_list.FindPtr(&cellA)  == NULL) cellB_list.Push(&cellA);
+      if (cellB_list.FindPtr(&cellA0) == NULL) cellB_list.Push(&cellA0);
+      if (cellB_list.FindPtr(&cellA1) == NULL) cellB_list.Push(&cellA1);
+    }
+  }
+};
+
+
+/*
+ Remove the connections between cells along a column in an avida grid.
+
+ Arguments:
+   row_id:  indicates the number of rows abovef the cut.
+            default (or -1) = cut population in half
+   min_col: First row to start cutting from
+            default = 0
+   max_col: Last row to cut to
+            default (or -1) = last row in population.
+*/
+class cActionJoinGridRow : public cAction
+{
+private:
+  int m_id;
+  int m_min;
+  int m_max;
+public:
+  cActionJoinGridRow(cWorld* world, const cString& args) : cAction(world, args), m_id(-1), m_min(0), m_max(-1)
+  {
+    cString largs(args);
+    if (largs.GetSize()) m_id = largs.PopWord().AsInt();
+    if (largs.GetSize()) m_min = largs.PopWord().AsInt();
+    if (largs.GetSize()) m_max = largs.PopWord().AsInt();
+  }
+  
+  const cString GetDescription() { return "JoinGridRow [int col_id=-1] [int min_col=0] [int max_col=-1]"; }
+  
+  void Process(cAvidaContext& ctx)
+  {
+    const int world_x = m_world->GetPopulation().GetWorldX();
+    const int world_y = m_world->GetPopulation().GetWorldY();
+    if (m_id == -1) m_id = world_y / 2;
+    if (m_max == -1) m_max = world_x;
+    if (m_id < 0 || m_id >= world_y) {
+      cString err = cStringUtil::Stringf("Row ID %d out of range for JoinGridCol", m_id);
+      m_world->GetDriver().RaiseException(err);
+      return;
+    }
+    // Loop through all of the rows and make the cut on each...
+    for (int col_id = m_min; col_id < m_max; col_id++) {
+      int idA = col_id * world_y + m_id;
+      int idB  = GridNeighbor(idA, world_x, world_y, 0, -1);
+      cPopulationCell& cellA = m_world->GetPopulation().GetCell(idA);
+      cPopulationCell& cellB = m_world->GetPopulation().GetCell(idB);
+      cPopulationCell& cellA0 = m_world->GetPopulation().GetCell(GridNeighbor(idA, world_x, world_y, -1,  0));
+      cPopulationCell& cellA1 = m_world->GetPopulation().GetCell(GridNeighbor(idA, world_x, world_y,  1,  0));
+      cPopulationCell& cellB0 = m_world->GetPopulation().GetCell(GridNeighbor(idA, world_x, world_y, -1, -1));
+      cPopulationCell& cellB1 = m_world->GetPopulation().GetCell(GridNeighbor(idA, world_x, world_y,  1, -1));
+      tList<cPopulationCell>& cellA_list = cellA.ConnectionList();
+      tList<cPopulationCell>& cellB_list = cellB.ConnectionList();
+      if (cellA_list.FindPtr(&cellB)  == NULL) cellA_list.Push(&cellB);
+      if (cellA_list.FindPtr(&cellB0) == NULL) cellA_list.Push(&cellB0);
+      if (cellA_list.FindPtr(&cellB1) == NULL) cellA_list.Push(&cellB1);
+      if (cellB_list.FindPtr(&cellA)  == NULL) cellB_list.Push(&cellA);
+      if (cellB_list.FindPtr(&cellA0) == NULL) cellB_list.Push(&cellA0);
+      if (cellB_list.FindPtr(&cellA1) == NULL) cellB_list.Push(&cellA1);
+    }
+  }
+};
+
+
+
 void RegisterPopulationActions(cActionLibrary* action_lib)
 {
   action_lib->Register<cActionInject>("Inject");
@@ -1009,6 +1133,8 @@
   
   action_lib->Register<cActionSeverGridCol>("SeverGridCol");
   action_lib->Register<cActionSeverGridRow>("SeverGridRow");
+  action_lib->Register<cActionJoinGridCol>("JoinGridCol");
+  action_lib->Register<cActionJoinGridRow>("JoinGridRow");
 
   // @DMB - The following actions are DEPRECATED aliases - These will be removed in 2.7.
   action_lib->Register<cActionInject>("inject");
@@ -1030,4 +1156,6 @@
   
   action_lib->Register<cActionSeverGridCol>("sever_grid_col");
   action_lib->Register<cActionSeverGridRow>("sever_grid_row");
+  action_lib->Register<cActionJoinGridCol>("join_grid_col");
+  action_lib->Register<cActionJoinGridRow>("join_grid_row");
 }

Modified: development/source/event/cEventManager.cc
===================================================================
--- development/source/event/cEventManager.cc	2006-08-21 17:52:36 UTC (rev 880)
+++ development/source/event/cEventManager.cc	2006-08-22 20:26:10 UTC (rev 881)
@@ -41,144 +41,7 @@
 using namespace std;
 
 
-///// join_grid_col /////
 
-/**
-* Join the connections between cells along a column in an avida grid.
- * Arguments:
- *  col_id:  indicates the number of columns to the left of the joining.
- *           default (or -1) = join population halves.
- *  min_row: First row to start joining from
- *           default = 0
- *  max_row: Last row to join to
- *           default (or -1) = last row in population.
- **/
-
-
-class cEvent_join_grid_col : public cEvent {
-private:
-  int col_id;
-  int min_row;
-  int max_row;
-public:
-    const cString GetName() const { return "join_grid_col"; }
-  const cString GetDescription() const { return "join_grid_col  [int col_id=-1] [int min_row=0] [int max_row=-1]"; }
-  
-  void Configure(cWorld* world, const cString& in_args)
-  {
-    m_world = world;
-    m_args = in_args;
-    cString args(in_args);
-    if (args == "") col_id=-1; else col_id=args.PopWord().AsInt();
-    if (args == "") min_row=0; else min_row=args.PopWord().AsInt();
-    if (args == "") max_row=-1; else max_row=args.PopWord().AsInt();
-  }
-  ///// join_grid_col /////
-  void Process(){
-    const int world_x = m_world->GetPopulation().GetWorldX();
-    const int world_y = m_world->GetPopulation().GetWorldY();
-    if (col_id == -1) col_id = world_x / 2;
-    if (max_row == -1) max_row = world_y;
-    if (col_id < 0 || col_id >= world_x) {
-      cerr << "Event Error: Column ID " << col_id
-      << " out of range for join_grid_col" << endl;
-      return;
-    }
-    // Loop through all of the rows and make the cut on each...
-    for (int row_id = min_row; row_id < max_row; row_id++) {
-      int idA = row_id * world_x + col_id;
-      int idB  = GridNeighbor(idA, world_x, world_y, -1,  0);
-      cPopulationCell & cellA = m_world->GetPopulation().GetCell(idA);
-      cPopulationCell & cellB = m_world->GetPopulation().GetCell(idB);
-      cPopulationCell & cellA0 =
-        m_world->GetPopulation().GetCell(GridNeighbor(idA, world_x, world_y,  0, -1));
-      cPopulationCell & cellA1 =
-        m_world->GetPopulation().GetCell(GridNeighbor(idA, world_x, world_y,  0,  1));
-      cPopulationCell & cellB0 =
-        m_world->GetPopulation().GetCell(GridNeighbor(idA, world_x, world_y, -1, -1));
-      cPopulationCell & cellB1 =
-        m_world->GetPopulation().GetCell(GridNeighbor(idA, world_x, world_y, -1,  1));
-      tList<cPopulationCell> & cellA_list = cellA.ConnectionList();
-      tList<cPopulationCell> & cellB_list = cellB.ConnectionList();
-      if (cellA_list.FindPtr(&cellB)  == NULL) cellA_list.Push(&cellB);
-      if (cellA_list.FindPtr(&cellB0) == NULL) cellA_list.Push(&cellB0);
-      if (cellA_list.FindPtr(&cellB1) == NULL) cellA_list.Push(&cellB1);
-      if (cellB_list.FindPtr(&cellA)  == NULL) cellB_list.Push(&cellA);
-      if (cellB_list.FindPtr(&cellA0) == NULL) cellB_list.Push(&cellA0);
-      if (cellB_list.FindPtr(&cellA1) == NULL) cellB_list.Push(&cellA1);
-    }
-  }
-};
-
-///// join_grid_row /////
-
-/**
-* Remove the connections between cells along a column in an avida grid.
- * Arguments:
- *  row_id:  indicates the number of rows abovef the cut.
- *           default (or -1) = cut population in half
- *  min_col: First row to start cutting from
- *           default = 0
- *  max_col: Last row to cut to
- *           default (or -1) = last row in population.
- **/
-
-
-class cEvent_join_grid_row : public cEvent {
-private:
-  int row_id;
-  int min_col;
-  int max_col;
-public:
-    const cString GetName() const { return "join_grid_row"; }
-  const cString GetDescription() const { return "join_grid_row  [int row_id=-1] [int min_col=0] [int max_col=-1]"; }
-  
-  void Configure(cWorld* world, const cString& in_args)
-  {
-    m_world = world;
-    m_args = in_args;
-    cString args(in_args);
-    if (args == "") row_id=-1; else row_id=args.PopWord().AsInt();
-    if (args == "") min_col=0; else min_col=args.PopWord().AsInt();
-    if (args == "") max_col=-1; else max_col=args.PopWord().AsInt();
-  }
-  ///// join_grid_row /////
-  void Process(){
-    const int world_x = m_world->GetPopulation().GetWorldX();
-    const int world_y = m_world->GetPopulation().GetWorldY();
-    if (row_id == -1) row_id = world_y / 2;
-    if (max_col == -1) max_col = world_x;
-    if (row_id < 0 || row_id >= world_y) {
-      cerr << "Event Error: Row ID " << row_id
-      << " out of range for join_grid_row" << endl;
-      return;
-    }
-    // Loop through all of the cols and make the cut on each...
-    for (int col_id = min_col; col_id < max_col; col_id++) {
-      int idA = row_id * world_x + col_id;
-      int idB  = GridNeighbor(idA, world_x, world_y,  0, -1);
-      cPopulationCell & cellA = m_world->GetPopulation().GetCell(idA);
-      cPopulationCell & cellB = m_world->GetPopulation().GetCell(idB);
-      cPopulationCell & cellA0 =
-        m_world->GetPopulation().GetCell(GridNeighbor(idA, world_x, world_y, -1,  0));
-      cPopulationCell & cellA1 =
-        m_world->GetPopulation().GetCell(GridNeighbor(idA, world_x, world_y,  1,  0));
-      cPopulationCell & cellB0 =
-        m_world->GetPopulation().GetCell(GridNeighbor(idA, world_x, world_y, -1, -1));
-      cPopulationCell & cellB1 =
-        m_world->GetPopulation().GetCell(GridNeighbor(idA, world_x, world_y,  1, -1));
-      tList<cPopulationCell> & cellA_list = cellA.ConnectionList();
-      tList<cPopulationCell> & cellB_list = cellB.ConnectionList();
-      if (cellA_list.FindPtr(&cellB)  == NULL) cellA_list.Push(&cellB);
-      if (cellA_list.FindPtr(&cellB0) == NULL) cellA_list.Push(&cellB0);
-      if (cellA_list.FindPtr(&cellB1) == NULL) cellA_list.Push(&cellB1);
-      if (cellB_list.FindPtr(&cellA)  == NULL) cellB_list.Push(&cellA);
-      if (cellB_list.FindPtr(&cellA0) == NULL) cellB_list.Push(&cellA0);
-      if (cellB_list.FindPtr(&cellA1) == NULL) cellB_list.Push(&cellA1);
-    }
-  }
-};
-
 ///// connect_cells /////
 
 /**
@@ -310,8 +173,6 @@
 cEventManager::cEventManager(cWorld* world) : m_world(world)
 {
   // Population events --> Population Actions
-  REGISTER(join_grid_col);
-  REGISTER(join_grid_row);
   REGISTER(connect_cells);
   REGISTER(disconnect_cells);
 }




More information about the Avida-cvs mailing list