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...> SimulationNode(Args&&... args)
47  : m_simulation(std::forward<Args>(args)...)
48  , m_last_state(m_simulation.get_result().get_last_value())
49  , m_t0(m_simulation.get_result().get_last_time())
50  {
51  }
52 
57  decltype(auto) get_result() const
58  {
59  return m_simulation.get_result();
60  }
61  decltype(auto) get_result()
62  {
63  return m_simulation.get_result();
64  }
72  {
73  return m_simulation;
74  }
75  const Sim& get_simulation() const
76  {
77  return m_simulation;
78  }
81  Eigen::Ref<const Eigen::VectorX<FP>> get_last_state() const
82  {
83  return m_last_state;
84  }
85 
86  FP get_t0() const
87  {
88  return m_t0;
89  }
90 
91  void advance(FP t, FP dt)
92  {
93  m_simulation.advance(t + dt);
94  m_last_state = m_simulation.get_result().get_last_value();
95  }
96 
97 private:
99  Eigen::VectorX<FP> m_last_state;
100  FP m_t0;
101 };
102 
106 template <typename FP>
108 
113 template <typename FP>
115 
120 template <typename FP>
122 {
123 public:
129  : m_coefficients(coeffs)
131  {
132  }
133 
138  MobilityParameters(const Eigen::VectorX<FP>& coeffs)
141  {
142  }
143 
154  MobilityParameters(const MobilityCoefficientGroup<FP>& coeffs, const std::vector<std::vector<size_t>>& save_indices)
155  : m_coefficients(coeffs)
156  , m_saved_compartment_indices(save_indices)
157  {
158  }
159 
169  MobilityParameters(const Eigen::VectorX<FP>& coeffs, const std::vector<std::vector<size_t>>& save_indices)
171  , m_saved_compartment_indices(save_indices)
172  {
173  }
174 
179  bool operator==(const MobilityParameters& other) const
180  {
181  return m_coefficients == other.m_coefficients;
182  }
183  bool operator!=(const MobilityParameters& other) const
184  {
185  return m_coefficients != other.m_coefficients;
186  }
188 
199  {
200  return m_coefficients;
201  }
203  {
204  return m_coefficients;
205  }
210  {
211  m_coefficients = coeffs;
212  }
213 
224  const auto& get_save_indices() const
225  {
227  }
228 
238  {
239  return m_dynamic_npis;
240  }
242  {
243  return m_dynamic_npis;
244  }
249  {
250  m_dynamic_npis = v;
251  }
258  template <class IOContext>
259  void serialize(IOContext& io) const
260  {
261  auto obj = io.create_object("MobilityParameters");
262  obj.add_element("Coefficients", m_coefficients);
263  obj.add_element("DynamicNPIs", m_dynamic_npis);
264  }
265 
270  template <class IOContext>
272  {
273  auto obj = io.expect_object("MobilityParameters");
274  auto c = obj.expect_element("Coefficients", Tag<MobilityCoefficientGroup<FP>>{});
275  auto d = obj.expect_element("DynamicNPIs", Tag<DynamicNPIs<FP>>{});
276  return apply(
277  io,
278  [](auto&& c_, auto&& d_) {
279  MobilityParameters params(c_);
280  params.set_dynamic_npis_infected(d_);
281  return params;
282  },
283  c, d);
284  }
285 
286 private:
287  MobilityCoefficientGroup<FP> m_coefficients; //one per group and compartment
289  std::vector<std::vector<size_t>> m_saved_compartment_indices; // groups of indices from compartments to save
290 };
291 
295 template <typename FP>
297 {
298 public:
304  : m_parameters(params)
305  , m_mobile_population(params.get_coefficients().get_shape().rows())
306  , m_return_times(0)
308  , m_saved_compartment_indices(params.get_save_indices())
310  {
311  }
312 
319  MobilityEdge(const Eigen::VectorX<FP>& coeffs)
320  : m_parameters(coeffs)
321  , m_mobile_population(coeffs.rows())
322  , m_return_times(0)
326  {
327  }
328 
337  MobilityEdge(const MobilityParameters<FP>& params, const std::vector<std::vector<size_t>>& save_indices)
338  : m_parameters(params)
339  , m_mobile_population(params.get_coefficients().get_shape().rows())
340  , m_return_times(0)
342  , m_saved_compartment_indices(save_indices)
344  {
345  }
346 
355  MobilityEdge(const Eigen::VectorX<FP>& coeffs, const std::vector<std::vector<size_t>>& save_indices)
356  : m_parameters(coeffs)
357  , m_mobile_population(coeffs.rows())
358  , m_return_times(0)
360  , m_saved_compartment_indices(save_indices)
362  {
363  }
364 
369  {
370  return m_parameters;
371  }
372 
380  {
381  return m_mobility_results;
382  }
384  {
385  return m_mobility_results;
386  }
399  template <class Sim>
400  void apply_mobility(FP t, FP dt, SimulationNode<FP, Sim>& node_from, SimulationNode<FP, Sim>& node_to);
401 
402 private:
407  FP m_t_last_dynamic_npi_check = -std::numeric_limits<FP>::infinity();
408  std::pair<FP, SimulationTime<FP>> m_dynamic_npi = {-std::numeric_limits<FP>::max(), SimulationTime<FP>(0)};
409  std::vector<std::vector<size_t>> m_saved_compartment_indices; // groups of indices from compartments to save
410  TimeSeries<FP> m_mobility_results; // save results from edges + entry for the total number of commuters
411 
420  void add_mobility_result_time_point(const FP t);
421 };
422 
423 template <typename FP>
425 {
426  const size_t save_indices_size = this->m_saved_compartment_indices.size();
427  if (save_indices_size > 0) {
428  const auto& last_value = m_mobile_population.get_last_value();
429 
430  Eigen::VectorX<FP> condensed_values = Eigen::VectorX<FP>::Zero(save_indices_size + 1);
431 
432  // sum up the values of m_saved_compartment_indices for each group (e.g. Age groups)
433  for (size_t i = 0; i < save_indices_size; ++i) {
434  FP sum = 0.0;
435  for (auto index : this->m_saved_compartment_indices[i]) {
436  sum += last_value[index];
437  }
438  condensed_values[i] = sum;
439  }
440 
441  // the last value is the sum of commuters
442  condensed_values[save_indices_size] = m_mobile_population.get_last_value().sum();
443 
444  // Move the condensed values to the m_mobility_results time series
445  m_mobility_results.add_time_point(t, std::move(condensed_values));
446  }
447 }
448 
460 template <typename FP, IsCompartmentalModelSimulation<FP> Sim>
461 void calculate_mobility_returns(Eigen::Ref<typename TimeSeries<FP>::Vector> mobile_population, const Sim& sim,
462  Eigen::Ref<const typename TimeSeries<FP>::Vector> total, FP t, FP dt)
463 {
464  auto y0 = mobile_population.eval();
465  auto y1 = mobile_population;
467  [&](auto&& y, auto&& t_, auto&& dydt) {
468  sim.get_model().get_derivatives(total, y, t_, dydt);
469  },
470  y0, t, dt, y1);
471 }
472 
482 template <typename FP, class Sim>
483 FP get_infections_relative(const SimulationNode<FP, Sim>& node, FP t, const Eigen::Ref<const Eigen::VectorX<FP>>& y)
484 {
485  if constexpr (requires { get_infections_relative<FP>(node.get_simulation(), t, y); }) {
486  return get_infections_relative<FP>(node.get_simulation(), t, y);
487  }
488  else {
489  mio::unused(node, t, y);
490  mio::log_debug("get_infections_relative called without specialization for this simulation type. "
491  "Implement an overload in your model if you intend to use dynamic NPIs.");
492  return FP{0};
493  }
494 }
495 
507 template <typename FP, class Sim>
508 auto get_mobility_factors(const SimulationNode<FP, Sim>& node, FP t, const Eigen::Ref<const Eigen::VectorX<FP>>& y)
509 {
510  if constexpr (requires { get_mobility_factors<FP>(node.get_simulation(), t, y); }) {
511  return get_mobility_factors<FP>(node.get_simulation(), t, y);
512  }
513  else {
514  mio::unused(node, t);
515  mio::log_debug("get_mobility_factors called without specialization for this simulation type. "
516  "Using default mobility factor (1.0) for all compartments.");
517  return Eigen::VectorX<FP>::Ones(y.rows());
518  }
519 }
520 
531 template <typename FP, class Sim>
532 void test_commuters(SimulationNode<FP, Sim>& node, Eigen::Ref<Eigen::VectorX<FP>> mobile_population, FP time)
533 {
534  if constexpr (requires { test_commuters<FP>(node.get_simulation(), mobile_population, time); }) {
535  test_commuters<FP>(node.get_simulation(), mobile_population, time);
536  }
537  else {
538  mio::unused(node, mobile_population, time);
539  mio::log_debug("test_commuters called without specialization for this simulation type. "
540  "Implement an overload in your model if you intend to use commuter testing.");
541  }
542 }
543 
544 template <typename FP>
545 template <class Sim>
547  SimulationNode<FP, Sim>& node_to)
548 {
549  auto& dyn_npis = m_parameters.get_dynamic_npis_infected();
550  if (dyn_npis.get_thresholds().size() > 0) {
551  auto inf_rel =
552  get_infections_relative<FP>(node_from, t, node_from.get_last_state()) * dyn_npis.get_base_value();
553  auto exceeded_threshold = dyn_npis.get_max_exceeded_threshold(inf_rel);
554  const bool npi_expired = floating_point_greater_equal(t, FP(m_dynamic_npi.second), 1e-10);
555  if (exceeded_threshold != dyn_npis.get_thresholds().end() &&
556  (exceeded_threshold->first > m_dynamic_npi.first || npi_expired)) {
557  //old NPI was weaker or is expired
558  auto t_end = SimulationTime<FP>(t + dyn_npis.get_duration().get());
559  m_dynamic_npi = std::make_pair(exceeded_threshold->first, t_end);
560  implement_dynamic_npis<FP>(m_parameters.get_coefficients(), exceeded_threshold->second,
561  SimulationTime<FP>(t), t_end, [this](auto& g) {
562  return make_mobility_damping_vector<FP>(
563  m_parameters.get_coefficients().get_shape(), g);
564  });
565  }
566  }
567 
568  //returns
569  for (Eigen::Index i = m_return_times.get_num_time_points() - 1; i >= 0; --i) {
570  if (m_return_times.get_time(i) <= t) {
571  auto v0 = find_value_reverse<FP>(node_to.get_result(), m_mobile_population.get_time(i), 1e-10, 1e-10);
572  assert(v0 != node_to.get_result().rend() && "unexpected error.");
573  calculate_mobility_returns<FP>(m_mobile_population[i], node_to.get_simulation(), *v0,
574  m_mobile_population.get_time(i), dt);
575 
576  //the lower-order return calculation may in rare cases produce negative compartments,
577  //especially at the beginning of the simulation.
578  //fix by subtracting the supernumerous returns from the biggest compartment of the age group.
579  Eigen::VectorX<FP> remaining_after_return =
580  (node_to.get_result().get_last_value() - m_mobile_population[i]).eval();
581  for (Eigen::Index j = 0; j < node_to.get_result().get_last_value().size(); ++j) {
582  if (remaining_after_return(j) < 0) {
583  auto num_comparts = (Eigen::Index)Sim::Model::Compartments::Count;
584  auto group = Eigen::Index(j / num_comparts);
585  auto compart = j % num_comparts;
586  log(remaining_after_return(j) < -1e-3 ? LogLevel::warn : LogLevel::info,
587  "Underflow during mobility returns at time {}, compartment {}, age group {}: {}", t, compart,
588  group, remaining_after_return(j));
589  Eigen::Index max_index;
590  slice(remaining_after_return, {group * num_comparts, num_comparts}).maxCoeff(&max_index);
591  log_info("Transferring to compartment {}", max_index);
592  max_index += group * num_comparts;
593  m_mobile_population[i](max_index) -= remaining_after_return(j);
594  m_mobile_population[i](j) += remaining_after_return(j);
595  }
596  }
597  node_from.get_result().get_last_value() += m_mobile_population[i];
598  node_to.get_result().get_last_value() -= m_mobile_population[i];
599  add_mobility_result_time_point(t);
600  m_mobile_population.remove_time_point(i);
601  m_return_times.remove_time_point(i);
602  }
603  }
604 
605  if (!m_return_mobile_population &&
606  (m_parameters.get_coefficients().get_matrix_at(SimulationTime<FP>(t)).array() > 0.0).any()) {
607  //normal daily mobility
608  m_mobile_population.add_time_point(
609  t, (node_from.get_last_state().array() *
610  m_parameters.get_coefficients().get_matrix_at(SimulationTime<FP>(t)).array() *
611  get_mobility_factors<FP>(node_from, t, node_from.get_last_state()).array())
612  .matrix());
613  m_return_times.add_time_point(t + dt);
614 
615  test_commuters<FP>(node_from, m_mobile_population.get_last_value(), t);
616 
617  node_to.get_result().get_last_value() += m_mobile_population.get_last_value();
618  node_from.get_result().get_last_value() -= m_mobile_population.get_last_value();
619 
620  add_mobility_result_time_point(t);
621  }
622  m_return_mobile_population = !m_return_mobile_population;
623 }
624 
629 template <typename FP, class Sim>
630 void advance_model(FP t, FP dt, SimulationNode<FP, Sim>& node)
631 {
632  node.advance(t, dt);
633 }
634 
639 template <typename FP, class Sim>
640 void apply_mobility(FP t, FP dt, MobilityEdge<FP>& mobilityEdge, SimulationNode<FP, Sim>& node_from,
641  SimulationNode<FP, Sim>& node_to)
642 {
643  mobilityEdge.apply_mobility(t, dt, node_from, node_to);
644 }
645 
656 template <typename FP, class Sim>
657 GraphSimulation<FP, Graph<SimulationNode<FP, Sim>, MobilityEdge<FP>>, FP, FP,
659  void (*)(FP, FP, mio::SimulationNode<FP, Sim>&)>
661 {
662  return make_graph_sim<FP>(
663  t0, dt, graph, static_cast<void (*)(FP, FP, SimulationNode<FP, Sim>&)>(&advance_model<FP, Sim>),
664  static_cast<void (*)(FP, FP, MobilityEdge<FP>&, SimulationNode<FP, Sim>&, SimulationNode<FP, Sim>&)>(
665  &apply_mobility<FP>));
666 }
667 
668 template <typename FP, class Sim>
669 GraphSimulation<FP, Graph<SimulationNode<FP, Sim>, MobilityEdge<FP>>, FP, FP,
671  void (*)(FP, FP, mio::SimulationNode<FP, Sim>&)>
673 {
674  return make_graph_sim<FP>(
675  t0, dt, std::move(graph), static_cast<void (*)(FP, FP, SimulationNode<FP, Sim>&)>(&advance_model<FP, Sim>),
676  static_cast<void (*)(FP, FP, MobilityEdge<FP>&, SimulationNode<FP, Sim>&, SimulationNode<FP, Sim>&)>(
677  &apply_mobility<FP>));
678 }
679 
692 template <typename FP, class Sim>
694 {
698  void (*)(FP, FP, mio::SimulationNode<FP, Sim>&)>;
699  return GraphSim(t0, std::numeric_limits<FP>::infinity(), graph, &advance_model<FP, Sim>,
701 }
702 
703 template <typename FP, class Sim>
705 {
709  void (*)(FP, FP, mio::SimulationNode<FP, Sim>&)>;
710  return GraphSim(t0, std::numeric_limits<FP>::infinity(), std::move(graph), &advance_model<FP, Sim>,
712 }
713 
716 } // namespace mio
717 
718 #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 * (B - 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:37
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:148
represents the mobility between two nodes.
Definition: metapopulation_mobility_instant.h:297
std::pair< FP, SimulationTime< FP > > m_dynamic_npi
Definition: metapopulation_mobility_instant.h:408
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:337
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:355
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:379
std::vector< std::vector< size_t > > m_saved_compartment_indices
Definition: metapopulation_mobility_instant.h:409
MobilityParameters< FP > m_parameters
Definition: metapopulation_mobility_instant.h:403
MobilityEdge(const MobilityParameters< FP > &params)
Create edge with coefficients.
Definition: metapopulation_mobility_instant.h:303
FP m_t_last_dynamic_npi_check
Definition: metapopulation_mobility_instant.h:407
const MobilityParameters< FP > & get_parameters() const
get the mobility parameters.
Definition: metapopulation_mobility_instant.h:368
TimeSeries< FP > m_mobility_results
Definition: metapopulation_mobility_instant.h:410
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:424
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:546
MobilityEdge(const Eigen::VectorX< FP > &coeffs)
Create edge with coefficients.
Definition: metapopulation_mobility_instant.h:319
TimeSeries< FP > m_mobile_population
Definition: metapopulation_mobility_instant.h:404
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:383
TimeSeries< FP > m_return_times
Definition: metapopulation_mobility_instant.h:405
bool m_return_mobile_population
Definition: metapopulation_mobility_instant.h:406
parameters that influence mobility.
Definition: metapopulation_mobility_instant.h:122
bool operator!=(const MobilityParameters &other) const
Definition: metapopulation_mobility_instant.h:183
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:154
bool operator==(const MobilityParameters &other) const
equality comparison operators
Definition: metapopulation_mobility_instant.h:179
DynamicNPIs< FP > & get_dynamic_npis_infected()
Get/Setthe mobility coefficients.
Definition: metapopulation_mobility_instant.h:241
const MobilityCoefficientGroup< FP > & get_coefficients() const
Get/Setthe mobility coefficients.
Definition: metapopulation_mobility_instant.h:198
void serialize(IOContext &io) const
serialize this.
Definition: metapopulation_mobility_instant.h:259
void set_coefficients(const MobilityCoefficientGroup< FP > &coeffs)
Definition: metapopulation_mobility_instant.h:209
void set_dynamic_npis_infected(const DynamicNPIs< FP > &v)
Definition: metapopulation_mobility_instant.h:248
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:169
static IOResult< MobilityParameters > deserialize(IOContext &io)
deserialize an object of this class.
Definition: metapopulation_mobility_instant.h:271
MobilityParameters(const Eigen::VectorX< FP > &coeffs)
constructor from mobility coefficients.
Definition: metapopulation_mobility_instant.h:138
MobilityCoefficientGroup< FP > & get_coefficients()
Get/Setthe mobility coefficients.
Definition: metapopulation_mobility_instant.h:202
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:237
std::vector< std::vector< size_t > > m_saved_compartment_indices
Definition: metapopulation_mobility_instant.h:289
MobilityParameters(const MobilityCoefficientGroup< FP > &coeffs)
constructor from mobility coefficients.
Definition: metapopulation_mobility_instant.h:128
MobilityCoefficientGroup< FP > m_coefficients
Definition: metapopulation_mobility_instant.h:287
const auto & get_save_indices() const
Get the indices of compartments to be saved during mobility.
Definition: metapopulation_mobility_instant.h:224
DynamicNPIs< FP > m_dynamic_npis
Definition: metapopulation_mobility_instant.h:288
represents the simulation in one node of the graph.
Definition: metapopulation_mobility_instant.h:41
Sim m_simulation
Definition: metapopulation_mobility_instant.h:98
Sim Simulation
Definition: metapopulation_mobility_instant.h:43
requires std::is_constructible_v< Sim, Args... > SimulationNode(Args &&... args)
Definition: metapopulation_mobility_instant.h:46
Eigen::Ref< const Eigen::VectorX< FP > > get_last_state() const
Definition: metapopulation_mobility_instant.h:81
decltype(auto) get_result() const
get the result of the simulation in this node.
Definition: metapopulation_mobility_instant.h:57
Eigen::VectorX< FP > m_last_state
Definition: metapopulation_mobility_instant.h:99
FP get_t0() const
Definition: metapopulation_mobility_instant.h:86
FP m_t0
Definition: metapopulation_mobility_instant.h:100
void advance(FP t, FP dt)
Definition: metapopulation_mobility_instant.h:91
Sim & get_simulation()
get the the simulation in this node.
Definition: metapopulation_mobility_instant.h:71
const Sim & get_simulation() const
get the the simulation in this node.
Definition: metapopulation_mobility_instant.h:75
Typesafe wrapper for a floating-point simulation time value (in days).
Definition: damping.h:78
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:449
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 percentage of infected people of the total population in the node.
Definition: metapopulation_mobility_instant.h:483
boost::outcome_v2::in_place_type_t< T > Tag
Type that is used for overload resolution.
Definition: io.h:408
auto i
Definition: io.h:810
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:482
void advance_model(abm::TimePoint t, abm::TimeSpan dt, ABMSimulationNode< History... > &node)
Node functor for abm graph simulation.
Definition: graph_abm_mobility.h:171
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:461
void log(LogLevel level, spdlog::string_view_t fmt, const Args &... args)
Definition: logging.h:142
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:660
void log_debug(spdlog::string_view_t fmt, const Args &... args)
Definition: logging.h:132
bool floating_point_greater_equal(FP v1, FP v2, FP abs_tol=0, FP rel_tol=std::numeric_limits< FP >::min())
compare two floating point values with tolerances.
Definition: floating_point.h:136
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:693
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:157
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:508
boost::outcome_v2::unchecked< T, IOStatus > IOResult
Value-or-error type for operations that return a value but can fail.
Definition: io.h:354
void log_info(spdlog::string_view_t fmt, const Args &... args)
Definition: logging.h:108
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:532
Definition: io.h:95