You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

24 lines
800 B

  1. #!/usr/bin/python3
  2. from z3 import *
  3. a,b,c,d,e,f = Ints('a b c d e f')
  4. s = Solver()
  5. s.add(215*a + 275*b + 335*c + 355*d + 420*e + 580*f == 1505, a>=0, b>=0, c>=0, d>=0, e>=0, f>=0)
  6. results=[]
  7. while True:
  8. if s.check() == sat: #
  9. m = s.model() #
  10. print(m) #
  11. results.append(m)
  12. #block = [a != m[a].as_long(), b != m[b].as_long(), c != m[c].as_long(), d != m[d].as_long(), e != m[e].as_long(), f != m[f].as_long()]
  13. #Different approach: Iterate over all entries in the model
  14. block = []
  15. for d in m.decls():
  16. #print(d, type(d), d(), type(d()), m[d], type(m[d]))
  17. block.append(d() != m[d].as_long())
  18. s.add(Or(block))
  19. else:
  20. print ("All results enumerated, total =", len(results))
  21. break