How to use Z3Py online to compute Ro in a population with heterogeneity in sexual acitivity and proportionate miximg

StackOverflow https://stackoverflow.com/questions/18084242

  •  23-06-2022
  •  | 
  •  

質問

To solve the problem we use the following code:

R_H, R_L, g_H, g_L, x, R_0 = Reals('R_H R_L g_H g_L x R_0')
R_HH = R_H*g_H
R_HL = R_L*g_H
R_LH = R_H*g_L
R_LL = R_L*g_L
eq1 = R_HH*x+R_HL*(1-x)
eq2 = R_LH*x+R_LL*(1-x)
equations = [
             eq1 == R_0*x, eq2 == R_0*(1-x)
                                           ]
print "epidemiological equations:"
print equations
problem = [
g_H == 0.31, g_L == 0.69,
R_H == 3.93,
R_L == 0.18, x >0 , R_0 >0]
print "Problem:"
print problem 
print "Solution:"
set_option(rational_to_decimal=True)
solve(equations + problem)

The output is

epidemiological equations:
[R_H·g_H·x + R_L·g_H·(1 - x) = R_0·x, R_H·g_L·x + R_L·g_L·(1 - x) = R_0·(1 - x)]
Problem:
[g_H = 31/100, g_L = 69/100, R_H = 393/100, R_L = 9/50, x > 0, R_0 > 0]
Solution:
[x = 0.31,
R_0 = 1.3425,
R_L = 0.18,
R_H = 3.93,
g_L = 0.69,
g_H = 0.31]

Run this example online here

Please let me know what do you think. Many thanks.

役に立ちましたか?

解決

Other example with three classes of sexual activity : High, Medium, Low.

Code:

R_H, R_M, R_L, g_H, g_M, g_L, x, y, R_0 = Reals('R_H R_M R_L g_H g_M g_L x y R_0')
R_HH = R_H*g_H
R_HL = R_L*g_H
R_LH = R_H*g_L
R_LL = R_L*g_L
R_HM = R_M*g_H
R_MH = R_H*g_M
R_MM = R_M*g_M
R_ML = R_L*g_M
R_LM = R_M*g_L
eq1 = R_HH*x+R_HM*y+R_HL*(1-x-y)
eq2 = R_MH*x+R_MM*y+R_ML*(1-x-y)
eq3 = R_LH*x + R_LM*y + R_LL*(1-x-y)
equations = [
            eq1 == R_0*x, eq2 == R_0*y, eq3 == R_0*(1-x-y)
            ]
print "epidemiological equations:"
print equations
problem = [
           g_H == 0.31, g_M == 0.45 , g_L == 0.69,
           R_H == 3.93, R_M == 1.86,
           R_L == 0.18, x >0 , y >0,  R_0 >0]
print "Problem:"
print problem 
print "Solution:"
set_option(rational_to_decimal=True)
solve(equations + problem)

Output:

epidemiological equations:
[R_H·g_H·x + R_M·g_H·y + R_L·g_H·(1 - x - y) = R_0·x, R_H·g_M·x + R_M·g_M·y + R_L·g_M·(1 - x - y) = R_0·y, R_H·g_L·x + R_M·g_L·y + R_L·g_L·(1 - x - y) =
R_0·(1 - x - y)]
Problem:
[g_H = 31/100, g_M = 9/20, g_L = 69/100, R_H = 393/100, R_M = 93/50, R_L = 9/50, x > 0, y > 0,  R_0 > 0]
Solution:
[R_0 = 2.1795,
 y = 0.3103448275?,
 R_L = 0.18,
 R_M = 1.86,
 R_H = 3.93,
 g_L = 0.69,
 g_M = 0.45,
 g_H = 0.31,
 x = 0.2137931034?]

Run this example online here

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top