1 /*
2  *  cIntegratedScheduleNode.h
3  *  Avida
4  *
5  *  Called "integrated_schedule_node.hh" prior to 12/7/05.
6  *  Copyright 1999-2011 Michigan State University. All rights reserved.
7  *  Copyright 1993-2003 California Institute of Technology.
8  *
9  *
10  *  This file is part of Avida.
11  *
12  *  Avida is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License
13  *  as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
14  *
15  *  Avida is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
16  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
17  *
18  *  You should have received a copy of the GNU Lesser General Public License along with Avida.
19  *  If not, see <http://www.gnu.org/licenses/>.
20  *
21  */
22 
23 #ifndef cIntegratedScheduleNode_h
24 #define cIntegratedScheduleNode_h
25 
26 #ifndef tArray_h
27 #include "tArray.h"
28 #endif
29 
30 /**
31  * The cIntegratedScheduleNode object manages bundlings of item's for the
32  * integrated time slicing object (cIntegratedSchedule).  When GetNextID()
33  * is called on one of these nodes, it must either choose from itself, or
34  * pass the call down to the nodes below it (by running the GetNextID()
35  * method of the next node).  If the node alternates between everything in
36  * its own list the next node's list, then we have a perfect Logrithmic
37  * (base 2) decrease in activity.  Sometimes a merit will be skipped in the
38  * list, so the next node should only be called one out of every four times,
39  * etc.
40  *
41  * This allows binary representations of merits to determine which nodes
42  * each item should be included in.
43  **/
44 
45 class cIntegratedScheduleNode
46 {
47 private:
48   tArray<int> active_array; // Each cell in this array corressponds to the
49                       //  item with the same ID.  If creature is not in the
50                       //  list, its value in the array will be 0. If it is in
51                       //  the list, it will  point to the cell of the next
52                       //  included creature.  The last included creature has
53                       //  a -1 in its cell.
54   int first_entry;    // ID of first active creature.
55   int active_entry;   // ID of next scheduled entry.
56   int node_id;        // A unique id (representing the relative merit bit).
57 
58   int size;           // Number of active items in this node.
59   int process_size;   // Number of times this node should be executed before
60                       //   the next node is.
61   int process_count;  // Number of times this node has been executed.
62   bool execute;       // Should this node execute or pass?
63 
64   cIntegratedScheduleNode* next;
65   cIntegratedScheduleNode* prev;
66 
67 
68   cIntegratedScheduleNode(const cIntegratedScheduleNode&); // @not_implemented
69   cIntegratedScheduleNode& operator=(const cIntegratedScheduleNode&); // @not_implemented
70 
71 public:
72   cIntegratedScheduleNode(int _item_count = 0, int in_id = -1)
active_array(_item_count)73     : active_array(_item_count), first_entry(-1), active_entry(-1), node_id(in_id), size(0)
74     , process_size(1), process_count(0), execute(true), next(NULL), prev(NULL)
75   {
76       active_array.SetAll(0);
77   }
~cIntegratedScheduleNode()78   ~cIntegratedScheduleNode() { ; }
79 
80   void Insert(int item_id);
81   void Remove(int item_id);
82   int GetNextID();
83 
84   bool OK();
85 
SetProcessSize(int in_p_size)86   inline void SetProcessSize(int in_p_size) { process_size = in_p_size; }
SetNext(cIntegratedScheduleNode * in_next)87   inline void SetNext(cIntegratedScheduleNode * in_next) { next = in_next; }
SetPrev(cIntegratedScheduleNode * in_prev)88   inline void SetPrev(cIntegratedScheduleNode * in_prev) { prev = in_prev; }
89 
GetID()90   inline int GetID() { return node_id; }
GetSize()91   inline int GetSize() { return size; }
GetProcessSize()92   inline int GetProcessSize() { return process_size; }
GetProcessCount()93   inline int GetProcessCount() { return process_count; }
GetNext()94   inline cIntegratedScheduleNode * GetNext() { return next; }
GetPrev()95   inline cIntegratedScheduleNode * GetPrev() { return prev; }
96 };
97 
98 #endif
99