如何在线使用Z3Py来计算性行为异质性和比例混合的群体中的Ro

时间:2013-08-06 15:20:59

标签: z3 z3py

要解决此问题,我们使用以下代码:

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)

输出

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]

在线here

运行此示例

请让我知道您的想法。非常感谢。

1 个答案:

答案 0 :(得分:0)

有三类性活动的其他例子:高,中,低。

代码:

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)

输出:

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?]

在线here

运行此示例