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

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 More...
 
raw_toperator>> (raw_t *o, master_t &A)
 binary deserialization More...
 

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) {};
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.",
71  __func__,__FILE__,__LINE__);
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
Rbyte raw_t
Definition: internal.h:43
Here is the call graph for this function:

◆ 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
Here is the call graph for this function:

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  };
Balls function as pointers.
Definition: ball.h:29
node_t * holder(void) const
in whose pocket do I lie?
Definition: ball.h:109
ball_t * birth(ball_t *a, slate_t t, name_t d)
birth into deme d
Definition: genealogy.h:401
void insert(ball_t *b)
Definition: inventory.h:160
ball_t * random_ball(name_t i=0) const
choose one random ball from deme i
Definition: inventory.h:124
slate_t time(void) const
current time
Definition: master.h:113
inventory_t< ndeme > inventory
Definition: master.h:32
#define n
Definition: lbdp_pomp.c:8
Here is the call graph for this function:
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  };
size_t bytesize(void) const
size of serialized binary form
Definition: genealogy.h:73
Here is the call graph for this function:
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  };
void death(ball_t *a, slate_t t)
death
Definition: genealogy.h:417
void erase(ball_t *b)
Definition: inventory.h:168
Here is the call graph for this function:
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  };
std::string describe(void) const
human-readable info
Definition: genealogy.h:342
Here is the call graph for this function:

◆ 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  };
ball_t * graft(slate_t t, name_t d)
graft a new lineage into deme d
Definition: genealogy.h:422
Here is the call graph for this function:
Here is the caller graph for this function:

◆ jump()

void twospecies_genealogy_t::jump ( int  e)

makes a jump

Definition at line 72 of file lbdp.cc.

72  {
73  switch (event) {
74  case 0:
75  state.n += 1; birth();
76  break;
77  case 1:
78  state.n -= 1; death();
79  break;
80  case 2:
81  sample();
82  break;
83  default: // #nocov
84  assert(0); // #nocov
85  break; // #nocov
86  }
87 }
void birth(name_t i=0, name_t j=0, int n=1)
n births into deme j with parent in deme i
Definition: master.h:142
void sample(name_t i=0, int n=1)
sample in deme i
Definition: master.h:166
void death(name_t i=0)
death in deme i
Definition: master.h:153
Here is the call graph for this function:

◆ 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  };
void lineage_count(double *tout, int *deme, int *ell, int *sat, int *etype) const
Definition: genealogy.h:171
Here is the call graph for this function:

◆ 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  };
name_t deme(void) const
view deme
Definition: ball.h:86
ball_t * migrate(ball_t *a, slate_t t, name_t d=0)
movement into deme d
Definition: genealogy.h:451
Here is the call 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  };
std::string newick(void) const
put genealogy at current time into Newick format.
Definition: genealogy.h:364
Here is the call graph for this function:

◆ 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  };
Here is the call graph for this function:

◆ 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  };
slate_t & time(void)
view/set current time.
Definition: genealogy.h:150
Here is the call graph for this function:

◆ rinit()

void twospecies_genealogy_t::rinit ( void  )

initialize the state

Definition at line 66 of file lbdp.cc.

66  {
67  state.n = params.n0;
68  graft(deme,params.n0);
69 }
void graft(name_t i=0, int m=1)
new root in deme i
Definition: master.h:159
static int deme
Definition: lbdp.cc:7
Here is the call graph for this function:

◆ 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  {
168  for (ball_it a = p->begin(); a != p->end(); a++) {
169  geneal.sample(*a,time());
170  }
171  p->clear();
172  delete p;
173  };
void sample(ball_t *a, slate_t t)
insert a sample node
Definition: genealogy.h:432
pocket_t * random_balls(name_t i=0, int n=1) const
choose a random set of n balls from deme i
Definition: inventory.h:133
A pocket is a set of balls.
Definition: pocket.h:32
std::set< ball_t *, ball_order >::const_iterator ball_it
Definition: pocket.h:26
Here is the call graph for this function:
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  {
177  for (ball_it a = p->begin(); a != p->end(); a++) {
178  inventory.erase(*a);
179  geneal.sample_death(*a,time());
180  }
181  p->clear();
182  delete p;
183  };
void sample_death(ball_t *a, slate_t t)
insert a sample node and simultaneously terminate the lineage
Definition: genealogy.h:441
Here is the call 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  };
SEXP structure(void) const
R list description.
Definition: genealogy.h:322
Here is the call graph for this function:

◆ 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  };
SEXP time(TYPE &X)
Definition: generics.h:22
Here is the call graph for this function:
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  };
slate_t timezero(void) const
get zero time.
Definition: genealogy.h:158
Here is the call graph for this function:

◆ 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 + " ";
123  std::string s = popul_t::yaml(tab)
124  + "genealogy:\n" + geneal.yaml(t);
125  return s;
126  };
SEXP yaml(SEXP State)
extract a YAML description
Definition: bare.cc:21
virtual std::string yaml(std::string tab="") const
machine-readable info
Definition: genealogy.h:352
Here is the call graph for this function:

Friends And Related Function 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);
50  A.inventory = A.geneal.extant();
51  return o;
52  }
std::pair< node_it, node_it > extant(void) const
Definition: genealogy.h:461

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 files: