Stride Reference Manual  - generated for commit 9643b11
ContactPool.cpp
Go to the documentation of this file.
1 /*
2  * This is free software: you can redistribute it and/or modify it
3  * under the terms of the GNU General Public License as published by
4  * the Free Software Foundation, either version 3 of the License, or
5  * any later version.
6  * The software is distributed in the hope that it will be useful,
7  * but WITHOUT ANY WARRANTY; without even the implied warranty of
8  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9  * GNU General Public License for more details.
10  * You should have received a copy of the GNU General Public License
11  * along with the software. If not, see <http://www.gnu.org/licenses/>.
12  *
13  * Copyright 2017, Kuylen E, Willem L, Broeckhove J
14  */
15 
21 #include "ContactPool.h"
22 
23 #include "pop/Age.h"
24 #include "pop/Person.h"
25 
26 #include <algorithm>
27 
28 namespace stride {
29 
30 using namespace std;
31 
32 ContactPool::ContactPool(unsigned int poolId, ContactType::Id type)
33  : m_index_immune(0), m_pool_id(poolId), m_pool_type(type), m_members()
34 {
35 }
36 
38 {
39  m_members.emplace_back(p);
41 }
42 
43 unsigned int ContactPool::GetInfectedCount() const
44 {
45  unsigned int infected = 0;
46 
47  for (stride::Person* person : m_members) {
48  if (person->GetHealth().IsInfected()) {
49  infected++;
50  }
51  }
52  return infected;
53 }
54 
55 std::tuple<bool, unsigned int> ContactPool::SortMembers()
56 {
57  bool infectious_cases = false;
58  unsigned int num_cases = 0;
59 
60  for (size_t i_member = 0; i_member < m_index_immune; i_member++) {
61  // if immune, move to back
62  if (m_members[i_member]->GetHealth().IsImmune()) {
63  bool swapped = false;
64  unsigned int new_place = m_index_immune - 1;
65  m_index_immune--;
66  while (!swapped && new_place > i_member) {
67  if (m_members[new_place]->GetHealth().IsImmune()) {
68  m_index_immune--;
69  new_place--;
70  } else {
71  swap(m_members[i_member], m_members[new_place]);
72  swapped = true;
73  }
74  }
75  }
76  // else, if not susceptible, move to front
77  else if (!m_members[i_member]->GetHealth().IsSusceptible()) {
78  if (!infectious_cases && m_members[i_member]->GetHealth().IsInfectious()) {
79  infectious_cases = true;
80  }
81  if (i_member > num_cases) {
82  swap(m_members[i_member], m_members[num_cases]);
83  }
84  num_cases++;
85  }
86  }
87  return std::make_tuple(infectious_cases, num_cases);
88 }
89 
90 } // namespace stride
std::vector< Person * > m_members
Pointers to contactpool members (raw pointers intentional).
Definition: ContactPool.h:90
Id
Enumerates the ContactPool types.
Definition: ContactType.h:34
Header file for the Person class.
Header for the core ContactPool class.
void AddMember(Person *p)
Add the given Person.
Definition: ContactPool.cpp:37
unsigned int GetInfectedCount() const
Get Infected count.
Definition: ContactPool.cpp:43
STL namespace.
unsigned int m_index_immune
Index of the first immune member in the ContactPool.
Definition: ContactPool.h:87
Helpers for age.
std::tuple< bool, unsigned int > SortMembers()
Sort w.r.t. health status: order: exposed/infected/recovered, susceptible, immune.
Definition: ContactPool.cpp:55
ContactPool(unsigned int poolId, ContactType::Id type)
Initializing constructor.
Definition: ContactPool.cpp:32
Store and handle person data.
Definition: Person.h:34
Namespace for the simulator and related classes.
Definition: Calendar.cpp:28