Optimal control extension on SEITRNet. A companion implementing Pontryagin-based optimal control of the deterministic SEITR system and a numerically-optimized treatment policy for its stochastic network analogue, with cross-formulation comparison.
Overview · Formulation · Methodology · Repository · Run · Results · Cite
*SEITRNet++ presents the C++ refactored library with up to x200 performance improvements.
This repository accompanies a study of optimal treatment policy for an SEITR-class epidemic, formulated and solved at two levels:
-
Continuous level. A deterministic SEITR ODE system with a time-varying treatment-uptake control
$u(t) \in [0, \zeta]$ , solved via a forward-backward sweep that combines RK4 integration of state and adjoint equations with the Pontryagin characterization of the optimal control. -
Discrete level. The same epidemic process simulated stochastically on an explicit contact graph with a neighbor-resolved force of infection. The control profile is parameterized as a piecewise-constant function over
$K$ intervals and optimized numerically against the Monte Carlo objective.
The two solutions are compared head-to-head: the ODE-derived
This repository is the experimental complement to a baseline SEITR-on-networks pipeline; it is a script-and-notebook research artifact rather than a packaged R library.
Let
In this controlled formulation
with weight
Introducing adjoints
where
The forward-backward sweep iterates state forward, adjoint backward, control update via the expression above, and a convex-combination smoothing
The deterministic system is shadowed by a discrete-time stochastic process on a contact graph
-
$S \to E$ for node$i$ with probability$\beta_1 \cdot |\mathcal{N}_i \cap I_t| / |V_t|$ , where$\mathcal{N}_i$ is the neighborhood of$i$ . Force of infection is local, not mean-field. -
$E \to I$ with probability$\beta_2$ . -
$I \to R$ with probability$\beta_3$ , else$I \to T$ with probability$\alpha_1 + u(t)$ . -
$T \to R$ with probability$\alpha_2$ . - Disease deaths from
$I$ and$T$ are sampled as$\mathrm{Binomial}(|I_t|, \delta_I)$ and$\mathrm{Binomial}(|T_t|, \delta_T)$ ; natural deaths as$\mathrm{Binomial}(|V_t|, \mu)$ ; recruitment as$\mathrm{Poisson}(\Lambda)$ , with newborn nodes attached according to the host topology's generative rule.
For the uncontrolled system (
reported alongside each parameter set in the experiments.
| Step | Method |
|---|---|
| State integration | Classical fourth-order Runge–Kutta, forward in time |
| Adjoint integration | RK4, backward in time, with terminal |
| Control update | Pontryagin characterization, projected onto |
| Smoothing | Convex combination |
| Cost integration | Composite Simpson's rule |
| Step | Method |
|---|---|
| Control parameterization | Piecewise-constant on |
| Inner objective | Mean total cost over num_exp Monte Carlo replicates |
| Outer optimizer | L-BFGS-B with box constraints optimParallel
|
| Parallel RNG |
L'Ecuyer-CMRG streams seeded for reproducibility |
The ODE-derived control
.
├── README.md
├── output # Folder: contains experiment results.
├── SEITR_OC.R # Core: network simulator + ODE OC solver + utilities
├── SEITR_function.R # Legacy baseline SEITR simulator (no control)
├── OptControl_SEITR.ipynb # Experiment notebook (R kernel)
└── supplement.ipynb # Supplement experiment and plots
This repository ships R source and a Jupyter notebook with an R kernel. There is no installable package; functions are sourced directly.
install.packages(c(
"igraph", "deSolve", "ggplot2", "dplyr", "tidyr", "gridExtra",
"GA", "optimx", "optimParallel", "doParallel"
))install.packages("IRkernel")
IRkernel::installspec(user = TRUE)R
source("SEITR_OC.R")
# Pick a parameter set
Lambda <- 0.4
beta1 <- 0.9; beta2 <- 0.059; beta3 <- 0.2
alpha1 <- 0.03; alpha2 <- 0.055
delta_I <- 0.03; delta_T <- 0.03; mu <- 0.02
# ODE optimal control
oc <- solve_seitr_optimal_control(
Lambda, beta1, beta2, beta3, alpha1, alpha2, delta_I, delta_T, mu,
h = 0.01, t = seq(0, 100, by = 0.01),
w1 = 0.2, zeta = 1, delta = 1e-3,
S0 = 50, E0 = 25, I0 = 15, T0 = 5, R0 = 5
)
# Apply ODE-derived u1* to a stochastic ER network
res <- run_seitr_network_simulation(
network_type = "ER", n = 100, n_par1 = 0.2, n_par2 = NA,
Lambda, beta1, beta2, beta3, alpha1, alpha2, delta_I, delta_T, mu,
init_S = 50, init_E = 25, init_I = 15, init_T = 5, init_R = 5,
t_max = 100, u1_profile = oc$u1, num_exp = 20
)
J <- calculate_objective_functional(res$avg)$J_totalThe notebook is structured as:
- Library and parameter setup.
-
ODE optimal control at
$n = 100$ — full forward-backward sweep, objective trace, and before/after compartment trajectories. -
Network optimal control on Erdős–Rényi graphs — separate sections for
$p = 0.2$ and$p = 0.5$ , each comprising:- Network optimization via L-BFGS-B in parallel,
- Network simulation with the optimized
$u$ , - Network simulation without control,
- Network–ODE overlays with min/max bands.
Random number generation in parallel scenarios uses RNGkind("L'Ecuyer-CMRG") with clusterSetRNGStream(cl, 12345).
For each experiment the notebook reports: the optimized
Reproducibility caveat. Because the notebook runs Monte Carlo network simulations, exact figure replication requires the same seed and the same parallel-stream configuration. Numerical values may shift at the second-decimal level across hardware.
If this software contributes to a publication, please cite: Karaoglu S, Imran M, McKinney BA. Network-based SEITR epidemiological model with contact heterogeneity: comparison with homogeneous models for random, scale-free and small-world networks. The European Physical Journal Plus. 2025 Jun 18;140(6):551, https://doi.org/10.1140/epjp/s13360-025-06481-z.
Released for academic use. See LICENSE for full terms. For commercial use, contact the maintainer.
Built with igraph, deSolve, and optimParallel