77#include < sstream> // stringstream
88#include < string>
99#include " ../Organism.h"
10+ #include " DefaultOrganism.h"
1011#include " SymWorld.h"
1112
1213
13- class Host : public BaseHost {
14+ class Host : public BaseHost , public DefaultOrganism {
1415protected:
15- /* *
16- *
17- * Purpose: Represents the interaction value between the host and symbiont.
18- * A negative interaction value represent antagonism, while a positive
19- * one represents mutualism. Zero is a neutral value.
20- *
21- */
22- double interaction_val = 0 ;
23-
2416 /* *
2517 *
2618 * Purpose: Represents the set of in-progress "reproductive" symbionts belonging to a host. These are symbionts that aren't yet active.
@@ -45,16 +37,9 @@ class Host: public BaseHost {
4537 Host (emp::Ptr<emp::Random> _random, emp::Ptr<SymWorld> _world, emp::Ptr<SymConfigBase> _config,
4638 double _intval =0.0 , emp::vector<emp::Ptr<BaseSymbiont>> _syms = {},
4739 emp::vector<emp::Ptr<BaseSymbiont>> _repro_syms = {},
48- double _points = 0.0 ) : interaction_val (_intval), repro_syms(_repro_syms), Organism(_config, _world, _random, _points) {
40+ double _points = 0.0 ) : DefaultOrganism (_intval), repro_syms(_repro_syms), Organism(_config, _world, _random, _points) {
4941 // Base class members can't be initialized in the initializer list; later should add BaseHost ctor or remove _syms
5042 syms = _syms;
51-
52- if (_intval == -2 ) {
53- interaction_val = random->GetDouble (-1 , 1 );
54- }
55- if (interaction_val > 1 || interaction_val < -1 ) {
56- throw " Invalid interaction value. Must be between -1 and 1" ; // Exception for invalid interaction value
57- };
5843 }
5944
6045 /* *
@@ -146,15 +131,6 @@ class Host: public BaseHost {
146131 return " Host" ;
147132 }
148133
149- /* *
150- * Input: None
151- *
152- * Output: The double representing host's interaction value
153- *
154- * Purpose: To get the double representing host's interaction value
155- */
156- double GetIntVal () const { return interaction_val;}
157-
158134
159135/* *
160136 * Input: None
@@ -175,35 +151,6 @@ class Host: public BaseHost {
175151 */
176152 double GetResInProcess () { return res_in_process;}
177153
178- int GetPhyloBin () const override {
179- size_t num_phylo_bins = my_config->NUM_PHYLO_BINS ();
180- // classify orgs into bins base on interaction values,
181- // inclusive of lower bound, exclusive of upper
182- float size_of_bin = 2.0 / num_phylo_bins;
183- double int_val = GetIntVal ();
184- float prog = (int_val + 1 );
185- prog = (prog/size_of_bin) + (0.0000000000001 );
186- size_t bin = (size_t ) prog;
187- if (bin >= num_phylo_bins) bin = num_phylo_bins - 1 ;
188- return bin;
189- }
190-
191- /* *
192- * Input: A double representing the host's new interaction value.
193- *
194- * Output: None
195- *
196- * Purpose: To set a host's interaction value.
197- */
198- void SetIntVal (double _in) {
199- if ( _in > 1 || _in < -1 ) {
200- throw " Invalid interaction value. Must be between -1 and 1" ; // Exception for invalid interaction value
201- }
202- else {
203- interaction_val = _in;
204- }
205- }
206-
207154
208155 /* *
209156 * Input: A vector of pointers to organisms that will become a host's symbionts.
@@ -304,27 +251,6 @@ class Host: public BaseHost {
304251 return host_baby;
305252 }
306253
307- /* *
308- * Input: None
309- *
310- * Output: None
311- *
312- * Purpose: To mutate a host's interaction value. This is called on newly generated
313- * hosts to allow for evolution to occur.
314- */
315- void Mutate () override {
316- double mutation_size = my_config->HOST_MUTATION_SIZE ();
317- if (mutation_size == -1 ) mutation_size = my_config->MUTATION_SIZE ();
318- double mutation_rate = my_config->HOST_MUTATION_RATE ();
319- if (mutation_rate == -1 ) mutation_rate = my_config->MUTATION_RATE ();
320-
321- if (random->GetDouble (0.0 , 1.0 ) <= mutation_rate){
322- interaction_val += random->GetRandNormal (0.0 , mutation_size);
323- if (interaction_val < -1 ) interaction_val = -1 ;
324- else if (interaction_val > 1 ) interaction_val = 1 ;
325- }
326- }
327-
328254
329255 /* *
330256 * Input: The double representing the number of resources to be distributed to the host and its symbionts and the position of the host in the world.
0 commit comments