Z3py, random different solution generation

不想你离开。 提交于 2020-03-05 06:05:26

问题


from z3 import *
import random
a = Int('a')
b = Int('b')

s = Tactic('qflra').solver()
s.add(a > 10)
set_option('smt.arith.random_initial_value', True)
set_option('smt.random_seed', random.randint(0, 2 ** 8))

while s.check() == sat:
    m = s.model()
    print m[a]
    s.add(a != m[a])
    set_option('smt.random_seed', random.randint(0, 2 ** 8))

The result seems to be only randomed for a second... Then it just started to give consecutive numbers.

4294966399
4294966398
4294966397
4294966396
4294966395
4294966394
4294966393
11
12
13
14
4294966400
15
16
17
18
19

How can I make it more random? At least, not a list of consecutive numbers. My optimal goal is to have a list of solutions that are rather uniformly distributed in the solution space.


回答1:


I think you're conflating what randomization does with sampling. As @JohanC pointed out, you usually fix a random seed to get consistent results in SMT across multiple runs. Just because you change the seed, does not mean you'll get a different result. Sampling is an entirely different (and much more difficult) problem than setting some random numbers. Otherwise, what you're doing is correct; To find all the settable options, run z3 -p > options.txt and look inside options.txt for the keywords seed and random.



来源:https://stackoverflow.com/questions/60033332/z3py-random-different-solution-generation

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!