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.
 
 

45 lines
1.3 KiB

# coding: utf-8
import os, sys
from z3 import *
# No need to parse anything for this example
#################################### Farm Animals ####################################
solver = Solver()
# todo
# Create Z3 variables which hold the number of animals and the price respectively
amount_of_animals = Int("amount_of_animals")
total_price = Int("total_price")
target_price = 10000
target_amount = 100
# todo
# Create Z3 variables which hold the amount of the different animals our farmes is going to buy
cows = Int("cows")
mice = Int("mice")
chicken = Int("chicken")
# todo
# Add constraints which model our real life requirements
solver.add(cows + chicken + mice == amount_of_animals)
solver.add(cows * 1000 + chicken * 300 + mice * 25 == total_price)
solver.add(total_price == target_price)
solver.add(amount_of_animals == target_amount)
# Done?
# Check for satisfiability
res = solver.check()
if res != sat:
print("unsat")
sys.exit(1)
################################################################################
# print the model
# get the model
m = solver.model()
# print all Z3 variables which have an assignment in the model
for d in m.decls():
print("%s = %s" % (d.name(), m[d]))
################################################################################