Created
June 19, 2019 17:50
-
-
Save shapr/c34d52220b04318fd2287a46a8147a58 to your computer and use it in GitHub Desktop.
from page 259 of https://yurichev.com/writings/SAT_SMT_by_example.pdf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Pablo buys popsicles for his friends. | |
The store sells single popsicles for$1 each, 3-popsicle boxes for$2, and 5-popsicle boxes for$3. | |
What is the greatest number of popsicles that Pablo can buy with$8? | |
""" | |
from z3 import * | |
box1pop, box3pop, box5pop =Ints('box1pop box3pop box5pop') | |
pop_total=Int('pop_total') | |
cost_total=Int('cost_total') | |
s=Optimize() | |
s.add(pop_total == box1pop*1 + box3pop*3 + box5pop*5) | |
s.add(cost_total == box1pop*1 + box3pop*2 + box5pop*3) | |
s.add(cost_total==8) | |
s.add(box1pop>=0) | |
s.add(box3pop>=0) | |
s.add(box5pop>=0) | |
s.maximize(pop_total) | |
prints.check() | |
prints.model() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment