phylopomp
Phylodynamics for POMPs
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
inventory_t< NDEME > Class Template Reference

Representation for the inventory process. More...

#include <inventory.h>

Collaboration diagram for inventory_t< NDEME >:

Public Member Functions

 inventory_t (void)=default
 basic constructor for inventory class More...
 
 inventory_t (raw_t *o)
 constructor from serialized binary form More...
 
 inventory_t (std::pair< node_it, node_it > &&I)
 
 inventory_t (const inventory_t &)=default
 copy constructor More...
 
 inventory_t (inventory_t &&)=delete
 move constructor More...
 
inventory_toperator= (std::pair< node_it, node_it > &&I)
 copy an inventory by iterating over a node sequence More...
 
inventory_toperator= (const inventory_t &)=default
 copy assignment operator More...
 
inventory_toperator= (inventory_t &&)=delete
 move assignment operator More...
 
 ~inventory_t (void)
 destructor More...
 
void clean (void)
 memory cleanup More...
 
void clear (void)
 memory cleanup More...
 
size_t bytesize (void) const
 size of serialized binary form More...
 
size_t size (void) const
 
size_t size (name_t i) const
 size of deme More...
 
pocket_toperator[] (const name_t n)
 return the n-th deme More...
 
bool empty (void) const
 are all demes empty? More...
 
ball_trandom_ball (name_t i=0) const
 choose one random ball from deme i More...
 
pocket_trandom_balls (name_t i=0, int n=1) const
 choose a random set of n balls from deme i More...
 
void insert (ball_t *b)
 
void erase (ball_t *b)
 

Private Attributes

pocket_t _inven [NDEME]
 

Static Private Attributes

static const size_t ndeme = NDEME
 

Friends

raw_toperator>> (const inventory_t &I, raw_t *o)
 binary serialization More...
 
raw_toperator>> (raw_t *o, inventory_t &I)
 binary deserialization More...
 

Detailed Description

template<size_t NDEME = 1>
class inventory_t< NDEME >

Representation for the inventory process.

An inventory consists of an array of demes. Each deme is a set of black balls.

Definition at line 18 of file inventory.h.

Constructor & Destructor Documentation

◆ inventory_t() [1/5]

template<size_t NDEME = 1>
inventory_t< NDEME >::inventory_t ( void  )
default

basic constructor for inventory class

◆ inventory_t() [2/5]

template<size_t NDEME = 1>
inventory_t< NDEME >::inventory_t ( raw_t o)
inline

constructor from serialized binary form

Definition at line 31 of file inventory.h.

31  {
32  o >> *this;
33  };

◆ inventory_t() [3/5]

template<size_t NDEME = 1>
inventory_t< NDEME >::inventory_t ( std::pair< node_it, node_it > &&  I)
inline

constructor from node sequence (via 'extant' operation). this constructs an inventory from a genealogy.

Definition at line 36 of file inventory.h.

36  {
37  clean();
38  for (node_it i = I.first; i != I.second; i++) {
39  for (ball_it j = (*i)->begin(); j != (*i)->end(); j++) {
40  insert(*j); // 'insert' checks color
41  }
42  }
43  };
void insert(ball_t *b)
Definition: inventory.h:160
void clean(void)
memory cleanup
Definition: inventory.h:67
std::list< node_t * >::const_iterator node_it
Definition: nodeseq.h:14
std::set< ball_t *, ball_order >::const_iterator ball_it
Definition: pocket.h:26
#define I
Definition: seirs_pomp.c:35
Here is the call graph for this function:

◆ inventory_t() [4/5]

template<size_t NDEME = 1>
inventory_t< NDEME >::inventory_t ( const inventory_t< NDEME > &  )
default

copy constructor

◆ inventory_t() [5/5]

template<size_t NDEME = 1>
inventory_t< NDEME >::inventory_t ( inventory_t< NDEME > &&  )
delete

move constructor

◆ ~inventory_t()

template<size_t NDEME = 1>
inventory_t< NDEME >::~inventory_t ( void  )
inline

destructor

Definition at line 63 of file inventory.h.

63  {
64  clean();
65  };
Here is the call graph for this function:

Member Function Documentation

◆ bytesize()

template<size_t NDEME = 1>
size_t inventory_t< NDEME >::bytesize ( void  ) const
inline

size of serialized binary form

Definition at line 77 of file inventory.h.

77  {
78  size_t s = 0;
79  for (size_t i = 0; i < ndeme; i++)
80  s += _inven[i].bytesize();
81  return s;
82  };
size_t bytesize(void) const
size of serialized binary form
Definition: inventory.h:77
pocket_t _inven[NDEME]
Definition: inventory.h:22
static const size_t ndeme
Definition: inventory.h:23

◆ clean()

template<size_t NDEME = 1>
void inventory_t< NDEME >::clean ( void  )
inline

memory cleanup

Definition at line 67 of file inventory.h.

67  {
68  clear();
69  };
void clear(void)
memory cleanup
Definition: inventory.h:71
Here is the call graph for this function:
Here is the caller graph for this function:

◆ clear()

template<size_t NDEME = 1>
void inventory_t< NDEME >::clear ( void  )
inline

memory cleanup

Definition at line 71 of file inventory.h.

71  {
72  for (size_t i = 0; i < ndeme; i++)
73  _inven[i].clear();
74  };
Here is the caller graph for this function:

◆ empty()

template<size_t NDEME = 1>
bool inventory_t< NDEME >::empty ( void  ) const
inline

are all demes empty?

Definition at line 116 of file inventory.h.

116  {
117  bool q = true;
118  for (name_t i = 0; i < ndeme; i++) {
119  q = q && _inven[i].empty();
120  }
121  return q;
122  };
size_t name_t
Definition: internal.h:45

◆ erase()

template<size_t NDEME = 1>
void inventory_t< NDEME >::erase ( ball_t b)
inline

remove a black ball from its deme. this checks the color of the ball. if it is not black, nothing is done.

Definition at line 168 of file inventory.h.

168  {
169  if (b->is(black)) {
170  assert(!(_inven[b->deme()].empty()));
171  _inven[b->deme()].erase(b);
172  }
173  };
@ black
Definition: ball.h:14
name_t deme(void) const
view deme
Definition: ball.h:86
bool is(color_t c) const
is a given ball of the given color?
Definition: ball.h:117
Here is the call graph for this function:
Here is the caller graph for this function:

◆ insert()

template<size_t NDEME = 1>
void inventory_t< NDEME >::insert ( ball_t b)
inline

add a black ball to a deme. this checks the color of the ball. if it is not black, nothing is done.

Definition at line 160 of file inventory.h.

160  {
161  if (b->is(black)) {
162  _inven[b->deme()].insert(b);
163  }
164  };
Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator=() [1/3]

template<size_t NDEME = 1>
inventory_t& inventory_t< NDEME >::operator= ( const inventory_t< NDEME > &  )
default

copy assignment operator

◆ operator=() [2/3]

template<size_t NDEME = 1>
inventory_t& inventory_t< NDEME >::operator= ( inventory_t< NDEME > &&  )
delete

move assignment operator

◆ operator=() [3/3]

template<size_t NDEME = 1>
inventory_t& inventory_t< NDEME >::operator= ( std::pair< node_it, node_it > &&  I)
inline

copy an inventory by iterating over a node sequence

Definition at line 49 of file inventory.h.

49  {
50  clean();
51  for (node_it i = I.first; i != I.second; i++) {
52  for (ball_it j = (*i)->begin(); j != (*i)->end(); j++) {
53  insert(*j); // 'insert' checks color
54  }
55  }
56  return *this;
57  };
Here is the call graph for this function:

◆ operator[]()

template<size_t NDEME = 1>
pocket_t& inventory_t< NDEME >::operator[] ( const name_t  n)
inline

return the n-th deme

Definition at line 112 of file inventory.h.

112  {
113  return _inven[n];
114  };
#define n
Definition: lbdp_pomp.c:8

◆ random_ball()

template<size_t NDEME = 1>
ball_t* inventory_t< NDEME >::random_ball ( name_t  i = 0) const
inline

choose one random ball from deme i

Definition at line 124 of file inventory.h.

124  {
125  name_t n = _inven[i].size();
126  assert(n > 0);
127  name_t draw = random_integer(n);
128  ball_it k = _inven[i].begin();
129  while (draw-- > 0) k++;
130  return *k;
131  };
static int random_integer(int n)
Definition: internal.h:48
Here is the call graph for this function:
Here is the caller graph for this function:

◆ random_balls()

template<size_t NDEME = 1>
pocket_t* inventory_t< NDEME >::random_balls ( name_t  i = 0,
int  n = 1 
) const
inline

choose a random set of n balls from deme i

Definition at line 133 of file inventory.h.

133  {
134  pocket_t *p = new pocket_t();
135  if (n == 1) {
136  ball_t *b = random_ball(i);
137  p->insert(b);
138  } else if (n > 1) {
139  int N = _inven[i].size();
140  assert(N > 0);
141  assert(n <= N);
142  ball_it j = _inven[i].begin();
143  int k = 0, m = 0;
144  while (m < n && k < N) {
145  int u = random_integer(N-k);
146  if (u < n-m) {
147  p->insert(*j);
148  m++;
149  }
150  k++; j++;
151  }
152  } else {
153  assert(0); // #nocov
154  }
155  return p;
156  };
Balls function as pointers.
Definition: ball.h:29
ball_t * random_ball(name_t i=0) const
choose one random ball from deme i
Definition: inventory.h:124
A pocket is a set of balls.
Definition: pocket.h:32
#define N
Definition: seirs_pomp.c:32
Here is the call graph for this function:
Here is the caller graph for this function:

◆ size() [1/2]

template<size_t NDEME = 1>
size_t inventory_t< NDEME >::size ( name_t  i) const
inline

size of deme

Definition at line 108 of file inventory.h.

108  {
109  return _inven[i].size();
110  };

◆ size() [2/2]

template<size_t NDEME = 1>
size_t inventory_t< NDEME >::size ( void  ) const
inline

Total number of balls in an inventory. i.e., the sum of the sizes of all demes

Definition at line 100 of file inventory.h.

100  {
101  size_t n = 0;
102  for (name_t i = 0; i < ndeme; i++) {
103  n += size(i);
104  }
105  return n;
106  };
size_t size(void) const
Definition: inventory.h:100

Friends And Related Function Documentation

◆ operator>> [1/2]

template<size_t NDEME = 1>
raw_t* operator>> ( const inventory_t< NDEME > &  I,
raw_t o 
)
friend

binary serialization

Definition at line 84 of file inventory.h.

84  {
85  for (size_t i = 0; i < ndeme; i++) {
86  o = (I._inven[i] >> o);
87  }
88  return o;
89  };

◆ operator>> [2/2]

template<size_t NDEME = 1>
raw_t* operator>> ( raw_t o,
inventory_t< NDEME > &  I 
)
friend

binary deserialization

Definition at line 91 of file inventory.h.

91  {
92  I.clean();
93  for (size_t i = 0; i < ndeme; i++) {
94  o = (o >> I._inven[i]);
95  }
96  return o;
97  };

Field Documentation

◆ _inven

template<size_t NDEME = 1>
pocket_t inventory_t< NDEME >::_inven[NDEME]
private

Definition at line 22 of file inventory.h.

◆ ndeme

template<size_t NDEME = 1>
const size_t inventory_t< NDEME >::ndeme = NDEME
staticprivate

Definition at line 23 of file inventory.h.


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