-3

In this question here:

How to print z3 solver results print(s.model()) in order?

the first answer points out the problem of 10 coming after 1, and it only being sorted by the first digit, however he says with more processing it could be fixed, what would this processing be?

1 Answers1

0

Post-processing simply means you just use your Python programming skills to manipulate the output; at this point the problem has nothing to do with z3. For the specific example you're referring to, you can modify it to:

from z3 import *

v = [Real('v_%s' % (i+1)) for i in range(10)]

s = Solver()
for i in range(10):
    s.add(v[i] == i)
if s.check() == sat:
    m = s.model()
    print (sorted ([(d, m[d]) for d in m], key = lambda x: int(str(x[0])[2:])))

which prints:

[(v_1, 0), (v_2, 1), (v_3, 2), (v_4, 3), (v_5, 4), (v_6, 5), (v_7, 6), (v_8, 7), (v_9, 8), (v_10, 9)]

sorting the keys numerically. But again, this isn't really a z3 question: You can take this output and just perform regular Python programming on it as you wish.

alias
  • 28,120
  • 2
  • 23
  • 40