phylopomp
Phylodynamics for POMPs
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
master_t< POPN, NDEME > Class Template Reference

Encodes the master process. More...

#include <master.h>

Inheritance diagram for master_t< POPN, NDEME >:
Collaboration diagram for master_t< POPN, NDEME >:

Public Types

typedef POPN popul_t
 

Public Member Functions

size_t bytesize (void) const
 size of serialized binary form
 
 master_t (double t0=0)
 
 master_t (raw_t *o)
 constructor from serialized binary form
 
 master_t (SEXP o)
 constructor from RAW SEXP (containing binary serialization)
 
 master_t (const master_t &A)
 copy constructor
 
master_toperator= (const master_t &A)
 copy assignment operator
 
 master_t (master_t &&)=default
 move constructor
 
master_toperator= (master_t &&)=default
 move assignment operator
 
 ~master_t (void)
 destructor
 
slate_t timezero (void) const
 get zero-time
 
int play (double tfin)
 runs the process to time tfin
 
slate_t time (void) const
 current time
 
std::string describe (void) const
 human-readable info
 
std::string yaml (std::string tab="") const
 machine/human readable info
 
std::string newick (void) const
 tree in Newick format
 
SEXP lineage_count (void) const
 lineage count table
 
SEXP structure (void) const
 structure in R list format
 
void birth (name_t i=0, name_t j=0, int n=1)
 n births into deme j with parent in deme i
 
void death (name_t i=0)
 death in deme i
 
void graft (name_t i=0, int m=1)
 new root in deme i
 
void sample (name_t i=0, int n=1)
 sample in deme i
 
void sample_death (name_t i=0, int n=1)
 sample_death in deme i
 
void migrate (name_t i=0, name_t j=0)
 migration from deme i to deme j
 
void rinit (void)
 initialize the state
 
void jump (int e)
 makes a jump
 

Data Fields

genealogy_t geneal
 
inventory_t< ndemeinventory
 

Static Public Attributes

static const size_t ndeme = NDEME
 

Private Member Functions

void clean (void)
 

Friends

raw_toperator>> (const master_t &A, raw_t *o)
 binary serialization
 
raw_toperator>> (raw_t *o, master_t &A)
 binary deserialization
 

Detailed Description

template<class POPN, size_t NDEME = 1>
class master_t< POPN, NDEME >

Encodes the master process.

This consists of a population process and a genealogy process.

Definition at line 22 of file master.h.

Member Typedef Documentation

◆ popul_t

template<class POPN, size_t NDEME = 1>
typedef POPN master_t< POPN, NDEME >::popul_t

Definition at line 26 of file master.h.

Constructor & Destructor Documentation

◆ master_t() [1/5]

template<class POPN, size_t NDEME = 1>
master_t< POPN, NDEME >::master_t ( double t0 = 0)
inline

basic constructor t0 = initial time

Definition at line 62 of file master.h.

62: popul_t(t0), geneal(t0,0,ndeme) {};
Encodes the master process.
Definition master.h:22
genealogy_t geneal
Definition master.h:31
POPN popul_t
Definition master.h:26
static const size_t ndeme
Definition master.h:27

◆ master_t() [2/5]

template<class POPN, size_t NDEME = 1>
master_t< POPN, NDEME >::master_t ( raw_t * o)
inline

constructor from serialized binary form

Definition at line 64 of file master.h.

64 {
65 o >> *this;
66 };

◆ master_t() [3/5]

template<class POPN, size_t NDEME = 1>
master_t< POPN, NDEME >::master_t ( SEXP o)
inline

constructor from RAW SEXP (containing binary serialization)

Definition at line 68 of file master.h.

68 {
69 if (LENGTH(o)==0)
70 err("in %s (%s line %d): cannot deserialize a NULL.",
72 PROTECT(o = AS_RAW(o));
73 RAW(o) >> *this;
74 UNPROTECT(1);
75 };
#define err(...)
Definition internal.h:18

◆ master_t() [4/5]

template<class POPN, size_t NDEME = 1>
master_t< POPN, NDEME >::master_t ( const master_t< POPN, NDEME > & A)
inline

copy constructor

Definition at line 77 of file master.h.

77 {
78 raw_t *o = new raw_t[A.bytesize()];
79 A >> o;
80 o >> *this;
81 delete[] o;
82 };
size_t bytesize(void) const
size of serialized binary form
Definition master.h:36

◆ master_t() [5/5]

template<class POPN, size_t NDEME = 1>
master_t< POPN, NDEME >::master_t ( master_t< POPN, NDEME > && )
default

move constructor

◆ ~master_t()

template<class POPN, size_t NDEME = 1>
master_t< POPN, NDEME >::~master_t ( void )
inline

destructor

Definition at line 97 of file master.h.

97 {
98 clean();
99 };
void clean(void)
Definition master.h:56

Member Function Documentation

◆ birth()

template<class POPN, size_t NDEME = 1>
void master_t< POPN, NDEME >::birth ( name_t i = 0,
name_t j = 0,
int n = 1 )
inline

n births into deme j with parent in deme i

Definition at line 142 of file master.h.

142 {
143 ball_t *a = inventory.random_ball(i);
144 ball_t *b = geneal.birth(a,time(),j);
145 inventory.insert(b);
146 while (n > 1) {
147 b = geneal.birth(b->holder(),j);
148 inventory.insert(b);
149 n--;
150 }
151 };
slate_t time(void) const
current time
Definition master.h:113
inventory_t< ndeme > inventory
Definition master.h:32
Here is the caller graph for this function:

◆ bytesize()

template<class POPN, size_t NDEME = 1>
size_t master_t< POPN, NDEME >::bytesize ( void ) const
inline

size of serialized binary form

Definition at line 36 of file master.h.

36 {
37 return popul_t::bytesize() + geneal.bytesize();
38 };
Here is the caller graph for this function:

◆ clean()

template<class POPN, size_t NDEME = 1>
void master_t< POPN, NDEME >::clean ( void )
inlineprivate

Definition at line 56 of file master.h.

56{ };
Here is the caller graph for this function:

◆ death()

template<class POPN, size_t NDEME = 1>
void master_t< POPN, NDEME >::death ( name_t i = 0)
inline

death in deme i

Definition at line 153 of file master.h.

153 {
154 ball_t *a = inventory.random_ball(i);
155 inventory.erase(a);
156 geneal.death(a,time());
157 };
Here is the caller graph for this function:

◆ describe()

template<class POPN, size_t NDEME = 1>
std::string master_t< POPN, NDEME >::describe ( void ) const
inline

human-readable info

Definition at line 117 of file master.h.

117 {
118 return geneal.describe();
119 };

◆ graft()

template<class POPN, size_t NDEME = 1>
void master_t< POPN, NDEME >::graft ( name_t i = 0,
int m = 1 )
inline

new root in deme i

Definition at line 159 of file master.h.

159 {
160 for (int j = 0; j < m; j++) {
161 ball_t *a = geneal.graft(time(),i);
162 inventory.insert(a);
163 }
164 };
Here is the caller graph for this function:

◆ jump()

template<class POPN, size_t NDEME = 1>
void master_t< POPN, NDEME >::jump ( int e)

makes a jump

◆ lineage_count()

template<class POPN, size_t NDEME = 1>
SEXP master_t< POPN, NDEME >::lineage_count ( void ) const
inline

lineage count table

Definition at line 132 of file master.h.

132 {
133 return geneal.lineage_count();
134 };

◆ migrate()

template<class POPN, size_t NDEME = 1>
void master_t< POPN, NDEME >::migrate ( name_t i = 0,
name_t j = 0 )
inline

migration from deme i to deme j

Definition at line 185 of file master.h.

185 {
186 ball_t *a = inventory.random_ball(i);
187 inventory.erase(a);
188 geneal.migrate(a,time(),j);
189 a->deme() = j;
190 inventory.insert(a);
191 };
Here is the caller graph for this function:

◆ newick()

template<class POPN, size_t NDEME = 1>
std::string master_t< POPN, NDEME >::newick ( void ) const
inline

tree in Newick format

Definition at line 128 of file master.h.

128 {
129 return geneal.newick();
130 };

◆ operator=() [1/2]

template<class POPN, size_t NDEME = 1>
master_t & master_t< POPN, NDEME >::operator= ( const master_t< POPN, NDEME > & A)
inline

copy assignment operator

Definition at line 84 of file master.h.

84 {
85 clean();
86 raw_t *o = new raw_t[A.bytesize()];
87 A >> o;
88 o >> *this;
89 delete[] o;
90 return *this;
91 };

◆ operator=() [2/2]

template<class POPN, size_t NDEME = 1>
master_t & master_t< POPN, NDEME >::operator= ( master_t< POPN, NDEME > && )
default

move assignment operator

◆ play()

template<class POPN, size_t NDEME = 1>
int master_t< POPN, NDEME >::play ( double tfin)
inline

runs the process to time tfin

Definition at line 105 of file master.h.

105 {
106 int count = popul_t::play(tfin);
107 geneal.time() = tfin;
108 return count;
109 };

◆ rinit()

template<class POPN, size_t NDEME = 1>
void master_t< POPN, NDEME >::rinit ( void )

initialize the state

◆ sample()

template<class POPN, size_t NDEME = 1>
void master_t< POPN, NDEME >::sample ( name_t i = 0,
int n = 1 )
inline

sample in deme i

Definition at line 166 of file master.h.

166 {
167 pocket_t *p = inventory.random_balls(i,n);
168 for (ball_t *a : *p) {
169 geneal.sample(a,time());
170 }
171 p->clear();
172 delete p;
173 };
Here is the caller graph for this function:

◆ sample_death()

template<class POPN, size_t NDEME = 1>
void master_t< POPN, NDEME >::sample_death ( name_t i = 0,
int n = 1 )
inline

sample_death in deme i

Definition at line 175 of file master.h.

175 {
176 pocket_t *p = inventory.random_balls(i,n);
177 for (ball_t *a : *p) {
178 inventory.erase(a);
179 geneal.sample_death(a,time());
180 }
181 p->clear();
182 delete p;
183 };
Here is the caller graph for this function:

◆ structure()

template<class POPN, size_t NDEME = 1>
SEXP master_t< POPN, NDEME >::structure ( void ) const
inline

structure in R list format

Definition at line 136 of file master.h.

136 {
137 return geneal.structure();
138 };

◆ time()

template<class POPN, size_t NDEME = 1>
slate_t master_t< POPN, NDEME >::time ( void ) const
inline

current time

Definition at line 113 of file master.h.

113 {
114 return popul_t::time();
115 };
Here is the caller graph for this function:

◆ timezero()

template<class POPN, size_t NDEME = 1>
slate_t master_t< POPN, NDEME >::timezero ( void ) const
inline

get zero-time

Definition at line 101 of file master.h.

101 {
102 return geneal.timezero();
103 };

◆ yaml()

template<class POPN, size_t NDEME = 1>
std::string master_t< POPN, NDEME >::yaml ( std::string tab = "") const
inline

machine/human readable info

Definition at line 121 of file master.h.

121 {
122 std::string t = tab + " ";
124 + "genealogy:\n" + geneal.yaml(t);
125 return s;
126 };

Friends And Related Symbol Documentation

◆ operator>> [1/2]

template<class POPN, size_t NDEME = 1>
raw_t * operator>> ( const master_t< POPN, NDEME > & A,
raw_t * o )
friend

binary serialization

Definition at line 40 of file master.h.

40 {
41 o = (reinterpret_cast<const popul_t&>(A) >> o);
42 o = (A.geneal >> o);
43 return o;
44 }

◆ operator>> [2/2]

template<class POPN, size_t NDEME = 1>
raw_t * operator>> ( raw_t * o,
master_t< POPN, NDEME > & A )
friend

binary deserialization

Definition at line 46 of file master.h.

46 {
47 A.clean();
48 o = (o >> reinterpret_cast<popul_t&>(A));
49 o = (o >> A.geneal);
51 return o;
52 }
std::pair< node_it, node_it > extant(void) const
Definition genealogy.h:464

Field Documentation

◆ geneal

template<class POPN, size_t NDEME = 1>
genealogy_t master_t< POPN, NDEME >::geneal

Definition at line 31 of file master.h.

◆ inventory

template<class POPN, size_t NDEME = 1>
inventory_t<ndeme> master_t< POPN, NDEME >::inventory

Definition at line 32 of file master.h.

◆ ndeme

template<class POPN, size_t NDEME = 1>
const size_t master_t< POPN, NDEME >::ndeme = NDEME
static

Definition at line 27 of file master.h.


The documentation for this class was generated from the following file: