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 t = time();
34 slate_t t0 = timezero();
35 t0 = (t0 > G.timezero()) ? t0 : G.timezero();
36 t = (t < G.time()) ? t : G.time();
38 merge(G,compare);
39 timezero() = (timezero() < G.timezero()) ? timezero() : G.timezero();
40 time() = (time() > G.time()) ? time() : G.time();
41 ndeme() = (ndeme() > G.ndeme()) ? ndeme() : G.ndeme();
42 _unique = G._unique;
43 curtail(t,t0);
44 return *this;
45}
46
47extern "C" {
48
50 SEXP genealSum (SEXP args) {
51 args = CDR(args);
52 genealogy_t A(R_NegInf); // a "null" genealogy on [-inf,inf]
53 A.time() = R_PosInf;
54 while (args != R_NilValue) {
55 A += CAR(args);
56 args = CDR(args);
57 }
58 SEXP S;
59 PROTECT(S = serial(A));
60 SET_ATTR(S,install("class"),mkString("gpgen"));
61 UNPROTECT(1);
62 return S;
63 }
64
65}
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 curtail(SEXP State, SEXP Time, SEXP Troot)
curtail the given genealogy
Definition curtail.cc:88
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:50