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.

37 lines
1.0 KiB

  1. # coding: utf-8
  2. import os, sys
  3. from z3 import *
  4. # No need to parse anything for this example
  5. #################################### Farm Animals ####################################
  6. solver = Solver()
  7. # We have 100€ ( == 10000c) and we want to buy **exactly** 100 animals, where
  8. # price(cow) = 10€
  9. # price(chicken) = 3€
  10. # price(mouse) = 25c
  11. # todo
  12. # Create Z3 variables which hold the number of animals and the price respectively
  13. # todo
  14. # Create Z3 variables which hold the amount of the different animals our farmes is going to buy
  15. # todo
  16. # Add constraints which model our real life requirements
  17. # Check for satisfiability
  18. res = solver.check()
  19. if res != sat:
  20. print("unsat")
  21. sys.exit(1)
  22. ################################################################################
  23. # print the model
  24. # get the model
  25. m = solver.model()
  26. # print all Z3 variables which have an assignment in the model
  27. for d in m.decls():
  28. print("%s = %s" % (d.name(), m[d]))
  29. ################################################################################