-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathtest_odesecir.cpp
More file actions
executable file
·1786 lines (1494 loc) · 106 KB
/
test_odesecir.cpp
File metadata and controls
executable file
·1786 lines (1494 loc) · 106 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (C) 2020-2026 MEmilio
*
* Authors: Daniel Abele, Martin J. Kuehn
*
* Contact: Martin J. Kuehn <[email protected]>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "distributions_helpers.h"
#include "load_test_data.h"
#include "matchers.h"
#include "temp_file_register.h"
#include "ode_secir/model.h"
#include "ode_secir/parameter_space.h"
#include "ode_secir/parameters.h"
#include "ode_secir/parameters_io.h"
#include "memilio/io/parameters_io.h"
#include "memilio/data/analyze_result.h"
#include "memilio/math/adapt_rk.h"
#include "memilio/geography/regions.h"
#include "utils.h"
#include <numbers>
#include <gtest/gtest.h>
TEST(TestOdeSecir, compareWithPreviousRun)
{
/*
A similar test is implemented in python (without custom integrator) to compare the results of both simulations.
If this test is change the corresponding python test needs to be changed aswell (also updating the data file).
*/
double t0 = 0;
double tmax = 50;
double dt = 0.3;
double cont_freq = 10;
double nb_total_t0 = 10000, nb_exp_t0 = 100, nb_inf_t0 = 50, nb_car_t0 = 50, nb_hosp_t0 = 20, nb_icu_t0 = 10,
nb_rec_t0 = 10, nb_dead_t0 = 0;
mio::osecir::Model<double> model(1);
model.parameters.set<mio::osecir::StartDay<double>>(60);
model.parameters.set<mio::osecir::Seasonality<double>>(0.2);
model.parameters.get<mio::osecir::TimeExposed<double>>()[(mio::AgeGroup)0] = 3.2;
model.parameters.get<mio::osecir::TimeInfectedNoSymptoms<double>>()[(mio::AgeGroup)0] = 2.0;
model.parameters.get<mio::osecir::TimeInfectedSymptoms<double>>()[(mio::AgeGroup)0] = 5.8;
model.parameters.get<mio::osecir::TimeInfectedSevere<double>>()[(mio::AgeGroup)0] = 9.5;
model.parameters.get<mio::osecir::TimeInfectedCritical<double>>()[(mio::AgeGroup)0] = 7.1;
mio::ContactMatrixGroup<double>& contact_matrix = model.parameters.get<mio::osecir::ContactPatterns<double>>();
contact_matrix[0] = mio::ContactMatrix<double>(Eigen::MatrixXd::Constant(1, 1, cont_freq));
contact_matrix[0].add_damping(0.7, mio::SimulationTime<double>(30.));
model.populations.set_total(nb_total_t0);
model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::Exposed}] = nb_exp_t0;
model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::InfectedNoSymptoms}] = nb_car_t0;
model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::InfectedNoSymptomsConfirmed}] = 0;
model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::InfectedSymptoms}] = nb_inf_t0;
model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::InfectedSymptomsConfirmed}] = 0;
model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::InfectedSevere}] = nb_hosp_t0;
model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::InfectedCritical}] = nb_icu_t0;
model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::Recovered}] = nb_rec_t0;
model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::Dead}] = nb_dead_t0;
model.populations.set_difference_from_total({mio::AgeGroup(0), mio::osecir::InfectionState::Susceptible},
nb_total_t0);
model.parameters.get<mio::osecir::TransmissionProbabilityOnContact<double>>()[(mio::AgeGroup)0] = 0.05;
model.parameters.get<mio::osecir::RelativeTransmissionNoSymptoms<double>>()[(mio::AgeGroup)0] = 0.7;
model.parameters.get<mio::osecir::RecoveredPerInfectedNoSymptoms<double>>()[(mio::AgeGroup)0] = 0.09;
model.parameters.get<mio::osecir::RiskOfInfectionFromSymptomatic<double>>()[(mio::AgeGroup)0] = 0.25;
model.parameters.get<mio::osecir::MaxRiskOfInfectionFromSymptomatic<double>>()[(mio::AgeGroup)0] = 0.45;
model.parameters.get<mio::osecir::TestAndTraceCapacity<double>>() = 35;
model.parameters.get<mio::osecir::SeverePerInfectedSymptoms<double>>()[(mio::AgeGroup)0] = 0.2;
model.parameters.get<mio::osecir::CriticalPerSevere<double>>()[(mio::AgeGroup)0] = 0.3;
model.parameters.get<mio::osecir::DeathsPerCritical<double>>()[(mio::AgeGroup)0] = 0.3;
model.apply_constraints();
auto integrator = std::make_unique<mio::RKIntegratorCore<double>>();
integrator->set_dt_min(0.3);
integrator->set_dt_max(1.0);
integrator->set_rel_tolerance(1e-3);
integrator->set_abs_tolerance(1e-1);
mio::TimeSeries<double> secihurd =
mio::simulate<double, mio::osecir::Model<double>>(t0, tmax, dt, model, std::move(integrator));
auto compare = load_test_data_csv<double>("secihurd-compare.csv");
ASSERT_EQ(compare.size(), static_cast<size_t>(secihurd.get_num_time_points()));
for (size_t i = 0; i < compare.size(); i++) {
ASSERT_EQ(compare[i].size(), static_cast<size_t>(secihurd.get_num_elements()) + 1) << "at row " << i;
EXPECT_NEAR(secihurd.get_time(i), compare[i][0], 1e-10) << "at row " << i;
for (size_t j = 1; j < compare[i].size(); j++) {
EXPECT_NEAR(secihurd.get_value(i)[j - 1], compare[i][j], 1e-10) << " at row " << i;
}
}
}
TEST(TestOdeSecir, simulateDefault)
{
double t0 = 0;
double tmax = 1;
double dt = 0.1;
mio::osecir::Model<double> model(1);
mio::TimeSeries<double> result = mio::simulate<double>(t0, tmax, dt, model);
EXPECT_NEAR(result.get_last_time(), tmax, 1e-10);
}
TEST(TestOdeSecir, checkPopulationConservation)
{
double t0 = 0;
double tmax = 50;
double dt = 0.1;
double cont_freq = 10;
double nb_total_t0 = 10000;
mio::osecir::Model<double> model(1);
model.parameters.get<mio::osecir::TestAndTraceCapacity<double>>() = 35;
model.parameters.get<mio::osecir::TimeExposed<double>>()[(mio::AgeGroup)0] = 3.2;
model.parameters.get<mio::osecir::TimeInfectedNoSymptoms<double>>()[(mio::AgeGroup)0] = 2.0;
model.parameters.get<mio::osecir::TimeInfectedSymptoms<double>>()[(mio::AgeGroup)0] = 5.8;
model.parameters.get<mio::osecir::TimeInfectedSevere<double>>()[(mio::AgeGroup)0] = 9.5;
model.parameters.get<mio::osecir::TimeInfectedCritical<double>>()[(mio::AgeGroup)0] = 7.1;
mio::ContactMatrixGroup<double>& contact_matrix = model.parameters.get<mio::osecir::ContactPatterns<double>>();
contact_matrix[0] = mio::ContactMatrix<double>(Eigen::MatrixXd::Constant(1, 1, cont_freq));
contact_matrix[0].add_damping(0.7, mio::SimulationTime<double>(30.));
model.populations.set_total(nb_total_t0);
model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::Exposed}] = 10;
model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::InfectedNoSymptoms}] = 10;
model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::InfectedNoSymptomsConfirmed}] = 0;
model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::InfectedSymptoms}] = 10;
model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::InfectedSymptomsConfirmed}] = 0;
model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::InfectedSevere}] = 10;
model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::InfectedCritical}] = 10;
model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::Recovered}] = 10;
model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::Dead}] = 10;
model.populations.set_difference_from_total({mio::AgeGroup(0), mio::osecir::InfectionState::Susceptible},
nb_total_t0);
model.parameters.get<mio::osecir::TransmissionProbabilityOnContact<double>>()[(mio::AgeGroup)0] = 0.05;
model.parameters.get<mio::osecir::RelativeTransmissionNoSymptoms<double>>()[(mio::AgeGroup)0] = 1;
model.parameters.get<mio::osecir::RecoveredPerInfectedNoSymptoms<double>>()[(mio::AgeGroup)0] = 0.09;
model.parameters.get<mio::osecir::RiskOfInfectionFromSymptomatic<double>>()[(mio::AgeGroup)0] = 0.25;
model.parameters.get<mio::osecir::MaxRiskOfInfectionFromSymptomatic<double>>()[(mio::AgeGroup)0] = 0.45;
model.parameters.get<mio::osecir::SeverePerInfectedSymptoms<double>>()[(mio::AgeGroup)0] = 0.2;
model.parameters.get<mio::osecir::CriticalPerSevere<double>>()[(mio::AgeGroup)0] = 0.25;
model.parameters.get<mio::osecir::DeathsPerCritical<double>>()[(mio::AgeGroup)0] = 0.3;
model.apply_constraints();
mio::TimeSeries<double> secir = mio::simulate<double>(t0, tmax, dt, model);
double num_persons = 0.0;
for (auto i = 0; i < secir.get_last_value().size(); i++) {
num_persons += secir.get_last_value()[i];
}
EXPECT_NEAR(num_persons, nb_total_t0, 1e-10);
}
TEST(TestOdeSecir, testParamConstructors)
{
double cont_freq = 10;
double nb_total_t0 = 10000, nb_exp_t0 = 100, nb_inf_t0 = 54, nb_car_t0 = 50, nb_hosp_t0 = 20, nb_icu_t0 = 10,
nb_rec_t0 = 11, nb_dead_t0 = 0;
double icu_cap = 4444;
double start_day = 30, seasonality = 0.3;
mio::osecir::Model<double> model(1);
model.parameters.set<mio::osecir::ICUCapacity<double>>(icu_cap);
model.parameters.set<mio::osecir::StartDay<double>>(start_day);
model.parameters.set<mio::osecir::Seasonality<double>>(seasonality);
model.parameters.get<mio::osecir::TimeExposed<double>>()[(mio::AgeGroup)0] = 3.2;
model.parameters.get<mio::osecir::TimeInfectedNoSymptoms<double>>()[(mio::AgeGroup)0] = 2.0;
model.parameters.get<mio::osecir::TimeInfectedSymptoms<double>>()[(mio::AgeGroup)0] = 5;
model.parameters.get<mio::osecir::TimeInfectedSevere<double>>()[(mio::AgeGroup)0] = 10.;
model.parameters.get<mio::osecir::TimeInfectedCritical<double>>()[(mio::AgeGroup)0] = 8.;
model.populations.set_total(nb_total_t0);
model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::Exposed}] = nb_exp_t0;
model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::InfectedNoSymptoms}] = nb_car_t0;
model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::InfectedSymptoms}] = nb_inf_t0;
model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::InfectedSevere}] = nb_hosp_t0;
model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::InfectedCritical}] = nb_icu_t0;
model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::Recovered}] = nb_rec_t0;
model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::Dead}] = nb_dead_t0;
model.populations.set_difference_from_total({mio::AgeGroup(0), mio::osecir::InfectionState::Susceptible},
nb_total_t0);
model.parameters.get<mio::osecir::TransmissionProbabilityOnContact<double>>()[(mio::AgeGroup)0] = 0.05;
model.parameters.get<mio::osecir::RelativeTransmissionNoSymptoms<double>>()[(mio::AgeGroup)0] = 0.67;
model.parameters.get<mio::osecir::RecoveredPerInfectedNoSymptoms<double>>()[(mio::AgeGroup)0] = 0.09;
model.parameters.get<mio::osecir::RiskOfInfectionFromSymptomatic<double>>()[(mio::AgeGroup)0] = 0.25;
model.parameters.get<mio::osecir::SeverePerInfectedSymptoms<double>>()[(mio::AgeGroup)0] = 0.2;
model.parameters.get<mio::osecir::CriticalPerSevere<double>>()[(mio::AgeGroup)0] = 0.24;
model.parameters.get<mio::osecir::DeathsPerCritical<double>>()[(mio::AgeGroup)0] = 0.3;
mio::ContactMatrixGroup<double>& contact_matrix = model.parameters.get<mio::osecir::ContactPatterns<double>>();
contact_matrix[0] = mio::ContactMatrix<double>(Eigen::MatrixXd::Constant(1, 1, cont_freq));
contact_matrix[0].add_damping(0.7, mio::SimulationTime<double>(30.));
mio::osecir::Model<double> model2{model}; // copy constructor
EXPECT_EQ(model.parameters.get<mio::osecir::ICUCapacity<double>>(),
model2.parameters.get<mio::osecir::ICUCapacity<double>>());
EXPECT_EQ(model.parameters.get<mio::osecir::StartDay<double>>(),
model2.parameters.get<mio::osecir::StartDay<double>>());
EXPECT_EQ(model.parameters.get<mio::osecir::Seasonality<double>>(),
model2.parameters.get<mio::osecir::Seasonality<double>>());
EXPECT_EQ(model.populations.get_total(), model2.populations.get_total());
EXPECT_EQ((model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::Susceptible}]),
(model2.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::Susceptible}]));
EXPECT_EQ((model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::Exposed}]),
(model2.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::Exposed}]));
EXPECT_EQ((model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::InfectedNoSymptoms}]),
(model2.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::InfectedNoSymptoms}]));
EXPECT_EQ((model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::InfectedSymptoms}]),
(model2.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::InfectedSymptoms}]));
EXPECT_EQ((model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::InfectedSevere}]),
(model2.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::InfectedSevere}]));
EXPECT_EQ((model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::InfectedCritical}]),
(model2.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::InfectedCritical}]));
EXPECT_EQ((model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::Recovered}]),
(model2.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::Recovered}]));
EXPECT_EQ((model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::Dead}]),
(model2.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::Dead}]));
EXPECT_EQ(model.parameters.get<mio::osecir::TimeExposed<double>>()[(mio::AgeGroup)0],
model2.parameters.get<mio::osecir::TimeExposed<double>>()[(mio::AgeGroup)0]);
EXPECT_EQ(model.parameters.get<mio::osecir::TimeInfectedNoSymptoms<double>>()[(mio::AgeGroup)0],
model2.parameters.get<mio::osecir::TimeInfectedNoSymptoms<double>>()[(mio::AgeGroup)0]);
EXPECT_EQ(model.parameters.get<mio::osecir::TimeInfectedSymptoms<double>>()[(mio::AgeGroup)0],
model2.parameters.get<mio::osecir::TimeInfectedSymptoms<double>>()[(mio::AgeGroup)0]);
EXPECT_EQ(model.parameters.get<mio::osecir::TimeInfectedSevere<double>>()[(mio::AgeGroup)0],
model2.parameters.get<mio::osecir::TimeInfectedSevere<double>>()[(mio::AgeGroup)0]);
EXPECT_EQ(model.parameters.get<mio::osecir::TimeInfectedCritical<double>>()[(mio::AgeGroup)0],
model2.parameters.get<mio::osecir::TimeInfectedCritical<double>>()[(mio::AgeGroup)0]);
EXPECT_EQ(model.parameters.get<mio::osecir::ContactPatterns<double>>().get_cont_freq_mat(),
model2.parameters.get<mio::osecir::ContactPatterns<double>>().get_cont_freq_mat());
EXPECT_EQ(model.parameters.get<mio::osecir::TransmissionProbabilityOnContact<double>>()[(mio::AgeGroup)0],
model2.parameters.get<mio::osecir::TransmissionProbabilityOnContact<double>>()[(mio::AgeGroup)0]);
EXPECT_EQ(model.parameters.get<mio::osecir::RelativeTransmissionNoSymptoms<double>>()[(mio::AgeGroup)0],
model2.parameters.get<mio::osecir::RelativeTransmissionNoSymptoms<double>>()[(mio::AgeGroup)0]);
EXPECT_EQ(model.parameters.get<mio::osecir::RiskOfInfectionFromSymptomatic<double>>()[(mio::AgeGroup)0],
model2.parameters.get<mio::osecir::RiskOfInfectionFromSymptomatic<double>>()[(mio::AgeGroup)0]);
EXPECT_EQ(model.parameters.get<mio::osecir::RecoveredPerInfectedNoSymptoms<double>>()[(mio::AgeGroup)0],
model2.parameters.get<mio::osecir::RecoveredPerInfectedNoSymptoms<double>>()[(mio::AgeGroup)0]);
EXPECT_EQ(model.parameters.get<mio::osecir::SeverePerInfectedSymptoms<double>>()[(mio::AgeGroup)0],
model2.parameters.get<mio::osecir::SeverePerInfectedSymptoms<double>>()[(mio::AgeGroup)0]);
EXPECT_EQ(model.parameters.get<mio::osecir::CriticalPerSevere<double>>()[(mio::AgeGroup)0],
model2.parameters.get<mio::osecir::CriticalPerSevere<double>>()[(mio::AgeGroup)0]);
EXPECT_EQ(model.parameters.get<mio::osecir::DeathsPerCritical<double>>()[(mio::AgeGroup)0],
model2.parameters.get<mio::osecir::DeathsPerCritical<double>>()[(mio::AgeGroup)0]);
EXPECT_EQ(model.parameters.get<mio::osecir::ContactPatterns<double>>().get_cont_freq_mat(),
model2.parameters.get<mio::osecir::ContactPatterns<double>>().get_cont_freq_mat());
mio::osecir::Model<double> model3 = std::move(model2); // move constructor
EXPECT_EQ(model.parameters.get<mio::osecir::ICUCapacity<double>>(),
model3.parameters.get<mio::osecir::ICUCapacity<double>>());
EXPECT_EQ(model.parameters.get<mio::osecir::StartDay<double>>(),
model3.parameters.get<mio::osecir::StartDay<double>>());
EXPECT_EQ(model.parameters.get<mio::osecir::Seasonality<double>>(),
model3.parameters.get<mio::osecir::Seasonality<double>>());
EXPECT_EQ(model3.populations.get_total(), model.populations.get_total());
EXPECT_EQ((model3.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::Susceptible}]),
(model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::Susceptible}]));
EXPECT_EQ((model3.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::Exposed}]),
(model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::Exposed}]));
EXPECT_EQ((model3.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::InfectedNoSymptoms}]),
(model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::InfectedNoSymptoms}]));
EXPECT_EQ((model3.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::InfectedSymptoms}]),
(model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::InfectedSymptoms}]));
EXPECT_EQ((model3.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::InfectedSevere}]),
(model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::InfectedSevere}]));
EXPECT_EQ((model3.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::InfectedCritical}]),
(model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::InfectedCritical}]));
EXPECT_EQ((model3.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::Recovered}]),
(model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::Recovered}]));
EXPECT_EQ((model3.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::Dead}]),
(model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::Dead}]));
EXPECT_EQ(model3.parameters.get<mio::osecir::TimeExposed<double>>()[(mio::AgeGroup)0],
model.parameters.get<mio::osecir::TimeExposed<double>>()[(mio::AgeGroup)0]);
EXPECT_EQ(model3.parameters.get<mio::osecir::TimeInfectedNoSymptoms<double>>()[(mio::AgeGroup)0],
model.parameters.get<mio::osecir::TimeInfectedNoSymptoms<double>>()[(mio::AgeGroup)0]);
EXPECT_EQ(model3.parameters.get<mio::osecir::TimeInfectedSymptoms<double>>()[(mio::AgeGroup)0],
model.parameters.get<mio::osecir::TimeInfectedSymptoms<double>>()[(mio::AgeGroup)0]);
EXPECT_EQ(model3.parameters.get<mio::osecir::TimeInfectedSevere<double>>()[(mio::AgeGroup)0],
model.parameters.get<mio::osecir::TimeInfectedSevere<double>>()[(mio::AgeGroup)0]);
EXPECT_EQ(model3.parameters.get<mio::osecir::TimeInfectedCritical<double>>()[(mio::AgeGroup)0],
model.parameters.get<mio::osecir::TimeInfectedCritical<double>>()[(mio::AgeGroup)0]);
EXPECT_EQ(model3.parameters.get<mio::osecir::TransmissionProbabilityOnContact<double>>()[(mio::AgeGroup)0],
model.parameters.get<mio::osecir::TransmissionProbabilityOnContact<double>>()[(mio::AgeGroup)0]);
EXPECT_EQ(model3.parameters.get<mio::osecir::RelativeTransmissionNoSymptoms<double>>()[(mio::AgeGroup)0],
model.parameters.get<mio::osecir::RelativeTransmissionNoSymptoms<double>>()[(mio::AgeGroup)0]);
EXPECT_EQ(model3.parameters.get<mio::osecir::RiskOfInfectionFromSymptomatic<double>>()[(mio::AgeGroup)0],
model.parameters.get<mio::osecir::RiskOfInfectionFromSymptomatic<double>>()[(mio::AgeGroup)0]);
EXPECT_EQ(model3.parameters.get<mio::osecir::RecoveredPerInfectedNoSymptoms<double>>()[(mio::AgeGroup)0],
model.parameters.get<mio::osecir::RecoveredPerInfectedNoSymptoms<double>>()[(mio::AgeGroup)0]);
EXPECT_EQ(model3.parameters.get<mio::osecir::SeverePerInfectedSymptoms<double>>()[(mio::AgeGroup)0],
model.parameters.get<mio::osecir::SeverePerInfectedSymptoms<double>>()[(mio::AgeGroup)0]);
EXPECT_EQ(model3.parameters.get<mio::osecir::CriticalPerSevere<double>>()[(mio::AgeGroup)0],
model.parameters.get<mio::osecir::CriticalPerSevere<double>>()[(mio::AgeGroup)0]);
EXPECT_EQ(model3.parameters.get<mio::osecir::DeathsPerCritical<double>>()[(mio::AgeGroup)0],
model.parameters.get<mio::osecir::DeathsPerCritical<double>>()[(mio::AgeGroup)0]);
EXPECT_EQ(model.parameters.get<mio::osecir::ContactPatterns<double>>().get_cont_freq_mat(),
model3.parameters.get<mio::osecir::ContactPatterns<double>>().get_cont_freq_mat());
mio::osecir::Model<double> model4 = model3; // copy assignment constructor
EXPECT_EQ(model4.parameters.get<mio::osecir::ICUCapacity<double>>(),
model3.parameters.get<mio::osecir::ICUCapacity<double>>());
EXPECT_EQ(model4.parameters.get<mio::osecir::StartDay<double>>(),
model3.parameters.get<mio::osecir::StartDay<double>>());
EXPECT_EQ(model4.parameters.get<mio::osecir::Seasonality<double>>(),
model3.parameters.get<mio::osecir::Seasonality<double>>());
EXPECT_EQ(model3.populations.get_total(), model4.populations.get_total());
EXPECT_EQ((model3.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::Susceptible}]),
(model4.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::Susceptible}]));
EXPECT_EQ((model3.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::Exposed}]),
(model4.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::Exposed}]));
EXPECT_EQ((model3.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::InfectedNoSymptoms}]),
(model4.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::InfectedNoSymptoms}]));
EXPECT_EQ((model3.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::InfectedSymptoms}]),
(model4.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::InfectedSymptoms}]));
EXPECT_EQ((model3.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::InfectedSevere}]),
(model4.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::InfectedSevere}]));
EXPECT_EQ((model3.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::InfectedCritical}]),
(model4.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::InfectedCritical}]));
EXPECT_EQ((model3.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::Recovered}]),
(model4.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::Recovered}]));
EXPECT_EQ((model3.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::Dead}]),
(model4.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::Dead}]));
EXPECT_EQ(model3.parameters.get<mio::osecir::TimeExposed<double>>()[(mio::AgeGroup)0],
model4.parameters.get<mio::osecir::TimeExposed<double>>()[(mio::AgeGroup)0]);
EXPECT_EQ(model3.parameters.get<mio::osecir::TimeInfectedNoSymptoms<double>>()[(mio::AgeGroup)0],
model4.parameters.get<mio::osecir::TimeInfectedNoSymptoms<double>>()[(mio::AgeGroup)0]);
EXPECT_EQ(model3.parameters.get<mio::osecir::TimeInfectedSymptoms<double>>()[(mio::AgeGroup)0],
model4.parameters.get<mio::osecir::TimeInfectedSymptoms<double>>()[(mio::AgeGroup)0]);
EXPECT_EQ(model3.parameters.get<mio::osecir::TimeInfectedSevere<double>>()[(mio::AgeGroup)0],
model4.parameters.get<mio::osecir::TimeInfectedSevere<double>>()[(mio::AgeGroup)0]);
EXPECT_EQ(model3.parameters.get<mio::osecir::TimeInfectedCritical<double>>()[(mio::AgeGroup)0],
model4.parameters.get<mio::osecir::TimeInfectedCritical<double>>()[(mio::AgeGroup)0]);
EXPECT_EQ(model3.parameters.get<mio::osecir::TransmissionProbabilityOnContact<double>>()[(mio::AgeGroup)0],
model4.parameters.get<mio::osecir::TransmissionProbabilityOnContact<double>>()[(mio::AgeGroup)0]);
EXPECT_EQ(model3.parameters.get<mio::osecir::RelativeTransmissionNoSymptoms<double>>()[(mio::AgeGroup)0],
model4.parameters.get<mio::osecir::RelativeTransmissionNoSymptoms<double>>()[(mio::AgeGroup)0]);
EXPECT_EQ(model3.parameters.get<mio::osecir::RiskOfInfectionFromSymptomatic<double>>()[(mio::AgeGroup)0],
model4.parameters.get<mio::osecir::RiskOfInfectionFromSymptomatic<double>>()[(mio::AgeGroup)0]);
EXPECT_EQ(model3.parameters.get<mio::osecir::RecoveredPerInfectedNoSymptoms<double>>()[(mio::AgeGroup)0],
model4.parameters.get<mio::osecir::RecoveredPerInfectedNoSymptoms<double>>()[(mio::AgeGroup)0]);
EXPECT_EQ(model3.parameters.get<mio::osecir::SeverePerInfectedSymptoms<double>>()[(mio::AgeGroup)0],
model4.parameters.get<mio::osecir::SeverePerInfectedSymptoms<double>>()[(mio::AgeGroup)0]);
EXPECT_EQ(model3.parameters.get<mio::osecir::CriticalPerSevere<double>>()[(mio::AgeGroup)0],
model4.parameters.get<mio::osecir::CriticalPerSevere<double>>()[(mio::AgeGroup)0]);
EXPECT_EQ(model3.parameters.get<mio::osecir::DeathsPerCritical<double>>()[(mio::AgeGroup)0],
model4.parameters.get<mio::osecir::DeathsPerCritical<double>>()[(mio::AgeGroup)0]);
EXPECT_EQ(model4.parameters.get<mio::osecir::ContactPatterns<double>>().get_cont_freq_mat(),
model3.parameters.get<mio::osecir::ContactPatterns<double>>().get_cont_freq_mat());
mio::osecir::Model<double> model5 = std::move(model4); // move assignment constructor
EXPECT_EQ(model5.parameters.get<mio::osecir::ICUCapacity<double>>(),
model3.parameters.get<mio::osecir::ICUCapacity<double>>());
EXPECT_EQ(model5.parameters.get<mio::osecir::StartDay<double>>(),
model3.parameters.get<mio::osecir::StartDay<double>>());
EXPECT_EQ(model5.parameters.get<mio::osecir::Seasonality<double>>(),
model3.parameters.get<mio::osecir::Seasonality<double>>());
EXPECT_EQ(model5.populations.get_total(), model3.populations.get_total());
EXPECT_EQ((model5.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::Susceptible}]),
(model3.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::Susceptible}]));
EXPECT_EQ((model5.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::Exposed}]),
(model3.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::Exposed}]));
EXPECT_EQ((model5.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::InfectedNoSymptoms}]),
(model3.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::InfectedNoSymptoms}]));
EXPECT_EQ((model5.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::InfectedSymptoms}]),
(model3.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::InfectedSymptoms}]));
EXPECT_EQ((model5.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::InfectedSevere}]),
(model3.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::InfectedSevere}]));
EXPECT_EQ((model5.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::InfectedCritical}]),
(model3.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::InfectedCritical}]));
EXPECT_EQ((model5.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::Recovered}]),
(model3.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::Recovered}]));
EXPECT_EQ((model5.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::Dead}]),
(model3.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::Dead}]));
EXPECT_EQ(model5.parameters.get<mio::osecir::TimeExposed<double>>()[(mio::AgeGroup)0],
model3.parameters.get<mio::osecir::TimeExposed<double>>()[(mio::AgeGroup)0]);
EXPECT_EQ(model5.parameters.get<mio::osecir::TimeInfectedNoSymptoms<double>>()[(mio::AgeGroup)0],
model3.parameters.get<mio::osecir::TimeInfectedNoSymptoms<double>>()[(mio::AgeGroup)0]);
EXPECT_EQ(model5.parameters.get<mio::osecir::TimeInfectedSymptoms<double>>()[(mio::AgeGroup)0],
model3.parameters.get<mio::osecir::TimeInfectedSymptoms<double>>()[(mio::AgeGroup)0]);
EXPECT_EQ(model5.parameters.get<mio::osecir::TimeInfectedSevere<double>>()[(mio::AgeGroup)0],
model3.parameters.get<mio::osecir::TimeInfectedSevere<double>>()[(mio::AgeGroup)0]);
EXPECT_EQ(model5.parameters.get<mio::osecir::TimeInfectedCritical<double>>()[(mio::AgeGroup)0],
model3.parameters.get<mio::osecir::TimeInfectedCritical<double>>()[(mio::AgeGroup)0]);
EXPECT_EQ(model5.parameters.get<mio::osecir::TransmissionProbabilityOnContact<double>>()[(mio::AgeGroup)0],
model3.parameters.get<mio::osecir::TransmissionProbabilityOnContact<double>>()[(mio::AgeGroup)0]);
EXPECT_EQ(model5.parameters.get<mio::osecir::RelativeTransmissionNoSymptoms<double>>()[(mio::AgeGroup)0],
model3.parameters.get<mio::osecir::RelativeTransmissionNoSymptoms<double>>()[(mio::AgeGroup)0]);
EXPECT_EQ(model5.parameters.get<mio::osecir::RiskOfInfectionFromSymptomatic<double>>()[(mio::AgeGroup)0],
model3.parameters.get<mio::osecir::RiskOfInfectionFromSymptomatic<double>>()[(mio::AgeGroup)0]);
EXPECT_EQ(model5.parameters.get<mio::osecir::RecoveredPerInfectedNoSymptoms<double>>()[(mio::AgeGroup)0],
model3.parameters.get<mio::osecir::RecoveredPerInfectedNoSymptoms<double>>()[(mio::AgeGroup)0]);
EXPECT_EQ(model5.parameters.get<mio::osecir::SeverePerInfectedSymptoms<double>>()[(mio::AgeGroup)0],
model3.parameters.get<mio::osecir::SeverePerInfectedSymptoms<double>>()[(mio::AgeGroup)0]);
EXPECT_EQ(model5.parameters.get<mio::osecir::CriticalPerSevere<double>>()[(mio::AgeGroup)0],
model3.parameters.get<mio::osecir::CriticalPerSevere<double>>()[(mio::AgeGroup)0]);
EXPECT_EQ(model5.parameters.get<mio::osecir::DeathsPerCritical<double>>()[(mio::AgeGroup)0],
model3.parameters.get<mio::osecir::DeathsPerCritical<double>>()[(mio::AgeGroup)0]);
EXPECT_EQ(model5.parameters.get<mio::osecir::ContactPatterns<double>>().get_cont_freq_mat(),
model3.parameters.get<mio::osecir::ContactPatterns<double>>().get_cont_freq_mat());
}
TEST(TestOdeSecir, testSettersAndGetters)
{
std::vector<mio::UncertainValue<double>> vec;
for (int i = 1; i < 23; i++) {
mio::UncertainValue<double> val = mio::UncertainValue<double>(i);
val.set_distribution(mio::ParameterDistributionNormal(i, 10 * i, 5 * i, i / 10.0));
vec.push_back(val);
}
mio::osecir::Model<double> model(1);
EXPECT_EQ(model.parameters.get<mio::osecir::TimeExposed<double>>()[(mio::AgeGroup)0].get_distribution().get(),
nullptr);
model.parameters.set<mio::osecir::ICUCapacity<double>>(vec[0]);
model.parameters.get<mio::osecir::TimeExposed<double>>()[(mio::AgeGroup)0] = vec[1];
model.parameters.get<mio::osecir::TimeInfectedNoSymptoms<double>>()[(mio::AgeGroup)0] = vec[2];
model.parameters.get<mio::osecir::TimeInfectedSymptoms<double>>()[(mio::AgeGroup)0] = vec[3];
model.parameters.get<mio::osecir::TimeInfectedSevere<double>>()[(mio::AgeGroup)0] = vec[4];
model.parameters.get<mio::osecir::TimeInfectedCritical<double>>()[(mio::AgeGroup)0] = vec[5];
model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::Exposed}] = vec[6];
model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::InfectedNoSymptoms}] = vec[7];
model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::InfectedSymptoms}] = vec[8];
model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::InfectedSevere}] = vec[9];
model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::InfectedCritical}] = vec[10];
model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::Recovered}] = vec[11];
model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::Dead}] = vec[12];
model.parameters.get<mio::osecir::TransmissionProbabilityOnContact<double>>()[(mio::AgeGroup)0] = vec[13];
model.parameters.get<mio::osecir::RelativeTransmissionNoSymptoms<double>>()[(mio::AgeGroup)0] = vec[14];
model.parameters.get<mio::osecir::RecoveredPerInfectedNoSymptoms<double>>()[(mio::AgeGroup)0] = vec[15];
model.parameters.get<mio::osecir::RiskOfInfectionFromSymptomatic<double>>()[(mio::AgeGroup)0] = vec[16];
model.parameters.get<mio::osecir::SeverePerInfectedSymptoms<double>>()[(mio::AgeGroup)0] = vec[17];
model.parameters.get<mio::osecir::CriticalPerSevere<double>>()[(mio::AgeGroup)0] = vec[18];
model.parameters.get<mio::osecir::DeathsPerCritical<double>>()[(mio::AgeGroup)0] = vec[19];
EXPECT_NE(model.parameters.get<mio::osecir::TimeExposed<double>>()[(mio::AgeGroup)0].get_distribution().get(),
nullptr);
check_distribution(*vec[0].get_distribution(),
*model.parameters.get<mio::osecir::ICUCapacity<double>>().get_distribution());
model.parameters.set<mio::osecir::StartDay<double>>(vec[20]);
model.parameters.set<mio::osecir::Seasonality<double>>(vec[21]);
check_distribution(*vec[1].get_distribution(),
*model.parameters.get<mio::osecir::TimeExposed<double>>()[(mio::AgeGroup)0].get_distribution());
check_distribution(
*vec[2].get_distribution(),
*model.parameters.get<mio::osecir::TimeInfectedNoSymptoms<double>>()[(mio::AgeGroup)0].get_distribution());
check_distribution(
*vec[3].get_distribution(),
*model.parameters.get<mio::osecir::TimeInfectedSymptoms<double>>()[(mio::AgeGroup)0].get_distribution());
check_distribution(
*vec[4].get_distribution(),
*model.parameters.get<mio::osecir::TimeInfectedSevere<double>>()[(mio::AgeGroup)0].get_distribution());
check_distribution(
*vec[5].get_distribution(),
*model.parameters.get<mio::osecir::TimeInfectedCritical<double>>()[(mio::AgeGroup)0].get_distribution());
check_distribution(*vec[6].get_distribution(),
*model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::Exposed}].get_distribution());
check_distribution(
*vec[7].get_distribution(),
*model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::InfectedNoSymptoms}].get_distribution());
check_distribution(
*vec[8].get_distribution(),
*model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::InfectedSymptoms}].get_distribution());
check_distribution(
*vec[9].get_distribution(),
*model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::InfectedSevere}].get_distribution());
check_distribution(
*vec[10].get_distribution(),
*model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::InfectedCritical}].get_distribution());
check_distribution(
*vec[11].get_distribution(),
*model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::Recovered}].get_distribution());
check_distribution(*vec[12].get_distribution(),
*model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::Dead}].get_distribution());
check_distribution(*vec[13].get_distribution(),
*model.parameters.get<mio::osecir::TransmissionProbabilityOnContact<double>>()[(mio::AgeGroup)0]
.get_distribution());
check_distribution(*vec[14].get_distribution(),
*model.parameters.get<mio::osecir::RelativeTransmissionNoSymptoms<double>>()[(mio::AgeGroup)0]
.get_distribution());
check_distribution(*vec[15].get_distribution(),
*model.parameters.get<mio::osecir::RecoveredPerInfectedNoSymptoms<double>>()[(mio::AgeGroup)0]
.get_distribution());
check_distribution(*vec[16].get_distribution(),
*model.parameters.get<mio::osecir::RiskOfInfectionFromSymptomatic<double>>()[(mio::AgeGroup)0]
.get_distribution());
check_distribution(
*vec[17].get_distribution(),
*model.parameters.get<mio::osecir::SeverePerInfectedSymptoms<double>>()[(mio::AgeGroup)0].get_distribution());
check_distribution(
*vec[18].get_distribution(),
*model.parameters.get<mio::osecir::CriticalPerSevere<double>>()[(mio::AgeGroup)0].get_distribution());
check_distribution(
*vec[19].get_distribution(),
*model.parameters.get<mio::osecir::DeathsPerCritical<double>>()[(mio::AgeGroup)0].get_distribution());
// no dist for start day
check_distribution(*vec[21].get_distribution(),
*model.parameters.get<mio::osecir::Seasonality<double>>().get_distribution());
EXPECT_EQ(vec[0], model.parameters.get<mio::osecir::ICUCapacity<double>>());
EXPECT_EQ(vec[1], model.parameters.get<mio::osecir::TimeExposed<double>>()[(mio::AgeGroup)0]);
EXPECT_EQ(vec[2], model.parameters.get<mio::osecir::TimeInfectedNoSymptoms<double>>()[(mio::AgeGroup)0]);
EXPECT_EQ(vec[3], model.parameters.get<mio::osecir::TimeInfectedSymptoms<double>>()[(mio::AgeGroup)0]);
EXPECT_EQ(vec[4], model.parameters.get<mio::osecir::TimeInfectedSevere<double>>()[(mio::AgeGroup)0]);
EXPECT_EQ(vec[5], model.parameters.get<mio::osecir::TimeInfectedCritical<double>>()[(mio::AgeGroup)0]);
EXPECT_EQ(vec[6], (model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::Exposed}]));
EXPECT_EQ(vec[7], (model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::InfectedNoSymptoms}]));
EXPECT_EQ(vec[8], (model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::InfectedSymptoms}]));
EXPECT_EQ(vec[9], (model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::InfectedSevere}]));
EXPECT_EQ(vec[10], (model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::InfectedCritical}]));
EXPECT_EQ(vec[11], (model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::Recovered}]));
EXPECT_EQ(vec[12], (model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::Dead}]));
EXPECT_EQ(vec[13], model.parameters.get<mio::osecir::TransmissionProbabilityOnContact<double>>()[(mio::AgeGroup)0]);
EXPECT_EQ(vec[14], model.parameters.get<mio::osecir::RelativeTransmissionNoSymptoms<double>>()[(mio::AgeGroup)0]);
EXPECT_EQ(vec[15], model.parameters.get<mio::osecir::RecoveredPerInfectedNoSymptoms<double>>()[(mio::AgeGroup)0]);
EXPECT_EQ(vec[16], model.parameters.get<mio::osecir::RiskOfInfectionFromSymptomatic<double>>()[(mio::AgeGroup)0]);
EXPECT_EQ(vec[17], model.parameters.get<mio::osecir::SeverePerInfectedSymptoms<double>>()[(mio::AgeGroup)0]);
EXPECT_EQ(vec[18], model.parameters.get<mio::osecir::CriticalPerSevere<double>>()[(mio::AgeGroup)0]);
EXPECT_EQ(vec[19], model.parameters.get<mio::osecir::DeathsPerCritical<double>>()[(mio::AgeGroup)0]);
EXPECT_EQ(vec[20], model.parameters.get<mio::osecir::StartDay<double>>());
EXPECT_EQ(vec[21], model.parameters.get<mio::osecir::Seasonality<double>>());
}
// Test model initialization with total population of 0 and ensure get_flows returns no NaN values
TEST(TestOdeSecir, population_zero_no_nan)
{
// initialize simple model with total population 0
mio::osecir::Model<double> model(1);
model.populations.set_total(0.0);
// call the get_flows function
auto dydt_default = Eigen::VectorXd(15);
dydt_default.setZero();
auto y0 = model.get_initial_values();
model.get_flows(y0, y0, 0, dydt_default);
// check that there are now NaN values in dydt_default
for (int i = 0; i < dydt_default.size(); i++) {
EXPECT_FALSE(std::isnan(dydt_default[i]));
}
}
TEST(TestOdeSecir, testDamping)
{
// Test functionality of dampings
// (initially only implemented contact reductions but now also allow contact increases).
// Contact matrices with dampings are cosine-smoothed in decline/increase along one day to be C1 differentiable.
// If EulerIntegratorCore with dt=1 is used, we jump across this smoothing so that we can express the relationship
// between old and new transmission directly, only including damping, contact, and transmission probability values.
double t0 = 0;
double dt = 1;
double tmax = dt;
double cont_freq = 10;
double nb_total_t0 = 1000, nb_inf_t0 = 10;
// default model run to be compared against
mio::osecir::Model<double> model_a(1);
model_a.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::InfectedSymptoms}] = nb_inf_t0;
model_a.populations.set_difference_from_total({mio::AgeGroup(0), mio::osecir::InfectionState::Susceptible},
nb_total_t0);
mio::ContactMatrixGroup<double>& contact_matrix_a =
model_a.parameters.get<mio::osecir::ContactPatterns<ScalarType>>();
contact_matrix_a[0] = mio::ContactMatrix<double>(Eigen::MatrixXd::Constant(1, 1, cont_freq));
// set probability of transmission and risk of infection to 1.
model_a.parameters.get<mio::osecir::TransmissionProbabilityOnContact<ScalarType>>() = 1.0;
model_a.parameters.get<mio::osecir::RiskOfInfectionFromSymptomatic<ScalarType>>() = 1.0;
auto result_a = mio::simulate_flows<ScalarType>(t0, tmax, dt, model_a,
std::make_unique<mio::EulerIntegratorCore<ScalarType>>());
// reduced transmission
mio::osecir::Model<double> model_b{model_a};
model_b.populations.set_total(nb_total_t0);
model_b.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::InfectedSymptoms}] = nb_inf_t0;
model_b.populations.set_difference_from_total({mio::AgeGroup(0), mio::osecir::InfectionState::Susceptible},
nb_total_t0);
mio::ContactMatrixGroup<double>& contact_matrix_b =
model_b.parameters.get<mio::osecir::ContactPatterns<ScalarType>>();
contact_matrix_b[0] = mio::ContactMatrix<double>(Eigen::MatrixXd::Constant(1, 1, cont_freq));
contact_matrix_b[0].add_damping(0.5, mio::SimulationTime<double>(0.));
auto result_b = mio::simulate_flows<ScalarType>(t0, tmax, dt, model_b,
std::make_unique<mio::EulerIntegratorCore<ScalarType>>());
EXPECT_EQ(2 * result_b[1].get_last_value()[0], result_a[1].get_last_value()[0]);
// no transmission
mio::osecir::Model<double> model_c{model_a};
model_c.populations.set_total(nb_total_t0);
model_c.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::InfectedSymptoms}] = nb_inf_t0;
model_c.populations.set_difference_from_total({mio::AgeGroup(0), mio::osecir::InfectionState::Susceptible},
nb_total_t0);
mio::ContactMatrixGroup<double>& contact_matrix_c =
model_c.parameters.get<mio::osecir::ContactPatterns<ScalarType>>();
contact_matrix_c[0] = mio::ContactMatrix<double>(Eigen::MatrixXd::Constant(1, 1, cont_freq));
contact_matrix_c[0].add_damping(1., mio::SimulationTime<double>(0.));
auto result_c = mio::simulate_flows<ScalarType>(t0, tmax, dt, model_c,
std::make_unique<mio::EulerIntegratorCore<ScalarType>>());
EXPECT_EQ(result_c[1].get_last_value()[0], 0.0);
// increased transmission to a factor of two (by +1)
mio::osecir::Model<double> model_d{model_a};
model_d.populations.set_total(nb_total_t0);
model_d.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::InfectedSymptoms}] = nb_inf_t0;
model_d.populations.set_difference_from_total({mio::AgeGroup(0), mio::osecir::InfectionState::Susceptible},
nb_total_t0);
mio::ContactMatrixGroup<double>& contact_matrix_d =
model_d.parameters.get<mio::osecir::ContactPatterns<ScalarType>>();
contact_matrix_d[0] = mio::ContactMatrix<double>(Eigen::MatrixXd::Constant(1, 1, cont_freq));
contact_matrix_d[0].add_damping(-1., mio::SimulationTime<double>(0.));
auto result_d = mio::simulate_flows<ScalarType>(t0, tmax, dt, model_d,
std::make_unique<mio::EulerIntegratorCore<ScalarType>>());
EXPECT_EQ(2 * result_a[1].get_last_value()[0], result_d[1].get_last_value()[0]);
}
TEST(TestOdeSecir, testModelConstraints)
{
// as many random things are drawn, warnings are inevitable and cluster output
mio::LogLevelOverride llo(mio::LogLevel::err);
double t0 = 0;
double tmax = 57; // after 57 days with cont_freq 10 and winter, the virus would already decline
double dt = 0.1;
double cont_freq = 10;
double nb_total_t0 = 1000000, nb_exp_t0 = 10000, nb_inf_t0 = 5000, nb_car_t0 = 500, nb_hosp_t0 = 20, nb_icu_t0 = 0,
nb_rec_t0 = 10, nb_dead_t0 = 0;
mio::osecir::Model<double> model(1);
model.parameters.get<mio::osecir::TimeExposed<double>>()[(mio::AgeGroup)0] = 2.6;
model.parameters.get<mio::osecir::TimeInfectedNoSymptoms<double>>()[(mio::AgeGroup)0] = 2.6;
model.parameters.get<mio::osecir::TimeInfectedSymptoms<double>>()[(mio::AgeGroup)0] = 5;
model.parameters.get<mio::osecir::TimeInfectedSevere<double>>()[(mio::AgeGroup)0] = 10.;
model.parameters.get<mio::osecir::TimeInfectedCritical<double>>()[(mio::AgeGroup)0] = 8.;
model.parameters.get<mio::osecir::Seasonality<double>>() = 0.0;
model.parameters.get<mio::osecir::ICUCapacity<double>>() = 100.0;
model.parameters.get<mio::osecir::TestAndTraceCapacity<double>>() = 10.0;
model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::Exposed}] = nb_exp_t0;
model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::InfectedNoSymptoms}] = nb_car_t0;
model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::InfectedSymptoms}] = nb_inf_t0;
model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::InfectedSevere}] = nb_hosp_t0;
model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::InfectedCritical}] = nb_icu_t0;
model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::Recovered}] = nb_rec_t0;
model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::Dead}] = nb_dead_t0;
model.populations.set_difference_from_total({mio::AgeGroup(0), mio::osecir::InfectionState::Susceptible},
nb_total_t0);
model.parameters.get<mio::osecir::TransmissionProbabilityOnContact<double>>()[(mio::AgeGroup)0] = 0.05;
model.parameters.get<mio::osecir::RelativeTransmissionNoSymptoms<double>>()[(mio::AgeGroup)0] = 1;
model.parameters.get<mio::osecir::RecoveredPerInfectedNoSymptoms<double>>()[(mio::AgeGroup)0] = 0.09;
model.parameters.get<mio::osecir::MaxRiskOfInfectionFromSymptomatic<double>>() = 0.85;
model.parameters.get<mio::osecir::RiskOfInfectionFromSymptomatic<double>>()[(mio::AgeGroup)0] = 0.25;
model.parameters.get<mio::osecir::SeverePerInfectedSymptoms<double>>()[(mio::AgeGroup)0] = 0.2;
model.parameters.get<mio::osecir::CriticalPerSevere<double>>()[(mio::AgeGroup)0] = 0.25;
model.parameters.get<mio::osecir::DeathsPerCritical<double>>()[(mio::AgeGroup)0] = 0.3;
mio::ContactMatrixGroup<double>& contact_matrix = model.parameters.get<mio::osecir::ContactPatterns<double>>();
contact_matrix[0] = mio::ContactMatrix<double>(Eigen::MatrixXd::Constant(1, 1, cont_freq));
model.apply_constraints();
mio::TimeSeries<double> secihurd = mio::simulate<double>(t0, tmax, dt, model);
double max_icu_cap = 0;
for (Eigen::Index i = 0; i < secihurd.get_num_time_points(); i++) {
if (secihurd.get_value(i)[5] > max_icu_cap) {
max_icu_cap = secihurd.get_value(i)[5];
}
}
mio::TimeSeries<double> secihurd_interp = mio::interpolate_simulation_result(secihurd);
// Tests that infection numbers are higher in Winter season
model.parameters.set<mio::osecir::StartDay<double>>(100);
model.parameters.set<mio::osecir::Seasonality<double>>(0.5);
mio::TimeSeries<double> secihurd_season = mio::simulate<double>(t0, tmax, dt, model);
mio::TimeSeries<double> secihurd_season_interp = mio::interpolate_simulation_result(secihurd_season);
for (Eigen::Index i = 0; i < secihurd_interp.get_num_time_points(); i++) {
EXPECT_LE(secihurd_season_interp.get_value(i)[3], secihurd_interp.get_value(i)[3]) << " at row " << i;
}
model.parameters.set<mio::osecir::StartDay<double>>(280);
mio::TimeSeries<double> secihurd_season2 = mio::simulate<double>(t0, tmax, dt, model);
mio::TimeSeries<double> secihurd_season2_interp = mio::interpolate_simulation_result(secihurd_season2);
for (Eigen::Index i = 0; i < secihurd_interp.get_num_time_points(); i++) {
EXPECT_GE(secihurd_season2_interp.get_value(i)[3], secihurd_interp.get_value(i)[3]) << " at row " << i;
}
// temporary test for random variables
set_params_distributions_normal(model, t0, tmax, 0.2);
model.parameters.set<mio::osecir::Seasonality<double>>(mio::UncertainValue<double>(0.0));
model.parameters.set<mio::osecir::ICUCapacity<double>>(mio::UncertainValue<double>(8000));
for (size_t j = 0; j < 10; j++) {
draw_sample(model);
secihurd = mio::simulate<double>(t0, tmax, dt, model);
for (Eigen::Index i = 0; i < secihurd.get_num_time_points(); i++) {
EXPECT_LE(secihurd.get_value(i)[5], 9000) << " at row " << i;
}
}
}
TEST(TestOdeSecir, deathsPerSevere_flows)
{
// Test that DeathsPerSevere causes ISev->Dead flow independent of ICU overflow.
// CriticalPerSevere=0 blocks the ISev->ICr->Dead path entirely, so ICUCapacity and
// DeathsPerCritical have no influence and are left at their default values.
mio::osecir::Model<double> model(1);
auto& params = model.parameters;
params.get<mio::osecir::TimeInfectedSevere<double>>()[(mio::AgeGroup)0] = 10.0;
params.get<mio::osecir::TimeInfectedCritical<double>>()[(mio::AgeGroup)0] = 7.0;
params.get<mio::osecir::CriticalPerSevere<double>>()[(mio::AgeGroup)0] = 0.0; // block ISev->ICr->Dead path
params.get<mio::osecir::DeathsPerSevere<double>>()[(mio::AgeGroup)0] = 0.1;
const double nb_severe = 1000.0;
model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::InfectedSevere}] = nb_severe;
model.populations.set_difference_from_total({mio::AgeGroup(0), mio::osecir::InfectionState::Susceptible},
nb_severe);
// Simulate a small time step
double t0 = 0, tmax = 0.5, dt = 0.1;
mio::TimeSeries<double> result = mio::simulate<double>(t0, tmax, dt, model);
// With DeathsPerSevere=0.1 and no ICU overflow, deaths from ISev must be > 0
auto dead_final = result.get_last_value()[(size_t)mio::osecir::InfectionState::Dead];
EXPECT_GT(dead_final, 0.0);
// Now run again with DeathsPerSevere=0
params.get<mio::osecir::DeathsPerSevere<double>>()[(mio::AgeGroup)0] = 0.0;
mio::TimeSeries<double> result_no_severe_deaths = mio::simulate<double>(t0, tmax, dt, model);
auto dead_no_severe = result_no_severe_deaths.get_last_value()[(size_t)mio::osecir::InfectionState::Dead];
// With DeathsPerSevere=0 and no ICU overflow there should be no deaths from ISev,
// so dead compartment stays 0 (ICr is also 0 initially)
EXPECT_DOUBLE_EQ(dead_no_severe, 0.0);
// Population must be conserved in both runs
double total_with = result.get_last_value().sum();
double total_without = result_no_severe_deaths.get_last_value().sum();
EXPECT_NEAR(total_with, nb_severe, 1e-10);
EXPECT_NEAR(total_without, nb_severe, 1e-10);
// Recovery flow must be higher when DeathsPerSevere=0
auto rec_with = result.get_last_value()[(size_t)mio::osecir::InfectionState::Recovered];
auto rec_without = result_no_severe_deaths.get_last_value()[(size_t)mio::osecir::InfectionState::Recovered];
EXPECT_GT(rec_without, rec_with);
}
TEST(TestOdeSecir, testAndTraceCapacity)
{
double cont_freq = 10;
double nb_total_t0 = 10000, nb_exp_t0 = 100, nb_inf_t0 = 50, nb_car_t0 = 50;
mio::osecir::Model<double> model(1);
auto& params = model.parameters;
params.get<mio::osecir::TimeExposed<double>>()[(mio::AgeGroup)0] = 3.2;
params.get<mio::osecir::TimeInfectedNoSymptoms<double>>()[(mio::AgeGroup)0] = 2.0;
params.get<mio::osecir::TimeInfectedSymptoms<double>>()[(mio::AgeGroup)0] = 6.;
mio::ContactMatrixGroup<double>& contact_matrix = params.get<mio::osecir::ContactPatterns<double>>();
contact_matrix[0] = mio::ContactMatrix<double>(Eigen::MatrixXd::Constant(1, 1, cont_freq));
model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::Exposed}] = nb_exp_t0;
model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::InfectedNoSymptoms}] = nb_car_t0;
model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::InfectedSymptoms}] = nb_inf_t0;
model.populations.set_difference_from_total({mio::AgeGroup(0), mio::osecir::InfectionState::Susceptible},
nb_total_t0);
params.get<mio::osecir::TransmissionProbabilityOnContact<double>>()[(mio::AgeGroup)0] = 0.05;
params.get<mio::osecir::RelativeTransmissionNoSymptoms<double>>()[(mio::AgeGroup)0] = 1;
params.get<mio::osecir::RecoveredPerInfectedNoSymptoms<double>>()[(mio::AgeGroup)0] = 0.09;
params.get<mio::osecir::RiskOfInfectionFromSymptomatic<double>>()[(mio::AgeGroup)0] = 0.25;
params.apply_constraints();
auto y = model.populations.get_compartments();
auto dydt_default = Eigen::VectorXd(Eigen::Index(mio::osecir::InfectionState::Count));
model.get_derivatives(y.cast<double>(), y.cast<double>(), 0, dydt_default);
params.set<mio::osecir::TestAndTraceCapacity<double>>(50);
params.get<mio::osecir::MaxRiskOfInfectionFromSymptomatic<double>>()[(mio::AgeGroup)0] = 0.25 * 3;
auto dydt_under_capacity = Eigen::VectorXd(Eigen::Index(mio::osecir::InfectionState::Count));
model.get_derivatives(y.cast<double>(), y.cast<double>(), 0, dydt_under_capacity);
params.set<mio::osecir::TestAndTraceCapacity<double>>(10);
params.get<mio::osecir::MaxRiskOfInfectionFromSymptomatic<double>>()[(mio::AgeGroup)0] = 0.25 * 3;
auto dydt_over_capacity = Eigen::VectorXd(Eigen::Index(mio::osecir::InfectionState::Count));
model.get_derivatives(y.cast<double>(), y.cast<double>(), 0, dydt_over_capacity);
EXPECT_DOUBLE_EQ(dydt_under_capacity[(size_t)mio::osecir::InfectionState::Exposed],
dydt_default[(size_t)mio::osecir::InfectionState::Exposed]);
EXPECT_GT(dydt_over_capacity[(size_t)mio::osecir::InfectionState::Exposed],
dydt_default[(size_t)mio::osecir::InfectionState::Exposed]);
}
TEST(TestOdeSecir, getInfectionsRelative)
{
size_t num_groups = 3;
mio::osecir::Model<double> model((int)num_groups);
model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::InfectedSymptoms}] = 100.0;
model.populations.set_difference_from_group_total<mio::AgeGroup>(
{mio::AgeGroup(0), mio::osecir::InfectionState::Susceptible}, 10'000.0);
model.populations[{mio::AgeGroup(1), mio::osecir::InfectionState::InfectedSymptoms}] = 50.0;
model.populations.set_difference_from_group_total<mio::AgeGroup>(
{mio::AgeGroup(1), mio::osecir::InfectionState::Susceptible}, 20'000.0);
model.populations[{mio::AgeGroup(2), mio::osecir::InfectionState::InfectedSymptoms}] = 25.0;
model.populations.set_difference_from_group_total<mio::AgeGroup>(
{mio::AgeGroup(2), mio::osecir::InfectionState::Susceptible}, 40'000.0);
mio::osecir::Simulation<double> sim(model, 0.0);
ASSERT_EQ(mio::osecir::get_infections_relative<double>(sim, 0.0, sim.get_result().get_last_value()),
(100. + 50. + 25.) / (10'000 + 20'000 + 40'000));
}
TEST(TestOdeSecir, get_reproduction_number)
{
const size_t num_groups = 3;
mio::osecir::Model<double> model((int)num_groups);
mio::ContactMatrixGroup<double>& contact_matrix = model.parameters.get<mio::osecir::ContactPatterns<double>>();
contact_matrix[0] = mio::ContactMatrix<double>(Eigen::MatrixXd::Constant(3, 3, 10));
model.parameters.set<mio::osecir::StartDay<double>>(60);
model.parameters.set<mio::osecir::Seasonality<double>>(0.2);
//total population of 10.000
model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::Susceptible}] = 3000;
model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::Exposed}] = 400;
model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::InfectedNoSymptoms}] = 50;
model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::InfectedNoSymptomsConfirmed}] = 0;
model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::InfectedSymptoms}] = 50;
model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::InfectedSymptomsConfirmed}] = 0;
model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::InfectedSevere}] = 0;
model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::InfectedCritical}] = 0;
model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::Recovered}] = 0;
model.populations[{mio::AgeGroup(0), mio::osecir::InfectionState::Dead}] = 0;
model.populations[{mio::AgeGroup(1), mio::osecir::InfectionState::Susceptible}] = 4000;
model.populations[{mio::AgeGroup(1), mio::osecir::InfectionState::Exposed}] = 350;
model.populations[{mio::AgeGroup(1), mio::osecir::InfectionState::InfectedNoSymptoms}] = 50;
model.populations[{mio::AgeGroup(1), mio::osecir::InfectionState::InfectedNoSymptomsConfirmed}] = 0;
model.populations[{mio::AgeGroup(1), mio::osecir::InfectionState::InfectedSymptoms}] = 100;
model.populations[{mio::AgeGroup(1), mio::osecir::InfectionState::InfectedSymptomsConfirmed}] = 0;
model.populations[{mio::AgeGroup(1), mio::osecir::InfectionState::InfectedSevere}] = 0;
model.populations[{mio::AgeGroup(1), mio::osecir::InfectionState::InfectedCritical}] = 0;
model.populations[{mio::AgeGroup(1), mio::osecir::InfectionState::Recovered}] = 0;
model.populations[{mio::AgeGroup(1), mio::osecir::InfectionState::Dead}] = 0;
model.populations[{mio::AgeGroup(2), mio::osecir::InfectionState::Susceptible}] = 1500;
model.populations[{mio::AgeGroup(2), mio::osecir::InfectionState::Exposed}] = 200;
model.populations[{mio::AgeGroup(2), mio::osecir::InfectionState::InfectedNoSymptoms}] = 100;
model.populations[{mio::AgeGroup(2), mio::osecir::InfectionState::InfectedNoSymptomsConfirmed}] = 0;
model.populations[{mio::AgeGroup(2), mio::osecir::InfectionState::InfectedSymptoms}] = 100;
model.populations[{mio::AgeGroup(2), mio::osecir::InfectionState::InfectedSymptomsConfirmed}] = 0;
model.populations[{mio::AgeGroup(2), mio::osecir::InfectionState::InfectedSevere}] = 50;
model.populations[{mio::AgeGroup(2), mio::osecir::InfectionState::InfectedCritical}] = 50;
model.populations[{mio::AgeGroup(2), mio::osecir::InfectionState::Recovered}] = 0;
model.populations[{mio::AgeGroup(2), mio::osecir::InfectionState::Dead}] = 0;
for (auto i = mio::AgeGroup(0); i < (mio::AgeGroup)num_groups; i++) {
model.parameters.get<mio::osecir::TimeExposed<double>>()[i] = 3.2;
model.parameters.get<mio::osecir::TimeInfectedNoSymptoms<double>>()[i] = 2.0;
model.parameters.get<mio::osecir::TimeInfectedSymptoms<double>>()[i] = 5.8;
model.parameters.get<mio::osecir::TimeInfectedSevere<double>>()[i] = 9.5;
model.parameters.get<mio::osecir::TimeInfectedCritical<double>>()[i] = 7.1;
model.parameters.get<mio::osecir::TransmissionProbabilityOnContact<double>>()[i] = 0.05;
model.parameters.get<mio::osecir::RelativeTransmissionNoSymptoms<double>>()[i] = 0.7;
model.parameters.get<mio::osecir::RecoveredPerInfectedNoSymptoms<double>>()[i] = 0.09;
model.parameters.get<mio::osecir::RiskOfInfectionFromSymptomatic<double>>()[i] = 0.25;
model.parameters.get<mio::osecir::MaxRiskOfInfectionFromSymptomatic<double>>()[i] = 0.45;
model.parameters.get<mio::osecir::SeverePerInfectedSymptoms<double>>()[i] = 0.2;
model.parameters.get<mio::osecir::CriticalPerSevere<double>>()[i] = 0.25;
model.parameters.get<mio::osecir::DeathsPerCritical<double>>()[i] = 0.3;
}
model.parameters.get<mio::osecir::ICUCapacity<double>>() = std::numeric_limits<double>::max();
model.parameters.get<mio::osecir::TestAndTraceCapacity<double>>() = std::numeric_limits<double>::max();
mio::TimeSeries<ScalarType> time_series1((int)mio::osecir::InfectionState::Count * num_groups);
mio::TimeSeries<ScalarType>::Vector result_0((int)mio::osecir::InfectionState::Count * num_groups);
mio::TimeSeries<ScalarType>::Vector result_1((int)mio::osecir::InfectionState::Count * num_groups);
mio::TimeSeries<ScalarType>::Vector result_2((int)mio::osecir::InfectionState::Count * num_groups);
mio::TimeSeries<ScalarType>::Vector result_3((int)mio::osecir::InfectionState::Count * num_groups);
mio::TimeSeries<ScalarType>::Vector result_4((int)mio::osecir::InfectionState::Count * num_groups);
mio::TimeSeries<ScalarType>::Vector result_5((int)mio::osecir::InfectionState::Count * num_groups);
mio::TimeSeries<ScalarType>::Vector result_6((int)mio::osecir::InfectionState::Count * num_groups);
model.apply_constraints();
result_0 << 3000, 400, 50, 0, 50, 0, 0, 0, 0, 0, 4000, 350, 50, 0, 100, 0, 0, 0, 0, 0, 1500, 200, 100, 0, 100, 0,
50, 50, 0, 0;
result_1 << 2900, 500, 50, 0, 50, 0, 0, 0, 0, 0, 4000, 350, 50, 0, 100, 0, 0, 0, 0, 0, 1500, 200, 100, 0, 100, 0,
50, 50, 0, 0;
result_2 << 2850, 550, 50, 0, 50, 0, 0, 0, 0, 0, 4000, 350, 0, 0, 150, 0, 0, 0, 0, 0, 1500, 200, 100, 0, 100, 0, 50,
50, 0, 0;
result_3 << 2850, 550, 50, 0, 50, 0, 0, 0, 0, 0, 4000, 350, 0, 0, 150, 0, 0, 0, 0, 0, 1300, 400, 100, 0, 100, 0, 50,
50, 0, 0;
result_4 << 2800, 600, 50, 0, 50, 0, 0, 0, 0, 0, 4000, 300, 0, 0, 200, 0, 0, 0, 0, 0, 1300, 400, 100, 0, 100, 0, 50,
50, 0, 0;
result_5 << 2800, 600, 50, 0, 50, 0, 0, 0, 0, 0, 4000, 300, 0, 0, 200, 0, 0, 0, 0, 0, 1300, 400, 100, 0, 100, 0, 50,
50, 0, 0;
result_6 << 2700, 600, 100, 0, 100, 0, 0, 0, 0, 0, 4000, 300, 0, 0, 200, 0, 0, 0, 0, 0, 1300, 400, 100, 0, 100, 0,
0, 100, 0, 0;
time_series1.add_time_point(0.0, result_0);
time_series1.add_time_point(0.1000000000000000000, result_1);
time_series1.add_time_point(0.2000000000000000000, result_2);
time_series1.add_time_point(0.4000000000000000000, result_3);
time_series1.add_time_point(0.6000000000000000000, result_4);
time_series1.add_time_point(0.8000000000000000000, result_5);
time_series1.add_time_point(1.0, result_6);
mio::osecir::Simulation<double> sim(model, 0.0);
sim.get_result() = time_series1;
EXPECT_FALSE(
mio::osecir::get_reproduction_number(time_series1.get_time(0) - 0.5, sim)); //Test for indices out of range
EXPECT_FALSE(mio::osecir::get_reproduction_number(time_series1.get_last_time() + 0.5, sim));
EXPECT_FALSE(mio::osecir::get_reproduction_number((size_t)time_series1.get_num_time_points(), sim));
EXPECT_EQ(mio::osecir::get_reproduction_number((size_t)0, sim).value(),
mio::osecir::get_reproduction_number(0.0, sim).value());
//Test one function for integer timepoints
EXPECT_NEAR(mio::osecir::get_reproduction_number((size_t)0, sim).value(), 3.7417747463385571, 1e-12);