Skip to content

Commit abc02d7

Browse files
authored
1034 ide model simulation does not work under some conditions (#1035)
compute_compartment_from_flows() now works when the TransitionDistribution SusceptibleToExposed is set to a ConstantFunction (or any other function with an invalid maximum support).
1 parent e15b4bb commit abc02d7

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

cpp/memilio/epidemiology/state_age_function.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -658,8 +658,8 @@ struct ConstantFunction : public StateAgeFunction {
658658
unused(tol);
659659
m_support_max = -2.;
660660

661-
log_error("This function is not suited to be a TransitionDistribution. Do not call in case of StateAgeFunctions"
662-
"of type b); see documentation of StateAgeFunction Base class.");
661+
log_error("This function is not suited to be a TransitionDistribution. Do not call in case of "
662+
"StateAgeFunctions of type b); see documentation of StateAgeFunction Base class.");
663663

664664
return m_support_max;
665665
}

cpp/models/ide_secir/model.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,17 @@ void Model::compute_compartment_from_flows(ScalarType dt, Eigen::Index idx_Infec
6060
Eigen::Index idx_IncomingFlow, int idx_TransitionDistribution1,
6161
int idx_TransitionDistribution2)
6262
{
63-
ScalarType sum = 0;
64-
63+
ScalarType sum = 0;
64+
ScalarType calc_time = 0;
6565
// Determine relevant calculation area and corresponding index.
66-
ScalarType calc_time =
67-
std::max(parameters.get<TransitionDistributions>()[idx_TransitionDistribution1].get_support_max(dt, m_tol),
68-
parameters.get<TransitionDistributions>()[idx_TransitionDistribution2].get_support_max(dt, m_tol));
66+
if ((1 - parameters.get<TransitionProbabilities>()[idx_TransitionDistribution1]) > 0) {
67+
calc_time =
68+
std::max(parameters.get<TransitionDistributions>()[idx_TransitionDistribution1].get_support_max(dt, m_tol),
69+
parameters.get<TransitionDistributions>()[idx_TransitionDistribution2].get_support_max(dt, m_tol));
70+
}
71+
else {
72+
calc_time = parameters.get<TransitionDistributions>()[idx_TransitionDistribution1].get_support_max(dt, m_tol);
73+
}
6974

7075
Eigen::Index calc_time_index = (Eigen::Index)std::ceil(calc_time / dt) - 1;
7176

0 commit comments

Comments
 (0)