phylopomp
Phylodynamics for POMPs
Loading...
Searching...
No Matches
sum.cc
Go to the documentation of this file.
1#include "node.h"
2#include "genealogy.h"
3#include "generics.h"
4#include "internal.h"
5#include <Rinternals.h>
6
8void
10(name_t shift)
11{
12 this->uniq += shift;
13 for (ball_t *b : *this) {
14 b->uniq += shift;
15 }
16}
17
19void
21(name_t shift)
22{
23 this->_unique += shift;
24 for (node_t *p : *this) p->reuniqify(shift);
25}
26
29genealogy_t::operator+=
30(const genealogy_t& other)
31{
32 genealogy_t G = other;
33 slate_t t0 = timezero();
34 slate_t t = time();
35 t0 = (t0 < G.timezero()) ? t0 : G.timezero();
36 t = (t > G.time()) ? t : G.time();
38 merge(G,compare);
39 timezero() = t0;
40 time() = t;
41 ndeme() = (ndeme() > G.ndeme()) ? ndeme() : G.ndeme();
42 _unique = G._unique;
43 return *this;
44}
45
46extern "C" {
47
49 SEXP genealSum (SEXP args) {
50 args = CDR(args);
51 genealogy_t A(R_PosInf); // a "null" genealogy
52 A.time() = R_NegInf;
53 while (args != R_NilValue) {
54 A += CAR(args);
55 args = CDR(args);
56 }
57 SEXP S;
58 PROTECT(S = serial(A));
59 SET_ATTR(S,install("class"),mkString("gpgen"));
60 UNPROTECT(1);
61 return S;
62 }
63
64}
Balls function as pointers.
Definition ball.h:27
name_t uniq
Definition ball.h:35
Encodes a genealogy.
Definition genealogy.h:19
void reuniqify(name_t shift)
shifts names to avoid overlap
Definition sum.cc:21
genealogy_t(double t0=R_NaReal, size_t ndeme=0)
Definition genealogy.h:102
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
name_t _unique
The next unique name.
Definition genealogy.h:30
Encodes a genealogical node.
Definition node.h:21
void reuniqify(name_t shift)
shifts name to avoid overlap
Definition sum.cc:10
name_t uniq
Definition node.h:32
static bool compare(node_t *p, node_t *q)
Definition nodeseq.h:95
SEXP ndeme(TYPE &X)
Definition generics.h:7
SEXP timezero(TYPE &X)
Definition generics.h:22
SEXP time(TYPE &X)
Definition generics.h:27
SEXP serial(const TYPE &X)
binary serialization
Definition generics.h:33
size_t name_t
Definition internal.h:54
double slate_t
Definition internal.h:53
#define S
Definition seirs_pomp.c:37
SEXP genealSum(SEXP args)
combine genealogies
Definition sum.cc:49