phylopomp
Phylodynamics for POMPs
Loading...
Searching...
No Matches
lineages.cc
Go to the documentation of this file.
1
7
8#include "node.h"
9#include "genealogy.h"
10#include "internal.h"
11
12void
14(int *incr, int *sat, int *etype) const
15{
16 const name_t d = deme();
17 incr[d]--;
18 for (ball_t *b : *this) {
19 switch (b->color) {
20 case green: case black:
21 incr[b->deme()]++;
22 sat[b->deme()]++;
23 break;
24 default:
25 break;
26 }
27 }
28 if (holds_own()) {
29 sat[d]--;
30 etype[d] = -1;
31 } else if (holds(blue)) {
32 etype[d] = 1;
33 } else {
34 etype[d] = 2;
35 }
36}
37
38void
40(double *tout, int *deme,
41 int *ell, int *sat, int *etype) const
42{
43 size_t nd = ndeme()+1;
44 slate_t tcur = timezero();
45 for (size_t j = 0; j < nd; j++) {
46 tout[j] = tcur;
47 deme[j] = j;
48 sat[j] = ell[j] = 0;
49 etype[j] = 0;
50 }
51 for (const node_t *p : *this) {
52 if (tcur < p->slate) {
53 tout += nd; ell += nd; sat += nd;
54 deme += nd; etype += nd;
55 tcur = p->slate;
56 for (size_t j = 0; j < nd; j++) {
57 tout[j] = tcur;
58 deme[j] = j;
59 ell[j] = (ell-nd)[j];
60 sat[j] = 0;
61 etype[j] = 0;
62 }
63 }
64 p->lineage_incr(ell,sat,etype);
65 }
66 tout += nd; ell += nd; sat += nd;
67 deme += nd; etype += nd;
68 tcur = time();
69 for (size_t j = 0; j < nd; j++) {
70 tout[j] = tcur;
71 sat[j] = ell[j] = 0;
72 deme[j] = j;
73 etype[j] = 3;
74 }
75}
76
78SEXP
80(void) const
81{
82 SEXP tout, deme, ell, sat, etype, out, outn;
83 int nt = ntime(timezero())+1;
84 int nl = (ndeme()+1)*nt;
85 PROTECT(tout = NEW_NUMERIC(nl));
86 PROTECT(deme = NEW_INTEGER(nl));
87 PROTECT(ell = NEW_INTEGER(nl));
88 PROTECT(sat = NEW_INTEGER(nl));
89 PROTECT(etype = NEW_INTEGER(nl));
90 PROTECT(out = NEW_LIST(5));
91 PROTECT(outn = NEW_CHARACTER(5));
92 set_list_elem(out,outn,tout,"time",0);
93 set_list_elem(out,outn,deme,"deme",1);
94 set_list_elem(out,outn,ell,"lineages",2);
95 set_list_elem(out,outn,sat,"saturation",3);
96 set_list_elem(out,outn,etype,"event_type",4);
97 SET_NAMES(out,outn);
98 lineage_count(REAL(tout),INTEGER(deme),INTEGER(ell),
99 INTEGER(sat),INTEGER(etype));
100 UNPROTECT(7);
101 return out;
102}
@ green
Definition ball.h:12
@ black
Definition ball.h:12
@ blue
Definition ball.h:12
Balls function as pointers.
Definition ball.h:27
name_t deme(void) const
view deme
Definition ball.h:84
color_t color
Definition ball.h:36
SEXP lineage_count(void) const
lineage count and saturation
Definition lineages.cc:80
size_t ndeme(void) const
number of demes
Definition genealogy.h:59
slate_t & timezero(void)
view/set zero time.
Definition genealogy.h:153
slate_t & time(void)
view/set current time.
Definition genealogy.h:145
Encodes a genealogical node.
Definition node.h:21
name_t deme(void) const
view deme
Definition node.h:96
slate_t slate
Definition node.h:33
void lineage_incr(int *incr, int *sat, int *etype) const
Definition lineages.cc:14
bool holds_own(void) const
Definition node.h:118
size_t ntime(slate_t t) const
Number of distinct timepoints.
Definition nodeseq.h:131
bool holds(ball_t *b) const
does this node hold the given ball?
Definition pocket.h:109
static int set_list_elem(SEXP list, SEXP names, SEXP element, const char *name, int pos)
Definition internal.h:76
size_t name_t
Definition internal.h:54
double slate_t
Definition internal.h:53
static const int deme
Definition lbdp.cc:7
#define ell
Definition lbdp_pomp.c:11