1 /*
2  *  cPhenotype.h
3  *  Avida
4  *
5  *  Called "phenotype.hh" prior to 12/5/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 cPhenotype_h
24 #define cPhenotype_h
25 
26 #include "avida/core/Sequence.h"
27 
28 #include <fstream>
29 
30 #ifndef cMerit_h
31 #include "cMerit.h"
32 #endif
33 #ifndef cString_h
34 #include "cString.h"
35 #endif
36 #ifndef tArray_h
37 #include "tArray.h"
38 #endif
39 #ifndef cCodeLabel_h
40 #include "cCodeLabel.h"
41 #endif
42 #ifndef tHashMap_h
43 #include "tHashMap.h"
44 #endif
45 #ifndef cWorld_h
46 #include "cWorld.h"
47 #endif
48 
49 
50 /*************************************************************************
51  *
52  * The cPhenotype object contains a general description of all the
53  * phenotypic characteristics an organism has displayed.  That is, it
54  * monitors all of the organisms behaviors.
55  *
56  * After a phenotype is created in organism and organism within a population,
57  * it must have either SetupOffspring() or SetupInject() run on it to prime
58  * it for that population.  After that, it must have DivideReset() run on it
59  * whenever it produces an offspring.
60  *
61  * If the phenotype is part of an organism in a test cpu, no initial priming
62  * is required, and SetupTestDivide() needs to be run once it finally has
63  * produced an offspring in order to properly lock in any final values.
64  *
65  * In addition to a reference to the relevent environment, the data
66  * contained within this class comes in six flavors:
67  *   1. Calculations made at the previous divide.
68  *   2. Stats which are accumulated over each gestation cycle.
69  *   3. The final result of accumulations over the previous gestation cycle.
70  *   4. Accumulations over the entire life of the genome.
71  *   5. A collection of flags to indicate the presence of characteristics.
72  *   6. Information about the child being constructed.
73  *
74  *************************************************************************/
75 
76 class cAvidaContext;
77 class cContextPhenotype;
78 class cEnvironment;
79 template <class T> class tBuffer;
80 template <class T> class tList;
81 class cTaskContext;
82 class cTaskState;
83 class cPhenPlastSummary;
84 class cReactionResult;
85 
86 using namespace Avida;
87 
88 
89 class cPhenotype
90 {
91   friend class cOrganism;
92 private:
93   cWorld* m_world;
94   bool initialized;
95 
96   // 1. These are values calculated at the last divide (of self or offspring)
97   cMerit merit;             // Relative speed of CPU
98   double executionRatio;    //  ratio of current execution merit over base execution merit
99   double energy_store;      // Amount of energy.  Determines relative speed of CPU when turned on.
100   int genome_length;        // Number of instructions in genome.
101   int bonus_instruction_count; // Number of times MERIT_BONUS_INT is in genome.
102   int copied_size;          // Instructions copied into genome.
103   int executed_size;        // Instructions executed from genome.
104   int gestation_time;       // CPU cycles to produce offspring (or be produced),
105                             // including additional time costs of some instructions.
106   int gestation_start;      // Total instructions executed at last divide.
107   double fitness;           // Relative effective replication rate...
108   double div_type;          // Type of the divide command used
109 
110   // 2. These are "in progress" variables, updated as the organism operates
111   double cur_bonus;                           // Current Bonus
112   double cur_energy_bonus;                    // Current energy bonus
113   double energy_tobe_applied;                 // Energy that has not yet been added to energy store.
114   double energy_testament;
115   double energy_received_buffer;              // Energy received through donation, but not yet applied to energy store
116   double total_energy_donated;                // Tota amount of energy that has been donated
117   double total_energy_received;               // Total amount of energy received through donations
118   double total_energy_applied;                // Total amount of received energy applied to energy store
119   int num_energy_requests;                    // Number of times organism has requested energy
120   int num_energy_donations;                   // Number of times energy has been donated
121   int num_energy_receptions;                  // Number of times organism has received energy donations
122   int num_energy_applications;                // Number of times organism has applied donated energy to its energy store
123   int cur_num_errors;                         // Total instructions executed illeagally.
124   int cur_num_donates;                        // Number of donations so far
125   tArray<int> cur_task_count;                 // Total times each task was performed
126   tArray<int> cur_para_tasks;                 // Total times each task was performed by the parasite @LZ
127   tArray<int> cur_host_tasks;                 // Total times each task was done by JUST the host @LZ
128   tArray<int> cur_internal_task_count;        // Total times each task was performed using internal resources
129   tArray<int> eff_task_count;                 // Total times each task was performed (resetable during the life of the organism)
130   tArray<double> cur_task_quality;            // Average (total?) quality with which each task was performed
131   tArray<double> cur_task_value;              // Value with which this phenotype performs task
132   tArray<double> cur_internal_task_quality;   // Average (total?) quaility with which each task using internal resources was performed
133   tArray<double> cur_rbins_total;             // Total amount of resources collected over the organism's life
134   tArray<double> cur_rbins_avail;             // Amount of internal resources available
135   tArray<int> cur_collect_spec_counts;        // How many times each nop-specification was used in a collect-type instruction
136   tArray<int> cur_reaction_count;             // Total times each reaction was triggered.
137   tArray<int> first_reaction_cycles;          // CPU cycles of first time reaction was triggered.
138   tArray<int> first_reaction_execs;            // Execution count at first time reaction was triggered (will be > cycles in parallel exec multithreaded orgs).
139   tArray<int> cur_stolen_reaction_count;      // Total counts of reactions stolen by predators.
140   tArray<double> cur_reaction_add_reward;     // Bonus change from triggering each reaction.
141   tArray<int> cur_inst_count;                 // Instruction exection counter
142   tArray<int> cur_sense_count;                // Total times resource combinations have been sensed; @JEB
143   tArray<double> sensed_resources;            // Resources which the organism has sensed; @JEB
144   tArray<double> cur_task_time;               // Time at which each task was last performed; WRE 03-18-07
145   tHashMap<void*, cTaskState*> m_task_states;
146   tArray<double> cur_trial_fitnesses;         // Fitnesses of various trials.; @JEB
147   tArray<double> cur_trial_bonuses;           // Bonuses of various trials.; @JEB
148   tArray<int> cur_trial_times_used;           // Time used in of various trials.; @JEB
149   int trial_time_used;                        // like time_used, but reset every trial; @JEB
150   int trial_cpu_cycles_used;                  // like cpu_cycles_used, but reset every trial; @JEB
151   tList<int> m_tolerance_immigrants;           // record of previous updates tolerance has been decreased towards immigrants
152   tList<int> m_tolerance_offspring_own;        // record of previous updates tolerance has been decreased towards org's own offspring
153   tList<int> m_tolerance_offspring_others;     // record of previous updates tolerance has been decreased towards other offspring in group
154   tArray<pair<int,int> > m_intolerances;        // caches temporary values of the intolerance and the update
155   double last_child_germline_propensity;   // chance of child being a germline cell; @JEB
156 
157   int mating_type;                            // Organism's phenotypic sex @CHC
158   int mate_preference;                        // Organism's mating preference @CHC
159 
160   int cur_mating_display_a;                   // value of organism's current mating display A trait
161   int cur_mating_display_b;                   // value of organism's current mating display B trait
162 
163   cReactionResult* m_reaction_result;
164 
165 
166 
167   // 3. These mark the status of "in progess" variables at the last divide.
168   double last_merit_base;         // Either constant or based on genome length.
169   double last_bonus;
170   double last_energy_bonus;
171   int last_num_errors;
172   int last_num_donates;
173   tArray<int> last_task_count;
174   tArray<int> last_para_tasks;
175   tArray<int> last_host_tasks;                // Last task counts from hosts only, before last divide @LZ
176   tArray<int> last_internal_task_count;
177   tArray<double> last_task_quality;
178   tArray<double> last_task_value;
179   tArray<double> last_internal_task_quality;
180   tArray<double> last_rbins_total;
181   tArray<double> last_rbins_avail;
182   tArray<int> last_collect_spec_counts;
183   tArray<int> last_reaction_count;
184   tArray<double> last_reaction_add_reward;
185   tArray<int> last_inst_count;	  // Instruction exection counter
186   tArray<int> last_sense_count;   // Total times resource combinations have been sensed; @JEB
187   double last_fitness;            // Used to determine sterilization.
188   int last_cpu_cycles_used;
189   double cur_child_germline_propensity;   // chance of child being a germline cell; @JEB
190 
191   int last_mating_display_a;                   // value of organism's last mating display A trait
192   int last_mating_display_b;                   // value of organism's last mating display B trait
193 
194 
195   // 4. Records from this organism's life...
196   int num_divides_failed; //Number of failed divide events @LZ
197   int num_divides;       // Total successful divides organism has produced.
198   int generation;        // Number of birth events to original ancestor.
199   int cpu_cycles_used;   // Total CPU cycles consumed. @JEB
200   int time_used;         // Total CPU cycles consumed, including additional time costs of some instructions.
201   int num_execs;         // Total number of instructions executions attempted...accounts for parallel executions in multi-threaded orgs & corrects for cpu-cost 'pauses'
202   int age;               // Number of updates organism has survived for.
203   cString fault_desc;    // A description of the most recent error.
204   double neutral_metric; // Undergoes drift (gausian 0,1) per generation
205   double life_fitness; 	 // Organism fitness during its lifetime,
206 		         // calculated based on merit just before the divide
207   int exec_time_born;    // @MRR number of instructions since seed ancestor start
208   double gmu_exec_time_born; //@MRR mutation-rate and gestation time scaled time of birth
209   int birth_update;      // @MRR update *organism* born
210   int birth_cell_id;
211   int av_birth_cell_id;
212   int birth_group_id;
213   int birth_forager_type;
214   tArray<int> testCPU_inst_count;	  // Instruction exection counter as calculated by Test CPU
215   int last_task_id; // id of the previous task
216   int num_new_unique_reactions; // count the number of new unique reactions this organism has performed.
217   double res_consumed; // amount of resources consumed since the organism last turned them over to the deme.
218   bool is_germ_cell; // records whether or not the organism is part of the germline.
219   int last_task_time; // time at which the previous task was performed
220 
221 
222 
223 
224   // 5. Status Flags...  (updated at each divide)
225   bool to_die;		 // Has organism has triggered something fatal?
226   bool to_delete;        // Should this organism be deleted when finished?
227   bool is_injected;      // Was this organism injected into the population?
228   bool is_donor_cur;     // Has this organism attempted to donate merit?
229   bool is_donor_last;    // Did this organism's parent attempt to donate merit?
230   bool is_donor_rand;    // Has this organism attempted a random donation?
231   bool is_donor_rand_last; // Did this org's parent attempt to donate randomly
232   bool is_donor_null;    // Has this organism attempted a null donation?
233   bool is_donor_null_last;// Did this org's parent attempt a null donation?
234   bool is_donor_kin;     // Has this organism kin_donated?
235   bool is_donor_kin_last;// Did this org's parent kin_donate?
236   bool is_donor_edit;    // Has this organism edit_donated?
237   bool is_donor_edit_last; // Did this org's parent edit_donate?
238   bool is_donor_gbg;     //  Has this organism gbg_donated (green beard gene)?
239   bool is_donor_gbg_last;// Did this org's parent gbg_donate?
240   bool is_donor_truegb;  // Has this organism truegb_donated (true green beard)?
241   bool is_donor_truegb_last;// Did this org's parent truegb_donate?
242   bool is_donor_threshgb;  // Has this organism threshgb_donated (true green beard)?
243   bool is_donor_threshgb_last;// Did this org's parent threshgbg_donate?
244   bool is_donor_quanta_threshgb;  // Has this organism quanta_threshgb_donated (true green beard)?
245   bool is_donor_quanta_threshgb_last;// Did this org's parent quanta_threshgbg_donate?
246   bool is_donor_shadedgb; // Has this organism shaded_gb_donated (true shaded green beard)?
247   bool is_donor_shadedgb_last; // Did this org's parent shaded_gb_donate?
248   tArray<bool> is_donor_locus; // Did this org target a donation at a specific locus.
249   tArray<bool> is_donor_locus_last; // Did this org's parent target a donation at a specific locus.
250   bool is_energy_requestor; // Has this organism requested energy?
251   bool is_energy_donor; // Has this organism donated energy?
252   bool is_energy_receiver;  // Has this organism received an energy donation?
253   bool has_used_donated_energy; // Has the organism actively used an energy donation?
254   bool has_open_energy_request; // Does the organism have an energy request that hasn't been answered?
255   int num_thresh_gb_donations;  // Num times this organism threshgb_donated (thresh green beard)?
256   int num_thresh_gb_donations_last; // Num times this org's parent thresh_donated?
257   int num_quanta_thresh_gb_donations;  // Num times this organism threshgb_donated (thresh green beard)?
258   int num_quanta_thresh_gb_donations_last; // Num times this org's parent thresh_donated?
259   int num_shaded_gb_donations; // Num times this org shaded_gb_donated?
260   int num_shaded_gb_donations_last; // Num times this org's parent shaded_gb_donated?
261   int num_donations_locus; // Num times this org targeted a donation to a position.
262   int num_donations_locus_last; // Num times this org's parent targeted a donation to a position.
263   bool is_receiver;      // Has this organism ever received merit donation?
264   bool is_receiver_last;      // Did this organism's parent receive a merit donation?
265   bool is_receiver_rand; // Has this organism ever received random merit donation?
266   bool is_receiver_kin;  // Has this organism ever received kin merit donation?
267   bool is_receiver_kin_last;  // Did this organism's parent receive a kin merit donation?
268   bool is_receiver_edit; // Has this organism ever received edit donation?
269   bool is_receiver_edit_last; // Did this organism's parent receive an edit donation?
270   bool is_receiver_gbg;  // Has this organism ever received gbg donation?
271   bool is_receiver_truegb;// Has this organism ever received truegb donation?
272   bool is_receiver_truegb_last;// Did this organism's parent receive a truegb donation?
273   bool is_receiver_threshgb;// Has this organism ever received a threshgb donation?
274   bool is_receiver_threshgb_last;// Did this organism's parent receive a threshgb donation?
275   bool is_receiver_quanta_threshgb;// Has this organism ever received a quanta_threshgb donation?
276   bool is_receiver_quanta_threshgb_last;// Did this organism's parent receive a quanta_threshgb donation?
277   bool is_receiver_shadedgb; // Has this organism ever received a shaded_gb donation?
278   bool is_receiver_shadedgb_last; // Did this organism's parent receive a shaded gb donation?
279   bool is_receiver_gb_same_locus; // Has this org ever received a donation for a specific locus.
280   bool is_receiver_gb_same_locus_last; // Did this org's parent ever received a donation for a specific locus.
281   bool is_modifier;      // Has this organism modified another?
282   bool is_modified;      // Has this organism been modified by another?
283   bool is_fertile;       // Do we allow this organisms to produce offspring?
284   bool is_mutated;       // Has this organism been subject to any mutations?
285   bool is_multi_thread;  // Does this organism have 2 or more threads?
286   bool parent_true;      // Is this genome an exact copy of its parent's?
287   bool parent_sex;       // Did the parent divide with sex?
288   int  parent_cross_num; // How many corssovers did the parent do?
289   bool born_parent_group;// Was offspring born into the parent's group?
290 
291   // 6. Child information...
292   bool copy_true;        // Can this genome produce an exact copy of itself?
293   bool divide_sex;       // Was this child created with a sexual divide?
294   int mate_select_id;    // If divide sex, who to mate with?
295   int  cross_num  ;      // ...how many crossovers should this child do?
296   bool child_fertile;    // Will this organism's next child be fertile?
297   bool last_child_fertile;  // Was the child being born to be fertile?
298   int child_copied_size; // Instruction copied into child.
299 
300   // 7. Information that is set once (when organism was born)
301   double permanent_germline_propensity;
302 
303 
304   inline void SetInstSetSize(int inst_set_size);
305 
306 public:
cPhenotype()307   cPhenotype() : m_world(NULL), m_reaction_result(NULL) { ; } // Will not construct a valid cPhenotype! Only exists to support incorrect cDeme tArray usage.
308   cPhenotype(cWorld* world, int parent_generation, int num_nops);
309 
310 
311   cPhenotype(const cPhenotype&);
312   cPhenotype& operator=(const cPhenotype&);
313   ~cPhenotype();
314 
315   enum energy_levels {ENERGY_LEVEL_LOW = 0, ENERGY_LEVEL_MEDIUM, ENERGY_LEVEL_HIGH};
316 
317   void ResetMerit(const Sequence & _cgenome);
318   void Sterilize();
319   // Run when being setup *as* and offspring.
320   void SetupOffspring(const cPhenotype & parent_phenotype, const Sequence & _genome);
321 
322   // Run when being setup as an injected organism.
323   void SetupInject(const Sequence & _genome);
324 
325   // Run when this organism successfully executes a divide.
326   void DivideReset(const Sequence & _genome);
327 
328   // Same as DivideReset(), but only run in test CPUs.
329   void TestDivideReset(const Sequence & _genome);
330 
331   // Run when an organism is being forced to replicate, but not at the end
332   // of its replication cycle.  Assume exact clone with no mutations.
333   void SetupClone(const cPhenotype & clone_phenotype);
334 
335   // Input and Output Reaction Tests
336   bool TestInput(tBuffer<int>& inputs, tBuffer<int>& outputs);
337   bool TestOutput(cAvidaContext& ctx, cTaskContext& taskctx,
338                   const tArray<double>& res_in, const tArray<double>& rbins_in, tArray<double>& res_change,
339                   tArray<cString>& insts_triggered, bool is_parasite=false, cContextPhenotype* context_phenotype = 0);
340 
341   // State saving and loading, and printing...
342   void PrintStatus(std::ostream& fp) const;
343 
344   // Some useful methods...
345   int CalcSizeMerit() const;
346   double CalcCurrentMerit() const;
347   double CalcFitness(double _merit_base, double _bonus, int _gestation_time, int _cpu_cycles) const;
348 
CalcFitnessRatio()349   double CalcFitnessRatio() {
350     const int merit_base = CalcSizeMerit();
351     const double cur_fitness = merit_base * cur_bonus / time_used;
352     return cur_fitness / last_fitness;
353   }
CalcID()354   int CalcID() const {
355     int phen_id = 0;
356     for (int i = 0; i < last_task_count.GetSize(); i++) {
357       if (last_task_count[i] > 0) phen_id += (1 << i);
358     }
359     return phen_id;
360   }
361 
362   /////////////////////  Accessors -- Retrieving  ////////////////////
GetMerit()363   const cMerit & GetMerit() const { assert(initialized == true); return merit; }
GetEnergyUsageRatio()364   double GetEnergyUsageRatio() const { assert(initialized == true); return executionRatio; }
GetGenomeLength()365   int GetGenomeLength() const { assert(initialized == true); return genome_length; }
GetCopiedSize()366   int GetCopiedSize() const { assert(initialized == true); return copied_size; }
GetExecutedSize()367   int GetExecutedSize() const { assert(initialized == true); return executed_size; }
GetGestationTime()368   int GetGestationTime() const { assert(initialized == true); return gestation_time; }
GetGestationStart()369   int GetGestationStart() const { assert(initialized == true); return gestation_start; }
GetFitness()370   double GetFitness() const { assert(initialized == true); return fitness; }
GetDivType()371   double GetDivType() const { assert(initialized == true); return div_type; }
372 
GetCurBonus()373   double GetCurBonus() const { assert(initialized == true); return cur_bonus; }
GetCurBonusInstCount()374   int    GetCurBonusInstCount() const { assert(bonus_instruction_count >= 0); return bonus_instruction_count; }
375 
GetCurMeritBase()376   double GetCurMeritBase() const { assert(initialized == true); return CalcSizeMerit(); }
GetStoredEnergy()377   double GetStoredEnergy() const { return energy_store; }
GetEnergyBonus()378   double GetEnergyBonus() const { assert(initialized == true); return cur_energy_bonus; }
379   int GetDiscreteEnergyLevel() const;
GetEnergyInBufferAmount()380   double GetEnergyInBufferAmount() const { return energy_received_buffer; }
381 
382   double ConvertEnergyToMerit(double energy) const;
383 
384   //@MRR Organism-specific birth tracking
GetGMuExecTimeBorn()385   double GetGMuExecTimeBorn() const {return gmu_exec_time_born;}
GetExecTimeBorn()386   int GetExecTimeBorn() const {return exec_time_born;}
GetUpdateBorn()387   int GetUpdateBorn() const {return birth_update;}
388 
GetBirthCell()389   int GetBirthCell() const { return birth_cell_id; }
GetAVBirthCell()390   int GetAVBirthCell() const { return av_birth_cell_id; }
GetBirthGroupID()391   int GetBirthGroupID() const { return birth_group_id; }
GetBirthForagerType()392   int GetBirthForagerType() const { return birth_forager_type; }
393   inline void SetBirthCellID(int birth_cell);
394   inline void SetAVBirthCellID(int av_birth_cell);
395   inline void SetBirthGroupID(int group_id);
396   inline void SetBirthForagerType(int forager_type);
397 
GetMatingType()398   int GetMatingType() const { return mating_type; } //@CHC
GetMatePreference()399   int GetMatePreference() const { return mate_preference; } //@CHC
400 
GetCurMatingDisplayA()401   int GetCurMatingDisplayA() const { return cur_mating_display_a; } //@CHC
GetCurMatingDisplayB()402   int GetCurMatingDisplayB() const { return cur_mating_display_b; } //@CHC
GetLastMatingDisplayA()403   int GetLastMatingDisplayA() const { return last_mating_display_a; } //@CHC
GetLastMatingDisplayB()404   int GetLastMatingDisplayB() const { return last_mating_display_b; } //@CHC
405 
GetToDie()406   bool GetToDie() const { assert(initialized == true); return to_die; }
GetToDelete()407   bool GetToDelete() const { assert(initialized == true); return to_delete; }
GetCurNumErrors()408   int GetCurNumErrors() const { assert(initialized == true); return cur_num_errors; }
GetCurNumDonates()409   int GetCurNumDonates() const { assert(initialized == true); return cur_num_donates; }
GetCurTaskCount()410   const tArray<int>& GetCurTaskCount() const { assert(initialized == true); return cur_task_count; }
GetCurHostTaskCount()411   const tArray<int>& GetCurHostTaskCount() const { assert(initialized == true); return cur_host_tasks; }
GetCurParasiteTaskCount()412   const tArray<int>& GetCurParasiteTaskCount() const { assert(initialized == true); return cur_para_tasks; }
GetCurInternalTaskCount()413   const tArray<int>& GetCurInternalTaskCount() const { assert(initialized == true); return cur_internal_task_count; }
ClearEffTaskCount()414   void ClearEffTaskCount() { assert(initialized == true); eff_task_count.SetAll(0); }
GetCurTaskQuality()415   const tArray<double> & GetCurTaskQuality() const { assert(initialized == true); return cur_task_quality; }
GetCurTaskValue()416   const tArray<double> & GetCurTaskValue() const { assert(initialized == true); return cur_task_value; }
GetCurInternalTaskQuality()417   const tArray<double> & GetCurInternalTaskQuality() const { assert(initialized == true); return cur_internal_task_quality; }
GetCurRBinsTotal()418   const tArray<double>& GetCurRBinsTotal() const { assert(initialized == true); return cur_rbins_total; }
GetCurRBinTotal(int index)419   double GetCurRBinTotal(int index) const { assert(initialized == true); return cur_rbins_total[index]; }
GetCurRBinsAvail()420   const tArray<double>& GetCurRBinsAvail() const { assert(initialized == true); return cur_rbins_avail; }
GetCurRBinAvail(int index)421   double GetCurRBinAvail(int index) const { assert(initialized == true); return cur_rbins_avail[index]; }
422 
GetCurReactionCount()423   const tArray<int>& GetCurReactionCount() const { assert(initialized == true); return cur_reaction_count;}
GetFirstReactionCycles()424   const tArray<int>& GetFirstReactionCycles() const { assert(initialized == true); return first_reaction_cycles;}
SetFirstReactionCycle(int idx)425   void SetFirstReactionCycle(int idx) { if (first_reaction_cycles[idx] < 0) first_reaction_cycles[idx] = time_used; }
GetFirstReactionExecs()426   const tArray<int>& GetFirstReactionExecs() const { assert(initialized == true); return first_reaction_execs;}
SetFirstReactionExec(int idx)427   void SetFirstReactionExec(int idx) { if (first_reaction_execs[idx] < 0) first_reaction_execs[idx] = num_execs; }
428 
GetStolenReactionCount()429   const tArray<int>& GetStolenReactionCount() const { assert(initialized == true); return cur_stolen_reaction_count;}
GetCurReactionAddReward()430   const tArray<double>& GetCurReactionAddReward() const { assert(initialized == true); return cur_reaction_add_reward;}
GetCurInstCount()431   const tArray<int>& GetCurInstCount() const { assert(initialized == true); return cur_inst_count; }
GetCurSenseCount()432   const tArray<int>& GetCurSenseCount() const { assert(initialized == true); return cur_sense_count; }
GetSensedResource(int _in)433   double GetSensedResource(int _in) { assert(initialized == true); return sensed_resources[_in]; }
GetCurCollectSpecCounts()434   const tArray<int>& GetCurCollectSpecCounts() const { assert(initialized == true); return cur_collect_spec_counts; }
GetCurCollectSpecCount(int spec_id)435   int GetCurCollectSpecCount(int spec_id) const { assert(initialized == true); return cur_collect_spec_counts[spec_id]; }
GetTestCPUInstCount()436   const tArray<int>& GetTestCPUInstCount() const { assert(initialized == true); return testCPU_inst_count; }
437 
438   void  NewTrial(); //Save the current fitness, and reset the bonus. @JEB
439   void  TrialDivideReset(const Sequence & _genome); //Subset of resets specific to division not done by NewTrial. @JEB
GetTrialFitnesses()440   const tArray<double>& GetTrialFitnesses() { return cur_trial_fitnesses; }; //Return list of trial fitnesses. @JEB
GetTrialBonuses()441   const tArray<double>& GetTrialBonuses() { return cur_trial_bonuses; }; //Return list of trial bonuses. @JEB
GetTrialTimesUsed()442   const tArray<int>& GetTrialTimesUsed() { return cur_trial_times_used; }; //Return list of trial times used. @JEB
443 
GetToleranceImmigrants()444   tList<int>& GetToleranceImmigrants() { assert(initialized == true); return m_tolerance_immigrants; }
GetToleranceOffspringOwn()445   tList<int>& GetToleranceOffspringOwn() { assert(initialized == true); return m_tolerance_offspring_own; }
GetToleranceOffspringOthers()446   tList<int>& GetToleranceOffspringOthers() { assert(initialized == true); return m_tolerance_offspring_others; }
GetIntolerances()447   tArray<pair<int,int> >& GetIntolerances() { assert(initialized == true); return m_intolerances; }
448   int CalcToleranceImmigrants();
449   int CalcToleranceOffspringOwn();
450   int CalcToleranceOffspringOthers();
451 
GetLastMeritBase()452   double GetLastMeritBase() const { assert(initialized == true); return last_merit_base; }
GetLastBonus()453   double GetLastBonus() const { assert(initialized == true); return last_bonus; }
454 
GetLastMerit()455   double GetLastMerit() const { assert(initialized == true); return last_merit_base*last_bonus; }
GetLastNumErrors()456   int GetLastNumErrors() const { assert(initialized == true); return last_num_errors; }
GetLastNumDonates()457   int GetLastNumDonates() const { assert(initialized == true); return last_num_donates; }
GetLastTaskCount()458   const tArray<int>& GetLastTaskCount() const { assert(initialized == true); return last_task_count; }
SetLastTaskCount(tArray<int> tasks)459   void SetLastTaskCount(tArray<int> tasks) { assert(initialized == true); last_task_count = tasks; }
GetLastHostTaskCount()460   const tArray<int>& GetLastHostTaskCount() const { assert(initialized == true); return last_host_tasks; }
GetLastParasiteTaskCount()461   const tArray<int>& GetLastParasiteTaskCount() const { assert(initialized == true); return last_para_tasks; }
462   void  SetLastParasiteTaskCount(tArray<int>  oldParaPhenotype);
GetLastInternalTaskCount()463   const tArray<int>& GetLastInternalTaskCount() const { assert(initialized == true); return last_internal_task_count; }
GetLastTaskQuality()464   const tArray<double>& GetLastTaskQuality() const { assert(initialized == true); return last_task_quality; }
GetLastTaskValue()465   const tArray<double>& GetLastTaskValue() const { assert(initialized == true); return last_task_value; }
GetLastInternalTaskQuality()466   const tArray<double>& GetLastInternalTaskQuality() const { assert(initialized == true); return last_internal_task_quality; }
GetLastRBinsTotal()467   const tArray<double>& GetLastRBinsTotal() const { assert(initialized == true); return last_rbins_total; }
GetLastRBinsAvail()468   const tArray<double>& GetLastRBinsAvail() const { assert(initialized == true); return last_rbins_avail; }
GetLastReactionCount()469   const tArray<int>& GetLastReactionCount() const { assert(initialized == true); return last_reaction_count; }
GetLastReactionAddReward()470   const tArray<double>& GetLastReactionAddReward() const { assert(initialized == true); return last_reaction_add_reward; }
GetLastInstCount()471   const tArray<int>& GetLastInstCount() const { assert(initialized == true); return last_inst_count; }
GetLastSenseCount()472   const tArray<int>& GetLastSenseCount() const { assert(initialized == true); return last_sense_count; }
GetLastFitness()473   double GetLastFitness() const { assert(initialized == true); return last_fitness; }
GetPermanentGermlinePropensity()474   double GetPermanentGermlinePropensity() const { assert(initialized == true); return permanent_germline_propensity; }
GetLastCollectSpecCounts()475   const tArray<int>& GetLastCollectSpecCounts() const { assert(initialized == true); return last_collect_spec_counts; }
GetLastCollectSpecCount(int spec_id)476   int GetLastCollectSpecCount(int spec_id) const { assert(initialized == true); return last_collect_spec_counts[spec_id]; }
477 
GetNumDivides()478   int GetNumDivides() const { assert(initialized == true); return num_divides;}
GetNumDivideFailed()479   int GetNumDivideFailed() const { assert(initialized == true); return num_divides_failed;}
480 
GetGeneration()481   int GetGeneration() const { return generation; }
GetCPUCyclesUsed()482   int GetCPUCyclesUsed() const { assert(initialized == true); return cpu_cycles_used; }
GetTimeUsed()483   int GetTimeUsed()   const { assert(initialized == true); return time_used; }
GetNumExecs()484   int GetNumExecs() const { assert(initialized == true); return num_execs; }
GetTrialTimeUsed()485   int GetTrialTimeUsed()   const { assert(initialized == true); return trial_time_used; }
GetAge()486   int GetAge()        const { assert(initialized == true); return age; }
GetFault()487   const cString& GetFault() const { assert(initialized == true); return fault_desc; }
GetNeutralMetric()488   double GetNeutralMetric() const { assert(initialized == true); return neutral_metric; }
GetLifeFitness()489   double GetLifeFitness() const { assert(initialized == true); return life_fitness; }
GetNumThreshGbDonations()490   int  GetNumThreshGbDonations() const { assert(initialized == true); return num_thresh_gb_donations; }
GetNumThreshGbDonationsLast()491   int  GetNumThreshGbDonationsLast() const { assert(initialized == true); return num_thresh_gb_donations_last; }
GetNumQuantaThreshGbDonations()492   int  GetNumQuantaThreshGbDonations() const { assert(initialized == true); return num_quanta_thresh_gb_donations; }
GetNumQuantaThreshGbDonationsLast()493   int  GetNumQuantaThreshGbDonationsLast() const { assert(initialized == true); return num_quanta_thresh_gb_donations_last; }
GetNumShadedGbDonations()494   int  GetNumShadedGbDonations() const { assert(initialized == true); return num_shaded_gb_donations; }
GetNumShadedGbDonationsLast()495   int  GetNumShadedGbDonationsLast() const { assert(initialized == true); return num_shaded_gb_donations_last; }
GetNumDonationsLocus()496   int GetNumDonationsLocus() const { assert(initialized == true); return num_donations_locus; }
GetNumDonationsLocusLast()497   int GetNumDonationsLocusLast() const { assert(initialized == true); return num_donations_locus_last; }
498 
IsInjected()499   bool IsInjected() const { assert(initialized == true); return is_injected; }
IsDonorCur()500   bool IsDonorCur() const { assert(initialized == true); return is_donor_cur; }
IsDonorLast()501   bool IsDonorLast() const { assert(initialized == true); return is_donor_last; }
IsDonorRand()502   bool IsDonorRand() const { assert(initialized == true); return is_donor_rand; }
IsDonorRandLast()503   bool IsDonorRandLast() const { assert(initialized == true); return is_donor_rand_last; }
IsDonorKin()504   bool IsDonorKin() const { assert(initialized == true); return is_donor_kin; }
IsDonorKinLast()505   bool IsDonorKinLast() const { assert(initialized == true); return is_donor_kin_last; }
IsDonorEdit()506   bool IsDonorEdit() const { assert(initialized == true); return is_donor_edit; }
IsDonorEditLast()507   bool IsDonorEditLast() const { assert(initialized == true); return is_donor_edit_last; }
IsDonorGbg()508   bool IsDonorGbg() const { assert(initialized == true); return is_donor_gbg; }
IsDonorGbgLast()509   bool IsDonorGbgLast() const { assert(initialized == true); return is_donor_gbg_last; }
IsDonorTrueGb()510   bool IsDonorTrueGb() const { assert(initialized == true); return is_donor_truegb; }
IsDonorTrueGbLast()511   bool IsDonorTrueGbLast() const { assert(initialized == true); return is_donor_truegb_last; }
IsDonorThreshGb()512   bool IsDonorThreshGb() const { assert(initialized == true); return is_donor_threshgb; }
IsDonorThreshGbLast()513   bool IsDonorThreshGbLast() const { assert(initialized == true); return is_donor_threshgb_last; }
IsDonorQuantaThreshGb()514   bool IsDonorQuantaThreshGb() const { assert(initialized == true); return is_donor_quanta_threshgb; }
IsDonorQuantaThreshGbLast()515   bool IsDonorQuantaThreshGbLast() const { assert(initialized == true); return is_donor_quanta_threshgb_last; }
IsDonorShadedGb()516   bool IsDonorShadedGb() const { assert(initialized == true); return is_donor_shadedgb; }
IsDonorShadedGbLast()517   bool IsDonorShadedGbLast() const { assert(initialized == true); return is_donor_shadedgb_last; }
IsDonorPosition(int pos)518   bool IsDonorPosition(int pos) const {assert(initialized == true); return is_donor_locus.GetSize() > pos ? is_donor_locus[pos] : 0; }
IsDonorPositionLast(int pos)519   bool IsDonorPositionLast(int pos) const {assert(initialized == true); return is_donor_locus_last.GetSize() > pos ? is_donor_locus_last[pos] : 0; }
520 
IsEnergyRequestor()521   bool IsEnergyRequestor() const { assert(initialized == true); return is_energy_requestor; }
IsEnergyDonor()522   bool IsEnergyDonor() const { assert(initialized == true); return is_energy_donor; }
IsEnergyReceiver()523   bool IsEnergyReceiver() const { assert(initialized == true); return is_energy_receiver; }
HasUsedEnergyDonation()524   bool HasUsedEnergyDonation() const { assert(initialized == true); return has_used_donated_energy; }
HasOpenEnergyRequest()525   bool HasOpenEnergyRequest() const { assert(initialized == true); return has_open_energy_request; }
IsReceiver()526   bool IsReceiver() const { assert(initialized == true); return is_receiver; }
IsReceiverLast()527   bool IsReceiverLast() const { assert(initialized == true); return is_receiver_last; }
IsReceiverRand()528   bool IsReceiverRand() const { assert(initialized == true); return is_receiver_rand; }
IsReceiverKin()529   bool IsReceiverKin() const { assert(initialized == true); return is_receiver_kin; }
IsReceiverKinLast()530   bool IsReceiverKinLast() const { assert(initialized == true); return is_receiver_kin_last; }
IsReceiverEdit()531   bool IsReceiverEdit() const { assert(initialized == true); return is_receiver_edit; }
IsReceiverEditLast()532   bool IsReceiverEditLast() const { assert(initialized == true); return is_receiver_edit_last; }
IsReceiverGbg()533   bool IsReceiverGbg() const { assert(initialized == true); return is_receiver_gbg; }
IsReceiverTrueGb()534   bool IsReceiverTrueGb() const { assert(initialized == true); return is_receiver_truegb; }
IsReceiverTrueGbLast()535   bool IsReceiverTrueGbLast() const { assert(initialized == true); return is_receiver_truegb_last; }
IsReceiverThreshGb()536   bool IsReceiverThreshGb() const { assert(initialized == true); return is_receiver_threshgb; }
IsReceiverThreshGbLast()537   bool IsReceiverThreshGbLast() const { assert(initialized == true); return is_receiver_threshgb_last; }
IsReceiverQuantaThreshGb()538   bool IsReceiverQuantaThreshGb() const { assert(initialized == true); return is_receiver_quanta_threshgb; }
IsReceiverQuantaThreshGbLast()539   bool IsReceiverQuantaThreshGbLast() const { assert(initialized == true); return is_receiver_quanta_threshgb_last; }
IsReceiverShadedGb()540   bool IsReceiverShadedGb() const { assert(initialized == true); return is_receiver_shadedgb; }
IsReceiverShadedGbLast()541   bool IsReceiverShadedGbLast() const { assert(initialized == true); return is_receiver_shadedgb_last; }
IsReceiverGBSameLocus()542   bool IsReceiverGBSameLocus() const { assert(initialized == true); return is_receiver_gb_same_locus; }
IsReceiverGBSameLocusLast()543   bool IsReceiverGBSameLocusLast() const { assert(initialized == true); return is_receiver_gb_same_locus_last; }
IsModifier()544   bool IsModifier() const { assert(initialized == true); return is_modifier; }
IsModified()545   bool IsModified() const { assert(initialized == true); return is_modified; }
IsFertile()546   bool IsFertile() const  { assert(initialized == true); return is_fertile; }
IsMutated()547   bool IsMutated() const  { assert(initialized == true); return is_mutated; }
IsMultiThread()548   bool IsMultiThread() const { assert(initialized == true); return is_multi_thread; }
ParentTrue()549   bool ParentTrue() const { assert(initialized == true); return parent_true; }
ParentSex()550   bool ParentSex() const  { assert(initialized == true); return parent_sex; }
ParentCrossNum()551   int  ParentCrossNum() const  { assert(initialized == true); return parent_cross_num; }
BornParentGroup()552   bool BornParentGroup() const { assert(initialized == true); return born_parent_group; }
553 
CopyTrue()554   bool CopyTrue() const   { assert(initialized == true); return copy_true; }
DivideSex()555   bool DivideSex() const  { assert(initialized == true); return divide_sex; }
MateSelectID()556   int MateSelectID() const { assert(initialized == true); return mate_select_id; }
CrossNum()557   int CrossNum() const  { assert(initialized == true); return cross_num; }
ChildFertile()558   bool ChildFertile() const { assert(initialized == true); return child_fertile;}
GetChildCopiedSize()559   int GetChildCopiedSize() const { assert(initialized == true); return child_copied_size; }
560 
561 
562 
563   ////////////////////  Accessors -- Modifying  ///////////////////
SetMerit(const cMerit & in_merit)564   void SetMerit(const cMerit& in_merit) { merit = in_merit; }
SetFitness(const double in_fit)565   void SetFitness(const double in_fit) { fitness = in_fit; }
566   void ReduceEnergy(const double cost);
567   void SetEnergy(const double value);
SetGestationTime(int in_time)568   void SetGestationTime(int in_time) { gestation_time = in_time; }
SetTimeUsed(int in_time)569   void SetTimeUsed(int in_time) { time_used = in_time; }
SetTrialTimeUsed(int in_time)570   void SetTrialTimeUsed(int in_time) { trial_time_used = in_time; }
SetGeneration(int in_generation)571   void SetGeneration(int in_generation) { generation = in_generation; }
SetPermanentGermlinePropensity(double _in)572   void SetPermanentGermlinePropensity(double _in) { permanent_germline_propensity = _in; }
SetFault(const cString & in_fault)573   void SetFault(const cString& in_fault) { fault_desc = in_fault; }
SetNeutralMetric(double _in)574   void SetNeutralMetric(double _in){ neutral_metric = _in; }
SetLifeFitness(double _in)575   void SetLifeFitness(double _in){ life_fitness = _in; }
SetLinesExecuted(int _exe_size)576   void SetLinesExecuted(int _exe_size) { executed_size = _exe_size; }
SetLinesCopied(int _copied_size)577   void SetLinesCopied(int _copied_size) { child_copied_size = _copied_size; }
SetDivType(double _div_type)578   void SetDivType(double _div_type) { div_type = _div_type; }
SetDivideSex(bool _divide_sex)579   void SetDivideSex(bool _divide_sex) { divide_sex = _divide_sex; }
SetMateSelectID(int _select_id)580   void SetMateSelectID(int _select_id) { mate_select_id = _select_id; }
SetCrossNum(int _cross_num)581   void SetCrossNum(int _cross_num) { cross_num = _cross_num; }
SetToDie()582   void SetToDie() { to_die = true; }
SetToDelete()583   void SetToDelete() { to_delete = true; }
SetTestCPUInstCount(const tArray<int> & in_counts)584   void SetTestCPUInstCount(const tArray<int>& in_counts) { testCPU_inst_count = in_counts; }
IncreaseEnergyDonated(double amount)585   void IncreaseEnergyDonated(double amount) { assert(amount >=0); total_energy_donated += amount; }
IncreaseEnergyReceived(double amount)586   void IncreaseEnergyReceived(double amount) { assert(amount >=0); total_energy_received += amount; }
IncreaseEnergyApplied(double amount)587   void IncreaseEnergyApplied(double amount) { assert(amount >=0); total_energy_applied += amount; }
IncreaseNumEnergyRequests()588   void IncreaseNumEnergyRequests() { num_energy_requests++; }
IncreaseNumEnergyDonations()589   void IncreaseNumEnergyDonations() { num_energy_donations++; }
IncreaseNumEnergyApplications()590   void IncreaseNumEnergyApplications() { num_energy_applications++; }
IncreaseNumEnergyReceptions()591   void IncreaseNumEnergyReceptions() { num_energy_receptions++; }
GetAmountEnergyDonated()592   double GetAmountEnergyDonated() { return total_energy_donated; }
GetAmountEnergyReceived()593   double GetAmountEnergyReceived() { return total_energy_received; }
GetAmountEnergyApplied()594   double GetAmountEnergyApplied() { return total_energy_applied; }
GetNumEnergyDonations()595   int GetNumEnergyDonations() { return num_energy_donations; }
GetNumEnergyReceptions()596   int GetNumEnergyReceptions() { return num_energy_receptions; }
GetNumEnergyApplications()597   int GetNumEnergyApplications() { return num_energy_applications; }
598 
SetReactionCount(int index,int val)599   void SetReactionCount(int index, int val) { cur_reaction_count[index] = val; }
SetStolenReactionCount(int index,int val)600   void SetStolenReactionCount(int index, int val) { cur_stolen_reaction_count[index] = val; }
601 
SetCurRBinsAvail(const tArray<double> & in_avail)602   void SetCurRBinsAvail(const tArray<double>& in_avail) { cur_rbins_avail = in_avail; }
SetCurRbinsTotal(const tArray<double> & in_total)603   void SetCurRbinsTotal(const tArray<double>& in_total) { cur_rbins_total = in_total; }
SetCurRBinAvail(int index,double val)604   void SetCurRBinAvail(int index, double val) { cur_rbins_avail[index] = val; }
SetCurRBinTotal(int index,double val)605   void SetCurRBinTotal(int index, double val) { cur_rbins_total[index] = val; }
AddToCurRBinAvail(int index,double val)606   void AddToCurRBinAvail(int index, double val) { cur_rbins_avail[index] += val; }
AddToCurRBinTotal(int index,double val)607   void AddToCurRBinTotal(int index, double val) { cur_rbins_total[index] += val; }
SetCurCollectSpecCount(int spec_id,int val)608   void SetCurCollectSpecCount(int spec_id, int val) { cur_collect_spec_counts[spec_id] = val; }
609 
SetMatingType(int _mating_type)610   void SetMatingType(int _mating_type) { mating_type = _mating_type; } //@CHC
SetMatePreference(int _mate_preference)611   void SetMatePreference(int _mate_preference) { mate_preference = _mate_preference; } //@CHC
612 
SetIsMultiThread()613   void SetIsMultiThread() { is_multi_thread = true; }
SetIsDonorCur()614   void SetIsDonorCur() { is_donor_cur = true; }
SetIsDonorRand()615   void SetIsDonorRand() { SetIsDonorCur(); is_donor_rand = true; }
SetIsDonorKin()616   void SetIsDonorKin() { SetIsDonorCur(); is_donor_kin = true; }
SetIsDonorNull()617   void SetIsDonorNull() { SetIsDonorCur(); is_donor_null = true; }
SetIsDonorEdit()618   void SetIsDonorEdit() { SetIsDonorCur(); is_donor_edit = true; }
SetIsDonorGbg()619   void SetIsDonorGbg() { SetIsDonorCur(); is_donor_gbg = true; }
SetIsDonorTrueGb()620   void SetIsDonorTrueGb() { SetIsDonorCur(); is_donor_truegb = true; }
SetIsDonorThreshGb()621   void SetIsDonorThreshGb() { SetIsDonorCur(); is_donor_threshgb = true; }
SetIsDonorQuantaThreshGb()622   void SetIsDonorQuantaThreshGb() { SetIsDonorCur(); is_donor_quanta_threshgb = true; }
SetIsDonorShadedGb()623   void SetIsDonorShadedGb() { SetIsDonorCur(); is_donor_shadedgb = true; }
SetIsDonorPosition(int pos)624   void SetIsDonorPosition(int pos) { SetIsDonorCur(); if (is_donor_locus.GetSize() <= pos) is_donor_locus.Resize(pos+1, false); is_donor_locus[pos] = true; }
SetIsReceiver()625   void SetIsReceiver() { is_receiver = true; }
SetIsReceiverRand()626   void SetIsReceiverRand() { SetIsReceiver(); is_receiver_rand = true; }
SetIsReceiverKin()627   void SetIsReceiverKin() { SetIsReceiver(); is_receiver_kin = true; }
SetIsReceiverEdit()628   void SetIsReceiverEdit() { SetIsReceiver(); is_receiver_edit = true; }
SetIsReceiverGbg()629   void SetIsReceiverGbg() { SetIsReceiver(); is_receiver_gbg = true; }
SetIsReceiverTrueGb()630   void SetIsReceiverTrueGb() { SetIsReceiver(); is_receiver_truegb = true; }
SetIsReceiverThreshGb()631   void SetIsReceiverThreshGb() { SetIsReceiver(); is_receiver_threshgb = true; }
SetIsReceiverQuantaThreshGb()632   void SetIsReceiverQuantaThreshGb() { SetIsReceiver(); is_receiver_quanta_threshgb = true; }
SetIsReceiverShadedGb()633   void SetIsReceiverShadedGb() { SetIsReceiver(); is_receiver_shadedgb = true; }
SetIsReceiverGBSameLocus()634   void SetIsReceiverGBSameLocus() { SetIsReceiver(); is_receiver_gb_same_locus = true; }
SetIsEnergyRequestor()635   void SetIsEnergyRequestor() { is_energy_requestor = true; }
SetIsEnergyDonor()636   void SetIsEnergyDonor() { is_energy_donor = true; }
SetIsEnergyReceiver()637   void SetIsEnergyReceiver() { is_energy_receiver = true; }
SetBornParentGroup()638   bool& SetBornParentGroup() { return born_parent_group; }
SetHasUsedDonatedEnergy()639   void SetHasUsedDonatedEnergy() {has_used_donated_energy = true; }
SetHasOpenEnergyRequest()640   void SetHasOpenEnergyRequest() { has_open_energy_request = true; }
ClearHasOpenEnergyRequest()641   void ClearHasOpenEnergyRequest() { has_open_energy_request = false; }
ClearIsMultiThread()642   void ClearIsMultiThread() { is_multi_thread = false; }
643 
SetCurBonus(double _bonus)644   void SetCurBonus(double _bonus) { cur_bonus = _bonus; }
SetCurBonusInstCount(int _num_bonus_inst)645   void SetCurBonusInstCount(int _num_bonus_inst) {bonus_instruction_count = _num_bonus_inst;}
646 
IncCurInstCount(int _inst_num)647   void IncCurInstCount(int _inst_num)  { assert(initialized == true); cur_inst_count[_inst_num]++; }
DecCurInstCount(int _inst_num)648   void DecCurInstCount(int _inst_num)  { assert(initialized == true); cur_inst_count[_inst_num]--; }
649 
IncNumThreshGbDonations()650   void IncNumThreshGbDonations() { assert(initialized == true); num_thresh_gb_donations++; }
IncNumQuantaThreshGbDonations()651   void IncNumQuantaThreshGbDonations() { assert(initialized == true); num_quanta_thresh_gb_donations++; }
IncNumShadedGbDonations()652   void IncNumShadedGbDonations() { assert(initialized == true); num_shaded_gb_donations++; }
IncNumGreenBeardSameLocus()653   void IncNumGreenBeardSameLocus() { assert(initialized == true); num_donations_locus++; }
IncAge()654   void IncAge()      { assert(initialized == true); age++; }
IncCPUCyclesUsed()655   void IncCPUCyclesUsed() { assert(initialized == true); cpu_cycles_used++; trial_cpu_cycles_used++; }
DecCPUCyclesUsed()656   void DecCPUCyclesUsed() { assert(initialized == true); cpu_cycles_used--; trial_cpu_cycles_used--; }
657   void IncTimeUsed(int i=1) { assert(initialized == true); time_used+=i; trial_time_used+=i; }
IncNumExecs()658   void IncNumExecs() { assert(initialized == true); num_execs++; }
IncErrors()659   void IncErrors()   { assert(initialized == true); cur_num_errors++; }
IncDonates()660   void IncDonates()   { assert(initialized == true); cur_num_donates++; }
IncSenseCount(const int i)661   void IncSenseCount(const int i) { /*assert(initialized == true); cur_sense_count[i]++;*/ }
662 
SetCurMatingDisplayA(int _cur_mating_display_a)663   void SetCurMatingDisplayA(int _cur_mating_display_a) { cur_mating_display_a = _cur_mating_display_a; } //@CHC
SetCurMatingDisplayB(int _cur_mating_display_b)664   void SetCurMatingDisplayB(int _cur_mating_display_b) { cur_mating_display_b = _cur_mating_display_b; } //@CHC
SetLastMatingDisplayA(int _last_mating_display_a)665   void SetLastMatingDisplayA(int _last_mating_display_a) { last_mating_display_a = _last_mating_display_a; } //@CHC
SetLastMatingDisplayB(int _last_mating_display_b)666   void SetLastMatingDisplayB(int _last_mating_display_b) { last_mating_display_b = _last_mating_display_b; } //@CHC
667 
IsInjected()668   bool& IsInjected() { assert(initialized == true); return is_injected; }
IsModifier()669   bool& IsModifier() { assert(initialized == true); return is_modifier; }
IsModified()670   bool& IsModified() { assert(initialized == true); return is_modified; }
IsFertile()671   bool& IsFertile()  { assert(initialized == true); return is_fertile; }
IsMutated()672   bool& IsMutated()  { assert(initialized == true); return is_mutated; }
ParentTrue()673   bool& ParentTrue() { assert(initialized == true); return parent_true; }
ParentSex()674   bool& ParentSex()  { assert(initialized == true); return parent_sex; }
ParentCrossNum()675   int& ParentCrossNum()  { assert(initialized == true); return parent_cross_num; }
CopyTrue()676   bool& CopyTrue()   { assert(initialized == true); return copy_true; }
DivideSex()677   bool& DivideSex()  { assert(initialized == true); return divide_sex; }
MateSelectID()678   int& MateSelectID() { assert(initialized == true); return mate_select_id; }
CrossNum()679   int& CrossNum()     { assert(initialized == true); return cross_num; }
ChildFertile()680   bool& ChildFertile() { assert(initialized == true); return child_fertile; }
IsMultiThread()681   bool& IsMultiThread() { assert(initialized == true); return is_multi_thread; }
682 
683   void DoubleEnergyUsage();
684   void HalveEnergyUsage();
685   void DefaultEnergyUsage();
686 
687   // --- Support for Division of Labor --- //
GetLastTaskID()688   int GetLastTaskID() const { return last_task_id; }
GetNumNewUniqueReactions()689   int  GetNumNewUniqueReactions() const {assert(initialized == true);  return num_new_unique_reactions; }
ResetNumNewUniqueReactions()690   void  ResetNumNewUniqueReactions()  {num_new_unique_reactions =0; }
691   double GetResourcesConsumed();
692   tArray<int> GetCumulativeReactionCount();
693 
694 
695   // @LZ - Parasite Etc. Helpers
696   void DivideFailed();
UpdateParasiteTasks()697   void UpdateParasiteTasks() { last_para_tasks = cur_para_tasks; cur_para_tasks.SetAll(0); return; }
698 
699 
700   void RefreshEnergy();
701   void ApplyToEnergyStore();
702   void EnergyTestament(const double value); //! external energy given to organism
703   void ApplyDonatedEnergy();
704   void ReceiveDonatedEnergy(const double value);
705   double ExtractParentEnergy();
706 
707   // Compare two phenotypes and determine an ordering (arbitrary, but consistant among phenotypes).
708   static int Compare(const cPhenotype* lhs, const cPhenotype* rhs);
709 
710   // This pseudo-function is used to help sort phenotypes
711   struct PhenotypeCompare {
712     bool operator()(const cPhenotype* lhs, const cPhenotype* rhs) const;
713   };
714 };
715 
716 
SetInstSetSize(int inst_set_size)717 inline void cPhenotype::SetInstSetSize(int inst_set_size)
718 {
719   cur_inst_count.Resize(inst_set_size, 0);
720   last_inst_count.Resize(inst_set_size, 0);
721 }
722 
SetBirthCellID(int birth_cell)723 inline void cPhenotype::SetBirthCellID(int birth_cell) { birth_cell_id = birth_cell; }
SetAVBirthCellID(int av_birth_cell)724 inline void cPhenotype::SetAVBirthCellID(int av_birth_cell) { av_birth_cell_id = av_birth_cell; }
SetBirthGroupID(int group_id)725 inline void cPhenotype::SetBirthGroupID(int group_id) { birth_group_id = group_id; }
SetBirthForagerType(int forager_type)726 inline void cPhenotype::SetBirthForagerType(int forager_type) { birth_forager_type = forager_type; }
727 
728 #endif
729