Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problems solved by z3-python #7053

Closed
Byxs20 opened this issue Dec 13, 2023 · 1 comment
Closed

Problems solved by z3-python #7053

Byxs20 opened this issue Dec 13, 2023 · 1 comment

Comments

@Byxs20
Copy link

Byxs20 commented Dec 13, 2023

OS Version: Windows 11
Python Version: Python 3.8.10
Z3 Version: z3-solver 4.12.4.0

from z3 import *

# 创建整数变量 x
x = Int('x')

# 创建条件 x > 12 且 x < 16
condition = And(
x <= 45,
x <= 48,
x <= 49,
x <= 50,
x <= 51,
x <= 52,
x <= 53,
x <= 54,
x <= 55,
x <= 56,
)

# 创建 Z3 Solver
solver = Optimize()

# 向 Solver 添加条件
solver.add(condition)

solver.maximize(x)

# debug
assertions = solver.assertions()
for assertion in assertions:
    print(assertion)

# 检查是否存在解
if solver.check() == sat:
    # 获取解
    model = solver.model()
    solution = model[x].as_long()
    print(f"Solution: {solution}")
else:
    print("No solution")

image

This will not solve for 45, missing an 'x<=56' can be solved

@Byxs20
Copy link
Author

Byxs20 commented Dec 14, 2023

Returned version: pip install z3-solver==4.8.12
Have already solved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant