All problems
Epidemic R0 from Graph Degree
Problem
Estimate the basic reproduction number of an SIR process from the mean degree: R0 = beta * mean_degree / gamma.
beta is the transmission rate per edge, gamma the recovery rate, and edges the contact list of an undirected graph with n nodes. Return the float value, or 0.0 when n is 0 or gamma is 0.
Hint
A denser contact network raises R0 and makes outbreaks harder to contain.
Test cases
case 1
in: [3,[[0,1],[1,2]],0.5,0.25]
expected: 2.6666666666666665
case 2
in: [4,[[0,1],[0,2],[0,3]],0.2,0.5]
expected: 0.6000000000000001
case 3
in: [1,[],0.5,0.25]
expected: 0
case 4
in: [4,[[0,1],[0,2],[0,3],[1,2],[1,3],[2,3]],0.3,0.2]
expected: 4.5
Starter codePython
def epidemic_r0(n, edges, beta, gamma):
# Your code here
pass4 test cases · run your code against them in the editor