Health-GPS 3.0.0.0
Global Health Policy Simulation model (Health-GPS)
Loading...
Searching...
No Matches
population.h
Go to the documentation of this file.
1#pragma once
2#include "person.h"
3
4#ifndef NDEBUG
5#include <cassert>
6#endif
7
8#include <vector>
9
10namespace hgps {
11
20 public:
22 using IteratorType = std::vector<Person>::iterator;
24 using ConstIteratorType = std::vector<Person>::const_iterator;
25
26 Population() = delete;
29 explicit Population(const std::size_t size);
30
33 std::size_t size() const noexcept;
34
37 std::size_t initial_size() const noexcept;
38
41 std::size_t current_active_size() const noexcept;
42
46 Person &operator[](std::size_t index);
47
51 const Person &operator[](std::size_t index) const;
52
57 Person &at(std::size_t index);
58
63 const Person &at(std::size_t index) const;
64
68 void add(Person person, unsigned int time) noexcept;
69
74 void add_newborn_babies(std::size_t number, core::Gender gender, unsigned int time) noexcept;
75
78 IteratorType begin() noexcept { return people_.begin(); }
79
82 IteratorType end() noexcept { return people_.end(); }
83
86 ConstIteratorType begin() const noexcept { return people_.cbegin(); }
87
90 ConstIteratorType end() const noexcept { return people_.cend(); }
91
94 ConstIteratorType cbegin() const noexcept { return people_.cbegin(); }
95
98 ConstIteratorType cend() const noexcept { return people_.cend(); }
99
100 private:
101 std::size_t initial_size_;
102 // MAHIMA: Lifetime-unique person ID counter for post-initial entrants.
103 // Initial cohort keeps deterministic IDs [1..initial_size_] for baseline/intervention
104 // alignment. All later entrants (births/immigration) get IDs from this monotonic counter and
105 // IDs are never reused even when slots are recycled.
106 std::size_t next_person_id_{1};
107 std::vector<Person> people_;
108
109 std::vector<int> find_index_of_recyclables(unsigned int time,
110 std::size_t top = 0) const noexcept;
111
114 std::size_t allocate_next_person_id() noexcept {
115 const std::size_t id = next_person_id_;
116#ifndef NDEBUG
117 // MAHIMA: Debug-only duplicate-ID guard; compiled out in release (no extra memory or work).
118 assert(id != Person::unassigned_id);
119 assert(id == next_person_id_ && "Person ID must be the next unused value (no reuse)");
120#endif
121 ++next_person_id_;
122 return id;
123 }
124};
125} // namespace hgps
Defines the virtual population data type.
Definition population.h:19
ConstIteratorType end() const noexcept
Gets a read-only iterator to the element following the last Person of the population.
Definition population.h:90
IteratorType end() noexcept
Gets an iterator to the element following the last Person of the population.
Definition population.h:82
std::vector< Person >::iterator IteratorType
Population iterator.
Definition population.h:22
ConstIteratorType cend() const noexcept
Gets a read-only iterator to the element following the last Person of the population.
Definition population.h:98
std::size_t size() const noexcept
Gets the current size of the population.
Definition population.cpp:32
std::vector< Person >::const_iterator ConstIteratorType
Read-only population iterator.
Definition population.h:24
std::size_t initial_size() const noexcept
Gets the initial size of the population.
Definition population.cpp:34
Population()=delete
std::size_t current_active_size() const noexcept
Gets the current active size of the population.
Definition population.cpp:36
ConstIteratorType cbegin() const noexcept
Gets an read-only iterator to the beginning of the virtual population.
Definition population.h:94
Person & at(std::size_t index)
Gets a Person by index with bounds checking.
Definition population.cpp:47
IteratorType begin() noexcept
Gets an iterator to the beginning of the virtual population.
Definition population.h:78
void add_newborn_babies(std::size_t number, core::Gender gender, unsigned int time) noexcept
Adds newborn babies of gender to the virtual population, age = 0.
Definition population.cpp:65
void add(Person person, unsigned int time) noexcept
Adds a Person to the virtual population.
Definition population.cpp:51
ConstIteratorType begin() const noexcept
Gets an read-only iterator to the beginning of the virtual population.
Definition population.h:86
Top-level namespace for Health-GPS Console host application.
Definition command_options.cpp:8
Global namespace.
Definition column_iterator.h:123
Defines a virtual population person data type.
Definition person.h:39
static constexpr std::size_t unassigned_id
Sentinel returned by default constructors until Population assigns an ID.
Definition person.h:49