-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathSymbiont.h
More file actions
859 lines (748 loc) · 24 KB
/
Copy pathSymbiont.h
File metadata and controls
859 lines (748 loc) · 24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
#ifndef SYMBIONT_H
#define SYMBIONT_H
#include "../../Empirical/include/emp/math/Random.hpp"
#include "../../Empirical/include/emp/tools/string_utils.hpp"
#include "SymWorld.h"
#include <set>
#include <iomanip> // setprecision
#include <sstream> // stringstream
#include <optional>
class Symbiont: public Organism {
protected:
/**
*
* Purpose: Represents the interaction value between the host and symbiont.
* A negative interaction value represent antagonism, while a positive
* one represents mutualism. Zero is a neutral value.
*
*/
double interaction_val = 0;
/**
*
* Purpose: Represents the resource points possessed by a symbiont.
* This is what host's must collect to reproduce.
*
*/
double points = 0;
/**
*
* Purpose: Represents if a symbiont is alive.
* This is set to true when a symbiont is killed.
*
*/
bool dead = false;
/**
*
* Purpose: Represents the chance (between 0 and 1) that
* a free-living sym will infect a parallel host on process
*
*/
double infection_chance = 0.0;
/**
*
* Purpose: Represents the number of updates the symbiont
* has lived through; at birth is set to 0.
*
*/
int age = 0;
/**
*
* Purpose: Tracks the number of reproductive events in this symbiont's lineage.
*
*/
size_t reproductions = 0;
/**
*
* Purpose: Tracks the number of tag flips towards partner in this symbiont's lineage.
*
*/
size_t towards_partner_count = 0;
/**
*
* Purpose: Tracks the number of tag flips away from partner in this symbiont's lineage.
*
*/
size_t from_partner_count = 0;
/**
*
* Purpose: Represents an instance of random.
*
*/
emp::Ptr<emp::Random> random = NULL;
/**
*
* Purpose: Represents the world that the hosts are living in.
*
*/
emp::Ptr<SymWorld> my_world = NULL;
/**
*
* Purpose: Represents the symbiont's host.
*
*/
emp::Ptr<Organism> my_host = NULL;
/**
*
* Purpose: Represents the configuration settings for a particular run.
*
*/
emp::Ptr<SymConfigBase> my_config = NULL;
/**
*
* Purpose: Tracks the taxon of this organism.
*
*/
emp::Ptr<taxon_t::base_taxon_t> my_taxon = NULL;
/**
*
* Purpose: Represents the tag for this organism
*
*/
emp::BitSet<TAG_LENGTH> tag;
/**
*
* Purpose: To track location in the world
* id/Index is position in the host's symbiont vector if the symbiont is hosted, and 0 if the symbiont is free-living
* If the symbiont is hosted, the population id is the host's location in the world. If the symbiont is free-living, it is the location in the sym pop
*/
emp::WorldPosition location;
public:
/**
* The constructor for symbiont
*/
Symbiont(emp::Ptr<emp::Random> _random, emp::Ptr<SymWorld> _world, emp::Ptr<SymConfigBase> _config, double _intval=0.0, double _points = 0.0) : interaction_val(_intval), points(_points), random(_random), my_world(_world), my_config(_config) {
infection_chance = my_config->SYM_INFECTION_CHANCE();
if (infection_chance == -2) infection_chance = random->GetDouble(0,1); //randomized starting infection chance
if (infection_chance > 1 || infection_chance < 0) throw "Invalid infection chance. Must be between 0 and 1"; //exception for invalid infection chance
if (_intval == -2) {
interaction_val = random->GetDouble(-1, 1);
}
if (interaction_val > 1 || interaction_val < -1) {
throw "Invalid interaction value. Must be between -1 and 1"; // Exception for invalid interaction value
};
}
/**
* Input: None
*
* Output: None
*
* Purpose: To force a copy constructor to be generated by the compiler.
*/
Symbiont(const Symbiont &) = default;
/**
* Input: None
*
* Output: None
*
* Purpose: To force a move constructor to be generated by the compiler
*/
Symbiont(Symbiont &&) = default;
/**
* Input: None
*
* Output: None
*
* Purpose: To tell the compiler to use its default generated variants of the constructor
*/
Symbiont() = default;
/**
* Input: None
*
* Output: None
*
* Purpose: To force a copy assignment operator to be generated by the compiler.
*/
Symbiont & operator=(const Symbiont &) = default;
/**
* Input: None
*
* Output: None
*
* Purpose: To force a move assignment operator to be generated by the compiler.
*/
Symbiont & operator=(Symbiont &&) = default;
/**
* Input: None
*
* Output: None
*
* Purpose: To destruct the symbiont and remove the symbiont from the systematic.
*/
~Symbiont() {
if(my_config->PHYLOGENY() == 1) {
my_world->GetSymSys()->RemoveOrg(my_taxon.Cast<taxon_t::sym_taxon_t>());
if (my_config->STORE_EXTINCT() && my_taxon->GetOriginationTime() == my_taxon->GetDestructionTime() && my_taxon->GetTotalOffspring() == 0) {
my_world->GetSymSys()->outside_taxa.erase(my_taxon.Cast<taxon_t::sym_taxon_t>());
my_taxon.Delete();
}
}
}
/**
* Input: None
*
* Output: Name of class as string, Symbiont
*
* Purpose: To know which subclass the object is
*/
std::string const GetName() const {
return "Symbiont";
}
/**
* Input: Set the reproduction counter
*
* Output: None
*
* Purpose: To set the count of reproductions in this lineage.
*/
void SetReproCount(size_t _in) { reproductions = _in; }
/**
* Input: None.
*
* Output: The reproduction count
*
* Purpose: To get the count of reproductions in this lineage.
*/
size_t GetReproCount() const { return reproductions; }
/**
* Input: Set the flips towards a partner counter
*
* Output: None
*
* Purpose: To set the count of flips towards a partner in this lineage.
*/
void SetTowardsPartnerCount(size_t _in) { towards_partner_count = _in; }
/**
* Input: None.
*
* Output: The flips towards a partner count
*
* Purpose: To get the count of flips towards a partner in this lineage.
*/
size_t GetTowardsPartnerCount() const { return towards_partner_count; }
/**
* Input: Set the flips from a partner counter
*
* Output: None
*
* Purpose: To set the count of flips from a partner in this lineage.
*/
void SetFromPartnerCount(size_t _in) { from_partner_count = _in; }
/**
* Input: None.
*
* Output: The flips from a partner count
*
* Purpose: To get the count of flips from a partner in this lineage.
*/
size_t GetFromPartnerCount() const { return from_partner_count; }
/**
* Input: None
*
* Output: The double representing the symbiont's interaction value
*
* Purpose: To get a symbiont's interaction value.
*/
double GetIntVal() const {return interaction_val;}
/**
* Input: None
*
* Output: The double representing the symbiont's points
*
* Purpose: To get a symbiont's points.
*/
double GetPoints() const { return points; }
/**
* Input: None
*
* Output: The world position of the organism
*
* Purpose: To get the world position of the organism
*/
emp::WorldPosition GetLocation() const { return location; }
/**
* Input: None
*
* Output: The bool representing if a symbiont is a phage
*
* Purpose: To determine if a symbiont is a phage
*/
bool IsPhage() const { return false; }
/**
* Input: None
*
* Output: The bool representing if a symbiont is a host
*
* Purpose: To determine if a symbiont is a host
*/
bool IsHost() const { return false; }
/**
* Input: None
*
* Output: The chance of a symbiont infecting a parallel
* host during process
*
* Purpose: To determine a symbiont's infection chance
*/
double GetInfectionChance() const { return infection_chance; }
/**
* Input: None
*
* Output: The pointer to a symbiont's host
*
* Purpose: To retrieve a symbiont's host
*/
emp::Ptr<Organism> GetHost() { return my_host; }
/**
* Input: None
*
* Output: The pointer to the symbiont's taxon
*
* Purpose: To retrieve the symbiont's taxon
*/
emp::Ptr<taxon_t::base_taxon_t> GetTaxon() { return my_taxon; }
/**
* Input: A pointer to the taxon that this organism should belong to.
*
* Output: None
*
* Purpose: To set the symbiont's taxon
*/
void SetTaxon(emp::Ptr<taxon_t::base_taxon_t> _in) { my_taxon = _in; }
/**
* Input: The new tag
*
* Output: None
*
* Purpose: To set a symbiont's tag.
*/
void SetTag(const emp::BitSet<TAG_LENGTH>& _in) { tag.Import(_in); }
/**
* Input: None
*
* Output: The symbiont's tag.
*
* Purpose: To get a symbiont's tag.
*/
emp::BitSet<TAG_LENGTH>& GetTag() { return tag; }
/**
* Input: None
*
* Output: const reference to the symbiont's tag.
*
* Purpose: To get a symbiont's tag.
*/
const emp::BitSet<TAG_LENGTH>& GetTag() const { return tag; }
/**
* Input: None
*
* Output: None
*
* Purpose: To set a symbiont to dead
*/
void SetDead() {
dead = true;
}
/**
* Input: None
*
* Output: The bool representing if a symbiont is dead
*
* Purpose: To determine if a symbiont is dead
*/
bool GetDead() const { return dead; }
/**
* Input: The double representing the new interaction value of a symbiont
*
* Output: None
*
* Purpose: To set a symbiont's interaction value
*/
void SetIntVal(double _in) {
emp_assert(_in <= 1 && _in >= -1, "Invalid interaction value. Must be between -1 and 1");
interaction_val = _in;
}
/**
* Input: The double representing the points to be set as a symbiont's points
*
* Output: None
*
* Purpose: To set a symbiont's points
*/
void SetPoints(double _in) { points = _in; }
/**
* Input: The double representing the points to be added to a symbiont's points
*
* Output: None
*
* Purpose: To increment a symbiont's points
*/
void AddPoints(double _in) { points += _in; }
/**
* Input: A new world position
*
* Output: None
*
* Purpose: To set the organism's world position
*/
void SetLocation(emp::WorldPosition _in) { location = _in; }
/**
* Input: None
*
* Output: an int representing the current age of the Symbiont
*
* Purpose: To get the Symbiont's age.
*/
int GetAge() const { return age; }
/**
* Input: An int of what age the Symbiont should be set to
*
* Output: None
*
* Purpose: To set the Symbiont's age for testing purposes.
*/
void SetAge(int _in) {age = _in;}
/**
* Input: The pointer to an organism that will be set as the symbiont's host
*
* Output: None
*
* Purpose: To set a symbiont's host
*/
void SetHost(emp::Ptr<Organism> _in) { my_host = _in; }
/**
* Input: The double that will be the symbiont's infection chance
*
* Output: None
*
* Purpose: To set a symbiont's infection host and check that the proposed value is valid.
*/
void SetInfectionChance(double _in) {
if(_in > 1 || _in < 0) throw "Invalid infection chance. Must be between 0 and 1 (inclusive)";
else infection_chance = _in;
}
/**
* Input: None
*
* Output: None
*
* Purpose: Does nothing for now, added for backwards compatibility from phage to symbiont
*/
void UponInjection() {
//does nothing for now, added for backwards compatibility from phage to symbiont
}
/**
* Input: None
*
* Output: None
*
* Purpose: Increments age by one and kills it if too old.
*/
void GrowOlder() {
age = age + 1;
if(age > my_config->SYM_AGE_MAX() && my_config->SYM_AGE_MAX() > 0) {
SetDead();
}
}
/**
* Input: None
*
* Output: None
*
* Purpose: To mutate a symbiont's interaction value. The mutation value is chosen
* from a normal distribution centered on 0 with the mutation size as the standard
* deviation.
*/
void Mutate() {
double local_rate = my_config->MUTATION_RATE();
double local_size = my_config->MUTATION_SIZE();
if (random->GetDouble(0.0, 1.0) <= local_rate) {
interaction_val += random->GetNormal(0.0, local_size);
if(interaction_val < -1) interaction_val = -1;
else if (interaction_val > 1) interaction_val = 1;
//also modify infection chance, which is between 0 and 1
if(my_config->FREE_LIVING_SYMS()) {
infection_chance += random->GetNormal(0.0, local_size);
if (infection_chance < 0) infection_chance = 0;
else if (infection_chance > 1) infection_chance = 1;
}
}
if (my_config->TAG_MATCHING()) {
tag.FlipRandom(my_world->GetRandom(), my_config->TAG_MUTATION_SIZE());
}
}
/**
* Input: The double representing the resources to be distributed to the symbiont
* and (optionally) the host from whom it comes; if no host is provided, the
* symbiont's host variable is used.
*
* Output: The double representing the host's resources
*
* Purpose: To process and distribute resources.
*/
double ProcessResources(double host_donation, emp::Ptr<Organism> host = nullptr) {
if(host == nullptr) {
host = my_host;
}
double sym_int_val = GetIntVal();
double sym_portion = 0;
double host_portion = 0;
double synergy = my_config->SYNERGY();
if (sym_int_val<0) {
double stolen = host->StealResources(sym_int_val);
host_portion = 0;
sym_portion = stolen + host_donation;
}
else if (sym_int_val >= 0) {
host_portion = host_donation * sym_int_val;
sym_portion = host_donation - host_portion;
}
AddPoints(sym_portion);
return host_portion * synergy;
}
/**
* Input: None
*
* Output: The boolean representing if a symbiont
* will seek out to infect a host.
*
* Purpose: To determine if a symbiont wants to
* infect a host based upon its infection chance
*/
bool WantsToInfect() {
bool result = random->GetDouble(0.0, 1.0) < infection_chance;
return result;
}
/**
* Input: None
*
* Output: The boolean representing if a symbiont
* will survive crossing over into the host world.
*
* Purpose: To determine if a symbiont will survive
* crossing over into the host world based on infection risk.
*/
bool InfectionFails() {
//note: this can be returned true, and an infecting sym can then be killed by a host that is already infected.
bool sym_dies = random->GetDouble(0.0, 1.0) < my_config->SYM_INFECTION_FAILURE_RATE();
return sym_dies;
}
/**
* Input: The double representing the resources given by the world.
*
* Output: None
*
* Purpose: Free living symbionts specialized to interact with hosts
* (extreme interaction value in either direction) lose some of the resources that they get from the world.
*/
void LoseResources(double resources) {
double int_val = interaction_val;
if(my_host.IsNull()) { // this method should only be called on free-living syms, but double check!
if(int_val >= 0) {
double spent = resources * int_val;
this->AddPoints(resources - spent);
}
else {
double attack = -1.0 * int_val * resources;
this->AddPoints(resources - attack);
}
}
}
/**
* Input: A WorldPosition parameter describing the location of the symbiont;
* ID is where they are in the world, INDEX is where they are in the host's symbiont
* list (or 0 if they're free living).
*
* Output: None
*
* Purpose: To process a symbiont, meaning to check for reproduction, distribute resources,
* and to allow for movement
*/
void Process(emp::WorldPosition location) {
// if doing tag-based or individual phylogenies, track int val of this organism
if (my_config->PHYLOGENY() && my_world->GetPhylogenyTaxonType() == SymWorld::PHYLO_TAXON_TYPE::TAG) {
my_taxon->GetData().RecordIntVal(GetIntVal());
}
if (my_host.IsNull() && my_config->FREE_LIVING_SYMS()) { //free living symbiont
double resources = my_world->PullResources(my_config->FREE_SYM_RES_DISTRIBUTE()); //receive resources from the world
LoseResources(resources);
}
//Check if independent reproduction can occur and do it (either horizontal transmission or free-living reproduction, depending on config)
IndependentReproduction(location);
//Age the organism
GrowOlder();
if (my_config->SYM_WITHIN_LIFETIME_MUTATION_RATE()) {
if (random->P(my_config->SYM_WITHIN_LIFETIME_MUTATION_RATE())) {
Mutate();
}
}
//Check if the organism should move and do it
if (my_host.IsNull() && my_config->FREE_LIVING_SYMS() && !dead) {
//if the symbiont should move, and hasn't been killed
my_world->MoveFreeSym(location);
}
}
/**
* Input: None
*
* Output: The pointer to the newly created organism
*
* Purpose: To produce a new symbiont, identical to the original
*/
emp::Ptr<Organism> MakeNew() {
emp::Ptr<Symbiont> new_sym = emp::NewPtr<Symbiont>(random, my_world, my_config, GetIntVal());
new_sym->SetInfectionChance(GetInfectionChance());
if (my_config->TAG_MATCHING()) {
new_sym->SetTag(GetTag());
}
return new_sym;
}
/**
* Input: None
*
* Output: The pointer to the newly created organism
*
* Purpose: To produce a new symbiont; does not remove resources from the parent, assumes that is handled by calling function
*/
emp::Ptr<Organism> Reproduce() {
emp::Ptr<Organism> sym_baby = MakeNew();
sym_baby->Mutate();
sym_baby->SetReproCount(reproductions + 1);
if(my_config->PHYLOGENY() == 1) {
my_world->AddSymToSystematic(sym_baby, my_taxon);
//baby's taxon will be set in AddSymToSystematic
}
if (my_config->TAG_MATCHING() && my_host) {
// do not xor to get 1 where bits are matching
emp::BitSet<TAG_LENGTH> host_sym_parent_matching = my_host->GetTag().XOR(tag).NOT();
emp::BitSet<TAG_LENGTH> host_sym_baby_matching = my_host->GetTag().XOR(sym_baby->GetTag()).NOT();
// difference in matching-ness, with match in child
emp::BitSet<TAG_LENGTH> child_towards = host_sym_baby_matching.XOR(host_sym_parent_matching).AND(host_sym_baby_matching);
// difference in matching-ness, with match in parent
emp::BitSet<TAG_LENGTH> child_from = host_sym_baby_matching.XOR(host_sym_parent_matching).AND(host_sym_parent_matching);
sym_baby->SetTowardsPartnerCount(child_towards.CountOnes() + towards_partner_count);
sym_baby->SetFromPartnerCount(child_from.CountOnes() + from_partner_count);
}
return sym_baby;
}
/**
* Input: None
*
* Output: Whether the potential parent symbiont meets requirements individually to vertically transmit
*
* Purpose: To answer if this symbiont has enough points to vertically transmit.
* Only tests requirements that are strictly based on the symbiont parent's internal state.
*/
virtual bool MeetsVTRequirements() {
if (GetPoints() >= my_config->SYM_VERT_TRANS_RES()) {
return true;
}
return false;
}
/**
* Input: emp::Ptr<Organism> to host offspring, emp::Ptr<Organism> to symbiont offspring
*
* Output: boolean, whether or not sym/sym offspring meets requirements to successfully vertically transmit
*
* Purpose: To test for compatibility between sym parent/offspring and host parent/offspring, such as tags
* */
virtual bool SuccessfulVT(emp::Ptr<Organism> host_baby, emp::Ptr<Organism> sym_baby) {
if (my_config->TAG_MATCHING()) {
const double tag_distance = (*my_world->GetTagMetric())(host_baby->GetTag(), sym_baby->GetTag())* TAG_LENGTH;
const double permissiveness_mean = (my_config->HOST_TAG_PERMISSIVENESS_EVOLVES()) ? host_baby->GetTagPermissiveness() : my_config->TAG_PERMISSIVENESS();
const double cutoff = random->GetPoisson(permissiveness_mean * TAG_LENGTH);
if (tag_distance > cutoff) {
return false;
}
}
return true;
}
/**
* Input: The pointer to the organism that is the new host baby
*
* Output: Return symbiont offspring on success; std::nullopt otherwise.
*
* Purpose: To allow for vertical transmission to occur
*/
std::optional<emp::Ptr<Organism>> VerticalTransmission(emp::Ptr<Organism> host_baby) {
bool success = false;
emp::Ptr<Organism> sym_baby;
if(my_world->WillTransmit()) {
//vertical transmission data node
emp::DataMonitor<double, emp::data::Histogram>& data_node_attempts_verttrans = my_world->GetVerticalTransmissionAttemptCount();
data_node_attempts_verttrans.AddDatum(GetIntVal());
if (MeetsVTRequirements()) {
sym_baby = Reproduce();
if (!SuccessfulVT(host_baby, sym_baby)) {
sym_baby.Delete();
return std::nullopt;
}
points = points - my_config->SYM_VERT_TRANS_RES();
success = host_baby->AddSymbiont(sym_baby);
emp::DataMonitor<double, emp::data::Histogram>& data_node_successes_verttrans = my_world->GetVerticalTransmissionSuccessCount();
data_node_successes_verttrans.AddDatum(GetIntVal());
}
}
return success ? std::optional<emp::Ptr<Organism>>{sym_baby} : std::nullopt;
}
/*
* Input: None
*
* Output: Boolean representing whether or not the symbiont meets requirements to independently reproduce (horizontally transmission or free-living reproduction, depending on config)
*
* Purpose: To check if the symbiont meets requirements to independently reproduce, based on its own internal state, without considering the host or host baby. This is intended to be used in the horizontal transmission and free-living reproduction process, to determine if the symbiont can attempt to horizontally transmit/independently reproduce.
* Adjusts the requirements to free-living symbionts if enabled and the free sym repro resources is different than the horizontal transmission resources.
* Currently just checks point requirement.
*/
bool MeetsIndependentReproRequirements() {
double required_points = my_config->SYM_HORIZ_TRANS_RES();
if (my_config->FREE_LIVING_SYMS() && my_host == nullptr && my_config->FREE_SYM_REPRO_RES() > -1) {
required_points = my_config->FREE_SYM_REPRO_RES();
}
return GetPoints() >= required_points;
}
/*
* Input: sym_pos, world position
*
* Output: None
*
* Purpose: Start the process for independent reproduction, generally through horizontal transmission, by marking in progress repo and removing points
*/
bool AttemptIndependentReproduction(emp::WorldPosition sym_pos) {
if (my_config->HORIZ_TRANS()) { //non-lytic horizontal transmission enabled
if (MeetsIndependentReproRequirements()) {
emp::DataMonitor<double, emp::data::Histogram>& data_node_attempts_horiztrans = my_world->GetHorizontalTransmissionAttemptCount();
data_node_attempts_horiztrans.AddDatum(GetIntVal());
// symbiont reproduces independently (horizontal transmission) if it has enough resources
//TODO: try just subtracting points to be consistent with vertical transmission
//points = points - my_config->SYM_HORIZ_TRANS_RES();
if(!my_config->TAG_MATCHING() && !my_config->FREE_HT_FAILURE()) SetPoints(0);
// removing the above for tag matching--sym parent points are
// now set to 0 in symdobirth
return true;
}
}
return false;
}
void AfterIndependentReproduction(const emp::WorldPosition& sym_baby_pos) {
emp::DataMonitor<double, emp::data::Histogram>& data_node_successes_horiztrans = my_world->GetHorizontalTransmissionSuccessCount();
if(sym_baby_pos.IsValid()) {
data_node_successes_horiztrans.AddDatum(GetIntVal());
}
}
/**
* Input: The location of the organism as a emp::WorldPosition(<index of sym in host +1>, <index of host in world>)
*
* Output: None
*
* Purpose: To check and allow for independent reproduction to occur (eiter horizontal transmission or free-living reproduction)
*/
void IndependentReproduction(emp::WorldPosition location) {
if (AttemptIndependentReproduction(location)) {
emp::Ptr<Organism> sym_baby = Reproduce();
if (my_config->TAG_MATCHING() || my_config->FREE_HT_FAILURE()) sym_baby->SetPoints(0);
emp::WorldPosition new_pos = my_world->SymDoBirth(sym_baby, this, location);
AfterIndependentReproduction(new_pos);
}
}
};
#endif