metapopulation_mobility_instant.h Source File

CPP API: metapopulation_mobility_instant.h Source File
metapopulation_mobility_instant.h
Go to the documentation of this file.
1 /*
2 * Copyright (C) 2020-2026 MEmilio
3 *
4 * Authors: Daniel Abele
5 *
6 * Contact: Martin J. Kuehn <Martin.Kuehn@DLR.de>
7 *
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 */
20 #ifndef METAPOPULATION_MOBILITY_INSTANT_H
21 #define METAPOPULATION_MOBILITY_INSTANT_H
22 
26 #include "memilio/math/eigen.h"
27 #include "memilio/math/euler.h"
32 
33 namespace mio
34 {
35 
39 template <typename FP, class Sim>
41 {
42 public:
43  using Simulation = Sim;
44 
45  template <class... Args>
46  requires std::is_constructible_v<Sim, Args...>
47  SimulationNode(Args&&... args)
48  : m_simulation(std::forward<Args>(args)...)
49  , m_last_state(m_simulation.get_result().get_last_value())
50  , m_t0(m_simulation.get_result().get_last_time())
51  {
52  }
53 
58  decltype(auto) get_result() const
59  {
60  return m_simulation.get_result();
61  }
62  decltype(auto) get_result()
63  {
64  return m_simulation.get_result();
65  }
73  {
74  return m_simulation;
75  }
76  const Sim& get_simulation() const
77  {
78  return m_simulation;
79  }
82  Eigen::Ref<const Eigen::VectorX<FP>> get_last_state() const
83  {
84  return m_last_state;
85  }
86 
87  FP get_t0() const
88  {
89  return m_t0;
90  }
91 
92  void advance(FP t, FP dt)
93  {
94  m_simulation.advance(t + dt);
95  m_last_state = m_simulation.get_result().get_last_value();
96  }
97 
98 private:
100  Eigen::VectorX<FP> m_last_state;
101  FP m_t0;
102 };
103 
107 template <typename FP>
109 
114 template <typename FP>
116 
121 template <typename FP>
123 {
124 public:
130  : m_coefficients(coeffs)
132  {
133  }
134 
139  MobilityParameters(const Eigen::VectorX<FP>& coeffs)
142  {
143  }
144 
155  MobilityParameters(const MobilityCoefficientGroup<FP>& coeffs, const std::vector<std::vector<size_t>>& save_indices)
156  : m_coefficients(coeffs)
157  , m_saved_compartment_indices(save_indices)
158  {
159  }
160 
170  MobilityParameters(const Eigen::VectorX<FP>& coeffs, const std::vector<std::vector<size_t>>& save_indices)
172  , m_saved_compartment_indices(save_indices)
173  {
174  }
175 
180  bool operator==(const MobilityParameters& other) const
181  {
182  return m_coefficients == other.m_coefficients;
183  }
184  bool operator!=(const MobilityParameters& other) const
185  {
186  return m_coefficients != other.m_coefficients;
187  }
189 
200  {
201  return m_coefficients;
202  }
204  {
205  return m_coefficients;
206  }
211  {
212  m_coefficients = coeffs;
213  }
214 
225  const auto& get_save_indices() const
226  {
228  }
229 
239  {
240  return m_dynamic_npis;
241  }
243  {
244  return m_dynamic_npis;
245  }
250  {
251  m_dynamic_npis = v;
252  }
259  template <class IOContext>
260  void serialize(IOContext& io) const
261  {
262  auto obj = io.create_object("MobilityParameters");
263  obj.add_element("Coefficients", m_coefficients);
264  obj.add_element("DynamicNPIs", m_dynamic_npis);
265  }
266 
271  template <class IOContext>
273  {
274  auto obj = io.expect_object("MobilityParameters");
275  auto c = obj.expect_element("Coefficients", Tag<MobilityCoefficientGroup<FP>>{});
276  auto d = obj.expect_element("DynamicNPIs", Tag<DynamicNPIs<FP>>{});
277  return apply(
278  io,
279  [](auto&& c_, auto&& d_) {
280  MobilityParameters params(c_);
281  params.set_dynamic_npis_infected(d_);
282  return params;
283  },
284  c, d);
285  }
286 
287 private:
288  MobilityCoefficientGroup<FP> m_coefficients; //one per group and compartment
290  std::vector<std::vector<size_t>> m_saved_compartment_indices; // groups of indices from compartments to save
291 };
292 
296 template <typename FP>
298 {
299 public:
305  : m_parameters(params)
306  , m_mobile_population(params.get_coefficients().get_shape().rows())
307  , m_return_times(0)
309  , m_saved_compartment_indices(params.get_save_indices())
311  {
312  }
313 
320  MobilityEdge(const Eigen::VectorX<FP>& coeffs)
321  : m_parameters(coeffs)
322  , m_mobile_population(coeffs.rows())
323  , m_return_times(0)
327  {
328  }
329 
338  MobilityEdge(const MobilityParameters<FP>& params, const std::vector<std::vector<size_t>>& save_indices)
339  : m_parameters(params)
340  , m_mobile_population(params.get_coefficients().get_shape().rows())
341  , m_return_times(0)
343  , m_saved_compartment_indices(save_indices)
345  {
346  }
347 
356  MobilityEdge(const Eigen::VectorX<FP>& coeffs, const std::vector<std::vector<size_t>>& save_indices)
357  : m_parameters(coeffs)
358  , m_mobile_population(coeffs.rows())
359  , m_return_times(0)
361  , m_saved_compartment_indices(save_indices)
363  {
364  }
365 
370  {
371  return m_parameters;
372  }
373 
381  {
382  return m_mobility_results;
383  }
385  {
386  return m_mobility_results;
387  }
400  template <class Sim>
401  void apply_mobility(FP t, FP dt, SimulationNode<FP, Sim>& node_from, SimulationNode<FP, Sim>& node_to);
402 
403 private:
408  FP m_t_last_dynamic_npi_check = -std::numeric_limits<FP>::infinity();
409  std::pair<FP, SimulationTime<FP>> m_dynamic_npi = {-std::numeric_limits<FP>::max(), SimulationTime<FP>(0)};
410  std::vector<std::vector<size_t>> m_saved_compartment_indices; // groups of indices from compartments to save
411  TimeSeries<FP> m_mobility_results; // save results from edges + entry for the total number of commuters
412 
421  void add_mobility_result_time_point(const FP t);
422 };
423 
424 template <typename FP>
426 {
427  const size_t save_indices_size = this->m_saved_compartment_indices.size();
428  if (save_indices_size > 0) {
429  const auto& last_value = m_mobile_population.get_last_value();
430 
431  Eigen::VectorX<FP> condensed_values = Eigen::VectorX<FP>::Zero(save_indices_size + 1);
432 
433  // sum up the values of m_saved_compartment_indices for each group (e.g. Age groups)
434  for (size_t i = 0; i < save_indices_size; ++i) {
435  FP sum = 0.0;
436  for (auto index : this->m_saved_compartment_indices[i]) {
437  sum += last_value[index];
438  }
439  condensed_values[i] = sum;
440  }
441 
442  // the last value is the sum of commuters
443  condensed_values[save_indices_size] = m_mobile_population.get_last_value().sum();
444 
445  // Move the condensed values to the m_mobility_results time series
446  m_mobility_results.add_time_point(t, std::move(condensed_values));
447  }
448 }
449 
461 template <typename FP, IsCompartmentalModelSimulation<FP> Sim>
462 void calculate_mobility_returns(Eigen::Ref<typename TimeSeries<FP>::Vector> mobile_population, const Sim& sim,
463  Eigen::Ref<const typename TimeSeries<FP>::Vector> total, FP t, FP dt)
464 {
465  auto y0 = mobile_population.eval();
466  auto y1 = mobile_population;
468  [&](auto&& y, auto&& t_, auto&& dydt) {
469  sim.get_model().get_derivatives(total, y, t_, dydt);
470  },
471  y0, t, dt, y1);
472 }
473 
483 template <typename FP, class Sim>
484 FP get_infections_relative(const SimulationNode<FP, Sim>& node, FP t, const Eigen::Ref<const Eigen::VectorX<FP>>& y)
485 {
486  if constexpr (requires { get_infections_relative<FP>(node.get_simulation(), t, y); }) {
487  return get_infections_relative<FP>(node.get_simulation(), t, y);
488  }
489  else {
490  mio::unused(node, t, y);
491  mio::log_debug("get_infections_relative called without specialization for this simulation type. "
492  "Implement an overload in your model if you intend to use dynamic NPIs.");
493  return FP{0};
494  }
495 }
496 
508 template <typename FP, class Sim>
509 auto get_mobility_factors(const SimulationNode<FP, Sim>& node, FP t, const Eigen::Ref<const Eigen::VectorX<FP>>& y)
510 {
511  if constexpr (requires { get_mobility_factors<FP>(node.get_simulation(), t, y); }) {
512  return get_mobility_factors<FP>(node.get_simulation(), t, y);
513  }
514  else {
515  mio::unused(node, t);
516  mio::log_debug("get_mobility_factors called without specialization for this simulation type. "
517  "Using default mobility factor (1.0) for all compartments.");
518  return Eigen::VectorX<FP>::Ones(y.rows());
519  }
520 }
521 
532 template <typename FP, class Sim>
533 void test_commuters(SimulationNode<FP, Sim>& node, Eigen::Ref<Eigen::VectorX<FP>> mobile_population, FP time)
534 {
535  if constexpr (requires { test_commuters<FP>(node.get_simulation(), mobile_population, time); }) {
536  test_commuters<FP>(node.get_simulation(), mobile_population, time);
537  }
538  else {
539  mio::unused(node, mobile_population, time);
540  mio::log_debug("test_commuters called without specialization for this simulation type. "
541  "Implement an overload in your model if you intend to use commuter testing.");
542  }
543 }
544 
545 template <typename FP>
546 template <class Sim>
548  SimulationNode<FP, Sim>& node_to)
549 {
550  //check dynamic npis
551  if (m_t_last_dynamic_npi_check == -std::numeric_limits<FP>::infinity()) {
552  m_t_last_dynamic_npi_check = node_from.get_t0();
553  }
554 
555  auto& dyn_npis = m_parameters.get_dynamic_npis_infected();
556  if (dyn_npis.get_thresholds().size() > 0 &&
557  floating_point_greater_equal<FP>(t, m_t_last_dynamic_npi_check + dyn_npis.get_interval().get())) {
558  auto inf_rel =
559  get_infections_relative<FP>(node_from, t, node_from.get_last_state()) * dyn_npis.get_base_value();
560  auto exceeded_threshold = dyn_npis.get_max_exceeded_threshold(inf_rel);
561  if (exceeded_threshold != dyn_npis.get_thresholds().end() &&
562  (exceeded_threshold->first > m_dynamic_npi.first ||
563  t > FP(m_dynamic_npi.second))) { //old NPI was weaker or is expired
564  auto t_end = SimulationTime<FP>(t + dyn_npis.get_duration().get());
565  m_dynamic_npi = std::make_pair(exceeded_threshold->first, t_end);
566  implement_dynamic_npis<FP>(m_parameters.get_coefficients(), exceeded_threshold->second,
567  SimulationTime<FP>(t), t_end, [this](auto& g) {
568  return make_mobility_damping_vector<FP>(
569  m_parameters.get_coefficients().get_shape(), g);
570  });
571  }
572  m_t_last_dynamic_npi_check = t;
573  }
574 
575  //returns
576  for (Eigen::Index i = m_return_times.get_num_time_points() - 1; i >= 0; --i) {
577  if (m_return_times.get_time(i) <= t) {
578  auto v0 = find_value_reverse<FP>(node_to.get_result(), m_mobile_population.get_time(i), 1e-10, 1e-10);
579  assert(v0 != node_to.get_result().rend() && "unexpected error.");
580  calculate_mobility_returns<FP>(m_mobile_population[i], node_to.get_simulation(), *v0,
581  m_mobile_population.get_time(i), dt);
582 
583  //the lower-order return calculation may in rare cases produce negative compartments,
584  //especially at the beginning of the simulation.
585  //fix by subtracting the supernumerous returns from the biggest compartment of the age group.
586  Eigen::VectorX<FP> remaining_after_return =
587  (node_to.get_result().get_last_value() - m_mobile_population[i]).eval();
588  for (Eigen::Index j = 0; j < node_to.get_result().get_last_value().size(); ++j) {
589  if (remaining_after_return(j) < 0) {
590  auto num_comparts = (Eigen::Index)Sim::Model::Compartments::Count;
591  auto group = Eigen::Index(j / num_comparts);
592  auto compart = j % num_comparts;
593  log(remaining_after_return(j) < -1e-3 ? LogLevel::warn : LogLevel::info,
594  "Underflow during mobility returns at time {}, compartment {}, age group {}: {}", t, compart,
595  group, remaining_after_return(j));
596  Eigen::Index max_index;
597  slice(remaining_after_return, {group * num_comparts, num_comparts}).maxCoeff(&max_index);
598  log_info("Transferring to compartment {}", max_index);
599  max_index += group * num_comparts;
600  m_mobile_population[i](max_index) -= remaining_after_return(j);
601  m_mobile_population[i](j) += remaining_after_return(j);
602  }
603  }
604  node_from.get_result().get_last_value() += m_mobile_population[i];
605  node_to.get_result().get_last_value() -= m_mobile_population[i];
606  add_mobility_result_time_point(t);
607  m_mobile_population.remove_time_point(i);
608  m_return_times.remove_time_point(i);
609  }
610  }
611 
612  if (!m_return_mobile_population &&
613  (m_parameters.get_coefficients().get_matrix_at(SimulationTime<FP>(t)).array() > 0.0).any()) {
614  //normal daily mobility
615  m_mobile_population.add_time_point(
616  t, (node_from.get_last_state().array() *
617  m_parameters.get_coefficients().get_matrix_at(SimulationTime<FP>(t)).array() *
618  get_mobility_factors<FP>(node_from, t, node_from.get_last_state()).array())
619  .matrix());
620  m_return_times.add_time_point(t + dt);
621 
622  test_commuters<FP>(node_from, m_mobile_population.get_last_value(), t);
623 
624  node_to.get_result().get_last_value() += m_mobile_population.get_last_value();
625  node_from.get_result().get_last_value() -= m_mobile_population.get_last_value();
626 
627  add_mobility_result_time_point(t);
628  }
629  m_return_mobile_population = !m_return_mobile_population;
630 }
631 
636 template <typename FP, class Sim>
637 void advance_model(FP t, FP dt, SimulationNode<FP, Sim>& node)
638 {
639  node.advance(t, dt);
640 }
641 
646 template <typename FP, class Sim>
647 void apply_mobility(FP t, FP dt, MobilityEdge<FP>& mobilityEdge, SimulationNode<FP, Sim>& node_from,
648  SimulationNode<FP, Sim>& node_to)
649 {
650  mobilityEdge.apply_mobility(t, dt, node_from, node_to);
651 }
652 
663 template <typename FP, class Sim>
664 GraphSimulation<FP, Graph<SimulationNode<FP, Sim>, MobilityEdge<FP>>, FP, FP,
666  void (*)(FP, FP, mio::SimulationNode<FP, Sim>&)>
668 {
669  return make_graph_sim<FP>(
670  t0, dt, graph, static_cast<void (*)(FP, FP, SimulationNode<FP, Sim>&)>(&advance_model<FP, Sim>),
671  static_cast<void (*)(FP, FP, MobilityEdge<FP>&, SimulationNode<FP, Sim>&, SimulationNode<FP, Sim>&)>(
672  &apply_mobility<FP>));
673 }
674 
675 template <typename FP, class Sim>
676 GraphSimulation<FP, Graph<SimulationNode<FP, Sim>, MobilityEdge<FP>>, FP, FP,
678  void (*)(FP, FP, mio::SimulationNode<FP, Sim>&)>
680 {
681  return make_graph_sim<FP>(
682  t0, dt, std::move(graph), static_cast<void (*)(FP, FP, SimulationNode<FP, Sim>&)>(&advance_model<FP, Sim>),
683  static_cast<void (*)(FP, FP, MobilityEdge<FP>&, SimulationNode<FP, Sim>&, SimulationNode<FP, Sim>&)>(
684  &apply_mobility<FP>));
685 }
686 
699 template <typename FP, class Sim>
701 {
705  void (*)(FP, FP, mio::SimulationNode<FP, Sim>&)>;
706  return GraphSim(t0, std::numeric_limits<FP>::infinity(), graph, &advance_model<FP, Sim>,
708 }
709 
710 template <typename FP, class Sim>
712 {
716  void (*)(FP, FP, mio::SimulationNode<FP, Sim>&)>;
717  return GraphSim(t0, std::numeric_limits<FP>::infinity(), std::move(graph), &advance_model<FP, Sim>,
719 }
720 
723 } // namespace mio
724 
725 #endif //METAPOPULATION_MOBILITY_INSTANT_H
represents a collection of DampingMatrixExpressions that are summed up.
Definition: contact_matrix.h:272
represents the coefficient wise matrix (or vector) expression B - D * M where B is a baseline,...
Definition: contact_matrix.h:46
represents non-pharmaceutical interventions (NPI) that are activated during the simulation if some va...
Definition: dynamic_npis.h:35
Simple explicit euler integration y(t+1) = y(t) + h*f(t,y) for ODE y'(t) = f(t,y)
Definition: euler.h:34
bool step(const DerivFunction< FP > &f, Eigen::Ref< const Eigen::VectorX< FP >> yt, FP &t, FP &dt, Eigen::Ref< Eigen::VectorX< FP >> ytp1) const override
Fixed step width of the integration.
Definition: euler.h:54
Definition: graph_simulation.h:96
generic graph structure
Definition: graph.h:153
represents the mobility between two nodes.
Definition: metapopulation_mobility_instant.h:298
std::pair< FP, SimulationTime< FP > > m_dynamic_npi
Definition: metapopulation_mobility_instant.h:409
MobilityEdge(const MobilityParameters< FP > &params, const std::vector< std::vector< size_t >> &save_indices)
Create edge with coefficients as MobilityParameters object and a 2D vector of indices which determine...
Definition: metapopulation_mobility_instant.h:338
MobilityEdge(const Eigen::VectorX< FP > &coeffs, const std::vector< std::vector< size_t >> &save_indices)
Create edge with coefficients and a 2D vector of indices which determine which compartments are saved...
Definition: metapopulation_mobility_instant.h:356
TimeSeries< FP > & get_mobility_results()
Get the count of commuters in selected compartments, along with the total number of commuters.
Definition: metapopulation_mobility_instant.h:380
std::vector< std::vector< size_t > > m_saved_compartment_indices
Definition: metapopulation_mobility_instant.h:410
MobilityParameters< FP > m_parameters
Definition: metapopulation_mobility_instant.h:404
MobilityEdge(const MobilityParameters< FP > &params)
Create edge with coefficients.
Definition: metapopulation_mobility_instant.h:304
FP m_t_last_dynamic_npi_check
Definition: metapopulation_mobility_instant.h:408
const MobilityParameters< FP > & get_parameters() const
get the mobility parameters.
Definition: metapopulation_mobility_instant.h:369
TimeSeries< FP > m_mobility_results
Definition: metapopulation_mobility_instant.h:411
void add_mobility_result_time_point(const FP t)
Computes a condensed version of m_mobile_population and stores it in m_mobility_results.
Definition: metapopulation_mobility_instant.h:425
void apply_mobility(FP t, FP dt, SimulationNode< FP, Sim > &node_from, SimulationNode< FP, Sim > &node_to)
compute mobility from node_from to node_to.
Definition: metapopulation_mobility_instant.h:547
MobilityEdge(const Eigen::VectorX< FP > &coeffs)
Create edge with coefficients.
Definition: metapopulation_mobility_instant.h:320
TimeSeries< FP > m_mobile_population
Definition: metapopulation_mobility_instant.h:405
const TimeSeries< FP > & get_mobility_results() const
Get the count of commuters in selected compartments, along with the total number of commuters.
Definition: metapopulation_mobility_instant.h:384
TimeSeries< FP > m_return_times
Definition: metapopulation_mobility_instant.h:406
bool m_return_mobile_population
Definition: metapopulation_mobility_instant.h:407
parameters that influence mobility.
Definition: metapopulation_mobility_instant.h:123
bool operator!=(const MobilityParameters &other) const
Definition: metapopulation_mobility_instant.h:184
MobilityParameters(const MobilityCoefficientGroup< FP > &coeffs, const std::vector< std::vector< size_t >> &save_indices)
Constructor for initializing mobility parameters with coefficients from type MobilityCoefficientGroup...
Definition: metapopulation_mobility_instant.h:155
bool operator==(const MobilityParameters &other) const
equality comparison operators
Definition: metapopulation_mobility_instant.h:180
DynamicNPIs< FP > & get_dynamic_npis_infected()
Get/Setthe mobility coefficients.
Definition: metapopulation_mobility_instant.h:242
const MobilityCoefficientGroup< FP > & get_coefficients() const
Get/Setthe mobility coefficients.
Definition: metapopulation_mobility_instant.h:199
void serialize(IOContext &io) const
serialize this.
Definition: metapopulation_mobility_instant.h:260
void set_coefficients(const MobilityCoefficientGroup< FP > &coeffs)
Definition: metapopulation_mobility_instant.h:210
void set_dynamic_npis_infected(const DynamicNPIs< FP > &v)
Definition: metapopulation_mobility_instant.h:249
MobilityParameters(const Eigen::VectorX< FP > &coeffs, const std::vector< std::vector< size_t >> &save_indices)
Constructor for initializing mobility parameters with coefficients from an Eigen Vector and specific ...
Definition: metapopulation_mobility_instant.h:170
static IOResult< MobilityParameters > deserialize(IOContext &io)
deserialize an object of this class.
Definition: metapopulation_mobility_instant.h:272
MobilityParameters(const Eigen::VectorX< FP > &coeffs)
constructor from mobility coefficients.
Definition: metapopulation_mobility_instant.h:139
MobilityCoefficientGroup< FP > & get_coefficients()
Get/Setthe mobility coefficients.
Definition: metapopulation_mobility_instant.h:203
const DynamicNPIs< FP > & get_dynamic_npis_infected() const
Get/Set dynamic NPIs that are implemented when relative infections exceed thresholds.
Definition: metapopulation_mobility_instant.h:238
std::vector< std::vector< size_t > > m_saved_compartment_indices
Definition: metapopulation_mobility_instant.h:290
MobilityParameters(const MobilityCoefficientGroup< FP > &coeffs)
constructor from mobility coefficients.
Definition: metapopulation_mobility_instant.h:129
MobilityCoefficientGroup< FP > m_coefficients
Definition: metapopulation_mobility_instant.h:288
const auto & get_save_indices() const
Get the indices of compartments to be saved during mobility.
Definition: metapopulation_mobility_instant.h:225
DynamicNPIs< FP > m_dynamic_npis
Definition: metapopulation_mobility_instant.h:289
represents the simulation in one node of the graph.
Definition: metapopulation_mobility_instant.h:41
Sim m_simulation
Definition: metapopulation_mobility_instant.h:99
Sim Simulation
Definition: metapopulation_mobility_instant.h:43
requires std::is_constructible_v< Sim, Args... > SimulationNode(Args &&... args)
Definition: metapopulation_mobility_instant.h:47
Eigen::Ref< const Eigen::VectorX< FP > > get_last_state() const
Definition: metapopulation_mobility_instant.h:82
decltype(auto) get_result() const
get the result of the simulation in this node.
Definition: metapopulation_mobility_instant.h:58
Eigen::VectorX< FP > m_last_state
Definition: metapopulation_mobility_instant.h:100
FP get_t0() const
Definition: metapopulation_mobility_instant.h:87
FP m_t0
Definition: metapopulation_mobility_instant.h:101
void advance(FP t, FP dt)
Definition: metapopulation_mobility_instant.h:92
Sim & get_simulation()
get the the simulation in this node.
Definition: metapopulation_mobility_instant.h:72
const Sim & get_simulation() const
get the the simulation in this node.
Definition: metapopulation_mobility_instant.h:76
double simulation time.
Definition: damping.h:58
stores vectors of values at time points (or some other abstract variable) the value at each time poin...
Definition: time_series.h:58
Eigen::Matrix< FP, Eigen::Dynamic, 1 > Vector
base type of expressions of vector values at a time point
Definition: time_series.h:63
static min_max_return_type< ad::internal::active_type< AD_TAPE_REAL, DATA_HANDLER_1 >, ad::internal::active_type< AD_TAPE_REAL, DATA_HANDLER_1 > >::type max(const ad::internal::active_type< AD_TAPE_REAL, DATA_HANDLER_1 > &a, const ad::internal::active_type< AD_TAPE_REAL, DATA_HANDLER_1 > &b)
Definition: ad.hpp:2596
ApplyResultT< F, T... > eval(F f, const IOResult< T > &... rs)
Evaluates a function f using values of the given IOResults as arguments, assumes all IOResults are su...
Definition: io.h:448
int size(Comm comm)
Return the size of the given communicator.
Definition: miompi.cpp:75
A collection of classes to simplify handling of matrix shapes in meta programming.
Definition: models/abm/analyze_result.h:30
FP get_infections_relative(const SimulationNode< FP, Sim > &node, FP t, const Eigen::Ref< const Eigen::VectorX< FP >> &y)
get the percantage of infected people of the total population in the node If dynamic NPIs are enabled...
Definition: metapopulation_mobility_instant.h:484
boost::outcome_v2::in_place_type_t< T > Tag
Type that is used for overload resolution.
Definition: io.h:407
auto i
Definition: io.h:809
details::ApplyResultT< F, T... > apply(IOContext &io, F f, const IOResult< T > &... rs)
Evaluate a function with zero or more unpacked IOResults as arguments.
Definition: io.h:481
void advance_model(abm::TimePoint t, abm::TimeSpan dt, ABMSimulationNode< History... > &node)
Node functor for abm graph simulation.
Definition: graph_abm_mobility.h:178
requires(!std::is_trivial_v< T >) void BinarySerializerObject
Definition: binary_serializer.h:333
void calculate_mobility_returns(Eigen::Ref< typename TimeSeries< FP >::Vector > mobile_population, const Sim &sim, Eigen::Ref< const typename TimeSeries< FP >::Vector > total, FP t, FP dt)
adjust number of people that changed node when they return according to the model.
Definition: metapopulation_mobility_instant.h:462
void log(LogLevel level, spdlog::string_view_t fmt, const Args &... args)
Definition: logging.h:128
auto slice(V &&v, Seq< Eigen::Index > elems)
take a regular slice of a row or column vector.
Definition: eigen_util.h:107
GraphSimulation< FP, Graph< SimulationNode< FP, Sim >, MobilityEdge< FP > >, FP, FP, void(*)(FP, FP, mio::MobilityEdge< FP > &, mio::SimulationNode< FP, Sim > &, mio::SimulationNode< FP, Sim > &), void(*)(FP, FP, mio::SimulationNode< FP, Sim > &)> make_mobility_sim(FP t0, FP dt, const Graph< SimulationNode< FP, Sim >, MobilityEdge< FP >> &graph)
create a mobility-based simulation.
Definition: metapopulation_mobility_instant.h:667
void log_debug(spdlog::string_view_t fmt, const Args &... args)
Definition: logging.h:118
void unused(T &&...)
Does nothing, can be used to mark variables as not used.
Definition: compiler_diagnostics.h:30
auto make_no_mobility_sim(FP t0, Graph< SimulationNode< FP, Sim >, MobilityEdge< FP >> &graph)
Create a graph simulation without mobility.
Definition: metapopulation_mobility_instant.h:700
void apply_mobility(abm::TimePoint t, abm::TimeSpan, ABMMobilityEdge< History... > &edge, ABMSimulationNode< History... > &node_from, ABMSimulationNode< History... > &node_to)
Edge functor for abm graph simulation.
Definition: graph_abm_mobility.h:164
auto get_mobility_factors(const SimulationNode< FP, Sim > &node, FP t, const Eigen::Ref< const Eigen::VectorX< FP >> &y)
Get an additional mobility factor.
Definition: metapopulation_mobility_instant.h:509
boost::outcome_v2::unchecked< T, IOStatus > IOResult
Value-or-error type for operations that return a value but can fail.
Definition: io.h:353
void log_info(spdlog::string_view_t fmt, const Args &... args)
Definition: logging.h:94
void test_commuters(SimulationNode< FP, Sim > &node, Eigen::Ref< Eigen::VectorX< FP >> mobile_population, FP time)
Test persons when moving from their source node.
Definition: metapopulation_mobility_instant.h:533
Definition: io.h:94