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.

28 lines
865 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. """
  14. #Different approach: Iterate over all entries in the model
  15. block = []
  16. for d in m.decls():
  17. print(d, type(d), d(), type(d()), m[d], type(m[d]))
  18. c = d()
  19. block.append(c != m[d].as_long())
  20. #print(s.sexpr())
  21. """
  22. s.add(Or(block))
  23. else:
  24. print ("All results enumerated, total=", len(results))
  25. break