-
Notifications
You must be signed in to change notification settings - Fork 23
/
Organism.hpp
127 lines (104 loc) · 5.09 KB
/
Organism.hpp
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
/**
* @note This file is part of MABE, https://github.com/mercere99/MABE2
* @copyright Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
* @date 2019-2024.
*
* @file Organism.hpp
* @brief A base class for all organisms in MABE.
* @note Status: ALPHA
*
* All organism types or organism component types (e.g., brains or genomes) that can be
* individually configured in MABE must have mabe::OrgType as its ultimate base class. A helper
* template mabe::OrganismTemplate<ORG_T> is derived from mabe::OrgType and should be used as
* the more immediate base class for any user-defined organism types. Providing this template
* with your new organism type as ORG_T will setup type-specific return values for ease of use.
*
* All interactions between an organism and its environment are mediated through the Organism's
* DataMap. The configuration files need to be setup to ensure that environments and organisms
* agree on the input values, the output values, and use of any type adaptors.
*
* If an environment wants to allow ACTIONS to occur during execution, it can provide callback
* functions to the organisms in the appropriate OrganismManager DataMap. If the environment
* wants to indicate EVENTS that occur during an organism's lifetime, it can find the appropriate
* function to call in the manager's DataMap.
*
*/
#ifndef MABE_ORGANISM_H
#define MABE_ORGANISM_H
#include "emp/base/assert.hpp"
#include "emp/base/vector.hpp"
#include "emp/data/AnnotatedType.hpp"
#include "emp/tools/String.hpp"
#include "OrgType.hpp"
namespace mabe {
class Population;
class Organism : public OrgType, public emp::AnnotatedType {
private:
emp::Ptr<Population> pop_ptr = nullptr;
public:
Organism(ModuleBase & _man) : OrgType(_man) { ; }
virtual ~Organism() {
emp_assert(
pop_ptr.IsNull(),
"Organisms must be removed from populations before deletion; use MABE::ClearOrgAt()."
);
}
/// Test if this organism represents an empty cell.
virtual bool IsEmpty() const noexcept { return false; }
emp::Ptr<Population> GetPopPtr() const { return pop_ptr; }
Population & GetPopulation() { return *pop_ptr; }
void SetPopulation(Population & in) { pop_ptr = ∈ }
void ClearPopulation() { pop_ptr = nullptr; }
/// Specialty version of Clone to return an Organism type.
[[nodiscard]] virtual emp::Ptr<Organism> CloneOrganism() const {
return OrgType::Clone().DynamicCast<Organism>();
}
[[nodiscard]] emp::Ptr<Organism>
RecombineOrganisms(emp::Ptr<Organism> parent2, emp::Random & random) const {
return OrgType::Recombine(parent2, random).DynamicCast<Organism>();
}
// @CAO: Need to clean this one up...
[[nodiscard]] emp::vector<emp::Ptr<OrgType>>
RecombineOrganisms(emp::vector<emp::Ptr<OrgType>> other_parents, emp::Random & random) const {
return OrgType::Recombine(other_parents, random);
}
/// Produce an asexual offspring WITH MUTATIONS.
[[nodiscard]] virtual emp::Ptr<Organism> MakeOffspringOrganism(emp::Random & random) const {
return OrgType::MakeOffspring(random).DynamicCast<Organism>();
}
/// Produce an sexual (two parent) offspring WITH MUTATIONS.
[[nodiscard]] virtual emp::Ptr<Organism>
MakeOffspringOrganism_TwoParent(emp::Ptr<Organism> parent2, emp::Random & random) const {
return OrgType::MakeOffspring(parent2, random).DynamicCast<Organism>();
}
// @CAO: Need to clean this one up to use Organism...
/// Produce one or more offspring from multiple parents WITH MUTATIONS.
// @CAO: By default, use Recombine() and then Mutate() ?
[[nodiscard]] virtual emp::vector<emp::Ptr<OrgType>>
MakeOffspringOrganisms_MultiParent(emp::vector<emp::Ptr<OrgType>> other_parents, emp::Random & random) const {
return OrgType::MakeOffspring(other_parents, random);
}
// -- Also deal with some deprecated functionality... --
[[deprecated("Use OrgType::HasTrait() instead of OrgType::HasVar()")]]
bool HasVar(const emp::String & name) const { return HasTrait(name); }
template <typename T>
[[deprecated("Use OrgType::GetTrait() instead of OrgType::GetVar()")]]
T & GetVar(const emp::String & name) { return GetTrait<T>(name); }
template <typename T>
[[deprecated("Use OrgType::GetTrait() instead of OrgType::GetVar()")]]
const T & GetVar(const emp::String & name) const { return GetTrait<T>(name); }
template <typename T>
[[deprecated("Use OrgType::GetTrait() instead of OrgType::GetVar()")]]
T & GetVar(size_t id) { return GetTrait<T>(id); }
template <typename T>
[[deprecated("Use OrgType::GetTrait() instead of OrgType::GetVar()")]]
const T & GetVar(size_t id) const { return GetTrait<T>(id); }
template <typename T>
[[deprecated("Use OrgType::SetTrait() instead of OrgType::SetVar()")]]
void SetVar(const emp::String & name, const T & value) { SetTrait(name, value); }
template <typename T>
[[deprecated("Use OrgType::SetTrait() instead of OrgType::SetVar()")]]
void SetVar(size_t id, const T & value) { SetTrait(id, value); }
};
}
#endif