Skip to content

Agent Network SIR

junlingm edited this page Mar 7, 2023 · 3 revisions

A Network SIR Model

The setup of a contact network model is almost identical to a random-mixing model, except that the contact object is a network. In this example, we use the newConfigurationModel function to return a random network generated by the configuration model. This function takes a single argument which is a random number generator to generate a random degree from the degree distribution.

  gamma = newExpWaitingTime(0.2)
  beta = 0.1333
  n = 10000
  sim = Simulation$new(n)
  sim$addLogger(newCounter("S", "S"))
  sim$addLogger(newCounter("I", "I"))
  sim$addLogger(newCounter("R", "R"))
  # Generate a Poisson random network with an average degree 5.
  m = newConfigurationModel(function(n) rpois(n, 5))
  sim$addContact(m)
  sim$addTransition("I"->"R", gamma)#, changed_callback=changed_IR)
  sim$addTransition("I" + "S" -> "I" + "I" ~ m, beta) #, changed_callback=changed)
  for (i in 1:n) {
    sim$setState(i, if (i <= 10) "I" else "S")
  }
  sim$run(0:100)