如何使用Z3Py进行量化消除,以及在电网情况下使用Taylor的想法

时间:2013-08-04 01:42:26

标签: z3 z3py

请考虑以下电气网络

enter image description here

该电网的SAT问题是

enter image description here

使用以下代码使用Z3Py在线解决此问题:

r01, r02, r12, r13, r23 = Reals('r01 r02 r12 r13 r23')
i0, i01, i02, i12, i13, i23, i3 = Reals('i0 i01 i02 i12 i13 i23 i3')
u0, u1, u2, u3 = Reals('u0 u1 u2 u3')
r01=1000
r02 = 100
r12 = 300
r13 = 47000
u0 = 0
u3 = 12
s = Solver()
s.add(u1-u0==r01*i01, u2-u0==r02*i02, u2-u1==r12*i12,u3-u1==r13*i13, u3-u2==r23*i23)
s.add(-i0 + i01 + i02 ==0, -i01+i12+i13==0,-i02-i12+i23==0,-i13-i23+i3==0)
s.add(i3==i0)
s.add((u1-u0)*i01<=0.25, (u2-u0)*i02<=0.25, (u2-u1)*i12<=0.25,(u3-u1)*i13<=0.25,  (u3-u2)*i23<=0.25)         
s.add(r23 > 0)
print s
print s.check()
m = s.model()
set_option(rational_to_decimal=True)
print m

,输出为:

sat
[u1 = 1,
r23 = 824.4299674267?,
i02 = 0.0122978723?,
i12 = 0.0007659574?,
u2 = 1.2297872340?,
i23 = 0.0130638297?,
i3 = 0.0132978723?,
i0 = 0.0132978723?,
i01 = 0.001,
i13 = 0.0002340425?]

最后使用Z3Py我们解决了量词消除的线性问题:

g = Goal()
g.add(Exists([i0, i01, i02, i12, i13, i23, i3, u1, u2], And(u1-u0==r01*i01, u2-u0==r02*i02, u2-u1==r12*i12,
         u3-u1==r13*i13, u3-u2==r23*i23,-i0 + i01 + i02 ==0, -i01+i12+i13==0,-i02-i12+i23==0,
         -i13-i23+i3==0,i3==i0,r23 > 0, (u1-u0)<=7, (u2-u0)<=7, (u2-u1)<=7,
          (u3-u1)<=7, (u3-u2)<=7 )))
t = Tactic('qe')
print t(g)
print t(g).as_expr()
s1 = Solver()
s1.add(t(g).as_expr())
print s1.check()
m1 = s1.model()
print m1

,相应的输出是:

[[∃x!5 :
¬(r23 ≤ 0) ∧
0.0107817589?·r23·x!5 + x!5 ≤ 0.1291856677? ∧
-0.0107817589?·r23·x!5 + -1·x!5 ≤ -0.1291856677? ∧
x!5 + 0.0107817589?·r23·x!5 ≤ 0.1291856677? ∧
r23·x!5 ≥ 2.9319148936? ∧
r23·x!5 ≥ 5 ∧
r23·x!5 ≥ -18.0972222222? ∧
r23·x!5 ≤ 5.5446808510? ∧
r23·x!5 ≤ 7]]

∃x!5 :
¬(r23 ≤ 0) ∧
0.0107817589?·r23·x!5 + x!5 ≤ 0.1291856677? ∧
-0.0107817589?·r23·x!5 + -1·x!5 ≤ -0.1291856677? ∧
x!5 + 0.0107817589?·r23·x!5 ≤ 0.1291856677? ∧
r23·x!5 ≥ 2.9319148936? ∧
 r23·x!5 ≥ 5 ∧
r23·x!5 ≥ -18.0972222222? ∧
r23·x!5 ≤ 5.5446808510? ∧
r23·x!5 ≤ 7

sat

[r23 = 68, x!5!54 = 0.0745376635?]

在线here

运行此示例

请让我知道为什么Z3Py在线性示例中没有完全执行量词消除;如果可以使用Z3Py在线解决量词消除的原始非线性问题。非常感谢。

2 个答案:

答案 0 :(得分:0)

使用Redlog of Reduce可以解决线性问题,如下所示:

enter image description here

答案 1 :(得分:0)

使用Redlog of Reduce可以解决非线性问题,如下所示:

enter image description here