phylopomp
Phylodynamics for POMPs
Loading...
Searching...
No Matches
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
 
string_t yaml (string_t tab="") const
 human/machine readable info
 
string_t 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=1, name_t j=1, int n=1)
 n births into deme j with parent in deme i
 
void death (name_t i=1)
 death in deme i
 
void graft (name_t i=1, int m=1)
 new root in deme i
 
void sample (name_t i=1, int n=1)
 sample in deme i
 
void sample_death (name_t i=1, int n=1)
 sample_death in deme i
 
void migrate (name_t i=1, name_t j=1)
 migration from deme i to deme j
 
void sample_migrate (name_t i=1, name_t j=1)
 sample_migrate in 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< NDEME > inventory
 

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>
class master_t< POPN, NDEME >

Encodes the master process.

This consists of a population process and a genealogy process.

Definition at line 21 of file master.h.

Member Typedef Documentation

◆ popul_t

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

Definition at line 25 of file master.h.

Constructor & Destructor Documentation

◆ master_t() [1/5]

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

basic constructor t0 = initial time

Definition at line 61 of file master.h.

61: popul_t(t0), geneal(t0,ndeme) {};
Encodes the master process.
Definition master.h:21
genealogy_t geneal
Definition master.h:30
POPN popul_t
Definition master.h:25
static const size_t ndeme
Definition master.h:26

◆ master_t() [2/5]

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

constructor from serialized binary form

Definition at line 63 of file master.h.

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

◆ master_t() [3/5]

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

constructor from RAW SEXP (containing binary serialization)

Definition at line 67 of file master.h.

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

◆ master_t() [4/5]

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

copy constructor

Definition at line 75 of file master.h.

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

◆ master_t() [5/5]

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

move constructor

◆ ~master_t()

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

destructor

Definition at line 95 of file master.h.

95 {
96 clean();
97 };
void clean(void)
Definition master.h:55

Member Function Documentation

◆ birth()

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

n births into deme j with parent in deme i

Definition at line 136 of file master.h.

136 {
137 ball_t *a = inventory.random_ball(i);
138 ball_t *b = geneal.birth(a,time(),j);
139 inventory.insert(b);
140 while (n > 1) {
141 b = geneal.birth(b->holder(),j);
142 inventory.insert(b);
143 n--;
144 }
145 };
slate_t time(void) const
current time
Definition master.h:111
inventory_t< NDEME > inventory
Definition master.h:31
Here is the caller graph for this function:

◆ bytesize()

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

size of serialized binary form

Definition at line 35 of file master.h.

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

◆ clean()

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

Definition at line 55 of file master.h.

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

◆ death()

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

death in deme i

Definition at line 147 of file master.h.

147 {
148 ball_t *a = inventory.random_ball(i);
149 inventory.erase(a);
150 geneal.death(a,time());
151 };
Here is the caller graph for this function:

◆ graft()

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

new root in deme i

Definition at line 153 of file master.h.

153 {
154 for (int j = 0; j < m; j++) {
155 ball_t *a = geneal.graft(time(),i);
156 inventory.insert(a);
157 }
158 };
Here is the caller graph for this function:

◆ jump()

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

makes a jump

◆ lineage_count()

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

lineage count table

Definition at line 126 of file master.h.

126 {
127 return geneal.lineage_count();
128 };

◆ migrate()

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

migration from deme i to deme j

Definition at line 179 of file master.h.

179 {
180 ball_t *a = inventory.random_ball(i);
181 inventory.erase(a);
182 geneal.migrate(a,time(),j);
183 inventory.insert(a);
184 };
Here is the caller graph for this function:

◆ newick()

template<class POPN, size_t NDEME>
string_t master_t< POPN, NDEME >::newick ( void ) const
inline

tree in Newick format

Definition at line 122 of file master.h.

122 {
123 return geneal.newick();
124 };

◆ operator=() [1/2]

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

copy assignment operator

Definition at line 82 of file master.h.

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

◆ operator=() [2/2]

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

move assignment operator

◆ play()

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

runs the process to time tfin

Definition at line 103 of file master.h.

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

◆ rinit()

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

initialize the state

◆ sample()

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

sample in deme i

Definition at line 160 of file master.h.

160 {
161 pocket_t *p = inventory.random_balls(i,n);
162 for (ball_t *a : *p) {
163 geneal.sample(a,time());
164 }
165 p->clear();
166 delete p;
167 };
Here is the caller graph for this function:

◆ sample_death()

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

sample_death in deme i

Definition at line 169 of file master.h.

169 {
170 pocket_t *p = inventory.random_balls(i,n);
171 for (ball_t *a : *p) {
172 inventory.erase(a);
173 geneal.sample_death(a,time());
174 }
175 p->clear();
176 delete p;
177 };
Here is the caller graph for this function:

◆ sample_migrate()

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

sample_migrate in deme i to deme j

Definition at line 186 of file master.h.

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

◆ structure()

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

structure in R list format

Definition at line 130 of file master.h.

130 {
131 return geneal.structure();
132 };

◆ time()

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

current time

Definition at line 111 of file master.h.

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

◆ timezero()

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

get zero-time

Definition at line 99 of file master.h.

99 {
100 return geneal.timezero();
101 };

◆ yaml()

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

human/machine readable info

Definition at line 115 of file master.h.

115 {
116 string_t t = tab + " ";
118 + "genealogy:\n" + geneal.yaml(t);
119 return s;
120 };

Friends And Related Symbol Documentation

◆ operator>> [1/2]

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

binary serialization

Definition at line 39 of file master.h.

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

◆ operator>> [2/2]

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

binary deserialization

Definition at line 45 of file master.h.

45 {
46 A.clean();
47 o = (o >> A.geneal);
48 o = (o >> reinterpret_cast<popul_t&>(A));
50 return o;
51 }

Field Documentation

◆ geneal

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

Definition at line 30 of file master.h.

◆ inventory

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

Definition at line 31 of file master.h.

◆ ndeme

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

Definition at line 26 of file master.h.


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