<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE nta PUBLIC '-//Uppaal Team//DTD Flat System 1.6//EN' 'http://www.it.uu.se/research/group/darts/uppaal/flat-1_6.dtd'>
<nta>
	<declaration>// SEIRD model of COVID-19 spreading as a Continuous Time Markov Chain (CTMC).
// The state is the vector of compartment counts (S, E, I, R, D); each event
// type (reaction) is a Reaction process whose single location has an
// exponential exit rate equal to the event's propensity. UPPAAL SMC's race
// semantics between these processes is exactly the CTMC (Gillespie) dynamics.
// Time unit: days.

// ---------------- Population ----------------
const int N  = 100;             // population size (change freely)
const int I0 = 1;               // initially infectious individuals

// ---------------- Epidemiological parameters ----------------
const double R0    = 2.5;             // basic reproduction number
const double gamma = 1.0 / 7.0;       // recovery rate   (mean infectious period 7 days)
const double sigma = 1.0 / 5.2;       // incubation rate (mean latent period 5.2 days)
const double beta  = R0 * gamma;      // transmission rate
const double ifr   = 0.01;            // infection fatality ratio (1%)

// ---------------- CTMC state ----------------
int Sus  = N - I0;              // susceptible
int Exp  = 0;                   // exposed (infected, not yet infectious)
int Inf  = I0;                  // infectious
int Rec  = 0;                   // recovered (immune)
int Dead = 0;                   // deceased

// ---------------- Transitions of the CTMC ----------------
//   INFECTION : S + I -&gt; E + I   rate beta * S * I / N
//   ONSET     : E     -&gt; I       rate sigma * E
//   RECOVERY  : I     -&gt; R       rate gamma * (1 - ifr) * I
//   DEATH     : I     -&gt; D       rate gamma * ifr * I
const int INFECTION = 0;
const int ONSET     = 1;
const int RECOVERY  = 2;
const int DEATH     = 3;
typedef int[0, 3] ev_t;

double propensity(ev_t e) {
    if (e == INFECTION) return beta * Sus * Inf / N;
    if (e == ONSET)     return sigma * Exp;
    if (e == RECOVERY)  return gamma * (1.0 - ifr) * Inf;
    return gamma * ifr * Inf;   // DEATH
}

void fire(ev_t e) {
    if (e == INFECTION)     { Sus--; Exp++; }
    else if (e == ONSET)    { Exp--; Inf++; }
    else if (e == RECOVERY) { Inf--; Rec++; }
    else                    { Inf--; Dead++; }
}</declaration>
	<template>
		<name x="5" y="5">Reaction</name>
		<parameter>const ev_t e</parameter>
		<location id="id0" x="0" y="0">
			<name x="-25" y="-42">Active</name>
			<label kind="exponentialrate" x="-42" y="17">propensity(e)</label>
		</location>
		<init ref="id0"/>
		<transition id="id1">
			<source ref="id0"/>
			<target ref="id0"/>
			<label kind="guard" x="76" y="-34">propensity(e) &gt; 0.0</label>
			<label kind="assignment" x="76" y="0">fire(e)</label>
			<nail x="68" y="-34"/>
			<nail x="68" y="34"/>
		</transition>
	</template>
	<system>// One Reaction process per CTMC event type. Model size no longer depends on N.
system Reaction;</system>
	<queries>
		<query>
			<formula>simulate [&lt;=180; 1] { Sus, Exp, Inf, Rec, Dead }</formula>
			<comment>One simulated epidemic trajectory over 180 days (plot all compartments).</comment>
		</query>
		<query>
			<formula>simulate [&lt;=180; 10] { Inf }</formula>
			<comment>Ten trajectories of the number of infectious people: shows the run-to-run variability.</comment>
		</query>
		<query>
			<formula>E [&lt;=365; 500] (max: Inf)</formula>
			<comment>Expected peak number of simultaneously infectious people.</comment>
		</query>
		<query>
			<formula>E [&lt;=365; 500] (max: Dead)</formula>
			<comment>Expected number of deaths within one year.</comment>
		</query>
		<query>
			<formula>Pr [&lt;=365] (&lt;&gt; Rec + Dead &gt;= N / 2)</formula>
			<comment>Probability that at least half the population is infected within a year (a major outbreak).</comment>
		</query>
		<query>
			<formula>Pr [&lt;=365] (&lt;&gt; Inf &gt;= N / 5)</formula>
			<comment>Probability that 20% of the population is infectious at the same time (e.g. exceeding healthcare capacity).</comment>
		</query>
		<query>
			<formula>Pr [&lt;=365] (&lt;&gt; Exp + Inf == 0 &amp;&amp; Rec + Dead &lt; N / 10)</formula>
			<comment>Probability of early stochastic extinction: the epidemic dies out before infecting 10% of the population.</comment>
		</query>
		<query>
			<formula>Pr [&lt;=365] ([] Sus + Exp + Inf + Rec + Dead == N)</formula>
			<comment>Sanity check: the compartments always sum to the population size (should be ~1).</comment>
		</query>
	</queries>
</nta>
